@sequenceholdings/orm 2.6.1 → 2.6.2

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.
@@ -102,8 +102,8 @@ type CanonicalFetchShape = z.infer<typeof canonicalFetchShapeSchema>;
102
102
  declare const canonicalResolvedSourceSchema: z.ZodObject<{
103
103
  name: z.ZodString;
104
104
  kind: z.ZodEnum<{
105
- prefetch: "prefetch";
106
105
  manual: "manual";
106
+ prefetch: "prefetch";
107
107
  etl: "etl";
108
108
  }>;
109
109
  table: z.ZodString;
@@ -160,8 +160,8 @@ declare const canonicalResolvedSchema: z.ZodObject<{
160
160
  sources: z.ZodArray<z.ZodObject<{
161
161
  name: z.ZodString;
162
162
  kind: z.ZodEnum<{
163
- prefetch: "prefetch";
164
163
  manual: "manual";
164
+ prefetch: "prefetch";
165
165
  etl: "etl";
166
166
  }>;
167
167
  table: z.ZodString;
@@ -325,13 +325,13 @@ declare const canonicalColumnSchema: z.ZodObject<{
325
325
  bigint: "bigint";
326
326
  boolean: "boolean";
327
327
  date: "date";
328
- uuid: "uuid";
329
328
  text: "text";
329
+ timestamptz: "timestamptz";
330
+ jsonb: "jsonb";
331
+ uuid: "uuid";
330
332
  integer: "integer";
331
333
  numeric: "numeric";
332
334
  double: "double";
333
- timestamptz: "timestamptz";
334
- jsonb: "jsonb";
335
335
  }>, z.ZodObject<{
336
336
  enum: z.ZodString;
337
337
  }, z.core.$strip>]>;
@@ -353,10 +353,10 @@ declare const canonicalColumnSchema: z.ZodObject<{
353
353
  of: z.ZodString;
354
354
  part: z.ZodEnum<{
355
355
  at: "at";
356
- source: "source";
357
356
  by: "by";
358
- conflicts: "conflicts";
359
357
  rev: "rev";
358
+ source: "source";
359
+ conflicts: "conflicts";
360
360
  }>;
361
361
  }, z.core.$strict>>;
362
362
  }, z.core.$strip>;
@@ -460,21 +460,21 @@ declare const canonicalActionSchema: z.ZodObject<{
460
460
  bigint: "bigint";
461
461
  boolean: "boolean";
462
462
  date: "date";
463
- uuid: "uuid";
464
463
  text: "text";
464
+ timestamptz: "timestamptz";
465
+ jsonb: "jsonb";
466
+ uuid: "uuid";
465
467
  integer: "integer";
466
468
  numeric: "numeric";
467
469
  double: "double";
468
- timestamptz: "timestamptz";
469
- jsonb: "jsonb";
470
470
  }>;
471
471
  nullable: z.ZodDefault<z.ZodBoolean>;
472
472
  }, z.core.$strip>>>;
473
473
  executes: z.ZodString;
474
474
  returns: z.ZodDefault<z.ZodEnum<{
475
475
  rows: "rows";
476
- scalar: "scalar";
477
476
  rowsAffected: "rowsAffected";
477
+ scalar: "scalar";
478
478
  }>>;
479
479
  audit: z.ZodOptional<z.ZodObject<{
480
480
  action: z.ZodString;
@@ -540,13 +540,13 @@ declare const canonicalTableSchema: z.ZodObject<{
540
540
  bigint: "bigint";
541
541
  boolean: "boolean";
542
542
  date: "date";
543
- uuid: "uuid";
544
543
  text: "text";
544
+ timestamptz: "timestamptz";
545
+ jsonb: "jsonb";
546
+ uuid: "uuid";
545
547
  integer: "integer";
546
548
  numeric: "numeric";
547
549
  double: "double";
548
- timestamptz: "timestamptz";
549
- jsonb: "jsonb";
550
550
  }>, z.ZodObject<{
551
551
  enum: z.ZodString;
552
552
  }, z.core.$strip>]>;
@@ -568,10 +568,10 @@ declare const canonicalTableSchema: z.ZodObject<{
568
568
  of: z.ZodString;
569
569
  part: z.ZodEnum<{
570
570
  at: "at";
571
- source: "source";
572
571
  by: "by";
573
- conflicts: "conflicts";
574
572
  rev: "rev";
573
+ source: "source";
574
+ conflicts: "conflicts";
575
575
  }>;
576
576
  }, z.core.$strict>>;
577
577
  }, z.core.$strip>>>;
@@ -655,21 +655,21 @@ declare const canonicalTableSchema: z.ZodObject<{
655
655
  bigint: "bigint";
656
656
  boolean: "boolean";
657
657
  date: "date";
658
- uuid: "uuid";
659
658
  text: "text";
659
+ timestamptz: "timestamptz";
660
+ jsonb: "jsonb";
661
+ uuid: "uuid";
660
662
  integer: "integer";
661
663
  numeric: "numeric";
662
664
  double: "double";
663
- timestamptz: "timestamptz";
664
- jsonb: "jsonb";
665
665
  }>;
666
666
  nullable: z.ZodDefault<z.ZodBoolean>;
667
667
  }, z.core.$strip>>>;
668
668
  executes: z.ZodString;
669
669
  returns: z.ZodDefault<z.ZodEnum<{
670
670
  rows: "rows";
671
- scalar: "scalar";
672
671
  rowsAffected: "rowsAffected";
672
+ scalar: "scalar";
673
673
  }>>;
674
674
  audit: z.ZodOptional<z.ZodObject<{
675
675
  action: z.ZodString;
@@ -726,13 +726,13 @@ declare const canonicalViewSchema: z.ZodObject<{
726
726
  bigint: "bigint";
727
727
  boolean: "boolean";
728
728
  date: "date";
729
- uuid: "uuid";
730
729
  text: "text";
730
+ timestamptz: "timestamptz";
731
+ jsonb: "jsonb";
732
+ uuid: "uuid";
731
733
  integer: "integer";
732
734
  numeric: "numeric";
733
735
  double: "double";
734
- timestamptz: "timestamptz";
735
- jsonb: "jsonb";
736
736
  }>, z.ZodObject<{
737
737
  enum: z.ZodString;
738
738
  }, z.core.$strip>]>;
@@ -754,10 +754,10 @@ declare const canonicalViewSchema: z.ZodObject<{
754
754
  of: z.ZodString;
755
755
  part: z.ZodEnum<{
756
756
  at: "at";
757
- source: "source";
758
757
  by: "by";
759
- conflicts: "conflicts";
760
758
  rev: "rev";
759
+ source: "source";
760
+ conflicts: "conflicts";
761
761
  }>;
762
762
  }, z.core.$strict>>;
763
763
  }, z.core.$strip>>;
@@ -806,8 +806,8 @@ declare const canonicalViewSchema: z.ZodObject<{
806
806
  sources: z.ZodArray<z.ZodObject<{
807
807
  name: z.ZodString;
808
808
  kind: z.ZodEnum<{
809
- prefetch: "prefetch";
810
809
  manual: "manual";
810
+ prefetch: "prefetch";
811
811
  etl: "etl";
812
812
  }>;
813
813
  table: z.ZodString;
@@ -947,13 +947,13 @@ declare const localDefinitionSchema: z.ZodObject<{
947
947
  bigint: "bigint";
948
948
  boolean: "boolean";
949
949
  date: "date";
950
- uuid: "uuid";
951
950
  text: "text";
951
+ timestamptz: "timestamptz";
952
+ jsonb: "jsonb";
953
+ uuid: "uuid";
952
954
  integer: "integer";
953
955
  numeric: "numeric";
954
956
  double: "double";
955
- timestamptz: "timestamptz";
956
- jsonb: "jsonb";
957
957
  }>, z.ZodObject<{
958
958
  enum: z.ZodString;
959
959
  }, z.core.$strip>]>;
@@ -975,10 +975,10 @@ declare const localDefinitionSchema: z.ZodObject<{
975
975
  of: z.ZodString;
976
976
  part: z.ZodEnum<{
977
977
  at: "at";
978
- source: "source";
979
978
  by: "by";
980
- conflicts: "conflicts";
981
979
  rev: "rev";
980
+ source: "source";
981
+ conflicts: "conflicts";
982
982
  }>;
983
983
  }, z.core.$strict>>;
984
984
  }, z.core.$strip>>>;
@@ -1062,21 +1062,21 @@ declare const localDefinitionSchema: z.ZodObject<{
1062
1062
  bigint: "bigint";
1063
1063
  boolean: "boolean";
1064
1064
  date: "date";
1065
- uuid: "uuid";
1066
1065
  text: "text";
1066
+ timestamptz: "timestamptz";
1067
+ jsonb: "jsonb";
1068
+ uuid: "uuid";
1067
1069
  integer: "integer";
1068
1070
  numeric: "numeric";
1069
1071
  double: "double";
1070
- timestamptz: "timestamptz";
1071
- jsonb: "jsonb";
1072
1072
  }>;
1073
1073
  nullable: z.ZodDefault<z.ZodBoolean>;
1074
1074
  }, z.core.$strip>>>;
1075
1075
  executes: z.ZodString;
1076
1076
  returns: z.ZodDefault<z.ZodEnum<{
1077
1077
  rows: "rows";
1078
- scalar: "scalar";
1079
1078
  rowsAffected: "rowsAffected";
1079
+ scalar: "scalar";
1080
1080
  }>>;
1081
1081
  audit: z.ZodOptional<z.ZodObject<{
1082
1082
  action: z.ZodString;
@@ -1132,13 +1132,13 @@ declare const localDefinitionSchema: z.ZodObject<{
1132
1132
  bigint: "bigint";
1133
1133
  boolean: "boolean";
1134
1134
  date: "date";
1135
- uuid: "uuid";
1136
1135
  text: "text";
1136
+ timestamptz: "timestamptz";
1137
+ jsonb: "jsonb";
1138
+ uuid: "uuid";
1137
1139
  integer: "integer";
1138
1140
  numeric: "numeric";
1139
1141
  double: "double";
1140
- timestamptz: "timestamptz";
1141
- jsonb: "jsonb";
1142
1142
  }>, z.ZodObject<{
1143
1143
  enum: z.ZodString;
1144
1144
  }, z.core.$strip>]>;
@@ -1160,10 +1160,10 @@ declare const localDefinitionSchema: z.ZodObject<{
1160
1160
  of: z.ZodString;
1161
1161
  part: z.ZodEnum<{
1162
1162
  at: "at";
1163
- source: "source";
1164
1163
  by: "by";
1165
- conflicts: "conflicts";
1166
1164
  rev: "rev";
1165
+ source: "source";
1166
+ conflicts: "conflicts";
1167
1167
  }>;
1168
1168
  }, z.core.$strict>>;
1169
1169
  }, z.core.$strip>>;
@@ -1212,8 +1212,8 @@ declare const localDefinitionSchema: z.ZodObject<{
1212
1212
  sources: z.ZodArray<z.ZodObject<{
1213
1213
  name: z.ZodString;
1214
1214
  kind: z.ZodEnum<{
1215
- prefetch: "prefetch";
1216
1215
  manual: "manual";
1216
+ prefetch: "prefetch";
1217
1217
  etl: "etl";
1218
1218
  }>;
1219
1219
  table: z.ZodString;
@@ -1336,13 +1336,13 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
1336
1336
  bigint: "bigint";
1337
1337
  boolean: "boolean";
1338
1338
  date: "date";
1339
- uuid: "uuid";
1340
1339
  text: "text";
1340
+ timestamptz: "timestamptz";
1341
+ jsonb: "jsonb";
1342
+ uuid: "uuid";
1341
1343
  integer: "integer";
1342
1344
  numeric: "numeric";
1343
1345
  double: "double";
1344
- timestamptz: "timestamptz";
1345
- jsonb: "jsonb";
1346
1346
  }>, z.ZodObject<{
1347
1347
  enum: z.ZodString;
1348
1348
  }, z.core.$strip>]>;
@@ -1364,10 +1364,10 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
1364
1364
  of: z.ZodString;
1365
1365
  part: z.ZodEnum<{
1366
1366
  at: "at";
1367
- source: "source";
1368
1367
  by: "by";
1369
- conflicts: "conflicts";
1370
1368
  rev: "rev";
1369
+ source: "source";
1370
+ conflicts: "conflicts";
1371
1371
  }>;
1372
1372
  }, z.core.$strict>>;
1373
1373
  }, z.core.$strip>>>;
@@ -1451,21 +1451,21 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
1451
1451
  bigint: "bigint";
1452
1452
  boolean: "boolean";
1453
1453
  date: "date";
1454
- uuid: "uuid";
1455
1454
  text: "text";
1455
+ timestamptz: "timestamptz";
1456
+ jsonb: "jsonb";
1457
+ uuid: "uuid";
1456
1458
  integer: "integer";
1457
1459
  numeric: "numeric";
1458
1460
  double: "double";
1459
- timestamptz: "timestamptz";
1460
- jsonb: "jsonb";
1461
1461
  }>;
1462
1462
  nullable: z.ZodDefault<z.ZodBoolean>;
1463
1463
  }, z.core.$strip>>>;
1464
1464
  executes: z.ZodString;
1465
1465
  returns: z.ZodDefault<z.ZodEnum<{
1466
1466
  rows: "rows";
1467
- scalar: "scalar";
1468
1467
  rowsAffected: "rowsAffected";
1468
+ scalar: "scalar";
1469
1469
  }>>;
1470
1470
  audit: z.ZodOptional<z.ZodObject<{
1471
1471
  action: z.ZodString;
@@ -1521,13 +1521,13 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
1521
1521
  bigint: "bigint";
1522
1522
  boolean: "boolean";
1523
1523
  date: "date";
1524
- uuid: "uuid";
1525
1524
  text: "text";
1525
+ timestamptz: "timestamptz";
1526
+ jsonb: "jsonb";
1527
+ uuid: "uuid";
1526
1528
  integer: "integer";
1527
1529
  numeric: "numeric";
1528
1530
  double: "double";
1529
- timestamptz: "timestamptz";
1530
- jsonb: "jsonb";
1531
1531
  }>, z.ZodObject<{
1532
1532
  enum: z.ZodString;
1533
1533
  }, z.core.$strip>]>;
@@ -1549,10 +1549,10 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
1549
1549
  of: z.ZodString;
1550
1550
  part: z.ZodEnum<{
1551
1551
  at: "at";
1552
- source: "source";
1553
1552
  by: "by";
1554
- conflicts: "conflicts";
1555
1553
  rev: "rev";
1554
+ source: "source";
1555
+ conflicts: "conflicts";
1556
1556
  }>;
1557
1557
  }, z.core.$strict>>;
1558
1558
  }, z.core.$strip>>;
@@ -1601,8 +1601,8 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
1601
1601
  sources: z.ZodArray<z.ZodObject<{
1602
1602
  name: z.ZodString;
1603
1603
  kind: z.ZodEnum<{
1604
- prefetch: "prefetch";
1605
1604
  manual: "manual";
1605
+ prefetch: "prefetch";
1606
1606
  etl: "etl";
1607
1607
  }>;
1608
1608
  table: z.ZodString;
@@ -1724,13 +1724,13 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
1724
1724
  bigint: "bigint";
1725
1725
  boolean: "boolean";
1726
1726
  date: "date";
1727
- uuid: "uuid";
1728
1727
  text: "text";
1728
+ timestamptz: "timestamptz";
1729
+ jsonb: "jsonb";
1730
+ uuid: "uuid";
1729
1731
  integer: "integer";
1730
1732
  numeric: "numeric";
1731
1733
  double: "double";
1732
- timestamptz: "timestamptz";
1733
- jsonb: "jsonb";
1734
1734
  }>, z.ZodObject<{
1735
1735
  enum: z.ZodString;
1736
1736
  }, z.core.$strip>]>;
@@ -1752,10 +1752,10 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
1752
1752
  of: z.ZodString;
1753
1753
  part: z.ZodEnum<{
1754
1754
  at: "at";
1755
- source: "source";
1756
1755
  by: "by";
1757
- conflicts: "conflicts";
1758
1756
  rev: "rev";
1757
+ source: "source";
1758
+ conflicts: "conflicts";
1759
1759
  }>;
1760
1760
  }, z.core.$strict>>;
1761
1761
  }, z.core.$strip>>>;
@@ -1839,21 +1839,21 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
1839
1839
  bigint: "bigint";
1840
1840
  boolean: "boolean";
1841
1841
  date: "date";
1842
- uuid: "uuid";
1843
1842
  text: "text";
1843
+ timestamptz: "timestamptz";
1844
+ jsonb: "jsonb";
1845
+ uuid: "uuid";
1844
1846
  integer: "integer";
1845
1847
  numeric: "numeric";
1846
1848
  double: "double";
1847
- timestamptz: "timestamptz";
1848
- jsonb: "jsonb";
1849
1849
  }>;
1850
1850
  nullable: z.ZodDefault<z.ZodBoolean>;
1851
1851
  }, z.core.$strip>>>;
1852
1852
  executes: z.ZodString;
1853
1853
  returns: z.ZodDefault<z.ZodEnum<{
1854
1854
  rows: "rows";
1855
- scalar: "scalar";
1856
1855
  rowsAffected: "rowsAffected";
1856
+ scalar: "scalar";
1857
1857
  }>>;
1858
1858
  audit: z.ZodOptional<z.ZodObject<{
1859
1859
  action: z.ZodString;
@@ -1909,13 +1909,13 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
1909
1909
  bigint: "bigint";
1910
1910
  boolean: "boolean";
1911
1911
  date: "date";
1912
- uuid: "uuid";
1913
1912
  text: "text";
1913
+ timestamptz: "timestamptz";
1914
+ jsonb: "jsonb";
1915
+ uuid: "uuid";
1914
1916
  integer: "integer";
1915
1917
  numeric: "numeric";
1916
1918
  double: "double";
1917
- timestamptz: "timestamptz";
1918
- jsonb: "jsonb";
1919
1919
  }>, z.ZodObject<{
1920
1920
  enum: z.ZodString;
1921
1921
  }, z.core.$strip>]>;
@@ -1937,10 +1937,10 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
1937
1937
  of: z.ZodString;
1938
1938
  part: z.ZodEnum<{
1939
1939
  at: "at";
1940
- source: "source";
1941
1940
  by: "by";
1942
- conflicts: "conflicts";
1943
1941
  rev: "rev";
1942
+ source: "source";
1943
+ conflicts: "conflicts";
1944
1944
  }>;
1945
1945
  }, z.core.$strict>>;
1946
1946
  }, z.core.$strip>>;
@@ -1989,8 +1989,8 @@ declare const canonicalDefinitionSchema: z.ZodObject<{
1989
1989
  sources: z.ZodArray<z.ZodObject<{
1990
1990
  name: z.ZodString;
1991
1991
  kind: z.ZodEnum<{
1992
- prefetch: "prefetch";
1993
1992
  manual: "manual";
1993
+ prefetch: "prefetch";
1994
1994
  etl: "etl";
1995
1995
  }>;
1996
1996
  table: z.ZodString;
package/dist/client.cjs CHANGED
@@ -193,6 +193,20 @@ function readOperationResponse({
193
193
  }
194
194
  return payload.data;
195
195
  }
196
+ function readOperationResponseWithReceipt({
197
+ ok,
198
+ status,
199
+ body,
200
+ expectedSourceGeneration
201
+ }) {
202
+ const data = readOperationResponse({ ok, status, body });
203
+ const extensions = isRecord(body) && isRecord(body.extensions) ? body.extensions : null;
204
+ const sourceGeneration = extensions?.sourceGeneration;
205
+ if (typeof sourceGeneration !== "string" || !/^[a-f0-9]{64}$/.test(sourceGeneration) || expectedSourceGeneration !== void 0 && expectedSourceGeneration !== sourceGeneration) {
206
+ throw new OrmOperationError("Source generation unavailable", status, "OBJECT_UNAVAILABLE");
207
+ }
208
+ return { data, sourceGeneration };
209
+ }
196
210
 
197
211
  // src/client/sql.ts
198
212
  var BUILTIN_SQL_READ_HASH = "sha256:a50c477c952a5e0fe68ed158a4530e4aab573c09bcbb1a8ac454dc88a39a6258";
@@ -203,6 +217,11 @@ function validateIdempotencyKey(key) {
203
217
  throw new OrmClientError("idempotencyKey must be 1\u2013128 letters, digits, dots, underscores, colons or hyphens");
204
218
  }
205
219
  }
220
+ function validateExpectedSourceGeneration(value) {
221
+ if (value !== void 0 && (typeof value !== "string" || !/^[a-f0-9]{64}$/.test(value))) {
222
+ throw new OrmClientError("expectedSourceGeneration must be a lowercase 64-character hexadecimal receipt");
223
+ }
224
+ }
206
225
  var dataPlanePath = (namespace) => `/_data/v2/${namespace}`;
207
226
  function resolveOpHash(manifest, op) {
208
227
  if (op.startsWith("sha256:")) return op;
@@ -215,6 +234,23 @@ function resolveOpHash(manifest, op) {
215
234
  }
216
235
  return entry.hash;
217
236
  }
237
+ function createReadReceiptOperationResolver({ operations }) {
238
+ const hashesByName = /* @__PURE__ */ new Map();
239
+ const readHashes = /* @__PURE__ */ new Set([BUILTIN_SQL_READ_HASH]);
240
+ const mutationHashes = /* @__PURE__ */ new Set();
241
+ for (const [name, entry] of operations) {
242
+ hashesByName.set(name, entry.hash);
243
+ if (entry.kind === "query" && /^sha256:[a-f0-9]{64}$/.test(entry.hash)) readHashes.add(entry.hash);
244
+ if (entry.kind === "mutation") mutationHashes.add(entry.hash);
245
+ }
246
+ return ({ selector, hashOnly = false }) => {
247
+ const hash = selector.startsWith("sha256:") ? selector : hashOnly ? void 0 : hashesByName.get(selector);
248
+ if (!hash || !readHashes.has(hash) || mutationHashes.has(hash)) {
249
+ throw new OrmClientError("read receipts require a registered query or the built-in SQL read");
250
+ }
251
+ return hash;
252
+ };
253
+ }
218
254
  function createOperationExecutor({
219
255
  baseUrl,
220
256
  namespace,
@@ -228,25 +264,42 @@ function createOperationExecutor({
228
264
  throw new OrmClientError("provide exactly one of getToken (bearer) or getDataToken (delegated)");
229
265
  }
230
266
  const root = baseUrl.replace(/\/+$/, "");
231
- async function execute(op, variables = {}, options = {}) {
267
+ const resolveReceiptOperation = createReadReceiptOperationResolver({ operations: Object.entries(manifest.operations) });
268
+ async function request({ op, variables, options, requireReadReceipt = false }) {
232
269
  validateIdempotencyKey(options.idempotencyKey);
270
+ validateExpectedSourceGeneration(options.expectedSourceGeneration);
233
271
  if (typeof op !== "string" && op.namespace !== namespace) throw new OrmClientError("operation belongs to a different namespace");
234
- const hash = typeof op === "string" ? resolveOpHash(manifest, op) : op.hash;
272
+ const hash = requireReadReceipt ? resolveReceiptOperation({ selector: typeof op === "string" ? op : op.hash, hashOnly: typeof op !== "string" }) : typeof op === "string" ? resolveOpHash(manifest, op) : op.hash;
235
273
  const token = await (getDataToken ?? getToken)();
236
274
  if (!token) throw new OrmClientError("not authenticated \u2014 no token available");
237
275
  const auth = getDataToken ? { [ORM_DATA_TOKEN_HEADER]: token } : { Authorization: `Bearer ${token}` };
238
276
  const response = await fetchImpl(`${root}${dataPlanePath(namespace)}`, {
239
277
  method: "POST",
240
278
  headers: { ...auth, "Content-Type": "application/json" },
241
- body: JSON.stringify({ op: hash, variables, idempotencyKey: options.idempotencyKey })
279
+ body: JSON.stringify({
280
+ op: hash,
281
+ variables,
282
+ idempotencyKey: options.idempotencyKey,
283
+ expectedSourceGeneration: options.expectedSourceGeneration
284
+ })
242
285
  });
243
- return readOperationResponse({
286
+ return {
244
287
  ok: response.ok,
245
288
  status: response.status,
246
289
  body: await response.json().catch(() => null)
247
- });
290
+ };
291
+ }
292
+ async function execute(op, variables = {}, options = {}) {
293
+ const executionOptions = { ...options };
294
+ const response = await request({ op, variables, options: executionOptions });
295
+ return executionOptions.expectedSourceGeneration === void 0 ? readOperationResponse(response) : readOperationResponseWithReceipt({ ...response, expectedSourceGeneration: executionOptions.expectedSourceGeneration }).data;
296
+ }
297
+ async function executeWithReadReceipt(op, variables = {}, options = {}) {
298
+ const executionOptions = { ...options };
299
+ const response = await request({ op, variables, options: executionOptions, requireReadReceipt: true });
300
+ return readOperationResponseWithReceipt({ ...response, expectedSourceGeneration: executionOptions.expectedSourceGeneration });
248
301
  }
249
- return { execute, sql: (variables) => execute(BUILTIN_SQL_READ_HASH, variables) };
302
+ return { execute, executeWithReadReceipt, sql: (variables) => execute(BUILTIN_SQL_READ_HASH, variables) };
250
303
  }
251
304
  var configured = null;
252
305
  function configureOrmOperations(config) {
@@ -315,33 +368,46 @@ function readManifestHashes(manifest) {
315
368
  if (!/^[_A-Za-z][_0-9A-Za-z]*$/.test(name) || !isRecord(entry) || typeof entry.hash !== "string" || !operationHash.test(entry.hash) || entry.kind !== "query" && entry.kind !== "mutation") {
316
369
  throw new OrmClientError(`invalid operations manifest entry "${name}" \u2014 regenerate the manifest`);
317
370
  }
318
- hashes.set(name, entry.hash);
371
+ hashes.set(name, { hash: entry.hash, kind: entry.kind });
319
372
  }
320
373
  return hashes;
321
374
  }
322
375
  function createOperationExecutorWithTransport({ namespace, manifest, transport }) {
323
376
  if (typeof namespace !== "string" || !NAMESPACE_PATTERN.test(namespace)) throw new OrmClientError("invalid ORM namespace \u2014 expected a lowercase identifier of at most 41 characters");
324
377
  const hashes = manifest === void 0 ? /* @__PURE__ */ new Map() : readManifestHashes(manifest);
325
- const knownHashes = new Set(hashes.values());
326
- async function execute(op, variables = {}, options = {}) {
378
+ const knownHashes = new Set([...hashes.values()].map((entry) => entry.hash));
379
+ const resolveReceiptOperation = createReadReceiptOperationResolver({ operations: hashes });
380
+ async function request({ op, variables, options, requireReadReceipt = false }) {
327
381
  validateIdempotencyKey(options.idempotencyKey);
382
+ validateExpectedSourceGeneration(options.expectedSourceGeneration);
328
383
  if (typeof op !== "string" && op.namespace !== namespace) throw new OrmClientError("operation belongs to a different namespace");
329
384
  const selector = typeof op === "string" ? op : op.hash;
330
- const hash = selector === BUILTIN_SQL_READ_HASH ? selector : hashes.get(selector) ?? (knownHashes.has(selector) ? selector : void 0);
385
+ const hash = requireReadReceipt ? resolveReceiptOperation({ selector, hashOnly: typeof op !== "string" }) : selector === BUILTIN_SQL_READ_HASH ? selector : hashes.get(selector)?.hash ?? (knownHashes.has(selector) ? selector : void 0);
331
386
  if (!hash) throw new OrmClientError(`unknown operation "${op}" \u2014 not in the manifest (${hashes.size} known). Re-run seq-studio orm generate.`);
332
387
  if (!isRecord(variables)) throw new OrmClientError("operation variables must be an object");
333
388
  const response = await transport({
334
389
  namespace,
335
390
  op: hash,
336
391
  variables,
337
- ...options.idempotencyKey === void 0 ? {} : { idempotencyKey: options.idempotencyKey }
392
+ ...options.idempotencyKey === void 0 ? {} : { idempotencyKey: options.idempotencyKey },
393
+ ...options.expectedSourceGeneration === void 0 ? {} : { expectedSourceGeneration: options.expectedSourceGeneration }
338
394
  });
339
395
  if (!response || typeof response.ok !== "boolean" || !Number.isInteger(response.status) || response.status < 100 || response.status > 599 || response.ok !== (response.status >= 200 && response.status < 300)) {
340
396
  throw new OrmOperationError("malformed transport response", null, null);
341
397
  }
342
- return readOperationResponse(response);
398
+ return response;
399
+ }
400
+ async function execute(op, variables = {}, options = {}) {
401
+ const executionOptions = { ...options };
402
+ const response = await request({ op, variables, options: executionOptions });
403
+ return executionOptions.expectedSourceGeneration === void 0 ? readOperationResponse(response) : readOperationResponseWithReceipt({ ...response, expectedSourceGeneration: executionOptions.expectedSourceGeneration }).data;
404
+ }
405
+ async function executeWithReadReceipt(op, variables = {}, options = {}) {
406
+ const executionOptions = { ...options };
407
+ const response = await request({ op, variables, options: executionOptions, requireReadReceipt: true });
408
+ return readOperationResponseWithReceipt({ ...response, expectedSourceGeneration: executionOptions.expectedSourceGeneration });
343
409
  }
344
- return { execute, sql: (variables) => execute(BUILTIN_SQL_READ_HASH, variables) };
410
+ return { execute, executeWithReadReceipt, sql: (variables) => execute(BUILTIN_SQL_READ_HASH, variables) };
345
411
  }
346
412
 
347
413
  // src/client/index.ts