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.
- package/dist/array.d.ts +4 -4
- package/dist/broadcastchannel.d.ts +3 -3
- package/dist/decoding.d.ts +3 -3
- package/dist/delta/delta.d.ts +0 -8
- package/dist/delta/rdt/dom.d.ts +19 -25
- package/dist/delta/rdt.d.ts +24 -0
- package/dist/diff.d.ts +1 -1
- package/dist/encoding.d.ts +4 -4
- package/dist/environment.common.d.ts +21 -0
- package/dist/environment.d.ts +2 -8
- package/dist/error.d.ts +21 -3
- package/dist/eventloop.d.ts +1 -1
- package/dist/indexeddb.d.ts +3 -3
- package/dist/indexeddbV2.d.ts +3 -3
- package/dist/iterator.d.ts +3 -3
- package/dist/list.d.ts +6 -6
- package/dist/logging.common.d.ts +1 -1
- package/dist/logging.d.ts +1 -1
- package/dist/logging.node.d.ts +1 -1
- package/dist/map.d.ts +4 -4
- package/dist/object.d.ts +2 -2
- package/dist/observable.d.ts +2 -2
- package/dist/pair.d.ts +2 -2
- package/dist/pledge.d.ts +10 -10
- package/dist/promise.d.ts +2 -2
- package/dist/schema.d.ts +19 -1
- package/dist/sort.d.ts +3 -3
- package/dist/storage.d.ts +2 -2
- package/dist/testing.d.ts +18 -11
- package/package.json +3 -3
- package/src/array.js +5 -5
- package/src/broadcastchannel.js +4 -4
- package/src/cache.js +1 -1
- package/src/decoding.js +2 -2
- package/src/delta/delta.js +13 -26
- package/src/delta/rdt/dom.js +176 -63
- package/src/delta/rdt.js +39 -10
- package/src/diff.js +1 -1
- package/src/encoding.js +2 -2
- package/src/environment.common.js +41 -0
- package/src/environment.js +2 -21
- package/src/error.js +10 -4
- package/src/eventloop.js +3 -3
- package/src/function.js +1 -1
- package/src/indexeddb.js +4 -4
- package/src/indexeddbV2.js +4 -4
- package/src/iterator.js +4 -4
- package/src/list.js +4 -4
- package/src/logging.common.js +3 -3
- package/src/logging.js +3 -3
- package/src/logging.node.js +3 -3
- package/src/map.js +4 -4
- package/src/mutex.js +2 -2
- package/src/object.js +2 -2
- package/src/observable.js +1 -1
- package/src/pair.js +2 -2
- package/src/pledge.js +6 -6
- package/src/promise.js +3 -3
- package/src/schema.js +316 -3
- package/src/sort.js +4 -4
- package/src/storage.js +8 -4
- package/src/testing.js +15 -15
package/src/delta/rdt.js
CHANGED
|
@@ -25,7 +25,9 @@
|
|
|
25
25
|
* back as a fresh change on its side. A fix on one side and a fix on the other are concurrent, so they
|
|
26
26
|
* are rebased against each other: the pending pair `{ a, b }` is run through `transformer.apply`, whose
|
|
27
27
|
* machinery already transposes the two sides. This repeats until neither side reports a fix, so fixes
|
|
28
|
-
* must converge to a fixpoint (a well-behaved RDT applies them idempotently).
|
|
28
|
+
* must converge to a fixpoint (a well-behaved RDT applies them idempotently). All of this fix traffic
|
|
29
|
+
* is applied with the {@link correctionOrigin} origin, while an ordinary mapped change carries the binding
|
|
30
|
+
* itself — see the "Origins" section of {@link RDT}.
|
|
29
31
|
*
|
|
30
32
|
* On creation a binding first **synchronizes the initial state**: `a`'s current state (`a.delta`)
|
|
31
33
|
* is projected through the transformer, and the projection is diffed against `b`'s current state
|
|
@@ -87,6 +89,12 @@ export { $domDelta, domRDT } from './rdt/dom.js'
|
|
|
87
89
|
* it just received. The `origin` argument to `applyDelta` is optional and defaults to `null` (an
|
|
88
90
|
* anonymous/local change); the emitted event always carries whatever value was supplied.
|
|
89
91
|
*
|
|
92
|
+
* A {@link Binding} distinguishes the two kinds of changes it produces. An ordinary change mapped
|
|
93
|
+
* over from the other side carries the binding itself as its origin. A change that adjusts a side's
|
|
94
|
+
* own earlier change after the fact — a fix returned by the opposite RDT transformed back, or a
|
|
95
|
+
* transformer self-heal — carries {@link correctionOrigin}, so a consumer that applied a delta can recognise
|
|
96
|
+
* that (part of) its change was reverted or amended.
|
|
97
|
+
*
|
|
90
98
|
* ## `Delta` vs `DeltaBuilder`
|
|
91
99
|
*
|
|
92
100
|
* The interface is parameterized by a {@link import('./delta.js').DeltaConf DeltaConf} (like a
|
|
@@ -124,15 +132,30 @@ export const $rdt = /** @type {Schema<RDT<any>>} */ (/* @__PURE__ */ s.$custom(o
|
|
|
124
132
|
typeof o.destroy === 'function'
|
|
125
133
|
))
|
|
126
134
|
|
|
135
|
+
/**
|
|
136
|
+
* The {@link RDT origin} carried by every change a {@link Binding} applies as an after-the-fact
|
|
137
|
+
* adjustment to a side's own change: a fix returned by the opposite RDT's `applyDelta` transformed back
|
|
138
|
+
* onto the side that produced the original change, a transformer self-heal (including during the
|
|
139
|
+
* initial-state sync), and every later round of the fix-convergence loop (fixes of fixes). A "fix"
|
|
140
|
+
* covers invariant corrections as well as rebased concurrent edits (see `./rdt/dom.js`). An ordinary
|
|
141
|
+
* mapped change carries the binding itself instead — see the "Origins" section of {@link RDT}. The
|
|
142
|
+
* value is a plain string, so `origin === 'correction'` works without importing this constant.
|
|
143
|
+
*
|
|
144
|
+
* @type {'correction'}
|
|
145
|
+
*/
|
|
146
|
+
export const correctionOrigin = 'correction'
|
|
147
|
+
|
|
127
148
|
/**
|
|
128
149
|
* Propagate a pair of concurrent changes between the two sides of `binding` until they converge.
|
|
129
150
|
*
|
|
130
151
|
* `ta` / `tb` are changes that have ALREADY been applied to `a` / `b` (an incoming `'delta'`, or a fix
|
|
131
152
|
* returned by a previous `applyDelta`). Each is mapped onto the other side via the transformer —
|
|
132
153
|
* `apply` rebases the two against each other — and the mapped results are applied, which may yield
|
|
133
|
-
* further RDT fixes. We repeat until neither side reports a fix.
|
|
134
|
-
*
|
|
135
|
-
* produced the
|
|
154
|
+
* further RDT fixes. We repeat until neither side reports a fix. `aOrigin` / `bOrigin` are the
|
|
155
|
+
* {@link RDT origins} for the first round's applications: the side receiving the ordinary mapped
|
|
156
|
+
* change is handed the `binding` itself, while the side that produced the triggering change only ever
|
|
157
|
+
* receives adjustments (a transformer self-heal), tagged {@link correctionOrigin}. After the first round
|
|
158
|
+
* every applied change derives from a fix, so both origins become {@link correctionOrigin}.
|
|
136
159
|
*
|
|
137
160
|
* `ta`/`tb` are shared read deltas (an event payload, or a fix that was also written into the producing
|
|
138
161
|
* RDT's state), so they are {@link delta.cloneDeep deep-cloned} into private builders before the
|
|
@@ -143,15 +166,19 @@ export const $rdt = /** @type {Schema<RDT<any>>} */ (/* @__PURE__ */ s.$custom(o
|
|
|
143
166
|
* @param {Binding<A,B>} binding
|
|
144
167
|
* @param {any} ta change already applied on `a` — a shared read delta (event payload or a fix), or `null`
|
|
145
168
|
* @param {any} tb change already applied on `b` — a shared read delta (event payload or a fix), or `null`
|
|
169
|
+
* @param {any} [aOrigin] origin for the first-round application onto `a`; defaults to {@link correctionOrigin}
|
|
170
|
+
* @param {any} [bOrigin] origin for the first-round application onto `b`; defaults to {@link correctionOrigin}
|
|
146
171
|
*/
|
|
147
|
-
const propagate = (binding, ta, tb) => {
|
|
172
|
+
const propagate = (binding, ta, tb, aOrigin = correctionOrigin, bOrigin = correctionOrigin) => {
|
|
148
173
|
while ((ta != null && !ta.isEmpty()) || (tb != null && !tb.isEmpty())) {
|
|
149
174
|
const tres = binding.t.apply(dt.createTransformResult(
|
|
150
175
|
ta != null ? delta.cloneDeep(ta) : null,
|
|
151
176
|
tb != null ? delta.cloneDeep(tb) : null
|
|
152
177
|
))
|
|
153
|
-
ta = tres.a != null ? binding.a.applyDelta(tres.a,
|
|
154
|
-
tb = tres.b != null ? binding.b.applyDelta(tres.b,
|
|
178
|
+
ta = tres.a != null ? binding.a.applyDelta(tres.a, aOrigin) : null
|
|
179
|
+
tb = tres.b != null ? binding.b.applyDelta(tres.b, bOrigin) : null
|
|
180
|
+
aOrigin = correctionOrigin
|
|
181
|
+
bOrigin = correctionOrigin
|
|
155
182
|
}
|
|
156
183
|
}
|
|
157
184
|
|
|
@@ -197,14 +224,16 @@ export class Binding {
|
|
|
197
224
|
*/
|
|
198
225
|
this.b = b
|
|
199
226
|
this._mux = mux.createMutex()
|
|
200
|
-
this._achanged = this.a.on('delta', d => this._mux(() => propagate(this, d, null)))
|
|
201
|
-
this._bchanged = this.b.on('delta', d => this._mux(() => propagate(this, null, d)))
|
|
227
|
+
this._achanged = this.a.on('delta', d => this._mux(() => propagate(this, d, null, correctionOrigin, this)))
|
|
228
|
+
this._bchanged = this.b.on('delta', d => this._mux(() => propagate(this, null, d, this, correctionOrigin)))
|
|
202
229
|
this.a.on('destroy', this.destroy)
|
|
203
230
|
this.b.on('destroy', this.destroy)
|
|
204
231
|
// Sync the initial state. `a` is the source of truth: project its current state through the
|
|
205
232
|
// transformer (`applyA`) — which also yields any self-heal correction for `a` (`tres.a`) — then
|
|
206
233
|
// diff the projection against `b`'s current state and apply the difference so `b` ends up
|
|
207
234
|
// matching `a`'s projection. Any fixes the two sides report are reconciled via `propagate`.
|
|
235
|
+
// The self-heal onto `a` adjusts a's own state, so it is a `correction`; the diff onto `b` is an
|
|
236
|
+
// ordinary binding-produced change.
|
|
208
237
|
// NOTE: `delta.diff` is content-only (it excludes marks), so cursor marks present on `a` at bind
|
|
209
238
|
// time are NOT transferred to `b` here; marks ride only on subsequent live `applyA`/`applyB`.
|
|
210
239
|
// Wrapped in the mutex so these `applyDelta` calls don't echo back through the listeners above.
|
|
@@ -214,7 +243,7 @@ export class Binding {
|
|
|
214
243
|
// transformer — which rebases its input in place — projects it. A shallow `clone` would still share
|
|
215
244
|
// those frozen children and corrupt / fail on the live state (see `delta.cloneDeep`).
|
|
216
245
|
const tres = this.t.applyA(delta.cloneDeep(this.a.delta))
|
|
217
|
-
const fa = tres.a ? this.a.applyDelta(tres.a,
|
|
246
|
+
const fa = tres.a ? this.a.applyDelta(tres.a, correctionOrigin) : null
|
|
218
247
|
// `diff` shares nested children with `tres.b` by default, and `tres.b` is a (possibly stateful)
|
|
219
248
|
// transformer's output that may still alias its internal state — so `clone` keeps the diff
|
|
220
249
|
// independent, since it is then applied into `b` (which freezes it) and propagated onward.
|
package/src/diff.js
CHANGED
|
@@ -77,7 +77,7 @@ export const simpleDiff = simpleDiffString
|
|
|
77
77
|
*
|
|
78
78
|
* @param {Array<T>} a The old version of the array
|
|
79
79
|
* @param {Array<T>} b The updated version of the array
|
|
80
|
-
* @param {
|
|
80
|
+
* @param {(a: T, b: T) => boolean} [compare]
|
|
81
81
|
* @return {SimpleDiff<Array<T>>} The diff description.
|
|
82
82
|
*/
|
|
83
83
|
export const simpleDiffArray = (a, b, compare = equalityStrict) => {
|
package/src/encoding.js
CHANGED
|
@@ -53,7 +53,7 @@ export class Encoder {
|
|
|
53
53
|
export const createEncoder = () => new Encoder()
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* @param {
|
|
56
|
+
* @param {(encoder: Encoder) => void} f
|
|
57
57
|
*/
|
|
58
58
|
export const encode = (f) => {
|
|
59
59
|
const encoder = createEncoder()
|
|
@@ -622,7 +622,7 @@ export const writeAny = (encoder, data) => {
|
|
|
622
622
|
*/
|
|
623
623
|
export class RleEncoder extends Encoder {
|
|
624
624
|
/**
|
|
625
|
-
* @param {
|
|
625
|
+
* @param {(encoder: Encoder, value: T) => void} writer
|
|
626
626
|
*/
|
|
627
627
|
constructor (writer) {
|
|
628
628
|
super()
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
|
|
8
|
+
/* c8 ignore next */
|
|
9
|
+
export const isNode = /* @__PURE__ */(() => typeof process !== 'undefined' && process.release && /node|io\.js/.test(process.release.name) && Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]')()
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* True iff this script is running in deno
|
|
13
|
+
* @type {boolean}
|
|
14
|
+
*/
|
|
15
|
+
/* c8 ignore next 2 */
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
export const isDeno = /* @__PURE__ */(() => typeof Deno !== 'undefined')()
|
|
18
|
+
|
|
19
|
+
/* c8 ignore start */
|
|
20
|
+
export const globalScope = /* @__PURE__ */(() =>/** @type {any} */ (typeof globalThis !== 'undefined'
|
|
21
|
+
? globalThis
|
|
22
|
+
: typeof window !== 'undefined'
|
|
23
|
+
? window
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
: typeof global !== 'undefined' ? global : {}))()
|
|
26
|
+
/* c8 ignore stop */
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* True iff this script is running in a browser-family environment — either a DOM main
|
|
30
|
+
* thread (`window` + `document`) or a WebWorker / ServiceWorker (a `WorkerGlobalScope`,
|
|
31
|
+
* which has `btoa`/`atob`/`fetch` but no DOM). Excludes Node and Deno.
|
|
32
|
+
* @type {boolean}
|
|
33
|
+
*/
|
|
34
|
+
/* c8 ignore next */
|
|
35
|
+
export const isBrowser = /* @__PURE__ */(() =>
|
|
36
|
+
!isNode && !isDeno && (
|
|
37
|
+
(typeof window !== 'undefined' && typeof document !== 'undefined') ||
|
|
38
|
+
// WebWorker / ServiceWorker: no window/document, but a worker global scope
|
|
39
|
+
(typeof globalScope.WorkerGlobalScope !== 'undefined' && globalScope.self instanceof globalScope.WorkerGlobalScope)
|
|
40
|
+
)
|
|
41
|
+
)()
|
package/src/environment.js
CHANGED
|
@@ -9,20 +9,10 @@ import * as string from './string.js'
|
|
|
9
9
|
import * as conditions from './conditions.js'
|
|
10
10
|
import * as storage from './storage.js'
|
|
11
11
|
import * as f from './function.js'
|
|
12
|
+
import { isNode, globalScope } from './environment.common.js'
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
export const isNode = /* @__PURE__ */(() => typeof process !== 'undefined' && process.release && /node|io\.js/.test(process.release.name) && Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]')()
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* True iff this script is running in deno
|
|
18
|
-
* @type {boolean}
|
|
19
|
-
*/
|
|
20
|
-
/* c8 ignore next 2 */
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
export const isDeno = /* @__PURE__ */(() => typeof Deno !== 'undefined')()
|
|
14
|
+
export { isNode, isDeno, isBrowser } from './environment.common.js'
|
|
23
15
|
|
|
24
|
-
/* c8 ignore next */
|
|
25
|
-
export const isBrowser = /* @__PURE__ */(() => typeof window !== 'undefined' && typeof document !== 'undefined' && !isNode)()
|
|
26
16
|
/* c8 ignore next */
|
|
27
17
|
export const isMac = /* @__PURE__ */(() => typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false)()
|
|
28
18
|
|
|
@@ -168,13 +158,4 @@ export const supportsColor = /* @__PURE__ */(() => forceColor || (
|
|
|
168
158
|
))()
|
|
169
159
|
/* c8 ignore stop */
|
|
170
160
|
|
|
171
|
-
/* c8 ignore start */
|
|
172
|
-
const globalScope = /* @__PURE__ */(() =>/** @type {any} */ (typeof globalThis !== 'undefined'
|
|
173
|
-
? globalThis
|
|
174
|
-
: typeof window !== 'undefined'
|
|
175
|
-
? window
|
|
176
|
-
// @ts-ignore
|
|
177
|
-
: typeof global !== 'undefined' ? global : {}))()
|
|
178
|
-
/* c8 ignore stop */
|
|
179
|
-
|
|
180
161
|
export { globalScope as global }
|
package/src/error.js
CHANGED
|
@@ -12,8 +12,12 @@
|
|
|
12
12
|
export const create = s => new Error(s)
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
+
* `@type` (not `@param`/`@return`) is required for the `never` return to affect control-flow
|
|
16
|
+
* analysis — a call to a never-returning function only terminates a code path if the callee is
|
|
17
|
+
* declared with an explicit type annotation.
|
|
18
|
+
*
|
|
15
19
|
* @throws {Error}
|
|
16
|
-
* @
|
|
20
|
+
* @type {() => never}
|
|
17
21
|
*/
|
|
18
22
|
/* c8 ignore next 3 */
|
|
19
23
|
export const methodUnimplemented = () => {
|
|
@@ -22,7 +26,7 @@ export const methodUnimplemented = () => {
|
|
|
22
26
|
|
|
23
27
|
/**
|
|
24
28
|
* @throws {Error}
|
|
25
|
-
* @
|
|
29
|
+
* @type {() => never}
|
|
26
30
|
*/
|
|
27
31
|
/* c8 ignore next 3 */
|
|
28
32
|
export const unexpectedCase = () => {
|
|
@@ -30,7 +34,9 @@ export const unexpectedCase = () => {
|
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
37
|
+
* `@type` (not `@param`/`@return`) is required — an assertion signature only narrows if the
|
|
38
|
+
* callee is declared with an explicit type annotation.
|
|
39
|
+
*
|
|
40
|
+
* @type {(property: boolean) => asserts property is true}
|
|
35
41
|
*/
|
|
36
42
|
export const assert = property => { if (!property) throw create('Assert failed') }
|
package/src/eventloop.js
CHANGED
|
@@ -21,7 +21,7 @@ const _runQueue = () => {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* @param {
|
|
24
|
+
* @param {() => void} f
|
|
25
25
|
*/
|
|
26
26
|
export const enqueue = f => {
|
|
27
27
|
queue.push(f)
|
|
@@ -36,7 +36,7 @@ export const enqueue = f => {
|
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* @param {
|
|
39
|
+
* @param {(timeoutId: number) => void} clearFunction
|
|
40
40
|
*/
|
|
41
41
|
const createTimeoutClass = clearFunction => class TT {
|
|
42
42
|
/**
|
|
@@ -73,7 +73,7 @@ export const interval = (timeout, callback) => new Interval(setInterval(callback
|
|
|
73
73
|
export const Animation = createTimeoutClass(arg => typeof requestAnimationFrame !== 'undefined' && cancelAnimationFrame(arg))
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* @param {
|
|
76
|
+
* @param {(timestamp: number) => void} cb
|
|
77
77
|
* @return {TimeoutObject}
|
|
78
78
|
*/
|
|
79
79
|
/* c8 ignore next */
|
package/src/function.js
CHANGED
package/src/indexeddb.js
CHANGED
|
@@ -26,7 +26,7 @@ export const rtop = request => promise.create((resolve, reject) => {
|
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @param {string} name
|
|
29
|
-
* @param {
|
|
29
|
+
* @param {(db: IDBDatabase) => any} initDB Called when the database is first created
|
|
30
30
|
* @return {Promise<IDBDatabase>}
|
|
31
31
|
*/
|
|
32
32
|
export const openDB = (name, initDB) => promise.create((resolve, reject) => {
|
|
@@ -193,7 +193,7 @@ export const getAllKeysValues = (store, range, limit) =>
|
|
|
193
193
|
|
|
194
194
|
/**
|
|
195
195
|
* @param {any} request
|
|
196
|
-
* @param {
|
|
196
|
+
* @param {(cursor: IDBCursorWithValue) => void|boolean|Promise<void|boolean>} f
|
|
197
197
|
* @return {Promise<void>}
|
|
198
198
|
*/
|
|
199
199
|
const iterateOnRequest = (request, f) => promise.create((resolve, reject) => {
|
|
@@ -214,7 +214,7 @@ const iterateOnRequest = (request, f) => promise.create((resolve, reject) => {
|
|
|
214
214
|
* Iterate on keys and values
|
|
215
215
|
* @param {IDBObjectStore} store
|
|
216
216
|
* @param {IDBKeyRange|null} keyrange
|
|
217
|
-
* @param {
|
|
217
|
+
* @param {(value: any, key: any) => void|boolean|Promise<void|boolean>} f Callback that receives (value, key)
|
|
218
218
|
* @param {'next'|'prev'|'nextunique'|'prevunique'} direction
|
|
219
219
|
*/
|
|
220
220
|
export const iterate = (store, keyrange, f, direction = 'next') =>
|
|
@@ -225,7 +225,7 @@ export const iterate = (store, keyrange, f, direction = 'next') =>
|
|
|
225
225
|
*
|
|
226
226
|
* @param {IDBObjectStore} store
|
|
227
227
|
* @param {IDBKeyRange|null} keyrange
|
|
228
|
-
* @param {
|
|
228
|
+
* @param {(key: any) => void|boolean|Promise<void|boolean>} f callback that receives the key
|
|
229
229
|
* @param {'next'|'prev'|'nextunique'|'prevunique'} direction
|
|
230
230
|
*/
|
|
231
231
|
export const iterateKeys = (store, keyrange, f, direction = 'next') =>
|
package/src/indexeddbV2.js
CHANGED
|
@@ -28,7 +28,7 @@ export const bindPledge = (p, request) => {
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* @param {string} name
|
|
31
|
-
* @param {
|
|
31
|
+
* @param {(db: IDBDatabase) => any} initDB Called when the database is first created
|
|
32
32
|
* @return {pledge.PledgeInstance<IDBDatabase>}
|
|
33
33
|
*/
|
|
34
34
|
export const openDB = (name, initDB) => {
|
|
@@ -194,7 +194,7 @@ export const getAllKeysValues = (store, range, limit) => pledge.createWithDepend
|
|
|
194
194
|
/**
|
|
195
195
|
* @param {pledge.PledgeInstance<void>} p
|
|
196
196
|
* @param {any} request
|
|
197
|
-
* @param {
|
|
197
|
+
* @param {(cursor: IDBCursorWithValue) => void|boolean|Promise<void|boolean>} f
|
|
198
198
|
*/
|
|
199
199
|
const iterateOnRequest = (p, request, f) => {
|
|
200
200
|
request.onerror = p.cancel.bind(p)
|
|
@@ -215,7 +215,7 @@ const iterateOnRequest = (p, request, f) => {
|
|
|
215
215
|
* Iterate on keys and values
|
|
216
216
|
* @param {pledge.Pledge<IDBObjectStore>} store
|
|
217
217
|
* @param {pledge.Pledge<IDBKeyRange|null>} keyrange
|
|
218
|
-
* @param {
|
|
218
|
+
* @param {(value: any, key: any) => void|boolean|Promise<void|boolean>} f Callback that receives (value, key)
|
|
219
219
|
* @param {'next'|'prev'|'nextunique'|'prevunique'} direction
|
|
220
220
|
*/
|
|
221
221
|
export const iterate = (store, keyrange, f, direction = 'next') => pledge.createWithDependencies((p, store, keyrange) => {
|
|
@@ -227,7 +227,7 @@ export const iterate = (store, keyrange, f, direction = 'next') => pledge.create
|
|
|
227
227
|
*
|
|
228
228
|
* @param {pledge.Pledge<IDBObjectStore>} store
|
|
229
229
|
* @param {pledge.Pledge<IDBKeyRange|null>} keyrange
|
|
230
|
-
* @param {
|
|
230
|
+
* @param {(key: any) => void|boolean|Promise<void|boolean>} f callback that receives the key
|
|
231
231
|
* @param {'next'|'prev'|'nextunique'|'prevunique'} direction
|
|
232
232
|
*/
|
|
233
233
|
export const iterateKeys = (store, keyrange, f, direction = 'next') => pledge.createWithDependencies((p, store, keyrange) => {
|
package/src/iterator.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* @template T,R
|
|
9
9
|
* @param {Iterator<T>} iterator
|
|
10
|
-
* @param {
|
|
10
|
+
* @param {(v: T) => R} f
|
|
11
11
|
* @return {IterableIterator<R>}
|
|
12
12
|
*/
|
|
13
13
|
export const mapIterator = (iterator, f) => ({
|
|
@@ -23,7 +23,7 @@ export const mapIterator = (iterator, f) => ({
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @template T
|
|
26
|
-
* @param {
|
|
26
|
+
* @param {() => IteratorResult<T>} next
|
|
27
27
|
* @return {IterableIterator<T>}
|
|
28
28
|
*/
|
|
29
29
|
export const createIterator = next => ({
|
|
@@ -40,7 +40,7 @@ export const createIterator = next => ({
|
|
|
40
40
|
/**
|
|
41
41
|
* @template T
|
|
42
42
|
* @param {Iterator<T>} iterator
|
|
43
|
-
* @param {
|
|
43
|
+
* @param {(v: T) => boolean} filter
|
|
44
44
|
*/
|
|
45
45
|
export const iteratorFilter = (iterator, filter) => createIterator(() => {
|
|
46
46
|
let res
|
|
@@ -53,7 +53,7 @@ export const iteratorFilter = (iterator, filter) => createIterator(() => {
|
|
|
53
53
|
/**
|
|
54
54
|
* @template T,M
|
|
55
55
|
* @param {Iterator<T>} iterator
|
|
56
|
-
* @param {
|
|
56
|
+
* @param {(v: T) => M} fmap
|
|
57
57
|
*/
|
|
58
58
|
export const iteratorMap = (iterator, fmap) => createIterator(() => {
|
|
59
59
|
const { done, value } = iterator.next()
|
package/src/list.js
CHANGED
|
@@ -45,7 +45,7 @@ export class List {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
|
-
* @param {
|
|
48
|
+
* @param {(node: N) => any} f
|
|
49
49
|
*/
|
|
50
50
|
forEach (f) {
|
|
51
51
|
forEach(this, f)
|
|
@@ -53,7 +53,7 @@ export class List {
|
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* @template M
|
|
56
|
-
* @param {
|
|
56
|
+
* @param {(node: N) => M} f
|
|
57
57
|
* @return {Array<M>}
|
|
58
58
|
*/
|
|
59
59
|
map (f) {
|
|
@@ -206,7 +206,7 @@ export const popEnd = list =>
|
|
|
206
206
|
* @template M
|
|
207
207
|
*
|
|
208
208
|
* @param {List<N>} list
|
|
209
|
-
* @param {
|
|
209
|
+
* @param {(node: N) => M} f
|
|
210
210
|
* @return {Array<M>}
|
|
211
211
|
*/
|
|
212
212
|
export const map = (list, f) => {
|
|
@@ -232,7 +232,7 @@ export const toArray = list => map(list, id)
|
|
|
232
232
|
/**
|
|
233
233
|
* @template {ListNode} N
|
|
234
234
|
* @param {List<N>} list
|
|
235
|
-
* @param {
|
|
235
|
+
* @param {(node: N) => any} f
|
|
236
236
|
*/
|
|
237
237
|
export const forEach = (list, f) => {
|
|
238
238
|
let n = list.start
|
package/src/logging.common.js
CHANGED
|
@@ -16,7 +16,7 @@ export const UNCOLOR = symbol.create()
|
|
|
16
16
|
|
|
17
17
|
/* c8 ignore start */
|
|
18
18
|
/**
|
|
19
|
-
* @param {Array<undefined|string|Symbol|Object|number|
|
|
19
|
+
* @param {Array<undefined|string|Symbol|Object|number|(() => any)>} args
|
|
20
20
|
* @return {Array<string|object|number|undefined>}
|
|
21
21
|
*/
|
|
22
22
|
export const computeNoColorLoggingArgs = args => {
|
|
@@ -58,9 +58,9 @@ let lastLoggingTime = time.getUnixTime()
|
|
|
58
58
|
|
|
59
59
|
/* c8 ignore start */
|
|
60
60
|
/**
|
|
61
|
-
* @param {
|
|
61
|
+
* @param {(...args: Array<any>) => void} _print
|
|
62
62
|
* @param {string} moduleName
|
|
63
|
-
* @return {
|
|
63
|
+
* @return {(...args: Array<any>) => void}
|
|
64
64
|
*/
|
|
65
65
|
export const createModuleLogger = (_print, moduleName) => {
|
|
66
66
|
const color = loggingColors[nextColor]
|
package/src/logging.js
CHANGED
|
@@ -32,7 +32,7 @@ const _browserStyleMap = {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* @param {Array<string|Symbol|Object|number|
|
|
35
|
+
* @param {Array<string|Symbol|Object|number|(() => any)>} args
|
|
36
36
|
* @return {Array<string|object|number>}
|
|
37
37
|
*/
|
|
38
38
|
/* c8 ignore start */
|
|
@@ -174,7 +174,7 @@ export const groupEnd = () => {
|
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
/**
|
|
177
|
-
* @param {
|
|
177
|
+
* @param {() => Node} createNode
|
|
178
178
|
*/
|
|
179
179
|
/* c8 ignore next 2 */
|
|
180
180
|
export const printDom = (createNode) =>
|
|
@@ -378,6 +378,6 @@ export const createVConsole = (dom) => new VConsole(dom)
|
|
|
378
378
|
|
|
379
379
|
/**
|
|
380
380
|
* @param {string} moduleName
|
|
381
|
-
* @return {
|
|
381
|
+
* @return {(...args: Array<any>) => void}
|
|
382
382
|
*/
|
|
383
383
|
export const createModuleLogger = (moduleName) => common.createModuleLogger(print, moduleName)
|
package/src/logging.node.js
CHANGED
|
@@ -23,7 +23,7 @@ const _nodeStyleMap = {
|
|
|
23
23
|
|
|
24
24
|
/* c8 ignore start */
|
|
25
25
|
/**
|
|
26
|
-
* @param {Array<string|undefined|Symbol|Object|number|
|
|
26
|
+
* @param {Array<string|undefined|Symbol|Object|number|(() => Array<any>)>} args
|
|
27
27
|
* @return {Array<string|object|number|undefined>}
|
|
28
28
|
*/
|
|
29
29
|
const computeNodeLoggingArgs = (args) => {
|
|
@@ -137,7 +137,7 @@ export const groupEnd = () => {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/**
|
|
140
|
-
* @param {
|
|
140
|
+
* @param {() => Node} _createNode
|
|
141
141
|
*/
|
|
142
142
|
/* c8 ignore next 2 */
|
|
143
143
|
export const printDom = (_createNode) => {}
|
|
@@ -158,7 +158,7 @@ export const createVConsole = (_dom) => {}
|
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
160
|
* @param {string} moduleName
|
|
161
|
-
* @return {
|
|
161
|
+
* @return {(...args: Array<any>) => void}
|
|
162
162
|
*/
|
|
163
163
|
/* c8 ignore next */
|
|
164
164
|
export const createModuleLogger = (moduleName) => common.createModuleLogger(print, moduleName)
|
package/src/map.js
CHANGED
|
@@ -44,7 +44,7 @@ export const copy = m => {
|
|
|
44
44
|
*
|
|
45
45
|
* @function
|
|
46
46
|
* @template {Map<any, any>} MAP
|
|
47
|
-
* @template {MAP extends Map<any,infer V> ?
|
|
47
|
+
* @template {MAP extends Map<any,infer V> ? (() => V) : unknown} CF
|
|
48
48
|
* @param {MAP} map
|
|
49
49
|
* @param {MAP extends Map<infer K,any> ? K : unknown} key
|
|
50
50
|
* @param {CF} createT
|
|
@@ -66,7 +66,7 @@ export const setIfUndefined = (map, key, createT) => {
|
|
|
66
66
|
* @template V
|
|
67
67
|
* @template R
|
|
68
68
|
* @param {Map<K,V>} m
|
|
69
|
-
* @param {
|
|
69
|
+
* @param {(value: V, key: K) => R} f
|
|
70
70
|
* @return {Array<R>}
|
|
71
71
|
*/
|
|
72
72
|
export const map = (m, f) => {
|
|
@@ -86,7 +86,7 @@ export const map = (m, f) => {
|
|
|
86
86
|
* @template K
|
|
87
87
|
* @template V
|
|
88
88
|
* @param {Map<K,V>} m
|
|
89
|
-
* @param {
|
|
89
|
+
* @param {(value: V, key: K) => boolean} f
|
|
90
90
|
* @return {boolean}
|
|
91
91
|
*/
|
|
92
92
|
export const any = (m, f) => {
|
|
@@ -105,7 +105,7 @@ export const any = (m, f) => {
|
|
|
105
105
|
* @template K
|
|
106
106
|
* @template V
|
|
107
107
|
* @param {Map<K,V>} m
|
|
108
|
-
* @param {
|
|
108
|
+
* @param {(value: V, key: K) => boolean} f
|
|
109
109
|
* @return {boolean}
|
|
110
110
|
*/
|
|
111
111
|
export const all = (m, f) => {
|
package/src/mutex.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @callback mutex
|
|
9
|
-
* @param {
|
|
10
|
-
* @param {
|
|
9
|
+
* @param {() => void} cb Only executed when this mutex is not in the current stack
|
|
10
|
+
* @param {() => void} [elseCb] Executed when this mutex is in the current stack
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
/**
|
package/src/object.js
CHANGED
|
@@ -37,7 +37,7 @@ export const values = Object.values
|
|
|
37
37
|
/**
|
|
38
38
|
* @template V
|
|
39
39
|
* @param {{[k:string]:V}} obj
|
|
40
|
-
* @param {
|
|
40
|
+
* @param {(value: V, key: string) => any} f
|
|
41
41
|
*/
|
|
42
42
|
export const forEach = (obj, f) => {
|
|
43
43
|
for (const key in obj) {
|
|
@@ -50,7 +50,7 @@ export const forEach = (obj, f) => {
|
|
|
50
50
|
*
|
|
51
51
|
* @template R
|
|
52
52
|
* @param {Object<string,any>} obj
|
|
53
|
-
* @param {
|
|
53
|
+
* @param {(value: any, key: string) => R} f
|
|
54
54
|
* @return {Array<R>}
|
|
55
55
|
*/
|
|
56
56
|
export const map = (obj, f) => {
|
package/src/observable.js
CHANGED
|
@@ -15,7 +15,7 @@ import * as array from './array.js'
|
|
|
15
15
|
* This is basically a (better typed) duplicate of Observable, which will replace Observable in the
|
|
16
16
|
* next release.
|
|
17
17
|
*
|
|
18
|
-
* @template {{[key in keyof EVENTS]:
|
|
18
|
+
* @template {{[key in keyof EVENTS]: (...args: Array<any>) => void}} EVENTS
|
|
19
19
|
*/
|
|
20
20
|
export class ObservableV2 {
|
|
21
21
|
constructor () {
|
package/src/pair.js
CHANGED
|
@@ -37,14 +37,14 @@ export const createReversed = (right, left) => new Pair(left, right)
|
|
|
37
37
|
/**
|
|
38
38
|
* @template L,R
|
|
39
39
|
* @param {Array<Pair<L,R>>} arr
|
|
40
|
-
* @param {
|
|
40
|
+
* @param {(left: L, right: R) => any} f
|
|
41
41
|
*/
|
|
42
42
|
export const forEach = (arr, f) => arr.forEach(p => f(p.left, p.right))
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* @template L,R,X
|
|
46
46
|
* @param {Array<Pair<L,R>>} arr
|
|
47
|
-
* @param {
|
|
47
|
+
* @param {(left: L, right: R) => X} f
|
|
48
48
|
* @return {Array<X>}
|
|
49
49
|
*/
|
|
50
50
|
export const map = (arr, f) => arr.map(p => f(p.left, p.right))
|
package/src/pledge.js
CHANGED
|
@@ -45,11 +45,11 @@ export class PledgeInstance {
|
|
|
45
45
|
this._v = null
|
|
46
46
|
this.isResolved = false
|
|
47
47
|
/**
|
|
48
|
-
* @type {Array<
|
|
48
|
+
* @type {Array<(val: Val) => void> | null}
|
|
49
49
|
*/
|
|
50
50
|
this._whenResolved = []
|
|
51
51
|
/**
|
|
52
|
-
* @type {Array<
|
|
52
|
+
* @type {Array<(reason: CancelReason) => void> | null}
|
|
53
53
|
*/
|
|
54
54
|
this._whenCanceled = []
|
|
55
55
|
}
|
|
@@ -93,7 +93,7 @@ export class PledgeInstance {
|
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
95
|
* @template R
|
|
96
|
-
* @param {
|
|
96
|
+
* @param {(val: Val) => Pledge<R>} f
|
|
97
97
|
* @return {PledgeInstance<R>}
|
|
98
98
|
*/
|
|
99
99
|
map (f) {
|
|
@@ -117,7 +117,7 @@ export class PledgeInstance {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
|
-
* @param {
|
|
120
|
+
* @param {(val: Val) => void} f
|
|
121
121
|
*/
|
|
122
122
|
whenResolved (f) {
|
|
123
123
|
if (this.isResolved) {
|
|
@@ -187,7 +187,7 @@ export const createWithDependencies = (init, ...deps) => {
|
|
|
187
187
|
/**
|
|
188
188
|
* @template R
|
|
189
189
|
* @param {Pledge<R>} p
|
|
190
|
-
* @param {
|
|
190
|
+
* @param {(res: R) => void} f
|
|
191
191
|
*/
|
|
192
192
|
export const whenResolved = (p, f) => {
|
|
193
193
|
if (p instanceof PledgeInstance) {
|
|
@@ -199,7 +199,7 @@ export const whenResolved = (p, f) => {
|
|
|
199
199
|
/**
|
|
200
200
|
* @template {Pledge<unknown>} P
|
|
201
201
|
* @param {P} p
|
|
202
|
-
* @param {P extends PledgeInstance<unknown, infer CancelReason> ?
|
|
202
|
+
* @param {P extends PledgeInstance<unknown, infer CancelReason> ? ((reason: CancelReason) => void) : ((reason: any) => void)} f
|
|
203
203
|
*/
|
|
204
204
|
export const whenCanceled = (p, f) => {
|
|
205
205
|
if (p instanceof PledgeInstance) {
|