@sovereignbase/sequencer 1.0.2 → 1.1.0

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/dist/index.d.cts CHANGED
@@ -33,7 +33,7 @@ type Acknowledgement = U32List;
33
33
  type Gossip<T> = ReadonlyArray<Acknowledgement | Insertion<T>>;
34
34
  /**
35
35
  * Retained state required to hydrate the same visible Projection.
36
- * One structural array and one JavaScript-owned content array.
36
+ * One structural array and JavaScript-owned Footage.
37
37
  * Small snapshots use six-word insertion records after length-prefixed ACKs;
38
38
  * `words[0]` locates those records. Large snapshots begin with
39
39
  * `[0, frontiersEnd, insertionCount]` and omit predictable coordinate fields.
@@ -41,13 +41,16 @@ type Gossip<T> = ReadonlyArray<Acknowledgement | Insertion<T>>;
41
41
  * Eligible masks, deleted Footage and compacted Session claims are omitted;
42
42
  * Actor membership remains. Compaction may translate retained coordinates.
43
43
  * Positive insertion diffs consume successive spans of `footage`.
44
+ * String-encoded Footage preserves Insertion order, not visible text order.
45
+ * It uses one UTF-16 code unit per Frame. Missing slots use
46
+ * NUL (`\u0000`); hydration splits the string with `split('')`.
44
47
  * `[[], []]` is an empty Sequence. Both numeric arrays and typed views are accepted.
45
48
  */
46
- type Sequence<T> = Readonly<[
49
+ type Sequence<T, StringEncoded extends boolean = false> = Readonly<[
47
50
  /** Acknowledgements followed by canonical Insertions in Structural Order. */
48
51
  words: U32List,
49
52
  /** Consecutive positive Insertion spans, including missing Footage slots. */
50
- footage: ReadonlyArray<T | undefined>]>;
53
+ footage: StringEncoded extends true ? string : ReadonlyArray<T | undefined>]>;
51
54
  /** Visible mutation: insertion uses `[at, at, values]`; removal ends exclusively. */
52
55
  type Splice<T> = Readonly<[
53
56
  /** First affected position in the Projection after preceding Splices. */
@@ -63,7 +66,7 @@ type Result<T> = Readonly<[change: Change<T>, gossip?: Gossip<T>]>;
63
66
  //#endregion
64
67
  //#region src/typescript/errors/class.d.ts
65
68
  /** Semantic error codes reported by the Sequencer public API. */
66
- type SequencerErrorCode = 'PROJECTION_DESTROYED' | 'NATIVE_OPERATION_FAILED';
69
+ type SequencerErrorCode = 'PROJECTION_DESTROYED' | 'NATIVE_OPERATION_FAILED' | 'STRING_ENCODING_FAILED';
67
70
  /** Error reported by Sequencer with a stable code and package-prefixed message. */
68
71
  export declare class SequencerError extends Error {
69
72
  /** Machine-readable code identifying the failure condition. */
@@ -88,7 +91,7 @@ export declare class Projection<T> {
88
91
  * Prepares to sequence a projection, optionally hydrating from a trusted sequence stored by the application.
89
92
  *
90
93
  * @param actorID Actor identifier used in acknowledgements.
91
- * @param trustedSequence Optional trusted Sequence in Structural Order, stored by the application.
94
+ * @param trustedSequence Optional trusted Sequence in Structural Order; string Footage is split into UTF-16 code units.
92
95
  * @throws {@link SequencerError} if native initialization fails.
93
96
  */
94
97
  constructor(actorID: number, trustedSequence?: unknown);
@@ -164,10 +167,12 @@ export declare class Projection<T> {
164
167
  * permit masks and deleted Footage to be omitted from the retained checkpoint.
165
168
  * Compaction may translate retained anchors without rewriting this instance.
166
169
  *
170
+ * @param stringEncode Whether to concatenate Footage into a string; each text Frame must be one UTF-16 code unit. Defaults to `false`.
167
171
  * @returns A Sequence with acknowledged removals compacted in the exported state.
168
172
  * @throws {@link SequencerError} if destroyed or the native runtime reports an operation failure.
173
+ * @throws {@link SequencerError} with code `STRING_ENCODING_FAILED` if Footage concatenation fails.
169
174
  */
170
- sequence(): Sequence<T>;
175
+ sequence<StringEncoded extends boolean = false>(stringEncode?: StringEncoded): Sequence<T, StringEncoded>;
171
176
  /**
172
177
  * Returns the value at a Projection position.
173
178
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/typescript/types/type.ts","../src/typescript/errors/class.ts","../src/typescript/class.ts"],"mappings":";;;KACY,UAAU,cAAc;;;;;;;;;KAUxB,iBAAiB;;;;;;KAOjB,UAAU,KAAK;;AAGvB,OAAO;;AAEP,UAAU,cAAc;;;;;;;;KAWhB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OAAO;;KAEjC,OAAO,KAAK,UAAU,QAAQ,OAAO,IAAI,SAAS,OAAO;;;;KC7EzD;;qBAIC,uBAAuB;;WAEzB,MAAM;;;;;;;;EAUb,YAAA,MAAM,oBACN,kBACA,UAAU;;;;;qBCdD,WAAW;WAYJ;;UAVV;;;;;;;;EAUU,YAAA,iBAChB;;;;;;;;;EAaF,MAAM,kBAAkB,OAAO;;;;;;;;;EAY/B,OAAO,QAAQ,MAAM,IAAI,aAAa,OAAO;;;;;;;EAU7C;;;;;;;;;EAYA,MAAM,oBAAoB,OAAO;;;;;;;;;EAYjC,OAAO,kBAAkB,mBAAmB,OAAO;;;;;;;;;;EAanD,QAAQ,YAAY,MAAM,IAAI,kBAAkB,mBAAmB,OAAO;;;;;;;;;;;EAoB1E,OAAO;;;;;;;;;;;;;;EAiBP,SAAS,uCACP,eAAe,gBACd,SAAS,GAAG;;;;;;;;EAWf,MAAM,aAAa;;;;;;;;;EAYnB,OAAO,kBAAkB,mBAAmB,MAAM;;EAKlD"}
package/dist/index.d.ts CHANGED
@@ -33,7 +33,7 @@ type Acknowledgement = U32List;
33
33
  type Gossip<T> = ReadonlyArray<Acknowledgement | Insertion<T>>;
34
34
  /**
35
35
  * Retained state required to hydrate the same visible Projection.
36
- * One structural array and one JavaScript-owned content array.
36
+ * One structural array and JavaScript-owned Footage.
37
37
  * Small snapshots use six-word insertion records after length-prefixed ACKs;
38
38
  * `words[0]` locates those records. Large snapshots begin with
39
39
  * `[0, frontiersEnd, insertionCount]` and omit predictable coordinate fields.
@@ -41,13 +41,16 @@ type Gossip<T> = ReadonlyArray<Acknowledgement | Insertion<T>>;
41
41
  * Eligible masks, deleted Footage and compacted Session claims are omitted;
42
42
  * Actor membership remains. Compaction may translate retained coordinates.
43
43
  * Positive insertion diffs consume successive spans of `footage`.
44
+ * String-encoded Footage preserves Insertion order, not visible text order.
45
+ * It uses one UTF-16 code unit per Frame. Missing slots use
46
+ * NUL (`\u0000`); hydration splits the string with `split('')`.
44
47
  * `[[], []]` is an empty Sequence. Both numeric arrays and typed views are accepted.
45
48
  */
46
- type Sequence<T> = Readonly<[
49
+ type Sequence<T, StringEncoded extends boolean = false> = Readonly<[
47
50
  /** Acknowledgements followed by canonical Insertions in Structural Order. */
48
51
  words: U32List,
49
52
  /** Consecutive positive Insertion spans, including missing Footage slots. */
50
- footage: ReadonlyArray<T | undefined>]>;
53
+ footage: StringEncoded extends true ? string : ReadonlyArray<T | undefined>]>;
51
54
  /** Visible mutation: insertion uses `[at, at, values]`; removal ends exclusively. */
52
55
  type Splice<T> = Readonly<[
53
56
  /** First affected position in the Projection after preceding Splices. */
@@ -63,7 +66,7 @@ type Result<T> = Readonly<[change: Change<T>, gossip?: Gossip<T>]>;
63
66
  //#endregion
64
67
  //#region src/typescript/errors/class.d.ts
65
68
  /** Semantic error codes reported by the Sequencer public API. */
66
- type SequencerErrorCode = 'PROJECTION_DESTROYED' | 'NATIVE_OPERATION_FAILED';
69
+ type SequencerErrorCode = 'PROJECTION_DESTROYED' | 'NATIVE_OPERATION_FAILED' | 'STRING_ENCODING_FAILED';
67
70
  /** Error reported by Sequencer with a stable code and package-prefixed message. */
68
71
  export declare class SequencerError extends Error {
69
72
  /** Machine-readable code identifying the failure condition. */
@@ -88,7 +91,7 @@ export declare class Projection<T> {
88
91
  * Prepares to sequence a projection, optionally hydrating from a trusted sequence stored by the application.
89
92
  *
90
93
  * @param actorID Actor identifier used in acknowledgements.
91
- * @param trustedSequence Optional trusted Sequence in Structural Order, stored by the application.
94
+ * @param trustedSequence Optional trusted Sequence in Structural Order; string Footage is split into UTF-16 code units.
92
95
  * @throws {@link SequencerError} if native initialization fails.
93
96
  */
94
97
  constructor(actorID: number, trustedSequence?: unknown);
@@ -164,10 +167,12 @@ export declare class Projection<T> {
164
167
  * permit masks and deleted Footage to be omitted from the retained checkpoint.
165
168
  * Compaction may translate retained anchors without rewriting this instance.
166
169
  *
170
+ * @param stringEncode Whether to concatenate Footage into a string; each text Frame must be one UTF-16 code unit. Defaults to `false`.
167
171
  * @returns A Sequence with acknowledged removals compacted in the exported state.
168
172
  * @throws {@link SequencerError} if destroyed or the native runtime reports an operation failure.
173
+ * @throws {@link SequencerError} with code `STRING_ENCODING_FAILED` if Footage concatenation fails.
169
174
  */
170
- sequence(): Sequence<T>;
175
+ sequence<StringEncoded extends boolean = false>(stringEncode?: StringEncoded): Sequence<T, StringEncoded>;
171
176
  /**
172
177
  * Returns the value at a Projection position.
173
178
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/typescript/types/type.ts","../src/typescript/errors/class.ts","../src/typescript/class.ts"],"mappings":";;;KACY,UAAU,cAAc;;;;;;;;;KAUxB,iBAAiB;;;;;;KAOjB,UAAU,KAAK;;AAGvB,OAAO;;AAEP,UAAU,cAAc;;;;;;;;KAWhB,kBAAkB;;KAGlB,OAAO,KAAK,cAAc,kBAAkB,UAAU;;;;;;;;;;;;;KActD,SAAS,KAAK;;AAGtB,OAAO;;AAEP,SAAS,cAAc;;KAKf,OAAO,KAAK;;AAGpB;;AAEA;;AAEA,SAAS,cAAc;;KAKf,OAAO,KAAK,cAAc,OAAO;;KAEjC,OAAO,KAAK,UAAU,QAAQ,OAAO,IAAI,SAAS,OAAO;;;;KC1EzD;;qBAIC,uBAAuB;;WAEzB,MAAM;;;;;;;;EAUb,YAAA,MAAM,oBACN,kBACA,UAAU;;;;;qBCdD,WAAW;WAYJ;;UAVV;;;;;;;;EAUU,YAAA,iBAChB;;;;;;;;;EAaF,MAAM,kBAAkB,OAAO;;;;;;;;;EAY/B,OAAO,QAAQ,MAAM,IAAI,aAAa,OAAO;;;;;;;EAU7C;;;;;;;;;EAYA,MAAM,oBAAoB,OAAO;;;;;;;;;EAYjC,OAAO,kBAAkB,mBAAmB,OAAO;;;;;;;;;;EAanD,QAAQ,YAAY,MAAM,IAAI,kBAAkB,mBAAmB,OAAO;;;;;;;;;;;EAoB1E,OAAO;;;;;;;;;;;;EAeP,YAAY,SAAS;;;;;;;;EAWrB,MAAM,aAAa;;;;;;;;;EAYnB,OAAO,kBAAkB,mBAAmB,MAAM;;EAKlD"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/typescript/types/type.ts","../src/typescript/errors/class.ts","../src/typescript/class.ts"],"mappings":";;;KACY,UAAU,cAAc;;;;;;;;;KAUxB,iBAAiB;;;;;;KAOjB,UAAU,KAAK;;AAGvB,OAAO;;AAEP,UAAU,cAAc;;;;;;;;KAWhB,kBAAkB;;KAGlB,OAAO,KAAK,cAAc,kBAAkB,UAAU;;;;;;;;;;;;;;;;KAiBtD,SAAS,GAAG,yCAAyC;;AAG7D,OAAO;;AAEP,SAAS,sCAAsC,cAAc;;KAKrD,OAAO,KAAK;;AAGpB;;AAEA;;AAEA,SAAS,cAAc;;KAKf,OAAO,KAAK,cAAc,OAAO;;KAEjC,OAAO,KAAK,UAAU,QAAQ,OAAO,IAAI,SAAS,OAAO;;;;KC7EzD;;qBAIC,uBAAuB;;WAEzB,MAAM;;;;;;;;EAUb,YAAA,MAAM,oBACN,kBACA,UAAU;;;;;qBCdD,WAAW;WAYJ;;UAVV;;;;;;;;EAUU,YAAA,iBAChB;;;;;;;;;EAaF,MAAM,kBAAkB,OAAO;;;;;;;;;EAY/B,OAAO,QAAQ,MAAM,IAAI,aAAa,OAAO;;;;;;;EAU7C;;;;;;;;;EAYA,MAAM,oBAAoB,OAAO;;;;;;;;;EAYjC,OAAO,kBAAkB,mBAAmB,OAAO;;;;;;;;;;EAanD,QAAQ,YAAY,MAAM,IAAI,kBAAkB,mBAAmB,OAAO;;;;;;;;;;;EAoB1E,OAAO;;;;;;;;;;;;;;EAiBP,SAAS,uCACP,eAAe,gBACd,SAAS,GAAG;;;;;;;;EAWf,MAAM,aAAa;;;;;;;;;EAYnB,OAAO,kBAAkB,mBAAmB,MAAM;;EAKlD"}
package/dist/index.js CHANGED
@@ -332,6 +332,11 @@ var Runtime = class {
332
332
  const heap = module.HEAPU32;
333
333
  return this.content[id][heap[pointer]]?.[heap[pointer + 1]];
334
334
  }
335
+ /** Exports native spans directly, with optional string Footage assembled in JavaScript. */
336
+ sequence(id, stringEncode) {
337
+ if (id < 0) throw new SequencerError("PROJECTION_DESTROYED", "Projection has been destroyed.");
338
+ return this.result(Operation.Sequence, id, module._runtime_dispatch(Operation.Sequence, id, 0, 0, 0, 0, 0), stringEncode);
339
+ }
335
340
  /** Authors trusted local Frames through the dedicated six-word result path. */
336
341
  insert(id, values, at) {
337
342
  if (id < 0) throw new SequencerError("PROJECTION_DESTROYED", "Projection has been destroyed.");
@@ -449,16 +454,16 @@ var Runtime = class {
449
454
  a0 = value ?? absent;
450
455
  a1 = at ?? absent;
451
456
  } else if (operation === Operation.Retire) a0 = value;
452
- else if (operation === Operation.Create || operation === Operation.Merge) {
457
+ else {
453
458
  a0 = operation === Operation.Create ? value : 0;
454
459
  const sequence = operation === Operation.Create ? at : value;
455
- const valid = operation === Operation.Create && sequence === void 0 || Array.isArray(sequence) && sequence.length === 2 && (Array.isArray(sequence[0]) || sequence[0] instanceof Uint32Array) && Array.isArray(sequence[1]) && (operation === Operation.Create || sequence[0] instanceof Uint32Array || sequence[0].every((word) => Number.isInteger(word) && word >= 0 && word <= absent));
460
+ const valid = operation === Operation.Create && sequence === void 0 || Array.isArray(sequence) && sequence.length === 2 && (Array.isArray(sequence[0]) || sequence[0] instanceof Uint32Array) && (Array.isArray(sequence[1]) || typeof sequence[1] === "string") && (operation === Operation.Create || sequence[0] instanceof Uint32Array || sequence[0].every((word) => Number.isInteger(word) && word >= 0 && word <= absent));
456
461
  a2 = valid ? 1 : 0;
457
462
  if (valid && sequence !== void 0) {
458
463
  const words = sequence[0];
459
464
  heap.set(words, base);
460
465
  a1 = contents.length;
461
- footage = sequence[1];
466
+ footage = typeof sequence[1] === "string" ? sequence[1].split("") : sequence[1];
462
467
  }
463
468
  }
464
469
  const resultPointer = module._runtime_dispatch(operation, id, a0, a1, a2, pointer, count);
@@ -472,7 +477,7 @@ var Runtime = class {
472
477
  return this.result(operation, id, resultPointer);
473
478
  }
474
479
  /** Consumes borrowed native output before another call may overwrite its storage. */
475
- result(operation, id, pointer) {
480
+ result(operation, id, pointer, stringEncode) {
476
481
  const heap = module.HEAPU32, header = pointer >>> 2, content = this.content[id];
477
482
  const kind = heap[header], p0 = heap[header + 3], n0 = heap[header + 4], p1 = heap[header + 5], n1 = heap[header + 6];
478
483
  const mutable = this.mutable[id];
@@ -589,6 +594,22 @@ var Runtime = class {
589
594
  metadata.length = n0;
590
595
  for (let i = 0, at = p0 >>> 2; i < n0; ++i) metadata[i] = heap[at + i];
591
596
  } else metadata = words(p0, n0);
597
+ if (stringEncode) {
598
+ let text = "";
599
+ try {
600
+ for (let at = p1 >>> 2, end = at + n1 * 3; at < end; at += 3) {
601
+ const source = content[heap[at]], start = heap[at + 1], count = heap[at + 2];
602
+ for (let i = 0; i < count; ++i) {
603
+ const value = source?.[start + i];
604
+ text += value === void 0 ? "\0" : value;
605
+ }
606
+ }
607
+ } catch (cause) {
608
+ throw new SequencerError("STRING_ENCODING_FAILED", "Sequence Footage could not be encoded as a string.", { cause });
609
+ }
610
+ result = [metadata, text];
611
+ break;
612
+ }
592
613
  const span = p1 >>> 2, token = heap[span];
593
614
  const shared = n1 === 1 && heap[span + 1] === 0 && content[token]?.length === heap[span + 2] && !!mutable[token];
594
615
  if (shared && mutable[token] !== 3) {
@@ -657,7 +678,7 @@ var Projection = class {
657
678
  * Prepares to sequence a projection, optionally hydrating from a trusted sequence stored by the application.
658
679
  *
659
680
  * @param actorID Actor identifier used in acknowledgements.
660
- * @param trustedSequence Optional trusted Sequence in Structural Order, stored by the application.
681
+ * @param trustedSequence Optional trusted Sequence in Structural Order; string Footage is split into UTF-16 code units.
661
682
  * @throws {@link SequencerError} if native initialization fails.
662
683
  */
663
684
  constructor(actorID, trustedSequence) {
@@ -750,11 +771,13 @@ var Projection = class {
750
771
  * permit masks and deleted Footage to be omitted from the retained checkpoint.
751
772
  * Compaction may translate retained anchors without rewriting this instance.
752
773
  *
774
+ * @param stringEncode Whether to concatenate Footage into a string; each text Frame must be one UTF-16 code unit. Defaults to `false`.
753
775
  * @returns A Sequence with acknowledged removals compacted in the exported state.
754
776
  * @throws {@link SequencerError} if destroyed or the native runtime reports an operation failure.
777
+ * @throws {@link SequencerError} with code `STRING_ENCODING_FAILED` if Footage concatenation fails.
755
778
  */
756
- sequence() {
757
- return runtime.call(Operation.Sequence, this.id);
779
+ sequence(stringEncode) {
780
+ return runtime.sequence(this.id, stringEncode);
758
781
  }
759
782
  /**
760
783
  * Returns the value at a Projection position.