@laserdata/laser-sdk 0.1.1 → 0.2.1

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 (142) hide show
  1. package/README.md +65 -5
  2. package/dist/agent/reliable-consumer.d.ts.map +1 -1
  3. package/dist/agent/reliable-consumer.js +1 -0
  4. package/dist/agent/reliable-consumer.js.map +1 -1
  5. package/dist/agent/workflow.d.ts +2 -0
  6. package/dist/agent/workflow.d.ts.map +1 -1
  7. package/dist/agent/workflow.js +114 -13
  8. package/dist/agent/workflow.js.map +1 -1
  9. package/dist/bridges/a2a.d.ts +1 -1
  10. package/dist/bridges/a2a.js +1 -1
  11. package/dist/client/capabilities.d.ts +14 -1
  12. package/dist/client/capabilities.d.ts.map +1 -1
  13. package/dist/client/capabilities.js +57 -23
  14. package/dist/client/capabilities.js.map +1 -1
  15. package/dist/client/errors.d.ts +6 -1
  16. package/dist/client/errors.d.ts.map +1 -1
  17. package/dist/client/errors.js +5 -0
  18. package/dist/client/errors.js.map +1 -1
  19. package/dist/client/laser.d.ts +8 -0
  20. package/dist/client/laser.d.ts.map +1 -1
  21. package/dist/client/laser.js +42 -10
  22. package/dist/client/laser.js.map +1 -1
  23. package/dist/client/managed.d.ts +3 -1
  24. package/dist/client/managed.d.ts.map +1 -1
  25. package/dist/client/managed.js +2 -2
  26. package/dist/client/managed.js.map +1 -1
  27. package/dist/full.d.ts +1 -0
  28. package/dist/full.d.ts.map +1 -1
  29. package/dist/full.js +1 -0
  30. package/dist/full.js.map +1 -1
  31. package/dist/iggy/apache-iggy.d.ts +6 -2
  32. package/dist/iggy/apache-iggy.d.ts.map +1 -1
  33. package/dist/iggy/apache-iggy.js +11 -10
  34. package/dist/iggy/apache-iggy.js.map +1 -1
  35. package/dist/index.d.ts +11 -5
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +5 -3
  38. package/dist/index.js.map +1 -1
  39. package/dist/managed/batch.d.ts.map +1 -1
  40. package/dist/managed/batch.js +23 -2
  41. package/dist/managed/batch.js.map +1 -1
  42. package/dist/managed/destinations.d.ts +19 -0
  43. package/dist/managed/destinations.d.ts.map +1 -0
  44. package/dist/managed/destinations.js +90 -0
  45. package/dist/managed/destinations.js.map +1 -0
  46. package/dist/managed/kv.d.ts +33 -6
  47. package/dist/managed/kv.d.ts.map +1 -1
  48. package/dist/managed/kv.js +99 -17
  49. package/dist/managed/kv.js.map +1 -1
  50. package/dist/managed/query.d.ts +26 -19
  51. package/dist/managed/query.d.ts.map +1 -1
  52. package/dist/managed/query.js +97 -55
  53. package/dist/managed/query.js.map +1 -1
  54. package/dist/stream/publish.d.ts +3 -0
  55. package/dist/stream/publish.d.ts.map +1 -1
  56. package/dist/stream/publish.js +25 -0
  57. package/dist/stream/publish.js.map +1 -1
  58. package/dist/stream/record.d.ts +4 -1
  59. package/dist/stream/record.d.ts.map +1 -1
  60. package/dist/stream/record.js +34 -3
  61. package/dist/stream/record.js.map +1 -1
  62. package/dist/wire/arrow.d.ts +39 -0
  63. package/dist/wire/arrow.d.ts.map +1 -0
  64. package/dist/wire/arrow.js +133 -0
  65. package/dist/wire/arrow.js.map +1 -0
  66. package/dist/wire/authz.d.ts +2 -2
  67. package/dist/wire/authz.d.ts.map +1 -1
  68. package/dist/wire/authz.js +39 -20
  69. package/dist/wire/authz.js.map +1 -1
  70. package/dist/wire/cbor.d.ts +9 -1
  71. package/dist/wire/cbor.d.ts.map +1 -1
  72. package/dist/wire/cbor.js +45 -2
  73. package/dist/wire/cbor.js.map +1 -1
  74. package/dist/wire/checkpoint.d.ts +386 -0
  75. package/dist/wire/checkpoint.d.ts.map +1 -0
  76. package/dist/wire/checkpoint.js +1373 -0
  77. package/dist/wire/checkpoint.js.map +1 -0
  78. package/dist/wire/codes.d.ts +10 -0
  79. package/dist/wire/codes.d.ts.map +1 -1
  80. package/dist/wire/codes.js +14 -0
  81. package/dist/wire/codes.js.map +1 -1
  82. package/dist/wire/commands.d.ts +14 -5
  83. package/dist/wire/commands.d.ts.map +1 -1
  84. package/dist/wire/commands.js +75 -7
  85. package/dist/wire/commands.js.map +1 -1
  86. package/dist/wire/control.d.ts +3 -12
  87. package/dist/wire/control.d.ts.map +1 -1
  88. package/dist/wire/control.js +10 -43
  89. package/dist/wire/control.js.map +1 -1
  90. package/dist/wire/destination.d.ts +86 -0
  91. package/dist/wire/destination.d.ts.map +1 -0
  92. package/dist/wire/destination.js +251 -0
  93. package/dist/wire/destination.js.map +1 -0
  94. package/dist/wire/headers.d.ts +1 -0
  95. package/dist/wire/headers.d.ts.map +1 -1
  96. package/dist/wire/headers.js +1 -0
  97. package/dist/wire/headers.js.map +1 -1
  98. package/dist/wire/hello.d.ts +83 -11
  99. package/dist/wire/hello.d.ts.map +1 -1
  100. package/dist/wire/hello.js +292 -73
  101. package/dist/wire/hello.js.map +1 -1
  102. package/dist/wire/http.d.ts +153 -1
  103. package/dist/wire/http.d.ts.map +1 -1
  104. package/dist/wire/http.js +491 -10
  105. package/dist/wire/http.js.map +1 -1
  106. package/dist/wire/ids.d.ts +60 -0
  107. package/dist/wire/ids.d.ts.map +1 -1
  108. package/dist/wire/ids.js +143 -0
  109. package/dist/wire/ids.js.map +1 -1
  110. package/dist/wire/index.d.ts +5 -0
  111. package/dist/wire/index.d.ts.map +1 -1
  112. package/dist/wire/index.js +5 -0
  113. package/dist/wire/index.js.map +1 -1
  114. package/dist/wire/kv.d.ts +35 -0
  115. package/dist/wire/kv.d.ts.map +1 -1
  116. package/dist/wire/kv.js +178 -18
  117. package/dist/wire/kv.js.map +1 -1
  118. package/dist/wire/limits.d.ts +10 -0
  119. package/dist/wire/limits.d.ts.map +1 -1
  120. package/dist/wire/limits.js +10 -0
  121. package/dist/wire/limits.js.map +1 -1
  122. package/dist/wire/mutation.d.ts +10 -0
  123. package/dist/wire/mutation.d.ts.map +1 -1
  124. package/dist/wire/mutation.js +14 -0
  125. package/dist/wire/mutation.js.map +1 -1
  126. package/dist/wire/query.d.ts +192 -97
  127. package/dist/wire/query.d.ts.map +1 -1
  128. package/dist/wire/query.js +968 -443
  129. package/dist/wire/query.js.map +1 -1
  130. package/dist/wire/result.d.ts +6 -0
  131. package/dist/wire/result.d.ts.map +1 -1
  132. package/dist/wire/result.js +19 -2
  133. package/dist/wire/result.js.map +1 -1
  134. package/dist/wire/schema.d.ts +121 -0
  135. package/dist/wire/schema.d.ts.map +1 -0
  136. package/dist/wire/schema.js +778 -0
  137. package/dist/wire/schema.js.map +1 -0
  138. package/dist/wire/source.d.ts +35 -0
  139. package/dist/wire/source.d.ts.map +1 -0
  140. package/dist/wire/source.js +105 -0
  141. package/dist/wire/source.js.map +1 -0
  142. package/package.json +5 -5
package/dist/wire/http.js CHANGED
@@ -1,16 +1,22 @@
1
1
  import { CodecError } from "../client/errors.js";
2
2
  import { decodeProjectionInfo, decodeSchemaInfo, encodeProjectionInfo, encodeSchemaInfo } from "./browse.js";
3
- import { expectMap, field } from "./cbor.js";
3
+ import { expectMap, expectString, field } from "./cbor.js";
4
4
  import { decodeSchemaDef, encodeSchemaDef } from "./control.js";
5
5
  import { decodeForkInfo, encodeForkInfo } from "./fork.js";
6
6
  import { decodeBackendDescriptor, decodeOpVersions, encodeBackendDescriptor, encodeOpVersions } from "./hello.js";
7
7
  import { decodeMemoryRowScope, encodeMemoryRowScope } from "./kv.js";
8
- import { consistencyToWord, decodeQueryResult, encodeQueryResult, parseConsistency } from "./query.js";
8
+ import { consistencyToWord, decodeQueryResult, encodeQueryResult, parseConsistency, decodeQueryExecutionStatus, encodeQueryExecutionStatus } from "./query.js";
9
9
  import { decodeSourceRef, encodeSourceRef } from "./graph.js";
10
10
  import {} from "./result.js";
11
11
  import { decodeWireTopology, encodeWireTopology } from "./topology.js";
12
+ import { bigIntToBytes16, bytes16ToBigInt, CheckpointRequestId, crockfordDecode, crockfordEncode, DestinationId, DestinationOperationId } from "./ids.js";
13
+ import { decodeDestinationBlock, decodeDestinationCheckpointStatus, decodePreparedAttemptSummary, decodeRetentionGap, encodeDestinationBlock, encodeDestinationCheckpointStatus, encodePreparedAttemptSummary, encodeRetentionGap } from "./checkpoint.js";
14
+ import { decodeMaterializationDestination, decodeQueryRoute, encodeMaterializationDestination, encodeQueryRoute } from "./destination.js";
15
+ import { decodeLogicalSchema, decodeTypedValue, encodeLogicalSchema, encodeTypedValue } from "./schema.js";
12
16
  export const CAPABILITIES_PATH = "/agdx/capabilities";
13
17
  export const QUERY_PATH = "/agdx/query";
18
+ export const DESTINATIONS_PATH = "/agdx/destinations";
19
+ export const QUERY_ROUTES_PATH = "/agdx/query-routes";
14
20
  export const PROJECTIONS_PATH = "/agdx/projections";
15
21
  export const BINDINGS_PATH = "/agdx/bindings";
16
22
  export const SCHEMAS_PATH = "/agdx/schemas";
@@ -37,6 +43,24 @@ export const forkPromotePath = (id) => `${forkPath(id)}/promote`;
37
43
  export const forkRowsPath = (id) => `${forkPath(id)}/rows`;
38
44
  export const runPath = (id) => `${RUNS_PATH}/${id}`;
39
45
  export const runCancelPath = (id) => `${runPath(id)}/cancel`;
46
+ export const destinationPath = (id) => `${DESTINATIONS_PATH}/${id.toString()}`;
47
+ export const destinationEnablePath = (id) => `${destinationPath(id)}/enable`;
48
+ export const destinationDisablePath = (id) => `${destinationPath(id)}/disable`;
49
+ export const destinationStatusPath = (id) => `${destinationPath(id)}/status`;
50
+ export const destinationCheckpointPath = (id) => `${destinationPath(id)}/checkpoint`;
51
+ export const destinationRetentionGapPath = (id) => `${destinationPath(id)}/retention-gap`;
52
+ export const destinationPreparedAttemptPath = (id) => `${destinationPath(id)}/prepared-attempt`;
53
+ export const destinationTablePath = (id) => `${destinationPath(id)}/table`;
54
+ export const destinationTableSchemaPath = (id) => `${destinationTablePath(id)}/schema`;
55
+ export const destinationSnapshotsPath = (id) => `${destinationTablePath(id)}/snapshots`;
56
+ export const destinationCurrentSnapshotPath = (id) => `${destinationTablePath(id)}/current-snapshot`;
57
+ export const destinationSnapshotPath = (id, snapshotId) => `${destinationSnapshotsPath(id)}/${snapshotId.toString()}`;
58
+ export const destinationFilesPath = (id) => `${destinationTablePath(id)}/files`;
59
+ export const destinationMetricsPath = (id) => `${destinationTablePath(id)}/metrics`;
60
+ export const queryExecutionPath = (id) => `${QUERY_PATH}/${id.toString()}`;
61
+ export const queryPagePath = (id) => `${queryExecutionPath(id)}/pages`;
62
+ export const queryCancelPath = (id) => `${queryExecutionPath(id)}/cancel`;
63
+ export const destinationOperationPath = (id) => `${DESTINATIONS_PATH}/operations/${id.toString()}`;
40
64
  const RESULT_NAMES = new Map([
41
65
  ["ok", { kind: "known", name: "Ok" }],
42
66
  ["unsupported", { kind: "known", name: "Unsupported" }],
@@ -50,7 +74,13 @@ const RESULT_NAMES = new Map([
50
74
  ["backend", { kind: "known", name: "Backend" }],
51
75
  ["forbidden", { kind: "known", name: "Forbidden" }],
52
76
  ["step_up_required", { kind: "known", name: "StepUpRequired" }],
53
- ["unavailable", { kind: "known", name: "Unavailable" }]
77
+ ["unavailable", { kind: "known", name: "Unavailable" }],
78
+ ["resource_limit", { kind: "known", name: "ResourceLimit" }],
79
+ ["cancelled", { kind: "known", name: "Cancelled" }],
80
+ ["deadline_exceeded", { kind: "known", name: "DeadlineExceeded" }],
81
+ ["expired_snapshot", { kind: "known", name: "ExpiredSnapshot" }],
82
+ ["stale_generation", { kind: "known", name: "StaleGeneration" }],
83
+ ["target_unavailable", { kind: "known", name: "TargetUnavailable" }]
54
84
  ]);
55
85
  const RESULT_WORDS = {
56
86
  Ok: "ok",
@@ -65,7 +95,13 @@ const RESULT_WORDS = {
65
95
  Backend: "backend",
66
96
  Forbidden: "forbidden",
67
97
  StepUpRequired: "step_up_required",
68
- Unavailable: "unavailable"
98
+ Unavailable: "unavailable",
99
+ ResourceLimit: "resource_limit",
100
+ Cancelled: "cancelled",
101
+ DeadlineExceeded: "deadline_exceeded",
102
+ ExpiredSnapshot: "expired_snapshot",
103
+ StaleGeneration: "stale_generation",
104
+ TargetUnavailable: "target_unavailable"
69
105
  };
70
106
  function parseJson(text, context) {
71
107
  try {
@@ -77,7 +113,34 @@ function parseJson(text, context) {
77
113
  throw new CodecError(`failed to decode ${context}`, context, "decode", { cause });
78
114
  }
79
115
  }
116
+ const READABLE_ID_FIELDS = new Set([
117
+ "backend_resource_id",
118
+ "cluster",
119
+ "destination_id",
120
+ "execution_id",
121
+ "operation_id",
122
+ "owner",
123
+ "request_id",
124
+ "resource_id"
125
+ ]);
126
+ function isReadableIdContext(context) {
127
+ const fieldName = /\.([^.[\]]+)$/.exec(context)?.[1];
128
+ if (fieldName !== undefined && READABLE_ID_FIELDS.has(fieldName))
129
+ return true;
130
+ return context.endsWith(".destination.id") || /\.routes\[\d+\]\.id$/.test(context);
131
+ }
132
+ function readableIdFromJson(value, context) {
133
+ try {
134
+ return bigIntToBytes16(crockfordDecode(value));
135
+ }
136
+ catch (cause) {
137
+ throw new CodecError(`${context} must be a Crockford base32 id`, context, "string", { cause });
138
+ }
139
+ }
80
140
  function fromJsonValue(value, context) {
141
+ if (typeof value === "string" && isReadableIdContext(context)) {
142
+ return readableIdFromJson(value, context);
143
+ }
81
144
  if (value === null || typeof value === "string" || typeof value === "boolean")
82
145
  return value;
83
146
  if (typeof value === "number") {
@@ -91,7 +154,11 @@ function fromJsonValue(value, context) {
91
154
  return value;
92
155
  }
93
156
  if (Array.isArray(value)) {
94
- if (value.every((item) => Number.isInteger(item) && Number(item) >= 0 && Number(item) <= 255)) {
157
+ if (isReadableIdContext(context)) {
158
+ throw new CodecError(`${context} must be a Crockford base32 id`, context, "string");
159
+ }
160
+ if (value.length > 0 &&
161
+ value.every((item) => Number.isInteger(item) && Number(item) >= 0 && Number(item) <= 255)) {
95
162
  return Uint8Array.from(value);
96
163
  }
97
164
  return value.map((item, index) => fromJsonValue(item, `${context}[${String(index)}]`));
@@ -109,8 +176,15 @@ function toJsonValue(value, context) {
109
176
  }
110
177
  return number;
111
178
  }
112
- if (value instanceof Uint8Array)
179
+ if (value instanceof Uint8Array) {
180
+ if (isReadableIdContext(context)) {
181
+ if (value.length !== 16) {
182
+ throw new CodecError(`${context} must contain 16 bytes`, context, "bytes");
183
+ }
184
+ return crockfordEncode(bytes16ToBigInt(value));
185
+ }
113
186
  return [...value];
187
+ }
114
188
  if (value instanceof Map) {
115
189
  return Object.fromEntries([...value].map(([key, item]) => {
116
190
  if (typeof key !== "string") {
@@ -149,13 +223,383 @@ export function decodeQueryResultJson(text) {
149
223
  return decodeQueryResult(expectMap(parseJson(text, "QueryResult"), "QueryResult"), "QueryResult");
150
224
  }
151
225
  export const encodeQueryResultJson = (result) => encodeJson(encodeQueryResult(result), "QueryResult");
226
+ function fixedBytes(value, length, context) {
227
+ if (value.length !== length) {
228
+ throw new CodecError(`${context} must contain ${String(length)} bytes`, context, "bytes");
229
+ }
230
+ return value;
231
+ }
232
+ function enumWord(map, key, context, values) {
233
+ const value = field.requiredString(map, key, context);
234
+ if (!values.includes(value)) {
235
+ throw new CodecError(`unknown ${key} \`${value}\``, context, key);
236
+ }
237
+ return value;
238
+ }
239
+ function parseResultCode(value, context) {
240
+ const code = RESULT_NAMES.get(value);
241
+ if (code === undefined)
242
+ throw new CodecError(`unknown result code \`${value}\``, context, "code");
243
+ return code;
244
+ }
245
+ function encodeResultCode(value, context) {
246
+ if (value.kind === "unrecognized") {
247
+ throw new CodecError("unrecognized numeric result codes have no JSON spelling", context, "code");
248
+ }
249
+ const word = RESULT_WORDS[value.name];
250
+ if (word === undefined)
251
+ throw new CodecError("result code has no JSON spelling", context, "code");
252
+ return word;
253
+ }
254
+ function decodeStringMap(map, context) {
255
+ return new Map([...map].map(([key, value]) => {
256
+ const name = expectString(key, `${context} key`);
257
+ return [name, expectString(value, `${context}.${name}`)];
258
+ }));
259
+ }
260
+ function encodeStringMap(value) {
261
+ return new Map([...value].sort(([left], [right]) => left.localeCompare(right)));
262
+ }
263
+ function decodeTypedValueMap(map, context) {
264
+ return new Map([...map].map(([key, value]) => {
265
+ const name = expectString(key, `${context} key`);
266
+ return [name, decodeTypedValue(value, `${context}.${name}`)];
267
+ }));
268
+ }
269
+ function encodeTypedValueMap(value) {
270
+ return new Map([...value]
271
+ .sort(([left], [right]) => left.localeCompare(right))
272
+ .map(([key, item]) => [key, encodeTypedValue(item)]));
273
+ }
274
+ function parseFieldId(key, context) {
275
+ const value = Number(key);
276
+ if (!Number.isInteger(value) || value < 0 || value > 0xffff_ffff || String(value) !== key) {
277
+ throw new CodecError(`invalid field id \`${key}\``, context, "key");
278
+ }
279
+ return value;
280
+ }
281
+ function decodeFieldValueMap(map, context) {
282
+ return new Map([...map].map(([key, value]) => {
283
+ const name = expectString(key, `${context} key`);
284
+ return [parseFieldId(name, context), decodeTypedValue(value, `${context}.${name}`)];
285
+ }));
286
+ }
287
+ function encodeFieldValueMap(value) {
288
+ return new Map([...value]
289
+ .sort(([left], [right]) => left - right)
290
+ .map(([key, item]) => [String(key), encodeTypedValue(item)]));
291
+ }
292
+ function decodeFieldCountMap(map, context) {
293
+ return new Map([...map].map(([key]) => {
294
+ const name = expectString(key, `${context} key`);
295
+ return [parseFieldId(name, context), field.requiredU64(map, name, context)];
296
+ }));
297
+ }
298
+ function encodeFieldCountMap(value) {
299
+ return new Map([...value].sort(([left], [right]) => left - right).map(([key, item]) => [String(key), item]));
300
+ }
301
+ function decodeDestinationView(map, context) {
302
+ return {
303
+ destination: decodeMaterializationDestination(field.requiredMap(map, "destination", context), `${context}.destination`),
304
+ status: decodeDestinationCheckpointStatus(field.requiredMap(map, "status", context), `${context}.status`)
305
+ };
306
+ }
307
+ function encodeDestinationView(value) {
308
+ return new Map([
309
+ ["destination", encodeMaterializationDestination(value.destination)],
310
+ ["status", encodeDestinationCheckpointStatus(value.status)]
311
+ ]);
312
+ }
313
+ export function decodeDestinationPageJson(text) {
314
+ const context = "DestinationPageView";
315
+ const map = expectMap(parseJson(text, context), context);
316
+ const nextCursor = field.optionalString(map, "next_cursor", context);
317
+ return {
318
+ destinations: field.requiredArray(map, "destinations", context, (item, index) => decodeDestinationView(expectMap(item, `${context}.destinations[${String(index)}]`), `${context}.destinations[${String(index)}]`)),
319
+ ...(nextCursor === undefined ? {} : { nextCursor }),
320
+ globalStateRevision: field.requiredU64(map, "global_state_revision", context),
321
+ consistency: enumWord(map, "consistency", context, ["linearizable", "potentially_stale"])
322
+ };
323
+ }
324
+ export function encodeDestinationPageJson(value) {
325
+ const map = new Map([
326
+ ["destinations", value.destinations.map(encodeDestinationView)]
327
+ ]);
328
+ if (value.nextCursor !== undefined)
329
+ map.set("next_cursor", value.nextCursor);
330
+ map.set("global_state_revision", value.globalStateRevision);
331
+ map.set("consistency", value.consistency);
332
+ return encodeJson(map, "DestinationPageView");
333
+ }
334
+ export function decodeQueryRoutePageJson(text) {
335
+ const context = "QueryRoutePageView";
336
+ const map = expectMap(parseJson(text, context), context);
337
+ const nextCursor = field.optionalString(map, "next_cursor", context);
338
+ return {
339
+ routes: field.requiredArray(map, "routes", context, (item, index) => decodeQueryRoute(expectMap(item, `${context}.routes[${String(index)}]`), `${context}.routes[${String(index)}]`)),
340
+ ...(nextCursor === undefined ? {} : { nextCursor }),
341
+ definitionRevision: field.requiredU64(map, "definition_revision", context)
342
+ };
343
+ }
344
+ export function encodeQueryRoutePageJson(value) {
345
+ const map = new Map([["routes", value.routes.map(encodeQueryRoute)]]);
346
+ if (value.nextCursor !== undefined)
347
+ map.set("next_cursor", value.nextCursor);
348
+ map.set("definition_revision", value.definitionRevision);
349
+ return encodeJson(map, "QueryRoutePageView");
350
+ }
351
+ export function decodeTableViewJson(text) {
352
+ const context = "TableView";
353
+ const map = expectMap(parseJson(text, context), context);
354
+ return {
355
+ tableUuid: fixedBytes(field.requiredBytes(map, "table_uuid", context), 16, `${context}.table_uuid`),
356
+ destinationId: DestinationId.fromBytes(field.requiredBytes(map, "destination_id", context)),
357
+ destinationGeneration: field.requiredU64(map, "destination_generation", context),
358
+ namespace: field.requiredArray(map, "namespace", context, (item, index) => expectString(item, `${context}.namespace[${String(index)}]`)),
359
+ table: field.requiredString(map, "table", context),
360
+ currentSnapshotId: field.requiredI64(map, "current_snapshot_id", context),
361
+ currentSchemaId: field.requiredI32(map, "current_schema_id", context),
362
+ currentPartitionSpecId: field.requiredI32(map, "current_partition_spec_id", context),
363
+ metadataIdentity: field.requiredString(map, "metadata_identity", context),
364
+ properties: decodeStringMap(field.requiredMap(map, "properties", context), `${context}.properties`)
365
+ };
366
+ }
367
+ export function encodeTableViewJson(value) {
368
+ return encodeJson(new Map([
369
+ ["table_uuid", value.tableUuid],
370
+ ["destination_id", value.destinationId.toBytes()],
371
+ ["destination_generation", value.destinationGeneration],
372
+ ["namespace", [...value.namespace]],
373
+ ["table", value.table],
374
+ ["current_snapshot_id", value.currentSnapshotId],
375
+ ["current_schema_id", value.currentSchemaId],
376
+ ["current_partition_spec_id", value.currentPartitionSpecId],
377
+ ["metadata_identity", value.metadataIdentity],
378
+ ["properties", encodeStringMap(value.properties)]
379
+ ]), "TableView");
380
+ }
381
+ export function decodeTableSchemaJson(text) {
382
+ const context = "TableSchemaView";
383
+ const map = expectMap(parseJson(text, context), context);
384
+ return {
385
+ tableUuid: fixedBytes(field.requiredBytes(map, "table_uuid", context), 16, `${context}.table_uuid`),
386
+ icebergSchemaId: field.requiredI32(map, "iceberg_schema_id", context),
387
+ logicalSchema: decodeLogicalSchema(field.requiredMap(map, "logical_schema", context), `${context}.logical_schema`)
388
+ };
389
+ }
390
+ export function encodeTableSchemaJson(value) {
391
+ return encodeJson(new Map([
392
+ ["table_uuid", value.tableUuid],
393
+ ["iceberg_schema_id", value.icebergSchemaId],
394
+ ["logical_schema", encodeLogicalSchema(value.logicalSchema)]
395
+ ]), "TableSchemaView");
396
+ }
397
+ function decodeTableSnapshot(map, context) {
398
+ const parentSnapshotId = field.optionalI64(map, "parent_snapshot_id", context);
399
+ return {
400
+ snapshotId: field.requiredI64(map, "snapshot_id", context),
401
+ ...(parentSnapshotId === undefined ? {} : { parentSnapshotId }),
402
+ sequenceNumber: field.requiredI64(map, "sequence_number", context),
403
+ committedAtMicros: field.requiredU64(map, "committed_at_micros", context),
404
+ schemaId: field.requiredI32(map, "schema_id", context),
405
+ partitionSpecId: field.requiredI32(map, "partition_spec_id", context),
406
+ materializationBoundaryDigest: fixedBytes(field.requiredBytes(map, "materialization_boundary_digest", context), 32, `${context}.materialization_boundary_digest`),
407
+ checkpointRevision: field.requiredU64(map, "checkpoint_revision", context),
408
+ summary: decodeStringMap(field.requiredMap(map, "summary", context), `${context}.summary`)
409
+ };
410
+ }
411
+ function encodeTableSnapshot(value) {
412
+ const map = new Map([["snapshot_id", value.snapshotId]]);
413
+ if (value.parentSnapshotId !== undefined)
414
+ map.set("parent_snapshot_id", value.parentSnapshotId);
415
+ map.set("sequence_number", value.sequenceNumber);
416
+ map.set("committed_at_micros", value.committedAtMicros);
417
+ map.set("schema_id", value.schemaId);
418
+ map.set("partition_spec_id", value.partitionSpecId);
419
+ map.set("materialization_boundary_digest", value.materializationBoundaryDigest);
420
+ map.set("checkpoint_revision", value.checkpointRevision);
421
+ map.set("summary", encodeStringMap(value.summary));
422
+ return map;
423
+ }
424
+ export function decodeSnapshotPageJson(text) {
425
+ const context = "SnapshotPageView";
426
+ const map = expectMap(parseJson(text, context), context);
427
+ const nextBeforeSnapshotId = field.optionalI64(map, "next_before_snapshot_id", context);
428
+ return {
429
+ snapshots: field.requiredArray(map, "snapshots", context, (item, index) => decodeTableSnapshot(expectMap(item, `${context}.snapshots[${String(index)}]`), `${context}.snapshots[${String(index)}]`)),
430
+ ...(nextBeforeSnapshotId === undefined ? {} : { nextBeforeSnapshotId })
431
+ };
432
+ }
433
+ export function encodeSnapshotPageJson(value) {
434
+ const map = new Map([["snapshots", value.snapshots.map(encodeTableSnapshot)]]);
435
+ if (value.nextBeforeSnapshotId !== undefined) {
436
+ map.set("next_before_snapshot_id", value.nextBeforeSnapshotId);
437
+ }
438
+ return encodeJson(map, "SnapshotPageView");
439
+ }
440
+ function decodeTableFile(map, context) {
441
+ return {
442
+ objectIdentity: field.requiredString(map, "object_identity", context),
443
+ fileSizeBytes: field.requiredU64(map, "file_size_bytes", context),
444
+ rowCount: field.requiredU64(map, "row_count", context),
445
+ partition: decodeTypedValueMap(field.requiredMap(map, "partition", context), `${context}.partition`),
446
+ lowerBounds: decodeFieldValueMap(field.requiredMap(map, "lower_bounds", context), `${context}.lower_bounds`),
447
+ upperBounds: decodeFieldValueMap(field.requiredMap(map, "upper_bounds", context), `${context}.upper_bounds`),
448
+ nullValueCounts: decodeFieldCountMap(field.requiredMap(map, "null_value_counts", context), `${context}.null_value_counts`)
449
+ };
450
+ }
451
+ function encodeTableFile(value) {
452
+ return new Map([
453
+ ["object_identity", value.objectIdentity],
454
+ ["file_size_bytes", value.fileSizeBytes],
455
+ ["row_count", value.rowCount],
456
+ ["partition", encodeTypedValueMap(value.partition)],
457
+ ["lower_bounds", encodeFieldValueMap(value.lowerBounds)],
458
+ ["upper_bounds", encodeFieldValueMap(value.upperBounds)],
459
+ ["null_value_counts", encodeFieldCountMap(value.nullValueCounts)]
460
+ ]);
461
+ }
462
+ export function decodeTableFilePageJson(text) {
463
+ const context = "TableFilePageView";
464
+ const map = expectMap(parseJson(text, context), context);
465
+ const nextCursor = field.optionalString(map, "next_cursor", context);
466
+ return {
467
+ files: field.requiredArray(map, "files", context, (item, index) => decodeTableFile(expectMap(item, `${context}.files[${String(index)}]`), `${context}.files[${String(index)}]`)),
468
+ ...(nextCursor === undefined ? {} : { nextCursor })
469
+ };
470
+ }
471
+ export function encodeTableFilePageJson(value) {
472
+ const map = new Map([["files", value.files.map(encodeTableFile)]]);
473
+ if (value.nextCursor !== undefined)
474
+ map.set("next_cursor", value.nextCursor);
475
+ return encodeJson(map, "TableFilePageView");
476
+ }
477
+ export function decodeTableMetricsJson(text) {
478
+ const context = "TableMetricsView";
479
+ const map = expectMap(parseJson(text, context), context);
480
+ return {
481
+ snapshotId: field.requiredI64(map, "snapshot_id", context),
482
+ dataFileCount: field.requiredU64(map, "data_file_count", context),
483
+ deleteFileCount: field.requiredU64(map, "delete_file_count", context),
484
+ totalRows: field.requiredU64(map, "total_rows", context),
485
+ totalBytes: field.requiredU64(map, "total_bytes", context),
486
+ partitionCount: field.requiredU64(map, "partition_count", context)
487
+ };
488
+ }
489
+ export function encodeTableMetricsJson(value) {
490
+ return encodeJson(new Map([
491
+ ["snapshot_id", value.snapshotId],
492
+ ["data_file_count", value.dataFileCount],
493
+ ["delete_file_count", value.deleteFileCount],
494
+ ["total_rows", value.totalRows],
495
+ ["total_bytes", value.totalBytes],
496
+ ["partition_count", value.partitionCount]
497
+ ]), "TableMetricsView");
498
+ }
499
+ export function decodeAcceptedOperationJson(text) {
500
+ const context = "AcceptedOperationView";
501
+ const map = expectMap(parseJson(text, context), context);
502
+ const completedAtMicros = field.optionalU64(map, "completed_at_micros", context);
503
+ const error = field.optionalMap(map, "error", context);
504
+ return {
505
+ operationId: DestinationOperationId.fromBytes(field.requiredBytes(map, "operation_id", context)),
506
+ requestId: CheckpointRequestId.fromBytes(field.requiredBytes(map, "request_id", context)),
507
+ state: enumWord(map, "state", context, [
508
+ "accepted",
509
+ "running",
510
+ "succeeded",
511
+ "failed",
512
+ "cancelled"
513
+ ]),
514
+ submittedAtMicros: field.requiredU64(map, "submitted_at_micros", context),
515
+ ...(completedAtMicros === undefined ? {} : { completedAtMicros }),
516
+ ...(error === undefined
517
+ ? {}
518
+ : {
519
+ error: {
520
+ code: parseResultCode(field.requiredString(error, "code", context), `${context}.error`),
521
+ message: field.requiredString(error, "message", context)
522
+ }
523
+ })
524
+ };
525
+ }
526
+ export function encodeAcceptedOperationJson(value) {
527
+ const context = "AcceptedOperationView";
528
+ const map = new Map([
529
+ ["operation_id", value.operationId.toBytes()],
530
+ ["request_id", value.requestId.toBytes()],
531
+ ["state", value.state],
532
+ ["submitted_at_micros", value.submittedAtMicros]
533
+ ]);
534
+ if (value.completedAtMicros !== undefined)
535
+ map.set("completed_at_micros", value.completedAtMicros);
536
+ if (value.error !== undefined) {
537
+ map.set("error", new Map([
538
+ ["code", encodeResultCode(value.error.code, `${context}.error`)],
539
+ ["message", value.error.message]
540
+ ]));
541
+ }
542
+ return encodeJson(map, "AcceptedOperationView");
543
+ }
544
+ export function decodeQueryExecutionJson(text) {
545
+ const context = "QueryExecutionView";
546
+ const map = expectMap(parseJson(text, context), context);
547
+ const result = field.optionalMap(map, "result", context);
548
+ return {
549
+ status: decodeQueryExecutionStatus(field.requiredMap(map, "status", context), `${context}.status`),
550
+ ...(result === undefined ? {} : { result: decodeQueryResult(result, `${context}.result`) })
551
+ };
552
+ }
553
+ export function encodeQueryExecutionJson(value) {
554
+ const map = new Map([["status", encodeQueryExecutionStatus(value.status)]]);
555
+ if (value.result !== undefined)
556
+ map.set("result", encodeQueryResult(value.result));
557
+ return encodeJson(map, "QueryExecutionView");
558
+ }
559
+ export function decodeDestinationIssueJson(text) {
560
+ const context = "DestinationIssueView";
561
+ const map = expectMap(parseJson(text, context), context);
562
+ const retentionGap = field.optionalMap(map, "retention_gap", context);
563
+ const preparedAttempt = field.optionalMap(map, "prepared_attempt", context);
564
+ const block = field.optionalMap(map, "block", context);
565
+ return {
566
+ ...(retentionGap === undefined
567
+ ? {}
568
+ : { retentionGap: decodeRetentionGap(retentionGap, `${context}.retention_gap`) }),
569
+ ...(preparedAttempt === undefined
570
+ ? {}
571
+ : {
572
+ preparedAttempt: decodePreparedAttemptSummary(preparedAttempt, `${context}.prepared_attempt`)
573
+ }),
574
+ ...(block === undefined ? {} : { block: decodeDestinationBlock(block, `${context}.block`) }),
575
+ checkpointRevision: field.requiredU64(map, "checkpoint_revision", context),
576
+ consistency: enumWord(map, "consistency", context, ["linearizable", "potentially_stale"])
577
+ };
578
+ }
579
+ export function encodeDestinationIssueJson(value) {
580
+ const map = new Map();
581
+ if (value.retentionGap !== undefined) {
582
+ map.set("retention_gap", encodeRetentionGap(value.retentionGap));
583
+ }
584
+ if (value.preparedAttempt !== undefined) {
585
+ map.set("prepared_attempt", encodePreparedAttemptSummary(value.preparedAttempt));
586
+ }
587
+ if (value.block !== undefined)
588
+ map.set("block", encodeDestinationBlock(value.block));
589
+ map.set("checkpoint_revision", value.checkpointRevision);
590
+ map.set("consistency", value.consistency);
591
+ return encodeJson(map, "DestinationIssueView");
592
+ }
152
593
  function decodeQueryCaps(map, context) {
153
594
  return {
154
595
  available: field.requiredBoolean(map, "available", context),
155
596
  projections: field.requiredBoolean(map, "projections", context),
156
597
  schemas: field.requiredBoolean(map, "schemas", context),
157
598
  consistency: parseConsistency(field.optionalString(map, "consistency", context) ?? "eventual", context),
158
- keyword: field.optionalBoolean(map, "keyword", context) ?? false
599
+ keyword: field.optionalBoolean(map, "keyword", context) ?? false,
600
+ cursorPaging: field.optionalBoolean(map, "cursor_paging", context) ?? false,
601
+ cancellation: field.optionalBoolean(map, "cancellation", context) ?? false,
602
+ executionStatus: field.optionalBoolean(map, "execution_status", context) ?? false
159
603
  };
160
604
  }
161
605
  function encodeQueryCaps(value) {
@@ -164,7 +608,40 @@ function encodeQueryCaps(value) {
164
608
  ["projections", value.projections],
165
609
  ["schemas", value.schemas],
166
610
  ["consistency", consistencyToWord(value.consistency)],
167
- ["keyword", value.keyword]
611
+ ["keyword", value.keyword],
612
+ ["cursor_paging", value.cursorPaging],
613
+ ["cancellation", value.cancellation],
614
+ ["execution_status", value.executionStatus]
615
+ ]);
616
+ }
617
+ function decodeDestinationCaps(map, context) {
618
+ const consistency = field.optionalString(map, "strongest_consistency", context) ?? "potentially_stale";
619
+ if (consistency !== "potentially_stale" && consistency !== "linearizable") {
620
+ throw new CodecError(`unknown checkpoint consistency \`${consistency}\``, context, "strongest_consistency");
621
+ }
622
+ return {
623
+ available: field.requiredBoolean(map, "available", context),
624
+ lifecycle: field.optionalBoolean(map, "lifecycle", context) ?? false,
625
+ checkpointStatus: field.optionalBoolean(map, "checkpoint_status", context) ?? false,
626
+ queryRoutes: field.optionalBoolean(map, "query_routes", context) ?? false,
627
+ tableSchema: field.optionalBoolean(map, "table_schema", context) ?? false,
628
+ snapshots: field.optionalBoolean(map, "snapshots", context) ?? false,
629
+ files: field.optionalBoolean(map, "files", context) ?? false,
630
+ metrics: field.optionalBoolean(map, "metrics", context) ?? false,
631
+ strongestConsistency: consistency
632
+ };
633
+ }
634
+ function encodeDestinationCaps(value) {
635
+ return new Map([
636
+ ["available", value.available],
637
+ ["lifecycle", value.lifecycle],
638
+ ["checkpoint_status", value.checkpointStatus],
639
+ ["query_routes", value.queryRoutes],
640
+ ["table_schema", value.tableSchema],
641
+ ["snapshots", value.snapshots],
642
+ ["files", value.files],
643
+ ["metrics", value.metrics],
644
+ ["strongest_consistency", value.strongestConsistency]
168
645
  ]);
169
646
  }
170
647
  export function decodeCapabilitiesJson(text) {
@@ -174,11 +651,13 @@ export function decodeCapabilitiesJson(text) {
174
651
  return {
175
652
  managed: field.requiredBoolean(map, "managed", context),
176
653
  query: decodeQueryCaps(field.requiredMap(map, "query", context), `${context}.query`),
654
+ destinations: decodeDestinationCaps(field.requiredMap(map, "destinations", context), `${context}.destinations`),
177
655
  kv: {
178
656
  available: field.requiredBoolean(field.requiredMap(map, "kv", context), "available", `${context}.kv`),
179
657
  cas: field.optionalBoolean(field.requiredMap(map, "kv", context), "cas", `${context}.kv`) ??
180
658
  false,
181
- casFenced: field.optionalBoolean(field.requiredMap(map, "kv", context), "cas_fenced", `${context}.kv`) ?? false
659
+ casFenced: field.optionalBoolean(field.requiredMap(map, "kv", context), "cas_fenced", `${context}.kv`) ?? false,
660
+ fencedLeases: field.optionalBoolean(field.requiredMap(map, "kv", context), "fenced_leases", `${context}.kv`) ?? false
182
661
  },
183
662
  graph: field.optionalBoolean(map, "graph", context) ?? false,
184
663
  fork: field.requiredBoolean(map, "fork", context),
@@ -196,12 +675,14 @@ export function encodeCapabilitiesJson(value) {
196
675
  const map = new Map([
197
676
  ["managed", value.managed],
198
677
  ["query", encodeQueryCaps(value.query)],
678
+ ["destinations", encodeDestinationCaps(value.destinations)],
199
679
  [
200
680
  "kv",
201
681
  new Map([
202
682
  ["available", value.kv.available],
203
683
  ["cas", value.kv.cas],
204
- ["cas_fenced", value.kv.casFenced]
684
+ ["cas_fenced", value.kv.casFenced],
685
+ ["fenced_leases", value.kv.fencedLeases]
205
686
  ])
206
687
  ],
207
688
  ["graph", value.graph],