@opengeni/contracts 0.40.0 → 0.44.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 (125) hide show
  1. package/dist/atlassian.d.ts +278 -0
  2. package/dist/atlassian.js +55 -0
  3. package/dist/atlassian.js.map +1 -0
  4. package/dist/chunk-52SGB2QO.js +688 -0
  5. package/dist/chunk-52SGB2QO.js.map +1 -0
  6. package/dist/{chunk-7JZMI22I.js → chunk-5UDNP7AO.js} +34 -2
  7. package/dist/chunk-5UDNP7AO.js.map +1 -0
  8. package/dist/chunk-BVGIYW7D.js +11 -0
  9. package/dist/chunk-BVGIYW7D.js.map +1 -0
  10. package/dist/chunk-CADSX6UN.js +1145 -0
  11. package/dist/chunk-CADSX6UN.js.map +1 -0
  12. package/dist/chunk-D2HKF2EF.js +1460 -0
  13. package/dist/chunk-D2HKF2EF.js.map +1 -0
  14. package/dist/chunk-FJBG5E4O.js +194 -0
  15. package/dist/chunk-FJBG5E4O.js.map +1 -0
  16. package/dist/chunk-H5BVCZKF.js +382 -0
  17. package/dist/chunk-H5BVCZKF.js.map +1 -0
  18. package/dist/chunk-LSB7GRLG.js +779 -0
  19. package/dist/chunk-LSB7GRLG.js.map +1 -0
  20. package/dist/chunk-MYBZRDTY.js +340 -0
  21. package/dist/chunk-MYBZRDTY.js.map +1 -0
  22. package/dist/chunk-RIY7GYQS.js +1204 -0
  23. package/dist/chunk-RIY7GYQS.js.map +1 -0
  24. package/dist/chunk-TZ6YEYN4.js +386 -0
  25. package/dist/chunk-TZ6YEYN4.js.map +1 -0
  26. package/dist/chunk-VA22KRHS.js +15177 -0
  27. package/dist/chunk-VA22KRHS.js.map +1 -0
  28. package/dist/chunk-Y3MLSLB4.js +392 -0
  29. package/dist/chunk-Y3MLSLB4.js.map +1 -0
  30. package/dist/chunk-YRKRZ6OF.js +134 -0
  31. package/dist/chunk-YRKRZ6OF.js.map +1 -0
  32. package/dist/company-profile.d.ts +629 -0
  33. package/dist/document-artifact-commands.d.ts +282 -0
  34. package/dist/document-artifact-commands.js +54 -0
  35. package/dist/document-artifact-commands.js.map +1 -0
  36. package/dist/document-artifact-query.d.ts +2 -0
  37. package/dist/document-artifact-query.js +54 -0
  38. package/dist/document-artifact-query.js.map +1 -0
  39. package/dist/editable-artifact-binary.d.ts +56 -0
  40. package/dist/editable-artifact-causal-frontier.d.ts +12 -0
  41. package/dist/editable-artifact-causal-frontier.js +18 -0
  42. package/dist/editable-artifact-causal-frontier.js.map +1 -0
  43. package/dist/editable-artifact-codec-registry.d.ts +48 -0
  44. package/dist/editable-artifact-codec-registry.js +20 -0
  45. package/dist/editable-artifact-codec-registry.js.map +1 -0
  46. package/dist/editable-artifact-committed-transaction.d.ts +35 -0
  47. package/dist/editable-artifact-committed-transaction.js +19 -0
  48. package/dist/editable-artifact-committed-transaction.js.map +1 -0
  49. package/dist/editable-artifact-live.d.ts +276 -0
  50. package/dist/editable-artifact-live.js +907 -0
  51. package/dist/editable-artifact-live.js.map +1 -0
  52. package/dist/editable-artifact-serialized-commit.d.ts +53 -0
  53. package/dist/editable-artifact-serialized-commit.js +26 -0
  54. package/dist/editable-artifact-serialized-commit.js.map +1 -0
  55. package/dist/editable-artifact-versions.d.ts +6 -0
  56. package/dist/editable-artifact-versions.js +11 -0
  57. package/dist/editable-artifact-versions.js.map +1 -0
  58. package/dist/editable-artifacts.d.ts +46 -0
  59. package/dist/editable-artifacts.js +236 -0
  60. package/dist/editable-artifacts.js.map +1 -0
  61. package/dist/event-preview.d.ts +1 -1
  62. package/dist/google-drive.d.ts +114 -2
  63. package/dist/google-drive.js +70 -14
  64. package/dist/google-drive.js.map +1 -1
  65. package/dist/image-generation.d.ts +70 -0
  66. package/dist/index.d.ts +4460 -155
  67. package/dist/index.js +1127 -30
  68. package/dist/interaction.d.ts +6895 -0
  69. package/dist/memory-slack-delivery.d.ts +397 -0
  70. package/dist/presentation-artifact-commands.d.ts +349 -0
  71. package/dist/presentation-artifact-commands.js +66 -0
  72. package/dist/presentation-artifact-commands.js.map +1 -0
  73. package/dist/presentation-artifact-query.d.ts +2 -0
  74. package/dist/presentation-artifact-query.js +66 -0
  75. package/dist/presentation-artifact-query.js.map +1 -0
  76. package/dist/retained-output.d.ts +24 -0
  77. package/dist/sandbox-snapshots.d.ts +9 -0
  78. package/dist/scoped-knowledge.d.ts +14 -13
  79. package/dist/slack-bot-scopes.d.ts +4 -0
  80. package/dist/slack-bot-scopes.js +3 -1
  81. package/dist/spreadsheet-artifact-commands.d.ts +101 -0
  82. package/dist/spreadsheet-artifact-commands.js +27 -0
  83. package/dist/spreadsheet-artifact-commands.js.map +1 -0
  84. package/dist/spreadsheet-artifact-date.d.ts +4 -0
  85. package/dist/spreadsheet-artifact-query.d.ts +120 -0
  86. package/dist/spreadsheet-artifact-query.js +48 -0
  87. package/dist/spreadsheet-artifact-query.js.map +1 -0
  88. package/dist/tool-catalog.d.ts +576 -0
  89. package/dist/video-generation.d.ts +532 -0
  90. package/dist/video-generation.js +51 -0
  91. package/dist/video-generation.js.map +1 -0
  92. package/dist/workspace-learning-policy.d.ts +208 -0
  93. package/package.json +61 -1
  94. package/src/atlassian.ts +160 -0
  95. package/src/company-profile.ts +306 -0
  96. package/src/document-artifact-commands.ts +1709 -0
  97. package/src/document-artifact-query.ts +2 -0
  98. package/src/editable-artifact-binary.ts +396 -0
  99. package/src/editable-artifact-causal-frontier.ts +154 -0
  100. package/src/editable-artifact-codec-registry.ts +261 -0
  101. package/src/editable-artifact-committed-transaction.ts +478 -0
  102. package/src/editable-artifact-live.ts +1379 -0
  103. package/src/editable-artifact-serialized-commit.ts +494 -0
  104. package/src/editable-artifact-versions.ts +8 -0
  105. package/src/editable-artifacts.ts +473 -0
  106. package/src/google-drive.ts +68 -15
  107. package/src/image-generation.ts +106 -0
  108. package/src/index.ts +2326 -325
  109. package/src/interaction.ts +2292 -0
  110. package/src/memory-slack-delivery.ts +183 -0
  111. package/src/presentation-artifact-commands.ts +2035 -0
  112. package/src/presentation-artifact-query.ts +2 -0
  113. package/src/retained-output.ts +149 -2
  114. package/src/sandbox-snapshots.ts +28 -1
  115. package/src/scoped-knowledge.ts +18 -4
  116. package/src/slack-bot-scopes.ts +34 -1
  117. package/src/spreadsheet-artifact-commands.ts +999 -0
  118. package/src/spreadsheet-artifact-date.ts +21 -0
  119. package/src/spreadsheet-artifact-query.ts +1411 -0
  120. package/src/tool-catalog.ts +334 -0
  121. package/src/video-generation.ts +394 -0
  122. package/src/workspace-learning-policy.ts +233 -0
  123. package/dist/chunk-5HR2GPSC.js +0 -11031
  124. package/dist/chunk-5HR2GPSC.js.map +0 -1
  125. package/dist/chunk-7JZMI22I.js.map +0 -1
@@ -0,0 +1,1145 @@
1
+ import {
2
+ canonicalSpreadsheetDateFromMilliseconds,
3
+ canonicalSpreadsheetDateMilliseconds,
4
+ spreadsheetSheetId
5
+ } from "./chunk-LSB7GRLG.js";
6
+
7
+ // src/spreadsheet-artifact-query.ts
8
+ var SPREADSHEET_ARTIFACT_QUERY_VERSION = 1;
9
+ var SPREADSHEET_ARTIFACT_QUERY_MAX_BYTES = 68;
10
+ var SPREADSHEET_ARTIFACT_PROJECTION_MAX_BYTES = 8 * 1024 * 1024;
11
+ var SPREADSHEET_ARTIFACT_VIEWPORT_MAX_AREA = 1048576;
12
+ var SPREADSHEET_ARTIFACT_VIEWPORT_MAX_CELLS = 262144;
13
+ var SPREADSHEET_ARTIFACT_METADATA_MAX_SHEETS = 1e4;
14
+ var SPREADSHEET_ARTIFACT_PROJECTION_MAX_STRING_BYTES = 4 * 1024 * 1024;
15
+ var SPREADSHEET_ARTIFACT_VIEWPORT_MIN_RESPONSE_BYTES = 92;
16
+ var SPREADSHEET_ARTIFACT_METADATA_MIN_RESPONSE_BYTES = 48;
17
+ var QUERY_MAGIC = new TextEncoder().encode("OGAKQ001");
18
+ var PROJECTION_MAGIC = new TextEncoder().encode("OGAKV001");
19
+ var QUERY_HEADER_BYTES = 28;
20
+ var PROJECTION_HEADER_BYTES = 36;
21
+ var CHECKSUM_BYTES = 8;
22
+ var VIEWPORT_QUERY_PAYLOAD_BYTES = 32;
23
+ var VIEWPORT_PROJECTION_PREFIX_BYTES = 48;
24
+ var METADATA_PROJECTION_PREFIX_BYTES = 4;
25
+ var GENERATIONS_FLAG = 1;
26
+ var UINT32_MAX = 4294967295;
27
+ var UINT64_MAX = 0xffffffffffffffffn;
28
+ var FNV_OFFSET = 0xcbf29ce484222325n;
29
+ var FNV_PRIME = 0x100000001b3n;
30
+ var textEncoder = new TextEncoder();
31
+ var textDecoder = new TextDecoder("utf-8", { fatal: true });
32
+ function encodeSpreadsheetViewportKernelQuery(input) {
33
+ const query = normalizeViewportQuery(input);
34
+ const payload = new FixedWriter(VIEWPORT_QUERY_PAYLOAD_BYTES);
35
+ payload.stableId(query.sheetId);
36
+ payload.u32(query.startRow);
37
+ payload.u32(query.startColumn);
38
+ payload.u32(query.rowCount);
39
+ payload.u32(query.columnCount);
40
+ return encodeQueryFrame(0, query.maxCells, query.maxBytes, payload.finish());
41
+ }
42
+ function encodeSpreadsheetMetadataKernelQuery(input) {
43
+ const query = normalizeMetadataQuery(input);
44
+ return encodeQueryFrame(1, query.maxSheets, query.maxBytes, new Uint8Array());
45
+ }
46
+ function encodeSpreadsheetArtifactKernelQuery(input) {
47
+ const envelope = exactRecord(input, "spreadsheet kernel query");
48
+ exactKeys(envelope, ["kind", "query"], "spreadsheet kernel query");
49
+ if (envelope.kind === "viewport") {
50
+ return encodeSpreadsheetViewportKernelQuery(envelope.query);
51
+ }
52
+ if (envelope.kind === "workbook-metadata") {
53
+ return encodeSpreadsheetMetadataKernelQuery(envelope.query);
54
+ }
55
+ throw queryError("unknown spreadsheet kernel query kind");
56
+ }
57
+ function decodeSpreadsheetArtifactKernelQuery(bytes) {
58
+ const frame = decodeQueryFrame(bytes);
59
+ if (frame.kind === 0) {
60
+ if (frame.payload.byteLength < VIEWPORT_QUERY_PAYLOAD_BYTES) {
61
+ throw queryError("spreadsheet viewport query is truncated");
62
+ }
63
+ if (frame.payload.byteLength > VIEWPORT_QUERY_PAYLOAD_BYTES) {
64
+ throw queryError("spreadsheet viewport query contains trailing bytes");
65
+ }
66
+ const reader = new Reader(frame.payload);
67
+ const query = normalizeViewportQuery({
68
+ sheetId: reader.stableId("viewport sheet id"),
69
+ startRow: reader.u32(),
70
+ startColumn: reader.u32(),
71
+ rowCount: reader.u32(),
72
+ columnCount: reader.u32(),
73
+ maxCells: frame.maxItems,
74
+ maxBytes: frame.maxBytes
75
+ });
76
+ reader.done("spreadsheet viewport query contains trailing bytes");
77
+ return Object.freeze({ kind: "viewport", query });
78
+ }
79
+ if (frame.payload.byteLength !== 0) {
80
+ throw queryError("spreadsheet metadata query contains trailing bytes");
81
+ }
82
+ return Object.freeze({
83
+ kind: "workbook-metadata",
84
+ query: normalizeMetadataQuery({
85
+ maxSheets: frame.maxItems,
86
+ maxBytes: frame.maxBytes
87
+ })
88
+ });
89
+ }
90
+ function assertCanonicalSpreadsheetArtifactKernelQueryBytes(bytes) {
91
+ const canonical = encodeSpreadsheetArtifactKernelQuery(
92
+ decodeSpreadsheetArtifactKernelQuery(bytes)
93
+ );
94
+ if (!equalBytes(bytes, canonical)) throw queryError("spreadsheet kernel query is not canonical");
95
+ return bytes;
96
+ }
97
+ function encodeSpreadsheetViewportKernelProjection(input, maximumBytes = SPREADSHEET_ARTIFACT_PROJECTION_MAX_BYTES) {
98
+ const projection = normalizeViewportProjection(input);
99
+ const maximum = effectiveProjectionMaximum(
100
+ maximumBytes,
101
+ SPREADSHEET_ARTIFACT_VIEWPORT_MIN_RESPONSE_BYTES
102
+ );
103
+ const payload = new DynamicWriter(maximum - PROJECTION_HEADER_BYTES - CHECKSUM_BYTES);
104
+ payload.stableId(projection.sheetId);
105
+ payload.optionalStableId(projection.generationId);
106
+ payload.u32(projection.startRow);
107
+ payload.u32(projection.startColumn);
108
+ payload.u32(projection.rowCount);
109
+ payload.u32(projection.columnCount);
110
+ for (const cell of projection.cells) {
111
+ payload.u32(cell.row - projection.startRow);
112
+ payload.u32(cell.column - projection.startColumn);
113
+ payload.cell(cell);
114
+ }
115
+ return encodeProjectionFrame(
116
+ 0,
117
+ projection.revision,
118
+ projection.generationId === null ? 0 : GENERATIONS_FLAG,
119
+ projection.cells.length,
120
+ payload.finish(),
121
+ maximum
122
+ );
123
+ }
124
+ function encodeSpreadsheetMetadataKernelProjection(input, maximumBytes = SPREADSHEET_ARTIFACT_PROJECTION_MAX_BYTES) {
125
+ const projection = normalizeMetadataProjection(input);
126
+ const maximum = effectiveProjectionMaximum(
127
+ maximumBytes,
128
+ SPREADSHEET_ARTIFACT_METADATA_MIN_RESPONSE_BYTES
129
+ );
130
+ const payload = new DynamicWriter(maximum - PROJECTION_HEADER_BYTES - CHECKSUM_BYTES);
131
+ payload.u32(0);
132
+ for (const sheet of projection.sheets) {
133
+ payload.stableId(sheet.sheetId);
134
+ payload.optionalStableId(sheet.generationId);
135
+ payload.string(sheet.name);
136
+ if (sheet.usedBounds === null) {
137
+ payload.u8(0);
138
+ } else {
139
+ payload.u8(1);
140
+ payload.u32(sheet.usedBounds.startRow);
141
+ payload.u32(sheet.usedBounds.startColumn);
142
+ payload.u32(sheet.usedBounds.endRow);
143
+ payload.u32(sheet.usedBounds.endColumn);
144
+ }
145
+ }
146
+ const generations = projection.sheets.length > 0 && projection.sheets[0].generationId !== null;
147
+ return encodeProjectionFrame(
148
+ 1,
149
+ projection.revision,
150
+ generations ? GENERATIONS_FLAG : 0,
151
+ projection.sheets.length,
152
+ payload.finish(),
153
+ maximum
154
+ );
155
+ }
156
+ function encodeSpreadsheetArtifactKernelProjection(input, maximumBytes = SPREADSHEET_ARTIFACT_PROJECTION_MAX_BYTES) {
157
+ const envelope = exactRecord(input, "spreadsheet kernel projection");
158
+ exactKeys(envelope, ["kind", "projection"], "spreadsheet kernel projection");
159
+ if (envelope.kind === "viewport") {
160
+ return encodeSpreadsheetViewportKernelProjection(
161
+ envelope.projection,
162
+ maximumBytes
163
+ );
164
+ }
165
+ if (envelope.kind === "workbook-metadata") {
166
+ return encodeSpreadsheetMetadataKernelProjection(
167
+ envelope.projection,
168
+ maximumBytes
169
+ );
170
+ }
171
+ throw projectionError("unknown spreadsheet kernel projection kind");
172
+ }
173
+ function decodeSpreadsheetArtifactKernelProjection(bytes) {
174
+ const frame = decodeProjectionFrame(bytes);
175
+ if (frame.kind === 0) {
176
+ return Object.freeze({
177
+ kind: "viewport",
178
+ projection: decodeViewportPayload(frame)
179
+ });
180
+ }
181
+ return Object.freeze({
182
+ kind: "workbook-metadata",
183
+ projection: decodeMetadataPayload(frame)
184
+ });
185
+ }
186
+ function decodeSpreadsheetViewportKernelProjection(bytes, expected) {
187
+ const decoded = decodeSpreadsheetArtifactKernelProjection(bytes);
188
+ if (decoded.kind !== "viewport") throw projectionError("expected a viewport projection");
189
+ if (expected !== void 0) {
190
+ const query = normalizeViewportQuery(expected);
191
+ enforceProjectionEnvelopeLimit(bytes, query.maxBytes);
192
+ if (decoded.projection.cells.length > Math.min(query.maxCells, SPREADSHEET_ARTIFACT_VIEWPORT_MAX_CELLS)) {
193
+ throw projectionError("viewport projection exceeds its requested cell limit");
194
+ }
195
+ if (decoded.projection.sheetId !== query.sheetId || decoded.projection.startRow !== query.startRow || decoded.projection.startColumn !== query.startColumn || decoded.projection.rowCount !== query.rowCount || decoded.projection.columnCount !== query.columnCount) {
196
+ throw projectionError("viewport projection does not match its query");
197
+ }
198
+ }
199
+ return decoded.projection;
200
+ }
201
+ function decodeSpreadsheetMetadataKernelProjection(bytes, expected) {
202
+ const decoded = decodeSpreadsheetArtifactKernelProjection(bytes);
203
+ if (decoded.kind !== "workbook-metadata") {
204
+ throw projectionError("expected a workbook metadata projection");
205
+ }
206
+ if (expected !== void 0) {
207
+ const query = normalizeMetadataQuery(expected);
208
+ enforceProjectionEnvelopeLimit(bytes, query.maxBytes);
209
+ if (decoded.projection.sheets.length > Math.min(query.maxSheets, SPREADSHEET_ARTIFACT_METADATA_MAX_SHEETS)) {
210
+ throw projectionError("metadata projection exceeds its requested sheet limit");
211
+ }
212
+ }
213
+ return decoded.projection;
214
+ }
215
+ function assertCanonicalSpreadsheetArtifactKernelProjectionBytes(bytes) {
216
+ const canonical = encodeSpreadsheetArtifactKernelProjection(
217
+ decodeSpreadsheetArtifactKernelProjection(bytes)
218
+ );
219
+ if (!equalBytes(bytes, canonical)) {
220
+ throw projectionError("spreadsheet kernel projection is not canonical");
221
+ }
222
+ return bytes;
223
+ }
224
+ function encodeQueryFrame(kind, maxItems, maxBytes, payload) {
225
+ const output = new FixedWriter(QUERY_HEADER_BYTES + payload.byteLength + CHECKSUM_BYTES);
226
+ output.bytes(QUERY_MAGIC);
227
+ output.u16(SPREADSHEET_ARTIFACT_QUERY_VERSION);
228
+ output.u16(0);
229
+ output.u8(kind);
230
+ output.bytes(new Uint8Array(3));
231
+ output.u32(maxItems);
232
+ output.u32(maxBytes);
233
+ output.u32(payload.byteLength);
234
+ output.bytes(payload);
235
+ output.u64(fnv1a64(output.view()));
236
+ const bytes = output.finish();
237
+ if (bytes.byteLength > SPREADSHEET_ARTIFACT_QUERY_MAX_BYTES) {
238
+ throw queryError("spreadsheet kernel query exceeds its byte limit");
239
+ }
240
+ return bytes;
241
+ }
242
+ function decodeQueryFrame(bytes) {
243
+ requireBytes(bytes, "spreadsheet kernel query");
244
+ if (bytes.byteLength > SPREADSHEET_ARTIFACT_QUERY_MAX_BYTES) {
245
+ throw queryError("spreadsheet kernel query exceeds its byte limit");
246
+ }
247
+ if (bytes.byteLength < QUERY_HEADER_BYTES + CHECKSUM_BYTES) {
248
+ throw queryError("spreadsheet kernel query is truncated");
249
+ }
250
+ const reader = new Reader(bytes);
251
+ if (!equalBytes(reader.bytes(8), QUERY_MAGIC))
252
+ throw queryError("spreadsheet query magic is invalid");
253
+ const version = reader.u16();
254
+ if (version !== SPREADSHEET_ARTIFACT_QUERY_VERSION) {
255
+ throw queryError(`unsupported spreadsheet query version: ${version}`);
256
+ }
257
+ if (reader.u16() !== 0) throw queryError("spreadsheet query reserved flags must be zero");
258
+ const kindTag = reader.u8();
259
+ if (kindTag > 1) throw queryError("spreadsheet query kind is invalid");
260
+ if (reader.u8() !== 0 || reader.u8() !== 0 || reader.u8() !== 0) {
261
+ throw queryError("spreadsheet query reserved bytes must be zero");
262
+ }
263
+ const maxItems = reader.u32();
264
+ const maxBytes = reader.u32();
265
+ const payloadLength = reader.u32();
266
+ const expected = QUERY_HEADER_BYTES + payloadLength + CHECKSUM_BYTES;
267
+ if (bytes.byteLength < expected) throw queryError("spreadsheet kernel query is truncated");
268
+ if (bytes.byteLength > expected)
269
+ throw queryError("spreadsheet kernel query contains trailing bytes");
270
+ const payload = reader.bytes(payloadLength);
271
+ const checksum = reader.u64();
272
+ reader.done("spreadsheet kernel query contains trailing bytes");
273
+ if (checksum !== fnv1a64(bytes.subarray(0, -CHECKSUM_BYTES))) {
274
+ throw queryError("spreadsheet kernel query checksum does not match");
275
+ }
276
+ return Object.freeze({ kind: kindTag, maxItems, maxBytes, payload });
277
+ }
278
+ function encodeProjectionFrame(kind, revision, flags, itemCount, payload, maximum) {
279
+ const output = new FixedWriter(PROJECTION_HEADER_BYTES + payload.byteLength + CHECKSUM_BYTES);
280
+ output.bytes(PROJECTION_MAGIC);
281
+ output.u16(SPREADSHEET_ARTIFACT_QUERY_VERSION);
282
+ output.u16(flags);
283
+ output.u8(kind);
284
+ output.bytes(new Uint8Array(3));
285
+ output.u64(revision);
286
+ output.u32(itemCount);
287
+ output.u64(BigInt(payload.byteLength));
288
+ output.bytes(payload);
289
+ output.u64(fnv1a64(output.view()));
290
+ const bytes = output.finish();
291
+ if (bytes.byteLength > maximum || bytes.byteLength > SPREADSHEET_ARTIFACT_PROJECTION_MAX_BYTES) {
292
+ throw projectionError("spreadsheet kernel projection exceeds its byte limit");
293
+ }
294
+ return bytes;
295
+ }
296
+ function decodeProjectionFrame(bytes) {
297
+ requireBytes(bytes, "spreadsheet kernel projection");
298
+ if (bytes.byteLength > SPREADSHEET_ARTIFACT_PROJECTION_MAX_BYTES) {
299
+ throw projectionError("spreadsheet kernel projection exceeds its byte limit");
300
+ }
301
+ if (bytes.byteLength < PROJECTION_HEADER_BYTES + CHECKSUM_BYTES) {
302
+ throw projectionError("spreadsheet kernel projection is truncated");
303
+ }
304
+ const reader = new Reader(bytes);
305
+ if (!equalBytes(reader.bytes(8), PROJECTION_MAGIC)) {
306
+ throw projectionError("spreadsheet projection magic is invalid");
307
+ }
308
+ const version = reader.u16();
309
+ if (version !== SPREADSHEET_ARTIFACT_QUERY_VERSION) {
310
+ throw projectionError(`unsupported spreadsheet projection version: ${version}`);
311
+ }
312
+ const flags = reader.u16();
313
+ if ((flags & ~GENERATIONS_FLAG) !== 0) {
314
+ throw projectionError("spreadsheet projection flags are noncanonical");
315
+ }
316
+ const kindTag = reader.u8();
317
+ if (kindTag > 1) throw projectionError("spreadsheet projection kind is invalid");
318
+ if (reader.u8() !== 0 || reader.u8() !== 0 || reader.u8() !== 0) {
319
+ throw projectionError("spreadsheet projection reserved bytes must be zero");
320
+ }
321
+ const revision = reader.u64();
322
+ const itemCount = reader.u32();
323
+ const payloadLengthBig = reader.u64();
324
+ if (payloadLengthBig > BigInt(SPREADSHEET_ARTIFACT_PROJECTION_MAX_BYTES)) {
325
+ throw projectionError("spreadsheet projection payload exceeds its byte limit");
326
+ }
327
+ const payloadLength = Number(payloadLengthBig);
328
+ const expected = PROJECTION_HEADER_BYTES + payloadLength + CHECKSUM_BYTES;
329
+ if (bytes.byteLength < expected)
330
+ throw projectionError("spreadsheet kernel projection is truncated");
331
+ if (bytes.byteLength > expected) {
332
+ throw projectionError("spreadsheet kernel projection contains trailing bytes");
333
+ }
334
+ const payload = reader.bytes(payloadLength);
335
+ const checksum = reader.u64();
336
+ reader.done("spreadsheet kernel projection contains trailing bytes");
337
+ if (checksum !== fnv1a64(bytes.subarray(0, -CHECKSUM_BYTES))) {
338
+ throw projectionError("spreadsheet kernel projection checksum does not match");
339
+ }
340
+ return Object.freeze({
341
+ kind: kindTag,
342
+ flags,
343
+ revision,
344
+ itemCount,
345
+ payload
346
+ });
347
+ }
348
+ function decodeViewportPayload(frame) {
349
+ if (frame.itemCount > SPREADSHEET_ARTIFACT_VIEWPORT_MAX_CELLS) {
350
+ throw projectionError("viewport projection exceeds its hard cell limit");
351
+ }
352
+ if (frame.payload.byteLength < VIEWPORT_PROJECTION_PREFIX_BYTES + frame.itemCount * 10) {
353
+ throw projectionError("viewport projection payload is truncated");
354
+ }
355
+ const reader = new Reader(frame.payload);
356
+ const sheetId = reader.stableId("viewport sheet id");
357
+ const generationId = reader.optionalStableId((frame.flags & GENERATIONS_FLAG) !== 0);
358
+ const startRow = reader.u32();
359
+ const startColumn = reader.u32();
360
+ const rowCount = reader.u32();
361
+ const columnCount = reader.u32();
362
+ validateViewportGeometry(startRow, startColumn, rowCount, columnCount);
363
+ const cells = [];
364
+ let previousOrdinal = -1;
365
+ for (let index = 0; index < frame.itemCount; index += 1) {
366
+ const relativeRow = reader.u32();
367
+ const relativeColumn = reader.u32();
368
+ if (relativeRow >= rowCount || relativeColumn >= columnCount) {
369
+ throw projectionError("viewport cell lies outside its response extent");
370
+ }
371
+ const ordinal = relativeRow * columnCount + relativeColumn;
372
+ if (!Number.isSafeInteger(ordinal) || ordinal <= previousOrdinal) {
373
+ throw projectionError("viewport cells are not unique strict row-major entries");
374
+ }
375
+ previousOrdinal = ordinal;
376
+ const formula = reader.formula();
377
+ const value = reader.cellValue();
378
+ if (formula === null && value.kind === "empty") {
379
+ throw projectionError("sparse viewport contains an empty cell");
380
+ }
381
+ cells.push(
382
+ Object.freeze({
383
+ row: startRow + relativeRow,
384
+ column: startColumn + relativeColumn,
385
+ formula,
386
+ value
387
+ })
388
+ );
389
+ }
390
+ reader.done("viewport projection payload contains trailing bytes");
391
+ return Object.freeze({
392
+ revision: frame.revision,
393
+ sheetId,
394
+ generationId,
395
+ startRow,
396
+ startColumn,
397
+ rowCount,
398
+ columnCount,
399
+ cells: Object.freeze(cells)
400
+ });
401
+ }
402
+ function decodeMetadataPayload(frame) {
403
+ if (frame.itemCount > SPREADSHEET_ARTIFACT_METADATA_MAX_SHEETS) {
404
+ throw projectionError("metadata projection exceeds its hard sheet limit");
405
+ }
406
+ if (frame.payload.byteLength < METADATA_PROJECTION_PREFIX_BYTES + frame.itemCount * 37) {
407
+ throw projectionError("metadata projection payload is truncated");
408
+ }
409
+ const reader = new Reader(frame.payload);
410
+ if (reader.u32() !== 0) {
411
+ throw projectionError("metadata projection contains unknown modeled feature bits");
412
+ }
413
+ const hasGenerations = (frame.flags & GENERATIONS_FLAG) !== 0;
414
+ if (frame.itemCount === 0 && hasGenerations) {
415
+ throw projectionError("empty metadata projection must not set the generations flag");
416
+ }
417
+ const sheets = [];
418
+ const ids = /* @__PURE__ */ new Set();
419
+ const names = /* @__PURE__ */ new Set();
420
+ for (let index = 0; index < frame.itemCount; index += 1) {
421
+ const sheetId = reader.stableId("metadata sheet id");
422
+ if (ids.has(sheetId)) throw projectionError("metadata projection contains duplicate sheet ids");
423
+ ids.add(sheetId);
424
+ const generationId = reader.optionalStableId(hasGenerations);
425
+ const name = validateSheetName(reader.string(), "metadata sheet name");
426
+ const foldedName = name.toLowerCase();
427
+ if (names.has(foldedName)) {
428
+ throw projectionError("metadata projection contains duplicate case-insensitive sheet names");
429
+ }
430
+ names.add(foldedName);
431
+ const boundsTag = reader.u8();
432
+ if (boundsTag > 1) throw projectionError("metadata used-bounds tag is invalid");
433
+ let usedBounds = null;
434
+ if (boundsTag === 1) {
435
+ const startRow = reader.u32();
436
+ const startColumn = reader.u32();
437
+ const endRow = reader.u32();
438
+ const endColumn = reader.u32();
439
+ if (startRow > endRow || startColumn > endColumn) {
440
+ throw projectionError("metadata used bounds are not ordered");
441
+ }
442
+ usedBounds = Object.freeze({ startRow, startColumn, endRow, endColumn });
443
+ }
444
+ sheets.push(Object.freeze({ sheetId, generationId, name, usedBounds }));
445
+ }
446
+ reader.done("metadata projection payload contains trailing bytes");
447
+ return Object.freeze({
448
+ revision: frame.revision,
449
+ modeledFeatures: MODELED_FEATURES_NONE,
450
+ sheets: Object.freeze(sheets)
451
+ });
452
+ }
453
+ function normalizeViewportQuery(input) {
454
+ const query = exactRecord(input, "spreadsheet viewport query");
455
+ exactKeys(
456
+ query,
457
+ ["columnCount", "maxBytes", "maxCells", "rowCount", "sheetId", "startColumn", "startRow"],
458
+ "spreadsheet viewport query"
459
+ );
460
+ const sheetId = spreadsheetSheetId(requireString(query.sheetId, "viewport sheetId"));
461
+ const startRow = uint32(query.startRow, "viewport startRow");
462
+ const startColumn = uint32(query.startColumn, "viewport startColumn");
463
+ const rowCount = positiveUint32(query.rowCount, "viewport rowCount");
464
+ const columnCount = positiveUint32(query.columnCount, "viewport columnCount");
465
+ validateViewportGeometry(startRow, startColumn, rowCount, columnCount);
466
+ const maxCells = positiveUint32(query.maxCells, "viewport maxCells");
467
+ const maxBytes = positiveUint32(query.maxBytes, "viewport maxBytes");
468
+ if (maxBytes < SPREADSHEET_ARTIFACT_VIEWPORT_MIN_RESPONSE_BYTES) {
469
+ throw queryError("viewport maxBytes cannot fit an empty response");
470
+ }
471
+ return Object.freeze({
472
+ sheetId,
473
+ startRow,
474
+ startColumn,
475
+ rowCount,
476
+ columnCount,
477
+ maxCells,
478
+ maxBytes
479
+ });
480
+ }
481
+ function normalizeMetadataQuery(input) {
482
+ const query = exactRecord(input, "spreadsheet metadata query");
483
+ exactKeys(query, ["maxBytes", "maxSheets"], "spreadsheet metadata query");
484
+ const maxSheets = positiveUint32(query.maxSheets, "metadata maxSheets");
485
+ const maxBytes = positiveUint32(query.maxBytes, "metadata maxBytes");
486
+ if (maxBytes < SPREADSHEET_ARTIFACT_METADATA_MIN_RESPONSE_BYTES) {
487
+ throw queryError("metadata maxBytes cannot fit an empty response");
488
+ }
489
+ return Object.freeze({ maxSheets, maxBytes });
490
+ }
491
+ function normalizeViewportProjection(input) {
492
+ const projection = exactRecord(input, "spreadsheet viewport projection");
493
+ exactKeys(
494
+ projection,
495
+ [
496
+ "cells",
497
+ "columnCount",
498
+ "generationId",
499
+ "revision",
500
+ "rowCount",
501
+ "sheetId",
502
+ "startColumn",
503
+ "startRow"
504
+ ],
505
+ "spreadsheet viewport projection"
506
+ );
507
+ const revision = uint64(projection.revision, "viewport revision");
508
+ const sheetId = spreadsheetSheetId(requireString(projection.sheetId, "viewport sheetId"));
509
+ const generationId = nullableGenerationId(projection.generationId, "viewport generationId");
510
+ const startRow = uint32(projection.startRow, "viewport startRow");
511
+ const startColumn = uint32(projection.startColumn, "viewport startColumn");
512
+ const rowCount = positiveUint32(projection.rowCount, "viewport rowCount");
513
+ const columnCount = positiveUint32(projection.columnCount, "viewport columnCount");
514
+ validateViewportGeometry(startRow, startColumn, rowCount, columnCount);
515
+ if (!Array.isArray(projection.cells)) throw projectionError("viewport cells must be an array");
516
+ if (projection.cells.length > SPREADSHEET_ARTIFACT_VIEWPORT_MAX_CELLS) {
517
+ throw projectionError("viewport projection exceeds its hard cell limit");
518
+ }
519
+ const cells = [];
520
+ let previousOrdinal = -1;
521
+ for (let index = 0; index < projection.cells.length; index += 1) {
522
+ const cell = normalizeProjectedCell(ownArrayElement(projection.cells, index, "viewport cells"));
523
+ if (cell.row < startRow || cell.row >= startRow + rowCount || cell.column < startColumn || cell.column >= startColumn + columnCount) {
524
+ throw projectionError("viewport cell lies outside its response extent");
525
+ }
526
+ const ordinal = (cell.row - startRow) * columnCount + (cell.column - startColumn);
527
+ if (!Number.isSafeInteger(ordinal) || ordinal <= previousOrdinal) {
528
+ throw projectionError("viewport cells are not unique strict row-major entries");
529
+ }
530
+ previousOrdinal = ordinal;
531
+ if (cell.formula === null && cell.value.kind === "empty") {
532
+ throw projectionError("sparse viewport contains an empty cell");
533
+ }
534
+ cells.push(cell);
535
+ }
536
+ return Object.freeze({
537
+ revision,
538
+ sheetId,
539
+ generationId,
540
+ startRow,
541
+ startColumn,
542
+ rowCount,
543
+ columnCount,
544
+ cells: Object.freeze(cells)
545
+ });
546
+ }
547
+ function normalizeMetadataProjection(input) {
548
+ const projection = exactRecord(input, "spreadsheet metadata projection");
549
+ exactKeys(
550
+ projection,
551
+ ["modeledFeatures", "revision", "sheets"],
552
+ "spreadsheet metadata projection"
553
+ );
554
+ const revision = uint64(projection.revision, "metadata revision");
555
+ const features = exactRecord(projection.modeledFeatures, "metadata modeledFeatures");
556
+ exactKeys(features, ["dimensions", "hidden", "merges"], "metadata modeledFeatures");
557
+ if (features.dimensions !== false || features.hidden !== false || features.merges !== false) {
558
+ throw projectionError("version 1 metadata modeled features must all be false");
559
+ }
560
+ if (!Array.isArray(projection.sheets)) throw projectionError("metadata sheets must be an array");
561
+ if (projection.sheets.length > SPREADSHEET_ARTIFACT_METADATA_MAX_SHEETS) {
562
+ throw projectionError("metadata projection exceeds its hard sheet limit");
563
+ }
564
+ const ids = /* @__PURE__ */ new Set();
565
+ const names = /* @__PURE__ */ new Set();
566
+ const sheets = [];
567
+ let generationPresence = null;
568
+ for (let index = 0; index < projection.sheets.length; index += 1) {
569
+ const value = exactRecord(
570
+ ownArrayElement(projection.sheets, index, "metadata sheets"),
571
+ "metadata sheet"
572
+ );
573
+ exactKeys(value, ["generationId", "name", "sheetId", "usedBounds"], "metadata sheet");
574
+ const sheetId = spreadsheetSheetId(requireString(value.sheetId, "metadata sheetId"));
575
+ if (ids.has(sheetId)) throw projectionError("metadata projection contains duplicate sheet ids");
576
+ ids.add(sheetId);
577
+ const generationId = nullableGenerationId(value.generationId, "metadata generationId");
578
+ const present = generationId !== null;
579
+ if (generationPresence !== null && generationPresence !== present) {
580
+ throw projectionError("metadata generations must be uniformly present or absent");
581
+ }
582
+ generationPresence = present;
583
+ const name = validateSheetName(
584
+ requireString(value.name, "metadata sheet name"),
585
+ "metadata sheet name"
586
+ );
587
+ const foldedName = name.toLowerCase();
588
+ if (names.has(foldedName)) {
589
+ throw projectionError("metadata projection contains duplicate case-insensitive sheet names");
590
+ }
591
+ names.add(foldedName);
592
+ const usedBounds = value.usedBounds === null ? null : normalizeUsedBounds(value.usedBounds);
593
+ sheets.push(Object.freeze({ sheetId, generationId, name, usedBounds }));
594
+ }
595
+ return Object.freeze({
596
+ revision,
597
+ modeledFeatures: MODELED_FEATURES_NONE,
598
+ sheets: Object.freeze(sheets)
599
+ });
600
+ }
601
+ function normalizeProjectedCell(input) {
602
+ const cell = exactRecord(input, "projected cell");
603
+ exactKeys(cell, ["column", "formula", "row", "value"], "projected cell");
604
+ const row = uint32(cell.row, "projected cell row");
605
+ const column = uint32(cell.column, "projected cell column");
606
+ let formula;
607
+ if (cell.formula === null) {
608
+ formula = null;
609
+ } else {
610
+ formula = requireString(cell.formula, "projected cell formula");
611
+ if (formula.length === 0) throw projectionError("projected cell formula must not be empty");
612
+ boundedUtf8(
613
+ formula,
614
+ SPREADSHEET_ARTIFACT_PROJECTION_MAX_STRING_BYTES,
615
+ "projected cell formula"
616
+ );
617
+ }
618
+ return Object.freeze({
619
+ row,
620
+ column,
621
+ formula,
622
+ value: normalizeProjectedValue(cell.value)
623
+ });
624
+ }
625
+ function normalizeProjectedValue(input) {
626
+ const value = exactRecord(input, "projected cell value");
627
+ if (value.kind === "empty") {
628
+ exactKeys(value, ["kind"], "empty projected cell value");
629
+ return EMPTY_VALUE;
630
+ }
631
+ if (value.kind === "boolean") {
632
+ exactKeys(value, ["kind", "value"], "boolean projected cell value");
633
+ if (typeof value.value !== "boolean") throw projectionError("boolean cell value is invalid");
634
+ return Object.freeze({ kind: "boolean", value: value.value });
635
+ }
636
+ if (value.kind === "number") {
637
+ exactKeys(value, ["kind", "value"], "number projected cell value");
638
+ if (typeof value.value !== "number" || !Number.isFinite(value.value)) {
639
+ throw projectionError("number cell value must be finite");
640
+ }
641
+ return Object.freeze({
642
+ kind: "number",
643
+ value: value.value === 0 ? 0 : value.value
644
+ });
645
+ }
646
+ if (value.kind === "date") {
647
+ exactKeys(value, ["kind", "value"], "date projected cell value");
648
+ return Object.freeze({
649
+ kind: "date",
650
+ value: canonicalDateString(value.value)
651
+ });
652
+ }
653
+ if (value.kind === "text") {
654
+ exactKeys(value, ["kind", "value"], "text projected cell value");
655
+ const text = requireString(value.value, "text cell value");
656
+ boundedUtf8(text, SPREADSHEET_ARTIFACT_PROJECTION_MAX_STRING_BYTES, "text cell value");
657
+ return Object.freeze({ kind: "text", value: text });
658
+ }
659
+ if (value.kind === "error") {
660
+ exactKeys(value, ["kind", "value"], "error projected cell value");
661
+ return Object.freeze({
662
+ kind: "error",
663
+ value: normalizeFormulaError(value.value)
664
+ });
665
+ }
666
+ throw projectionError("projected cell value kind is invalid");
667
+ }
668
+ function canonicalDateString(input) {
669
+ canonicalSpreadsheetDateMilliseconds(input);
670
+ return input;
671
+ }
672
+ function normalizeFormulaError(input) {
673
+ if (typeof input === "string" && FORMULA_ERROR_TAGS.has(input)) {
674
+ return input;
675
+ }
676
+ const error = exactRecord(input, "custom formula error");
677
+ exactKeys(error, ["custom"], "custom formula error");
678
+ const custom = requireString(error.custom, "custom formula error");
679
+ boundedUtf8(custom, SPREADSHEET_ARTIFACT_PROJECTION_MAX_STRING_BYTES, "custom formula error");
680
+ return Object.freeze({ custom });
681
+ }
682
+ function normalizeUsedBounds(input) {
683
+ const bounds = exactRecord(input, "metadata used bounds");
684
+ exactKeys(bounds, ["endColumn", "endRow", "startColumn", "startRow"], "metadata used bounds");
685
+ const startRow = uint32(bounds.startRow, "used bounds startRow");
686
+ const startColumn = uint32(bounds.startColumn, "used bounds startColumn");
687
+ const endRow = uint32(bounds.endRow, "used bounds endRow");
688
+ const endColumn = uint32(bounds.endColumn, "used bounds endColumn");
689
+ if (startRow > endRow || startColumn > endColumn) {
690
+ throw projectionError("metadata used bounds are not ordered");
691
+ }
692
+ return Object.freeze({ startRow, startColumn, endRow, endColumn });
693
+ }
694
+ function validateViewportGeometry(startRow, startColumn, rowCount, columnCount) {
695
+ if (rowCount < 1 || columnCount < 1) {
696
+ throw queryError("viewport extents must be nonzero");
697
+ }
698
+ if (rowCount - 1 > UINT32_MAX - startRow || columnCount - 1 > UINT32_MAX - startColumn) {
699
+ throw queryError("viewport extent exceeds uint32 coordinates");
700
+ }
701
+ const area = rowCount * columnCount;
702
+ if (!Number.isSafeInteger(area) || area > SPREADSHEET_ARTIFACT_VIEWPORT_MAX_AREA) {
703
+ throw queryError("viewport area exceeds its hard limit");
704
+ }
705
+ }
706
+ function validateSheetName(value, label) {
707
+ boundedUtf8(value, SPREADSHEET_ARTIFACT_PROJECTION_MAX_STRING_BYTES, label);
708
+ if (value.length === 0 || value.trim() !== value || value.length > 31 || /[\\/?*[\]:\0]/u.test(value)) {
709
+ throw projectionError(`${label} does not match the public spreadsheet model`);
710
+ }
711
+ return value;
712
+ }
713
+ function nullableGenerationId(value, label) {
714
+ return value === null ? null : spreadsheetSheetId(requireString(value, label));
715
+ }
716
+ function enforceProjectionEnvelopeLimit(bytes, requested) {
717
+ if (bytes.byteLength > Math.min(requested, SPREADSHEET_ARTIFACT_PROJECTION_MAX_BYTES)) {
718
+ throw projectionError("spreadsheet projection exceeds its requested byte limit");
719
+ }
720
+ }
721
+ function effectiveProjectionMaximum(value, minimum) {
722
+ const maximum = positiveUint32(value, "projection maximumBytes");
723
+ const effective = Math.min(maximum, SPREADSHEET_ARTIFACT_PROJECTION_MAX_BYTES);
724
+ if (effective < minimum) throw projectionError("projection maximum cannot fit an empty response");
725
+ return effective;
726
+ }
727
+ function requireBytes(value, label) {
728
+ if (!(value instanceof Uint8Array)) throw new TypeError(`${label} must be a Uint8Array`);
729
+ }
730
+ function requireString(value, label) {
731
+ if (typeof value !== "string") throw new TypeError(`${label} must be a string`);
732
+ return value;
733
+ }
734
+ function uint32(value, label) {
735
+ if (!Number.isInteger(value) || value < 0 || value > UINT32_MAX) {
736
+ throw new TypeError(`${label} must be a uint32`);
737
+ }
738
+ return value;
739
+ }
740
+ function positiveUint32(value, label) {
741
+ const number = uint32(value, label);
742
+ if (number === 0) throw new TypeError(`${label} must be nonzero`);
743
+ return number;
744
+ }
745
+ function uint64(value, label) {
746
+ if (typeof value !== "bigint" || value < 0n || value > UINT64_MAX) {
747
+ throw new TypeError(`${label} must be a uint64 bigint`);
748
+ }
749
+ return value;
750
+ }
751
+ function exactRecord(value, label) {
752
+ if (typeof value !== "object" || value === null || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype) {
753
+ throw new TypeError(`${label} must be a plain record`);
754
+ }
755
+ return value;
756
+ }
757
+ function exactKeys(value, expected, label) {
758
+ const keys = Reflect.ownKeys(value);
759
+ if (keys.some((key) => typeof key !== "string"))
760
+ throw new TypeError(`${label} has symbol fields`);
761
+ const actual = keys.sort(compareCodeUnits);
762
+ if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) {
763
+ throw new TypeError(`${label} fields must be exactly: ${expected.join(", ")}`);
764
+ }
765
+ for (const key of actual) {
766
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
767
+ if (!descriptor || !("value" in descriptor) || !descriptor.enumerable) {
768
+ throw new TypeError(`${label} fields must be enumerable data properties`);
769
+ }
770
+ }
771
+ }
772
+ function ownArrayElement(value, index, label) {
773
+ if (!Object.hasOwn(value, index)) throw new TypeError(`${label} must be dense`);
774
+ return value[index];
775
+ }
776
+ function compareCodeUnits(left, right) {
777
+ return left < right ? -1 : left > right ? 1 : 0;
778
+ }
779
+ function boundedUtf8(value, maximum, label) {
780
+ for (let index = 0; index < value.length; index += 1) {
781
+ const code = value.charCodeAt(index);
782
+ if (code >= 55296 && code <= 56319) {
783
+ const next = value.charCodeAt(index + 1);
784
+ if (!(next >= 56320 && next <= 57343)) {
785
+ throw new TypeError(`${label} contains an unpaired surrogate`);
786
+ }
787
+ index += 1;
788
+ } else if (code >= 56320 && code <= 57343) {
789
+ throw new TypeError(`${label} contains an unpaired surrogate`);
790
+ }
791
+ }
792
+ const bytes = textEncoder.encode(value);
793
+ if (bytes.byteLength > maximum) throw new RangeError(`${label} exceeds its byte limit`);
794
+ return bytes;
795
+ }
796
+ function equalBytes(left, right) {
797
+ return left.byteLength === right.byteLength && left.every((byte, index) => byte === right[index]);
798
+ }
799
+ function fnv1a64(bytes) {
800
+ let hash = FNV_OFFSET;
801
+ for (const byte of bytes) {
802
+ hash ^= BigInt(byte);
803
+ hash = BigInt.asUintN(64, hash * FNV_PRIME);
804
+ }
805
+ return hash;
806
+ }
807
+ function queryError(message) {
808
+ return new TypeError(message);
809
+ }
810
+ function projectionError(message) {
811
+ return new TypeError(message);
812
+ }
813
+ var MODELED_FEATURES_NONE = Object.freeze({
814
+ dimensions: false,
815
+ hidden: false,
816
+ merges: false
817
+ });
818
+ var EMPTY_VALUE = Object.freeze({
819
+ kind: "empty"
820
+ });
821
+ var FORMULA_ERRORS = [
822
+ "null",
823
+ "divide_by_zero",
824
+ "value",
825
+ "reference",
826
+ "name",
827
+ "number",
828
+ "not_available",
829
+ "spill",
830
+ "calculation"
831
+ ];
832
+ var FORMULA_ERROR_TAGS = new Set(FORMULA_ERRORS);
833
+ var FixedWriter = class {
834
+ buffer;
835
+ viewBuffer;
836
+ offset = 0;
837
+ constructor(length) {
838
+ this.buffer = new Uint8Array(length);
839
+ this.viewBuffer = new DataView(this.buffer.buffer);
840
+ }
841
+ view() {
842
+ return this.buffer.subarray(0, this.offset);
843
+ }
844
+ finish() {
845
+ if (this.offset !== this.buffer.byteLength)
846
+ throw new TypeError("fixed binary writer is incomplete");
847
+ return this.buffer;
848
+ }
849
+ u8(value) {
850
+ this.reserve(1);
851
+ this.viewBuffer.setUint8(this.offset, value);
852
+ this.offset += 1;
853
+ }
854
+ u16(value) {
855
+ this.reserve(2);
856
+ this.viewBuffer.setUint16(this.offset, value, true);
857
+ this.offset += 2;
858
+ }
859
+ u32(value) {
860
+ this.reserve(4);
861
+ this.viewBuffer.setUint32(this.offset, value, true);
862
+ this.offset += 4;
863
+ }
864
+ u64(value) {
865
+ this.reserve(8);
866
+ this.viewBuffer.setBigUint64(this.offset, value, true);
867
+ this.offset += 8;
868
+ }
869
+ stableId(value) {
870
+ const id = spreadsheetSheetId(value);
871
+ this.u64(BigInt(`0x${id.slice(16)}`));
872
+ this.u64(BigInt(`0x${id.slice(0, 16)}`));
873
+ }
874
+ bytes(value) {
875
+ this.reserve(value.byteLength);
876
+ this.buffer.set(value, this.offset);
877
+ this.offset += value.byteLength;
878
+ }
879
+ reserve(length) {
880
+ if (this.offset + length > this.buffer.byteLength)
881
+ throw new RangeError("fixed binary writer overflow");
882
+ }
883
+ };
884
+ var DynamicWriter = class {
885
+ constructor(maximum) {
886
+ this.maximum = maximum;
887
+ this.buffer = new Uint8Array(Math.min(1024, maximum));
888
+ this.viewBuffer = new DataView(this.buffer.buffer);
889
+ }
890
+ buffer;
891
+ viewBuffer;
892
+ offset = 0;
893
+ finish() {
894
+ return this.buffer.slice(0, this.offset);
895
+ }
896
+ u8(value) {
897
+ this.reserve(1);
898
+ this.viewBuffer.setUint8(this.offset, value);
899
+ this.offset += 1;
900
+ }
901
+ u32(value) {
902
+ this.reserve(4);
903
+ this.viewBuffer.setUint32(this.offset, value, true);
904
+ this.offset += 4;
905
+ }
906
+ u64(value) {
907
+ this.reserve(8);
908
+ this.viewBuffer.setBigUint64(this.offset, value, true);
909
+ this.offset += 8;
910
+ }
911
+ f64(value) {
912
+ this.reserve(8);
913
+ this.viewBuffer.setFloat64(this.offset, value === 0 ? 0 : value, true);
914
+ this.offset += 8;
915
+ }
916
+ stableId(value) {
917
+ const id = spreadsheetSheetId(value);
918
+ this.u64(BigInt(`0x${id.slice(16)}`));
919
+ this.u64(BigInt(`0x${id.slice(0, 16)}`));
920
+ }
921
+ optionalStableId(value) {
922
+ if (value === null) this.bytes(new Uint8Array(16));
923
+ else this.stableId(value);
924
+ }
925
+ string(value) {
926
+ const bytes = boundedUtf8(
927
+ value,
928
+ SPREADSHEET_ARTIFACT_PROJECTION_MAX_STRING_BYTES,
929
+ "projection string"
930
+ );
931
+ this.u32(bytes.byteLength);
932
+ this.bytes(bytes);
933
+ }
934
+ cell(cell) {
935
+ if (cell.formula === null) {
936
+ this.u8(0);
937
+ } else {
938
+ this.u8(1);
939
+ this.string(cell.formula);
940
+ }
941
+ const value = cell.value;
942
+ switch (value.kind) {
943
+ case "empty":
944
+ this.u8(0);
945
+ break;
946
+ case "boolean":
947
+ this.u8(value.value ? 2 : 1);
948
+ break;
949
+ case "number":
950
+ this.u8(3);
951
+ this.f64(value.value);
952
+ break;
953
+ case "date":
954
+ this.u8(6);
955
+ this.i64(BigInt(Date.parse(value.value)));
956
+ break;
957
+ case "text":
958
+ this.u8(4);
959
+ this.string(value.value);
960
+ break;
961
+ case "error":
962
+ this.u8(5);
963
+ this.formulaError(value.value);
964
+ break;
965
+ }
966
+ }
967
+ formulaError(error) {
968
+ if (typeof error === "string") {
969
+ this.u8(FORMULA_ERRORS.indexOf(error));
970
+ } else {
971
+ this.u8(9);
972
+ this.string(error.custom);
973
+ }
974
+ }
975
+ bytes(value) {
976
+ this.reserve(value.byteLength);
977
+ this.buffer.set(value, this.offset);
978
+ this.offset += value.byteLength;
979
+ }
980
+ i64(value) {
981
+ this.reserve(8);
982
+ this.viewBuffer.setBigInt64(this.offset, value, true);
983
+ this.offset += 8;
984
+ }
985
+ reserve(additional) {
986
+ const required = this.offset + additional;
987
+ if (!Number.isSafeInteger(required) || required > this.maximum) {
988
+ throw projectionError("spreadsheet projection exceeds its byte limit");
989
+ }
990
+ if (required <= this.buffer.byteLength) return;
991
+ let size = Math.max(1, this.buffer.byteLength);
992
+ while (size < required) size = Math.min(this.maximum, size * 2);
993
+ const next = new Uint8Array(size);
994
+ next.set(this.buffer.subarray(0, this.offset));
995
+ this.buffer = next;
996
+ this.viewBuffer = new DataView(next.buffer);
997
+ }
998
+ };
999
+ var Reader = class {
1000
+ constructor(input) {
1001
+ this.input = input;
1002
+ this.viewBuffer = new DataView(input.buffer, input.byteOffset, input.byteLength);
1003
+ }
1004
+ viewBuffer;
1005
+ offset = 0;
1006
+ u8() {
1007
+ this.reserve(1);
1008
+ return this.input[this.offset++];
1009
+ }
1010
+ u16() {
1011
+ this.reserve(2);
1012
+ const value = this.viewBuffer.getUint16(this.offset, true);
1013
+ this.offset += 2;
1014
+ return value;
1015
+ }
1016
+ u32() {
1017
+ this.reserve(4);
1018
+ const value = this.viewBuffer.getUint32(this.offset, true);
1019
+ this.offset += 4;
1020
+ return value;
1021
+ }
1022
+ u64() {
1023
+ this.reserve(8);
1024
+ const value = this.viewBuffer.getBigUint64(this.offset, true);
1025
+ this.offset += 8;
1026
+ return value;
1027
+ }
1028
+ f64() {
1029
+ this.reserve(8);
1030
+ const value = this.viewBuffer.getFloat64(this.offset, true);
1031
+ this.offset += 8;
1032
+ if (!Number.isFinite(value) || Object.is(value, -0)) {
1033
+ throw projectionError("spreadsheet projection number is noncanonical");
1034
+ }
1035
+ return value;
1036
+ }
1037
+ stableId(label) {
1038
+ const counter = this.u64().toString(16).padStart(16, "0");
1039
+ const namespace = this.u64().toString(16).padStart(16, "0");
1040
+ try {
1041
+ return spreadsheetSheetId(`${namespace}${counter}`);
1042
+ } catch {
1043
+ throw projectionError(`${label} is reserved or noncanonical`);
1044
+ }
1045
+ }
1046
+ optionalStableId(present) {
1047
+ if (present) return this.stableId("projection generation id");
1048
+ const bytes = this.bytes(16);
1049
+ if (bytes.some((byte) => byte !== 0)) {
1050
+ throw projectionError("projection has a generation id without its flag");
1051
+ }
1052
+ return null;
1053
+ }
1054
+ string() {
1055
+ const length = this.u32();
1056
+ if (length > SPREADSHEET_ARTIFACT_PROJECTION_MAX_STRING_BYTES) {
1057
+ throw projectionError("projection string exceeds its byte limit");
1058
+ }
1059
+ try {
1060
+ return textDecoder.decode(this.bytes(length));
1061
+ } catch {
1062
+ throw projectionError("projection string is not canonical UTF-8");
1063
+ }
1064
+ }
1065
+ formula() {
1066
+ const tag = this.u8();
1067
+ if (tag === 0) return null;
1068
+ if (tag !== 1) throw projectionError("projection formula tag is invalid");
1069
+ const formula = this.string();
1070
+ if (formula.length === 0) throw projectionError("projection formula must not be empty");
1071
+ return formula;
1072
+ }
1073
+ cellValue() {
1074
+ switch (this.u8()) {
1075
+ case 0:
1076
+ return EMPTY_VALUE;
1077
+ case 1:
1078
+ return Object.freeze({ kind: "boolean", value: false });
1079
+ case 2:
1080
+ return Object.freeze({ kind: "boolean", value: true });
1081
+ case 3:
1082
+ return Object.freeze({ kind: "number", value: this.f64() });
1083
+ case 4:
1084
+ return Object.freeze({ kind: "text", value: this.string() });
1085
+ case 5:
1086
+ return Object.freeze({ kind: "error", value: this.formulaError() });
1087
+ case 6:
1088
+ return Object.freeze({
1089
+ kind: "date",
1090
+ value: canonicalSpreadsheetDateFromMilliseconds(this.i64())
1091
+ });
1092
+ default:
1093
+ throw projectionError("projection cell value tag is invalid");
1094
+ }
1095
+ }
1096
+ done(message) {
1097
+ if (this.offset !== this.input.byteLength) throw new TypeError(message);
1098
+ }
1099
+ i64() {
1100
+ const bytes = this.bytes(8);
1101
+ return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getBigInt64(0, true);
1102
+ }
1103
+ bytes(length) {
1104
+ this.reserve(length);
1105
+ const bytes = this.input.subarray(this.offset, this.offset + length);
1106
+ this.offset += length;
1107
+ return bytes;
1108
+ }
1109
+ formulaError() {
1110
+ const tag = this.u8();
1111
+ if (tag <= 8) return FORMULA_ERRORS[tag];
1112
+ if (tag === 9) return Object.freeze({ custom: this.string() });
1113
+ throw projectionError("projection formula error tag is invalid");
1114
+ }
1115
+ reserve(length) {
1116
+ if (!Number.isSafeInteger(length) || length < 0 || this.offset + length > this.input.byteLength) {
1117
+ throw projectionError("spreadsheet projection payload is truncated");
1118
+ }
1119
+ }
1120
+ };
1121
+
1122
+ export {
1123
+ SPREADSHEET_ARTIFACT_QUERY_VERSION,
1124
+ SPREADSHEET_ARTIFACT_QUERY_MAX_BYTES,
1125
+ SPREADSHEET_ARTIFACT_PROJECTION_MAX_BYTES,
1126
+ SPREADSHEET_ARTIFACT_VIEWPORT_MAX_AREA,
1127
+ SPREADSHEET_ARTIFACT_VIEWPORT_MAX_CELLS,
1128
+ SPREADSHEET_ARTIFACT_METADATA_MAX_SHEETS,
1129
+ SPREADSHEET_ARTIFACT_PROJECTION_MAX_STRING_BYTES,
1130
+ SPREADSHEET_ARTIFACT_VIEWPORT_MIN_RESPONSE_BYTES,
1131
+ SPREADSHEET_ARTIFACT_METADATA_MIN_RESPONSE_BYTES,
1132
+ encodeSpreadsheetViewportKernelQuery,
1133
+ encodeSpreadsheetMetadataKernelQuery,
1134
+ encodeSpreadsheetArtifactKernelQuery,
1135
+ decodeSpreadsheetArtifactKernelQuery,
1136
+ assertCanonicalSpreadsheetArtifactKernelQueryBytes,
1137
+ encodeSpreadsheetViewportKernelProjection,
1138
+ encodeSpreadsheetMetadataKernelProjection,
1139
+ encodeSpreadsheetArtifactKernelProjection,
1140
+ decodeSpreadsheetArtifactKernelProjection,
1141
+ decodeSpreadsheetViewportKernelProjection,
1142
+ decodeSpreadsheetMetadataKernelProjection,
1143
+ assertCanonicalSpreadsheetArtifactKernelProjectionBytes
1144
+ };
1145
+ //# sourceMappingURL=chunk-CADSX6UN.js.map