lib0 1.0.0-rc.2 → 1.0.0-rc.21
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/README.md +0 -1315
- package/{types → dist}/buffer.d.ts +2 -10
- package/{types → dist}/delta/delta.d.ts +582 -144
- package/dist/delta/position.d.ts +65 -0
- package/dist/delta/rdt/delta.d.ts +57 -0
- package/dist/delta/rdt/dom.d.ts +102 -0
- package/dist/delta/rdt.d.ts +180 -0
- package/dist/delta/transformer/attr.d.ts +64 -0
- package/dist/delta/transformer/attribution-to-format.d.ts +52 -0
- package/dist/delta/transformer/children.d.ts +69 -0
- package/dist/delta/transformer/conform.d.ts +83 -0
- package/dist/delta/transformer/core.d.ts +189 -0
- package/dist/delta/transformer/full-attributions.d.ts +37 -0
- package/dist/delta/transformer/id.d.ts +2 -0
- package/dist/delta/transformer/inline.d.ts +89 -0
- package/dist/delta/transformer/pipe.d.ts +182 -0
- package/dist/delta/transformer/project.d.ts +223 -0
- package/dist/delta/transformer/rename-attrs.d.ts +75 -0
- package/dist/delta/transformer/rename.d.ts +41 -0
- package/dist/delta/transformer/value.d.ts +92 -0
- package/dist/delta/transformer.d.ts +14 -0
- package/dist/diff/patience.d.ts +25 -0
- package/{types → dist}/environment.d.ts +10 -0
- package/dist/hash/fnv1a.d.ts +11 -0
- package/{types → dist}/schema.d.ts +49 -38
- package/{types → dist}/ts.d.ts +4 -0
- package/dist/webcrypto.d.ts +3 -0
- package/package.json +148 -82
- package/src/bin/0serve.js +11 -3
- package/src/broadcastchannel.js +6 -1
- package/src/buffer.js +35 -25
- package/src/decoding.js +1 -1
- package/src/delta/delta.js +2531 -564
- package/src/delta/position.js +165 -0
- package/src/delta/rdt/delta.js +105 -0
- package/src/delta/rdt/dom.js +307 -0
- package/src/delta/rdt.js +255 -0
- package/src/delta/transformer/attr.js +126 -0
- package/src/delta/transformer/attribution-to-format.js +335 -0
- package/src/delta/transformer/children.js +219 -0
- package/src/delta/transformer/conform.js +401 -0
- package/src/delta/transformer/core.js +323 -0
- package/src/delta/transformer/full-attributions.js +282 -0
- package/src/delta/transformer/id.js +13 -0
- package/src/delta/transformer/inline.js +818 -0
- package/src/delta/transformer/pipe.js +272 -0
- package/src/delta/transformer/project.js +526 -0
- package/src/delta/transformer/rename-attrs.js +152 -0
- package/src/delta/transformer/rename.js +84 -0
- package/src/delta/transformer/value.js +214 -0
- package/src/delta/transformer.js +38 -0
- package/src/diff/patience.js +22 -11
- package/src/dom.js +2 -2
- package/src/encoding.js +1 -1
- package/src/environment.js +15 -0
- package/src/hash/fnv1a.js +82 -0
- package/src/number.js +1 -3
- package/src/performance.node.js +3 -3
- package/src/schema.js +231 -177
- package/src/string.js +3 -5
- package/src/testing.js +1 -1
- package/src/trait/equality.js +1 -1
- package/src/trait/fingerprint.js +1 -1
- package/src/ts.js +11 -0
- package/src/bin/gendocs.js +0 -117
- package/src/component.js +0 -414
- package/src/delta/binding.js +0 -372
- package/src/tree.js +0 -546
- package/types/bin/gendocs.d.ts +0 -3
- package/types/component.d.ts +0 -86
- package/types/delta/binding.d.ts +0 -106
- package/types/diff/patience.d.ts +0 -16
- package/types/tree.d.ts +0 -96
- package/types/webcrypto.d.ts +0 -3
- /package/{types → dist}/array.d.ts +0 -0
- /package/{types → dist}/bin/0ecdsa-generate-keypair.d.ts +0 -0
- /package/{types → dist}/bin/0serve.d.ts +0 -0
- /package/{types → dist}/bin/gentesthtml.d.ts +0 -0
- /package/{types → dist}/binary.d.ts +0 -0
- /package/{types → dist}/broadcastchannel.d.ts +0 -0
- /package/{types → dist}/cache.d.ts +0 -0
- /package/{types → dist}/conditions.d.ts +0 -0
- /package/{types → dist}/crypto/aes-gcm.d.ts +0 -0
- /package/{types → dist}/crypto/common.d.ts +0 -0
- /package/{types → dist}/crypto/ecdsa.d.ts +0 -0
- /package/{types → dist}/crypto/jwt.d.ts +0 -0
- /package/{types → dist}/crypto/rsa-oaep.d.ts +0 -0
- /package/{types → dist}/decoding.d.ts +0 -0
- /package/{types → dist}/diff.d.ts +0 -0
- /package/{types → dist}/dom.d.ts +0 -0
- /package/{types → dist}/encoding.d.ts +0 -0
- /package/{types → dist}/error.d.ts +0 -0
- /package/{types → dist}/eventloop.d.ts +0 -0
- /package/{types → dist}/function.d.ts +0 -0
- /package/{types → dist}/hash/rabin-gf2-polynomial.d.ts +0 -0
- /package/{types → dist}/hash/rabin-uncached.d.ts +0 -0
- /package/{types → dist}/hash/rabin.d.ts +0 -0
- /package/{types → dist}/hash/sha256.d.ts +0 -0
- /package/{types → dist}/hash/sha256.node.d.ts +0 -0
- /package/{types → dist}/indexeddb.d.ts +0 -0
- /package/{types → dist}/indexeddbV2.d.ts +0 -0
- /package/{types → dist}/iterator.d.ts +0 -0
- /package/{types → dist}/json.d.ts +0 -0
- /package/{types → dist}/list.d.ts +0 -0
- /package/{types → dist}/logging.common.d.ts +0 -0
- /package/{types → dist}/logging.d.ts +0 -0
- /package/{types → dist}/logging.node.d.ts +0 -0
- /package/{types → dist}/map.d.ts +0 -0
- /package/{types → dist}/math.d.ts +0 -0
- /package/{types → dist}/metric.d.ts +0 -0
- /package/{types → dist}/mutex.d.ts +0 -0
- /package/{types → dist}/number.d.ts +0 -0
- /package/{types → dist}/object.d.ts +0 -0
- /package/{types → dist}/observable.d.ts +0 -0
- /package/{types → dist}/pair.d.ts +0 -0
- /package/{types → dist}/performance.d.ts +0 -0
- /package/{types → dist}/performance.node.d.ts +0 -0
- /package/{types → dist}/pledge.d.ts +0 -0
- /package/{types → dist}/prng/Mt19937.d.ts +0 -0
- /package/{types → dist}/prng/Xoroshiro128plus.d.ts +0 -0
- /package/{types → dist}/prng/Xorshift32.d.ts +0 -0
- /package/{types → dist}/prng.d.ts +0 -0
- /package/{types → dist}/promise.d.ts +0 -0
- /package/{types → dist}/queue.d.ts +0 -0
- /package/{types → dist}/random.d.ts +0 -0
- /package/{types → dist}/set.d.ts +0 -0
- /package/{types → dist}/sort.d.ts +0 -0
- /package/{types → dist}/statistics.d.ts +0 -0
- /package/{types → dist}/storage.d.ts +0 -0
- /package/{types → dist}/string.d.ts +0 -0
- /package/{types → dist}/symbol.d.ts +0 -0
- /package/{types → dist}/testing.d.ts +0 -0
- /package/{types → dist}/time.d.ts +0 -0
- /package/{types → dist}/trait/equality.d.ts +0 -0
- /package/{types → dist}/trait/fingerprint.d.ts +0 -0
- /package/{types → dist}/trait/traits.d.ts +0 -0
- /package/{types → dist}/url.d.ts +0 -0
- /package/{types → dist}/webcrypto.deno.d.ts +0 -0
- /package/{types → dist}/webcrypto.node.d.ts +0 -0
- /package/{types → dist}/webcrypto.react-native.d.ts +0 -0
- /package/{types → dist}/websocket.d.ts +0 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import * as array from 'lib0/array'
|
|
2
|
+
import { Transformer, Template, createTransformResult } from './core.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../delta.js').DeltaConf} DeltaConf
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A delta schema for a given conf — `Schema<Delta<C>>`. Local alias to keep the overload signatures
|
|
10
|
+
* readable; defined via inline `import()` so no value import is needed.
|
|
11
|
+
*
|
|
12
|
+
* @template {DeltaConf} C
|
|
13
|
+
* @typedef {import('../../schema.js').Schema<import('../delta.js').Delta<C>>} DSchema
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Build each pipe stage's {@link Template} by threading the schema left→right: stage `k` is built
|
|
18
|
+
* against stage `k-1`'s output schema (`$out`). Returns the stage templates and the final output schema.
|
|
19
|
+
*
|
|
20
|
+
* @param {DSchema<any>} $in
|
|
21
|
+
* @param {Array<(d: DSchema<any>) => Template<any,any>>} stageFns
|
|
22
|
+
* @return {{ stages: Template<any,any>[], $out: DSchema<any> }}
|
|
23
|
+
*/
|
|
24
|
+
const buildStages = ($in, stageFns) => {
|
|
25
|
+
let $cur = $in
|
|
26
|
+
/** @type {Template<any,any>[]} */
|
|
27
|
+
const stages = []
|
|
28
|
+
for (const fn of stageFns) { const t = fn($cur); stages.push(t); $cur = t.$out }
|
|
29
|
+
return { stages, $out: $cur }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The composite template produced by {@link pipe}: holds the threaded stage templates; `init()`
|
|
34
|
+
* materializes each into a {@link PipeTransformer}.
|
|
35
|
+
*
|
|
36
|
+
* @template {DeltaConf} [IN=any]
|
|
37
|
+
* @template {DeltaConf} [OUT=any]
|
|
38
|
+
* @extends {Template<IN, OUT>}
|
|
39
|
+
*/
|
|
40
|
+
export class Pipe extends Template {
|
|
41
|
+
/**
|
|
42
|
+
* @param {DSchema<IN>} $in
|
|
43
|
+
* @param {DSchema<OUT>} $out
|
|
44
|
+
* @param {Template<any,any>[]} stages the threaded stage templates (A→B order)
|
|
45
|
+
*/
|
|
46
|
+
constructor ($in, $out, stages) {
|
|
47
|
+
super($in, $out)
|
|
48
|
+
this.stages = stages
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get name () { return 'lib0:pipe' }
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @return {Transformer<IN, OUT>}
|
|
55
|
+
*/
|
|
56
|
+
init () {
|
|
57
|
+
return /** @type {any} */ (new PipeTransformer(this.$in, this.$out, this.stages.map(t => t.init())))
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @extends {Transformer<any,any>}
|
|
63
|
+
*/
|
|
64
|
+
export class PipeTransformer extends Transformer {
|
|
65
|
+
/**
|
|
66
|
+
* @param {DSchema<any>} $in
|
|
67
|
+
* @param {DSchema<any>} $out
|
|
68
|
+
* @param {Transformer<any,any>[]} ts the per-stage transformers (materialized, A→B order)
|
|
69
|
+
*/
|
|
70
|
+
constructor ($in, $out, ts) {
|
|
71
|
+
super($in, $out)
|
|
72
|
+
/**
|
|
73
|
+
* @type {Transformer<any,any>[]}
|
|
74
|
+
*/
|
|
75
|
+
this.ts = ts
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {import('./core.js').TransformResultAny} tin
|
|
80
|
+
* @return {import('./core.js').TransformResultAny}
|
|
81
|
+
*/
|
|
82
|
+
apply (tin) {
|
|
83
|
+
const ts = this.ts
|
|
84
|
+
// the deltas we still have to apply on the respective transformers (ts[i].apply(tr[i]))
|
|
85
|
+
const trs = array.unfold(ts.length, () => createTransformResult(null, null))
|
|
86
|
+
// the final accumulated result
|
|
87
|
+
const res = createTransformResult(null, null)
|
|
88
|
+
trs[0].a = tin.a
|
|
89
|
+
trs[trs.length - 1].b = tin.b
|
|
90
|
+
let madeChange = false
|
|
91
|
+
// change direction whenever possible, go back and forth until no more changes can be applied
|
|
92
|
+
if (!tin.isEmpty()) {
|
|
93
|
+
do {
|
|
94
|
+
madeChange = false
|
|
95
|
+
let forward = trs[0].a != null
|
|
96
|
+
let i = forward ? 0 : ts.length - 1
|
|
97
|
+
while (i >= 0 && i < ts.length) {
|
|
98
|
+
const ti = ts[i]
|
|
99
|
+
const tri = trs[i]
|
|
100
|
+
if (!tri.isEmpty()) {
|
|
101
|
+
madeChange = true
|
|
102
|
+
const tires = ti.apply(tri)
|
|
103
|
+
if (i === 0) {
|
|
104
|
+
res.applyA(tires.a)
|
|
105
|
+
} else {
|
|
106
|
+
trs[i - 1].applyB(tires.a)
|
|
107
|
+
}
|
|
108
|
+
if (i === trs.length - 1) {
|
|
109
|
+
res.applyB(tires.b)
|
|
110
|
+
} else {
|
|
111
|
+
trs[i + 1].applyA(tires.b)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
tri.clear()
|
|
115
|
+
const hasForwardChange = i + 1 < ts.length && !trs[i + 1].isEmpty()
|
|
116
|
+
const hasBackwardChange = i > 0 && !trs[i - 1].isEmpty()
|
|
117
|
+
// go back and forth
|
|
118
|
+
if (forward && hasBackwardChange) {
|
|
119
|
+
forward = false
|
|
120
|
+
} else if (!forward && hasForwardChange) {
|
|
121
|
+
forward = true
|
|
122
|
+
}
|
|
123
|
+
forward ? i++ : i--
|
|
124
|
+
}
|
|
125
|
+
} while (madeChange)
|
|
126
|
+
}
|
|
127
|
+
return res
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Chain transformers, threading the input schema left→right so each stage is typed against the
|
|
133
|
+
* previous stage's output. `pipe($d, $d1 => …, $d2 => …)` infers the end-to-end output type
|
|
134
|
+
* automatically; each stage is a `($schema) => Template` factory. Returns a reusable {@link Pipe}
|
|
135
|
+
* template — call `.init()` for the transformer.
|
|
136
|
+
*
|
|
137
|
+
* Order is directional: an `applyA` change flows through the stages **left→right** (the leftmost maps
|
|
138
|
+
* the A-side first), an `applyB` change flows **right→left**. So list stages in A→B order — e.g.
|
|
139
|
+
* `pipe($d, $d1 => children($d1, …), $d2 => rename($d2, 'ul'))` maps an A-side change with `children`
|
|
140
|
+
* then `rename`. Reversing the order silently produces wrong results (there is no init-time check).
|
|
141
|
+
*
|
|
142
|
+
* The overloads cover up to a fixed arity; longer typed pipes nest
|
|
143
|
+
* (`pipe($d, …, $dk => pipe($dk, …more))`).
|
|
144
|
+
*
|
|
145
|
+
* @template {DeltaConf} In
|
|
146
|
+
* @template {DeltaConf} O1
|
|
147
|
+
* @overload
|
|
148
|
+
* @param {DSchema<In>} $in
|
|
149
|
+
* @param {(d: DSchema<In>) => Template<In, O1>} f1
|
|
150
|
+
* @returns {Pipe<In, O1>}
|
|
151
|
+
*/
|
|
152
|
+
/**
|
|
153
|
+
* @template {DeltaConf} In
|
|
154
|
+
* @template {DeltaConf} O1
|
|
155
|
+
* @template {DeltaConf} O2
|
|
156
|
+
* @overload
|
|
157
|
+
* @param {DSchema<In>} $in
|
|
158
|
+
* @param {(d: DSchema<In>) => Template<In, O1>} f1
|
|
159
|
+
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
|
|
160
|
+
* @returns {Pipe<In, O2>}
|
|
161
|
+
*/
|
|
162
|
+
/**
|
|
163
|
+
* @template {DeltaConf} In
|
|
164
|
+
* @template {DeltaConf} O1
|
|
165
|
+
* @template {DeltaConf} O2
|
|
166
|
+
* @template {DeltaConf} O3
|
|
167
|
+
* @overload
|
|
168
|
+
* @param {DSchema<In>} $in
|
|
169
|
+
* @param {(d: DSchema<In>) => Template<In, O1>} f1
|
|
170
|
+
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
|
|
171
|
+
* @param {(d: DSchema<O2>) => Template<O2, O3>} f3
|
|
172
|
+
* @returns {Pipe<In, O3>}
|
|
173
|
+
*/
|
|
174
|
+
/**
|
|
175
|
+
* @template {DeltaConf} In
|
|
176
|
+
* @template {DeltaConf} O1
|
|
177
|
+
* @template {DeltaConf} O2
|
|
178
|
+
* @template {DeltaConf} O3
|
|
179
|
+
* @template {DeltaConf} O4
|
|
180
|
+
* @overload
|
|
181
|
+
* @param {DSchema<In>} $in
|
|
182
|
+
* @param {(d: DSchema<In>) => Template<In, O1>} f1
|
|
183
|
+
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
|
|
184
|
+
* @param {(d: DSchema<O2>) => Template<O2, O3>} f3
|
|
185
|
+
* @param {(d: DSchema<O3>) => Template<O3, O4>} f4
|
|
186
|
+
* @returns {Pipe<In, O4>}
|
|
187
|
+
*/
|
|
188
|
+
/**
|
|
189
|
+
* @template {DeltaConf} In
|
|
190
|
+
* @template {DeltaConf} O1
|
|
191
|
+
* @template {DeltaConf} O2
|
|
192
|
+
* @template {DeltaConf} O3
|
|
193
|
+
* @template {DeltaConf} O4
|
|
194
|
+
* @template {DeltaConf} O5
|
|
195
|
+
* @overload
|
|
196
|
+
* @param {DSchema<In>} $in
|
|
197
|
+
* @param {(d: DSchema<In>) => Template<In, O1>} f1
|
|
198
|
+
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
|
|
199
|
+
* @param {(d: DSchema<O2>) => Template<O2, O3>} f3
|
|
200
|
+
* @param {(d: DSchema<O3>) => Template<O3, O4>} f4
|
|
201
|
+
* @param {(d: DSchema<O4>) => Template<O4, O5>} f5
|
|
202
|
+
* @returns {Pipe<In, O5>}
|
|
203
|
+
*/
|
|
204
|
+
/**
|
|
205
|
+
* @template {DeltaConf} In
|
|
206
|
+
* @template {DeltaConf} O1
|
|
207
|
+
* @template {DeltaConf} O2
|
|
208
|
+
* @template {DeltaConf} O3
|
|
209
|
+
* @template {DeltaConf} O4
|
|
210
|
+
* @template {DeltaConf} O5
|
|
211
|
+
* @template {DeltaConf} O6
|
|
212
|
+
* @overload
|
|
213
|
+
* @param {DSchema<In>} $in
|
|
214
|
+
* @param {(d: DSchema<In>) => Template<In, O1>} f1
|
|
215
|
+
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
|
|
216
|
+
* @param {(d: DSchema<O2>) => Template<O2, O3>} f3
|
|
217
|
+
* @param {(d: DSchema<O3>) => Template<O3, O4>} f4
|
|
218
|
+
* @param {(d: DSchema<O4>) => Template<O4, O5>} f5
|
|
219
|
+
* @param {(d: DSchema<O5>) => Template<O5, O6>} f6
|
|
220
|
+
* @returns {Pipe<In, O6>}
|
|
221
|
+
*/
|
|
222
|
+
/**
|
|
223
|
+
* @template {DeltaConf} In
|
|
224
|
+
* @template {DeltaConf} O1
|
|
225
|
+
* @template {DeltaConf} O2
|
|
226
|
+
* @template {DeltaConf} O3
|
|
227
|
+
* @template {DeltaConf} O4
|
|
228
|
+
* @template {DeltaConf} O5
|
|
229
|
+
* @template {DeltaConf} O6
|
|
230
|
+
* @template {DeltaConf} O7
|
|
231
|
+
* @overload
|
|
232
|
+
* @param {DSchema<In>} $in
|
|
233
|
+
* @param {(d: DSchema<In>) => Template<In, O1>} f1
|
|
234
|
+
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
|
|
235
|
+
* @param {(d: DSchema<O2>) => Template<O2, O3>} f3
|
|
236
|
+
* @param {(d: DSchema<O3>) => Template<O3, O4>} f4
|
|
237
|
+
* @param {(d: DSchema<O4>) => Template<O4, O5>} f5
|
|
238
|
+
* @param {(d: DSchema<O5>) => Template<O5, O6>} f6
|
|
239
|
+
* @param {(d: DSchema<O6>) => Template<O6, O7>} f7
|
|
240
|
+
* @returns {Pipe<In, O7>}
|
|
241
|
+
*/
|
|
242
|
+
/**
|
|
243
|
+
* @template {DeltaConf} In
|
|
244
|
+
* @template {DeltaConf} O1
|
|
245
|
+
* @template {DeltaConf} O2
|
|
246
|
+
* @template {DeltaConf} O3
|
|
247
|
+
* @template {DeltaConf} O4
|
|
248
|
+
* @template {DeltaConf} O5
|
|
249
|
+
* @template {DeltaConf} O6
|
|
250
|
+
* @template {DeltaConf} O7
|
|
251
|
+
* @template {DeltaConf} O8
|
|
252
|
+
* @overload
|
|
253
|
+
* @param {DSchema<In>} $in
|
|
254
|
+
* @param {(d: DSchema<In>) => Template<In, O1>} f1
|
|
255
|
+
* @param {(d: DSchema<O1>) => Template<O1, O2>} f2
|
|
256
|
+
* @param {(d: DSchema<O2>) => Template<O2, O3>} f3
|
|
257
|
+
* @param {(d: DSchema<O3>) => Template<O3, O4>} f4
|
|
258
|
+
* @param {(d: DSchema<O4>) => Template<O4, O5>} f5
|
|
259
|
+
* @param {(d: DSchema<O5>) => Template<O5, O6>} f6
|
|
260
|
+
* @param {(d: DSchema<O6>) => Template<O6, O7>} f7
|
|
261
|
+
* @param {(d: DSchema<O7>) => Template<O7, O8>} f8
|
|
262
|
+
* @returns {Pipe<In, O8>}
|
|
263
|
+
*/
|
|
264
|
+
/**
|
|
265
|
+
* @param {DSchema<any>} $in
|
|
266
|
+
* @param {...((d: DSchema<any>) => Template<any,any>)} fns
|
|
267
|
+
* @returns {any}
|
|
268
|
+
*/
|
|
269
|
+
export const pipe = ($in, ...fns) => {
|
|
270
|
+
const { stages, $out } = buildStages($in, fns)
|
|
271
|
+
return new Pipe($in, $out, stages)
|
|
272
|
+
}
|