@bjornpagen/bumbledb 0.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.
Files changed (108) hide show
  1. package/LICENSE +12 -0
  2. package/README.md +84 -0
  3. package/dist/brand.d.ts +59 -0
  4. package/dist/brand.d.ts.map +1 -0
  5. package/dist/brand.js +47 -0
  6. package/dist/brand.js.map +1 -0
  7. package/dist/closed.d.ts +97 -0
  8. package/dist/closed.d.ts.map +1 -0
  9. package/dist/closed.js +107 -0
  10. package/dist/closed.js.map +1 -0
  11. package/dist/count.d.ts +55 -0
  12. package/dist/count.d.ts.map +1 -0
  13. package/dist/count.js +92 -0
  14. package/dist/count.js.map +1 -0
  15. package/dist/db.d.ts +341 -0
  16. package/dist/db.d.ts.map +1 -0
  17. package/dist/db.js +1016 -0
  18. package/dist/db.js.map +1 -0
  19. package/dist/exhume.d.ts +130 -0
  20. package/dist/exhume.d.ts.map +1 -0
  21. package/dist/exhume.js +145 -0
  22. package/dist/exhume.js.map +1 -0
  23. package/dist/face.d.ts +91 -0
  24. package/dist/face.d.ts.map +1 -0
  25. package/dist/face.js +69 -0
  26. package/dist/face.js.map +1 -0
  27. package/dist/fields.d.ts +187 -0
  28. package/dist/fields.d.ts.map +1 -0
  29. package/dist/fields.js +204 -0
  30. package/dist/fields.js.map +1 -0
  31. package/dist/index.d.ts +49 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +31 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/lower.d.ts +34 -0
  36. package/dist/lower.d.ts.map +1 -0
  37. package/dist/lower.js +105 -0
  38. package/dist/lower.js.map +1 -0
  39. package/dist/marshal.d.ts +79 -0
  40. package/dist/marshal.d.ts.map +1 -0
  41. package/dist/marshal.js +167 -0
  42. package/dist/marshal.js.map +1 -0
  43. package/dist/native.d.ts +532 -0
  44. package/dist/native.d.ts.map +1 -0
  45. package/dist/native.js +64 -0
  46. package/dist/native.js.map +1 -0
  47. package/dist/query/atom.d.ts +285 -0
  48. package/dist/query/atom.d.ts.map +1 -0
  49. package/dist/query/atom.js +281 -0
  50. package/dist/query/atom.js.map +1 -0
  51. package/dist/query/lower.d.ts +145 -0
  52. package/dist/query/lower.d.ts.map +1 -0
  53. package/dist/query/lower.js +604 -0
  54. package/dist/query/lower.js.map +1 -0
  55. package/dist/query/predicate.d.ts +101 -0
  56. package/dist/query/predicate.d.ts.map +1 -0
  57. package/dist/query/predicate.js +85 -0
  58. package/dist/query/predicate.js.map +1 -0
  59. package/dist/query/run.d.ts +30 -0
  60. package/dist/query/run.d.ts.map +1 -0
  61. package/dist/query/run.js +94 -0
  62. package/dist/query/run.js.map +1 -0
  63. package/dist/query/scope.d.ts +168 -0
  64. package/dist/query/scope.d.ts.map +1 -0
  65. package/dist/query/scope.js +134 -0
  66. package/dist/query/scope.js.map +1 -0
  67. package/dist/query/select.d.ts +106 -0
  68. package/dist/query/select.d.ts.map +1 -0
  69. package/dist/query/select.js +69 -0
  70. package/dist/query/select.js.map +1 -0
  71. package/dist/relation.d.ts +120 -0
  72. package/dist/relation.d.ts.map +1 -0
  73. package/dist/relation.js +108 -0
  74. package/dist/relation.js.map +1 -0
  75. package/dist/schema.d.ts +50 -0
  76. package/dist/schema.d.ts.map +1 -0
  77. package/dist/schema.js +235 -0
  78. package/dist/schema.js.map +1 -0
  79. package/dist/spec.d.ts +218 -0
  80. package/dist/spec.d.ts.map +1 -0
  81. package/dist/spec.js +154 -0
  82. package/dist/spec.js.map +1 -0
  83. package/dist/statements.d.ts +91 -0
  84. package/dist/statements.d.ts.map +1 -0
  85. package/dist/statements.js +101 -0
  86. package/dist/statements.js.map +1 -0
  87. package/package.json +66 -0
  88. package/src/brand.ts +82 -0
  89. package/src/closed.ts +228 -0
  90. package/src/count.ts +117 -0
  91. package/src/db.ts +1519 -0
  92. package/src/exhume.ts +243 -0
  93. package/src/face.ts +161 -0
  94. package/src/fields.ts +385 -0
  95. package/src/index.ts +185 -0
  96. package/src/lower.ts +118 -0
  97. package/src/marshal.ts +220 -0
  98. package/src/native.ts +576 -0
  99. package/src/query/atom.ts +556 -0
  100. package/src/query/lower.ts +855 -0
  101. package/src/query/predicate.ts +195 -0
  102. package/src/query/run.ts +106 -0
  103. package/src/query/scope.ts +301 -0
  104. package/src/query/select.ts +140 -0
  105. package/src/relation.ts +252 -0
  106. package/src/schema.ts +297 -0
  107. package/src/spec.ts +325 -0
  108. package/src/statements.ts +148 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lower.js","sourceRoot":"","sources":["../src/lower.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH;;;GAGG;AACH,SAAS,cAAc,CAAC,MAAsB;IAC7C,OAAO,SAAS,IAAI,MAAM,CAAC,IAAI,CAAA;AAChC,CAAC;AAED,4EAA4E;AAC5E,SAAS,SAAS,CAAC,IAAc;IAChC,OAAO;QACN,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI;QACzB,UAAU,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC;QAChC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,YAAY,CAAC,OAAO;YAC1D,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAU,CAAA;QAC7C,CAAC,CAAC;KACF,CAAA;AACF,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,SAAoB;IAC3C,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAA;IAC3B,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,KAAK;YACT,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,CAAA;QACnF,KAAK,aAAa;YACjB,OAAO;gBACN,IAAI,EAAE,aAAa;gBACnB,MAAM,EAAE,SAAS,C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AA;IACF,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,QAAQ,CAAC,GAAG;QAC3D,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CAAA;IAClD,CAAC,CAAC,CAAA;IACF,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAA;AACtE,CAAC;AAED;;;;GAIG;AACH,SAAS,KAAK,CAAC,MAAiB;IAC/B,MAAM,SAAS,GAAmB,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,SAAS,WAAW,CAAC,MAAM;QAChG,IAAI,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5B,OAAO,WAAW,CAAC,MAAM,CAAC,CAAA;QAC3B,CAAC;QACD,OAAO,aAAa,CAAC,MAAM,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;IACF,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,CAAA;AACxE,CAAC;AAED,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,CAAA"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The marshal layer (PRD-07): fact object ⇄ positional `FactValue[]` by
3
+ * field ordinal, schema-directed, in ONE place only. The write side lowers
4
+ * named host objects to rows in the relation's field-declaration order
5
+ * (declaration order = ordinal ids, the macro's law); the read side decodes
6
+ * rows back to named objects with brands applied by assertion — the store
7
+ * is the proof carrier: a row the engine admitted IS a legal fact of its
8
+ * relation, so readback asserts the brand instead of re-judging the value
9
+ * (the same trust direction as Rust's typed readback). Shape mismatches
10
+ * here are genuine failures and THROW typed; they are never domain data.
11
+ */
12
+ import type { FieldData } from "#fields.ts";
13
+ import type { FactValue } from "#native.ts";
14
+ import type { AnyRelation, Fact, FreshKeys, RelationData } from "#relation.ts";
15
+ /**
16
+ * The inferred object type `tx.insert` returns: one property per
17
+ * fresh-marked field of `R`, carrying the minted (or resupplied) branded
18
+ * id. A relation with no fresh field returns the empty object.
19
+ */
20
+ type Minted<R extends AnyRelation> = {
21
+ [K in FreshKeys<R>]: Fact<R>[K];
22
+ };
23
+ /**
24
+ * The key object `get` reads through. THE PRIMARY-KEY RULE: `get` always
25
+ * reads through the PRIMARY candidate key — the first-declared one in the
26
+ * engine's materialized statement order (fresh-implied keys first, closed
27
+ * auto-keys second, declared `key()` statements last), so a fresh-bearing
28
+ * relation's primary key is always its fresh field. When `R` carries a
29
+ * fresh field the type demands exactly that field; otherwise the primary
30
+ * key lives in the schema's statement list, which the type system cannot
31
+ * see (statements are untyped values), so the type admits any partial fact
32
+ * and the projection is verified at runtime — a missing key field throws
33
+ * naming the projection.
34
+ */
35
+ type KeyFact<R extends AnyRelation> = [FreshKeys<R>] extends [never] ? Partial<Fact<R>> : {
36
+ [K in FreshKeys<R>]: Fact<R>[K];
37
+ };
38
+ /**
39
+ * Reprojects any host object to a string-indexed record — the boundary
40
+ * through which generic fact objects (whose type parameters carry no index
41
+ * signature) enter the name-directed marshaling below, without a cast.
42
+ */
43
+ declare function recordOf(fact: object): Record<string, unknown>;
44
+ /**
45
+ * Marshals one host cell at its field position to the natural wire value,
46
+ * schema-directed by the field's structural type (never guessed). Brands
47
+ * are phantoms, so the runtime values are exactly the wire's natural JS
48
+ * values; only widths and domains are left to the engine's own judge.
49
+ */
50
+ declare function cellOf(context: string, field: FieldData, value: unknown): FactValue;
51
+ /**
52
+ * Marshals one complete fact object to its positional row, in field
53
+ * declaration order (= ordinal ids). Every declared field must be present;
54
+ * fresh minting happens BEFORE this point (the transaction fills omitted
55
+ * fresh cells via the engine's alloc lane).
56
+ */
57
+ declare function rowOf(relation: RelationData, fact: Readonly<Record<string, unknown>>): FactValue[];
58
+ /**
59
+ * Marshals a key object through a key statement's projection, in the
60
+ * statement's projection order (what the engine's keyed point reads take).
61
+ * A key field absent from the object throws naming the primary projection
62
+ * (the {@link KeyFact} rule's runtime half).
63
+ */
64
+ declare function keyRowOf(relation: RelationData, projection: readonly string[], key: Readonly<Record<string, unknown>>): FactValue[];
65
+ /**
66
+ * The insert-return trusted seam: the collected fresh cells of one insert
67
+ * (minted by the engine or resupplied by the caller) are the relation's
68
+ * branded fresh ids — same assertion direction as {@link isBrandedFact}.
69
+ */
70
+ declare function isMintedFresh<R extends AnyRelation>(relation: R, minted: Readonly<Record<string, FactValue>>): minted is Readonly<Record<string, FactValue>> & Minted<R>;
71
+ /**
72
+ * Unmarshals one positional row to the relation's named, branded, frozen
73
+ * fact object — the inverse of {@link rowOf}, ordinal-directed by the same
74
+ * declaration order.
75
+ */
76
+ declare function factOf<R extends AnyRelation>(relation: R, row: readonly FactValue[]): Fact<R>;
77
+ export type { KeyFact, Minted };
78
+ export { cellOf, factOf, isMintedFresh, keyRowOf, recordOf, rowOf };
79
+ //# sourceMappingURL=marshal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marshal.d.ts","sourceRoot":"","sources":["../src/marshal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE9E;;;;GAIG;AACH,KAAK,MAAM,CAAC,CAAC,SAAS,WAAW,IAAI;KAAG,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA;AAExE;;;;;;;;;;;GAWG;AACH,KAAK,OAAO,CAAC,CAAC,SAAS,WAAW,IAAI,C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AAED,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAA"}
@@ -0,0 +1,167 @@
1
+ /**
2
+ * The marshal layer (PRD-07): fact object ⇄ positional `FactValue[]` by
3
+ * field ordinal, schema-directed, in ONE place only. The write side lowers
4
+ * named host objects to rows in the relation's field-declaration order
5
+ * (declaration order = ordinal ids, the macro's law); the read side decodes
6
+ * rows back to named objects with brands applied by assertion — the store
7
+ * is the proof carrier: a row the engine admitted IS a legal fact of its
8
+ * relation, so readback asserts the brand instead of re-judging the value
9
+ * (the same trust direction as Rust's typed readback). Shape mismatches
10
+ * here are genuine failures and THROW typed; they are never domain data.
11
+ */
12
+ import * as errors from "@superbuilders/errors";
13
+ /** The typed shape refusal of the row marshaler — a genuine failure, never data. */
14
+ function cellShapeError(context, expected, value) {
15
+ return errors.new(`${context}: expected ${expected}, got ${typeof value}`);
16
+ }
17
+ /** Narrows an interval cell: a plain object with bigint start/end. */
18
+ function isIntervalCell(value) {
19
+ return (typeof value === "object" &&
20
+ value !== null &&
21
+ "start" in value &&
22
+ "end" in value &&
23
+ typeof value.start === "bigint" &&
24
+ typeof value.end === "bigint");
25
+ }
26
+ /**
27
+ * Reprojects any host object to a string-indexed record — the boundary
28
+ * through which generic fact objects (whose type parameters carry no index
29
+ * signature) enter the name-directed marshaling below, without a cast.
30
+ */
31
+ function recordOf(fact) {
32
+ return Object.fromEntries(Object.entries(fact));
33
+ }
34
+ /**
35
+ * Marshals one host cell at its field position to the natural wire value,
36
+ * schema-directed by the field's structural type (never guessed). Brands
37
+ * are phantoms, so the runtime values are exactly the wire's natural JS
38
+ * values; only widths and domains are left to the engine's own judge.
39
+ */
40
+ function cellOf(context, field, value) {
41
+ switch (field.type.kind) {
42
+ case "bool": {
43
+ if (typeof value !== "boolean") {
44
+ throw cellShapeError(context, "boolean", value);
45
+ }
46
+ return value;
47
+ }
48
+ case "u64":
49
+ case "i64": {
50
+ if (typeof value !== "bigint") {
51
+ throw cellShapeError(context, "bigint", value);
52
+ }
53
+ return value;
54
+ }
55
+ case "string": {
56
+ if (typeof value !== "string") {
57
+ throw cellShapeError(context, "string", value);
58
+ }
59
+ /**
60
+ * A lone surrogate would be lossily replaced with U+FFFD at the
61
+ * bridge's UTF-8 crossing — the stored fact would differ from the
62
+ * written one, and distinct JS strings would collapse to one fact.
63
+ * The bijection law refuses it here, the one seam every write and
64
+ * lookup lowers through.
65
+ */
66
+ if (!value.isWellFormed()) {
67
+ throw cellShapeError(context, "well-formed string", value);
68
+ }
69
+ return value;
70
+ }
71
+ case "fixedBytes": {
72
+ if (!(value instanceof Uint8Array)) {
73
+ throw cellShapeError(context, "Uint8Array", value);
74
+ }
75
+ return value;
76
+ }
77
+ case "interval": {
78
+ if (!isIntervalCell(value)) {
79
+ throw cellShapeError(context, "interval ({ start, end } bigints)", value);
80
+ }
81
+ return { start: value.start, end: value.end };
82
+ }
83
+ }
84
+ }
85
+ /**
86
+ * Marshals one complete fact object to its positional row, in field
87
+ * declaration order (= ordinal ids). Every declared field must be present;
88
+ * fresh minting happens BEFORE this point (the transaction fills omitted
89
+ * fresh cells via the engine's alloc lane).
90
+ */
91
+ function rowOf(relation, fact) {
92
+ return relation.fields.map(function marshalCell(declared) {
93
+ const value = fact[declared.name];
94
+ if (value === undefined) {
95
+ throw errors.new(`relation ${relation.name}: fact is missing field ${declared.name}`);
96
+ }
97
+ return cellOf(`relation ${relation.name} field ${declared.name}`, declared.field, value);
98
+ });
99
+ }
100
+ /**
101
+ * Marshals a key object through a key statement's projection, in the
102
+ * statement's projection order (what the engine's keyed point reads take).
103
+ * A key field absent from the object throws naming the primary projection
104
+ * (the {@link KeyFact} rule's runtime half).
105
+ */
106
+ function keyRowOf(relation, projection, key) {
107
+ return projection.map(function marshalKeyCell(fieldName) {
108
+ const declared = relation.fields.find(function byName(candidate) {
109
+ return candidate.name === fieldName;
110
+ });
111
+ if (declared === undefined) {
112
+ throw errors.new(`relation ${relation.name}: key projection cites unknown field ${fieldName}`);
113
+ }
114
+ const value = key[fieldName];
115
+ if (value === undefined) {
116
+ throw errors.new(`relation ${relation.name}: key object is missing field ${fieldName} — get reads through the primary (first-declared) key, whose projection is (${projection.join(", ")})`);
117
+ }
118
+ return cellOf(`relation ${relation.name} key field ${fieldName}`, declared.field, value);
119
+ });
120
+ }
121
+ /**
122
+ * The read-side trusted seam: a decoded row carrying every declared field
123
+ * IS a fact of its relation — the engine admitted it, so the brand is
124
+ * asserted, not re-derived. The checkable half (completeness) is verified;
125
+ * the phantom half (brands) is carried by the store's own judgment.
126
+ */
127
+ function isBrandedFact(relation, decoded) {
128
+ return relation.data.fields.every(function present(declared) {
129
+ return decoded[declared.name] !== undefined;
130
+ });
131
+ }
132
+ /**
133
+ * The insert-return trusted seam: the collected fresh cells of one insert
134
+ * (minted by the engine or resupplied by the caller) are the relation's
135
+ * branded fresh ids — same assertion direction as {@link isBrandedFact}.
136
+ */
137
+ function isMintedFresh(relation, minted) {
138
+ return relation.data.fields.every(function presentWhenFresh(declared) {
139
+ return !declared.field.minted || minted[declared.name] !== undefined;
140
+ });
141
+ }
142
+ /**
143
+ * Unmarshals one positional row to the relation's named, branded, frozen
144
+ * fact object — the inverse of {@link rowOf}, ordinal-directed by the same
145
+ * declaration order.
146
+ */
147
+ function factOf(relation, row) {
148
+ const data = relation.data;
149
+ if (row.length !== data.fields.length) {
150
+ throw errors.new(`relation ${data.name}: row arity ${row.length} does not match the ${data.fields.length} declared fields`);
151
+ }
152
+ const decoded = {};
153
+ data.fields.forEach(function decodeCell(declared, ordinal) {
154
+ const cell = row[ordinal];
155
+ if (cell === undefined) {
156
+ throw errors.new(`relation ${data.name}: row cell ${ordinal} (${declared.name}) is absent`);
157
+ }
158
+ decoded[declared.name] = cell;
159
+ });
160
+ Object.freeze(decoded);
161
+ if (!isBrandedFact(relation, decoded)) {
162
+ throw errors.new(`relation ${data.name}: decoded row is not a complete fact`);
163
+ }
164
+ return decoded;
165
+ }
166
+ export { cellOf, factOf, isMintedFresh, keyRowOf, recordOf, rowOf };
167
+ //# sourceMappingURL=marshal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marshal.js","sourceRoot":"","sources":["../src/marshal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAA;AA4B/C,oFAAoF;AACpF,SAAS,cAAc,CAAC,OAAe,EAAE,QAAgB,EAAE,KAAc;IACxE,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,cAAc,QAAQ,SAAS,OAAO,KAAK,EAAE,CAAC,CAAA;AAC3E,CAAC;AAED,sEAAsE;AACtE,SAAS,cAAc,CAAC,KAAc;IACrC,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,IAAI,KAAK;QAChB,KAAK,IAAI,KAAK;QACd,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ;QAC/B,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ,CAC7B,CAAA;AACF,CAAC;AAED;;;;GAIG;AACH,SAAS,QAAQ,CAAC,IAAY;IAC7B,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA;AAChD,CAAC;AAED;;;;;GAKG;AACH,SAAS,MAAM,CAAC,OAAe,EAAE,KAAgB,EAAE,KAAc;IAChE,QAAQ,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACzB,KAAK,MAAM,EAAE,CAAC;YACb,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;gBAChC,MAAM,cAAc,CAAC,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;YAChD,CAAC;YACD,OAAO,KAAK,CAAA;QACb,CAAC;QACD,KAAK,KAAK,CAAC;QACX,KAAK,KAAK,EA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