@bilig/workbook 0.42.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/guards.js ADDED
@@ -0,0 +1,659 @@
1
+ import { isCellRangeRef, isLiteralInput } from '@bilig/protocol';
2
+ const HORIZONTAL_ALIGNMENT_VALUES = new Set(['general', 'left', 'center', 'right', 'fill', 'justify', 'centerContinuous', 'distributed']);
3
+ const VERTICAL_ALIGNMENT_VALUES = new Set(['top', 'middle', 'bottom', 'justify', 'distributed']);
4
+ const BORDER_STYLE_VALUES = new Set(['solid', 'dashed', 'dotted', 'double']);
5
+ const BORDER_WEIGHT_VALUES = new Set(['thin', 'medium', 'thick']);
6
+ const NUMBER_FORMAT_KIND_VALUES = new Set(['general', 'number', 'currency', 'accounting', 'percent', 'date', 'time', 'datetime', 'text']);
7
+ const COMPATIBILITY_MODE_VALUES = new Set(['excel-modern', 'odf-1.4']);
8
+ const SORT_DIRECTION_VALUES = new Set(['asc', 'desc']);
9
+ const PIVOT_AGGREGATION_VALUES = new Set(['sum', 'count', 'countNums', 'average', 'min', 'max', 'product']);
10
+ const VALIDATION_COMPARISON_OPERATOR_VALUES = new Set([
11
+ 'between',
12
+ 'notBetween',
13
+ 'equal',
14
+ 'notEqual',
15
+ 'greaterThan',
16
+ 'greaterThanOrEqual',
17
+ 'lessThan',
18
+ 'lessThanOrEqual',
19
+ ]);
20
+ const VALIDATION_ERROR_STYLE_VALUES = new Set(['stop', 'warning', 'information']);
21
+ function isRecord(value) {
22
+ return typeof value === 'object' && value !== null;
23
+ }
24
+ function isFiniteNumber(value) {
25
+ return typeof value === 'number' && Number.isFinite(value);
26
+ }
27
+ function isSafeNonNegativeInteger(value) {
28
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
29
+ }
30
+ function isSafePositiveInteger(value) {
31
+ return typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
32
+ }
33
+ function isStringArray(value) {
34
+ return Array.isArray(value) && value.every((entry) => typeof entry === 'string');
35
+ }
36
+ function isOptionalString(value) {
37
+ return value === undefined || typeof value === 'string';
38
+ }
39
+ function isOptionalNumber(value) {
40
+ return value === undefined || isFiniteNumber(value);
41
+ }
42
+ function isOptionalSafePositiveInteger(value) {
43
+ return value === undefined || isSafePositiveInteger(value);
44
+ }
45
+ function isOptionalSafeNonNegativeInteger(value) {
46
+ return value === undefined || isSafeNonNegativeInteger(value);
47
+ }
48
+ function isOptionalNullableNumber(value) {
49
+ return value === undefined || value === null || isFiniteNumber(value);
50
+ }
51
+ function isOptionalNullableSafePositiveInteger(value) {
52
+ return value === undefined || value === null || isSafePositiveInteger(value);
53
+ }
54
+ function isOptionalBoolean(value) {
55
+ return value === undefined || typeof value === 'boolean';
56
+ }
57
+ function isOptionalLiteralInput(value) {
58
+ return value === undefined || isLiteralInput(value);
59
+ }
60
+ function isOptionalNullableBoolean(value) {
61
+ return value === undefined || value === null || typeof value === 'boolean';
62
+ }
63
+ function hasString(value, key) {
64
+ return typeof value[key] === 'string';
65
+ }
66
+ function hasFiniteNumber(value, key) {
67
+ return isFiniteNumber(value[key]);
68
+ }
69
+ function hasSafeNonNegativeInteger(value, key) {
70
+ return isSafeNonNegativeInteger(value[key]);
71
+ }
72
+ function hasSafePositiveInteger(value, key) {
73
+ return isSafePositiveInteger(value[key]);
74
+ }
75
+ function isWorkbookAxisEntry(value) {
76
+ return (isRecord(value) &&
77
+ hasString(value, 'id') &&
78
+ hasSafeNonNegativeInteger(value, 'index') &&
79
+ isOptionalNullableSafePositiveInteger(value['size']) &&
80
+ isOptionalNullableBoolean(value['hidden']));
81
+ }
82
+ function isCellBorderSide(value) {
83
+ return (isRecord(value) &&
84
+ hasString(value, 'color') &&
85
+ typeof value['style'] === 'string' &&
86
+ BORDER_STYLE_VALUES.has(value['style']) &&
87
+ typeof value['weight'] === 'string' &&
88
+ BORDER_WEIGHT_VALUES.has(value['weight']));
89
+ }
90
+ function isCellStyleRecord(value) {
91
+ if (!isRecord(value) || !hasString(value, 'id')) {
92
+ return false;
93
+ }
94
+ const fill = value['fill'];
95
+ if (fill !== undefined && (!isRecord(fill) || typeof fill['backgroundColor'] !== 'string')) {
96
+ return false;
97
+ }
98
+ const font = value['font'];
99
+ if (font !== undefined &&
100
+ (!isRecord(font) ||
101
+ !isOptionalString(font['family']) ||
102
+ !isOptionalNumber(font['size']) ||
103
+ !isOptionalBoolean(font['bold']) ||
104
+ !isOptionalBoolean(font['italic']) ||
105
+ !isOptionalBoolean(font['underline']) ||
106
+ !isOptionalString(font['color']))) {
107
+ return false;
108
+ }
109
+ const alignment = value['alignment'];
110
+ if (alignment !== undefined &&
111
+ (!isRecord(alignment) ||
112
+ !(alignment['horizontal'] === undefined ||
113
+ (typeof alignment['horizontal'] === 'string' && HORIZONTAL_ALIGNMENT_VALUES.has(alignment['horizontal']))) ||
114
+ !(alignment['vertical'] === undefined ||
115
+ (typeof alignment['vertical'] === 'string' && VERTICAL_ALIGNMENT_VALUES.has(alignment['vertical']))) ||
116
+ !isOptionalBoolean(alignment['wrap']) ||
117
+ !isOptionalNumber(alignment['indent']) ||
118
+ !isOptionalBoolean(alignment['shrinkToFit']) ||
119
+ !isOptionalNumber(alignment['readingOrder']) ||
120
+ !isOptionalNumber(alignment['textRotation']) ||
121
+ !isOptionalBoolean(alignment['justifyLastLine']))) {
122
+ return false;
123
+ }
124
+ const borders = value['borders'];
125
+ if (borders !== undefined &&
126
+ (!isRecord(borders) ||
127
+ !(borders['top'] === undefined || isCellBorderSide(borders['top'])) ||
128
+ !(borders['right'] === undefined || isCellBorderSide(borders['right'])) ||
129
+ !(borders['bottom'] === undefined || isCellBorderSide(borders['bottom'])) ||
130
+ !(borders['left'] === undefined || isCellBorderSide(borders['left'])))) {
131
+ return false;
132
+ }
133
+ const protection = value['protection'];
134
+ if (protection !== undefined &&
135
+ (!isRecord(protection) || !isOptionalBoolean(protection['locked']) || !isOptionalBoolean(protection['hidden']))) {
136
+ return false;
137
+ }
138
+ return true;
139
+ }
140
+ function isCellNumberFormatRecord(value) {
141
+ return (isRecord(value) &&
142
+ hasString(value, 'id') &&
143
+ hasString(value, 'code') &&
144
+ typeof value['kind'] === 'string' &&
145
+ NUMBER_FORMAT_KIND_VALUES.has(value['kind']));
146
+ }
147
+ function isWorkbookCalculationSettings(value) {
148
+ return (isRecord(value) &&
149
+ (value['mode'] === 'automatic' || value['mode'] === 'manual') &&
150
+ (value['compatibilityMode'] === undefined ||
151
+ (typeof value['compatibilityMode'] === 'string' && COMPATIBILITY_MODE_VALUES.has(value['compatibilityMode']))));
152
+ }
153
+ function isWorkbookVolatileContext(value) {
154
+ return isRecord(value) && hasFiniteNumber(value, 'recalcEpoch');
155
+ }
156
+ function isWorkbookSortKey(value) {
157
+ return (isRecord(value) &&
158
+ hasString(value, 'keyAddress') &&
159
+ typeof value['direction'] === 'string' &&
160
+ SORT_DIRECTION_VALUES.has(value['direction']));
161
+ }
162
+ function isWorkbookValidationListSource(value) {
163
+ if (!isRecord(value) || typeof value['kind'] !== 'string') {
164
+ return false;
165
+ }
166
+ switch (value['kind']) {
167
+ case 'named-range':
168
+ return hasString(value, 'name');
169
+ case 'cell-ref':
170
+ return hasString(value, 'sheetName') && hasString(value, 'address');
171
+ case 'range-ref':
172
+ return isCellRangeRef(value);
173
+ case 'structured-ref':
174
+ return hasString(value, 'tableName') && hasString(value, 'columnName');
175
+ default:
176
+ return false;
177
+ }
178
+ }
179
+ function isWorkbookDataValidationRule(value) {
180
+ if (!isRecord(value) || typeof value['kind'] !== 'string') {
181
+ return false;
182
+ }
183
+ switch (value['kind']) {
184
+ case 'list': {
185
+ const hasValues = Array.isArray(value['values']) && value['values'].every((entry) => isLiteralInput(entry));
186
+ const hasSource = value['source'] !== undefined && isWorkbookValidationListSource(value['source']);
187
+ return (hasValues ? 1 : 0) + (hasSource ? 1 : 0) === 1;
188
+ }
189
+ case 'checkbox':
190
+ return isOptionalLiteralInput(value['checkedValue']) && isOptionalLiteralInput(value['uncheckedValue']);
191
+ case 'any':
192
+ return true;
193
+ case 'whole':
194
+ case 'decimal':
195
+ case 'date':
196
+ case 'time':
197
+ case 'textLength':
198
+ return (typeof value['operator'] === 'string' &&
199
+ VALIDATION_COMPARISON_OPERATOR_VALUES.has(value['operator']) &&
200
+ Array.isArray(value['values']) &&
201
+ value['values'].every((entry) => isLiteralInput(entry)) &&
202
+ (value['operator'] === 'between' || value['operator'] === 'notBetween'
203
+ ? value['values'].length === 2
204
+ : value['values'].length === 1));
205
+ default:
206
+ return false;
207
+ }
208
+ }
209
+ function isWorkbookDataValidation(value) {
210
+ return (isRecord(value) &&
211
+ isCellRangeRef(value['range']) &&
212
+ isWorkbookDataValidationRule(value['rule']) &&
213
+ isOptionalBoolean(value['allowBlank']) &&
214
+ isOptionalBoolean(value['showDropdown']) &&
215
+ isOptionalString(value['promptTitle']) &&
216
+ isOptionalString(value['promptMessage']) &&
217
+ (value['errorStyle'] === undefined ||
218
+ (typeof value['errorStyle'] === 'string' && VALIDATION_ERROR_STYLE_VALUES.has(value['errorStyle']))) &&
219
+ isOptionalString(value['errorTitle']) &&
220
+ isOptionalString(value['errorMessage']));
221
+ }
222
+ function isCellStylePatch(value) {
223
+ if (!isRecord(value)) {
224
+ return false;
225
+ }
226
+ const fill = value['fill'];
227
+ if (fill !== undefined &&
228
+ fill !== null &&
229
+ (!isRecord(fill) || !(fill['backgroundColor'] === undefined || fill['backgroundColor'] === null || hasString(fill, 'backgroundColor')))) {
230
+ return false;
231
+ }
232
+ const font = value['font'];
233
+ if (font !== undefined &&
234
+ font !== null &&
235
+ (!isRecord(font) ||
236
+ !(font['family'] === undefined || font['family'] === null || hasString(font, 'family')) ||
237
+ !isOptionalNullableNumber(font['size']) ||
238
+ !isOptionalNullableBoolean(font['bold']) ||
239
+ !isOptionalNullableBoolean(font['italic']) ||
240
+ !isOptionalNullableBoolean(font['underline']) ||
241
+ !(font['color'] === undefined || font['color'] === null || hasString(font, 'color')))) {
242
+ return false;
243
+ }
244
+ const alignment = value['alignment'];
245
+ if (alignment !== undefined &&
246
+ alignment !== null &&
247
+ (!isRecord(alignment) ||
248
+ !(alignment['horizontal'] === undefined ||
249
+ alignment['horizontal'] === null ||
250
+ (typeof alignment['horizontal'] === 'string' && HORIZONTAL_ALIGNMENT_VALUES.has(alignment['horizontal']))) ||
251
+ !(alignment['vertical'] === undefined ||
252
+ alignment['vertical'] === null ||
253
+ (typeof alignment['vertical'] === 'string' && VERTICAL_ALIGNMENT_VALUES.has(alignment['vertical']))) ||
254
+ !isOptionalNullableBoolean(alignment['wrap']) ||
255
+ !isOptionalNullableNumber(alignment['indent']) ||
256
+ !isOptionalNullableBoolean(alignment['shrinkToFit']) ||
257
+ !isOptionalNullableNumber(alignment['readingOrder']) ||
258
+ !isOptionalNullableNumber(alignment['textRotation']) ||
259
+ !isOptionalNullableBoolean(alignment['justifyLastLine']))) {
260
+ return false;
261
+ }
262
+ const borders = value['borders'];
263
+ if (borders !== undefined && borders !== null) {
264
+ if (!isRecord(borders)) {
265
+ return false;
266
+ }
267
+ for (const side of ['top', 'right', 'bottom', 'left']) {
268
+ const sideValue = borders[side];
269
+ if (sideValue === undefined || sideValue === null) {
270
+ continue;
271
+ }
272
+ if (!isRecord(sideValue) ||
273
+ !(sideValue['style'] === undefined ||
274
+ sideValue['style'] === null ||
275
+ (typeof sideValue['style'] === 'string' && BORDER_STYLE_VALUES.has(sideValue['style']))) ||
276
+ !(sideValue['weight'] === undefined ||
277
+ sideValue['weight'] === null ||
278
+ (typeof sideValue['weight'] === 'string' && BORDER_WEIGHT_VALUES.has(sideValue['weight']))) ||
279
+ !(sideValue['color'] === undefined || sideValue['color'] === null || hasString(sideValue, 'color'))) {
280
+ return false;
281
+ }
282
+ }
283
+ }
284
+ return true;
285
+ }
286
+ function isWorkbookConditionalFormatRule(value) {
287
+ if (!isRecord(value) || typeof value['kind'] !== 'string') {
288
+ return false;
289
+ }
290
+ switch (value['kind']) {
291
+ case 'cellIs':
292
+ return (typeof value['operator'] === 'string' &&
293
+ VALIDATION_COMPARISON_OPERATOR_VALUES.has(value['operator']) &&
294
+ Array.isArray(value['values']) &&
295
+ value['values'].every((entry) => isLiteralInput(entry)) &&
296
+ (value['operator'] === 'between' || value['operator'] === 'notBetween'
297
+ ? value['values'].length === 2
298
+ : value['values'].length === 1));
299
+ case 'textContains':
300
+ return hasString(value, 'text') && isOptionalBoolean(value['caseSensitive']);
301
+ case 'formula':
302
+ return hasString(value, 'formula');
303
+ case 'blanks':
304
+ case 'notBlanks':
305
+ return true;
306
+ default:
307
+ return false;
308
+ }
309
+ }
310
+ function isWorkbookConditionalFormat(value) {
311
+ return (isRecord(value) &&
312
+ hasString(value, 'id') &&
313
+ isCellRangeRef(value['range']) &&
314
+ isWorkbookConditionalFormatRule(value['rule']) &&
315
+ isCellStylePatch(value['style']) &&
316
+ isOptionalBoolean(value['stopIfTrue']) &&
317
+ isOptionalSafeNonNegativeInteger(value['priority']));
318
+ }
319
+ function isWorkbookSheetProtection(value) {
320
+ return isRecord(value) && hasString(value, 'sheetName') && isOptionalBoolean(value['hideFormulas']);
321
+ }
322
+ function isWorkbookRangeProtection(value) {
323
+ return isRecord(value) && hasString(value, 'id') && isCellRangeRef(value['range']) && isOptionalBoolean(value['hideFormulas']);
324
+ }
325
+ function isWorkbookCommentEntry(value) {
326
+ return (isRecord(value) &&
327
+ hasString(value, 'id') &&
328
+ hasString(value, 'body') &&
329
+ isOptionalString(value['authorUserId']) &&
330
+ isOptionalString(value['authorDisplayName']) &&
331
+ isOptionalSafeNonNegativeInteger(value['createdAtUnixMs']));
332
+ }
333
+ function isWorkbookCommentThread(value) {
334
+ return (isRecord(value) &&
335
+ hasString(value, 'threadId') &&
336
+ hasString(value, 'sheetName') &&
337
+ hasString(value, 'address') &&
338
+ Array.isArray(value['comments']) &&
339
+ value['comments'].length > 0 &&
340
+ value['comments'].every((entry) => isWorkbookCommentEntry(entry)) &&
341
+ isOptionalBoolean(value['resolved']) &&
342
+ isOptionalString(value['resolvedByUserId']) &&
343
+ isOptionalSafeNonNegativeInteger(value['resolvedAtUnixMs']));
344
+ }
345
+ function isWorkbookNote(value) {
346
+ return isRecord(value) && hasString(value, 'sheetName') && hasString(value, 'address') && hasString(value, 'text');
347
+ }
348
+ function isWorkbookDefinedNameValue(value) {
349
+ if (isLiteralInput(value)) {
350
+ return true;
351
+ }
352
+ if (!isRecord(value) || typeof value['kind'] !== 'string') {
353
+ return false;
354
+ }
355
+ switch (value['kind']) {
356
+ case 'scalar':
357
+ return isLiteralInput(value['value']);
358
+ case 'cell-ref':
359
+ return hasString(value, 'sheetName') && hasString(value, 'address');
360
+ case 'range-ref':
361
+ return isCellRangeRef(value);
362
+ case 'structured-ref':
363
+ return hasString(value, 'tableName') && hasString(value, 'columnName');
364
+ case 'formula':
365
+ return hasString(value, 'formula');
366
+ default:
367
+ return false;
368
+ }
369
+ }
370
+ function isWorkbookTableOp(value) {
371
+ return (isRecord(value) &&
372
+ hasString(value, 'name') &&
373
+ hasString(value, 'sheetName') &&
374
+ hasString(value, 'startAddress') &&
375
+ hasString(value, 'endAddress') &&
376
+ isStringArray(value['columnNames']) &&
377
+ typeof value['headerRow'] === 'boolean' &&
378
+ typeof value['totalsRow'] === 'boolean' &&
379
+ (value['columns'] === undefined || isWorkbookTableColumns(value['columns'])) &&
380
+ (value['style'] === undefined || isWorkbookTableStyle(value['style'])) &&
381
+ isOptionalString(value['sortState']));
382
+ }
383
+ function isWorkbookTableColumns(value) {
384
+ return (Array.isArray(value) &&
385
+ value.every((entry) => isRecord(entry) &&
386
+ hasString(entry, 'name') &&
387
+ isOptionalString(entry['totalsRowLabel']) &&
388
+ isOptionalString(entry['totalsRowFunction'])));
389
+ }
390
+ function isWorkbookTableStyle(value) {
391
+ return (isRecord(value) &&
392
+ isOptionalString(value['name']) &&
393
+ isOptionalBoolean(value['showFirstColumn']) &&
394
+ isOptionalBoolean(value['showLastColumn']) &&
395
+ isOptionalBoolean(value['showRowStripes']) &&
396
+ isOptionalBoolean(value['showColumnStripes']));
397
+ }
398
+ function isWorkbookPivotValue(value) {
399
+ return (isRecord(value) &&
400
+ hasString(value, 'sourceColumn') &&
401
+ typeof value['summarizeBy'] === 'string' &&
402
+ PIVOT_AGGREGATION_VALUES.has(value['summarizeBy']) &&
403
+ isOptionalString(value['outputLabel']));
404
+ }
405
+ function isOptionalLiteralInputArray(value) {
406
+ return value === undefined || (Array.isArray(value) && value.every((entry) => isLiteralInput(entry)));
407
+ }
408
+ function isWorkbookPivotFilter(value) {
409
+ return (isRecord(value) &&
410
+ hasString(value, 'sourceColumn') &&
411
+ isOptionalLiteralInputArray(value['includedValues']) &&
412
+ isOptionalLiteralInputArray(value['hiddenValues']));
413
+ }
414
+ function isWorkbookPivotPageField(value) {
415
+ return isRecord(value) && hasString(value, 'sourceColumn') && isOptionalLiteralInput(value['selectedValue']);
416
+ }
417
+ function isWorkbookPivotHiddenItems(value) {
418
+ return isRecord(value) && hasString(value, 'sourceColumn') && Array.isArray(value['values']) && value['values'].every(isLiteralInput);
419
+ }
420
+ function isWorkbookPivotCalculatedFormula(value) {
421
+ return (isRecord(value) &&
422
+ hasString(value, 'name') &&
423
+ hasString(value, 'formula') &&
424
+ (value['clause'] === '18.10' || value['clause'] === '3.2.3.1'));
425
+ }
426
+ function isOptionalStringArray(value) {
427
+ return value === undefined || isStringArray(value);
428
+ }
429
+ function isOptionalPivotFilterArray(value) {
430
+ return value === undefined || (Array.isArray(value) && value.every(isWorkbookPivotFilter));
431
+ }
432
+ function isOptionalPivotPageFieldArray(value) {
433
+ return value === undefined || (Array.isArray(value) && value.every(isWorkbookPivotPageField));
434
+ }
435
+ function isOptionalPivotHiddenItemsArray(value) {
436
+ return value === undefined || (Array.isArray(value) && value.every(isWorkbookPivotHiddenItems));
437
+ }
438
+ function isOptionalPivotCalculatedFormulaArray(value) {
439
+ return value === undefined || (Array.isArray(value) && value.every(isWorkbookPivotCalculatedFormula));
440
+ }
441
+ function isOptionalCachedRecords(value) {
442
+ return value === undefined || (Array.isArray(value) && value.every((row) => Array.isArray(row) && row.every(isLiteralInput)));
443
+ }
444
+ const CHART_TYPE_VALUES = new Set(['column', 'bar', 'line', 'area', 'pie', 'scatter']);
445
+ const CHART_SERIES_ORIENTATION_VALUES = new Set(['rows', 'columns']);
446
+ const CHART_LEGEND_POSITION_VALUES = new Set(['top', 'right', 'bottom', 'left', 'hidden']);
447
+ const SHAPE_TYPE_VALUES = new Set(['rectangle', 'roundedRectangle', 'ellipse', 'line', 'arrow', 'textBox']);
448
+ function isWorkbookChart(value) {
449
+ return (isRecord(value) &&
450
+ hasString(value, 'id') &&
451
+ hasString(value, 'sheetName') &&
452
+ hasString(value, 'address') &&
453
+ isCellRangeRef(value['source']) &&
454
+ typeof value['chartType'] === 'string' &&
455
+ CHART_TYPE_VALUES.has(value['chartType']) &&
456
+ (value['seriesOrientation'] === undefined ||
457
+ (typeof value['seriesOrientation'] === 'string' && CHART_SERIES_ORIENTATION_VALUES.has(value['seriesOrientation']))) &&
458
+ isOptionalBoolean(value['firstRowAsHeaders']) &&
459
+ isOptionalBoolean(value['firstColumnAsLabels']) &&
460
+ isOptionalString(value['title']) &&
461
+ (value['legendPosition'] === undefined ||
462
+ (typeof value['legendPosition'] === 'string' && CHART_LEGEND_POSITION_VALUES.has(value['legendPosition']))) &&
463
+ hasSafePositiveInteger(value, 'rows') &&
464
+ hasSafePositiveInteger(value, 'cols'));
465
+ }
466
+ function isWorkbookImage(value) {
467
+ return (isRecord(value) &&
468
+ hasString(value, 'id') &&
469
+ hasString(value, 'sheetName') &&
470
+ hasString(value, 'address') &&
471
+ hasString(value, 'sourceUrl') &&
472
+ hasSafePositiveInteger(value, 'rows') &&
473
+ hasSafePositiveInteger(value, 'cols') &&
474
+ isOptionalString(value['altText']));
475
+ }
476
+ function isWorkbookShape(value) {
477
+ return (isRecord(value) &&
478
+ hasString(value, 'id') &&
479
+ hasString(value, 'sheetName') &&
480
+ hasString(value, 'address') &&
481
+ typeof value['shapeType'] === 'string' &&
482
+ SHAPE_TYPE_VALUES.has(value['shapeType']) &&
483
+ hasSafePositiveInteger(value, 'rows') &&
484
+ hasSafePositiveInteger(value, 'cols') &&
485
+ isOptionalString(value['text']) &&
486
+ isOptionalString(value['fillColor']) &&
487
+ isOptionalString(value['strokeColor']));
488
+ }
489
+ export function isWorkbookOp(value) {
490
+ if (!isRecord(value) || typeof value['kind'] !== 'string') {
491
+ return false;
492
+ }
493
+ switch (value['kind']) {
494
+ case 'upsertWorkbook':
495
+ return hasString(value, 'name');
496
+ case 'setWorkbookMetadata':
497
+ return hasString(value, 'key') && isLiteralInput(value['value']);
498
+ case 'setCalculationSettings':
499
+ return isWorkbookCalculationSettings(value['settings']);
500
+ case 'setVolatileContext':
501
+ return isWorkbookVolatileContext(value['context']);
502
+ case 'upsertSheet':
503
+ return hasString(value, 'name') && hasSafeNonNegativeInteger(value, 'order') && isOptionalSafePositiveInteger(value['id']);
504
+ case 'renameSheet':
505
+ return hasString(value, 'oldName') && hasString(value, 'newName');
506
+ case 'deleteSheet':
507
+ return hasString(value, 'name');
508
+ case 'insertRows':
509
+ case 'insertColumns':
510
+ return (hasString(value, 'sheetName') &&
511
+ hasSafeNonNegativeInteger(value, 'start') &&
512
+ hasSafePositiveInteger(value, 'count') &&
513
+ (value['entries'] === undefined ||
514
+ (Array.isArray(value['entries']) && value['entries'].every((entry) => isWorkbookAxisEntry(entry)))));
515
+ case 'deleteRows':
516
+ case 'deleteColumns':
517
+ return hasString(value, 'sheetName') && hasSafeNonNegativeInteger(value, 'start') && hasSafePositiveInteger(value, 'count');
518
+ case 'moveRows':
519
+ case 'moveColumns':
520
+ return (hasString(value, 'sheetName') &&
521
+ hasSafeNonNegativeInteger(value, 'start') &&
522
+ hasSafePositiveInteger(value, 'count') &&
523
+ hasSafeNonNegativeInteger(value, 'target'));
524
+ case 'updateRowMetadata':
525
+ case 'updateColumnMetadata':
526
+ return (hasString(value, 'sheetName') &&
527
+ hasSafeNonNegativeInteger(value, 'start') &&
528
+ hasSafePositiveInteger(value, 'count') &&
529
+ isOptionalNullableSafePositiveInteger(value['size']) &&
530
+ isOptionalNullableBoolean(value['hidden']));
531
+ case 'setFreezePane':
532
+ return hasString(value, 'sheetName') && hasSafeNonNegativeInteger(value, 'rows') && hasSafeNonNegativeInteger(value, 'cols');
533
+ case 'clearFreezePane':
534
+ return hasString(value, 'sheetName');
535
+ case 'mergeCells':
536
+ case 'unmergeCells':
537
+ return isCellRangeRef(value['range']);
538
+ case 'setSheetProtection':
539
+ return isWorkbookSheetProtection(value['protection']);
540
+ case 'clearSheetProtection':
541
+ return hasString(value, 'sheetName');
542
+ case 'setFilter':
543
+ case 'clearFilter':
544
+ case 'clearSort':
545
+ return hasString(value, 'sheetName') && isCellRangeRef(value['range']);
546
+ case 'setSort':
547
+ return (hasString(value, 'sheetName') &&
548
+ isCellRangeRef(value['range']) &&
549
+ Array.isArray(value['keys']) &&
550
+ value['keys'].every((entry) => isWorkbookSortKey(entry)));
551
+ case 'setDataValidation':
552
+ return isWorkbookDataValidation(value['validation']);
553
+ case 'clearDataValidation':
554
+ return hasString(value, 'sheetName') && isCellRangeRef(value['range']);
555
+ case 'upsertConditionalFormat':
556
+ return isWorkbookConditionalFormat(value['format']);
557
+ case 'deleteConditionalFormat':
558
+ return hasString(value, 'id') && hasString(value, 'sheetName');
559
+ case 'upsertRangeProtection':
560
+ return isWorkbookRangeProtection(value['protection']);
561
+ case 'deleteRangeProtection':
562
+ return hasString(value, 'id') && hasString(value, 'sheetName');
563
+ case 'upsertCommentThread':
564
+ return isWorkbookCommentThread(value['thread']);
565
+ case 'deleteCommentThread':
566
+ case 'deleteNote':
567
+ return hasString(value, 'sheetName') && hasString(value, 'address');
568
+ case 'upsertNote':
569
+ return isWorkbookNote(value['note']);
570
+ case 'setCellValue':
571
+ return (hasString(value, 'sheetName') &&
572
+ hasString(value, 'address') &&
573
+ isLiteralInput(value['value']) &&
574
+ (value['authoredBlank'] === undefined || typeof value['authoredBlank'] === 'boolean'));
575
+ case 'setCellFormula':
576
+ return hasString(value, 'sheetName') && hasString(value, 'address') && hasString(value, 'formula');
577
+ case 'setCellFormat':
578
+ return (hasString(value, 'sheetName') && hasString(value, 'address') && (value['format'] === null || typeof value['format'] === 'string'));
579
+ case 'upsertCellStyle':
580
+ return isCellStyleRecord(value['style']);
581
+ case 'upsertCellNumberFormat':
582
+ return isCellNumberFormatRecord(value['format']);
583
+ case 'setStyleRange':
584
+ return isCellRangeRef(value['range']) && hasString(value, 'styleId');
585
+ case 'setFormatRange':
586
+ return isCellRangeRef(value['range']) && hasString(value, 'formatId');
587
+ case 'clearCell':
588
+ return hasString(value, 'sheetName') && hasString(value, 'address');
589
+ case 'upsertDefinedName':
590
+ return hasString(value, 'name') && isWorkbookDefinedNameValue(value['value']);
591
+ case 'deleteDefinedName':
592
+ case 'deleteTable':
593
+ return hasString(value, 'name');
594
+ case 'upsertTable':
595
+ return isWorkbookTableOp(value['table']);
596
+ case 'upsertSpillRange':
597
+ return (hasString(value, 'sheetName') &&
598
+ hasString(value, 'address') &&
599
+ hasSafePositiveInteger(value, 'rows') &&
600
+ hasSafePositiveInteger(value, 'cols'));
601
+ case 'deleteSpillRange':
602
+ case 'deletePivotTable':
603
+ return hasString(value, 'sheetName') && hasString(value, 'address');
604
+ case 'upsertPivotTable':
605
+ return (hasString(value, 'name') &&
606
+ hasString(value, 'sheetName') &&
607
+ hasString(value, 'address') &&
608
+ isCellRangeRef(value['source']) &&
609
+ isStringArray(value['groupBy']) &&
610
+ isOptionalStringArray(value['columnFields']) &&
611
+ isOptionalPivotPageFieldArray(value['pageFields']) &&
612
+ isOptionalPivotFilterArray(value['filters']) &&
613
+ isOptionalPivotHiddenItemsArray(value['hiddenItems']) &&
614
+ isOptionalPivotCalculatedFormulaArray(value['calculatedFields']) &&
615
+ isOptionalPivotCalculatedFormulaArray(value['calculatedItems']) &&
616
+ (value['sourceKind'] === undefined ||
617
+ value['sourceKind'] === 'worksheet' ||
618
+ value['sourceKind'] === 'table' ||
619
+ value['sourceKind'] === 'named-range' ||
620
+ value['sourceKind'] === 'external-cache-only') &&
621
+ (value['cacheOnly'] === undefined || typeof value['cacheOnly'] === 'boolean') &&
622
+ (value['cacheId'] === undefined || isSafeNonNegativeInteger(value['cacheId'])) &&
623
+ isOptionalStringArray(value['cacheFields']) &&
624
+ isOptionalCachedRecords(value['cachedRecords']) &&
625
+ Array.isArray(value['values']) &&
626
+ value['values'].every((entry) => isWorkbookPivotValue(entry)) &&
627
+ hasSafePositiveInteger(value, 'rows') &&
628
+ hasSafePositiveInteger(value, 'cols'));
629
+ case 'upsertChart':
630
+ return isWorkbookChart(value['chart']);
631
+ case 'deleteChart':
632
+ return hasString(value, 'id');
633
+ case 'upsertImage':
634
+ return isWorkbookImage(value['image']);
635
+ case 'deleteImage':
636
+ return hasString(value, 'id');
637
+ case 'upsertShape':
638
+ return isWorkbookShape(value['shape']);
639
+ case 'deleteShape':
640
+ return hasString(value, 'id');
641
+ default:
642
+ return false;
643
+ }
644
+ }
645
+ export function isEngineOp(value) {
646
+ return isWorkbookOp(value);
647
+ }
648
+ export function isEngineOps(value) {
649
+ return Array.isArray(value) && value.every((entry) => isEngineOp(entry));
650
+ }
651
+ export function isEngineOpBatch(value) {
652
+ return (isRecord(value) &&
653
+ hasString(value, 'id') &&
654
+ hasString(value, 'replicaId') &&
655
+ isRecord(value['clock']) &&
656
+ hasSafeNonNegativeInteger(value['clock'], 'counter') &&
657
+ isEngineOps(value['ops']));
658
+ }
659
+ //# sourceMappingURL=guards.js.map