web3ql-client 1.2.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 (86) hide show
  1. package/README.md +66 -0
  2. package/contracts/PublicKeyRegistry.sol +87 -0
  3. package/dist/src/access.d.ts +176 -0
  4. package/dist/src/access.d.ts.map +1 -0
  5. package/dist/src/access.js +283 -0
  6. package/dist/src/access.js.map +1 -0
  7. package/dist/src/batch.d.ts +107 -0
  8. package/dist/src/batch.d.ts.map +1 -0
  9. package/dist/src/batch.js +188 -0
  10. package/dist/src/batch.js.map +1 -0
  11. package/dist/src/cli.d.ts +40 -0
  12. package/dist/src/cli.d.ts.map +1 -0
  13. package/dist/src/cli.js +361 -0
  14. package/dist/src/cli.js.map +1 -0
  15. package/dist/src/constraints.d.ts +126 -0
  16. package/dist/src/constraints.d.ts.map +1 -0
  17. package/dist/src/constraints.js +192 -0
  18. package/dist/src/constraints.js.map +1 -0
  19. package/dist/src/crypto.d.ts +118 -0
  20. package/dist/src/crypto.d.ts.map +1 -0
  21. package/dist/src/crypto.js +192 -0
  22. package/dist/src/crypto.js.map +1 -0
  23. package/dist/src/factory-client.d.ts +106 -0
  24. package/dist/src/factory-client.d.ts.map +1 -0
  25. package/dist/src/factory-client.js +202 -0
  26. package/dist/src/factory-client.js.map +1 -0
  27. package/dist/src/index-cache.d.ts +156 -0
  28. package/dist/src/index-cache.d.ts.map +1 -0
  29. package/dist/src/index-cache.js +265 -0
  30. package/dist/src/index-cache.js.map +1 -0
  31. package/dist/src/index.d.ts +60 -0
  32. package/dist/src/index.d.ts.map +1 -0
  33. package/dist/src/index.js +60 -0
  34. package/dist/src/index.js.map +1 -0
  35. package/dist/src/migrations.d.ts +114 -0
  36. package/dist/src/migrations.d.ts.map +1 -0
  37. package/dist/src/migrations.js +173 -0
  38. package/dist/src/migrations.js.map +1 -0
  39. package/dist/src/model.d.ts +198 -0
  40. package/dist/src/model.d.ts.map +1 -0
  41. package/dist/src/model.js +379 -0
  42. package/dist/src/model.js.map +1 -0
  43. package/dist/src/query.d.ts +155 -0
  44. package/dist/src/query.d.ts.map +1 -0
  45. package/dist/src/query.js +386 -0
  46. package/dist/src/query.js.map +1 -0
  47. package/dist/src/registry.d.ts +45 -0
  48. package/dist/src/registry.d.ts.map +1 -0
  49. package/dist/src/registry.js +80 -0
  50. package/dist/src/registry.js.map +1 -0
  51. package/dist/src/schema-manager.d.ts +109 -0
  52. package/dist/src/schema-manager.d.ts.map +1 -0
  53. package/dist/src/schema-manager.js +259 -0
  54. package/dist/src/schema-manager.js.map +1 -0
  55. package/dist/src/table-client.d.ts +156 -0
  56. package/dist/src/table-client.d.ts.map +1 -0
  57. package/dist/src/table-client.js +292 -0
  58. package/dist/src/table-client.js.map +1 -0
  59. package/dist/src/typed-table.d.ts +159 -0
  60. package/dist/src/typed-table.d.ts.map +1 -0
  61. package/dist/src/typed-table.js +246 -0
  62. package/dist/src/typed-table.js.map +1 -0
  63. package/dist/src/types.d.ts +48 -0
  64. package/dist/src/types.d.ts.map +1 -0
  65. package/dist/src/types.js +222 -0
  66. package/dist/src/types.js.map +1 -0
  67. package/keyManager.js +337 -0
  68. package/package.json +38 -0
  69. package/src/access.ts +421 -0
  70. package/src/batch.ts +259 -0
  71. package/src/cli.ts +349 -0
  72. package/src/constraints.ts +283 -0
  73. package/src/crypto.ts +239 -0
  74. package/src/factory-client.ts +237 -0
  75. package/src/index-cache.ts +351 -0
  76. package/src/index.ts +171 -0
  77. package/src/migrations.ts +215 -0
  78. package/src/model.ts +538 -0
  79. package/src/query.ts +508 -0
  80. package/src/registry.ts +100 -0
  81. package/src/schema-manager.ts +301 -0
  82. package/src/table-client.ts +393 -0
  83. package/src/typed-table.ts +340 -0
  84. package/src/types.ts +284 -0
  85. package/tsconfig.json +22 -0
  86. package/walletUtils.js +204 -0
@@ -0,0 +1,246 @@
1
+ /**
2
+ * @file typed-table.ts
3
+ * @notice High-level Prisma-style API for Web3QL encrypted tables.
4
+ *
5
+ * v1.1 upgrades:
6
+ * • Optional SchemaDefinition support — auto validates, encodes, and decodes
7
+ * fields using the extended type system (TIMESTAMP, UUID, ENUM, DECIMAL, etc.)
8
+ * • NOT NULL + DEFAULT enforcement on write
9
+ * • findMany with full query builder support: where/orderBy/limit/select/distinct
10
+ * • findAll — convenience method (fetches + decrypts all records in batches)
11
+ * • aggregate — COUNT/SUM/AVG/MIN/MAX over filtered decrypted records
12
+ * • seed — bulk insert an array of records
13
+ *
14
+ * Usage (basic, schema-less — identical to v1.0):
15
+ * ─────────────────────────────────────────────────────────────
16
+ * const users = new TypedTableClient<User>('users', db.table('0xTABLE'))
17
+ * await users.create(1n, { id: 1n, name: 'Alice' })
18
+ * const alice = await users.findUnique(1n)
19
+ *
20
+ * Usage (with schema for validation + type coercion):
21
+ * ─────────────────────────────────────────────────────────────
22
+ * const schema: SchemaDefinition = [
23
+ * { name: 'id', type: 'INT', primaryKey: true },
24
+ * { name: 'name', type: 'TEXT', notNull: true },
25
+ * { name: 'email', type: 'TEXT', notNull: true },
26
+ * { name: 'createdAt', type: 'TIMESTAMP', default: () => new Date() },
27
+ * { name: 'role', type: 'ENUM', enumValues: ['user','admin'], default: 'user' },
28
+ * ]
29
+ * const users = new TypedTableClient<User>('users', db.table('0xADDR'), schema)
30
+ *
31
+ * // findMany with query builder
32
+ * const admins = await users.findMany(ownerAddr, {
33
+ * where: [['role', 'eq', 'admin']],
34
+ * orderBy: [['createdAt', 'desc']],
35
+ * limit: 20,
36
+ * select: ['id', 'name', 'email'],
37
+ * })
38
+ * ─────────────────────────────────────────────────────────────
39
+ */
40
+ import { validateAndEncode, decodeRow, } from './types.js';
41
+ import { query as buildQuery, } from './query.js';
42
+ // ─────────────────────────────────────────────────────────────
43
+ // TypedTableClient
44
+ // ─────────────────────────────────────────────────────────────
45
+ export class TypedTableClient {
46
+ tableName;
47
+ inner;
48
+ schema;
49
+ /**
50
+ * @param tableName Must match the name used in the SQL schema and createTable().
51
+ * @param inner An EncryptedTableClient from DatabaseClient.table(address).
52
+ * @param schema Optional field descriptors — enables validation, type coercion,
53
+ * NOT NULL enforcement, and DEFAULT values.
54
+ */
55
+ constructor(tableName, inner, schema) {
56
+ this.tableName = tableName;
57
+ this.inner = inner;
58
+ this.schema = schema;
59
+ }
60
+ // ── Key helper ─────────────────────────────────────────────
61
+ /** Derive the canonical bytes32 on-chain key for a given primary key id. */
62
+ key(id) {
63
+ return this.inner.deriveKey(this.tableName, id);
64
+ }
65
+ // ── Internal encode/decode ──────────────────────────────────
66
+ encode(data) {
67
+ if (this.schema) {
68
+ const wire = validateAndEncode(this.schema, data);
69
+ return JSON.stringify(wire);
70
+ }
71
+ return JSON.stringify(data);
72
+ }
73
+ decode(plaintext) {
74
+ const parsed = JSON.parse(plaintext);
75
+ if (this.schema)
76
+ return decodeRow(this.schema, parsed);
77
+ return parsed;
78
+ }
79
+ // ── Write ───────────────────────────────────────────────────
80
+ /**
81
+ * Validate, encode, encrypt, and store a new record.
82
+ * Throws if a non-deleted record with the same id already exists.
83
+ */
84
+ async create(id, data) {
85
+ return this.inner.writeRaw(this.key(id), this.encode(data));
86
+ }
87
+ /**
88
+ * Bulk-insert an array of records. Each record must include the primary key field.
89
+ * Records are written sequentially — fails on first error.
90
+ */
91
+ async seed(rows) {
92
+ const receipts = [];
93
+ for (const row of rows) {
94
+ receipts.push(await this.create(row.id, row.data));
95
+ }
96
+ return receipts;
97
+ }
98
+ // ── Read ────────────────────────────────────────────────────
99
+ /**
100
+ * Read and decrypt a single record by primary key.
101
+ * Returns `null` if the record does not exist or has been deleted.
102
+ */
103
+ async findUnique(id) {
104
+ try {
105
+ const exists = await this.inner.exists(this.key(id));
106
+ if (!exists)
107
+ return null;
108
+ const plaintext = await this.inner.readPlaintext(this.key(id));
109
+ return this.decode(plaintext);
110
+ }
111
+ catch (err) {
112
+ const msg = err.message ?? '';
113
+ if (msg.includes('deleted') || msg.includes('not found') || msg.includes('RecordMeta')) {
114
+ return null;
115
+ }
116
+ throw err;
117
+ }
118
+ }
119
+ /**
120
+ * List and decrypt all records owned by `ownerAddress`, with optional
121
+ * client-side filtering, sorting, pagination, and projection.
122
+ *
123
+ * ⚠ Records are decrypted client-side. Use `chainLimit` to constrain
124
+ * chain reads on large tables. For production scale, use the relay-
125
+ * maintained index endpoint (v1.2) instead.
126
+ */
127
+ async findMany(ownerAddress, options = {}) {
128
+ const chainOffset = options.chainOffset ?? 0n;
129
+ const chainLimit = options.chainLimit ?? 200n;
130
+ const keys = await this.inner.listOwnerRecords(ownerAddress, chainOffset, chainLimit);
131
+ const raw = [];
132
+ // Decrypt in parallel (capped at 20 concurrent RPCs)
133
+ const BATCH = 20;
134
+ for (let i = 0; i < keys.length; i += BATCH) {
135
+ const batch = keys.slice(i, i + BATCH);
136
+ const settled = await Promise.allSettled(batch.map(async (recordKey) => {
137
+ const plaintext = await this.inner.readPlaintext(recordKey);
138
+ return { id: 0n, data: this.decode(plaintext), recordKey };
139
+ }));
140
+ for (const r of settled) {
141
+ if (r.status === 'fulfilled')
142
+ raw.push(r.value);
143
+ // silently skip inaccessible / deleted records
144
+ }
145
+ }
146
+ // Build query
147
+ let q = buildQuery(raw.map((r) => r.data));
148
+ if (options.where) {
149
+ for (const clause of options.where) {
150
+ if (clause[1] === 'isNull' || clause[1] === 'isNotNull') {
151
+ q = q.where(clause[0], clause[1]);
152
+ }
153
+ else if (clause[1] === 'in' || clause[1] === 'notIn') {
154
+ q = q.where(clause[0], clause[1], clause[2]);
155
+ }
156
+ else if (clause[1] === 'between') {
157
+ q = q.where(clause[0], clause[1], clause[2]);
158
+ }
159
+ else {
160
+ q = q.where(clause[0], clause[1], clause[2]);
161
+ }
162
+ }
163
+ }
164
+ if (options.orderBy) {
165
+ for (const [field, dir] of options.orderBy)
166
+ q = q.orderBy(field, dir ?? 'asc');
167
+ }
168
+ if (options.limit != null)
169
+ q = q.limit(options.limit);
170
+ if (options.offset != null)
171
+ q = q.offset(options.offset);
172
+ if (options.select)
173
+ q = q.select(options.select);
174
+ if (options.distinct)
175
+ q = q.distinct(options.distinct);
176
+ const filteredData = q.execute();
177
+ // Remap back to RecordWithId — match by index since we decrypted in order
178
+ return filteredData.map((data, idx) => ({
179
+ id: 0n,
180
+ data,
181
+ recordKey: raw[idx]?.recordKey ?? '',
182
+ }));
183
+ }
184
+ /**
185
+ * Convenience: fetch and decrypt ALL records the wallet owns (no chain limit).
186
+ * Useful for small tables or full exports. Decrypts in parallel batches of 20.
187
+ */
188
+ async findAll(ownerAddress) {
189
+ const total = Number(await this.inner.ownerRecordCount(ownerAddress));
190
+ return this.findMany(ownerAddress, {
191
+ chainOffset: 0n,
192
+ chainLimit: BigInt(total),
193
+ });
194
+ }
195
+ /**
196
+ * Aggregate over owner's records: COUNT, SUM, AVG, MIN, MAX, GROUP BY.
197
+ *
198
+ * @example
199
+ * await users.aggregate(ownerAddress, { count: '*', groupBy: 'role' })
200
+ * // => [{ group: 'admin', count: 3 }, { group: 'user', count: 47 }]
201
+ */
202
+ async aggregate(ownerAddress, opts, where, chainLimit) {
203
+ const records = await this.findMany(ownerAddress, {
204
+ chainLimit,
205
+ where,
206
+ });
207
+ const rows = records.map((r) => r.data);
208
+ return buildQuery(rows).aggregate(opts);
209
+ }
210
+ // ── Update ──────────────────────────────────────────────────
211
+ /**
212
+ * Fetch existing data, merge with `patch`, re-encrypt, and update on-chain.
213
+ */
214
+ async update(id, patch) {
215
+ const current = await this.findUnique(id);
216
+ if (current === null)
217
+ throw new Error(`TypedTableClient.update: record ${id} not found`);
218
+ const merged = { ...current, ...patch };
219
+ return this.inner.updateRaw(this.key(id), this.encode(merged));
220
+ }
221
+ /**
222
+ * Replace a record's data entirely (no merge).
223
+ * More gas-efficient when you have the full new payload ready.
224
+ */
225
+ async replace(id, data) {
226
+ return this.inner.updateRaw(this.key(id), this.encode(data));
227
+ }
228
+ // ── Delete ──────────────────────────────────────────────────
229
+ /**
230
+ * Soft-delete a record. The symmetric key is scrubbed for all collaborators.
231
+ * Only the record owner can call this.
232
+ */
233
+ async remove(id) {
234
+ return this.inner.deleteRecord(this.key(id));
235
+ }
236
+ // ── Helpers ─────────────────────────────────────────────────
237
+ /** Total number of records ever written by `ownerAddress` (including deleted). */
238
+ async count(ownerAddress) {
239
+ return this.inner.ownerRecordCount(ownerAddress);
240
+ }
241
+ /** True if a live (non-deleted) record exists for the given id. */
242
+ async exists(id) {
243
+ return this.inner.exists(this.key(id));
244
+ }
245
+ }
246
+ //# sourceMappingURL=typed-table.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-table.js","sourceRoot":"","sources":["../../src/typed-table.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAIH,OAAO,EAEL,iBAAiB,EACjB,SAAS,GACV,MAAyC,YAAY,CAAC;AACvD,OAAO,EACL,KAAK,IAAI,UAAU,GAKpB,MAAyC,YAAY,CAAC;AAuDvD,gEAAgE;AAChE,oBAAoB;AACpB,gEAAgE;AAEhE,MAAM,OAAO,gBAAgB;IACnB,SAAS,CAAU;IACnB,KAAK,CAA4B;IACjC,MAAM,CAAuB;IAErC;;;;;OAKG;IACH,YAAY,SAAiB,EAAE,KAA2B,EAAE,MAAyB;QACnF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAO,KAAK,CAAC;QACvB,IAAI,CAAC,MAAM,GAAM,MAAM,CAAC;IAC1B,CAAC;IAED,8DAA8D;IAE9D,4EAA4E;IAC5E,GAAG,CAAC,EAAU;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,+DAA+D;IAEvD,MAAM,CAAC,IAAO;QACpB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC,MAAM,EAAE,IAA+B,CAAC,CAAC;YAC7E,OAAO,IAAI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IAAI,CAAC,CAAC,CAAC;IAC/D,CAAC;IAED,+DAA+D;IAE/D;;;OAGG;IACH,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,+DAA+D;IAE/D,kFAAkF;IAClF,KAAK,CAAC,KAAK,CAAC,YAAoB;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;IACnD,CAAC;IAED,mEAAmE;IACnE,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACzC,CAAC;CACF"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @file types.ts
3
+ * @notice Web3QL v1.1 — extended type system with serialization, validation,
4
+ * DEFAULT/NOT NULL enforcement, and codec helpers.
5
+ *
6
+ * Every type maps: JS value ↔ JSON-storable "wire" representation.
7
+ * The chain stores the JSON string; this module handles encode/decode.
8
+ */
9
+ export type FieldType = 'INT' | 'BIGINT' | 'UINT8' | 'UINT16' | 'UINT32' | 'UINT64' | 'TEXT' | 'BOOL' | 'FLOAT' | 'ADDRESS' | 'TIMESTAMP' | 'DATE' | 'UUID' | 'BYTES32' | 'JSON' | 'JSONB' | 'ENUM' | 'DECIMAL';
10
+ /** Sentinel value stored on-chain when a nullable field has no value. */
11
+ export declare const NULL_SENTINEL = "__NULL__";
12
+ export interface FieldDescriptor {
13
+ name: string;
14
+ type: FieldType;
15
+ primaryKey?: boolean;
16
+ notNull?: boolean;
17
+ /** Static default value OR factory function called on each write */
18
+ default?: unknown | (() => unknown);
19
+ /** ENUM: ordered list of string labels */
20
+ enumValues?: string[];
21
+ /** DECIMAL: [totalDigits, decimalPlaces] */
22
+ precision?: [number, number];
23
+ }
24
+ export type SchemaDefinition = FieldDescriptor[];
25
+ /** Encode a JS value → wire format (to be JSON-stringified and stored). */
26
+ export declare function encodeFieldValue(field: FieldDescriptor, value: unknown): unknown;
27
+ /** Decode a wire-format value → typed JS value. */
28
+ export declare function decodeFieldValue(field: FieldDescriptor, value: unknown): unknown;
29
+ /**
30
+ * Validate and normalise a plain JS object before writing to the chain.
31
+ *
32
+ * • Applies DEFAULT values for missing fields
33
+ * • Enforces NOT NULL for fields without a default
34
+ * • Encodes each field to its wire representation
35
+ *
36
+ * @param schema SchemaDefinition for this table
37
+ * @param row Raw user input object
38
+ * @returns Wire-ready object (to be JSON.stringify'd and encrypted)
39
+ */
40
+ export declare function validateAndEncode(schema: SchemaDefinition, row: Record<string, unknown>): Record<string, unknown>;
41
+ /**
42
+ * Decode a wire-format JSON object back to typed JS values.
43
+ *
44
+ * @param schema SchemaDefinition for this table
45
+ * @param wire Object from JSON.parse(plaintext)
46
+ */
47
+ export declare function decodeRow(schema: SchemaDefinition, wire: Record<string, unknown>): Record<string, unknown>;
48
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,MAAM,MAAM,SAAS,GACjB,KAAK,GACL,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,SAAS,GACT,WAAW,GACX,MAAM,GACN,MAAM,GACN,SAAS,GACT,MAAM,GACN,OAAO,GACP,MAAM,GACN,SAAS,CAAC;AAEd,yEAAyE;AACzE,eAAO,MAAM,aAAa,aAAa,CAAC;AAMxC,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAS,MAAM,CAAC;IACpB,IAAI,EAAS,SAAS,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAK,OAAO,CAAC;IACrB,oEAAoE;IACpE,OAAO,CAAC,EAAK,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC;IACvC,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,4CAA4C;IAC5C,SAAS,CAAC,EAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED,MAAM,MAAM,gBAAgB,GAAG,eAAe,EAAE,CAAC;AA8GjD,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAqBhF;AAED,mDAAmD;AACnD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAuBhF;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,gBAAgB,EACxB,GAAG,EAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAgCzB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASzB"}
@@ -0,0 +1,222 @@
1
+ /**
2
+ * @file types.ts
3
+ * @notice Web3QL v1.1 — extended type system with serialization, validation,
4
+ * DEFAULT/NOT NULL enforcement, and codec helpers.
5
+ *
6
+ * Every type maps: JS value ↔ JSON-storable "wire" representation.
7
+ * The chain stores the JSON string; this module handles encode/decode.
8
+ */
9
+ /** Sentinel value stored on-chain when a nullable field has no value. */
10
+ export const NULL_SENTINEL = '__NULL__';
11
+ // ─────────────────────────────────────────────────────────────
12
+ // Type codecs (encode: JS → wire, decode: wire → JS)
13
+ // ─────────────────────────────────────────────────────────────
14
+ function encodeInt(v) {
15
+ if (typeof v === 'bigint')
16
+ return v.toString();
17
+ if (typeof v === 'number')
18
+ return Math.trunc(v).toString();
19
+ return String(v);
20
+ }
21
+ function decodeInt(v) { return BigInt(String(v)); }
22
+ function encodeFloat(v) {
23
+ const n = Number(v);
24
+ if (!isFinite(n))
25
+ throw new TypeError(`FLOAT: expected finite number, got ${v}`);
26
+ // Store as scaled integer to avoid float drift
27
+ return Math.round(n * 1_000_000);
28
+ }
29
+ function decodeFloat(v) { return Number(v) / 1_000_000; }
30
+ function encodeTimestamp(v) {
31
+ if (v instanceof Date)
32
+ return v.getTime();
33
+ if (typeof v === 'number')
34
+ return v;
35
+ if (typeof v === 'string')
36
+ return new Date(v).getTime();
37
+ throw new TypeError(`TIMESTAMP: expected Date or number, got ${typeof v}`);
38
+ }
39
+ function decodeTimestamp(v) { return new Date(Number(v)); }
40
+ function encodeDate(v) {
41
+ const ms = encodeTimestamp(v);
42
+ // Truncate to midnight UTC
43
+ return ms - (ms % 86_400_000);
44
+ }
45
+ function decodeDate(v) {
46
+ const d = new Date(Number(v));
47
+ d.setUTCHours(0, 0, 0, 0);
48
+ return d;
49
+ }
50
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
51
+ function encodeUUID(v) {
52
+ const s = String(v).toLowerCase();
53
+ if (!UUID_RE.test(s))
54
+ throw new TypeError(`UUID: invalid format "${s}"`);
55
+ return s;
56
+ }
57
+ const BYTES32_RE = /^0x[0-9a-f]{64}$/i;
58
+ function encodeBytes32(v) {
59
+ const s = String(v).toLowerCase();
60
+ if (!BYTES32_RE.test(s))
61
+ throw new TypeError(`BYTES32: expected 0x-prefixed 64-hex-char string, got "${s}"`);
62
+ return s;
63
+ }
64
+ const ADDRESS_RE = /^0x[0-9a-f]{40}$/i;
65
+ function encodeAddress(v) {
66
+ const s = String(v).toLowerCase();
67
+ if (!ADDRESS_RE.test(s))
68
+ throw new TypeError(`ADDRESS: invalid EVM address "${s}"`);
69
+ return s;
70
+ }
71
+ function encodeUint(bits, v) {
72
+ const n = Number(v);
73
+ const max = bits === 8 ? 255 : bits === 16 ? 65535 : 4294967295;
74
+ if (!Number.isInteger(n) || n < 0 || n > max) {
75
+ throw new RangeError(`UINT${bits}: value ${n} out of range [0, ${max}]`);
76
+ }
77
+ return n;
78
+ }
79
+ function encodeUint64(v) {
80
+ const n = BigInt(String(v));
81
+ if (n < 0n)
82
+ throw new RangeError(`UINT64: value must be non-negative`);
83
+ return n.toString();
84
+ }
85
+ function encodeJSON(v) {
86
+ // Validate it round-trips cleanly
87
+ JSON.parse(JSON.stringify(v));
88
+ return v;
89
+ }
90
+ function encodeEnum(field, v) {
91
+ const labels = field.enumValues ?? [];
92
+ if (typeof v === 'number') {
93
+ if (v < 0 || v >= labels.length)
94
+ throw new RangeError(`ENUM: index ${v} out of range [0,${labels.length})`);
95
+ return v;
96
+ }
97
+ const idx = labels.indexOf(String(v));
98
+ if (idx === -1)
99
+ throw new TypeError(`ENUM: "${v}" not in [${labels.join(', ')}]`);
100
+ return idx;
101
+ }
102
+ function decodeEnum(field, v) {
103
+ const labels = field.enumValues ?? [];
104
+ const idx = Number(v);
105
+ return labels[idx] ?? String(v);
106
+ }
107
+ function encodeDecimal(field, v) {
108
+ const n = Number(v);
109
+ if (!isFinite(n))
110
+ throw new TypeError(`DECIMAL: expected finite number, got ${v}`);
111
+ const scale = field.precision?.[1] ?? 2;
112
+ return n.toFixed(scale);
113
+ }
114
+ function decodeDecimal(v) { return parseFloat(String(v)); }
115
+ // ─────────────────────────────────────────────────────────────
116
+ // Public encode / decode helpers
117
+ // ─────────────────────────────────────────────────────────────
118
+ /** Encode a JS value → wire format (to be JSON-stringified and stored). */
119
+ export function encodeFieldValue(field, value) {
120
+ switch (field.type) {
121
+ case 'INT':
122
+ case 'BIGINT': return encodeInt(value);
123
+ case 'UINT8': return encodeUint(8, value);
124
+ case 'UINT16': return encodeUint(16, value);
125
+ case 'UINT32': return encodeUint(32, value);
126
+ case 'UINT64': return encodeUint64(value);
127
+ case 'TEXT': return String(value);
128
+ case 'BOOL': return Boolean(value);
129
+ case 'FLOAT': return encodeFloat(value);
130
+ case 'ADDRESS': return encodeAddress(value);
131
+ case 'TIMESTAMP': return encodeTimestamp(value);
132
+ case 'DATE': return encodeDate(value);
133
+ case 'UUID': return encodeUUID(value);
134
+ case 'BYTES32': return encodeBytes32(value);
135
+ case 'JSON':
136
+ case 'JSONB': return encodeJSON(value);
137
+ case 'ENUM': return encodeEnum(field, value);
138
+ case 'DECIMAL': return encodeDecimal(field, value);
139
+ }
140
+ }
141
+ /** Decode a wire-format value → typed JS value. */
142
+ export function decodeFieldValue(field, value) {
143
+ if (value === NULL_SENTINEL)
144
+ return null;
145
+ if (value === null || value === undefined)
146
+ return value;
147
+ switch (field.type) {
148
+ case 'INT':
149
+ case 'BIGINT': return decodeInt(value);
150
+ case 'UINT64': return BigInt(String(value));
151
+ case 'UINT8':
152
+ case 'UINT16':
153
+ case 'UINT32': return Number(value);
154
+ case 'TEXT':
155
+ case 'UUID':
156
+ case 'BYTES32':
157
+ case 'ADDRESS': return String(value);
158
+ case 'BOOL': return Boolean(value);
159
+ case 'FLOAT': return decodeFloat(value);
160
+ case 'TIMESTAMP': return decodeTimestamp(value);
161
+ case 'DATE': return decodeDate(value);
162
+ case 'JSON':
163
+ case 'JSONB': return value;
164
+ case 'ENUM': return decodeEnum(field, value);
165
+ case 'DECIMAL': return decodeDecimal(value);
166
+ }
167
+ }
168
+ // ─────────────────────────────────────────────────────────────
169
+ // Row-level validation — NOT NULL + DEFAULT + type coerce
170
+ // ─────────────────────────────────────────────────────────────
171
+ /**
172
+ * Validate and normalise a plain JS object before writing to the chain.
173
+ *
174
+ * • Applies DEFAULT values for missing fields
175
+ * • Enforces NOT NULL for fields without a default
176
+ * • Encodes each field to its wire representation
177
+ *
178
+ * @param schema SchemaDefinition for this table
179
+ * @param row Raw user input object
180
+ * @returns Wire-ready object (to be JSON.stringify'd and encrypted)
181
+ */
182
+ export function validateAndEncode(schema, row) {
183
+ const out = {};
184
+ for (const field of schema) {
185
+ let value = row[field.name];
186
+ // Apply default if value is absent
187
+ if (value === undefined || value === null) {
188
+ if (field.default !== undefined) {
189
+ value = typeof field.default === 'function'
190
+ ? field.default()
191
+ : field.default;
192
+ }
193
+ }
194
+ // NOT NULL enforcement
195
+ if ((value === undefined || value === null) && field.notNull) {
196
+ throw new TypeError(`Field "${field.name}" is NOT NULL but no value or default was provided.`);
197
+ }
198
+ // Skip truly absent optional fields (store as NULL_SENTINEL for type safety)
199
+ if (value === undefined || value === null) {
200
+ out[field.name] = NULL_SENTINEL;
201
+ continue;
202
+ }
203
+ out[field.name] = encodeFieldValue(field, value);
204
+ }
205
+ return out;
206
+ }
207
+ /**
208
+ * Decode a wire-format JSON object back to typed JS values.
209
+ *
210
+ * @param schema SchemaDefinition for this table
211
+ * @param wire Object from JSON.parse(plaintext)
212
+ */
213
+ export function decodeRow(schema, wire) {
214
+ const out = {};
215
+ const byName = new Map(schema.map((f) => [f.name, f]));
216
+ for (const [key, value] of Object.entries(wire)) {
217
+ const field = byName.get(key);
218
+ out[key] = field ? decodeFieldValue(field, value) : value;
219
+ }
220
+ return out;
221
+ }
222
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA0BH,yEAAyE;AACzE,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC;AAqBxC,gEAAgE;AAChE,wDAAwD;AACxD,gEAAgE;AAEhE,SAAS,SAAS,CAAC,CAAU;IAC3B,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC/C,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC3D,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACn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