lib0 1.0.0-rc.34 → 1.0.0-rc.36

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.
@@ -58,7 +58,7 @@ export const $attribution: s.Schema<Attribution>;
58
58
  * @typedef {{ type: 'insert', value: any, attribution?: Attribution } | { type: 'delete', attribution?: Attribution } | { type: 'modify', value: DeltaJSON, attribution?: Attribution|null }} DeltaAttrOpJSON
59
59
  */
60
60
  /**
61
- * @typedef {TextOp|InsertOp<any>|DeleteOp|RetainOp|ModifyOp<any>} ChildrenOpAny
61
+ * @typedef {TextOp|InsertOp<any>|DeleteOp<any>|RetainOp|ModifyOp<any>} ChildrenOpAny
62
62
  */
63
63
  /**
64
64
  * @typedef {SetAttrOp<any>|DeleteAttrOp<any>|ModifyAttrOp} AttrOpAny
@@ -249,14 +249,14 @@ export class DeleteOp<Conf extends DeltaConf = {}> extends list.ListNode {
249
249
  * @param {number} [end]
250
250
  * @param {boolean} [_markAsDone] accepted for a uniform children-op `clone` signature; ignored (a
251
251
  * delete holds no nested content).
252
- * @return {DeleteOp}
252
+ * @return {DeleteOp<any>}
253
253
  */
254
- clone(start?: number, end?: number, _markAsDone?: boolean): DeleteOp;
254
+ clone(start?: number, end?: number, _markAsDone?: boolean): DeleteOp<any>;
255
255
  $type: s.Schema<DeleteOp<any>>;
256
256
  /**
257
- * @param {DeleteOp} other
257
+ * @param {DeleteOp<any>} other
258
258
  */
259
- [equalityTrait.EqualityTraitSymbol](other: DeleteOp): boolean;
259
+ [equalityTrait.EqualityTraitSymbol](other: DeleteOp<any>): boolean;
260
260
  }
261
261
  /**
262
262
  * @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
@@ -321,10 +321,10 @@ export class RetainOp extends list.ListNode {
321
321
  /**
322
322
  * Delta that can be applied on a YType Embed
323
323
  *
324
- * @template {Delta} [DTypes=DeltaAny]
324
+ * @template {Delta<any>} [DTypes=DeltaAny]
325
325
  * @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
326
326
  */
327
- export class ModifyOp<DTypes extends Delta = DeltaAny> extends list.ListNode {
327
+ export class ModifyOp<DTypes extends Delta<any> = DeltaAny> extends list.ListNode {
328
328
  /**
329
329
  * @param {DTypes} delta
330
330
  * @param {Formats|null|undefined} format tri-state: `undefined` skip / `null` clear / object merge
@@ -530,9 +530,9 @@ export class ModifyAttrOp<Modifier extends DeltaAny = DeltaAny, K extends string
530
530
  get type(): "modify";
531
531
  get fingerprint(): string;
532
532
  /**
533
- * @return {DeltaBuilder}
533
+ * @return {DeltaBuilder<any>}
534
534
  */
535
- get _modValue(): DeltaBuilder;
535
+ get _modValue(): DeltaBuilder<any>;
536
536
  /**
537
537
  * @return {DeltaAttrOpJSON}
538
538
  */
@@ -737,13 +737,13 @@ export class DeltaBuilder<Conf extends DeltaConf = {}, FixedConf extends boolean
737
737
  text: true;
738
738
  })>, FixedConf>;
739
739
  /**
740
- * @template {Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>,Delta|DeltaData<any,any,any,any>|DeltaBuilder>} NewContent
740
+ * @template {Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>,Delta<any>|DeltaData<any,any,any,any>|DeltaBuilder<any>>} NewContent
741
741
  * @param {NewContent} modify
742
742
  * @param {Formats?} [formatting] tri-state: omit/`undefined` skip, `null` clear, `{k:v}`/`{k:null}` set/remove
743
743
  * @param {Attribution?} [attribution] tri-state: omit/`undefined` skip, `null` clear, `{k:v}`/`{k:null}` set/remove
744
744
  * @return {DeltaBuilder<DeltaConfOverwrite<Conf, {children: DeltaConfGetChildren<Conf>|NewContent}>, FixedConf>}
745
745
  */
746
- modify<NewContent extends Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>, Delta | DeltaData<any, any, any, any> | DeltaBuilder>>(modify: NewContent, formatting?: Formats | null, attribution?: Attribution | null): DeltaBuilder<DeltaConfOverwrite<Conf, {
746
+ modify<NewContent extends Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>, Delta<any> | DeltaData<any, any, any, any> | DeltaBuilder<any>>>(modify: NewContent, formatting?: Formats | null, attribution?: Attribution | null): DeltaBuilder<DeltaConfOverwrite<Conf, {
747
747
  children: DeltaConfGetChildren<Conf> | NewContent;
748
748
  }>, FixedConf>;
749
749
  /**
@@ -1009,45 +1009,35 @@ export function create<NodeName extends string | null, Attrs extends {
1009
1009
  [k: string | number]: any;
1010
1010
  } | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, children?: Children | undefined): DeltaBuilder<CondensedDeltaConf<NodeName, Attrs, Children>>;
1011
1011
  /**
1012
- * @template {string|null} NodeName
1013
- * @template {Array<any>|string} [Children=never]
1014
- * @overload
1015
- * @param {NodeName} nodeName
1016
- * @param {...Array<Children>} children
1017
- * @return {DeltaBuilder<CondensedDeltaConf<NodeName,null,Children>>}
1018
- */
1019
- export function from<NodeName extends string | null, Children extends Array<any> | string = never>(nodeName: NodeName, ...children: Array<Children>[]): DeltaBuilder<CondensedDeltaConf<NodeName, null, Children>>;
1020
- /**
1021
- * @template {Array<any>|string} [Children=never]
1022
- * @overload
1023
- * @param {...Array<Children>} children
1024
- * @return {DeltaBuilder<CondensedDeltaConf<null,null,Children>>}
1025
- */
1026
- export function from<Children extends Array<any> | string = never>(...children: Array<Children>[]): DeltaBuilder<CondensedDeltaConf<null, null, Children>>;
1027
- /**
1028
- * @template {{[k:string|number]:any}|null} Attrs
1029
- * @template {Array<any>|string} [Children=never]
1030
- * @overload
1031
- * @param {Attrs} attrs
1032
- * @param {...Array<Children>} children
1033
- * @return {DeltaBuilder<CondensedDeltaConf<null,Attrs,Children>>}
1034
- */
1035
- export function from<Attrs extends {
1036
- [k: string | number]: any;
1037
- } | null, Children extends Array<any> | string = never>(attrs: Attrs, ...children: Array<Children>[]): DeltaBuilder<CondensedDeltaConf<null, Attrs, Children>>;
1038
- /**
1039
- * @template {string|null} NodeName
1040
- * @template {{[k:string|number]:any}|null} Attrs
1041
- * @template {Array<any>|string} [Children=never]
1042
- * @overload
1043
- * @param {NodeName} nodeName
1044
- * @param {Attrs} attrs
1045
- * @param {...Array<Children>} children
1046
- * @return {DeltaBuilder<CondensedDeltaConf<NodeName,Attrs,Children>>}
1047
- */
1048
- export function from<NodeName extends string | null, Attrs extends {
1049
- [k: string | number]: any;
1050
- } | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, ...children: Array<Children>[]): DeltaBuilder<CondensedDeltaConf<NodeName, Attrs, Children>>;
1012
+ * Build a delta from positional args: an optional node name, optional attrs, then any number of
1013
+ * children (each either a string or an array of embeds) - see {@link create} for the fixed-arity
1014
+ * condensed form.
1015
+ *
1016
+ * Typed as a set of call signatures instead of `@overload` tags, because a rest parameter can't be
1017
+ * declared consistently in an `@overload` tag: the checker only turns `@param {...X} children`
1018
+ * into `X[]` if the implementation's rest parameter has the same name, otherwise it takes `X` as
1019
+ * the type of the whole rest array - while the declaration emit always writes `...children: X[]`.
1020
+ * lib0's source check and the consumers of the emitted declarations hence saw different
1021
+ * signatures. `Children` is the tuple of all children arguments, so that string and array children
1022
+ * can be mixed (`Children[number]` is the union of them).
1023
+ *
1024
+ * @type {{
1025
+ * <NodeName extends string|null, Children extends Array<Array<any>|string> = []>(nodeName: NodeName, ...children: Children): DeltaBuilder<CondensedDeltaConf<NodeName,null,Children[number]>>,
1026
+ * <Children extends Array<Array<any>|string> = []>(...children: Children): DeltaBuilder<CondensedDeltaConf<null,null,Children[number]>>,
1027
+ * <Attrs extends {[k:string|number]:any}|null, Children extends Array<Array<any>|string> = []>(attrs: Attrs, ...children: Children): DeltaBuilder<CondensedDeltaConf<null,Attrs,Children[number]>>,
1028
+ * <NodeName extends string|null, Attrs extends {[k:string|number]:any}|null, Children extends Array<Array<any>|string> = []>(nodeName: NodeName, attrs: Attrs, ...children: Children): DeltaBuilder<CondensedDeltaConf<NodeName,Attrs,Children[number]>>
1029
+ * }}
1030
+ */
1031
+ export const from: {
1032
+ <NodeName_1 extends string | null, Children_1 extends Array<Array<any> | string> = []>(nodeName: NodeName_1, ...children: Children_1): DeltaBuilder<CondensedDeltaConf<NodeName_1, null, Children_1[number]>>;
1033
+ <Children_1 extends Array<Array<any> | string> = []>(...children: Children_1): DeltaBuilder<CondensedDeltaConf<null, null, Children_1[number]>>;
1034
+ <Attrs_1 extends {
1035
+ [k: string | number]: any;
1036
+ } | null, Children_1 extends Array<Array<any> | string> = []>(attrs: Attrs_1, ...children: Children_1): DeltaBuilder<CondensedDeltaConf<null, Attrs_1, Children_1[number]>>;
1037
+ <NodeName_1 extends string | null, Attrs_1 extends {
1038
+ [k: string | number]: any;
1039
+ } | null, Children_1 extends Array<Array<any> | string> = []>(nodeName: NodeName_1, attrs: Attrs_1, ...children: Children_1): DeltaBuilder<CondensedDeltaConf<NodeName_1, Attrs_1, Children_1[number]>>;
1040
+ };
1051
1041
  /**
1052
1042
  * Shorthand for `delta.create().insert(..)` — see {@link DeltaBuilder#insert}.
1053
1043
  *
@@ -1222,7 +1212,7 @@ export type DeltaAttrOpJSON = {
1222
1212
  value: DeltaJSON;
1223
1213
  attribution?: Attribution | null;
1224
1214
  };
1225
- export type ChildrenOpAny = TextOp | InsertOp<any> | DeleteOp | RetainOp | ModifyOp<any>;
1215
+ export type ChildrenOpAny = TextOp | InsertOp<any> | DeleteOp<any> | RetainOp | ModifyOp<any>;
1226
1216
  export type AttrOpAny = SetAttrOp<any> | DeleteAttrOp<any> | ModifyAttrOp;
1227
1217
  export type _OpAny = ChildrenOpAny | AttrOpAny;
1228
1218
  export type AddToAttrs<Attrs_1 extends { [Key in string | number]: any; }, Key extends string | number, Val extends unknown> = { [K in (Key | keyof Attrs_1)]: (unknown extends Attrs_1[K] ? never : Attrs_1[K]) | (Key extends K ? Val : never); } & {};
@@ -1574,20 +1564,20 @@ declare class DeltaData<Name extends string, Attrs extends { [K in string | numb
1574
1564
  name: Name;
1575
1565
  $schema: s.Schema<Delta<any>> | null;
1576
1566
  /**
1577
- * @type {{ [K in keyof Attrs]?: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Attrs[K] extends Delta ? ModifyAttrOp<Extract<Attrs[K],Delta>,K> : never))) : never }
1578
- * & { [Symbol.iterator]: () => Iterator<{ [K in keyof Attrs]: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Delta extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K],Delta>,K> : never))) : never }[keyof Attrs]> }
1567
+ * @type {{ [K in keyof Attrs]?: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Delta<any> extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K],Delta<any>>,K> : never))) : never }
1568
+ * & { [Symbol.iterator]: () => Iterator<{ [K in keyof Attrs]: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Delta<any> extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K],Delta<any>>,K> : never))) : never }[keyof Attrs]> }
1579
1569
  * }
1580
1570
  */
1581
- attrs: { [K in keyof Attrs]?: K extends string | number ? (SetAttrOp<Attrs[K], K> | DeleteAttrOp<Attrs[K], K> | (Attrs[K] extends never ? never : (Attrs[K] extends Delta ? ModifyAttrOp<Extract<Attrs[K], Delta>, K> : never))) : never; } & {
1582
- [Symbol.iterator]: () => Iterator<{ [K in keyof Attrs]: K extends string | number ? (SetAttrOp<Attrs[K], K> | DeleteAttrOp<Attrs[K], K> | (Attrs[K] extends never ? never : (Delta extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K], Delta>, K> : never))) : never; }[keyof Attrs]>;
1571
+ attrs: { [K in keyof Attrs]?: K extends string | number ? (SetAttrOp<Attrs[K], K> | DeleteAttrOp<Attrs[K], K> | (Attrs[K] extends never ? never : (Delta<any> extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K], Delta<any>>, K> : never))) : never; } & {
1572
+ [Symbol.iterator]: () => Iterator<{ [K in keyof Attrs]: K extends string | number ? (SetAttrOp<Attrs[K], K> | DeleteAttrOp<Attrs[K], K> | (Attrs[K] extends never ? never : (Delta<any> extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K], Delta<any>>, K> : never))) : never; }[keyof Attrs]>;
1583
1573
  };
1584
1574
  /**
1585
1575
  * @type {list.List<
1586
1576
  * | (Text extends true ? (RetainOp|TextOp|DeleteOp<any>) : never)
1587
- * | (RetainOp|InsertOp<Children>|DeleteOp<any>|(Delta extends Children ? ModifyOp<Extract<Children,Delta>> : never))
1577
+ * | (RetainOp|InsertOp<Children>|DeleteOp<any>|(Delta<any> extends Children ? ModifyOp<Extract<Children,Delta<any>>> : never))
1588
1578
  * >}
1589
1579
  */
1590
- children: list.List<(Text extends true ? (RetainOp | TextOp | DeleteOp<any>) : never) | (RetainOp | InsertOp<Children> | DeleteOp<any> | (Delta extends Children ? ModifyOp<Extract<Children, Delta>> : never))>;
1580
+ children: list.List<(Text extends true ? (RetainOp | TextOp | DeleteOp<any>) : never) | (RetainOp | InsertOp<Children> | DeleteOp<any> | (Delta<any> extends Children ? ModifyOp<Extract<Children, Delta<any>>> : never))>;
1591
1581
  /**
1592
1582
  * All child-ops sizes combined. Note that delete-ops also have a length
1593
1583
  */
package/dist/number.d.ts CHANGED
@@ -4,6 +4,7 @@ export const LOWEST_INT32: number;
4
4
  export const HIGHEST_INT32: 2147483647;
5
5
  export const HIGHEST_UINT32: 4294967295;
6
6
  export const isInteger: (number: unknown) => boolean;
7
+ export const isSafeInteger: (number: unknown) => boolean;
7
8
  export const isNaN: (number: unknown) => boolean;
8
9
  export const parseInt: (string: string, radix?: number) => number;
9
10
  export function countBits(n: number): number;
package/dist/schema.d.ts CHANGED
@@ -480,17 +480,26 @@ export const $$symbol: Schema<Schema<Symbol>>;
480
480
  export const $number: Schema<number>;
481
481
  export const $$number: Schema<Schema<number>>;
482
482
  /**
483
- * A number without fractional component (`Number.isInteger`). The unwrapped type is still
484
- * `number` - JS has no separate integer type.
483
+ * A number without fractional component in the safe integer range (`Number.isSafeInteger`,
484
+ * i.e. `|n| <= 2^53 - 1`). The unwrapped type is still `number` - JS has no separate integer type.
485
+ *
486
+ * The range restriction guarantees that every `$int` is exactly representable as a 64-bit
487
+ * signed integer (`BigInt(n)` is lossless, databases can store it in an `int64` / `BIGINT` column).
488
+ * Values like `1e20` are integers to `Number.isInteger`, but they are neither exact (every float
489
+ * beyond 2^53 rounds to a multiple of a power of two) nor storable in 64 bits, so they are
490
+ * rejected. Use `$number` for unbounded floats and `$bigint` for arbitrary-precision integers.
485
491
  *
486
492
  * @type {Schema<number>}
487
493
  */
488
494
  export const $int: Schema<number>;
489
495
  export const $$int: Schema<Schema<number>>;
490
496
  /**
491
- * An unsigned integer: a number without fractional component that is `>= 0`. The unwrapped type is
497
+ * An unsigned integer: a `$int` that is `>= 0` (so `0 <= n <= 2^53 - 1`). The unwrapped type is
492
498
  * still `number` - JS has no separate integer type.
493
499
  *
500
+ * Like `$int`, every `$uint` is exactly representable as a 64-bit integer (signed or unsigned).
501
+ * See `$int` for why the range is restricted.
502
+ *
494
503
  * @type {Schema<number>}
495
504
  */
496
505
  export const $uint: Schema<number>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lib0",
3
- "version": "1.0.0-rc.34",
3
+ "version": "1.0.0-rc.36",
4
4
  "description": "isomorphic utility functions",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -341,7 +341,7 @@
341
341
  "scripts": {
342
342
  "clean": "rm -rf dist",
343
343
  "types": "rm -rf dist && tsc -p tsconfig.build.json",
344
- "check-dist-types": "tsc -p tsconfig.dist-check.json",
344
+ "check-dist-types": "node ./dist-check/copy-tests.js && tsc -p tsconfig.dist-check.json",
345
345
  "dist": "npm run clean && npm run types && npm run check-dist-types",
346
346
  "debug": "npm run gentesthtml && node ./src/bin/0serve.js -o test.html",
347
347
  "test": "c8 --check-coverage --lines 97 --branches 96 --functions 94 --statements 97 node --unhandled-rejections=strict ./src/test.js",
@@ -116,7 +116,7 @@ export const $attribution = /* @__PURE__ */(() => s.$object({
116
116
  */
117
117
 
118
118
  /**
119
- * @typedef {TextOp|InsertOp<any>|DeleteOp|RetainOp|ModifyOp<any>} ChildrenOpAny
119
+ * @typedef {TextOp|InsertOp<any>|DeleteOp<any>|RetainOp|ModifyOp<any>} ChildrenOpAny
120
120
  */
121
121
 
122
122
  /**
@@ -635,7 +635,7 @@ export class DeleteOp extends list.ListNode {
635
635
  }
636
636
 
637
637
  /**
638
- * @param {DeleteOp} other
638
+ * @param {DeleteOp<any>} other
639
639
  */
640
640
  [equalityTrait.EqualityTraitSymbol] (other) {
641
641
  return $deleteOp.check(other) && this.delete === other.delete
@@ -646,7 +646,7 @@ export class DeleteOp extends list.ListNode {
646
646
  * @param {number} [end]
647
647
  * @param {boolean} [_markAsDone] accepted for a uniform children-op `clone` signature; ignored (a
648
648
  * delete holds no nested content).
649
- * @return {DeleteOp}
649
+ * @return {DeleteOp<any>}
650
650
  */
651
651
  clone (start = 0, end = this.delete, _markAsDone = true) {
652
652
  const cpy = new DeleteOp(end - start)
@@ -758,7 +758,7 @@ export class RetainOp extends list.ListNode {
758
758
  /**
759
759
  * Delta that can be applied on a YType Embed
760
760
  *
761
- * @template {Delta} [DTypes=DeltaAny]
761
+ * @template {Delta<any>} [DTypes=DeltaAny]
762
762
  * @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
763
763
  */
764
764
  export class ModifyOp extends list.ListNode {
@@ -1088,7 +1088,7 @@ export class ModifyAttrOp {
1088
1088
  }
1089
1089
 
1090
1090
  /**
1091
- * @return {DeltaBuilder}
1091
+ * @return {DeltaBuilder<any>}
1092
1092
  */
1093
1093
  get _modValue () {
1094
1094
  return modValue(this)
@@ -1403,8 +1403,8 @@ class DeltaData {
1403
1403
  this.name = /** @type {Name} */ (name)
1404
1404
  this.$schema = $schema
1405
1405
  /**
1406
- * @type {{ [K in keyof Attrs]?: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Attrs[K] extends Delta ? ModifyAttrOp<Extract<Attrs[K],Delta>,K> : never))) : never }
1407
- * & { [Symbol.iterator]: () => Iterator<{ [K in keyof Attrs]: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Delta extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K],Delta>,K> : never))) : never }[keyof Attrs]> }
1406
+ * @type {{ [K in keyof Attrs]?: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Delta<any> extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K],Delta<any>>,K> : never))) : never }
1407
+ * & { [Symbol.iterator]: () => Iterator<{ [K in keyof Attrs]: K extends string|number ? (SetAttrOp<Attrs[K],K>|DeleteAttrOp<Attrs[K],K>|(Attrs[K] extends never ? never : (Delta<any> extends Attrs[K] ? ModifyAttrOp<Extract<Attrs[K],Delta<any>>,K> : never))) : never }[keyof Attrs]> }
1408
1408
  * }
1409
1409
  */
1410
1410
  this.attrs = /** @type {any} */ ({
@@ -1418,7 +1418,7 @@ class DeltaData {
1418
1418
  /**
1419
1419
  * @type {list.List<
1420
1420
  * | (Text extends true ? (RetainOp|TextOp|DeleteOp<any>) : never)
1421
- * | (RetainOp|InsertOp<Children>|DeleteOp<any>|(Delta extends Children ? ModifyOp<Extract<Children,Delta>> : never))
1421
+ * | (RetainOp|InsertOp<Children>|DeleteOp<any>|(Delta<any> extends Children ? ModifyOp<Extract<Children,Delta<any>>> : never))
1422
1422
  * >}
1423
1423
  */
1424
1424
  this.children = /** @type {any} */ (list.create())
@@ -2239,7 +2239,7 @@ export class DeltaBuilder extends Delta {
2239
2239
  }
2240
2240
 
2241
2241
  /**
2242
- * @template {Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>,Delta|DeltaData<any,any,any,any>|DeltaBuilder>} NewContent
2242
+ * @template {Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>,Delta<any>|DeltaData<any,any,any,any>|DeltaBuilder<any>>} NewContent
2243
2243
  * @param {NewContent} modify
2244
2244
  * @param {Formats?} [formatting] tri-state: omit/`undefined` skip, `null` clear, `{k:v}`/`{k:null}` set/remove
2245
2245
  * @param {Attribution?} [attribution] tri-state: omit/`undefined` skip, `null` clear, `{k:v}`/`{k:null}` set/remove
@@ -3926,58 +3926,48 @@ export const create = (nodeNameOrSchema, attrsOrSchema, children) => {
3926
3926
  }
3927
3927
 
3928
3928
  /**
3929
- * @template {string|null} NodeName
3930
- * @template {Array<any>|string} [Children=never]
3931
- * @overload
3932
- * @param {NodeName} nodeName
3933
- * @param {...Array<Children>} children
3934
- * @return {DeltaBuilder<CondensedDeltaConf<NodeName,null,Children>>}
3935
- */
3936
- /**
3937
- * @template {Array<any>|string} [Children=never]
3938
- * @overload
3939
- * @param {...Array<Children>} children
3940
- * @return {DeltaBuilder<CondensedDeltaConf<null,null,Children>>}
3941
- */
3942
- /**
3943
- * @template {{[k:string|number]:any}|null} Attrs
3944
- * @template {Array<any>|string} [Children=never]
3945
- * @overload
3946
- * @param {Attrs} attrs
3947
- * @param {...Array<Children>} children
3948
- * @return {DeltaBuilder<CondensedDeltaConf<null,Attrs,Children>>}
3949
- */
3950
- /**
3951
- * @template {string|null} NodeName
3952
- * @template {{[k:string|number]:any}|null} Attrs
3953
- * @template {Array<any>|string} [Children=never]
3954
- * @overload
3955
- * @param {NodeName} nodeName
3956
- * @param {Attrs} attrs
3957
- * @param {...Array<Children>} children
3958
- * @return {DeltaBuilder<CondensedDeltaConf<NodeName,Attrs,Children>>}
3959
- */
3960
- /**
3961
- * `...X` (not `Array<X>`) is the rest-parameter form — `@param {Array<X>} args` declares a single
3962
- * array-typed parameter, which makes the overloads above incompatible with this signature. TS only
3963
- * cross-checks overloads against the implementation for function declarations, so it stayed silent.
3929
+ * Returns `any` because the resulting conf is computed by the call signatures of {@link from} at
3930
+ * the type level only - as in a ts overload implementation, the body can't be checked against
3931
+ * each of them.
3964
3932
  *
3965
- * @param {...(string|null|{[K:string|number]:any}|Array<any>)} args
3966
- * @return {DeltaBuilder<{}>}
3933
+ * @param {...any} args
3934
+ * @return {any}
3967
3935
  */
3968
- export const from = (...args) => {
3936
+ const _from = (...args) => {
3969
3937
  const hasName = s.$string.check(args[0])
3970
3938
  let i = hasName ? 1 : 0
3971
3939
  const d = create(hasName ? /** @type {string} */ (args[0]) : null)
3972
3940
  if (s.$objectAny.check(args[i])) {
3973
- d.setAttrs(/** @type {any} */ (args[i++]))
3941
+ d.setAttrs(args[i++])
3974
3942
  }
3975
3943
  for (; i < args.length; i++) {
3976
- d.insert(/** @type {any} */ (args[i]))
3944
+ d.insert(args[i])
3977
3945
  }
3978
3946
  return d
3979
3947
  }
3980
3948
 
3949
+ /**
3950
+ * Build a delta from positional args: an optional node name, optional attrs, then any number of
3951
+ * children (each either a string or an array of embeds) - see {@link create} for the fixed-arity
3952
+ * condensed form.
3953
+ *
3954
+ * Typed as a set of call signatures instead of `@overload` tags, because a rest parameter can't be
3955
+ * declared consistently in an `@overload` tag: the checker only turns `@param {...X} children`
3956
+ * into `X[]` if the implementation's rest parameter has the same name, otherwise it takes `X` as
3957
+ * the type of the whole rest array - while the declaration emit always writes `...children: X[]`.
3958
+ * lib0's source check and the consumers of the emitted declarations hence saw different
3959
+ * signatures. `Children` is the tuple of all children arguments, so that string and array children
3960
+ * can be mixed (`Children[number]` is the union of them).
3961
+ *
3962
+ * @type {{
3963
+ * <NodeName extends string|null, Children extends Array<Array<any>|string> = []>(nodeName: NodeName, ...children: Children): DeltaBuilder<CondensedDeltaConf<NodeName,null,Children[number]>>,
3964
+ * <Children extends Array<Array<any>|string> = []>(...children: Children): DeltaBuilder<CondensedDeltaConf<null,null,Children[number]>>,
3965
+ * <Attrs extends {[k:string|number]:any}|null, Children extends Array<Array<any>|string> = []>(attrs: Attrs, ...children: Children): DeltaBuilder<CondensedDeltaConf<null,Attrs,Children[number]>>,
3966
+ * <NodeName extends string|null, Attrs extends {[k:string|number]:any}|null, Children extends Array<Array<any>|string> = []>(nodeName: NodeName, attrs: Attrs, ...children: Children): DeltaBuilder<CondensedDeltaConf<NodeName,Attrs,Children[number]>>
3967
+ * }}
3968
+ */
3969
+ export const from = _from
3970
+
3981
3971
  /**
3982
3972
  * Shorthand for `delta.create().insert(..)` — see {@link DeltaBuilder#insert}.
3983
3973
  *
package/src/number.js CHANGED
@@ -14,6 +14,7 @@ export const HIGHEST_INT32 = binary.BITS31
14
14
  export const HIGHEST_UINT32 = binary.BITS32
15
15
 
16
16
  export const isInteger = Number.isInteger
17
+ export const isSafeInteger = Number.isSafeInteger
17
18
  export const isNaN = Number.isNaN
18
19
  export const parseInt = Number.parseInt
19
20
 
package/src/schema.js CHANGED
@@ -670,7 +670,12 @@ export class $Record extends Schema {
670
670
  * @return {o is { [key in Unwrap<Keys>]: Unwrap<Values> }}
671
671
  */
672
672
  check (o, err) {
673
- return o != null && object.every(o, (vv, vk) => {
673
+ if (o === null || !object.isObject(o)) {
674
+ /* c8 ignore next */
675
+ err?.extend(null, 'Record', o === null ? 'null' : typeof o)
676
+ return false
677
+ }
678
+ return object.every(o, (vv, vk) => {
674
679
  const ck = this.shape.keys.check(vk, err)
675
680
  /* c8 ignore next */
676
681
  !ck && err?.extend(vk + '', 'Record', typeof o, ck ? 'Key doesn\'t match schema' : 'Value doesn\'t match value')
@@ -1028,21 +1033,30 @@ export const $number = /* @__PURE__ */$custom(o => typeof o === 'number')
1028
1033
  export const $$number = /** @type {Schema<Schema<number>>} */ (/* @__PURE__ */$type('s:$number', $number))
1029
1034
 
1030
1035
  /**
1031
- * A number without fractional component (`Number.isInteger`). The unwrapped type is still
1032
- * `number` - JS has no separate integer type.
1036
+ * A number without fractional component in the safe integer range (`Number.isSafeInteger`,
1037
+ * i.e. `|n| <= 2^53 - 1`). The unwrapped type is still `number` - JS has no separate integer type.
1038
+ *
1039
+ * The range restriction guarantees that every `$int` is exactly representable as a 64-bit
1040
+ * signed integer (`BigInt(n)` is lossless, databases can store it in an `int64` / `BIGINT` column).
1041
+ * Values like `1e20` are integers to `Number.isInteger`, but they are neither exact (every float
1042
+ * beyond 2^53 rounds to a multiple of a power of two) nor storable in 64 bits, so they are
1043
+ * rejected. Use `$number` for unbounded floats and `$bigint` for arbitrary-precision integers.
1033
1044
  *
1034
1045
  * @type {Schema<number>}
1035
1046
  */
1036
- export const $int = /* @__PURE__ */$custom(o => number.isInteger(o))
1047
+ export const $int = /* @__PURE__ */$custom(o => number.isSafeInteger(o))
1037
1048
  export const $$int = /** @type {Schema<Schema<number>>} */ (/* @__PURE__ */$type('s:$int', $int))
1038
1049
 
1039
1050
  /**
1040
- * An unsigned integer: a number without fractional component that is `>= 0`. The unwrapped type is
1051
+ * An unsigned integer: a `$int` that is `>= 0` (so `0 <= n <= 2^53 - 1`). The unwrapped type is
1041
1052
  * still `number` - JS has no separate integer type.
1042
1053
  *
1054
+ * Like `$int`, every `$uint` is exactly representable as a 64-bit integer (signed or unsigned).
1055
+ * See `$int` for why the range is restricted.
1056
+ *
1043
1057
  * @type {Schema<number>}
1044
1058
  */
1045
- export const $uint = /* @__PURE__ */$custom(o => number.isInteger(o) && o >= 0)
1059
+ export const $uint = /* @__PURE__ */$custom(o => number.isSafeInteger(o) && o >= 0)
1046
1060
  export const $$uint = /** @type {Schema<Schema<number>>} */ (/* @__PURE__ */$type('s:$uint', $uint))
1047
1061
 
1048
1062
  /**
@@ -1425,11 +1439,11 @@ const _createCoercer = ($s, cache) => {
1425
1439
  if (_isMeta($$int, $s) || _isMeta($$uint, $s)) {
1426
1440
  const min = _isMeta($$uint, $s) ? 0 : -Infinity
1427
1441
  return (o, path, ctx) => {
1428
- if (number.isInteger(o) && o >= min) return o
1442
+ if (number.isSafeInteger(o) && o >= min) return o
1429
1443
  const t = typeof o
1430
1444
  if (t === 'boolean' || t === 'bigint' || (t === 'string' && o.trim() !== '')) {
1431
1445
  const n = Number(o)
1432
- if (number.isInteger(n) && n >= min) return n
1446
+ if (number.isSafeInteger(n) && n >= min) return n
1433
1447
  }
1434
1448
  return _fail(ctx, path, o, expected)
1435
1449
  }