lib0 1.0.0-rc.21 → 1.0.0-rc.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/array.d.ts +4 -4
  2. package/dist/broadcastchannel.d.ts +3 -3
  3. package/dist/decoding.d.ts +3 -3
  4. package/dist/delta/delta.d.ts +0 -8
  5. package/dist/delta/rdt/dom.d.ts +19 -25
  6. package/dist/delta/rdt.d.ts +24 -0
  7. package/dist/diff.d.ts +1 -1
  8. package/dist/encoding.d.ts +4 -4
  9. package/dist/environment.common.d.ts +21 -0
  10. package/dist/environment.d.ts +2 -8
  11. package/dist/error.d.ts +21 -3
  12. package/dist/eventloop.d.ts +1 -1
  13. package/dist/indexeddb.d.ts +3 -3
  14. package/dist/indexeddbV2.d.ts +3 -3
  15. package/dist/iterator.d.ts +3 -3
  16. package/dist/list.d.ts +6 -6
  17. package/dist/logging.common.d.ts +1 -1
  18. package/dist/logging.d.ts +1 -1
  19. package/dist/logging.node.d.ts +1 -1
  20. package/dist/map.d.ts +4 -4
  21. package/dist/object.d.ts +2 -2
  22. package/dist/observable.d.ts +2 -2
  23. package/dist/pair.d.ts +2 -2
  24. package/dist/pledge.d.ts +10 -10
  25. package/dist/promise.d.ts +2 -2
  26. package/dist/schema.d.ts +19 -1
  27. package/dist/sort.d.ts +3 -3
  28. package/dist/storage.d.ts +2 -2
  29. package/dist/testing.d.ts +18 -11
  30. package/package.json +3 -3
  31. package/src/array.js +5 -5
  32. package/src/broadcastchannel.js +4 -4
  33. package/src/cache.js +1 -1
  34. package/src/decoding.js +2 -2
  35. package/src/delta/delta.js +13 -26
  36. package/src/delta/rdt/dom.js +176 -63
  37. package/src/delta/rdt.js +39 -10
  38. package/src/diff.js +1 -1
  39. package/src/encoding.js +2 -2
  40. package/src/environment.common.js +41 -0
  41. package/src/environment.js +2 -21
  42. package/src/error.js +10 -4
  43. package/src/eventloop.js +3 -3
  44. package/src/function.js +1 -1
  45. package/src/indexeddb.js +4 -4
  46. package/src/indexeddbV2.js +4 -4
  47. package/src/iterator.js +4 -4
  48. package/src/list.js +4 -4
  49. package/src/logging.common.js +3 -3
  50. package/src/logging.js +3 -3
  51. package/src/logging.node.js +3 -3
  52. package/src/map.js +4 -4
  53. package/src/mutex.js +2 -2
  54. package/src/object.js +2 -2
  55. package/src/observable.js +1 -1
  56. package/src/pair.js +2 -2
  57. package/src/pledge.js +6 -6
  58. package/src/promise.js +3 -3
  59. package/src/schema.js +316 -3
  60. package/src/sort.js +4 -4
  61. package/src/storage.js +8 -4
  62. package/src/testing.js +15 -15
package/dist/array.d.ts CHANGED
@@ -20,11 +20,11 @@ export function every<ARR extends ArrayLike<any>>(arr: ARR, f: ARR extends Array
20
20
  export function some<ARR extends ArrayLike<any>>(arr: ARR, f: ARR extends ArrayLike<infer S> ? ((value: S, index: number, arr: ARR) => boolean) : never): boolean;
21
21
  export function equalFlat<ELEM>(a: ArrayLike<ELEM>, b: ArrayLike<ELEM>): boolean;
22
22
  export function flatten<ELEM>(arr: Array<Array<ELEM>>): Array<ELEM>;
23
- export function unfold<T_1>(len: number, f: (arg0: number, arg1: Array<T_1>) => T_1): Array<T_1>;
24
- export function fold<T_1, RESULT>(arr: Array<T_1>, seed: RESULT, folder: (arg0: RESULT, arg1: T_1, arg2: number) => RESULT): RESULT;
23
+ export function unfold<T_1>(len: number, f: (index: number, arr: Array<T_1>) => T_1): Array<T_1>;
24
+ export function fold<T_1, RESULT>(arr: Array<T_1>, seed: RESULT, folder: (acc: RESULT, val: T_1, index: number) => RESULT): RESULT;
25
25
  export function isArray(o: any): o is any[];
26
26
  export function unique<T_1>(arr: Array<T_1>): Array<T_1>;
27
- export function uniqueBy<T_1, M>(arr: ArrayLike<T_1>, mapper: (arg0: T_1) => M): Array<T_1>;
28
- export function map<ARR extends ArrayLike<any>, MAPPER extends (arg0: ARR extends ArrayLike<infer T_1> ? T_1 : never, arg1: number, arg2: ARR) => any>(arr: ARR, mapper: MAPPER): Array<MAPPER extends (...args: any[]) => infer M ? M : never>;
27
+ export function uniqueBy<T_1, M>(arr: ArrayLike<T_1>, mapper: (val: T_1) => M): Array<T_1>;
28
+ export function map<ARR extends ArrayLike<any>, MAPPER extends (val: ARR extends ArrayLike<infer T_1> ? T_1 : never, index: number, arr: ARR) => any>(arr: ARR, mapper: MAPPER): Array<MAPPER extends ((...args: Array<any>) => infer M) ? M : never>;
29
29
  export function bubblesortItem<T_1>(arr: Array<T_1>, i: number, compareFn: (a: T_1, b: T_1) => number): number;
30
30
  //# sourceMappingURL=array.d.ts.map
@@ -1,8 +1,8 @@
1
- export function subscribe(room: string, f: (arg0: any, arg1: any) => any): (arg0: any, arg1: any) => any;
2
- export function unsubscribe(room: string, f: (arg0: any, arg1: any) => any): boolean;
1
+ export function subscribe(room: string, f: (data: any, origin: any) => any): (data: any, origin: any) => any;
2
+ export function unsubscribe(room: string, f: (data: any, origin: any) => any): boolean;
3
3
  export function publish(room: string, data: any, origin?: any): void;
4
4
  export type Channel = {
5
- subs: Set<(arg0: any, arg1: any) => any>;
5
+ subs: Set<(data: any, origin: any) => any>;
6
6
  bc: any;
7
7
  };
8
8
  //# sourceMappingURL=broadcastchannel.d.ts.map
@@ -58,13 +58,13 @@ export function readAny(decoder: Decoder): any;
58
58
  export class RleDecoder<T> extends Decoder<ArrayBufferLike> {
59
59
  /**
60
60
  * @param {Uint8Array} uint8Array
61
- * @param {function(Decoder):T} reader
61
+ * @param {(decoder: Decoder) => T} reader
62
62
  */
63
- constructor(uint8Array: Uint8Array, reader: (arg0: Decoder) => T);
63
+ constructor(uint8Array: Uint8Array, reader: (decoder: Decoder) => T);
64
64
  /**
65
65
  * The reader
66
66
  */
67
- reader: (arg0: Decoder) => T;
67
+ reader: (decoder: Decoder) => T;
68
68
  /**
69
69
  * Current state
70
70
  * @type {T|null}
@@ -110,10 +110,6 @@ export class TextOp extends list.ListNode {
110
110
  * @type {string?}
111
111
  */
112
112
  _fingerprint: string | null;
113
- /**
114
- * @param {string} newVal
115
- */
116
- _updateInsert(newVal: string): void;
117
113
  /**
118
114
  * @return {'insert'}
119
115
  */
@@ -175,10 +171,6 @@ export class InsertOp<ArrayContent extends unknown> extends list.ListNode {
175
171
  * @type {string?}
176
172
  */
177
173
  _fingerprint: string | null;
178
- /**
179
- * @param {ArrayContent} _newVal
180
- */
181
- _updateInsert(_newVal: ArrayContent): void;
182
174
  /**
183
175
  * @return {'insert'}
184
176
  */
@@ -28,16 +28,9 @@ export type DomDelta = delta.Delta<DomConf>;
28
28
  import * as delta from '../delta.js';
29
29
  import * as s from '../../schema.js';
30
30
  /**
31
- * The {@link delta.DeltaConf} of the deltas a {@link DomRDT} produces/consumes (see {@link $domDelta}).
32
- *
33
- * @typedef {{ name: string, attrs: { [key:string]: string }, text: true, recursiveChildren: true }} DomConf
34
- */
35
- /**
36
- * @typedef {delta.Delta<DomConf>} DomDelta
37
- */
38
- /**
39
- * An RDT backed by a live DOM subtree. DOM mutations observed via `MutationObserver` are diffed
40
- * against the last-known state and emitted as deltas; incoming deltas are applied back onto the DOM.
31
+ * An RDT backed by a live DOM subtree. DOM mutations observed via `MutationObserver` reconcile the
32
+ * mirror incrementally (re-reading only changed paths, reusing unchanged subtrees by reference) and the
33
+ * resulting minimal diff is emitted as a delta; incoming deltas are applied back onto the DOM.
41
34
  *
42
35
  * @implements {RDT<DomConf>}
43
36
  * @extends {ObservableV2<{ delta: (delta: delta.Delta<DomConf>, origin: any) => void, destroy: (rdt: DomRDT) => void }>}
@@ -56,24 +49,22 @@ declare class DomRDT extends ObservableV2<{
56
49
  $delta: Schema<DomDelta>;
57
50
  observedNode: Element;
58
51
  /**
59
- * Last-known DOM state. The observe path diffs the live DOM against this to compute the change to
60
- * emit, then advances it; `applyDelta` re-syncs it after mutating the DOM.
52
+ * Maps each observed DOM node to its mirror delta node in {@link DomRDT#_state}. A {@link reconcile}
53
+ * reuses an unchanged subtree by reference (skipping its DOM read) via this map; entries for removed
54
+ * nodes are reclaimed automatically.
61
55
  *
62
- * @type {DomDelta}
56
+ * @type {WeakMap<Node, DomDelta>}
63
57
  */
64
- _state: DomDelta;
65
- observer: MutationObserver;
58
+ _nodes: WeakMap<Node, DomDelta>;
66
59
  /**
67
- * Pull the local DOM changes accumulated since the last sync as a delta (by diffing the live DOM
68
- * against `_state`), advancing `_state` to the current DOM.
60
+ * The live delta mirror of the observed subtree, maintained incrementally. A reconcile rebuilds only
61
+ * the changed paths and swaps this whole root (see {@link pull}); it is never mutated in place, so a
62
+ * mirror handed out by {@link DomRDT#delta} stays a valid immutable snapshot.
69
63
  *
70
- * @return {DomDelta}
71
- */
72
- _pull(): DomDelta;
73
- /**
74
- * @param {MutationRecord[]} mutations
64
+ * @type {DomDelta}
75
65
  */
76
- _mutationHandler: (mutations: MutationRecord[]) => void;
66
+ _state: DomDelta;
67
+ observer: MutationObserver;
77
68
  /**
78
69
  * Apply a foreign delta onto the DOM.
79
70
  *
@@ -87,11 +78,14 @@ declare class DomRDT extends ObservableV2<{
87
78
  * listeners can recognise (and skip) their own changes — see {@link RDT} “Origins”. Defaults to `null`
88
79
  * (an anonymous/local change).
89
80
  * @return {delta.DeltaBuilder<DomConf> | null} the rebased local change (`b`), or `null` when there
90
- * were no concurrent edits
81
+ * were no concurrent edits. A binding maps a returned fix back onto the other side with the
82
+ * `correction` origin (see `../rdt.js`)
91
83
  */
92
84
  applyDelta(d: delta.Delta<DomConf>, origin?: any): delta.DeltaBuilder<DomConf> | null;
93
85
  /**
94
- * The current state as a delta: an "insert everything" delta describing the observed subtree.
86
+ * The current state as a delta: the live mirror ({@link DomRDT#_state}), an "insert everything" delta
87
+ * describing the observed subtree. A shared read snapshot — consumers clone before mutating (see
88
+ * {@link RDT}); the mirror is never mutated in place, so a returned snapshot stays valid.
95
89
  *
96
90
  * @return {delta.Delta<DomConf>}
97
91
  */
@@ -33,6 +33,12 @@ export { deltaRDT } from "./rdt/delta.js";
33
33
  * it just received. The `origin` argument to `applyDelta` is optional and defaults to `null` (an
34
34
  * anonymous/local change); the emitted event always carries whatever value was supplied.
35
35
  *
36
+ * A {@link Binding} distinguishes the two kinds of changes it produces. An ordinary change mapped
37
+ * over from the other side carries the binding itself as its origin. A change that adjusts a side's
38
+ * own earlier change after the fact — a fix returned by the opposite RDT transformed back, or a
39
+ * transformer self-heal — carries {@link correctionOrigin}, so a consumer that applied a delta can recognise
40
+ * that (part of) its change was reverted or amended.
41
+ *
36
42
  * ## `Delta` vs `DeltaBuilder`
37
43
  *
38
44
  * The interface is parameterized by a {@link import('./delta.js').DeltaConf DeltaConf} (like a
@@ -62,6 +68,18 @@ export { deltaRDT } from "./rdt/delta.js";
62
68
  * @type {Schema<RDT<any>>}
63
69
  */
64
70
  export const $rdt: Schema<RDT<any>>;
71
+ /**
72
+ * The {@link RDT origin} carried by every change a {@link Binding} applies as an after-the-fact
73
+ * adjustment to a side's own change: a fix returned by the opposite RDT's `applyDelta` transformed back
74
+ * onto the side that produced the original change, a transformer self-heal (including during the
75
+ * initial-state sync), and every later round of the fix-convergence loop (fixes of fixes). A "fix"
76
+ * covers invariant corrections as well as rebased concurrent edits (see `./rdt/dom.js`). An ordinary
77
+ * mapped change carries the binding itself instead — see the "Origins" section of {@link RDT}. The
78
+ * value is a plain string, so `origin === 'correction'` works without importing this constant.
79
+ *
80
+ * @type {'correction'}
81
+ */
82
+ export const correctionOrigin: "correction";
65
83
  /**
66
84
  * @typedef {object} BindOptions
67
85
  * @property {delta.DiffOptions['compare']} [diffCompare] **Experimental** (may be changed or removed
@@ -144,6 +162,12 @@ export type Schema<T> = import("../schema.js").Schema<T>;
144
162
  * it just received. The `origin` argument to `applyDelta` is optional and defaults to `null` (an
145
163
  * anonymous/local change); the emitted event always carries whatever value was supplied.
146
164
  *
165
+ * A {@link Binding} distinguishes the two kinds of changes it produces. An ordinary change mapped
166
+ * over from the other side carries the binding itself as its origin. A change that adjusts a side's
167
+ * own earlier change after the fact — a fix returned by the opposite RDT transformed back, or a
168
+ * transformer self-heal — carries {@link correctionOrigin}, so a consumer that applied a delta can recognise
169
+ * that (part of) its change was reverted or amended.
170
+ *
147
171
  * ## `Delta` vs `DeltaBuilder`
148
172
  *
149
173
  * The interface is parameterized by a {@link import ('./delta.js').DeltaConf DeltaConf} (like a
package/dist/diff.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export function simpleDiffString(a: string, b: string): SimpleDiff<string>;
2
2
  export function simpleDiff(a: string, b: string): SimpleDiff<string>;
3
- export function simpleDiffArray<T>(a: Array<T>, b: Array<T>, compare?: (arg0: T, arg1: T) => boolean): SimpleDiff<Array<T>>;
3
+ export function simpleDiffArray<T>(a: Array<T>, b: Array<T>, compare?: (a: T, b: T) => boolean): SimpleDiff<Array<T>>;
4
4
  export function simpleDiffStringWithCursor(a: string, b: string, cursor: number): {
5
5
  index: number;
6
6
  remove: number;
@@ -10,7 +10,7 @@ export class Encoder {
10
10
  bufs: Array<Uint8Array>;
11
11
  }
12
12
  export function createEncoder(): Encoder;
13
- export function encode(f: (arg0: Encoder) => void): Uint8Array<ArrayBuffer>;
13
+ export function encode(f: (encoder: Encoder) => void): Uint8Array<ArrayBuffer>;
14
14
  export function length(encoder: Encoder): number;
15
15
  export function hasContent(encoder: Encoder): boolean;
16
16
  export function toUint8Array(encoder: Encoder): Uint8Array<ArrayBuffer>;
@@ -56,13 +56,13 @@ export function writeAny(encoder: Encoder, data: AnyEncodable): void;
56
56
  */
57
57
  export class RleEncoder<T> extends Encoder {
58
58
  /**
59
- * @param {function(Encoder, T):void} writer
59
+ * @param {(encoder: Encoder, value: T) => void} writer
60
60
  */
61
- constructor(writer: (arg0: Encoder, arg1: T) => void);
61
+ constructor(writer: (encoder: Encoder, value: T) => void);
62
62
  /**
63
63
  * The writer
64
64
  */
65
- w: (arg0: Encoder, arg1: T) => void;
65
+ w: (encoder: Encoder, value: T) => void;
66
66
  /**
67
67
  * Current state
68
68
  * @type {T|null}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Environment detection primitives shared by `environment.js` and `storage.js`.
3
+ *
4
+ * Internal module (not exported in `package.json`) — it exists so that `storage.js` can check
5
+ * `isBrowser` without importing `environment.js`, which imports `storage.js` (circular import).
6
+ */
7
+ export const isNode: boolean;
8
+ /**
9
+ * True iff this script is running in deno
10
+ * @type {boolean}
11
+ */
12
+ export const isDeno: boolean;
13
+ export const globalScope: any;
14
+ /**
15
+ * True iff this script is running in a browser-family environment — either a DOM main
16
+ * thread (`window` + `document`) or a WebWorker / ServiceWorker (a `WorkerGlobalScope`,
17
+ * which has `btoa`/`atob`/`fetch` but no DOM). Excludes Node and Deno.
18
+ * @type {boolean}
19
+ */
20
+ export const isBrowser: boolean;
21
+ //# sourceMappingURL=environment.common.d.ts.map
@@ -1,10 +1,3 @@
1
- export const isNode: boolean;
2
- /**
3
- * True iff this script is running in deno
4
- * @type {boolean}
5
- */
6
- export const isDeno: boolean;
7
- export const isBrowser: boolean;
8
1
  export const isMac: boolean;
9
2
  /**
10
3
  * True iff a DOM is available — either a real browser, or Node with a jsdom shim installed (see
@@ -27,5 +20,6 @@ export const production: boolean;
27
20
  */
28
21
  export const supportsColor: boolean;
29
22
  export { globalScope as global };
30
- declare const globalScope: any;
23
+ import { globalScope } from './environment.common.js';
24
+ export { isNode, isDeno, isBrowser } from "./environment.common.js";
31
25
  //# sourceMappingURL=environment.d.ts.map
package/dist/error.d.ts CHANGED
@@ -1,5 +1,23 @@
1
1
  export function create(s: string): Error;
2
- export function methodUnimplemented(): never;
3
- export function unexpectedCase(): never;
4
- export function assert(property: boolean): asserts property is true;
2
+ /**
3
+ * `@type` (not `@param`/`@return`) is required for the `never` return to affect control-flow
4
+ * analysis — a call to a never-returning function only terminates a code path if the callee is
5
+ * declared with an explicit type annotation.
6
+ *
7
+ * @throws {Error}
8
+ * @type {() => never}
9
+ */
10
+ export const methodUnimplemented: () => never;
11
+ /**
12
+ * @throws {Error}
13
+ * @type {() => never}
14
+ */
15
+ export const unexpectedCase: () => never;
16
+ /**
17
+ * `@type` (not `@param`/`@return`) is required — an assertion signature only narrows if the
18
+ * callee is declared with an explicit type annotation.
19
+ *
20
+ * @type {(property: boolean) => asserts property is true}
21
+ */
22
+ export const assert: (property: boolean) => asserts property is true;
5
23
  //# sourceMappingURL=error.d.ts.map
@@ -7,7 +7,7 @@ export const Animation: {
7
7
  destroy(): void;
8
8
  };
9
9
  };
10
- export function animationFrame(cb: (arg0: number) => void): TimeoutObject;
10
+ export function animationFrame(cb: (timestamp: number) => void): TimeoutObject;
11
11
  export function idleCallback(cb: Function): TimeoutObject;
12
12
  export function createDebouncer(timeout: number, triggerAfter?: number): (cb: ((...args: any) => void) | null) => void;
13
13
  export type TimeoutObject = {
@@ -1,5 +1,5 @@
1
1
  export function rtop(request: IDBRequest): Promise<any>;
2
- export function openDB(name: string, initDB: (arg0: IDBDatabase) => any): Promise<IDBDatabase>;
2
+ export function openDB(name: string, initDB: (db: IDBDatabase) => any): Promise<IDBDatabase>;
3
3
  export function deleteDB(name: string): Promise<any>;
4
4
  export function createStores(db: IDBDatabase, definitions: Array<Array<string> | Array<string | IDBObjectStoreParameters | undefined>>): void;
5
5
  export function transact(db: IDBDatabase, stores: Array<string>, access?: "readwrite" | "readonly"): Array<IDBObjectStore>;
@@ -15,8 +15,8 @@ export function queryFirst(store: IDBObjectStore, query: IDBKeyRange | null, dir
15
15
  export function getLastKey(store: IDBObjectStore, range?: IDBKeyRange | null): Promise<any>;
16
16
  export function getFirstKey(store: IDBObjectStore, range?: IDBKeyRange | null): Promise<any>;
17
17
  export function getAllKeysValues(store: IDBObjectStore, range?: IDBKeyRange, limit?: number): Promise<Array<KeyValuePair>>;
18
- export function iterate(store: IDBObjectStore, keyrange: IDBKeyRange | null, f: (arg0: any, arg1: any) => void | boolean | Promise<void | boolean>, direction?: "next" | "prev" | "nextunique" | "prevunique"): Promise<void>;
19
- export function iterateKeys(store: IDBObjectStore, keyrange: IDBKeyRange | null, f: (arg0: any) => void | boolean | Promise<void | boolean>, direction?: "next" | "prev" | "nextunique" | "prevunique"): Promise<void>;
18
+ export function iterate(store: IDBObjectStore, keyrange: IDBKeyRange | null, f: (value: any, key: any) => void | boolean | Promise<void | boolean>, direction?: "next" | "prev" | "nextunique" | "prevunique"): Promise<void>;
19
+ export function iterateKeys(store: IDBObjectStore, keyrange: IDBKeyRange | null, f: (key: any) => void | boolean | Promise<void | boolean>, direction?: "next" | "prev" | "nextunique" | "prevunique"): Promise<void>;
20
20
  export function getStore(t: IDBTransaction, store: string): IDBObjectStore;
21
21
  export function createIDBKeyRangeBound(lower: any, upper: any, lowerOpen: boolean, upperOpen: boolean): IDBKeyRange;
22
22
  export function createIDBKeyRangeUpperBound(upper: any, upperOpen: boolean): IDBKeyRange;
@@ -1,5 +1,5 @@
1
1
  export function bindPledge(p: pledge.PledgeInstance<any>, request: IDBRequest): void;
2
- export function openDB(name: string, initDB: (arg0: IDBDatabase) => any): pledge.PledgeInstance<IDBDatabase>;
2
+ export function openDB(name: string, initDB: (db: IDBDatabase) => any): pledge.PledgeInstance<IDBDatabase>;
3
3
  export function deleteDB(name: pledge.Pledge<string>): pledge.PledgeInstance<void>;
4
4
  export function createStores(db: IDBDatabase, definitions: Array<Array<string> | Array<string | IDBObjectStoreParameters | undefined>>): void;
5
5
  export function transact(db: pledge.Pledge<IDBDatabase>, stores: pledge.Pledge<Array<string>>, access?: "readwrite" | "readonly"): pledge.Pledge<Array<IDBObjectStore>>;
@@ -15,8 +15,8 @@ export function queryFirst(store: IDBObjectStore, query: IDBKeyRange | null, dir
15
15
  export function getLastKey(store: IDBObjectStore, range?: IDBKeyRange | null): pledge.PledgeInstance<any>;
16
16
  export function getFirstKey(store: IDBObjectStore, range?: IDBKeyRange | null): pledge.PledgeInstance<any>;
17
17
  export function getAllKeysValues(store: pledge.Pledge<IDBObjectStore>, range?: pledge.Pledge<IDBKeyRange | undefined>, limit?: pledge.Pledge<number | undefined>): pledge.PledgeInstance<Array<KeyValuePair>>;
18
- export function iterate(store: pledge.Pledge<IDBObjectStore>, keyrange: pledge.Pledge<IDBKeyRange | null>, f: (arg0: any, arg1: any) => void | boolean | Promise<void | boolean>, direction?: "next" | "prev" | "nextunique" | "prevunique"): pledge.PledgeInstance<any, Error>;
19
- export function iterateKeys(store: pledge.Pledge<IDBObjectStore>, keyrange: pledge.Pledge<IDBKeyRange | null>, f: (arg0: any) => void | boolean | Promise<void | boolean>, direction?: "next" | "prev" | "nextunique" | "prevunique"): pledge.PledgeInstance<any, Error>;
18
+ export function iterate(store: pledge.Pledge<IDBObjectStore>, keyrange: pledge.Pledge<IDBKeyRange | null>, f: (value: any, key: any) => void | boolean | Promise<void | boolean>, direction?: "next" | "prev" | "nextunique" | "prevunique"): pledge.PledgeInstance<any, Error>;
19
+ export function iterateKeys(store: pledge.Pledge<IDBObjectStore>, keyrange: pledge.Pledge<IDBKeyRange | null>, f: (key: any) => void | boolean | Promise<void | boolean>, direction?: "next" | "prev" | "nextunique" | "prevunique"): pledge.PledgeInstance<any, Error>;
20
20
  export function getStore(t: IDBTransaction, store: string): IDBObjectStore;
21
21
  export function createIDBKeyRangeBound(lower: any, upper: any, lowerOpen: boolean, upperOpen: boolean): IDBKeyRange;
22
22
  export function createIDBKeyRangeUpperBound(upper: any, upperOpen: boolean): IDBKeyRange;
@@ -1,5 +1,5 @@
1
- export function mapIterator<T, R>(iterator: Iterator<T>, f: (arg0: T) => R): IterableIterator<R>;
1
+ export function mapIterator<T, R>(iterator: Iterator<T>, f: (v: T) => R): IterableIterator<R>;
2
2
  export function createIterator<T>(next: () => IteratorResult<T>): IterableIterator<T>;
3
- export function iteratorFilter<T>(iterator: Iterator<T>, filter: (arg0: T) => boolean): IterableIterator<T>;
4
- export function iteratorMap<T, M>(iterator: Iterator<T>, fmap: (arg0: T) => M): IterableIterator<M | undefined>;
3
+ export function iteratorFilter<T>(iterator: Iterator<T>, filter: (v: T) => boolean): IterableIterator<T>;
4
+ export function iteratorMap<T, M>(iterator: Iterator<T>, fmap: (v: T) => M): IterableIterator<M | undefined>;
5
5
  //# sourceMappingURL=iterator.d.ts.map
package/dist/list.d.ts CHANGED
@@ -23,15 +23,15 @@ export class List<N extends ListNode> {
23
23
  len: number;
24
24
  toArray(): N[];
25
25
  /**
26
- * @param {function(N):any} f
26
+ * @param {(node: N) => any} f
27
27
  */
28
- forEach(f: (arg0: N) => any): void;
28
+ forEach(f: (node: N) => any): void;
29
29
  /**
30
30
  * @template M
31
- * @param {function(N):M} f
31
+ * @param {(node: N) => M} f
32
32
  * @return {Array<M>}
33
33
  */
34
- map<M>(f: (arg0: N) => M): Array<M>;
34
+ map<M>(f: (node: N) => M): Array<M>;
35
35
  [Symbol.iterator](): Generator<N, void, unknown>;
36
36
  /**
37
37
  * @param {List<any>} other
@@ -48,8 +48,8 @@ export function pushEnd<N extends ListNode>(queue: List<N>, n: N): void;
48
48
  export function pushFront<N extends ListNode>(queue: List<N>, n: N): void;
49
49
  export function popFront<N extends ListNode>(list: List<N>): N | null;
50
50
  export function popEnd<N extends ListNode>(list: List<N>): N | null;
51
- export function map<N extends ListNode, M>(list: List<N>, f: (arg0: N) => M): Array<M>;
51
+ export function map<N extends ListNode, M>(list: List<N>, f: (node: N) => M): Array<M>;
52
52
  export function toArray<N extends ListNode>(list: List<N>): N[];
53
- export function forEach<N extends ListNode>(list: List<N>, f: (arg0: N) => any): void;
53
+ export function forEach<N extends ListNode>(list: List<N>, f: (node: N) => any): void;
54
54
  import * as equalityTrait from './trait/equality.js';
55
55
  //# sourceMappingURL=list.d.ts.map
@@ -8,5 +8,5 @@ export const PURPLE: symbol;
8
8
  export const ORANGE: symbol;
9
9
  export const UNCOLOR: symbol;
10
10
  export function computeNoColorLoggingArgs(args: Array<undefined | string | Symbol | Object | number | (() => any)>): Array<string | object | number | undefined>;
11
- export function createModuleLogger(_print: (...args: any[]) => void, moduleName: string): (...args: any[]) => void;
11
+ export function createModuleLogger(_print: (...args: Array<any>) => void, moduleName: string): (...args: Array<any>) => void;
12
12
  //# sourceMappingURL=logging.common.d.ts.map
package/dist/logging.d.ts CHANGED
@@ -50,6 +50,6 @@ export class VConsole {
50
50
  destroy(): void;
51
51
  }
52
52
  export function createVConsole(dom: Element): VConsole;
53
- export function createModuleLogger(moduleName: string): (...args: any[]) => void;
53
+ export function createModuleLogger(moduleName: string): (...args: Array<any>) => void;
54
54
  export { BOLD, UNBOLD, BLUE, GREY, GREEN, RED, PURPLE, ORANGE, UNCOLOR } from "./logging.common.js";
55
55
  //# sourceMappingURL=logging.d.ts.map
@@ -9,6 +9,6 @@ export function groupEnd(): void;
9
9
  export function printDom(_createNode: () => Node): void;
10
10
  export function printCanvas(canvas: HTMLCanvasElement, height: number): void;
11
11
  export function createVConsole(_dom: Element): void;
12
- export function createModuleLogger(moduleName: string): (...args: any[]) => void;
12
+ export function createModuleLogger(moduleName: string): (...args: Array<any>) => void;
13
13
  export { BOLD, UNBOLD, BLUE, GREY, GREEN, RED, PURPLE, ORANGE, UNCOLOR } from "./logging.common.js";
14
14
  //# sourceMappingURL=logging.node.d.ts.map
package/dist/map.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export function create(): Map<any, any>;
2
2
  export function copy<K, V>(m: Map<K, V>): Map<K, V>;
3
- export function setIfUndefined<MAP extends Map<any, any>, CF extends MAP extends Map<any, infer V> ? () => V : unknown>(map: MAP, key: MAP extends Map<infer K, any> ? K : unknown, createT: CF): ReturnType<CF>;
4
- export function map<K, V, R>(m: Map<K, V>, f: (arg0: V, arg1: K) => R): Array<R>;
5
- export function any<K, V>(m: Map<K, V>, f: (arg0: V, arg1: K) => boolean): boolean;
6
- export function all<K, V>(m: Map<K, V>, f: (arg0: V, arg1: K) => boolean): boolean;
3
+ export function setIfUndefined<MAP extends Map<any, any>, CF extends MAP extends Map<any, infer V> ? (() => V) : unknown>(map: MAP, key: MAP extends Map<infer K, any> ? K : unknown, createT: CF): ReturnType<CF>;
4
+ export function map<K, V, R>(m: Map<K, V>, f: (value: V, key: K) => R): Array<R>;
5
+ export function any<K, V>(m: Map<K, V>, f: (value: V, key: K) => boolean): boolean;
6
+ export function all<K, V>(m: Map<K, V>, f: (value: V, key: K) => boolean): boolean;
7
7
  export type GlobalMap<K, V> = Map<K, V>;
8
8
  //# sourceMappingURL=map.d.ts.map
package/dist/object.d.ts CHANGED
@@ -33,10 +33,10 @@ export const values: {
33
33
  };
34
34
  export function forEach<V_1>(obj: {
35
35
  [k: string]: V_1;
36
- }, f: (arg0: V_1, arg1: string) => any): void;
36
+ }, f: (value: V_1, key: string) => any): void;
37
37
  export function map<R>(obj: {
38
38
  [x: string]: any;
39
- }, f: (arg0: any, arg1: string) => R): Array<R>;
39
+ }, f: (value: any, key: string) => R): Array<R>;
40
40
  export function length(obj: {
41
41
  [x: string]: any;
42
42
  }): number;
@@ -5,9 +5,9 @@
5
5
  * This is basically a (better typed) duplicate of Observable, which will replace Observable in the
6
6
  * next release.
7
7
  *
8
- * @template {{[key in keyof EVENTS]: function(...any):void}} EVENTS
8
+ * @template {{[key in keyof EVENTS]: (...args: Array<any>) => void}} EVENTS
9
9
  */
10
- export class ObservableV2<EVENTS extends { [key in keyof EVENTS]: (...args: any[]) => void; }> {
10
+ export class ObservableV2<EVENTS extends { [key in keyof EVENTS]: (...args: Array<any>) => void; }> {
11
11
  /**
12
12
  * Some desc.
13
13
  * @type {Map<string, Set<any>>}
package/dist/pair.d.ts CHANGED
@@ -17,6 +17,6 @@ export class Pair<L, R> {
17
17
  }
18
18
  export function create<L, R>(left: L, right: R): Pair<L, R>;
19
19
  export function createReversed<L, R>(right: R, left: L): Pair<L, R>;
20
- export function forEach<L, R>(arr: Array<Pair<L, R>>, f: (arg0: L, arg1: R) => any): void;
21
- export function map<L, R, X>(arr: Array<Pair<L, R>>, f: (arg0: L, arg1: R) => X): Array<X>;
20
+ export function forEach<L, R>(arr: Array<Pair<L, R>>, f: (left: L, right: R) => any): void;
21
+ export function map<L, R, X>(arr: Array<Pair<L, R>>, f: (left: L, right: R) => X): Array<X>;
22
22
  //# sourceMappingURL=pair.d.ts.map
package/dist/pledge.d.ts CHANGED
@@ -13,13 +13,13 @@ export class PledgeInstance<Val extends unknown, CancelReason extends unknown =
13
13
  _v: Val | CancelReason | null;
14
14
  isResolved: boolean;
15
15
  /**
16
- * @type {Array<function(Val):void> | null}
16
+ * @type {Array<(val: Val) => void> | null}
17
17
  */
18
- _whenResolved: Array<(arg0: Val) => void> | null;
18
+ _whenResolved: Array<(val: Val) => void> | null;
19
19
  /**
20
- * @type {Array<function(CancelReason):void> | null}
20
+ * @type {Array<(reason: CancelReason) => void> | null}
21
21
  */
22
- _whenCanceled: Array<(arg0: CancelReason) => void> | null;
22
+ _whenCanceled: Array<(reason: CancelReason) => void> | null;
23
23
  get isDone(): boolean;
24
24
  get isCanceled(): boolean;
25
25
  /**
@@ -32,14 +32,14 @@ export class PledgeInstance<Val extends unknown, CancelReason extends unknown =
32
32
  cancel(reason: CancelReason): void;
33
33
  /**
34
34
  * @template R
35
- * @param {function(Val):Pledge<R>} f
35
+ * @param {(val: Val) => Pledge<R>} f
36
36
  * @return {PledgeInstance<R>}
37
37
  */
38
- map<R>(f: (arg0: Val) => Pledge<R>): PledgeInstance<R>;
38
+ map<R>(f: (val: Val) => Pledge<R>): PledgeInstance<R>;
39
39
  /**
40
- * @param {function(Val):void} f
40
+ * @param {(val: Val) => void} f
41
41
  */
42
- whenResolved(f: (arg0: Val) => void): void;
42
+ whenResolved(f: (val: Val) => void): void;
43
43
  /**
44
44
  * @param {(reason: CancelReason) => void} f
45
45
  */
@@ -51,8 +51,8 @@ export class PledgeInstance<Val extends unknown, CancelReason extends unknown =
51
51
  }
52
52
  export function create<T>(): PledgeInstance<T>;
53
53
  export function createWithDependencies<V, DEPS extends Array<Pledge<unknown>>>(init: (p: PledgeInstance<V>, ...deps: Resolved<DEPS>) => void, ...deps: DEPS): PledgeInstance<V>;
54
- export function whenResolved<R>(p: Pledge<R>, f: (arg0: R) => void): void;
55
- export function whenCanceled<P extends Pledge<unknown>>(p: P, f: P extends PledgeInstance<unknown, infer CancelReason> ? (arg0: CancelReason) => void : (arg0: any) => void): void;
54
+ export function whenResolved<R>(p: Pledge<R>, f: (res: R) => void): void;
55
+ export function whenCanceled<P extends Pledge<unknown>>(p: P, f: P extends PledgeInstance<unknown, infer CancelReason> ? ((reason: CancelReason) => void) : ((reason: any) => void)): void;
56
56
  export function map<P, Q>(p: Pledge<P>, f: (r: P) => Q): Pledge<Q>;
57
57
  export function all<PS extends PledgeMap>(ps: PS): PledgeInstance<Resolved<PS>>;
58
58
  export function coroutine<Result, YieldResults extends unknown>(f: () => Generator<Pledge<YieldResults> | PledgeInstance<YieldResults, any>, Result, any>): PledgeInstance<Result>;
package/dist/promise.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export function create<T>(f: (arg0: PromiseResolve<T>, arg1: (arg0: Error) => void) => any): Promise<T>;
2
- export function createEmpty(f: (arg0: () => void, arg1: (arg0: Error) => void) => void): Promise<void>;
1
+ export function create<T>(f: (resolve: PromiseResolve<T>, reject: (err: Error) => void) => any): Promise<T>;
2
+ export function createEmpty(f: (resolve: () => void, reject: (err: Error) => void) => void): Promise<void>;
3
3
  /**
4
4
  * `Promise.all` wait for all promises in the array to resolve and return the result
5
5
  * @template {unknown[] | []} PS
package/dist/schema.d.ts CHANGED
@@ -125,7 +125,7 @@ export class Schema<T> implements equalityTraits.EqualityTrait {
125
125
  * Can be useful when defining lambdas: `s.lambda(s.$number, s.$number).expect((n) => n + 1)`
126
126
  *
127
127
  * @param {T} o
128
- * @return {o extends T ? T : never}
128
+ * @return {T extends T ? T : never}
129
129
  */
130
130
  expect(o: T): T extends T ? T : never;
131
131
  $type: Schema<Schema<any>>;
@@ -564,6 +564,13 @@ export class PatternMatcher<State extends unknown = undefined, Patterns extends
564
564
  }
565
565
  export function match<State = undefined>(state?: State): PatternMatcher<State extends undefined ? undefined : ReadSchemaUnwrapped<State>>;
566
566
  export function random<S>(gen: prng.PRNG, schema: S, fallback?: (gen: prng.PRNG, o: Schema<any>) => any): ReadSchemaUnwrapped<S>;
567
+ export function coerce<S extends Schema<any>>(schema: S): (o: any) => {
568
+ err: string;
569
+ result: null;
570
+ } | {
571
+ err: null;
572
+ result: Unwrap<S>;
573
+ };
567
574
  export type Primitive = string | number | bigint | boolean | null | undefined | symbol;
568
575
  export type AnyObject = {
569
576
  [k: string | number | symbol]: any;
@@ -593,6 +600,17 @@ export type Pattern<In, Out> = {
593
600
  h: (o: In, state?: any) => Out;
594
601
  };
595
602
  export type PatternMatcherFn<Ps extends Pattern<any, any>, S> = import("./ts.js").UnionToIntersection<Ps extends Pattern<infer In, infer Out> ? [S] extends [undefined] ? (o: In) => Out : (o: In, state: S) => Out : never> & ([S] extends [undefined] ? (o: Ps extends Pattern<infer In, any> ? In : never) => (Ps extends Pattern<any, infer Out> ? Out : never) : (o: Ps extends Pattern<infer In, any> ? In : never, state: S) => (Ps extends Pattern<any, infer Out> ? Out : never));
603
+ /**
604
+ * Carries the reason of a failed coercion out of the recursion.
605
+ */
606
+ export type _CoerceCtx = {
607
+ err: string;
608
+ };
609
+ /**
610
+ * A compiled coercer. Returns the coerced value, or `_failed` after writing the reason to
611
+ * `ctx.err`.
612
+ */
613
+ export type _Coercer = (o: any, path: string, ctx: _CoerceCtx) => any;
596
614
  import * as equalityTraits from './trait/equality.js';
597
615
  /**
598
616
  * @extends Schema<never>
package/dist/sort.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export function _insertionSort<T>(arr: Array<T>, lo: number, hi: number, compare: (arg0: T, arg1: T) => number): void;
2
- export function insertionSort<T>(arr: Array<T>, compare: (arg0: T, arg1: T) => number): void;
3
- export function quicksort<T>(arr: Array<T>, compare: (arg0: T, arg1: T) => number): void;
1
+ export function _insertionSort<T>(arr: Array<T>, lo: number, hi: number, compare: (a: T, b: T) => number): void;
2
+ export function insertionSort<T>(arr: Array<T>, compare: (a: T, b: T) => number): void;
3
+ export function quicksort<T>(arr: Array<T>, compare: (a: T, b: T) => number): void;
4
4
  //# sourceMappingURL=sort.d.ts.map
package/dist/storage.d.ts CHANGED
@@ -2,12 +2,12 @@
2
2
  * This is basically localStorage in browser, or a polyfill in nodejs
3
3
  */
4
4
  export const varStorage: any;
5
- export function onChange(eventHandler: (arg0: {
5
+ export function onChange(eventHandler: (e: {
6
6
  key: string;
7
7
  newValue: string;
8
8
  oldValue: string;
9
9
  }) => void): true | void;
10
- export function offChange(eventHandler: (arg0: {
10
+ export function offChange(eventHandler: (e: {
11
11
  key: string;
12
12
  newValue: string;
13
13
  oldValue: string;