@@ -181,129 +181,15 @@ export class PersistedSlice<T = string> extends Range<T> implements MutableSlice
181181 return new NestedType < T > ( this ) ;
182182 }
183183
184- public typeAsArr ( ) : ArrApi {
185- const api = this . typeApi ( ) ;
186- if ( api && api . node . name ( ) === 'arr' ) return api as unknown as ArrApi ;
187- let type : unknown ;
188- if ( ! api ) type = [ 0 ] ;
189- else {
190- type = api . view ( ) ;
191- if ( ! Array . isArray ( type ) ) type = typeof type === 'number' || typeof type === 'string' ? [ type ] : [ 0 ] ;
192- }
193- this . tupleApi ( ) . set ( [ [ SliceTupleIndex . Type , schema . type ( type as SliceTypeSteps ) ] ] ) ;
194- return this . typeApi ( ) as unknown as ArrApi ;
195- }
196-
197- public typeStepAsVec ( index ?: number ) : VecApi {
198- const arr = this . typeAsArr ( ) ;
199- const typeLen = arr . length ( ) ;
200- if ( typeof index !== 'number' || index > typeLen - 1 ) index = typeLen - 1 ;
201- const vec = arr . get ( index ) ;
202- if ( vec instanceof VecApi ) return vec ;
203- const tag = vec instanceof ConApi ? vec . view ( ) : 0 ;
204- arr . upd ( index , s . vec ( s . con ( tag ) ) ) ;
205- return arr . get ( index ) as VecApi ;
206- }
207-
208- public tagDataAsObj ( index ?: number ) : ObjApi {
209- const vec = this . typeStepAsVec ( index ) ;
210- const data = vec . select ( 2 ) ;
211- if ( data instanceof ObjApi ) return data ;
212- vec . set ( [ [ 2 , s . obj ( { } ) ] ] ) ;
213- return vec . get ( 2 ) as ObjApi ;
214- }
215-
216- public typeStepApi ( index ?: number ) : NodeApi {
217- const arr = this . typeAsArr ( ) ;
218- let typeLen = arr . length ( ) ;
219- if ( typeLen === 0 ) {
220- arr . ins ( 0 , [ s . con ( 0 ) ] ) ;
221- typeLen = 1 ;
222- }
223- if ( typeof index !== 'number' || index > typeLen - 1 ) index = typeLen - 1 ;
224- return arr . get ( index ) as NodeApi ;
225- }
226-
227184 public type ( ) : SliceType {
228- return this . typeApi ( ) ?. view ( ) as SliceType ;
229- }
230-
231- public typeLen ( ) : number {
232- const node = this . typeNode ( ) ;
233- if ( ! node ) return 1 ;
234- if ( node instanceof ArrNode ) return node . length ( ) ;
235- if ( node instanceof ConNode ) {
236- const view = node . view ( ) ;
237- if ( Array . isArray ( view ) ) return view . length ;
238- }
239- return 1 ;
185+ return this . typeNode ( ) ?. view ( ) as SliceType ;
240186 }
241187
242188 public typeSteps ( ) : SliceTypeSteps {
243189 const type = this . type ( ) ?? SliceTypeCon . p ;
244190 return Array . isArray ( type ) ? type : [ type ] ;
245191 }
246192
247- public typeStep ( index ?: number ) : SliceTypeStep | undefined {
248- const typeLen = this . typeLen ( ) ;
249- if ( typeof index !== 'number' || index > typeLen - 1 ) index = typeLen - 1 ;
250- const type = this . type ( ) ;
251- return Array . isArray ( type ) ? type [ index ] : type ;
252- }
253-
254- // public tag(index?: number): TypeTag {
255- // const step = this.typeStep(index);
256- // if (!step) return 0;
257- // return Array.isArray(step) ? step[0] : step;
258- // }
259-
260- // public tagDisc(index?: number): number {
261- // const step = this.typeStep(index);
262- // if (!step) return 0;
263- // return Array.isArray(step) ? (step[1] ?? 0) : 0;
264- // }
265-
266- // public tagData(index?: number): unknown | undefined {
267- // const step = this.typeStep(index);
268- // if (!step) return;
269- // return Array.isArray(step) ? step[2] : void 0;
270- // }
271-
272- // public typeStepNodeAsVec(index?: number): VecNode | undefined {
273- // const arr = this.typeNodeAsArr();
274- // const typeLen = type.length();
275- // if (typeLen === 0) return;
276- // if (typeof index !== 'number' || index > typeLen - 1) index = typeLen - 1;
277- // const node = arr.getNode(index);
278- // if (node instanceof VecNode) return node;
279- // // arr.upd()
280- // // const typeLen = type.length();
281- // // if (typeLen === 0) return;
282- // // if (typeof index !== 'number' || index > typeLen - 1) index = typeLen - 1;
283- // // const step = this.typeStepNode(index);
284- // // // if (!step) return;
285- // }
286-
287- // public tagDataNode(index?: number): JsonNode<unknown> | undefined {
288- // const stepNode = this.typeStepApi(index);
289- // if (!stepNode) return;
290- // return stepNode instanceof VecNode ? stepNode.get(2) : void 0;
291- // }
292-
293- // public tagDataNodeAsObj(index?: number): ObjApi<ObjNode> | undefined {
294- // const node = this.tagDataNode(index);
295- // if (node instanceof ObjNode) {
296- // return this.model.api.wrap(node);
297- // }
298- // if (node instanceof VecNode) {
299- // const objNode = node.get(2);
300- // if (objNode instanceof ObjNode) {
301- // return this.model.api.wrap(objNode);
302- // }
303- // }
304- // return undefined;
305- // }
306-
307193 // -------------------------------------------------- slice data manipulation
308194
309195 public data ( ) : unknown | undefined {
0 commit comments