mol_vary 0.0.40 → 0.0.42

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