mol_vary 0.0.41 → 0.0.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mol_vary",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
4
4
  "exports": {
5
5
  "node": {
6
6
  "import": "./node.mjs",
package/web.d.ts CHANGED
@@ -78,18 +78,30 @@ declare namespace $ {
78
78
  true,
79
79
  fake,
80
80
  both,
81
- fp16 = 93,
82
- fp32 = 94,
83
- fp64 = 95
81
+ fp16,
82
+ fp32,
83
+ fp64,
84
+ f128,
85
+ f256
84
86
  }
85
- class $mol_vary extends Object {
86
- static pack(data: unknown): Uint8Array<ArrayBuffer>;
87
- static take(buffer: Uint8Array<ArrayBuffer>): unknown;
88
- static rich_index: Map<string | null, any>;
89
- static rich_node(keys: readonly string[]): Map<string | null, any>;
90
- static type<const Instance extends object, const Keys extends readonly any[], const Vals extends readonly any[]>(Class: new (...vals: any[]) => Instance, keys: Keys, lean: (obj: Instance) => Vals, rich: (...vals: Vals) => Instance): void;
87
+ class $mol_vary_class extends Object {
88
+ lean_symbol: symbol;
89
+ array: Uint8Array<ArrayBuffer>;
90
+ buffer: DataView<ArrayBuffer>;
91
+ pack(data: unknown): Uint8Array<ArrayBuffer>;
92
+ take(array: Uint8Array<ArrayBuffer>): unknown;
93
+ rich_index: Map<string | null, any>;
94
+ room(): $mol_vary_class;
95
+ rich_node(keys: readonly string[]): Map<string | null, any>;
96
+ lean_find(val: any): any;
97
+ type<const Instance extends object, const Keys extends readonly any[], const Vals extends readonly any[]>({ type, keys, rich, lean }: {
98
+ type: new (...vals: any[]) => Instance;
99
+ keys: Keys;
100
+ lean: (obj: Instance) => Vals;
101
+ rich: (vals: Vals) => Instance;
102
+ }): void;
91
103
  }
92
- const $mol_vary_lean: unique symbol;
104
+ let $mol_vary: $mol_vary_class;
93
105
  }
94
106
 
95
107
  export = $;
package/web.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../mam.d.ts","../../bigint/encode/encode.d.ts","../../fail/fail.d.ts","../../charset/encode/encode.d.ts","../../bigint/decode/decode.d.ts","../../charset/encoding/encoding.d.ts","../../charset/decode/decode.d.ts","../../charset/decode/from/from.d.ts","../../dom/context/context.d.ts","../../dom/context/context.web.d.ts","../../dom/dom.d.ts","../vary.d.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACfA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;AACA;AACA;ACLA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;ACHA;AACA;AACA;ACFA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null]}
1
+ {"version":3,"sources":["../../../mam.d.ts","../../bigint/encode/encode.d.ts","../../fail/fail.d.ts","../../charset/encode/encode.d.ts","../../bigint/decode/decode.d.ts","../../charset/encoding/encoding.d.ts","../../charset/decode/decode.d.ts","../../charset/decode/from/from.d.ts","../../dom/context/context.d.ts","../../dom/context/context.web.d.ts","../../dom/dom.d.ts","../vary.d.ts"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACfA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;AACA;AACA;ACLA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;ACHA;AACA;AACA;ACFA;AACA;AACA;AACA;ACHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null]}
package/web.deps.json CHANGED
@@ -1 +1 @@
1
- {"files":["mam.ts","LICENSE","README.md","mam.jam.js","tsfmt.json","package.json","tsconfig.json","lang.lang.tree","meta.lang.tree","sandbox.config.json","mol/CNAME","mol/LICENSE","mol/readme.md","mol/mol.meta.tree","mol/CONTRIBUTING.md","mol/CODE_OF_CONDUCT.md","mol/bigint/encode/encode.ts","mol/fail/fail.ts","mol/charset/encode/encode.ts","mol/bigint/decode/decode.ts","mol/charset/encoding/encoding.ts","mol/charset/decode/decode.ts","mol/charset/decode/from/from.ts","mol/dom/context/context.ts","mol/dom/context/context.web.ts","mol/dom/dom.ts","mol/vary/vary.ts","mol/vary/readme.md"],"mods":{},"deps_in":{"mol":{"mol/vary":-999,"mol/bigint":-999,"mol/fail":-999,"mol/charset":-999,"mol/dom":-999},"":{"mol":-999},"mol/bigint/encode":{"mol/vary":-4},"mol/bigint":{"mol/bigint/encode":-999,"mol/bigint/decode":-999},"mol/fail":{"mol/vary":-3},"mol/charset/encode":{"mol/vary":-4},"mol/charset":{"mol/charset/encode":-999,"mol/charset/decode":-999,"mol/charset/encoding":-999},"mol/bigint/decode":{"mol/vary":-5},"mol/charset/decode/from":{"mol/vary":-4},"mol/charset/decode":{"mol/charset/decode/from":-999},"mol/charset/encoding":{"mol/charset/decode":-1},"mol/dom":{"mol/vary":-2},"mol/dom/context":{"mol/dom":-1},"mol/dom/context/context.ts":{"mol/dom/context":0}},"deps_out":{"mol/vary":{"mol":-999,"mol/bigint/encode":-4,"mol/fail":-3,"mol/charset/encode":-4,"mol/bigint/decode":-5,"mol/charset/decode/from":-4,"mol/dom":-2},"mol":{"":-999},"mol/bigint/encode":{"mol/bigint":-999},"mol/bigint":{"mol":-999},"mol/fail":{"mol":-999},"mol/charset/encode":{"mol/charset":-999},"mol/charset":{"mol":-999},"mol/bigint/decode":{"mol/bigint":-999},"mol/charset/decode/from":{"mol/charset/decode":-999},"mol/charset/decode":{"mol/charset":-999,"mol/charset/encoding":-1},"mol/charset/encoding":{"mol/charset":-999},"mol/dom":{"mol":-999,"mol/dom/context":-1},"mol/dom/context":{"mol/dom/context/context.ts":0},"mol/dom/context/context.ts":{}},"sloc":{"ts":654,"LICENSE":113,"md":530,"js":9,"json":82,"tree":41,"CNAME":1},"deps":{"mol/vary":{"..":-999,"/mol/vary/tip":-1,"/mol/vary/len":-1,"/mol/vary/spec":-1,"/mol/vary/tip/spec":-2,"/mol/vary":-1,"/mol/vary/tip/uint":-4,"/mol/vary/tip/link":-4,"/mol/bigint/encode":-4,"/mol/fail":-3,"/mol/vary/spec/fp64":-4,"/mol/vary/tip/text":-4,"/mol/charset/encode/to":-4,"/mol/vary/tip/blob":-4,"/mol/vary/tip/sint":-4,"/mol/vary/spec/fp16":-4,"/mol/vary/spec/fp32":-4,"/mol/vary/tip/list":-4,"/mol/vary/lean":-1,"/mol/vary/tip/tupl":-4,"/mol/vary/spec/both":-5,"/mol/vary/spec/true":-5,"/mol/vary/spec/fake":-5,"/mol/vary/spec/none":-5,"/mol/bigint/decode":-5,"/mol/charset/decode/from":-4,"/mol/vary/type":-1,"/mol/dom":-2,"/mol/dom/document/create/element":-3,"/mol/dom/document/create/text/node":-4,"/mol/dom/document/create/comment":-2,"/mol/dom/document/create/processing/instruction":-2},"mol":{"..":-999},"":{},"mol/bigint/encode":{"..":-999,"/mol/bigint/encode":-1},"mol/bigint":{"..":-999},"mol/fail":{"..":-999,"/mol/fail":-1},"mol/charset/encode":{"..":-999,"/mol/charset/encode":-1,"/mol/charset/encode/to":-1,"/mol/charset/encode/size":-1},"mol/charset":{"..":-999},"mol/bigint/decode":{"..":-999,"/mol/bigint/decode":-1},"mol/charset/decode/from":{"..":-999,"/mol/charset/decode/from":-1},"mol/charset/decode":{"..":-999,"/mol/charset/encoding":-1,"/mol/charset/decode":-1},"mol/charset/encoding":{"..":-999,"/mol/charset/encoding":-1},"mol/dom":{"..":-999,"/mol/dom":-1,"/mol/dom/context":-1},"mol/dom/context":{"..":-999,"/mol/dom/context":-1,"./context.ts":0},"mol/dom/context/context.ts":{"/mol/dom/context":-1}}}
1
+ {"files":["mam.ts","LICENSE","README.md","mam.jam.js","tsfmt.json","package.json","tsconfig.json","lang.lang.tree","meta.lang.tree","sandbox.config.json","mol/CNAME","mol/LICENSE","mol/readme.md","mol/mol.meta.tree","mol/CONTRIBUTING.md","mol/CODE_OF_CONDUCT.md","mol/bigint/encode/encode.ts","mol/fail/fail.ts","mol/charset/encode/encode.ts","mol/bigint/decode/decode.ts","mol/charset/encoding/encoding.ts","mol/charset/decode/decode.ts","mol/charset/decode/from/from.ts","mol/dom/context/context.ts","mol/dom/context/context.web.ts","mol/dom/dom.ts","mol/vary/vary.ts","mol/vary/readme.md"],"mods":{},"deps_in":{"mol":{"mol/vary":-999,"mol/bigint":-999,"mol/fail":-999,"mol/charset":-999,"mol/dom":-999},"":{"mol":-999},"mol/bigint/encode":{"mol/vary":-4},"mol/bigint":{"mol/bigint/encode":-999,"mol/bigint/decode":-999},"mol/fail":{"mol/vary":-3},"mol/charset/encode":{"mol/vary":-4},"mol/charset":{"mol/charset/encode":-999,"mol/charset/decode":-999,"mol/charset/encoding":-999},"mol/bigint/decode":{"mol/vary":-5},"mol/charset/decode/from":{"mol/vary":-4},"mol/charset/decode":{"mol/charset/decode/from":-999},"mol/charset/encoding":{"mol/charset/decode":-1},"mol/dom":{"mol/vary":-2},"mol/dom/context":{"mol/dom":-1},"mol/dom/context/context.ts":{"mol/dom/context":0}},"deps_out":{"mol/vary":{"mol":-999,"mol/bigint/encode":-4,"mol/fail":-3,"mol/charset/encode":-4,"mol/bigint/decode":-5,"mol/charset/decode/from":-4,"mol/dom":-2},"mol":{"":-999},"mol/bigint/encode":{"mol/bigint":-999},"mol/bigint":{"mol":-999},"mol/fail":{"mol":-999},"mol/charset/encode":{"mol/charset":-999},"mol/charset":{"mol":-999},"mol/bigint/decode":{"mol/bigint":-999},"mol/charset/decode/from":{"mol/charset/decode":-999},"mol/charset/decode":{"mol/charset":-999,"mol/charset/encoding":-1},"mol/charset/encoding":{"mol/charset":-999},"mol/dom":{"mol":-999,"mol/dom/context":-1},"mol/dom/context":{"mol/dom/context/context.ts":0},"mol/dom/context/context.ts":{}},"sloc":{"ts":677,"LICENSE":113,"md":536,"js":9,"json":82,"tree":41,"CNAME":1},"deps":{"mol/vary":{"..":-999,"/mol/vary/tip":-1,"/mol/vary/len":-1,"/mol/vary/spec":-1,"/mol/vary/class":-1,"/mol/vary/lean":-2,"/mol/vary/tip/uint":-4,"/mol/vary/tip/link":-4,"/mol/bigint/encode":-4,"/mol/fail":-3,"/mol/vary/spec/fp64":-4,"/mol/vary/tip/text":-4,"/mol/charset/encode/to":-4,"/mol/vary/tip/blob":-4,"/mol/vary/tip/sint":-4,"/mol/vary/spec/fp16":-4,"/mol/vary/spec/fp32":-4,"/mol/vary/tip/list":-4,"/mol/vary/tip/tupl":-4,"/mol/vary/spec/both":-5,"/mol/vary/spec/true":-5,"/mol/vary/spec/fake":-5,"/mol/vary/spec/none":-5,"/mol/bigint/decode":-5,"/mol/charset/decode/from":-4,"/mol/vary/tip/spec":-5,"/mol/vary":-1,"/mol/vary/type":-1,"/mol/dom":-2,"/mol/dom/document/create/element":-3,"/mol/dom/document/create/text/node":-4,"/mol/dom/document/create/comment":-2,"/mol/dom/document/create/processing/instruction":-2},"mol":{"..":-999},"":{},"mol/bigint/encode":{"..":-999,"/mol/bigint/encode":-1},"mol/bigint":{"..":-999},"mol/fail":{"..":-999,"/mol/fail":-1},"mol/charset/encode":{"..":-999,"/mol/charset/encode":-1,"/mol/charset/encode/to":-1,"/mol/charset/encode/size":-1},"mol/charset":{"..":-999},"mol/bigint/decode":{"..":-999,"/mol/bigint/decode":-1},"mol/charset/decode/from":{"..":-999,"/mol/charset/decode/from":-1},"mol/charset/decode":{"..":-999,"/mol/charset/encoding":-1,"/mol/charset/decode":-1},"mol/charset/encoding":{"..":-999,"/mol/charset/encoding":-1},"mol/dom":{"..":-999,"/mol/dom":-1,"/mol/dom/context":-1},"mol/dom/context":{"..":-999,"/mol/dom/context":-1,"./context.ts":0},"mol/dom/context/context.ts":{"/mol/dom/context":-1}}}
package/web.js CHANGED
@@ -262,14 +262,23 @@ var $;
262
262
  $mol_vary_spec[$mol_vary_spec["true"] = 'T'.charCodeAt(0)] = "true";
263
263
  $mol_vary_spec[$mol_vary_spec["fake"] = 'F'.charCodeAt(0)] = "fake";
264
264
  $mol_vary_spec[$mol_vary_spec["both"] = 'B'.charCodeAt(0)] = "both";
265
- $mol_vary_spec[$mol_vary_spec["fp16"] = 93] = "fp16";
266
- $mol_vary_spec[$mol_vary_spec["fp32"] = 94] = "fp32";
267
- $mol_vary_spec[$mol_vary_spec["fp64"] = 95] = "fp64";
265
+ $mol_vary_spec[$mol_vary_spec["fp16"] = 'H'.charCodeAt(0)] = "fp16";
266
+ $mol_vary_spec[$mol_vary_spec["fp32"] = 'S'.charCodeAt(0)] = "fp32";
267
+ $mol_vary_spec[$mol_vary_spec["fp64"] = 'D'.charCodeAt(0)] = "fp64";
268
+ $mol_vary_spec[$mol_vary_spec["f128"] = 'Q'.charCodeAt(0)] = "f128";
269
+ $mol_vary_spec[$mol_vary_spec["f256"] = 'O'.charCodeAt(0)] = "f256";
268
270
  })($mol_vary_spec = $.$mol_vary_spec || ($.$mol_vary_spec = {}));
269
- let buffer = new Uint8Array(256);
270
- let pack = new DataView(buffer.buffer);
271
- class $mol_vary extends Object {
272
- static pack(data) {
271
+ const pojo_maker = (keys) => (vals) => {
272
+ const obj = {};
273
+ for (let i = 0; i < keys.length; ++i)
274
+ obj[keys[i]] = vals[i];
275
+ return obj;
276
+ };
277
+ class $mol_vary_class extends Object {
278
+ lean_symbol = Symbol('$mol_vary_lean');
279
+ array = new Uint8Array(256);
280
+ buffer = new DataView(this.array.buffer);
281
+ pack(data) {
273
282
  let pos = 0;
274
283
  let capacity = 9;
275
284
  const offsets = new Map();
@@ -278,19 +287,19 @@ var $;
278
287
  if (size < 0)
279
288
  return;
280
289
  capacity += size;
281
- if (buffer.byteLength >= capacity)
290
+ if (this.array.byteLength >= capacity)
282
291
  return;
283
292
  const buffer2 = new Uint8Array(Math.ceil(capacity / 4096) * 4096);
284
- buffer2.set(buffer);
285
- buffer = buffer2;
286
- pack = new DataView(buffer.buffer);
293
+ buffer2.set(this.array);
294
+ this.array = buffer2;
295
+ this.buffer = new DataView(this.array.buffer);
287
296
  };
288
297
  const release = (size) => {
289
298
  capacity -= size;
290
299
  };
291
300
  const dump_unum = (tip, val) => {
292
301
  if (val < $mol_vary_len.L1) {
293
- buffer[pos++] = tip | Number(val);
302
+ this.array[pos++] = tip | Number(val);
294
303
  release(8);
295
304
  return;
296
305
  }
@@ -300,25 +309,25 @@ var $;
300
309
  return dump_unum($mol_vary_tip.link, offset);
301
310
  }
302
311
  if (val < 2 ** 8) {
303
- buffer[pos++] = tip | $mol_vary_len.L1;
304
- buffer[pos++] = Number(val);
312
+ this.array[pos++] = tip | $mol_vary_len.L1;
313
+ this.array[pos++] = Number(val);
305
314
  release(7);
306
315
  }
307
316
  else if (val < 2 ** 16) {
308
- buffer[pos++] = tip | $mol_vary_len.L2;
309
- pack.setUint16(pos, Number(val), true);
317
+ this.array[pos++] = tip | $mol_vary_len.L2;
318
+ this.buffer.setUint16(pos, Number(val), true);
310
319
  pos += 2;
311
320
  release(6);
312
321
  }
313
322
  else if (val < 2 ** 32) {
314
- buffer[pos++] = tip | $mol_vary_len.L4;
315
- pack.setUint32(pos, Number(val), true);
323
+ this.array[pos++] = tip | $mol_vary_len.L4;
324
+ this.buffer.setUint32(pos, Number(val), true);
316
325
  pos += 4;
317
326
  release(4);
318
327
  }
319
328
  else if (val < 2n ** 64n) {
320
- buffer[pos++] = tip | $mol_vary_len.L8;
321
- pack.setBigUint64(pos, BigInt(val), true);
329
+ this.array[pos++] = tip | $mol_vary_len.L8;
330
+ this.buffer.setBigUint64(pos, BigInt(val), true);
322
331
  pos += 8;
323
332
  }
324
333
  else {
@@ -329,7 +338,7 @@ var $;
329
338
  };
330
339
  const dump_snum = (val) => {
331
340
  if (val > -$mol_vary_len.L1) {
332
- buffer[pos++] = Number(val);
341
+ this.array[pos++] = Number(val);
333
342
  release(8);
334
343
  return;
335
344
  }
@@ -337,25 +346,25 @@ var $;
337
346
  if (offset !== undefined)
338
347
  return dump_unum($mol_vary_tip.link, offset);
339
348
  if (val >= -(2 ** 7)) {
340
- buffer[pos++] = -$mol_vary_len.L1;
341
- buffer[pos++] = Number(val);
349
+ this.array[pos++] = -$mol_vary_len.L1;
350
+ this.array[pos++] = Number(val);
342
351
  release(7);
343
352
  }
344
353
  else if (val >= -(2 ** 15)) {
345
- buffer[pos++] = -$mol_vary_len.L2;
346
- pack.setInt16(pos, Number(val), true);
354
+ this.array[pos++] = -$mol_vary_len.L2;
355
+ this.buffer.setInt16(pos, Number(val), true);
347
356
  pos += 2;
348
357
  release(6);
349
358
  }
350
359
  else if (val >= -(2 ** 31)) {
351
- buffer[pos++] = -$mol_vary_len.L4;
352
- pack.setInt32(pos, Number(val), true);
360
+ this.array[pos++] = -$mol_vary_len.L4;
361
+ this.buffer.setInt32(pos, Number(val), true);
353
362
  pos += 4;
354
363
  release(4);
355
364
  }
356
365
  else if (val >= -(2n ** 63n)) {
357
- buffer[pos++] = -$mol_vary_len.L8;
358
- pack.setBigInt64(pos, BigInt(val), true);
366
+ this.array[pos++] = -$mol_vary_len.L8;
367
+ this.buffer.setBigInt64(pos, BigInt(val), true);
359
368
  pos += 8;
360
369
  }
361
370
  else {
@@ -368,17 +377,17 @@ var $;
368
377
  if (buf.byteLength > 264)
369
378
  $mol_fail(new Error('Number too high', { cause: { val } }));
370
379
  acquire(buf.byteLength - 7);
371
- buffer[pos++] = -$mol_vary_len.LA;
372
- buffer[pos++] = buf.byteLength - 9;
373
- buffer.set(buf, pos);
380
+ this.array[pos++] = -$mol_vary_len.LA;
381
+ this.array[pos++] = buf.byteLength - 9;
382
+ this.array.set(buf, pos);
374
383
  pos += buf.byteLength;
375
384
  };
376
385
  const dump_float = (val) => {
377
386
  const offset = offsets.get(val);
378
387
  if (offset !== undefined)
379
388
  return dump_unum($mol_vary_tip.link, offset);
380
- buffer[pos++] = $mol_vary_spec.fp64;
381
- pack.setFloat64(pos, val, true);
389
+ this.array[pos++] = $mol_vary_spec.fp64;
390
+ this.buffer.setFloat64(pos, val, true);
382
391
  pos += 8;
383
392
  offsets.set(val, offsets.size);
384
393
  };
@@ -388,7 +397,7 @@ var $;
388
397
  return dump_unum($mol_vary_tip.link, offset);
389
398
  dump_unum($mol_vary_tip.text, val.length);
390
399
  acquire(val.length * 3);
391
- const len = $mol_charset_encode_to(val, buffer, pos);
400
+ const len = $mol_charset_encode_to(val, this.array, pos);
392
401
  pos += len;
393
402
  release(val.length * 3 - len);
394
403
  offsets.set(val, offsets.size);
@@ -401,31 +410,31 @@ var $;
401
410
  dump_unum($mol_vary_tip.blob, val.byteLength);
402
411
  acquire(1 + val.byteLength);
403
412
  if (val instanceof Uint8Array)
404
- buffer[pos++] = $mol_vary_tip.uint | $mol_vary_len.L1;
413
+ this.array[pos++] = $mol_vary_tip.uint | $mol_vary_len.L1;
405
414
  else if (val instanceof Uint16Array)
406
- buffer[pos++] = $mol_vary_tip.uint | $mol_vary_len.L2;
415
+ this.array[pos++] = $mol_vary_tip.uint | $mol_vary_len.L2;
407
416
  else if (val instanceof Uint32Array)
408
- buffer[pos++] = $mol_vary_tip.uint | $mol_vary_len.L4;
417
+ this.array[pos++] = $mol_vary_tip.uint | $mol_vary_len.L4;
409
418
  else if (val instanceof BigUint64Array)
410
- buffer[pos++] = $mol_vary_tip.uint | $mol_vary_len.L8;
419
+ this.array[pos++] = $mol_vary_tip.uint | $mol_vary_len.L8;
411
420
  else if (val instanceof Int8Array)
412
- buffer[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L1;
421
+ this.array[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L1;
413
422
  else if (val instanceof Int16Array)
414
- buffer[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L2;
423
+ this.array[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L2;
415
424
  else if (val instanceof Int32Array)
416
- buffer[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L4;
425
+ this.array[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L4;
417
426
  else if (val instanceof BigInt64Array)
418
- buffer[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L8;
427
+ this.array[pos++] = $mol_vary_tip.sint | ~$mol_vary_len.L8;
419
428
  else if (typeof Float16Array === 'function' && val instanceof Float16Array)
420
- buffer[pos++] = $mol_vary_spec.fp16;
429
+ this.array[pos++] = $mol_vary_spec.fp16;
421
430
  else if (val instanceof Float32Array)
422
- buffer[pos++] = $mol_vary_spec.fp32;
431
+ this.array[pos++] = $mol_vary_spec.fp32;
423
432
  else if (val instanceof Float64Array)
424
- buffer[pos++] = $mol_vary_spec.fp64;
433
+ this.array[pos++] = $mol_vary_spec.fp64;
425
434
  else
426
435
  $mol_fail(new Error(`Unsupported type`));
427
436
  const src = (val instanceof Uint8Array) ? val : new Uint8Array(val.buffer, val.byteOffset, val.byteLength);
428
- buffer.set(src, pos);
437
+ this.array.set(src, pos);
429
438
  pos += val.byteLength;
430
439
  offsets.set(val, offsets.size);
431
440
  };
@@ -459,7 +468,7 @@ var $;
459
468
  const offset = offsets.get(val);
460
469
  if (offset !== undefined)
461
470
  return dump_unum($mol_vary_tip.link, offset);
462
- const [keys, vals] = val[$.$mol_vary_lean]?.(val) ?? [shape(val), Object.values(val)];
471
+ const [keys, vals] = this.lean_find(val)?.(val) ?? [shape(val), Object.values(val)];
463
472
  dump_unum($mol_vary_tip.tupl, vals.length);
464
473
  acquire((vals.length + 1) * 9);
465
474
  dump_list(keys);
@@ -476,12 +485,12 @@ var $;
476
485
  const dump = (val) => {
477
486
  switch (typeof val) {
478
487
  case 'undefined': {
479
- buffer[pos++] = $mol_vary_spec.both;
488
+ this.array[pos++] = $mol_vary_spec.both;
480
489
  release(8);
481
490
  return;
482
491
  }
483
492
  case 'boolean': {
484
- buffer[pos++] = val ? $mol_vary_spec.true : $mol_vary_spec.fake;
493
+ this.array[pos++] = val ? $mol_vary_spec.true : $mol_vary_spec.fake;
485
494
  release(8);
486
495
  return;
487
496
  }
@@ -502,7 +511,7 @@ var $;
502
511
  case 'object': {
503
512
  if (!val) {
504
513
  release(8);
505
- return buffer[pos++] = $mol_vary_spec.none;
514
+ return this.array[pos++] = $mol_vary_spec.none;
506
515
  }
507
516
  if (ArrayBuffer.isView(val))
508
517
  return dump_buffer(val);
@@ -516,10 +525,10 @@ var $;
516
525
  dump(data);
517
526
  if (pos !== capacity)
518
527
  $mol_fail(new Error('Wrong reserved capacity', { cause: { capacity, size: pos, data } }));
519
- return buffer.slice(0, pos);
528
+ return this.array.slice(0, pos);
520
529
  }
521
- static take(buffer) {
522
- const pack = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
530
+ take(array) {
531
+ const buffer = new DataView(array.buffer, array.byteOffset, array.byteLength);
523
532
  const stream = [];
524
533
  let pos = 0;
525
534
  const read_unum = (kind) => {
@@ -529,18 +538,18 @@ var $;
529
538
  return num;
530
539
  let res = 0;
531
540
  if (num === $mol_vary_len.L1) {
532
- res = pack.getUint8(pos++);
541
+ res = buffer.getUint8(pos++);
533
542
  }
534
543
  else if (num === $mol_vary_len.L2) {
535
- res = pack.getUint16(pos, true);
544
+ res = buffer.getUint16(pos, true);
536
545
  pos += 2;
537
546
  }
538
547
  else if (num === $mol_vary_len.L4) {
539
- res = pack.getUint32(pos, true);
548
+ res = buffer.getUint32(pos, true);
540
549
  pos += 4;
541
550
  }
542
551
  else if (num === $mol_vary_len.L8) {
543
- res = pack.getBigUint64(pos, true);
552
+ res = buffer.getBigUint64(pos, true);
544
553
  if (res <= Number.MAX_SAFE_INTEGER)
545
554
  res = Number(res);
546
555
  pos += 8;
@@ -553,30 +562,30 @@ var $;
553
562
  return res;
554
563
  };
555
564
  const read_snum = (kind) => {
556
- const num = pack.getInt8(pos++);
565
+ const num = buffer.getInt8(pos++);
557
566
  if (num > -$mol_vary_len.L1)
558
567
  return num;
559
568
  let res = 0;
560
569
  if (num === -$mol_vary_len.L1) {
561
- res = pack.getInt8(pos++);
570
+ res = buffer.getInt8(pos++);
562
571
  }
563
572
  else if (num === -$mol_vary_len.L2) {
564
- res = pack.getInt16(pos, true);
573
+ res = buffer.getInt16(pos, true);
565
574
  pos += 2;
566
575
  }
567
576
  else if (num === -$mol_vary_len.L4) {
568
- res = pack.getInt32(pos, true);
577
+ res = buffer.getInt32(pos, true);
569
578
  pos += 4;
570
579
  }
571
580
  else if (num === -$mol_vary_len.L8) {
572
- res = pack.getBigInt64(pos, true);
581
+ res = buffer.getBigInt64(pos, true);
573
582
  if (res >= Number.MIN_SAFE_INTEGER && res <= Number.MAX_SAFE_INTEGER)
574
583
  res = Number(res);
575
584
  pos += 8;
576
585
  }
577
586
  else if (num === -$mol_vary_len.LA) {
578
- const len = pack.getUint8(pos++) + 9;
579
- res = $mol_bigint_decode(new Uint8Array(pack.buffer, pack.byteOffset + pos, len));
587
+ const len = buffer.getUint8(pos++) + 9;
588
+ res = $mol_bigint_decode(new Uint8Array(buffer.buffer, buffer.byteOffset + pos, len));
580
589
  pos += len;
581
590
  }
582
591
  else {
@@ -587,20 +596,20 @@ var $;
587
596
  };
588
597
  const read_text = (kind) => {
589
598
  const len = read_unum(kind);
590
- const [text, bytes] = $mol_charset_decode_from(buffer, pack.byteOffset + pos, len);
599
+ const [text, bytes] = $mol_charset_decode_from(array, buffer.byteOffset + pos, len);
591
600
  pos += bytes;
592
601
  stream.push(text);
593
602
  return text;
594
603
  };
595
604
  const read_buffer = (len, TypedArray) => {
596
- const bin = new TypedArray(buffer.slice(pos, pos + len).buffer);
605
+ const bin = new TypedArray(array.slice(pos, pos + len).buffer);
597
606
  pos += len;
598
607
  stream.push(bin);
599
608
  return bin;
600
609
  };
601
610
  const read_blob = (kind) => {
602
611
  const len = read_unum(kind);
603
- const kind_item = pack.getUint8(pos++);
612
+ const kind_item = buffer.getUint8(pos++);
604
613
  switch (kind_item) {
605
614
  case $mol_vary_len.L1: return read_buffer(len, Uint8Array);
606
615
  case $mol_vary_len.L2: return read_buffer(len, Uint16Array);
@@ -640,13 +649,8 @@ var $;
640
649
  const node = this.rich_node(keys);
641
650
  let rich = node.get(null);
642
651
  if (!rich)
643
- node.set(null, rich = (...vals) => {
644
- const obj = {};
645
- for (let i = 0; i < len; ++i)
646
- obj[keys[i]] = vals[i];
647
- return obj;
648
- });
649
- const obj = rich(...vals);
652
+ node.set(null, rich = pojo_maker(keys));
653
+ const obj = rich(vals);
650
654
  stream.push(obj);
651
655
  return obj;
652
656
  };
@@ -665,19 +669,19 @@ var $;
665
669
  ++pos;
666
670
  return undefined;
667
671
  case $mol_vary_spec.fp64: {
668
- const val = pack.getFloat64(++pos, true);
672
+ const val = buffer.getFloat64(++pos, true);
669
673
  stream.push(val);
670
674
  pos += 8;
671
675
  return val;
672
676
  }
673
677
  case $mol_vary_spec.fp32: {
674
- const val = pack.getFloat32(++pos, true);
678
+ const val = buffer.getFloat32(++pos, true);
675
679
  stream.push(val);
676
680
  pos += 4;
677
681
  return val;
678
682
  }
679
683
  case $mol_vary_spec.fp16: {
680
- const val = pack.getFloat16(++pos, true);
684
+ const val = buffer.getFloat16(++pos, true);
681
685
  stream.push(val);
682
686
  pos += 2;
683
687
  return val;
@@ -687,7 +691,7 @@ var $;
687
691
  }
688
692
  };
689
693
  const read_vary = () => {
690
- const kind = pack.getUint8(pos);
694
+ const kind = buffer.getUint8(pos);
691
695
  const tip = kind & 0b111_00000;
692
696
  switch (tip) {
693
697
  case $mol_vary_tip.uint: return read_unum(kind);
@@ -702,14 +706,21 @@ var $;
702
706
  }
703
707
  };
704
708
  const result = read_vary();
705
- if (pos !== buffer.byteLength)
706
- $mol_fail(new Error('Buffer too large', { cause: { size: buffer.byteLength, taken: pos, result } }));
709
+ if (pos !== array.byteLength)
710
+ $mol_fail(new Error('Buffer too large', { cause: { size: array.byteLength, taken: pos, result } }));
707
711
  return result;
708
712
  }
709
- static rich_index = new Map([
713
+ rich_index = new Map([
710
714
  [null, () => ({})]
711
715
  ]);
712
- static rich_node(keys) {
716
+ room() {
717
+ const room = new $mol_vary_class;
718
+ Object.setPrototypeOf(room, this);
719
+ const index_clone = (map) => new Map([...map].map(([k, v]) => [k, k === null ? v : index_clone(v)]));
720
+ room.rich_index = index_clone(this.rich_index);
721
+ return room;
722
+ }
723
+ rich_node(keys) {
713
724
  let node = this.rich_index;
714
725
  for (const key of keys) {
715
726
  let sub = node.get(key);
@@ -720,33 +731,72 @@ var $;
720
731
  }
721
732
  return node;
722
733
  }
723
- static type(Class, keys, lean, rich) {
734
+ lean_find(val) {
735
+ const lean = val[this.lean_symbol];
736
+ if (lean)
737
+ return lean;
738
+ const sup = Object.getPrototypeOf(this);
739
+ if (sup === Object.prototype)
740
+ return;
741
+ return sup.lean_find(val);
742
+ }
743
+ type({ type, keys, rich, lean }) {
724
744
  this.rich_node(keys).set(null, rich);
725
- Class.prototype[$.$mol_vary_lean] = (val) => [keys, lean(val)];
745
+ type.prototype[this.lean_symbol] = (val) => [keys, lean(val)];
726
746
  }
727
747
  }
728
- $.$mol_vary = $mol_vary;
729
- $.$mol_vary_lean = Symbol.for('$mol_vary_lean');
730
- $mol_vary.type(Map, ['keys', 'vals'], obj => [[...obj.keys()], [...obj.values()]], (keys, vals) => new Map(keys.map((k, i) => [k, vals[i]])));
731
- $mol_vary.type(Set, ['set'], obj => [[...obj.values()]], vals => new Set(vals));
732
- $mol_vary.type(Date, ['unix_time'], obj => [obj.valueOf() / 1000], ts => new Date(ts * 1000));
733
- $mol_vary.type($mol_dom.Element, ['elem', 'keys', 'vals', 'kids'], node => {
734
- const attrs = [...node.attributes];
735
- const kids = [...node.childNodes].map(kid => kid instanceof $mol_dom.Text ? kid.nodeValue : kid);
736
- return [node.nodeName, attrs.map(attr => attr.nodeName), attrs.map(attr => attr.nodeValue), kids];
737
- }, (name, keys, vals, kids) => {
738
- const el = $mol_dom.document.createElement(name);
739
- for (let i = 0; i < keys.length; ++i)
740
- el.setAttribute(keys[i], vals[i]);
741
- for (let kid of kids) {
742
- if (typeof kid === 'string')
743
- kid = $mol_dom.document.createTextNode(kid);
744
- el.appendChild(kid);
745
- }
746
- return el;
748
+ $.$mol_vary_class = $mol_vary_class;
749
+ $.$mol_vary = new $mol_vary_class;
750
+ $.$mol_vary.type({
751
+ type: Map,
752
+ keys: ['keys', 'vals'],
753
+ lean: obj => [[...obj.keys()], [...obj.values()]],
754
+ rich: ([keys, vals]) => new Map(keys.map((k, i) => [k, vals[i]])),
755
+ });
756
+ $.$mol_vary.type({
757
+ type: Set,
758
+ keys: ['set'],
759
+ lean: obj => [[...obj.values()]],
760
+ rich: ([vals]) => new Set(vals),
761
+ });
762
+ $.$mol_vary.type({
763
+ type: Date,
764
+ keys: ['unix_time'],
765
+ lean: obj => [obj.valueOf() / 1000],
766
+ rich: ([ts]) => new Date(ts * 1000),
767
+ });
768
+ $.$mol_vary.type({
769
+ type: $mol_dom.Element,
770
+ keys: ['elem', 'keys', 'vals', 'kids'],
771
+ lean: node => {
772
+ const attrs = [...node.attributes];
773
+ const kids = [...node.childNodes].map(kid => kid instanceof $mol_dom.Text ? kid.nodeValue : kid);
774
+ return [node.nodeName, attrs.map(attr => attr.nodeName), attrs.map(attr => attr.nodeValue), kids];
775
+ },
776
+ rich: ([name, keys, vals, kids]) => {
777
+ const el = $mol_dom.document.createElement(name);
778
+ for (let i = 0; i < keys.length; ++i)
779
+ el.setAttribute(keys[i], vals[i]);
780
+ for (let kid of kids) {
781
+ if (typeof kid === 'string')
782
+ kid = $mol_dom.document.createTextNode(kid);
783
+ el.appendChild(kid);
784
+ }
785
+ return el;
786
+ },
787
+ });
788
+ $.$mol_vary.type({
789
+ type: $mol_dom.Comment,
790
+ keys: ['#comment'],
791
+ lean: node => [node.nodeValue],
792
+ rich: ([text]) => $mol_dom.document.createComment(text),
793
+ });
794
+ $.$mol_vary.type({
795
+ type: $mol_dom.ProcessingInstruction,
796
+ keys: ['target', 'text'],
797
+ lean: node => [node.nodeName, node.nodeValue],
798
+ rich: ([target, text]) => $mol_dom.document.createProcessingInstruction(target, text),
747
799
  });
748
- $mol_vary.type($mol_dom.Comment, ['#comment'], node => [node.nodeValue], text => $mol_dom.document.createComment(text));
749
- $mol_vary.type($mol_dom.ProcessingInstruction, ['target', 'text'], node => [node.nodeName, node.nodeValue], (target, text) => $mol_dom.document.createProcessingInstruction(target, text));
750
800
  })($ || ($ = {}));
751
801
 
752
802