lib0 1.0.0-rc.13 → 1.0.0-rc.15
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/delta/binding.d.ts +45 -82
- package/dist/delta/delta.d.ts +60 -18
- package/dist/delta/rdt/delta.d.ts +45 -0
- package/dist/delta/rdt/dom.d.ts +61 -0
- package/dist/delta/transformer/children.d.ts +64 -0
- package/dist/delta/transformer/core.d.ts +69 -0
- package/dist/delta/transformer/filter.d.ts +103 -0
- package/dist/delta/transformer/id.d.ts +9 -0
- package/dist/delta/transformer/inline.d.ts +90 -0
- package/dist/delta/transformer/pipe.d.ts +271 -0
- package/dist/delta/transformer/projection.d.ts +33 -0
- package/dist/delta/transformer/query.d.ts +60 -0
- package/dist/delta/transformer/rename.d.ts +51 -0
- package/dist/delta/transformer.d.ts +14 -296
- package/dist/hash/fnv1a.d.ts +11 -0
- package/package.json +52 -3
- package/src/bin/0serve.js +10 -2
- package/src/delta/binding.js +78 -337
- package/src/delta/delta.js +262 -38
- package/src/delta/rdt/delta.js +75 -0
- package/src/delta/rdt/dom.js +314 -0
- package/src/delta/transformer/children.js +207 -0
- package/src/delta/transformer/core.js +159 -0
- package/src/delta/transformer/filter.js +104 -0
- package/src/delta/transformer/id.js +10 -0
- package/src/delta/transformer/inline.js +677 -0
- package/src/delta/transformer/pipe.js +238 -0
- package/src/delta/transformer/projection.js +89 -0
- package/src/delta/transformer/query.js +110 -0
- package/src/delta/transformer/rename.js +99 -0
- package/src/delta/transformer.js +28 -643
- package/src/hash/fnv1a.js +82 -0
package/dist/delta/binding.d.ts
CHANGED
|
@@ -3,104 +3,67 @@
|
|
|
3
3
|
* @typedef {import('../schema.js').Schema<T>} Schema
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Abstract interface for a delta-based Replicated Data Type.
|
|
7
|
+
*
|
|
8
|
+
* An RDT is an observable that emits a `'delta'` (and, on teardown, a `'destroy'`) event, exposes the
|
|
9
|
+
* {@link Schema schema} of the deltas it produces via `$schema` (so a {@link Binding} can initialize a
|
|
10
|
+
* transformer for it), and accepts foreign deltas via `applyDelta`.
|
|
11
|
+
*
|
|
12
|
+
* @template {delta.DeltaAny} D
|
|
13
|
+
* @typedef {ObservableV2<{ delta: (delta: D) => void, destroy: (rdt: RDT<D>) => void }> & {
|
|
14
|
+
* $schema: Schema<D>,
|
|
15
|
+
* applyDelta: (delta: D) => void,
|
|
16
|
+
* destroy: () => void
|
|
17
|
+
* }} RDT
|
|
8
18
|
*/
|
|
9
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Connects two RDTs so that changes on either side are transformed and reflected on the other.
|
|
21
|
+
*
|
|
22
|
+
* @template {delta.DeltaAny} DeltaA
|
|
23
|
+
*/
|
|
24
|
+
export class Binding<DeltaA extends delta.DeltaAny> {
|
|
10
25
|
/**
|
|
11
26
|
* @param {RDT<DeltaA>} a
|
|
12
|
-
* @param {RDT<
|
|
13
|
-
* @param {dt.Template
|
|
27
|
+
* @param {RDT<delta.DeltaAny>} b
|
|
28
|
+
* @param {dt.Template} [template] defaults to the {@link dt.id identity} transformer
|
|
29
|
+
*/
|
|
30
|
+
constructor(a: RDT<DeltaA>, b: RDT<delta.DeltaAny>, template?: dt.Template);
|
|
31
|
+
/**
|
|
32
|
+
* @type {dt.Transformer<any,any>}
|
|
14
33
|
*/
|
|
15
|
-
|
|
34
|
+
t: dt.Transformer<any, any>;
|
|
16
35
|
/**
|
|
17
|
-
* @type {
|
|
36
|
+
* @type {RDT<any>}
|
|
18
37
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
38
|
+
a: RDT<any>;
|
|
39
|
+
/**
|
|
40
|
+
* @type {RDT<any>}
|
|
41
|
+
*/
|
|
42
|
+
b: RDT<any>;
|
|
22
43
|
_mux: mux.mutex;
|
|
23
|
-
_achanged: (delta:
|
|
24
|
-
_bchanged: (delta:
|
|
44
|
+
_achanged: (delta: any) => void;
|
|
45
|
+
_bchanged: (delta: any) => void;
|
|
25
46
|
destroy: () => void;
|
|
26
47
|
}
|
|
27
|
-
export function bind<DeltaA extends delta.
|
|
28
|
-
export function deltaRDT<Delta extends delta.AbstractDelta>($delta: Schema<Delta>): DeltaRDT<Delta>;
|
|
29
|
-
export const $domDelta: any;
|
|
30
|
-
export function domRDT(dom: Element): DomRDT<delta.RecursiveNode<string, {
|
|
31
|
-
[key: string]: string;
|
|
32
|
-
}, never, true>>;
|
|
48
|
+
export function bind<DeltaA extends delta.DeltaAny>(a: RDT<DeltaA>, b: RDT<delta.DeltaAny>, template?: dt.Template): Binding<DeltaA>;
|
|
33
49
|
export type Schema<T> = import("../schema.js").Schema<T>;
|
|
34
50
|
/**
|
|
35
|
-
* Abstract
|
|
51
|
+
* Abstract interface for a delta-based Replicated Data Type.
|
|
52
|
+
*
|
|
53
|
+
* An RDT is an observable that emits a `'delta'` (and, on teardown, a `'destroy'`) event, exposes the
|
|
54
|
+
* {@link Schema schema} of the deltas it produces via `$schema` (so a {@link Binding} can initialize a
|
|
55
|
+
* transformer for it), and accepts foreign deltas via `applyDelta`.
|
|
36
56
|
*/
|
|
37
|
-
export type RDT<
|
|
38
|
-
|
|
39
|
-
|
|
57
|
+
export type RDT<D extends delta.DeltaAny> = ObservableV2<{
|
|
58
|
+
delta: (delta: D) => void;
|
|
59
|
+
destroy: (rdt: RDT<D>) => void;
|
|
40
60
|
}> & {
|
|
41
|
-
|
|
61
|
+
$schema: Schema<D>;
|
|
62
|
+
applyDelta: (delta: D) => void;
|
|
42
63
|
destroy: () => void;
|
|
43
64
|
};
|
|
44
|
-
export type DomDelta = delta.RecursiveNode<string, {
|
|
45
|
-
[key: string]: string;
|
|
46
|
-
}, never, true>;
|
|
47
65
|
import * as delta from './delta.js';
|
|
66
|
+
import * as dt from './transformer.js';
|
|
48
67
|
import * as mux from '../mutex.js';
|
|
49
|
-
/**
|
|
50
|
-
* @template {delta.AbstractDelta} Delta
|
|
51
|
-
* @implements RDT<Delta>
|
|
52
|
-
* @extends {ObservableV2<{ change: (delta: Delta) => void, 'destroy': (rdt:DeltaRDT<Delta>)=>void }>}
|
|
53
|
-
*/
|
|
54
|
-
declare class DeltaRDT<Delta extends delta.AbstractDelta> extends ObservableV2<{
|
|
55
|
-
change: (delta: Delta) => void;
|
|
56
|
-
destroy: (rdt: DeltaRDT<Delta>) => void;
|
|
57
|
-
}> implements RDT<Delta> {
|
|
58
|
-
/**
|
|
59
|
-
* @param {Schema<Delta>} $delta
|
|
60
|
-
*/
|
|
61
|
-
constructor($delta: Schema<Delta>);
|
|
62
|
-
$delta: s.Schema<Delta>;
|
|
63
|
-
/**
|
|
64
|
-
* @type {Delta?}
|
|
65
|
-
*/
|
|
66
|
-
state: Delta | null;
|
|
67
|
-
_mux: mux.mutex;
|
|
68
|
-
/**
|
|
69
|
-
* @param {Delta} delta
|
|
70
|
-
*/
|
|
71
|
-
update: (delta: Delta) => any;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @typedef {delta.RecursiveNode<string, { [key:string]: string }, never, true>} DomDelta
|
|
75
|
-
*/
|
|
76
|
-
/**
|
|
77
|
-
* @template {DomDelta} [D=DomDelta]
|
|
78
|
-
* @implements RDT<D>
|
|
79
|
-
* @extends {ObservableV2<{ change: (delta: D)=>void, destroy: (rdt:DomRDT<D>)=>void }>}>}
|
|
80
|
-
*/
|
|
81
|
-
declare class DomRDT<D extends DomDelta = delta.RecursiveNode<string, {
|
|
82
|
-
[key: string]: string;
|
|
83
|
-
}, never, true>> extends ObservableV2<{
|
|
84
|
-
change: (delta: D) => void;
|
|
85
|
-
destroy: (rdt: DomRDT<D>) => void;
|
|
86
|
-
}> implements RDT<D> {
|
|
87
|
-
/**
|
|
88
|
-
* @param {Element} observedNode
|
|
89
|
-
*/
|
|
90
|
-
constructor(observedNode: Element);
|
|
91
|
-
observedNode: Element;
|
|
92
|
-
_mux: mux.mutex;
|
|
93
|
-
observer: MutationObserver;
|
|
94
|
-
/**
|
|
95
|
-
* @param {MutationRecord[]} mutations
|
|
96
|
-
*/
|
|
97
|
-
_mutationHandler: (mutations: MutationRecord[]) => any;
|
|
98
|
-
/**
|
|
99
|
-
* @param {D} delta
|
|
100
|
-
*/
|
|
101
|
-
update: (delta: D) => void;
|
|
102
|
-
}
|
|
103
68
|
import { ObservableV2 } from '../observable.js';
|
|
104
|
-
import * as s from '../schema.js';
|
|
105
|
-
export {};
|
|
106
69
|
//# sourceMappingURL=binding.d.ts.map
|
package/dist/delta/delta.d.ts
CHANGED
|
@@ -42,6 +42,22 @@ export const $attribution: s.Schema<Attribution>;
|
|
|
42
42
|
* @type {s.Schema<DeltaAttrOpJSON>}
|
|
43
43
|
*/
|
|
44
44
|
export const $deltaMapChangeJson: s.Schema<DeltaAttrOpJSON>;
|
|
45
|
+
/**
|
|
46
|
+
* Invariants shared by all op classes below (TextOp, InsertOp, DeleteOp,
|
|
47
|
+
* RetainOp, ModifyOp, SetAttrOp, DeleteAttrOp, ModifyAttrOp):
|
|
48
|
+
*
|
|
49
|
+
* - **Only code inside `delta.js` may mutate op fields.** External consumers
|
|
50
|
+
* treat ops as immutable; structural fields are JSDoc-annotated `@readonly`
|
|
51
|
+
* to reinforce this. Mutation is permitted only while the owning Delta is
|
|
52
|
+
* not `done` — every builder entry point routes through `modDeltaCheck`
|
|
53
|
+
* to enforce this at runtime.
|
|
54
|
+
* - **Any mutation of a fingerprinted field MUST null `_fingerprint`.** The
|
|
55
|
+
* fingerprint is a lazy cache; if it has already been computed and the
|
|
56
|
+
* underlying data changes without invalidating it, every subsequent
|
|
57
|
+
* fingerprint read (and any `diff` / equality check that relies on it) is
|
|
58
|
+
* wrong. Fields covered: insert, delete, retain, format, attribution,
|
|
59
|
+
* value, key.
|
|
60
|
+
*/
|
|
45
61
|
export class TextOp extends list.ListNode {
|
|
46
62
|
/**
|
|
47
63
|
* @param {string} insert
|
|
@@ -125,9 +141,9 @@ export class InsertOp<ArrayContent extends unknown> extends list.ListNode {
|
|
|
125
141
|
*/
|
|
126
142
|
_fingerprint: string | null;
|
|
127
143
|
/**
|
|
128
|
-
* @param {ArrayContent}
|
|
144
|
+
* @param {ArrayContent} _newVal
|
|
129
145
|
*/
|
|
130
|
-
_updateInsert(
|
|
146
|
+
_updateInsert(_newVal: ArrayContent): void;
|
|
131
147
|
/**
|
|
132
148
|
* @return {'insert'}
|
|
133
149
|
*/
|
|
@@ -184,10 +200,10 @@ export class DeleteOp<Conf extends DeltaConf = {}> extends list.ListNode {
|
|
|
184
200
|
/**
|
|
185
201
|
* Remove a part of the operation (similar to Array.splice)
|
|
186
202
|
*
|
|
187
|
-
* @param {number}
|
|
203
|
+
* @param {number} offset
|
|
188
204
|
* @param {number} len
|
|
189
205
|
*/
|
|
190
|
-
_splice(
|
|
206
|
+
_splice(offset: number, len: number): this;
|
|
191
207
|
/**
|
|
192
208
|
* @return {DeltaListOpJSON}
|
|
193
209
|
*/
|
|
@@ -666,10 +682,12 @@ export class DeltaBuilder<Conf extends DeltaConf = {}, FixedConf extends boolean
|
|
|
666
682
|
*
|
|
667
683
|
* a.apply(b).apply(c)
|
|
668
684
|
*
|
|
669
|
-
*
|
|
685
|
+
* If `final = true`, we consider this delta the final state and drop deleteAttrOps from
|
|
686
|
+
* attributes. (E.g. if `otherOp` deletes an attribute, this op will simply not have the
|
|
687
|
+
* attribute). Any kind of `delete` op might be considered a bug. A final delta is not idempotent.
|
|
670
688
|
*
|
|
671
689
|
* @param {Delta<Conf>?} other
|
|
672
|
-
* @param {{ final?: boolean }} opts -- experimental
|
|
690
|
+
* @param {{ final?: boolean }} opts -- (experimental)
|
|
673
691
|
* @return {DeltaBuilder<Conf>}
|
|
674
692
|
*/
|
|
675
693
|
apply(other: Delta<Conf> | null, { final }?: {
|
|
@@ -800,8 +818,7 @@ export function create<Schema extends s.Schema<DeltaAny>>(schema: Schema): Schem
|
|
|
800
818
|
* @param {NodeName} nodeName
|
|
801
819
|
* @param {Attrs} attrs
|
|
802
820
|
* @param {Children} [children]
|
|
803
|
-
* @return {DeltaBuilder<{
|
|
804
|
-
* name: NodeName,
|
|
821
|
+
* @return {DeltaBuilder<(NodeName extends string ? { name: NodeName } : {}) & {
|
|
805
822
|
* attrs: Attrs extends null ? {} : Attrs,
|
|
806
823
|
* children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
|
|
807
824
|
* text: Extract<Children,string> extends never ? false : true
|
|
@@ -809,8 +826,9 @@ export function create<Schema extends s.Schema<DeltaAny>>(schema: Schema): Schem
|
|
|
809
826
|
*/
|
|
810
827
|
export function create<NodeName extends string | null, Attrs extends {
|
|
811
828
|
[k: string | number]: any;
|
|
812
|
-
} | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, children?: Children | undefined): DeltaBuilder<{
|
|
829
|
+
} | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, children?: Children | undefined): DeltaBuilder<(NodeName extends string ? {
|
|
813
830
|
name: NodeName;
|
|
831
|
+
} : {}) & {
|
|
814
832
|
attrs: Attrs extends null ? {} : Attrs;
|
|
815
833
|
children: Extract<Children, Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never;
|
|
816
834
|
text: Extract<Children, string> extends never ? false : true;
|
|
@@ -821,14 +839,14 @@ export function create<NodeName extends string | null, Attrs extends {
|
|
|
821
839
|
* @overload
|
|
822
840
|
* @param {NodeName} nodeName
|
|
823
841
|
* @param {...Array<Children>} children
|
|
824
|
-
* @return {DeltaBuilder<{
|
|
825
|
-
* name: NodeName,
|
|
842
|
+
* @return {DeltaBuilder<(NodeName extends string ? { name: NodeName } : {}) & {
|
|
826
843
|
* children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
|
|
827
844
|
* text: Extract<Children,string> extends never ? false : true
|
|
828
845
|
* }>}
|
|
829
846
|
*/
|
|
830
|
-
export function from<NodeName extends string | null, Children extends Array<any> | string = never>(nodeName: NodeName, ...children: Array<Children>[]): DeltaBuilder<{
|
|
847
|
+
export function from<NodeName extends string | null, Children extends Array<any> | string = never>(nodeName: NodeName, ...children: Array<Children>[]): DeltaBuilder<(NodeName extends string ? {
|
|
831
848
|
name: NodeName;
|
|
849
|
+
} : {}) & {
|
|
832
850
|
children: Extract<Children, Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never;
|
|
833
851
|
text: Extract<Children, string> extends never ? false : true;
|
|
834
852
|
}>;
|
|
@@ -872,8 +890,7 @@ export function from<Attrs extends {
|
|
|
872
890
|
* @param {NodeName} nodeName
|
|
873
891
|
* @param {Attrs} attrs
|
|
874
892
|
* @param {...Array<Children>} children
|
|
875
|
-
* @return {DeltaBuilder<{
|
|
876
|
-
* name: NodeName,
|
|
893
|
+
* @return {DeltaBuilder<(NodeName extends string ? { name: NodeName } : {}) & {
|
|
877
894
|
* attrs: Attrs extends null ? {} : Attrs,
|
|
878
895
|
* children: Extract<Children,Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never,
|
|
879
896
|
* text: Extract<Children,string> extends never ? false : true
|
|
@@ -881,13 +898,14 @@ export function from<Attrs extends {
|
|
|
881
898
|
*/
|
|
882
899
|
export function from<NodeName extends string | null, Attrs extends {
|
|
883
900
|
[k: string | number]: any;
|
|
884
|
-
} | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, ...children: Array<Children>[]): DeltaBuilder<{
|
|
901
|
+
} | null, Children extends Array<any> | string = never>(nodeName: NodeName, attrs: Attrs, ...children: Array<Children>[]): DeltaBuilder<(NodeName extends string ? {
|
|
885
902
|
name: NodeName;
|
|
903
|
+
} : {}) & {
|
|
886
904
|
attrs: Attrs extends null ? {} : Attrs;
|
|
887
905
|
children: Extract<Children, Array<any>> extends Array<infer Ac> ? (unknown extends Ac ? never : Ac) : never;
|
|
888
906
|
text: Extract<Children, string> extends never ? false : true;
|
|
889
907
|
}>;
|
|
890
|
-
export function diff<Conf_1 extends DeltaConf>(d1: Delta<Conf_1>, d2: NoInfer<Delta<Conf_1
|
|
908
|
+
export function diff<Conf_1 extends DeltaConf>(d1: Delta<Conf_1>, d2: NoInfer<Delta<Conf_1>>, options?: DiffOptions): Delta<Conf_1>;
|
|
891
909
|
export function diffChangesetWithSeparator(changeset: Array<{
|
|
892
910
|
index: number;
|
|
893
911
|
remove: Array<any>;
|
|
@@ -961,6 +979,13 @@ export type DeltaConf = {
|
|
|
961
979
|
recursiveChildren?: boolean | undefined;
|
|
962
980
|
recursiveAttrs?: boolean | undefined;
|
|
963
981
|
};
|
|
982
|
+
/**
|
|
983
|
+
* Coerce a computed conf to provably satisfy the `DeltaConf` constraint. Declaration emit re-checks
|
|
984
|
+
* type arguments eagerly, so a deeply-computed conf (mapped/recursive) passed to `Delta<…>` /
|
|
985
|
+
* `Transformer<…>` must be wrapped here: the conditional exposes `DeltaConf` as its upper bound,
|
|
986
|
+
* letting the constraint resolve without forcing TS to expand the (self-referential) body.
|
|
987
|
+
*/
|
|
988
|
+
export type AsDeltaConf<T> = T extends infer DC extends DeltaConf ? DC : never;
|
|
964
989
|
export type DeltaConfGetName<Conf_1 extends DeltaConf> = Conf_1 extends {
|
|
965
990
|
name: infer Name;
|
|
966
991
|
} ? (unknown extends Name ? any : (Exclude<Name, undefined>)) : any;
|
|
@@ -1016,7 +1041,7 @@ export type ReadDeltaConf<DConfSpec extends ReadableDeltaConf> = [DConfSpec exte
|
|
|
1016
1041
|
attrs: infer A;
|
|
1017
1042
|
} ? s.ReadSchemaUnwrapped<A> : {}, DConfSpec extends {
|
|
1018
1043
|
children: infer C;
|
|
1019
|
-
} ? s.ReadSchemaUnwrapped<C> : never] extends [infer NodeName_1, infer Attrs_1, infer Children_1] ? PrettifyDeltaConf<(import("../ts.js").TypeIsAny<NodeName_1, {}, {
|
|
1044
|
+
} ? s.ReadSchemaUnwrapped<C> : never] extends [infer NodeName_1, infer Attrs_1, infer Children_1] ? AsDeltaConf<PrettifyDeltaConf<(import("../ts.js").TypeIsAny<NodeName_1, {}, {
|
|
1020
1045
|
name: NodeName_1;
|
|
1021
1046
|
}> & ([keyof Attrs_1] extends [never] ? {} : {
|
|
1022
1047
|
attrs: Attrs_1;
|
|
@@ -1030,7 +1055,15 @@ export type ReadDeltaConf<DConfSpec extends ReadableDeltaConf> = [DConfSpec exte
|
|
|
1030
1055
|
recursiveChildren: true;
|
|
1031
1056
|
} ? {
|
|
1032
1057
|
recursiveChildren: true;
|
|
1033
|
-
} : {}))
|
|
1058
|
+
} : {}))>> : never;
|
|
1059
|
+
export type DiffOptions = {
|
|
1060
|
+
/**
|
|
1061
|
+
* Predicate deciding when two nodes
|
|
1062
|
+
* are paired into a `modify` (vs. replaced wholesale). Defaults to comparing names
|
|
1063
|
+
* (`(d1, d2) => d1.name === d2.name`). Called as `compare(fromNode, toNode)`.
|
|
1064
|
+
*/
|
|
1065
|
+
compare?: ((d1: DeltaAny, d2: DeltaAny) => boolean) | undefined;
|
|
1066
|
+
};
|
|
1034
1067
|
import * as s from '../schema.js';
|
|
1035
1068
|
import * as list from '../list.js';
|
|
1036
1069
|
import * as equalityTrait from '../trait/equality.js';
|
|
@@ -1061,6 +1094,15 @@ import * as fingerprintTrait from '../trait/fingerprint.js';
|
|
|
1061
1094
|
* @property {boolean} [DeltaConf.recursiveChildren=false]
|
|
1062
1095
|
* @property {boolean} [DeltaConf.recursiveAttrs=false]
|
|
1063
1096
|
*/
|
|
1097
|
+
/**
|
|
1098
|
+
* Coerce a computed conf to provably satisfy the `DeltaConf` constraint. Declaration emit re-checks
|
|
1099
|
+
* type arguments eagerly, so a deeply-computed conf (mapped/recursive) passed to `Delta<…>` /
|
|
1100
|
+
* `Transformer<…>` must be wrapped here: the conditional exposes `DeltaConf` as its upper bound,
|
|
1101
|
+
* letting the constraint resolve without forcing TS to expand the (self-referential) body.
|
|
1102
|
+
*
|
|
1103
|
+
* @template T
|
|
1104
|
+
* @typedef {T extends infer DC extends DeltaConf ? DC : never} AsDeltaConf
|
|
1105
|
+
*/
|
|
1064
1106
|
/**
|
|
1065
1107
|
* @template {DeltaConf} Conf
|
|
1066
1108
|
* @typedef {Conf extends {name:infer Name} ? (unknown extends Name ? any : (Exclude<Name,undefined>)) : any} DeltaConfGetName
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function deltaRDT<D extends delta.DeltaAny>($schema: Schema<D>): DeltaRDT<D>;
|
|
2
|
+
export type Schema<T> = import("../../schema.js").Schema<T>;
|
|
3
|
+
export type RDT<D extends delta.DeltaAny> = import("../binding.js").RDT<D>;
|
|
4
|
+
import * as delta from '../delta.js';
|
|
5
|
+
/**
|
|
6
|
+
* @template T
|
|
7
|
+
* @typedef {import('../../schema.js').Schema<T>} Schema
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @template {delta.DeltaAny} D
|
|
11
|
+
* @typedef {import('../binding.js').RDT<D>} RDT
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* An in-memory RDT whose state is the accumulated delta. Calling `applyDelta` merges the incoming delta
|
|
15
|
+
* into `state` (via {@link delta.DeltaBuilder#apply}) and re-emits it as a `'delta'`.
|
|
16
|
+
*
|
|
17
|
+
* @template {delta.DeltaAny} D
|
|
18
|
+
* @implements {RDT<D>}
|
|
19
|
+
* @extends {ObservableV2<{ delta: (delta: D) => void, destroy: (rdt: DeltaRDT<D>) => void }>}
|
|
20
|
+
*/
|
|
21
|
+
declare class DeltaRDT<D extends delta.DeltaAny> extends ObservableV2<{
|
|
22
|
+
delta: (delta: D) => void;
|
|
23
|
+
destroy: (rdt: DeltaRDT<D>) => void;
|
|
24
|
+
}> implements RDT<D> {
|
|
25
|
+
/**
|
|
26
|
+
* @param {Schema<D>} $schema schema of the deltas this RDT produces
|
|
27
|
+
*/
|
|
28
|
+
constructor($schema: Schema<D>);
|
|
29
|
+
$schema: import("../../schema.js").Schema<D>;
|
|
30
|
+
/**
|
|
31
|
+
* @type {delta.DeltaBuilderAny?}
|
|
32
|
+
*/
|
|
33
|
+
state: delta.DeltaBuilderAny | null;
|
|
34
|
+
_mux: mux.mutex;
|
|
35
|
+
/**
|
|
36
|
+
* Merge an incoming delta into the current state and notify observers.
|
|
37
|
+
*
|
|
38
|
+
* @param {D} d
|
|
39
|
+
*/
|
|
40
|
+
applyDelta(d: D): void;
|
|
41
|
+
}
|
|
42
|
+
import { ObservableV2 } from '../../observable.js';
|
|
43
|
+
import * as mux from '../../mutex.js';
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=delta.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema describing the deltas produced/consumed by a {@link DomRDT}: a recursive node with a string
|
|
3
|
+
* name, string→string attributes, and text content.
|
|
4
|
+
*/
|
|
5
|
+
export const $domDelta: s.Schema<delta.Delta<{
|
|
6
|
+
name: string;
|
|
7
|
+
attrs: {
|
|
8
|
+
[x: string]: string;
|
|
9
|
+
};
|
|
10
|
+
text: true;
|
|
11
|
+
recursiveChildren: true;
|
|
12
|
+
}>>;
|
|
13
|
+
export function domRDT(dom: Element): DomRDT<DomDelta>;
|
|
14
|
+
export type Schema<T> = import("../../schema.js").Schema<T>;
|
|
15
|
+
export type RDT<D extends delta.DeltaAny> = import("../binding.js").RDT<D>;
|
|
16
|
+
export type DomDelta = delta.Delta<{
|
|
17
|
+
name: string;
|
|
18
|
+
attrs: {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
};
|
|
21
|
+
text: true;
|
|
22
|
+
recursiveChildren: true;
|
|
23
|
+
}>;
|
|
24
|
+
import * as delta from '../delta.js';
|
|
25
|
+
import * as s from '../../schema.js';
|
|
26
|
+
/**
|
|
27
|
+
* An RDT backed by a live DOM subtree. DOM mutations observed via `MutationObserver` are emitted as
|
|
28
|
+
* deltas; incoming deltas are applied back onto the DOM.
|
|
29
|
+
*
|
|
30
|
+
* @template {DomDelta} [D=DomDelta]
|
|
31
|
+
* @implements {RDT<D>}
|
|
32
|
+
* @extends {ObservableV2<{ delta: (delta: D) => void, destroy: (rdt: DomRDT<D>) => void }>}
|
|
33
|
+
*/
|
|
34
|
+
declare class DomRDT<D extends DomDelta = DomDelta> extends ObservableV2<{
|
|
35
|
+
delta: (delta: D) => void;
|
|
36
|
+
destroy: (rdt: DomRDT<D>) => void;
|
|
37
|
+
}> implements RDT<D> {
|
|
38
|
+
/**
|
|
39
|
+
* @param {Element} observedNode
|
|
40
|
+
*/
|
|
41
|
+
constructor(observedNode: Element);
|
|
42
|
+
/**
|
|
43
|
+
* @type {Schema<D>}
|
|
44
|
+
*/
|
|
45
|
+
$schema: Schema<D>;
|
|
46
|
+
observedNode: Element;
|
|
47
|
+
_mux: mux.mutex;
|
|
48
|
+
observer: MutationObserver;
|
|
49
|
+
/**
|
|
50
|
+
* @param {MutationRecord[]} mutations
|
|
51
|
+
*/
|
|
52
|
+
_mutationHandler: (mutations: MutationRecord[]) => any;
|
|
53
|
+
/**
|
|
54
|
+
* @param {D} d
|
|
55
|
+
*/
|
|
56
|
+
applyDelta(d: D): void;
|
|
57
|
+
}
|
|
58
|
+
import { ObservableV2 } from '../../observable.js';
|
|
59
|
+
import * as mux from '../../mutex.js';
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=dom.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stateful transformer that descends one level into a node's child *nodes* and applies a per-child
|
|
3
|
+
* sub-transformer, chosen by `handler`. Attributes and text pass through untouched. Designed to be
|
|
4
|
+
* applied recursively (see {@link children}).
|
|
5
|
+
*
|
|
6
|
+
* The per-child sub-transformer instances are kept in {@link ChildrenTransformer#childTs}, positionally
|
|
7
|
+
* aligned to the parent's child list (children carry no stable id - identity is positional). `children`
|
|
8
|
+
* never changes the child count at its own level, so side A and side B stay aligned position-for-
|
|
9
|
+
* position and the same `childTs` indexes both directions.
|
|
10
|
+
*
|
|
11
|
+
* `childTs` is a sparse positional map kept as a delta: each transformed child is an `insert([t])` op
|
|
12
|
+
* holding its sub-transformer; every other position (text runs, opted-out nodes) is a coalesced
|
|
13
|
+
* `retain(n)` gap. A run of N text characters costs one retain op, not N array slots. It is walked with
|
|
14
|
+
* a forward cursor in step with the change (see {@link ChildrenTransformer#transform}). Transformer
|
|
15
|
+
* instances are carried by reference across rebuilds, so their per-instance state survives.
|
|
16
|
+
*
|
|
17
|
+
* @extends {Transformer<any,any>}
|
|
18
|
+
*/
|
|
19
|
+
export class ChildrenTransformer extends Transformer<any, any> {
|
|
20
|
+
/**
|
|
21
|
+
* @param {(d: delta.DeltaAny) => Template | null} handler picks the template for a child node, or
|
|
22
|
+
* `null` to leave that child untransformed. Evaluated once, when the child is inserted.
|
|
23
|
+
*/
|
|
24
|
+
constructor(handler: (d: delta.DeltaAny) => Template | null);
|
|
25
|
+
handler: (d: delta.DeltaAny) => Template | null;
|
|
26
|
+
/**
|
|
27
|
+
* Sparse positional map of sub-transformers: `insert([t])` at each transformed child, `retain(n)`
|
|
28
|
+
* over gaps (text and opted-out nodes).
|
|
29
|
+
*
|
|
30
|
+
* @type {delta.DeltaBuilderAny}
|
|
31
|
+
*/
|
|
32
|
+
childTs: delta.DeltaBuilderAny;
|
|
33
|
+
/**
|
|
34
|
+
* @param {delta.DeltaBuilderAny} d the change to map
|
|
35
|
+
* @param {boolean} fwd `true` maps side A -> B (applying sub-transformers' `applyA`), `false` maps
|
|
36
|
+
* side B -> A. `children` is 1:1 over children, so the same `childTs` indexes both directions.
|
|
37
|
+
* @return {import('./core.js').TransformResultAny}
|
|
38
|
+
*/
|
|
39
|
+
transform(d: delta.DeltaBuilderAny, fwd: boolean): import("./core.js").TransformResultAny;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Template for {@link ChildrenTransformer}.
|
|
43
|
+
*
|
|
44
|
+
* @implements Template
|
|
45
|
+
*/
|
|
46
|
+
export class Children implements Template {
|
|
47
|
+
/**
|
|
48
|
+
* @param {(d: delta.DeltaAny) => Template | null} handler
|
|
49
|
+
*/
|
|
50
|
+
constructor(handler: (d: delta.DeltaAny) => Template | null);
|
|
51
|
+
handler: (d: delta.DeltaAny) => Template | null;
|
|
52
|
+
get stateless(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* @template {delta.DeltaConf} IN
|
|
55
|
+
* @param {import('../../schema.js').Schema<delta.Delta<IN>>} _$d
|
|
56
|
+
* @return {Transformer<IN, any>}
|
|
57
|
+
*/
|
|
58
|
+
init<IN extends delta.DeltaConf>(_$d: import("../../schema.js").Schema<delta.Delta<IN>>): Transformer<IN, any>;
|
|
59
|
+
}
|
|
60
|
+
export function children(handler: (d: delta.DeltaAny) => Template | null): Children;
|
|
61
|
+
export type Template = import("./core.js").Template;
|
|
62
|
+
import { Transformer } from './core.js';
|
|
63
|
+
import * as delta from '../delta.js';
|
|
64
|
+
//# sourceMappingURL=children.d.ts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export function $tresult<A extends delta.DeltaConf, B extends delta.DeltaConf>($a: s.Schema<delta.Delta<A>>, $b: s.Schema<delta.Delta<B>>): s.Schema<TransformResult<A, B>>;
|
|
2
|
+
export function createTransformResult<DeltaA extends delta.DeltaBuilderAny = delta.DeltaBuilderAny, DeltaB extends delta.DeltaBuilderAny = delta.DeltaBuilderAny>(a: DeltaA | null, b: DeltaB | null): TransformResult<any, any>;
|
|
3
|
+
/**
|
|
4
|
+
* @template {delta.DeltaConf} A
|
|
5
|
+
* @template {delta.DeltaConf} B
|
|
6
|
+
*/
|
|
7
|
+
export class Transformer<A extends delta.DeltaConf, B extends delta.DeltaConf> {
|
|
8
|
+
/**
|
|
9
|
+
* @param {TransformResult<A, B>} tin
|
|
10
|
+
* @return {TransformResult<A,B>}
|
|
11
|
+
*/
|
|
12
|
+
apply(tin: TransformResult<A, B>): TransformResult<A, B>;
|
|
13
|
+
/**
|
|
14
|
+
* @param {delta.DeltaBuilder<A>} t
|
|
15
|
+
* @return {TransformResult<A,B>}
|
|
16
|
+
*/
|
|
17
|
+
applyA(t: delta.DeltaBuilder<A>): TransformResult<A, B>;
|
|
18
|
+
/**
|
|
19
|
+
* @param {delta.DeltaBuilder<B>} t
|
|
20
|
+
* @return {TransformResult<A,B>}
|
|
21
|
+
*/
|
|
22
|
+
applyB(t: delta.DeltaBuilder<B>): TransformResult<A, B>;
|
|
23
|
+
}
|
|
24
|
+
export function transformerWith<A extends delta.DeltaConf, B extends delta.DeltaConf>(_a: s.Schema<delta.Delta<A>> | A, _b: s.Schema<delta.Delta<B>> | A): s.Schema<Transformer<A, B>>;
|
|
25
|
+
export const $transformer: s.Schema<Transformer<delta.DeltaConf, delta.DeltaConf>>;
|
|
26
|
+
export type TransformResultAny = TransformResult<any, any>;
|
|
27
|
+
/**
|
|
28
|
+
* A composable transformer factory. `init` instantiates a stateful {@link Transformer} for a given
|
|
29
|
+
* input schema; `stateless` reports whether the produced transformer carries no per-instance state
|
|
30
|
+
* (so it can be shared / cached).
|
|
31
|
+
*/
|
|
32
|
+
export type Template = {
|
|
33
|
+
stateless: boolean;
|
|
34
|
+
init: ($d: s.Schema<delta.DeltaAny>) => Transformer<any, any>;
|
|
35
|
+
};
|
|
36
|
+
import * as delta from '../delta.js';
|
|
37
|
+
import * as s from '../../schema.js';
|
|
38
|
+
/**
|
|
39
|
+
* @template {delta.DeltaConf} [A={}]
|
|
40
|
+
* @template {delta.DeltaConf} [B={}]
|
|
41
|
+
*/
|
|
42
|
+
declare class TransformResult<A extends delta.DeltaConf = {}, B extends delta.DeltaConf = {}> {
|
|
43
|
+
/**
|
|
44
|
+
* @param {delta.DeltaBuilder<A>?} a
|
|
45
|
+
* @param {delta.DeltaBuilder<B>?} b
|
|
46
|
+
*/
|
|
47
|
+
constructor(a: delta.DeltaBuilder<A> | null, b: delta.DeltaBuilder<B> | null);
|
|
48
|
+
/**
|
|
49
|
+
* @type {delta.DeltaBuilder<A>?}
|
|
50
|
+
*/
|
|
51
|
+
a: delta.DeltaBuilder<A> | null;
|
|
52
|
+
/**
|
|
53
|
+
* @type {delta.DeltaBuilder<B>?}
|
|
54
|
+
*/
|
|
55
|
+
b: delta.DeltaBuilder<B> | null;
|
|
56
|
+
isEmpty(): boolean;
|
|
57
|
+
clear(): void;
|
|
58
|
+
/**
|
|
59
|
+
* @param {delta.DeltaBuilder<A>?} a
|
|
60
|
+
*/
|
|
61
|
+
applyA(a: delta.DeltaBuilder<A> | null): this;
|
|
62
|
+
/**
|
|
63
|
+
* @param {delta.DeltaBuilder<B>?} b
|
|
64
|
+
*/
|
|
65
|
+
applyB(b: delta.DeltaBuilder<B> | null): this;
|
|
66
|
+
reverse(): TransformResult<B, A>;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import('./core.js').Template} Template
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* @template {delta.DeltaConf} DConf
|
|
6
|
+
* @template {delta.DeltaConf} IN
|
|
7
|
+
* @typedef {delta.AsDeltaConf<{ [K in keyof DConf & keyof IN]: K extends 'attrs' ? import('../../ts.js').PropsPickShared<DConf[K], IN[K]> : (DConf[K] & IN[K])}>} ApplyExpectType
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Drops everything that does not match the configured schema (only attrs are filtered for now).
|
|
11
|
+
*
|
|
12
|
+
* @template {delta.DeltaConf} DConf
|
|
13
|
+
* @implements Template
|
|
14
|
+
*/
|
|
15
|
+
export class Filter<DConf extends delta.DeltaConf> implements Template {
|
|
16
|
+
/**
|
|
17
|
+
* @param {import('../../schema.js').Schema<delta.Delta<DConf>>} $d
|
|
18
|
+
*/
|
|
19
|
+
constructor($d: import("../../schema.js").Schema<delta.Delta<DConf>>);
|
|
20
|
+
$d: delta.$Delta<delta.DeltaConf>;
|
|
21
|
+
$dshape: {
|
|
22
|
+
$name: s.Schema<any>;
|
|
23
|
+
$attrs: s.Schema<{}>;
|
|
24
|
+
$children: s.Schema<never>;
|
|
25
|
+
hasText: never;
|
|
26
|
+
recursiveChildren: false;
|
|
27
|
+
$formats: s.Schema<{
|
|
28
|
+
[K: string]: any;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
get stateless(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* @template {delta.DeltaConf} IN
|
|
34
|
+
* @param {import('../../schema.js').Schema<delta.Delta<IN>>} _$d
|
|
35
|
+
* @return {Transformer<IN,ApplyExpectType<DConf, IN>>}
|
|
36
|
+
*/
|
|
37
|
+
init<IN extends delta.DeltaConf>(_$d: import("../../schema.js").Schema<delta.Delta<IN>>): Transformer<IN, ApplyExpectType<DConf, IN>>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @template {delta.DeltaConf} IN
|
|
41
|
+
* @template {delta.DeltaConf} OUT
|
|
42
|
+
* @template {delta.DeltaConf} DConf
|
|
43
|
+
* @extends Transformer<IN,OUT>
|
|
44
|
+
*/
|
|
45
|
+
export class FilterTransformer<IN extends delta.DeltaConf, OUT extends delta.DeltaConf, DConf extends delta.DeltaConf> extends Transformer<IN, OUT> {
|
|
46
|
+
/**
|
|
47
|
+
* @param {delta.$Delta<DConf>} $d
|
|
48
|
+
*/
|
|
49
|
+
constructor($d: delta.$Delta<DConf>);
|
|
50
|
+
$dshape: {
|
|
51
|
+
$name: s.Schema<delta.DeltaConfGetName<DConf>>;
|
|
52
|
+
$attrs: s.Schema<import("../../ts.js").TypeIsAny<DConf, {
|
|
53
|
+
[K: string]: any;
|
|
54
|
+
[K: number]: any;
|
|
55
|
+
}, DConf extends {
|
|
56
|
+
attrs: infer Attrs;
|
|
57
|
+
} ? Attrs extends undefined ? {} : Attrs : {}>>;
|
|
58
|
+
$children: s.Schema<delta.DeltaConfGetChildren<DConf>>;
|
|
59
|
+
hasText: delta.DeltaConfGetText<DConf>;
|
|
60
|
+
recursiveChildren: delta.DeltaConfGetRecursiveChildren<DConf>;
|
|
61
|
+
$formats: s.Schema<{
|
|
62
|
+
[K: string]: any;
|
|
63
|
+
}>;
|
|
64
|
+
};
|
|
65
|
+
filter: delta.DeltaBuilder<{
|
|
66
|
+
children: any;
|
|
67
|
+
}, true>;
|
|
68
|
+
/**
|
|
69
|
+
* @type {delta.DeltaAny}
|
|
70
|
+
*/
|
|
71
|
+
dreversed: delta.DeltaAny;
|
|
72
|
+
/**
|
|
73
|
+
* @param {delta.DeltaBuilderAny} deltaA
|
|
74
|
+
*/
|
|
75
|
+
applyA(deltaA: delta.DeltaBuilderAny): {
|
|
76
|
+
a: delta.DeltaBuilder<any, false> | null;
|
|
77
|
+
b: delta.DeltaBuilder<any, false> | null;
|
|
78
|
+
isEmpty(): boolean;
|
|
79
|
+
clear(): void;
|
|
80
|
+
applyA(a: delta.DeltaBuilder<any, false> | null): /*elided*/ any;
|
|
81
|
+
applyB(b: delta.DeltaBuilder<any, false> | null): /*elided*/ any;
|
|
82
|
+
reverse(): /*elided*/ any;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* @param {delta.DeltaBuilderAny} deltaB
|
|
86
|
+
*/
|
|
87
|
+
applyB(deltaB: delta.DeltaBuilderAny): {
|
|
88
|
+
a: delta.DeltaBuilder<any, false> | null;
|
|
89
|
+
b: delta.DeltaBuilder<any, false> | null;
|
|
90
|
+
isEmpty(): boolean;
|
|
91
|
+
clear(): void;
|
|
92
|
+
applyA(a: delta.DeltaBuilder<any, false> | null): /*elided*/ any;
|
|
93
|
+
applyB(b: delta.DeltaBuilder<any, false> | null): /*elided*/ any;
|
|
94
|
+
reverse(): /*elided*/ any;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export function filter<DConf extends delta.DeltaConf>($d: import("../../schema.js").Schema<delta.Delta<DConf>>): Filter<DConf>;
|
|
98
|
+
export type Template = import("./core.js").Template;
|
|
99
|
+
export type ApplyExpectType<DConf extends delta.DeltaConf, IN extends delta.DeltaConf> = delta.AsDeltaConf<{ [K in keyof DConf & keyof IN]: K extends "attrs" ? import("../../ts.js").PropsPickShared<DConf[K], IN[K]> : (DConf[K] & IN[K]); }>;
|
|
100
|
+
import * as delta from '../delta.js';
|
|
101
|
+
import * as s from '../../schema.js';
|
|
102
|
+
import { Transformer } from './core.js';
|
|
103
|
+
//# sourceMappingURL=filter.d.ts.map
|