@@ -5,15 +5,16 @@ import type {
55} from '@enonic-types/core' ;
66import type {
77 BooleanFilter ,
8+ CreateNodeParams ,
89 HasValueFilter ,
910 MoveNodeParams ,
11+ Node ,
1012 QueryNodeParams ,
1113} from '@enonic-types/lib-node' ;
1214import type {
1315 GetActiveVersionParamObject ,
1416 GetActiveVersionResponse ,
1517 Log ,
16- NodeCreateParams ,
1718 NodeModifyParams ,
1819 NodeQueryResponse ,
1920 NodeRefreshParams ,
@@ -166,7 +167,7 @@ export class Branch {
166167 // this.log.debug('in Branch constructor');
167168 }
168169
169- _createNodeInternal ( {
170+ _createNodeInternal < NodeData = unknown > ( {
170171 // _childOrder,
171172 _id = this . repo . generateId ( ) ,
172173 _indexConfig = DEFAULT_INDEX_CONFIG ,
@@ -178,19 +179,17 @@ export class Branch {
178179 _ts = Branch . generateInstantString ( ) ,
179180 _versionKey = this . repo . generateId ( ) ,
180181 ...rest // contains _nodeType
181- } : NodeCreateParams & {
182+ } : CreateNodeParams < NodeData > & {
182183 _id ?: string
183- _ts ?: string
184- _versionKey ?: string
185- } ) : RepoNodeWithData {
184+ } ) : Node < NodeData > {
186185 for ( const k of IGNORED_ON_CREATE ) {
187186 if ( rest . hasOwnProperty ( k ) ) { delete rest [ k ] ; }
188187 }
188+ if ( ! _name ) { _name = _id as string ; }
189189 if ( ! rest . _nodeType ) {
190+ // @ts -expect-error Too complex to waste time on making perfect!
190191 rest . _nodeType = 'default' ;
191192 }
192- if ( ! _name ) { _name = _id as string ; }
193-
194193 if ( ! _parentPath . endsWith ( '/' ) ) {
195194 _parentPath += '/'
196195 }
@@ -213,17 +212,18 @@ export class Branch {
213212 throw new NodeAlreadyExistAtPathException ( `Node already exists at ${ _path } repository: ${ this . repo . id } branch: ${ this . id } ` ) ;
214213 }
215214
216- const node : RepoNodeWithData = {
215+ const node : Node < NodeData > = {
217216 _id,
218217 _indexConfig,
219218 _name,
219+ // _nodeType,
220220 _path,
221221 _state : 'DEFAULT' ,
222222 _ts,
223223 _versionKey,
224224 ...( enonify ( rest ) as Object )
225- } as unknown as RepoNodeWithData ;
226- this . nodes [ _id ] = node ;
225+ } as unknown as Node < NodeData > ;
226+ this . nodes [ _id ] = node as RepoNodeWithData ;
227227 this . pathIndex [ _path ] = _id ;
228228
229229 const restKeys = Object . keys ( rest ) . filter ( k => ! SEARCH_INDEX_BLACKLIST . includes ( k ) ) ;
@@ -263,8 +263,8 @@ export class Branch {
263263 return deref ( node ) ;
264264 } // _createNodeInternal
265265
266- createNode ( params : NodeCreateParams ) : RepoNodeWithData {
267- return this . _createNodeInternal ( params ) ; // already dereffed
266+ createNode < NodeData = unknown > ( params : CreateNodeParams < NodeData > ) : Node < NodeData > {
267+ return this . _createNodeInternal < NodeData > ( params ) ; // already dereffed
268268 }
269269
270270 private keyToId ( key : string ) : string | undefined {
@@ -650,7 +650,7 @@ export class Branch {
650650 }
651651
652652 if ( isQueryDsl ( query ) ) {
653- this . log . info ( 'query: Search Index: %s' , this . searchIndex ) ;
653+ this . log . info ( 'query:%s Search Index: %s' , query , this . searchIndex ) ;
654654 const mustSets : string [ ] [ ] = [ ] ;
655655 const mustNotSets : string [ ] [ ] = [ ] ;
656656
0 commit comments