@opengeni/contracts 0.40.0 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atlassian.d.ts +278 -0
- package/dist/atlassian.js +57 -0
- package/dist/atlassian.js.map +1 -0
- package/dist/canonical-human-identities.d.ts +157 -0
- package/dist/canonical-human-identities.js +23 -0
- package/dist/canonical-human-identities.js.map +1 -0
- package/dist/{chunk-7JZMI22I.js → chunk-5UDNP7AO.js} +34 -2
- package/dist/chunk-5UDNP7AO.js.map +1 -0
- package/dist/chunk-BVGIYW7D.js +11 -0
- package/dist/chunk-BVGIYW7D.js.map +1 -0
- package/dist/chunk-CADSX6UN.js +1145 -0
- package/dist/chunk-CADSX6UN.js.map +1 -0
- package/dist/chunk-CM6BMECR.js +24 -0
- package/dist/chunk-CM6BMECR.js.map +1 -0
- package/dist/chunk-D2HKF2EF.js +1460 -0
- package/dist/chunk-D2HKF2EF.js.map +1 -0
- package/dist/chunk-JBCIY7QD.js +194 -0
- package/dist/chunk-JBCIY7QD.js.map +1 -0
- package/dist/chunk-JUFK3T4Q.js +80 -0
- package/dist/chunk-JUFK3T4Q.js.map +1 -0
- package/dist/chunk-LSB7GRLG.js +779 -0
- package/dist/chunk-LSB7GRLG.js.map +1 -0
- package/dist/chunk-LW7OH6CS.js +382 -0
- package/dist/chunk-LW7OH6CS.js.map +1 -0
- package/dist/chunk-M5ZGRVIQ.js +719 -0
- package/dist/chunk-M5ZGRVIQ.js.map +1 -0
- package/dist/chunk-MYBZRDTY.js +340 -0
- package/dist/chunk-MYBZRDTY.js.map +1 -0
- package/dist/chunk-Q6A7XT2N.js +16734 -0
- package/dist/chunk-Q6A7XT2N.js.map +1 -0
- package/dist/chunk-RIY7GYQS.js +1204 -0
- package/dist/chunk-RIY7GYQS.js.map +1 -0
- package/dist/chunk-TZ6YEYN4.js +386 -0
- package/dist/chunk-TZ6YEYN4.js.map +1 -0
- package/dist/chunk-Y3MLSLB4.js +392 -0
- package/dist/chunk-Y3MLSLB4.js.map +1 -0
- package/dist/chunk-YRKRZ6OF.js +134 -0
- package/dist/chunk-YRKRZ6OF.js.map +1 -0
- package/dist/codex-provider-account-authority.d.ts +23 -0
- package/dist/codex-provider-account-authority.js +23 -0
- package/dist/codex-provider-account-authority.js.map +1 -0
- package/dist/company-profile.d.ts +629 -0
- package/dist/document-artifact-commands.d.ts +282 -0
- package/dist/document-artifact-commands.js +54 -0
- package/dist/document-artifact-commands.js.map +1 -0
- package/dist/document-artifact-query.d.ts +2 -0
- package/dist/document-artifact-query.js +54 -0
- package/dist/document-artifact-query.js.map +1 -0
- package/dist/editable-artifact-binary.d.ts +56 -0
- package/dist/editable-artifact-causal-frontier.d.ts +12 -0
- package/dist/editable-artifact-causal-frontier.js +18 -0
- package/dist/editable-artifact-causal-frontier.js.map +1 -0
- package/dist/editable-artifact-codec-registry.d.ts +48 -0
- package/dist/editable-artifact-codec-registry.js +20 -0
- package/dist/editable-artifact-codec-registry.js.map +1 -0
- package/dist/editable-artifact-committed-transaction.d.ts +35 -0
- package/dist/editable-artifact-committed-transaction.js +19 -0
- package/dist/editable-artifact-committed-transaction.js.map +1 -0
- package/dist/editable-artifact-live.d.ts +276 -0
- package/dist/editable-artifact-live.js +907 -0
- package/dist/editable-artifact-live.js.map +1 -0
- package/dist/editable-artifact-serialized-commit.d.ts +53 -0
- package/dist/editable-artifact-serialized-commit.js +26 -0
- package/dist/editable-artifact-serialized-commit.js.map +1 -0
- package/dist/editable-artifact-versions.d.ts +6 -0
- package/dist/editable-artifact-versions.js +11 -0
- package/dist/editable-artifact-versions.js.map +1 -0
- package/dist/editable-artifacts.d.ts +46 -0
- package/dist/editable-artifacts.js +236 -0
- package/dist/editable-artifacts.js.map +1 -0
- package/dist/event-preview.d.ts +1 -1
- package/dist/google-drive.d.ts +114 -2
- package/dist/google-drive.js +72 -14
- package/dist/google-drive.js.map +1 -1
- package/dist/image-generation.d.ts +70 -0
- package/dist/index.d.ts +5661 -166
- package/dist/index.js +1438 -21
- package/dist/interaction.d.ts +8290 -0
- package/dist/knowledge.d.ts +543 -0
- package/dist/memory-slack-delivery.d.ts +397 -0
- package/dist/presentation-artifact-commands.d.ts +349 -0
- package/dist/presentation-artifact-commands.js +66 -0
- package/dist/presentation-artifact-commands.js.map +1 -0
- package/dist/presentation-artifact-query.d.ts +2 -0
- package/dist/presentation-artifact-query.js +66 -0
- package/dist/presentation-artifact-query.js.map +1 -0
- package/dist/retained-output.d.ts +24 -0
- package/dist/sandbox-snapshots.d.ts +9 -0
- package/dist/scoped-knowledge.d.ts +14 -13
- package/dist/slack-bot-scopes.d.ts +4 -0
- package/dist/slack-bot-scopes.js +3 -1
- package/dist/slack-task-policy.d.ts +294 -0
- package/dist/spreadsheet-artifact-commands.d.ts +101 -0
- package/dist/spreadsheet-artifact-commands.js +27 -0
- package/dist/spreadsheet-artifact-commands.js.map +1 -0
- package/dist/spreadsheet-artifact-date.d.ts +4 -0
- package/dist/spreadsheet-artifact-query.d.ts +120 -0
- package/dist/spreadsheet-artifact-query.js +48 -0
- package/dist/spreadsheet-artifact-query.js.map +1 -0
- package/dist/task-notes.d.ts +128 -0
- package/dist/tool-catalog.d.ts +576 -0
- package/dist/video-generation.d.ts +580 -0
- package/dist/video-generation.js +59 -0
- package/dist/video-generation.js.map +1 -0
- package/dist/workspace-learning-policy.d.ts +208 -0
- package/dist/xai-provider-account-authority.d.ts +23 -0
- package/dist/xai-provider-account-authority.js +9 -0
- package/dist/xai-provider-account-authority.js.map +1 -0
- package/package.json +73 -1
- package/src/artifacts.ts +1 -1
- package/src/atlassian.ts +160 -0
- package/src/canonical-human-identities.ts +93 -0
- package/src/codex-provider-account-authority.ts +37 -0
- package/src/company-profile.ts +306 -0
- package/src/document-artifact-commands.ts +1709 -0
- package/src/document-artifact-query.ts +2 -0
- package/src/editable-artifact-binary.ts +396 -0
- package/src/editable-artifact-causal-frontier.ts +154 -0
- package/src/editable-artifact-codec-registry.ts +261 -0
- package/src/editable-artifact-committed-transaction.ts +478 -0
- package/src/editable-artifact-live.ts +1379 -0
- package/src/editable-artifact-serialized-commit.ts +494 -0
- package/src/editable-artifact-versions.ts +8 -0
- package/src/editable-artifacts.ts +473 -0
- package/src/google-drive.ts +68 -15
- package/src/image-generation.ts +106 -0
- package/src/index.ts +2920 -326
- package/src/interaction.ts +3173 -0
- package/src/knowledge.ts +207 -0
- package/src/memory-slack-delivery.ts +183 -0
- package/src/presentation-artifact-commands.ts +2035 -0
- package/src/presentation-artifact-query.ts +2 -0
- package/src/retained-output.ts +149 -2
- package/src/sandbox-snapshots.ts +28 -1
- package/src/scoped-knowledge.ts +18 -4
- package/src/slack-bot-scopes.ts +34 -1
- package/src/slack-task-policy.ts +215 -0
- package/src/spreadsheet-artifact-commands.ts +999 -0
- package/src/spreadsheet-artifact-date.ts +21 -0
- package/src/spreadsheet-artifact-query.ts +1411 -0
- package/src/task-notes.ts +92 -0
- package/src/tool-catalog.ts +334 -0
- package/src/video-generation.ts +431 -0
- package/src/workspace-learning-policy.ts +233 -0
- package/src/xai-provider-account-authority.ts +37 -0
- package/dist/chunk-5HR2GPSC.js +0 -11031
- package/dist/chunk-5HR2GPSC.js.map +0 -1
- package/dist/chunk-7JZMI22I.js.map +0 -1
|
@@ -0,0 +1,779 @@
|
|
|
1
|
+
// src/spreadsheet-artifact-date.ts
|
|
2
|
+
var ECMASCRIPT_DATE_MAX_MILLISECONDS = 8640000000000000n;
|
|
3
|
+
function canonicalSpreadsheetDateMilliseconds(value) {
|
|
4
|
+
const milliseconds = typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
5
|
+
if (!Number.isFinite(milliseconds) || new Date(milliseconds).toISOString() !== value) {
|
|
6
|
+
throw new TypeError("date must be canonical ISO");
|
|
7
|
+
}
|
|
8
|
+
return milliseconds;
|
|
9
|
+
}
|
|
10
|
+
function canonicalSpreadsheetDateFromMilliseconds(milliseconds) {
|
|
11
|
+
if (milliseconds < -ECMASCRIPT_DATE_MAX_MILLISECONDS || milliseconds > ECMASCRIPT_DATE_MAX_MILLISECONDS) {
|
|
12
|
+
throw new RangeError("date outside supported range");
|
|
13
|
+
}
|
|
14
|
+
return new Date(Number(milliseconds)).toISOString();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// src/spreadsheet-artifact-commands.ts
|
|
18
|
+
var SPREADSHEET_ARTIFACT_COMMAND_VERSION = 1;
|
|
19
|
+
var SPREADSHEET_ARTIFACT_COMMAND_MAX_BYTES = 4 * 1024 * 1024;
|
|
20
|
+
var SPREADSHEET_ARTIFACT_COMMAND_MAX_COMMANDS = 4096;
|
|
21
|
+
var SPREADSHEET_ARTIFACT_COMMAND_MAX_CELLS = 1e6;
|
|
22
|
+
var SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES = 1 * 1024 * 1024;
|
|
23
|
+
var SPREADSHEET_ARTIFACT_SHEET_NAME_MAX_UTF16_UNITS = 31;
|
|
24
|
+
var MAGIC = new TextEncoder().encode("OGASC001");
|
|
25
|
+
var HEADER_BYTES = 8 + 2 + 2 + 4 + 8;
|
|
26
|
+
var CHECKSUM_BYTES = 8;
|
|
27
|
+
var textEncoder = new TextEncoder();
|
|
28
|
+
var textDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
29
|
+
var LOWER_HEX_ID = /^[0-9a-f]{32}$/u;
|
|
30
|
+
var UINT64_HEX_ZERO = "0".repeat(16);
|
|
31
|
+
var UINT32_MAX = 4294967295;
|
|
32
|
+
var FNV_OFFSET = 0xcbf29ce484222325n;
|
|
33
|
+
var FNV_PRIME = 0x100000001b3n;
|
|
34
|
+
function editableArtifactStableId(value) {
|
|
35
|
+
return genericStableId(value, "stable id");
|
|
36
|
+
}
|
|
37
|
+
function spreadsheetSheetId(value) {
|
|
38
|
+
return sheetObjectId(value, "sheet id");
|
|
39
|
+
}
|
|
40
|
+
function encodeSpreadsheetArtifactCommandBatch(input) {
|
|
41
|
+
const batch = batchRecord(input);
|
|
42
|
+
const payload = new BinaryWriter(
|
|
43
|
+
SPREADSHEET_ARTIFACT_COMMAND_MAX_BYTES - HEADER_BYTES - CHECKSUM_BYTES
|
|
44
|
+
);
|
|
45
|
+
const context = new CommandContext();
|
|
46
|
+
for (let index = 0; index < batch.commands.length; index += 1) {
|
|
47
|
+
const command = ownArrayElement(batch.commands, index, "commands");
|
|
48
|
+
encodeCommand(payload, command, index, context);
|
|
49
|
+
}
|
|
50
|
+
const payloadBytes = payload.finish();
|
|
51
|
+
const output = new BinaryWriter(SPREADSHEET_ARTIFACT_COMMAND_MAX_BYTES);
|
|
52
|
+
output.bytes(MAGIC);
|
|
53
|
+
output.u16(SPREADSHEET_ARTIFACT_COMMAND_VERSION);
|
|
54
|
+
output.u16(0);
|
|
55
|
+
output.u32(batch.commands.length);
|
|
56
|
+
output.u64(BigInt(payloadBytes.byteLength));
|
|
57
|
+
output.bytes(payloadBytes);
|
|
58
|
+
output.u64(fnv1a64(output.view()));
|
|
59
|
+
return output.finish();
|
|
60
|
+
}
|
|
61
|
+
function decodeSpreadsheetArtifactCommandBatch(bytes) {
|
|
62
|
+
if (!(bytes instanceof Uint8Array)) {
|
|
63
|
+
throw new TypeError("spreadsheet command bytes must be a Uint8Array");
|
|
64
|
+
}
|
|
65
|
+
if (bytes.byteLength > SPREADSHEET_ARTIFACT_COMMAND_MAX_BYTES) {
|
|
66
|
+
throw new RangeError("spreadsheet command envelope exceeds its byte limit");
|
|
67
|
+
}
|
|
68
|
+
if (bytes.byteLength < HEADER_BYTES + CHECKSUM_BYTES) {
|
|
69
|
+
throw new TypeError("truncated spreadsheet command envelope");
|
|
70
|
+
}
|
|
71
|
+
const header = new BinaryReader(bytes);
|
|
72
|
+
if (!equalBytes(header.bytes(MAGIC.byteLength), MAGIC)) {
|
|
73
|
+
throw new TypeError("invalid spreadsheet command magic");
|
|
74
|
+
}
|
|
75
|
+
const version = header.u16();
|
|
76
|
+
if (version !== SPREADSHEET_ARTIFACT_COMMAND_VERSION) {
|
|
77
|
+
throw new TypeError(`unsupported spreadsheet command version: ${version}`);
|
|
78
|
+
}
|
|
79
|
+
if (header.u16() !== 0) {
|
|
80
|
+
throw new TypeError("spreadsheet command reserved flags must be zero");
|
|
81
|
+
}
|
|
82
|
+
const commandCount = header.u32();
|
|
83
|
+
if (commandCount < 1 || commandCount > SPREADSHEET_ARTIFACT_COMMAND_MAX_COMMANDS) {
|
|
84
|
+
throw new RangeError("spreadsheet command count is outside its limit");
|
|
85
|
+
}
|
|
86
|
+
const payloadLength = safeLength(header.u64(), "spreadsheet command payload");
|
|
87
|
+
const expectedLength = HEADER_BYTES + payloadLength + CHECKSUM_BYTES;
|
|
88
|
+
if (bytes.byteLength < expectedLength) {
|
|
89
|
+
throw new TypeError("truncated spreadsheet command envelope");
|
|
90
|
+
}
|
|
91
|
+
if (bytes.byteLength > expectedLength) {
|
|
92
|
+
throw new TypeError("spreadsheet command envelope contains trailing bytes");
|
|
93
|
+
}
|
|
94
|
+
const advertisedChecksum = readU64At(bytes, expectedLength - CHECKSUM_BYTES);
|
|
95
|
+
const actualChecksum = fnv1a64(bytes.subarray(0, expectedLength - CHECKSUM_BYTES));
|
|
96
|
+
if (advertisedChecksum !== actualChecksum) {
|
|
97
|
+
throw new TypeError("spreadsheet command checksum does not match");
|
|
98
|
+
}
|
|
99
|
+
const payload = new BinaryReader(bytes.subarray(HEADER_BYTES, HEADER_BYTES + payloadLength));
|
|
100
|
+
const context = new CommandContext();
|
|
101
|
+
const commands = [];
|
|
102
|
+
for (let index = 0; index < commandCount; index += 1) {
|
|
103
|
+
commands.push(decodeCommand(payload, index, context));
|
|
104
|
+
}
|
|
105
|
+
payload.done("spreadsheet command payload contains trailing bytes");
|
|
106
|
+
return Object.freeze({
|
|
107
|
+
version: SPREADSHEET_ARTIFACT_COMMAND_VERSION,
|
|
108
|
+
commands: Object.freeze(commands)
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
function assertCanonicalSpreadsheetArtifactCommandBytes(bytes) {
|
|
112
|
+
const canonical = encodeSpreadsheetArtifactCommandBatch(
|
|
113
|
+
decodeSpreadsheetArtifactCommandBatch(bytes)
|
|
114
|
+
);
|
|
115
|
+
if (!equalBytes(bytes, canonical)) {
|
|
116
|
+
throw new TypeError("spreadsheet command envelope is not canonical");
|
|
117
|
+
}
|
|
118
|
+
return bytes;
|
|
119
|
+
}
|
|
120
|
+
var CommandContext = class {
|
|
121
|
+
createdByIndex = /* @__PURE__ */ new Map();
|
|
122
|
+
createdSheetIds = /* @__PURE__ */ new Set();
|
|
123
|
+
totalCells = 0;
|
|
124
|
+
registerCreate(index, sheetId) {
|
|
125
|
+
if (this.createdSheetIds.has(sheetId)) {
|
|
126
|
+
throw commandError(index, "sheet id is created more than once in the batch");
|
|
127
|
+
}
|
|
128
|
+
this.createdByIndex.set(index, sheetId);
|
|
129
|
+
this.createdSheetIds.add(sheetId);
|
|
130
|
+
}
|
|
131
|
+
addCells(index, rows, columns) {
|
|
132
|
+
const count = rows * columns;
|
|
133
|
+
if (!Number.isSafeInteger(count) || count < 1) {
|
|
134
|
+
throw commandError(index, "cell block dimensions are invalid");
|
|
135
|
+
}
|
|
136
|
+
const next = this.totalCells + count;
|
|
137
|
+
if (!Number.isSafeInteger(next) || next > SPREADSHEET_ARTIFACT_COMMAND_MAX_CELLS) {
|
|
138
|
+
throw commandError(index, "cell count exceeds its transaction limit");
|
|
139
|
+
}
|
|
140
|
+
this.totalCells = next;
|
|
141
|
+
return count;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
function encodeCommand(writer, value, index, context) {
|
|
145
|
+
const command = plainRecord(value, `spreadsheet command ${index}`);
|
|
146
|
+
switch (command.kind) {
|
|
147
|
+
case "sheet.create": {
|
|
148
|
+
exactKeys(command, ["after", "kind", "name", "sheetId"], `spreadsheet command ${index}`);
|
|
149
|
+
const sheetId = sheetObjectId(command.sheetId, `spreadsheet command ${index} sheetId`);
|
|
150
|
+
const name = sheetName(command.name, index);
|
|
151
|
+
writer.u8(0);
|
|
152
|
+
writer.stableId(sheetId);
|
|
153
|
+
writer.string(name, SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES);
|
|
154
|
+
if (command.after === null) {
|
|
155
|
+
writer.u8(0);
|
|
156
|
+
} else {
|
|
157
|
+
writer.u8(1);
|
|
158
|
+
encodeSheetPrecondition(writer, command.after, index, context);
|
|
159
|
+
}
|
|
160
|
+
context.registerCreate(index, sheetId);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
case "sheet.rename": {
|
|
164
|
+
exactKeys(command, ["kind", "name", "sheet"], `spreadsheet command ${index}`);
|
|
165
|
+
writer.u8(1);
|
|
166
|
+
encodeSheetPrecondition(writer, command.sheet, index, context);
|
|
167
|
+
writer.string(sheetName(command.name, index), SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES);
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
case "sheet.delete": {
|
|
171
|
+
exactKeys(command, ["kind", "sheet"], `spreadsheet command ${index}`);
|
|
172
|
+
writer.u8(2);
|
|
173
|
+
encodeSheetPrecondition(writer, command.sheet, index, context);
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case "cells.set": {
|
|
177
|
+
exactKeys(
|
|
178
|
+
command,
|
|
179
|
+
["anchor", "cells", "columns", "kind", "rows", "sheet"],
|
|
180
|
+
`spreadsheet command ${index}`
|
|
181
|
+
);
|
|
182
|
+
const anchor = point(command.anchor, `spreadsheet command ${index} anchor`);
|
|
183
|
+
const rows = positiveU32(command.rows, `spreadsheet command ${index} rows`);
|
|
184
|
+
const columns = positiveU32(command.columns, `spreadsheet command ${index} columns`);
|
|
185
|
+
assertExtent(anchor.row, rows, "row", index);
|
|
186
|
+
assertExtent(anchor.column, columns, "column", index);
|
|
187
|
+
const count = context.addCells(index, rows, columns);
|
|
188
|
+
if (!Array.isArray(command.cells) || command.cells.length !== count) {
|
|
189
|
+
throw commandError(index, `cells must contain exactly ${count} row-major values`);
|
|
190
|
+
}
|
|
191
|
+
writer.u8(3);
|
|
192
|
+
encodeSheetPrecondition(writer, command.sheet, index, context);
|
|
193
|
+
writer.u32(anchor.row);
|
|
194
|
+
writer.u32(anchor.column);
|
|
195
|
+
writer.u32(rows);
|
|
196
|
+
writer.u32(columns);
|
|
197
|
+
for (let cellIndex = 0; cellIndex < count; cellIndex += 1) {
|
|
198
|
+
writer.cell(
|
|
199
|
+
ownArrayElement(command.cells, cellIndex, `spreadsheet command ${index} cells`)
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
case "range.clear": {
|
|
205
|
+
exactKeys(command, ["kind", "range", "sheet"], `spreadsheet command ${index}`);
|
|
206
|
+
const range = cellRange(command.range, index);
|
|
207
|
+
writer.u8(4);
|
|
208
|
+
encodeSheetPrecondition(writer, command.sheet, index, context);
|
|
209
|
+
writer.u32(range.start.row);
|
|
210
|
+
writer.u32(range.start.column);
|
|
211
|
+
writer.u32(range.end.row);
|
|
212
|
+
writer.u32(range.end.column);
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
default:
|
|
216
|
+
throw commandError(index, "unknown command kind");
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function decodeCommand(reader, index, context) {
|
|
220
|
+
switch (reader.u8()) {
|
|
221
|
+
case 0: {
|
|
222
|
+
const sheetId = reader.sheetObjectId();
|
|
223
|
+
const name = decodedSheetName(
|
|
224
|
+
reader.string(SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES),
|
|
225
|
+
index
|
|
226
|
+
);
|
|
227
|
+
const afterFlag = reader.u8();
|
|
228
|
+
if (afterFlag > 1) throw commandError(index, "after presence flag is invalid");
|
|
229
|
+
const after = afterFlag === 1 ? decodeSheetPrecondition(reader, index, context) : null;
|
|
230
|
+
context.registerCreate(index, sheetId);
|
|
231
|
+
return Object.freeze({ kind: "sheet.create", sheetId, name, after });
|
|
232
|
+
}
|
|
233
|
+
case 1:
|
|
234
|
+
return Object.freeze({
|
|
235
|
+
kind: "sheet.rename",
|
|
236
|
+
sheet: decodeSheetPrecondition(reader, index, context),
|
|
237
|
+
name: decodedSheetName(reader.string(SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES), index)
|
|
238
|
+
});
|
|
239
|
+
case 2:
|
|
240
|
+
return Object.freeze({
|
|
241
|
+
kind: "sheet.delete",
|
|
242
|
+
sheet: decodeSheetPrecondition(reader, index, context)
|
|
243
|
+
});
|
|
244
|
+
case 3: {
|
|
245
|
+
const sheet = decodeSheetPrecondition(reader, index, context);
|
|
246
|
+
const anchor = frozenPoint(reader.u32(), reader.u32());
|
|
247
|
+
const rows = reader.u32();
|
|
248
|
+
const columns = reader.u32();
|
|
249
|
+
if (rows === 0 || columns === 0) {
|
|
250
|
+
throw commandError(index, "cell block dimensions must be nonzero");
|
|
251
|
+
}
|
|
252
|
+
assertExtent(anchor.row, rows, "row", index);
|
|
253
|
+
assertExtent(anchor.column, columns, "column", index);
|
|
254
|
+
const count = context.addCells(index, rows, columns);
|
|
255
|
+
const cells = [];
|
|
256
|
+
for (let cellIndex = 0; cellIndex < count; cellIndex += 1) cells.push(reader.cell());
|
|
257
|
+
return Object.freeze({
|
|
258
|
+
kind: "cells.set",
|
|
259
|
+
sheet,
|
|
260
|
+
anchor,
|
|
261
|
+
rows,
|
|
262
|
+
columns,
|
|
263
|
+
cells: Object.freeze(cells)
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
case 4: {
|
|
267
|
+
const sheet = decodeSheetPrecondition(reader, index, context);
|
|
268
|
+
const start = frozenPoint(reader.u32(), reader.u32());
|
|
269
|
+
const end = frozenPoint(reader.u32(), reader.u32());
|
|
270
|
+
if (start.row > end.row || start.column > end.column) {
|
|
271
|
+
throw commandError(index, "clear range endpoints are not ordered");
|
|
272
|
+
}
|
|
273
|
+
return Object.freeze({
|
|
274
|
+
kind: "range.clear",
|
|
275
|
+
sheet,
|
|
276
|
+
range: Object.freeze({ start, end })
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
default:
|
|
280
|
+
throw commandError(index, "unknown binary command tag");
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function encodeSheetPrecondition(writer, value, commandIndex, context) {
|
|
284
|
+
const input = plainRecord(value, `spreadsheet command ${commandIndex} sheet precondition`);
|
|
285
|
+
if (input.kind === "generation") {
|
|
286
|
+
exactKeys(
|
|
287
|
+
input,
|
|
288
|
+
["creationOperationId", "kind", "sheetId"],
|
|
289
|
+
`spreadsheet command ${commandIndex} sheet generation`
|
|
290
|
+
);
|
|
291
|
+
writer.u8(0);
|
|
292
|
+
writer.stableId(sheetObjectId(input.sheetId, "sheet generation sheetId"));
|
|
293
|
+
writer.stableId(genericStableId(input.creationOperationId, "sheet creation operation id"));
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (input.kind === "created-in-batch") {
|
|
297
|
+
exactKeys(
|
|
298
|
+
input,
|
|
299
|
+
["createCommandIndex", "kind", "sheetId"],
|
|
300
|
+
`spreadsheet command ${commandIndex} prior-create precondition`
|
|
301
|
+
);
|
|
302
|
+
const sheetId = sheetObjectId(input.sheetId, "prior-create sheetId");
|
|
303
|
+
const createCommandIndex = nonnegativeU32(
|
|
304
|
+
input.createCommandIndex,
|
|
305
|
+
"prior-create command index"
|
|
306
|
+
);
|
|
307
|
+
assertPriorCreate(context, commandIndex, createCommandIndex, sheetId);
|
|
308
|
+
writer.u8(1);
|
|
309
|
+
writer.stableId(sheetId);
|
|
310
|
+
writer.u32(createCommandIndex);
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
throw commandError(commandIndex, "unknown sheet precondition kind");
|
|
314
|
+
}
|
|
315
|
+
function decodeSheetPrecondition(reader, commandIndex, context) {
|
|
316
|
+
switch (reader.u8()) {
|
|
317
|
+
case 0:
|
|
318
|
+
return Object.freeze({
|
|
319
|
+
kind: "generation",
|
|
320
|
+
sheetId: reader.sheetObjectId(),
|
|
321
|
+
creationOperationId: reader.genericStableId()
|
|
322
|
+
});
|
|
323
|
+
case 1: {
|
|
324
|
+
const sheetId = reader.sheetObjectId();
|
|
325
|
+
const createCommandIndex = reader.u32();
|
|
326
|
+
assertPriorCreate(context, commandIndex, createCommandIndex, sheetId);
|
|
327
|
+
return Object.freeze({
|
|
328
|
+
kind: "created-in-batch",
|
|
329
|
+
sheetId,
|
|
330
|
+
createCommandIndex
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
default:
|
|
334
|
+
throw commandError(commandIndex, "unknown sheet precondition tag");
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function assertPriorCreate(context, commandIndex, createCommandIndex, sheetId) {
|
|
338
|
+
if (createCommandIndex >= commandIndex) {
|
|
339
|
+
throw commandError(commandIndex, "prior-create reference must point to an earlier command");
|
|
340
|
+
}
|
|
341
|
+
if (context.createdByIndex.get(createCommandIndex) !== sheetId) {
|
|
342
|
+
throw commandError(
|
|
343
|
+
commandIndex,
|
|
344
|
+
"prior-create reference must match the referenced create command and sheet id"
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function batchRecord(input) {
|
|
349
|
+
const batch = plainRecord(input, "spreadsheet command batch");
|
|
350
|
+
exactKeys(batch, ["commands", "version"], "spreadsheet command batch");
|
|
351
|
+
if (batch.version !== SPREADSHEET_ARTIFACT_COMMAND_VERSION) {
|
|
352
|
+
throw new TypeError("spreadsheet command batch version must be 1");
|
|
353
|
+
}
|
|
354
|
+
if (!Array.isArray(batch.commands)) throw new TypeError("commands must be an array");
|
|
355
|
+
if (batch.commands.length < 1 || batch.commands.length > SPREADSHEET_ARTIFACT_COMMAND_MAX_COMMANDS) {
|
|
356
|
+
throw new RangeError("spreadsheet command count is outside its limit");
|
|
357
|
+
}
|
|
358
|
+
return input;
|
|
359
|
+
}
|
|
360
|
+
function cellRange(value, index) {
|
|
361
|
+
const range = plainRecord(value, `spreadsheet command ${index} range`);
|
|
362
|
+
exactKeys(range, ["end", "start"], `spreadsheet command ${index} range`);
|
|
363
|
+
const start = point(range.start, `spreadsheet command ${index} range start`);
|
|
364
|
+
const end = point(range.end, `spreadsheet command ${index} range end`);
|
|
365
|
+
if (start.row > end.row || start.column > end.column) {
|
|
366
|
+
throw commandError(index, "clear range endpoints are not ordered");
|
|
367
|
+
}
|
|
368
|
+
return { start, end };
|
|
369
|
+
}
|
|
370
|
+
function point(value, label) {
|
|
371
|
+
const input = plainRecord(value, label);
|
|
372
|
+
exactKeys(input, ["column", "row"], label);
|
|
373
|
+
return {
|
|
374
|
+
row: nonnegativeU32(input.row, `${label} row`),
|
|
375
|
+
column: nonnegativeU32(input.column, `${label} column`)
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
function frozenPoint(row, column) {
|
|
379
|
+
return Object.freeze({ row, column });
|
|
380
|
+
}
|
|
381
|
+
function sheetName(value, index) {
|
|
382
|
+
if (typeof value !== "string") throw commandError(index, "sheet name must be a string");
|
|
383
|
+
return decodedSheetName(value, index);
|
|
384
|
+
}
|
|
385
|
+
function decodedSheetName(value, index) {
|
|
386
|
+
const bytes = strictUtf8(value, "sheet name");
|
|
387
|
+
const forbidden = /[\\/?*[\]:\0]/u.test(value);
|
|
388
|
+
if (bytes.byteLength === 0 || value.trim() !== value || value.length > SPREADSHEET_ARTIFACT_SHEET_NAME_MAX_UTF16_UNITS || forbidden) {
|
|
389
|
+
throw commandError(index, "sheet name does not match the public spreadsheet model");
|
|
390
|
+
}
|
|
391
|
+
return value;
|
|
392
|
+
}
|
|
393
|
+
function genericStableId(value, label) {
|
|
394
|
+
if (typeof value !== "string" || !LOWER_HEX_ID.test(value) || /^0+$/u.test(value)) {
|
|
395
|
+
throw new TypeError(`${label} must be nonzero fixed-width lowercase hexadecimal text`);
|
|
396
|
+
}
|
|
397
|
+
return value;
|
|
398
|
+
}
|
|
399
|
+
function sheetObjectId(value, label) {
|
|
400
|
+
const id = genericStableId(value, label);
|
|
401
|
+
if (id.slice(0, 16) === UINT64_HEX_ZERO || id.slice(16) === UINT64_HEX_ZERO) {
|
|
402
|
+
throw new TypeError(`${label} must have a nonzero namespace and counter`);
|
|
403
|
+
}
|
|
404
|
+
return id;
|
|
405
|
+
}
|
|
406
|
+
function positiveU32(value, label) {
|
|
407
|
+
const output = nonnegativeU32(value, label);
|
|
408
|
+
if (output === 0) throw new TypeError(`${label} must be positive`);
|
|
409
|
+
return output;
|
|
410
|
+
}
|
|
411
|
+
function nonnegativeU32(value, label) {
|
|
412
|
+
if (!Number.isInteger(value) || value < 0 || value > UINT32_MAX) {
|
|
413
|
+
throw new TypeError(`${label} must be a uint32`);
|
|
414
|
+
}
|
|
415
|
+
return value;
|
|
416
|
+
}
|
|
417
|
+
function assertExtent(start, length, axis, index) {
|
|
418
|
+
if (length - 1 > UINT32_MAX - start) {
|
|
419
|
+
throw commandError(index, `${axis} extent exceeds uint32 coordinates`);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function safeLength(value, label) {
|
|
423
|
+
if (value > BigInt(Number.MAX_SAFE_INTEGER)) throw new RangeError(`${label} length is unsafe`);
|
|
424
|
+
const length = Number(value);
|
|
425
|
+
if (length > SPREADSHEET_ARTIFACT_COMMAND_MAX_BYTES - HEADER_BYTES - CHECKSUM_BYTES) {
|
|
426
|
+
throw new RangeError(`${label} exceeds its byte limit`);
|
|
427
|
+
}
|
|
428
|
+
return length;
|
|
429
|
+
}
|
|
430
|
+
function plainRecord(value, label) {
|
|
431
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || Object.getPrototypeOf(value) !== Object.prototype) {
|
|
432
|
+
throw new TypeError(`${label} must be a plain record`);
|
|
433
|
+
}
|
|
434
|
+
return value;
|
|
435
|
+
}
|
|
436
|
+
function exactKeys(value, expected, label) {
|
|
437
|
+
const keys = Reflect.ownKeys(value);
|
|
438
|
+
if (keys.some((key) => typeof key !== "string")) {
|
|
439
|
+
throw new TypeError(`${label} contains unsupported symbol fields`);
|
|
440
|
+
}
|
|
441
|
+
const actual = keys.sort(compareCodeUnits);
|
|
442
|
+
if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) {
|
|
443
|
+
throw new TypeError(`${label} fields must be exactly: ${expected.join(", ")}`);
|
|
444
|
+
}
|
|
445
|
+
for (const key of actual) {
|
|
446
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
447
|
+
if (!descriptor || !("value" in descriptor) || !descriptor.enumerable) {
|
|
448
|
+
throw new TypeError(`${label} fields must be enumerable data properties`);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function ownArrayElement(value, index, label) {
|
|
453
|
+
if (!Object.hasOwn(value, index)) throw new TypeError(`${label} must be dense`);
|
|
454
|
+
return value[index];
|
|
455
|
+
}
|
|
456
|
+
function commandError(index, message) {
|
|
457
|
+
return new TypeError(`spreadsheet command ${index}: ${message}`);
|
|
458
|
+
}
|
|
459
|
+
function strictUtf8(value, label) {
|
|
460
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
461
|
+
const code = value.charCodeAt(index);
|
|
462
|
+
if (code >= 55296 && code <= 56319) {
|
|
463
|
+
const next = value.charCodeAt(index + 1);
|
|
464
|
+
if (!(next >= 56320 && next <= 57343)) {
|
|
465
|
+
throw new TypeError(`${label} contains an unpaired surrogate`);
|
|
466
|
+
}
|
|
467
|
+
index += 1;
|
|
468
|
+
} else if (code >= 56320 && code <= 57343) {
|
|
469
|
+
throw new TypeError(`${label} contains an unpaired surrogate`);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return textEncoder.encode(value);
|
|
473
|
+
}
|
|
474
|
+
function compareCodeUnits(left, right) {
|
|
475
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
476
|
+
}
|
|
477
|
+
function fnv1a64(bytes) {
|
|
478
|
+
let hash = FNV_OFFSET;
|
|
479
|
+
for (const byte of bytes) {
|
|
480
|
+
hash ^= BigInt(byte);
|
|
481
|
+
hash = BigInt.asUintN(64, hash * FNV_PRIME);
|
|
482
|
+
}
|
|
483
|
+
return hash;
|
|
484
|
+
}
|
|
485
|
+
function equalBytes(left, right) {
|
|
486
|
+
return left.byteLength === right.byteLength && left.every((value, index) => value === right[index]);
|
|
487
|
+
}
|
|
488
|
+
function readU64At(bytes, offset) {
|
|
489
|
+
let value = 0n;
|
|
490
|
+
for (let index = 0; index < 8; index += 1) {
|
|
491
|
+
value |= BigInt(bytes[offset + index]) << BigInt(index * 8);
|
|
492
|
+
}
|
|
493
|
+
return value;
|
|
494
|
+
}
|
|
495
|
+
var STANDARD_ERROR_TAGS = Object.freeze({
|
|
496
|
+
"#NULL!": 0,
|
|
497
|
+
"#DIV/0!": 1,
|
|
498
|
+
"#VALUE!": 2,
|
|
499
|
+
"#REF!": 3,
|
|
500
|
+
"#NAME?": 4,
|
|
501
|
+
"#NUM!": 5,
|
|
502
|
+
"#N/A": 6,
|
|
503
|
+
"#SPILL!": 7,
|
|
504
|
+
"#CALC!": 8
|
|
505
|
+
});
|
|
506
|
+
var STANDARD_ERRORS = Object.freeze([
|
|
507
|
+
"#NULL!",
|
|
508
|
+
"#DIV/0!",
|
|
509
|
+
"#VALUE!",
|
|
510
|
+
"#REF!",
|
|
511
|
+
"#NAME?",
|
|
512
|
+
"#NUM!",
|
|
513
|
+
"#N/A",
|
|
514
|
+
"#SPILL!",
|
|
515
|
+
"#CALC!"
|
|
516
|
+
]);
|
|
517
|
+
var BinaryWriter = class {
|
|
518
|
+
constructor(maximum) {
|
|
519
|
+
this.maximum = maximum;
|
|
520
|
+
this.buffer = new Uint8Array(Math.min(1024, maximum));
|
|
521
|
+
this.viewBuffer = new DataView(this.buffer.buffer);
|
|
522
|
+
}
|
|
523
|
+
buffer;
|
|
524
|
+
viewBuffer;
|
|
525
|
+
length = 0;
|
|
526
|
+
view() {
|
|
527
|
+
return this.buffer.subarray(0, this.length);
|
|
528
|
+
}
|
|
529
|
+
finish() {
|
|
530
|
+
return this.buffer.slice(0, this.length);
|
|
531
|
+
}
|
|
532
|
+
u8(value) {
|
|
533
|
+
this.reserve(1);
|
|
534
|
+
this.viewBuffer.setUint8(this.length, value);
|
|
535
|
+
this.length += 1;
|
|
536
|
+
}
|
|
537
|
+
u16(value) {
|
|
538
|
+
this.reserve(2);
|
|
539
|
+
this.viewBuffer.setUint16(this.length, value, true);
|
|
540
|
+
this.length += 2;
|
|
541
|
+
}
|
|
542
|
+
u32(value) {
|
|
543
|
+
this.reserve(4);
|
|
544
|
+
this.viewBuffer.setUint32(this.length, value, true);
|
|
545
|
+
this.length += 4;
|
|
546
|
+
}
|
|
547
|
+
u64(value) {
|
|
548
|
+
this.reserve(8);
|
|
549
|
+
this.viewBuffer.setBigUint64(this.length, value, true);
|
|
550
|
+
this.length += 8;
|
|
551
|
+
}
|
|
552
|
+
i64(value) {
|
|
553
|
+
this.reserve(8);
|
|
554
|
+
this.viewBuffer.setBigInt64(this.length, value, true);
|
|
555
|
+
this.length += 8;
|
|
556
|
+
}
|
|
557
|
+
f64(value) {
|
|
558
|
+
this.reserve(8);
|
|
559
|
+
this.viewBuffer.setFloat64(this.length, value === 0 ? 0 : value, true);
|
|
560
|
+
this.length += 8;
|
|
561
|
+
}
|
|
562
|
+
stableId(value) {
|
|
563
|
+
this.u64(BigInt(`0x${value.slice(16)}`));
|
|
564
|
+
this.u64(BigInt(`0x${value.slice(0, 16)}`));
|
|
565
|
+
}
|
|
566
|
+
string(value, maximum) {
|
|
567
|
+
const bytes = strictUtf8(value, "spreadsheet string");
|
|
568
|
+
if (bytes.byteLength > maximum)
|
|
569
|
+
throw new RangeError("spreadsheet string exceeds its byte limit");
|
|
570
|
+
this.u32(bytes.byteLength);
|
|
571
|
+
this.bytes(bytes);
|
|
572
|
+
}
|
|
573
|
+
cell(value) {
|
|
574
|
+
if (isFormulaCell(value)) {
|
|
575
|
+
const cell = plainRecord(value, "formula cell");
|
|
576
|
+
exactKeys(cell, ["cached", "formula"], "formula cell");
|
|
577
|
+
if (typeof cell.formula !== "string" || cell.formula.length === 0) {
|
|
578
|
+
throw new TypeError("formula source must be a nonempty string");
|
|
579
|
+
}
|
|
580
|
+
this.u8(1);
|
|
581
|
+
this.string(cell.formula, SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES);
|
|
582
|
+
this.scalar(cell.cached);
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
this.u8(0);
|
|
586
|
+
this.scalar(value);
|
|
587
|
+
}
|
|
588
|
+
scalar(value) {
|
|
589
|
+
if (value === null) {
|
|
590
|
+
this.u8(0);
|
|
591
|
+
} else if (value === false) {
|
|
592
|
+
this.u8(1);
|
|
593
|
+
} else if (value === true) {
|
|
594
|
+
this.u8(2);
|
|
595
|
+
} else if (typeof value === "number") {
|
|
596
|
+
if (!Number.isFinite(value)) throw new TypeError("spreadsheet numbers must be finite");
|
|
597
|
+
this.u8(3);
|
|
598
|
+
this.f64(value);
|
|
599
|
+
} else if (typeof value === "string") {
|
|
600
|
+
this.u8(4);
|
|
601
|
+
this.string(value, SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES);
|
|
602
|
+
} else if (isDateValue(value)) {
|
|
603
|
+
const date = plainRecord(value, "date cell");
|
|
604
|
+
exactKeys(date, ["date"], "date cell");
|
|
605
|
+
this.u8(6);
|
|
606
|
+
this.i64(BigInt(canonicalDateMilliseconds(date.date)));
|
|
607
|
+
} else if (isFormulaError(value)) {
|
|
608
|
+
const error = plainRecord(value, "formula error");
|
|
609
|
+
exactKeys(error, ["error"], "formula error");
|
|
610
|
+
this.u8(5);
|
|
611
|
+
const tag = STANDARD_ERROR_TAGS[error.error];
|
|
612
|
+
if (tag !== void 0) {
|
|
613
|
+
this.u8(tag);
|
|
614
|
+
} else {
|
|
615
|
+
this.u8(9);
|
|
616
|
+
this.string(error.error, SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES);
|
|
617
|
+
}
|
|
618
|
+
} else {
|
|
619
|
+
throw new TypeError("spreadsheet cell has an unsupported value shape");
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
bytes(value) {
|
|
623
|
+
this.reserve(value.byteLength);
|
|
624
|
+
this.buffer.set(value, this.length);
|
|
625
|
+
this.length += value.byteLength;
|
|
626
|
+
}
|
|
627
|
+
reserve(additional) {
|
|
628
|
+
const needed = this.length + additional;
|
|
629
|
+
if (!Number.isSafeInteger(needed) || needed > this.maximum) {
|
|
630
|
+
throw new RangeError("spreadsheet command envelope exceeds its byte limit");
|
|
631
|
+
}
|
|
632
|
+
if (needed <= this.buffer.byteLength) return;
|
|
633
|
+
let size = Math.max(1, this.buffer.byteLength);
|
|
634
|
+
while (size < needed) size = Math.min(this.maximum, size * 2);
|
|
635
|
+
const next = new Uint8Array(size);
|
|
636
|
+
next.set(this.buffer.subarray(0, this.length));
|
|
637
|
+
this.buffer = next;
|
|
638
|
+
this.viewBuffer = new DataView(next.buffer);
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
var BinaryReader = class {
|
|
642
|
+
constructor(input) {
|
|
643
|
+
this.input = input;
|
|
644
|
+
}
|
|
645
|
+
offset = 0;
|
|
646
|
+
u8() {
|
|
647
|
+
return this.bytes(1)[0];
|
|
648
|
+
}
|
|
649
|
+
u16() {
|
|
650
|
+
const bytes = this.bytes(2);
|
|
651
|
+
return bytes[0] | bytes[1] << 8;
|
|
652
|
+
}
|
|
653
|
+
u32() {
|
|
654
|
+
const bytes = this.bytes(4);
|
|
655
|
+
return bytes[0] + bytes[1] * 2 ** 8 + bytes[2] * 2 ** 16 + bytes[3] * 2 ** 24;
|
|
656
|
+
}
|
|
657
|
+
u64() {
|
|
658
|
+
const bytes = this.bytes(8);
|
|
659
|
+
let value = 0n;
|
|
660
|
+
for (let index = 0; index < 8; index += 1) {
|
|
661
|
+
value |= BigInt(bytes[index]) << BigInt(index * 8);
|
|
662
|
+
}
|
|
663
|
+
return value;
|
|
664
|
+
}
|
|
665
|
+
i64() {
|
|
666
|
+
const bytes = this.bytes(8);
|
|
667
|
+
return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getBigInt64(0, true);
|
|
668
|
+
}
|
|
669
|
+
f64() {
|
|
670
|
+
const bytes = this.bytes(8);
|
|
671
|
+
const value = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getFloat64(
|
|
672
|
+
0,
|
|
673
|
+
true
|
|
674
|
+
);
|
|
675
|
+
if (!Number.isFinite(value)) throw new TypeError("spreadsheet numbers must be finite");
|
|
676
|
+
if (Object.is(value, -0)) {
|
|
677
|
+
throw new TypeError("spreadsheet numbers must encode zero with a positive sign");
|
|
678
|
+
}
|
|
679
|
+
return value;
|
|
680
|
+
}
|
|
681
|
+
sheetObjectId() {
|
|
682
|
+
return sheetObjectId(this.stableIdText(), "sheet id");
|
|
683
|
+
}
|
|
684
|
+
genericStableId() {
|
|
685
|
+
return genericStableId(this.stableIdText(), "stable id");
|
|
686
|
+
}
|
|
687
|
+
string(maximum) {
|
|
688
|
+
const length = this.u32();
|
|
689
|
+
if (length > maximum) throw new RangeError("spreadsheet string exceeds its byte limit");
|
|
690
|
+
return textDecoder.decode(this.bytes(length));
|
|
691
|
+
}
|
|
692
|
+
cell() {
|
|
693
|
+
const formulaTag = this.u8();
|
|
694
|
+
if (formulaTag > 1) throw new TypeError("spreadsheet formula presence tag is invalid");
|
|
695
|
+
const formula = formulaTag === 1 ? this.nonemptyFormula(this.string(SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES)) : null;
|
|
696
|
+
const cached = this.scalar();
|
|
697
|
+
return formula === null ? cached : Object.freeze({ formula, cached });
|
|
698
|
+
}
|
|
699
|
+
done(message) {
|
|
700
|
+
if (this.offset !== this.input.byteLength) throw new TypeError(message);
|
|
701
|
+
}
|
|
702
|
+
bytes(length) {
|
|
703
|
+
const end = this.offset + length;
|
|
704
|
+
if (!Number.isSafeInteger(length) || length < 0 || end > this.input.byteLength) {
|
|
705
|
+
throw new TypeError("truncated spreadsheet command envelope");
|
|
706
|
+
}
|
|
707
|
+
const result = this.input.subarray(this.offset, end);
|
|
708
|
+
this.offset = end;
|
|
709
|
+
return result;
|
|
710
|
+
}
|
|
711
|
+
stableIdText() {
|
|
712
|
+
const counter = this.u64().toString(16).padStart(16, "0");
|
|
713
|
+
const namespace = this.u64().toString(16).padStart(16, "0");
|
|
714
|
+
return `${namespace}${counter}`;
|
|
715
|
+
}
|
|
716
|
+
nonemptyFormula(value) {
|
|
717
|
+
if (value.length === 0) throw new TypeError("formula source must not be empty");
|
|
718
|
+
return value;
|
|
719
|
+
}
|
|
720
|
+
scalar() {
|
|
721
|
+
switch (this.u8()) {
|
|
722
|
+
case 0:
|
|
723
|
+
return null;
|
|
724
|
+
case 1:
|
|
725
|
+
return false;
|
|
726
|
+
case 2:
|
|
727
|
+
return true;
|
|
728
|
+
case 3:
|
|
729
|
+
return this.f64();
|
|
730
|
+
case 4:
|
|
731
|
+
return this.string(SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES);
|
|
732
|
+
case 5: {
|
|
733
|
+
const tag = this.u8();
|
|
734
|
+
if (tag <= 8) return Object.freeze({ error: STANDARD_ERRORS[tag] });
|
|
735
|
+
if (tag === 9) {
|
|
736
|
+
return Object.freeze({
|
|
737
|
+
error: this.string(SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES)
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
throw new TypeError("spreadsheet formula error tag is invalid");
|
|
741
|
+
}
|
|
742
|
+
case 6:
|
|
743
|
+
return Object.freeze({
|
|
744
|
+
date: canonicalSpreadsheetDateFromMilliseconds(this.i64())
|
|
745
|
+
});
|
|
746
|
+
default:
|
|
747
|
+
throw new TypeError("spreadsheet scalar tag is invalid");
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
function isFormulaCell(value) {
|
|
752
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.hasOwn(value, "formula");
|
|
753
|
+
}
|
|
754
|
+
function isFormulaError(value) {
|
|
755
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.error === "string";
|
|
756
|
+
}
|
|
757
|
+
function isDateValue(value) {
|
|
758
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.hasOwn(value, "date");
|
|
759
|
+
}
|
|
760
|
+
function canonicalDateMilliseconds(value) {
|
|
761
|
+
return canonicalSpreadsheetDateMilliseconds(value);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
export {
|
|
765
|
+
canonicalSpreadsheetDateMilliseconds,
|
|
766
|
+
canonicalSpreadsheetDateFromMilliseconds,
|
|
767
|
+
SPREADSHEET_ARTIFACT_COMMAND_VERSION,
|
|
768
|
+
SPREADSHEET_ARTIFACT_COMMAND_MAX_BYTES,
|
|
769
|
+
SPREADSHEET_ARTIFACT_COMMAND_MAX_COMMANDS,
|
|
770
|
+
SPREADSHEET_ARTIFACT_COMMAND_MAX_CELLS,
|
|
771
|
+
SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES,
|
|
772
|
+
SPREADSHEET_ARTIFACT_SHEET_NAME_MAX_UTF16_UNITS,
|
|
773
|
+
editableArtifactStableId,
|
|
774
|
+
spreadsheetSheetId,
|
|
775
|
+
encodeSpreadsheetArtifactCommandBatch,
|
|
776
|
+
decodeSpreadsheetArtifactCommandBatch,
|
|
777
|
+
assertCanonicalSpreadsheetArtifactCommandBytes
|
|
778
|
+
};
|
|
779
|
+
//# sourceMappingURL=chunk-LSB7GRLG.js.map
|