@sheetxl/primitives 0.8.0-beta.11 → 0.8.0-beta.12

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license @sheetxl/primitives - Primitives - Base types for SheetXL functions. - v0.8.0-beta.11
2
+ * @license @sheetxl/primitives - Primitives - Base types for SheetXL functions. - v0.8.0-beta.12
3
3
  *
4
4
  * (C) 2026-present SheetXL Inc. & Michael T. Ford
5
5
  * License: The license can be found at https://www.sheetxl.com/license.
@@ -370,34 +370,34 @@ var v = class {
370
370
  }
371
371
  }, y = class {
372
372
  createRange(e, t, n) {
373
- throw new S();
373
+ throw new C();
374
374
  }
375
375
  flattenAreas(e) {
376
- throw new S();
376
+ throw new C();
377
377
  }
378
378
  getReference(e, t) {
379
- throw new S();
379
+ throw new C();
380
380
  }
381
381
  getResizedReference(e, t, n) {
382
- throw new S();
382
+ throw new C();
383
383
  }
384
384
  getNumberFormat(e, t) {
385
- throw new S();
385
+ throw new C();
386
386
  }
387
387
  fromSerialDate(e, t) {
388
- throw new S();
388
+ throw new C();
389
389
  }
390
390
  toSerialDate(e, t) {
391
- throw new S();
391
+ throw new C();
392
392
  }
393
393
  getDateParts(e, t) {
394
- throw new S();
394
+ throw new C();
395
395
  }
396
396
  getSerialDate(e, t, n, r, i, a, o) {
397
- throw new S();
397
+ throw new C();
398
398
  }
399
399
  getNow() {
400
- throw new S();
400
+ throw new C();
401
401
  }
402
402
  getRandom() {
403
403
  return Math.random();
@@ -406,10 +406,10 @@ var v = class {
406
406
  return null;
407
407
  }
408
408
  getEntireCoords() {
409
- return C;
409
+ return w;
410
410
  }
411
411
  isValidDate(e, t) {
412
- return e instanceof Date || Object.prototype.toString.call(e) === "[object Date]" ? !isNaN(e.getTime()) : !t && typeof e == "number" && !(e < 0 || e > T);
412
+ return e instanceof Date || Object.prototype.toString.call(e) === "[object Date]" ? !isNaN(e.getTime()) : !t && typeof e == "number" && !(e < 0 || e > E);
413
413
  }
414
414
  getRow() {
415
415
  return 0;
@@ -433,6 +433,7 @@ var v = class {
433
433
  return 1;
434
434
  }
435
435
  markVolatile() {}
436
+ defer(e, t) {}
436
437
  formatResults(e) {}
437
438
  filterHidden(e, t) {
438
439
  return e;
@@ -444,22 +445,22 @@ var v = class {
444
445
  return null;
445
446
  }
446
447
  getAddress(e, t) {
447
- throw new S();
448
+ throw new C();
448
449
  }
449
450
  parseAsSerialDate(e, t) {
450
- throw new S();
451
+ throw new C();
451
452
  }
452
453
  parseAsDate(e, t) {
453
- throw new S();
454
+ throw new C();
454
455
  }
455
456
  parseAsNumber(e, t) {
456
- throw new S();
457
+ throw new C();
457
458
  }
458
459
  createCriteria(e, t) {
459
- throw new S();
460
+ throw new C();
460
461
  }
461
462
  createGrouping(e, t) {
462
- throw new S();
463
+ throw new C();
463
464
  }
464
465
  parseAsLiteral(e) {
465
466
  let t = e.toUpperCase();
@@ -474,10 +475,13 @@ var v = class {
474
475
  return r === i ? e < t ? -1 : +(e > t) : r < i ? -1 : 1;
475
476
  }
476
477
  getRuntime() {
477
- return w;
478
+ return T;
478
479
  }
479
480
  getArgs() {
480
- throw new S(x);
481
+ throw new C(x);
482
+ }
483
+ createRichData(e, t) {
484
+ throw new C(S);
481
485
  }
482
486
  }, b = (e) => {
483
487
  if (e == null) return 0;
@@ -487,19 +491,19 @@ var v = class {
487
491
  case "boolean": return 3;
488
492
  default: return 4;
489
493
  }
490
- }, x = "FormulaContext.getArgs() is only valid while a function body is running", S = class extends Error {
494
+ }, x = "FormulaContext.getArgs() is only valid while a function body is running", S = "FormulaContext.createRichData() needs a workbook being calculated", C = class extends Error {
491
495
  constructor(e = "Not implemented in StubbedFormulaContext") {
492
496
  super(e), this.name = "NotImplementedError";
493
497
  }
494
- }, C = Object.freeze({
498
+ }, w = Object.freeze({
495
499
  colStart: 0,
496
500
  rowStart: 0,
497
501
  colEnd: 2 ** 14 - 1,
498
502
  rowEnd: 2 ** 20 - 1
499
- }), w = {
503
+ }), T = {
500
504
  isDate1904: () => !1,
501
- getLocale: () => O.tag,
502
- getLocaleProfile: () => O,
505
+ getLocale: () => k.tag,
506
+ getLocaleProfile: () => k,
503
507
  isR1C1: () => !1,
504
508
  getNow: () => 0,
505
509
  getRandom: () => Math.random(),
@@ -508,12 +512,12 @@ var v = class {
508
512
  getOS: () => "unknown",
509
513
  getUser: () => "unidentified",
510
514
  getDescription: () => "Stubbed Formula Context"
511
- }, T = 2958465, E = new y(), D = class {
515
+ }, E = 2958465, D = new y(), O = class {
512
516
  constructor() {
513
- this._scope = E, this._argsFn = null;
517
+ this._scope = D, this._argsFn = null;
514
518
  }
515
519
  _setScope(e) {
516
- this._scope = e ?? E;
520
+ this._scope = e ?? D;
517
521
  }
518
522
  _getScope() {
519
523
  return this._scope;
@@ -525,7 +529,7 @@ var v = class {
525
529
  return this._getScope().getNumberFormat(e, t);
526
530
  }
527
531
  getEntireCoords() {
528
- return this._getScope().getEntireCoords() ?? C;
532
+ return this._getScope().getEntireCoords() ?? w;
529
533
  }
530
534
  parseAsSerialDate(e, t) {
531
535
  return this._getScope().parseAsSerialDate(e, t);
@@ -544,7 +548,7 @@ var v = class {
544
548
  }
545
549
  parseAsLiteral(e) {
546
550
  let t = this._getScope();
547
- return t.parseAsLiteral ? t.parseAsLiteral(e) : E.parseAsLiteral(e);
551
+ return t.parseAsLiteral ? t.parseAsLiteral(e) : D.parseAsLiteral(e);
548
552
  }
549
553
  toText(e) {
550
554
  return this._getScope().toText(e);
@@ -615,6 +619,9 @@ var v = class {
615
619
  markVolatile() {
616
620
  this._getScope().markVolatile?.();
617
621
  }
622
+ defer(e, t) {
623
+ return this._getScope().defer?.(e, t);
624
+ }
618
625
  formatResults(e) {
619
626
  this._getScope().formatResults?.(e);
620
627
  }
@@ -631,14 +638,18 @@ var v = class {
631
638
  return this._getScope().getAddress(e, t);
632
639
  }
633
640
  compare(e, t, n) {
634
- return this._getScope().compare?.(e, t, n) ?? E.compare(e, t, n);
641
+ return this._getScope().compare?.(e, t, n) ?? D.compare(e, t, n);
635
642
  }
636
643
  getRuntime() {
637
644
  return this._getScope().getRuntime();
638
645
  }
646
+ createRichData(e, t) {
647
+ let n = this._getScope();
648
+ return n.createRichData ? n.createRichData(e, t) : D.createRichData(e, t);
649
+ }
639
650
  getArgs() {
640
651
  let e = this._argsFn, t = e ? e() : null;
641
- if (!t) throw new S(x);
652
+ if (!t) throw new C(x);
642
653
  return t;
643
654
  }
644
655
  get [Symbol.toStringTag]() {
@@ -647,7 +658,7 @@ var v = class {
647
658
  toString() {
648
659
  return this._getScope()?.toString?.() ?? "{STUB SCOPE}";
649
660
  }
650
- }, O = Object.freeze({
661
+ }, k = Object.freeze({
651
662
  tag: "en-US",
652
663
  numberingSystem: "latn",
653
664
  decimal: ".",
@@ -727,5 +738,5 @@ var v = class {
727
738
  sensitivity: "base",
728
739
  numeric: !0
729
740
  })
730
- }), k = new D();
731
- export { O as DEFAULT_LOCALE_PROFILE, k as FormulaContext, i as FormulaError, t as IRange, r as IRangeStats, o as InteropScalarType, v as Observable, e as Scalar, a as ScalarType, D as ScopedFormulaContext, y as StubbedFormulaContext, s as ValueKind, u as WildCard, d as isLazyValue };
741
+ }), A = new O();
742
+ export { k as DEFAULT_LOCALE_PROFILE, A as FormulaContext, i as FormulaError, t as IRange, r as IRangeStats, o as InteropScalarType, v as Observable, e as Scalar, a as ScalarType, O as ScopedFormulaContext, y as StubbedFormulaContext, s as ValueKind, u as WildCard, d as isLazyValue };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license @sheetxl/primitives - Primitives - Base types for SheetXL functions. - v0.8.0-beta.11
2
+ * @license @sheetxl/primitives - Primitives - Base types for SheetXL functions. - v0.8.0-beta.12
3
3
  *
4
4
  * (C) 2026-present SheetXL Inc. & Michael T. Ford
5
5
  * License: The license can be found at https://www.sheetxl.com/license.
@@ -225,7 +225,7 @@ var t, r, o, n, s = {
225
225
  }
226
226
  }
227
227
  e.NA = g;
228
- class p extends o {
228
+ class h extends o {
229
229
  constructor(e, o) {
230
230
  super(t.GettingData, r.GettingData, e, o);
231
231
  }
@@ -233,8 +233,8 @@ var t, r, o, n, s = {
233
233
  this.code = n.Code.GettingData;
234
234
  }
235
235
  }
236
- e.GettingData = p;
237
- class h extends o {
236
+ e.GettingData = h;
237
+ class p extends o {
238
238
  constructor(e, o) {
239
239
  super(t.Spill, r.Spill, e, o);
240
240
  }
@@ -242,7 +242,7 @@ var t, r, o, n, s = {
242
242
  this.code = n.Code.Spill;
243
243
  }
244
244
  }
245
- e.Spill = h;
245
+ e.Spill = p;
246
246
  class m extends o {
247
247
  constructor(e, o) {
248
248
  super(t.Connect, r.Connect, e, o);
@@ -318,13 +318,13 @@ var t, r, o, n, s = {
318
318
  }(n || (n = {}));
319
319
  var g = {};
320
320
  g[n.Code.Parse] = n.Parse, g[n.Code.Null] = n.Null, g[n.Code.Div0] = n.Div0, g[n.Code.Value] = n.Value, g[n.Code.Ref] = n.Ref, g[n.Code.Name] = n.Name, g[n.Code.Num] = n.Num, g[n.Code.NA] = n.NA, g[n.Code.GettingData] = n.GettingData, g[n.Code.Spill] = n.Spill, g[n.Code.Connect] = n.Connect, g[n.Code.Blocked] = n.Blocked, g[n.Code.Unknown] = n.Unknown, g[n.Code.Field] = n.Field, g[n.Code.Calc] = n.Calc, g[n.Code.Busy] = n.Busy, g[n.Code.Python] = n.Python, g[n.Code.Timeout] = n.Timeout;
321
- var p = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), S = /* @__PURE__ */ new Map(), C = Object.keys(g);
321
+ var h = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), S = /* @__PURE__ */ new Map(), C = Object.keys(g);
322
322
  for (let e = 0; e < C.length; e++) {
323
323
  const t = g[C[e]], r = new t();
324
- m.set(r.getLabel(), t), S.set(r.getCode(), t), p.set(r.getLabel(), r), h.set(r.getCode(), r);
324
+ m.set(r.getLabel(), t), S.set(r.getCode(), t), h.set(r.getLabel(), r), p.set(r.getCode(), r);
325
325
  }
326
326
  (function(e) {
327
- const t = e.getBuiltInByCode = (e) => h.get(e);
327
+ const t = e.getBuiltInByCode = (e) => p.get(e);
328
328
  e.BuiltIn = {
329
329
  Parse: t(n.Code.Parse),
330
330
  Null: t(n.Code.Null),
@@ -347,7 +347,7 @@ for (let e = 0; e < C.length; e++) {
347
347
  }, e.newTypedError = (e, t, r) => {
348
348
  let o;
349
349
  return o = "string" == typeof e ? m.get(e) : S.get(e), o || (o = n.Unknown), new o(t, r);
350
- }, e.getBuiltInByLabel = (e) => p.get(e), e.isError = function(e, t) {
350
+ }, e.getBuiltInByLabel = (e) => h.get(e), e.isError = function(e, t) {
351
351
  return !!e && !0 === e.isFormulaError && (void 0 === t || e.getCode() === t);
352
352
  };
353
353
  })(n || (n = {}));
@@ -373,34 +373,34 @@ var w = class {
373
373
  }
374
374
  }, f = class {
375
375
  createRange(e, t, r) {
376
- throw new b();
376
+ throw new D();
377
377
  }
378
378
  flattenAreas(e) {
379
- throw new b();
379
+ throw new D();
380
380
  }
381
381
  getReference(e, t) {
382
- throw new b();
382
+ throw new D();
383
383
  }
384
384
  getResizedReference(e, t, r) {
385
- throw new b();
385
+ throw new D();
386
386
  }
387
387
  getNumberFormat(e, t) {
388
- throw new b();
388
+ throw new D();
389
389
  }
390
390
  fromSerialDate(e, t) {
391
- throw new b();
391
+ throw new D();
392
392
  }
393
393
  toSerialDate(e, t) {
394
- throw new b();
394
+ throw new D();
395
395
  }
396
396
  getDateParts(e, t) {
397
- throw new b();
397
+ throw new D();
398
398
  }
399
399
  getSerialDate(e, t, r, o, n, s, a) {
400
- throw new b();
400
+ throw new D();
401
401
  }
402
402
  getNow() {
403
- throw new b();
403
+ throw new D();
404
404
  }
405
405
  getRandom() {
406
406
  return Math.random();
@@ -412,7 +412,7 @@ var w = class {
412
412
  return A;
413
413
  }
414
414
  isValidDate(e, t) {
415
- return e instanceof Date || "[object Date]" === Object.prototype.toString.call(e) ? !isNaN(e.getTime()) : !t && "number" == typeof e && !(e < 0 || e > _);
415
+ return e instanceof Date || "[object Date]" === Object.prototype.toString.call(e) ? !isNaN(e.getTime()) : !t && "number" == typeof e && !(e < 0 || e > R);
416
416
  }
417
417
  getRow() {
418
418
  return 0;
@@ -436,6 +436,7 @@ var w = class {
436
436
  return 1;
437
437
  }
438
438
  markVolatile() {}
439
+ defer(e, t) {}
439
440
  formatResults(e) {}
440
441
  filterHidden(e, t) {
441
442
  return e;
@@ -447,22 +448,22 @@ var w = class {
447
448
  return null;
448
449
  }
449
450
  getAddress(e, t) {
450
- throw new b();
451
+ throw new D();
451
452
  }
452
453
  parseAsSerialDate(e, t) {
453
- throw new b();
454
+ throw new D();
454
455
  }
455
456
  parseAsDate(e, t) {
456
- throw new b();
457
+ throw new D();
457
458
  }
458
459
  parseAsNumber(e, t) {
459
- throw new b();
460
+ throw new D();
460
461
  }
461
462
  createCriteria(e, t) {
462
- throw new b();
463
+ throw new D();
463
464
  }
464
465
  createGrouping(e, t) {
465
- throw new b();
466
+ throw new D();
466
467
  }
467
468
  parseAsLiteral(e) {
468
469
  const t = e.toUpperCase();
@@ -477,10 +478,13 @@ var w = class {
477
478
  return o !== n ? o < n ? -1 : 1 : e < t ? -1 : e > t ? 1 : 0;
478
479
  }
479
480
  getRuntime() {
480
- return D;
481
+ return _;
481
482
  }
482
483
  getArgs() {
483
- throw new b(N);
484
+ throw new D(N);
485
+ }
486
+ createRichData(e, t) {
487
+ throw new D(b);
484
488
  }
485
489
  }, y = (e) => {
486
490
  if (null == e) return 0;
@@ -490,7 +494,7 @@ var w = class {
490
494
  case "boolean": return 3;
491
495
  default: return 4;
492
496
  }
493
- }, N = "FormulaContext.getArgs() is only valid while a function body is running", b = class extends Error {
497
+ }, N = "FormulaContext.getArgs() is only valid while a function body is running", b = "FormulaContext.createRichData() needs a workbook being calculated", D = class extends Error {
494
498
  constructor(e = "Not implemented in StubbedFormulaContext") {
495
499
  super(e), this.name = "NotImplementedError";
496
500
  }
@@ -499,10 +503,10 @@ var w = class {
499
503
  rowStart: 0,
500
504
  colEnd: Math.pow(2, 14) - 1,
501
505
  rowEnd: Math.pow(2, 20) - 1
502
- }), D = {
506
+ }), _ = {
503
507
  isDate1904: () => !1,
504
- getLocale: () => F.tag,
505
- getLocaleProfile: () => F,
508
+ getLocale: () => T.tag,
509
+ getLocaleProfile: () => T,
506
510
  isR1C1: () => !1,
507
511
  getNow: () => 0,
508
512
  getRandom: () => Math.random(),
@@ -511,12 +515,12 @@ var w = class {
511
515
  getOS: () => "unknown",
512
516
  getUser: () => "unidentified",
513
517
  getDescription: () => "Stubbed Formula Context"
514
- }, _ = 2958465, R = new f(), x = class {
518
+ }, R = 2958465, x = new f(), F = class {
515
519
  constructor() {
516
- this._scope = R, this._argsFn = null;
520
+ this._scope = x, this._argsFn = null;
517
521
  }
518
522
  _setScope(e) {
519
- this._scope = e ?? R;
523
+ this._scope = e ?? x;
520
524
  }
521
525
  _getScope() {
522
526
  return this._scope;
@@ -547,7 +551,7 @@ var w = class {
547
551
  }
548
552
  parseAsLiteral(e) {
549
553
  const t = this._getScope();
550
- return t.parseAsLiteral ? t.parseAsLiteral(e) : R.parseAsLiteral(e);
554
+ return t.parseAsLiteral ? t.parseAsLiteral(e) : x.parseAsLiteral(e);
551
555
  }
552
556
  toText(e) {
553
557
  return this._getScope().toText(e);
@@ -618,6 +622,9 @@ var w = class {
618
622
  markVolatile() {
619
623
  this._getScope().markVolatile?.();
620
624
  }
625
+ defer(e, t) {
626
+ return this._getScope().defer?.(e, t);
627
+ }
621
628
  formatResults(e) {
622
629
  this._getScope().formatResults?.(e);
623
630
  }
@@ -634,14 +641,18 @@ var w = class {
634
641
  return this._getScope().getAddress(e, t);
635
642
  }
636
643
  compare(e, t, r) {
637
- return this._getScope().compare?.(e, t, r) ?? R.compare(e, t, r);
644
+ return this._getScope().compare?.(e, t, r) ?? x.compare(e, t, r);
638
645
  }
639
646
  getRuntime() {
640
647
  return this._getScope().getRuntime();
641
648
  }
649
+ createRichData(e, t) {
650
+ const r = this._getScope();
651
+ return r.createRichData ? r.createRichData(e, t) : x.createRichData(e, t);
652
+ }
642
653
  getArgs() {
643
654
  const e = this._argsFn, t = e ? e() : null;
644
- if (!t) throw new b(N);
655
+ if (!t) throw new D(N);
645
656
  return t;
646
657
  }
647
658
  get [Symbol.toStringTag]() {
@@ -650,7 +661,7 @@ var w = class {
650
661
  toString() {
651
662
  return this._getScope()?.toString?.() ?? "{STUB SCOPE}";
652
663
  }
653
- }, F = Object.freeze({
664
+ }, T = Object.freeze({
654
665
  tag: "en-US",
655
666
  numberingSystem: "latn",
656
667
  decimal: ".",
@@ -730,5 +741,5 @@ var w = class {
730
741
  sensitivity: "base",
731
742
  numeric: !0
732
743
  })
733
- }), T = new x();
734
- export { F as DEFAULT_LOCALE_PROFILE, T as FormulaContext, n as FormulaError, t as IRange, o as IRangeStats, a as InteropScalarType, w as Observable, e as Scalar, s as ScalarType, x as ScopedFormulaContext, f as StubbedFormulaContext, i as ValueKind, l as WildCard, d as isLazyValue };
744
+ }), P = new F();
745
+ export { T as DEFAULT_LOCALE_PROFILE, P as FormulaContext, n as FormulaError, t as IRange, o as IRangeStats, a as InteropScalarType, w as Observable, e as Scalar, s as ScalarType, F as ScopedFormulaContext, f as StubbedFormulaContext, i as ValueKind, l as WildCard, d as isLazyValue };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sheetxl/primitives",
3
3
  "description": "Primitives - Base types for SheetXL functions.",
4
- "version": "0.8.0-beta.11",
4
+ "version": "0.8.0-beta.12",
5
5
  "license": "SEE LICENSE IN <LICENSE>",
6
6
  "type": "module",
7
7
  "exports": {
@@ -6,6 +6,7 @@ import { IFunction } from './IFunction';
6
6
  import { IFunctionArguments } from './IFunctionArguments';
7
7
  import { IFormulaContext } from './IFormulaContext';
8
8
  import { IRuntime } from './IRuntime';
9
+ import { IRichData } from './IRichData';
9
10
  import { LocaleProfile } from './LocaleProfile';
10
11
  /**
11
12
  * Default implementation of the IFormulaContext interface.
@@ -63,6 +64,8 @@ export declare class StubbedFormulaContext implements IFormulaContext {
63
64
  getSheetCount(): number | null;
64
65
  /** @inheritdoc IFormulaContext.markVolatile */
65
66
  markVolatile(): void;
67
+ /** @inheritdoc IFormulaContext.defer */
68
+ defer(_executor: IFormulaContext.DeferExecutor, _payload?: unknown): unknown;
66
69
  /** @inheritdoc IFormulaContext.formatResults */
67
70
  formatResults(numFmt: string): void;
68
71
  /** @inheritdoc IFormulaContext.filterHidden */
@@ -143,6 +146,8 @@ export declare class StubbedFormulaContext implements IFormulaContext {
143
146
  getRuntime(): IRuntime;
144
147
  /** @inheritdoc IFormulaContext.getArgs */
145
148
  getArgs(): IFunctionArguments;
149
+ /** @inheritdoc IFormulaContext.createRichData */
150
+ createRichData(_type: string, _data?: any): IRichData;
146
151
  }
147
152
  /**
148
153
  * The single, shared {@link IFormulaContext} that formula implementations use (via
@@ -231,6 +236,8 @@ export declare class ScopedFormulaContext implements IFormulaContext {
231
236
  getSheetCount(): number | null;
232
237
  /** @inheritdoc IFormulaContext.markVolatile */
233
238
  markVolatile(): void;
239
+ /** @inheritdoc IFormulaContext.defer */
240
+ defer(executor: IFormulaContext.DeferExecutor, payload?: unknown): unknown;
234
241
  /** @inheritdoc IFormulaContext.formatResults */
235
242
  formatResults(numFmt: string): void;
236
243
  /** @inheritdoc IFormulaContext.filterHidden */
@@ -245,6 +252,8 @@ export declare class ScopedFormulaContext implements IFormulaContext {
245
252
  compare(a: Scalar, b: Scalar, options?: Intl.CollatorOptions): number;
246
253
  /** @inheritdoc IFormulaContext.getRuntime */
247
254
  getRuntime(): IRuntime;
255
+ /** @inheritdoc IFormulaContext.createRichData */
256
+ createRichData(type: string, data?: any): IRichData;
248
257
  /** @inheritdoc IFormulaContext.getArgs */
249
258
  getArgs(): IFunctionArguments;
250
259
  get [Symbol.toStringTag](): string;
@@ -5,6 +5,7 @@ import { IReferenceRange } from './IReferenceRange';
5
5
  import { IFunction } from './IFunction';
6
6
  import { IFunctionArguments } from './IFunctionArguments';
7
7
  import { IRuntime } from './IRuntime';
8
+ import { IRichData } from './IRichData';
8
9
  /**
9
10
  * Everything a formula function is allowed to know about the world outside its arguments.
10
11
  *
@@ -29,6 +30,7 @@ import { IRuntime } from './IRuntime';
29
30
  * | Category | Key methods |
30
31
  * |---|---|
31
32
  * | Evaluation lifecycle | `markVolatile`, `getRow`, `getColumn`, `getEntireCoords`, `getRandom` |
33
+ * | Answering later | `defer` |
32
34
  * | Argument reflection | `getArgs` |
33
35
  * | Output hints | `formatResults` |
34
36
  * | Range construction | `createRange`, `flattenAreas`, `filterHidden` |
@@ -598,6 +600,64 @@ export interface IFormulaContext {
598
600
  * @throws If called outside a function dispatch — there are no arguments to reflect on.
599
601
  */
600
602
  getArgs(): IFunctionArguments;
603
+ /**
604
+ * Answers this call later: hands `executor` a call to settle, and leaves the cell showing what
605
+ * the function returns now.
606
+ *
607
+ * @param executor Runs once at the end of the recalculation with every call made against it.
608
+ * Pass a module-level function by name: calls join one batch when they name the same function.
609
+ * @param payload Everything the executor needs to answer this call, and how a later evaluation
610
+ * recognizes it: while the call is still waiting, a recalculation with
611
+ * an equal payload leaves it be rather than asking again. Once it has stopped, a recalculation
612
+ * calls the function again; what it fetched is answered from the workbook's cache
613
+ * (`IBatchContext.fetch`).
614
+ * @returns The last answer this call gave for the same question, when the function is being
615
+ * called again (a recalculation); `undefined` on a first call or a changed question. Return it
616
+ * to keep showing it until the new answer arrives, or return something else to show that the
617
+ * cell is waiting.
618
+ *
619
+ * @remarks
620
+ * The function still returns a value: what this call answers until its result arrives (nothing
621
+ * returned reads as blank), and it is what every formula over the cell calculates
622
+ * from meanwhile: return `#BUSY!` when they should wait as an error, or text such as
623
+ * `'Fetching…'` when that is what they should show.
624
+ *
625
+ * The executor runs after the recalculation, outside any cell; read nothing from the formula
626
+ * context there. Whatever the body knows goes in the payload.
627
+ *
628
+ * @example
629
+ * ```typescript
630
+ * function fetchAll(
631
+ * calls: readonly IFormulaContext.DeferredCall<string>[],
632
+ * ctx: IFormulaContext.IBatchContext
633
+ * ): void {
634
+ * for (const call of calls) {
635
+ * ctx.fetch(call.payload as string)
636
+ * .then((response) => response.text())
637
+ * .then((text) => call.resolve(text), (error) => call.reject(error));
638
+ * }
639
+ * }
640
+ *
641
+ * export function FETCHTEXT(url: string): string {
642
+ * FormulaContext.defer(fetchAll, url);
643
+ * return 'Fetching…';
644
+ * }
645
+ * ```
646
+ */
647
+ defer(executor: IFormulaContext.DeferExecutor, payload?: unknown): unknown;
648
+ /**
649
+ * A rich value of a registered type, made from its data as the type's JSON holds it, for the
650
+ * workbook being calculated.
651
+ *
652
+ * @param type The name of the value's kind (`'hyperlink'`): what its `getKind().getName()`
653
+ * will answer.
654
+ * @param data The value's data, as its JSON's `data`.
655
+ *
656
+ * @remarks
657
+ * A type nobody has registered still makes a value: one that carries the data and reads as
658
+ * nothing.
659
+ */
660
+ createRichData(type: string, data?: any): IRichData;
601
661
  }
602
662
  /**
603
663
  * {@inheritDoc IFormulaContext}
@@ -748,5 +808,66 @@ export declare namespace IFormulaContext {
748
808
  */
749
809
  readonly dow: number;
750
810
  }
811
+ /**
812
+ * Answers the calls made by {@link IFormulaContext.defer} against it. Invoked once at the end of
813
+ * a recalculation with every such call; how many requests that becomes is the executor's choice.
814
+ */
815
+ type DeferExecutor<T = any> = (calls: readonly DeferredCall<T>[], ctx: IBatchContext) => void | Promise<void>;
816
+ /**
817
+ * One call made by {@link IFormulaContext.defer}, as its executor receives it.
818
+ *
819
+ * @remarks
820
+ * Settle each call itself, never by its position in a response. An executor that returns a
821
+ * promise which rejects fails every call it has not settled.
822
+ */
823
+ interface DeferredCall<T = any> {
824
+ /** What the function passed to `defer`. */
825
+ readonly payload: unknown;
826
+ /** Settles the call with its result. */
827
+ resolve(value: T): void;
828
+ /** Settles the call with an error: a `FormulaError` as itself, anything else as `#VALUE!`. */
829
+ reject(error: unknown): void;
830
+ /** Runs `fn` when the result is no longer wanted. */
831
+ onCancel(fn: () => void): void;
832
+ /**
833
+ * Whether the result is no longer wanted. Only an executor that holds calls to settle later
834
+ * needs it; a result for a cancelled call is dropped.
835
+ */
836
+ readonly cancelled: boolean;
837
+ }
838
+ /**
839
+ * What an executor is given beside its calls.
840
+ */
841
+ interface IBatchContext {
842
+ /** A random number in `[0, 1)` from the calculation's source, which a test can seed. */
843
+ getRandom(): number;
844
+ /**
845
+ * State kept for this executor across recalculations, made by `init` on first ask. Keep data
846
+ * here (maps, numbers, strings, buffers), not connections or sockets.
847
+ */
848
+ getState<S>(init: () => S): S;
849
+ /**
850
+ * A rich value of a registered type, for the workbook being calculated: what
851
+ * {@link IFormulaContext.createRichData} makes inside a cell, made here for a call's result.
852
+ */
853
+ createRichData(type: string, data?: any): IRichData;
854
+ /**
855
+ * Adds bytes to the workbook being calculated as a resource (an `IResource`), for a rich value
856
+ * to hold: pass it in {@link createRichData}'s data. The workbook saves it while a value holds
857
+ * it. With `fetchedFrom` it is the workbook's copy of that URL: {@link fetch} answers the URL
858
+ * from it, and adding the same URL again answers the resource already added.
859
+ */
860
+ addResource(buffer: ArrayBuffer, options?: {
861
+ fetchedFrom?: string;
862
+ }): object;
863
+ /**
864
+ * Fetches through the workbook being calculated: the standard `fetch`, answered by the
865
+ * fetchers the host registered for the URL's scheme, with the host's authentication. An
866
+ * answer the workbook already has for the URL (a picture it keeps, or anything fetched while
867
+ * it is open) answers from the workbook, and two calls for one URL share one request. In an
868
+ * external calculation (*Refresh All*) it goes to the source.
869
+ */
870
+ fetch(input: string, init?: RequestInit): Promise<Response>;
871
+ }
751
872
  }
752
873
  //# sourceMappingURL=IFormulaContext.d.ts.map
@@ -284,11 +284,9 @@ export declare namespace IFunction {
284
284
  getMembers(): readonly IFunction.IEnumMember[];
285
285
  }
286
286
  /**
287
- * Describes the runtime return behavior of a function, including modifiers like
288
- * async resolution, streaming data, or volatility.
287
+ * Describes the runtime return behavior of a function, including modifiers like volatility.
289
288
  *
290
289
  * @remarks
291
- * All return type modifiers are mutually exclusive.
292
290
  * If none are specified, The value will be returned with no special behavior.
293
291
  */
294
292
  interface IReturnType extends IValueType {
@@ -300,19 +298,6 @@ export declare namespace IFunction {
300
298
  * @see {@link ReturnTypeJSON.kind}
301
299
  */
302
300
  getKind(): ValueKind | null;
303
- /**
304
- * Indicates the return value is a Promise or Promise-like (i.e., async).
305
- * The system will mark the result as pending and re-trigger evaluation once resolved.
306
- *
307
- * Can be combined with any scalar, array, or range return type.
308
- */
309
- isAsync(): boolean;
310
- /**
311
- * Indicates whether the function produces a continuous stream of output (e.g., real-time data).
312
- *
313
- * @defaultValue `false`
314
- */
315
- isStreaming(): boolean;
316
301
  /**
317
302
  * True when the result can change with nothing dirty, so a cell naming this function
318
303
  * recalculates on every pass — the `Volatile<T>` marker.
@@ -738,8 +723,7 @@ export declare namespace IFunction {
738
723
  members: [name: string, value: number | string, deprecated?: string | true][];
739
724
  }
740
725
  /**
741
- * Describes the runtime return behavior of a function, including modifiers like
742
- * async resolution, streaming data, or volatility.
726
+ * Describes the runtime return behavior of a function, including modifiers like volatility.
743
727
  *
744
728
  * @remarks
745
729
  * If none are specified, The value will be returned with no special behavior.
@@ -763,19 +747,6 @@ export declare namespace IFunction {
763
747
  * is a scalar is its member value downstream.
764
748
  */
765
749
  kind?: ValueKind;
766
- /**
767
- * Indicates the return value is a Promise or Promise-like (i.e., async).
768
- * The system will mark the result as pending and re-trigger evaluation once resolved.
769
- *
770
- * Can be combined with any scalar, array, or range return type.
771
- */
772
- async?: boolean;
773
- /**
774
- * Indicates whether the function produces a continuous stream of output (e.g., real-time data).
775
- *
776
- * @defaultValue `false`
777
- */
778
- stream?: boolean;
779
750
  /**
780
751
  * The result can change with nothing dirty — a cell naming this function recalculates on
781
752
  * every pass. Generated from the `Volatile<T>` marker.
@@ -784,8 +755,7 @@ export declare namespace IFunction {
784
755
  * Collected at COMPILE time from the formula text (`CompiledFormula.hasVolatile`), because
785
756
  * that is where Excel decides it: `=IF(TRUE,1,RAND())` recalculates on every idle pass though
786
757
  * no branch selects the arm, and with lazy arguments the call never happens for the engine to
787
- * observe. Sits beside {@link async} and {@link stream} because all three are about WHEN a
788
- * result arrives rather than what it is.
758
+ * observe.
789
759
  *
790
760
  * @see {@link Volatile}
791
761
  */
@@ -1,17 +1,24 @@
1
1
  import { Scalar } from './Scalar';
2
+ import { IRichMeta, IRichType } from './IRichType';
2
3
  /**
3
4
  * A complex object type. This allows for more complex data types to be stored in a cell.
4
5
  */
5
6
  export interface IRichData {
6
7
  /**
7
- * Reference to either a known typename or a JSON Type Definition.
8
- * * {@link https://jsontypedef.com/}
8
+ * The value's kind: the properties it has and how they show. Every value of a kind returns the
9
+ * same instance.
9
10
  */
10
- getType(): string;
11
+ getKind(): IRichType;
11
12
  /**
12
13
  * @param name The name of the property to retrieve.
13
14
  */
14
15
  getProperty(name: string): Scalar;
16
+ /**
17
+ * How the property `name` shows on this value: the value's own presentation where it differs
18
+ * from its kind's (a price in another currency), else the kind's ({@link IRichType.Property.meta}).
19
+ * `null`, or the method absent, for none.
20
+ */
21
+ getPropertyMeta?(name: string): IRichMeta | null;
15
22
  /**
16
23
  * The text shown for this value where nothing renders it: a client with no renderer for the
17
24
  * kind, a log, a placeholder. A rich text shows its text; an image a short description.
@@ -23,32 +30,48 @@ export interface IRichData {
23
30
  toString(): string;
24
31
  /**
25
32
  * The primitive this value reads as wherever one is consumed: `LEN`, `&`, `+`, comparison,
26
- * `ISTEXT`, `TYPE()`, sort, filter, find. A rich text reads as its text; an image reads as
27
- * nothing (`null`, or the method absent), and is `#VALUE!` wherever a primitive is needed.
33
+ * `ISTEXT`, `TYPE()`, sort, filter, find. A rich text reads as its text; an error that carries
34
+ * more than its code reads as that error; an image reads as nothing (`null`, or the method
35
+ * absent), and is `#VALUE!` wherever a primitive is needed.
28
36
  *
29
37
  * @remarks
30
- * The ordinary rules then apply to the primitive (text-to-number coercion, collation), so a
31
- * value adds no coercions of its own.
38
+ * The ordinary rules then apply to the primitive (text-to-number coercion, collation, error
39
+ * propagation), so a value adds no coercions of its own.
32
40
  */
33
- toPrimitive?(): number | string | boolean | null;
41
+ toPrimitive?(): Exclude<Scalar, IRichData>;
34
42
  /**
35
43
  * The items this value unpacks to where a range or array is accepted (a list); `null`, or the
36
44
  * method absent, for a value that is one value.
37
45
  */
38
46
  toArray?(): Scalar[][] | null;
39
47
  /**
40
- * Indicates this is an IRichData type.
48
+ * The value as JSON, which its kind makes it again from. A value that holds a resource (a
49
+ * picture's bytes) names it by the id `toResourceId` answers, and the file saves the resource;
50
+ * without `toResourceId` it names none.
41
51
  */
42
- toJSON?(): IRichData.JSON | Promise<IRichData.JSON>;
52
+ toJSON?(toResourceId?: IRichData.ToResourceId): IRichData.JSON | Promise<IRichData.JSON>;
43
53
  /**
44
54
  * For runtime type checking.
45
55
  */
46
56
  get isIRichData(): true;
47
57
  }
48
58
  export declare namespace IRichData {
59
+ /**
60
+ * The id a file being saved gives a resource a value holds (an `IResource`); `null` when the
61
+ * file does not save it.
62
+ */
63
+ type ToResourceId = (resource: any) => number | null;
49
64
  interface JSON {
65
+ /** The name of the value's kind ({@link IRichType.getName}). */
50
66
  type: string;
67
+ /** The value's own data, as its kind reads it. */
51
68
  data?: any;
69
+ /**
70
+ * Presentation for the properties where this value differs from its kind, by property name.
71
+ */
72
+ meta?: {
73
+ readonly [property: string]: IRichMeta;
74
+ };
52
75
  }
53
76
  }
54
77
  //# sourceMappingURL=IRichData.d.ts.map
@@ -0,0 +1,139 @@
1
+ import { Scalar } from './Scalar';
2
+ /**
3
+ * The kind of a rich value: its class. A kind is a static set of typed property definitions, and
4
+ * every value of a kind shares the one `IRichType` its {@link IRichData.getKind} returns.
5
+ *
6
+ * @remarks
7
+ * For introspection: a renderer, a card, a formula editor offering `A1.` completions, or a
8
+ * function reading a field asks the value's kind which properties it has. What a value reads as
9
+ * where a primitive is consumed is the value's own answer ({@link IRichData.toPrimitive}).
10
+ */
11
+ export interface IRichType {
12
+ /**
13
+ * The kind's name: what a value's JSON names as its `type`.
14
+ */
15
+ getName(): string;
16
+ /**
17
+ * The name a UI shows for the kind, such as in a list of what can be inserted. The name when the
18
+ * kind has no label of its own.
19
+ */
20
+ getLabel(): string;
21
+ /**
22
+ * The kind's properties, in the order the kind declares them.
23
+ */
24
+ getProperties(): readonly IRichType.Property[];
25
+ /**
26
+ * The property `name`, or `null` when the kind has none by that name.
27
+ */
28
+ getProperty(name: string): IRichType.Property | null;
29
+ /**
30
+ * The property whose value is the text a cell shows for a value of this kind, or `null` when
31
+ * the kind shows none (an image).
32
+ */
33
+ getDisplayProperty(): string | null;
34
+ /**
35
+ * The kind's own presentation (a card, an icon, a provider), or `null` for none.
36
+ */
37
+ getMeta(): IRichMeta | null;
38
+ }
39
+ export declare namespace IRichType {
40
+ /**
41
+ * What a property holds.
42
+ *
43
+ * @remarks
44
+ * `rich` is another rich value (a capital city, an image); `array` is an array value; `resource`
45
+ * is a workbook resource such as a picture's bytes.
46
+ */
47
+ type ValueType = 'number' | 'integer' | 'string' | 'boolean' | 'error' | 'rich' | 'array' | 'resource';
48
+ /**
49
+ * One property a kind declares.
50
+ */
51
+ interface Property {
52
+ /** The property's name. */
53
+ readonly name: string;
54
+ /** What it holds. */
55
+ readonly valueType: ValueType;
56
+ /** What it reads as on a value that holds none. Omitted, `null`. */
57
+ readonly defaultValue?: Scalar;
58
+ /** How the property shows, unless a value says otherwise. */
59
+ readonly meta?: IRichMeta;
60
+ }
61
+ /**
62
+ * A kind saved with the workbook whose values name it: one that is not registered in code, such
63
+ * as a kind read from a file.
64
+ */
65
+ interface JSON {
66
+ /** {@inheritDoc IRichType.getName} */
67
+ name: string;
68
+ /** {@inheritDoc IRichType.getLabel} */
69
+ label?: string;
70
+ /** {@inheritDoc IRichType.getProperties} */
71
+ properties?: readonly Property[];
72
+ /** {@inheritDoc IRichType.getDisplayProperty} */
73
+ displayProperty?: string | null;
74
+ /** {@inheritDoc IRichType.getMeta} */
75
+ meta?: IRichMeta;
76
+ }
77
+ }
78
+ /**
79
+ * How a rich value, or one of its properties, is presented: the number format and caption of a
80
+ * property, where it is offered, its sources; a kind's card, icon and provider.
81
+ *
82
+ * @remarks
83
+ * Presentation only, never a value. A kind gives each of its properties a default; a value gives
84
+ * one only for a property where it differs (a price in another currency).
85
+ */
86
+ export interface IRichMeta {
87
+ /** The number format a number property shows in. */
88
+ readonly numberFormat?: string;
89
+ /** A short caption shown beside the property, such as its unit or the year of its data. */
90
+ readonly sublabel?: string;
91
+ /** Where the property is not offered. Each omitted entry is `false`. */
92
+ readonly excludeFrom?: IRichMeta.ExcludeFrom;
93
+ /** Where the property's data comes from and under what license. */
94
+ readonly attribution?: readonly IRichMeta.Attribution[];
95
+ /** A kind's card. */
96
+ readonly card?: IRichMeta.Card;
97
+ /** A kind's icon, by name. */
98
+ readonly icon?: string;
99
+ /** Who provides a kind's data. */
100
+ readonly provider?: IRichMeta.Provider;
101
+ }
102
+ export declare namespace IRichMeta {
103
+ /** Where a property is not offered. */
104
+ interface ExcludeFrom {
105
+ /** Not shown on the card. */
106
+ readonly cardView?: boolean;
107
+ /** Not offered after `A1.` in a formula. */
108
+ readonly dotNotation?: boolean;
109
+ /** Not offered by formula autocomplete. */
110
+ readonly autoComplete?: boolean;
111
+ /** A change to the property is not a change to the value. */
112
+ readonly calcCompare?: boolean;
113
+ }
114
+ /** One source of a property's data. */
115
+ interface Attribution {
116
+ readonly sourceText?: string;
117
+ readonly sourceAddress?: string;
118
+ readonly licenseText?: string;
119
+ readonly licenseAddress?: string;
120
+ }
121
+ /** A kind's card: which properties it shows, and how. */
122
+ interface Card {
123
+ /** The properties shown, in order. Omitted, the kind's order. */
124
+ readonly order?: readonly string[];
125
+ /** The property shown as the title. */
126
+ readonly title?: string;
127
+ /** The property shown under the title. */
128
+ readonly subTitle?: string;
129
+ /** The image property shown at the top. */
130
+ readonly mainImage?: string;
131
+ }
132
+ /** Who provides a kind's data. */
133
+ interface Provider {
134
+ readonly description?: string;
135
+ readonly logoSourceAddress?: string;
136
+ readonly logoTargetAddress?: string;
137
+ }
138
+ }
139
+ //# sourceMappingURL=IRichType.d.ts.map
@@ -46,6 +46,33 @@ export declare namespace Scalar {
46
46
  * truncation, not rounding: `1234567890.123456789` stores `…345`, never `…346`.
47
47
  */
48
48
  function truncateNumberText(text: string): string;
49
+ /**
50
+ * Encodings of `ScalarType` for persistence.
51
+ */
52
+ type JSONType = 'n' | 's' | 'b' | 'e' | 'r' | 'z';
53
+ /**
54
+ * A value encoded as a number with an associated type.
55
+ */
56
+ interface JSONTypedValue {
57
+ t: JSONType;
58
+ /**
59
+ * The number, string id, error code or boolean flag; for `'r'`, the rich data's own JSON
60
+ * (`IRichData.JSON`), which its registered kind reads back.
61
+ */
62
+ v: number | IRichData.JSON;
63
+ }
64
+ /**
65
+ * JSON values whose type is implied by their JavaScript type.
66
+ *
67
+ * @remarks
68
+ * What a string means is up to the container: a worksheet stores the id of the string in its
69
+ * strings collection, while an external link cache stores the string itself.
70
+ */
71
+ type JSONUnTypedValue = number | boolean | string;
72
+ /**
73
+ * For persisting a single scalar value and its type.
74
+ */
75
+ type JSON = JSONUnTypedValue | JSONTypedValue;
49
76
  }
50
77
  /**
51
78
  * Represents a cell value in JavaScript, including `Date` for convenience.
@@ -15,6 +15,7 @@ export * from './Volatile';
15
15
  export * from './IRange';
16
16
  export * from './IReferenceRange';
17
17
  export * from './IRichData';
18
+ export * from './IRichType';
18
19
  export * from './IFunction';
19
20
  export * from './IFormulaContext';
20
21
  export * from './IFunctionArguments';