@homeostate/core 0.0.0 → 0.1.1
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/CHANGELOG.md +7 -0
- package/README.md +34 -4
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/apply.d.ts +37 -0
- package/dist/apply.d.ts.map +1 -0
- package/dist/apply.js +58 -0
- package/dist/apply.js.map +1 -0
- package/dist/change.d.ts +6 -3
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +0 -2
- package/dist/change.js.map +1 -1
- package/dist/diff.d.ts +2 -3
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.js +156 -166
- package/dist/diff.js.map +1 -1
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/memory-backend.d.ts +11 -0
- package/dist/memory-backend.d.ts.map +1 -0
- package/dist/memory-backend.js +26 -0
- package/dist/memory-backend.js.map +1 -0
- package/dist/patching.d.ts +6 -16
- package/dist/patching.d.ts.map +1 -1
- package/dist/patching.js +46 -137
- package/dist/patching.js.map +1 -1
- package/dist/sync-engine.d.ts +14 -8
- package/dist/sync-engine.d.ts.map +1 -1
- package/dist/sync-engine.js +67 -93
- package/dist/sync-engine.js.map +1 -1
- package/dist/types.d.ts +42 -16
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -3
- package/dist/types.js.map +1 -1
- package/package.json +4 -10
- package/dist/mapping.d.ts +0 -19
- package/dist/mapping.d.ts.map +0 -1
- package/dist/mapping.js +0 -45
- package/dist/mapping.js.map +0 -1
package/dist/sync-engine.js
CHANGED
|
@@ -1,136 +1,110 @@
|
|
|
1
|
-
import { defaultSyncFilter } from
|
|
2
|
-
import {
|
|
1
|
+
import { defaultSyncFilter } from "./types.js";
|
|
2
|
+
import { patchState } from "./patching.js";
|
|
3
3
|
/**
|
|
4
|
-
* Creates a sync engine that
|
|
5
|
-
*
|
|
4
|
+
* Creates a sync engine that keeps a store (via its adapter) and a CRDT backend
|
|
5
|
+
* in sync in both directions.
|
|
6
6
|
*
|
|
7
|
-
* This is the core abstraction that makes the sync logic state-manager
|
|
7
|
+
* This is the core abstraction that makes the sync logic state-manager and
|
|
8
|
+
* CRDT-library agnostic.
|
|
9
|
+
*
|
|
10
|
+
* On `connect()` the two sides are reconciled per key over the filtered view: a key the
|
|
11
|
+
* backend holds wins over the store's value, and a synced key the backend lacks stays in
|
|
12
|
+
* the store and is seeded into the backend unless `seed` is `'never'`. Afterwards the
|
|
13
|
+
* backend owns the synced document: every write replaces it with the store's filtered
|
|
14
|
+
* state, and a key removed from the backend is removed from the store.
|
|
8
15
|
*
|
|
9
16
|
* @example
|
|
10
17
|
* ```typescript
|
|
11
|
-
* const
|
|
18
|
+
* const backend = createYjsBackend(new Y.Doc(), 'shared');
|
|
12
19
|
* const adapter = new ZustandAdapter(store);
|
|
13
|
-
* const engine = createSyncEngine(
|
|
20
|
+
* const engine = createSyncEngine(backend, adapter);
|
|
14
21
|
* engine.connect();
|
|
15
22
|
* ```
|
|
16
23
|
*/
|
|
17
|
-
export function createSyncEngine(
|
|
18
|
-
const {
|
|
19
|
-
// The root Y.Map that the store is written and read from
|
|
20
|
-
const yMap = doc.getMap(name);
|
|
24
|
+
export function createSyncEngine(backend, adapter, config = {}) {
|
|
25
|
+
const { filter = defaultSyncFilter, seed = "if-empty" } = config;
|
|
21
26
|
let connected = false;
|
|
22
27
|
let storeUnsubscribe = null;
|
|
23
|
-
let
|
|
24
|
-
let
|
|
25
|
-
/**
|
|
26
|
-
* Filter state to only include syncable properties
|
|
27
|
-
*/
|
|
28
|
+
let backendUnsubscribe = null;
|
|
29
|
+
let applyingRemote = false;
|
|
28
30
|
const filterState = (state) => {
|
|
29
|
-
if (typeof state !== 'object' || state === null) {
|
|
30
|
-
return state;
|
|
31
|
-
}
|
|
32
31
|
const filtered = {};
|
|
33
32
|
for (const [key, value] of Object.entries(state)) {
|
|
34
|
-
if (filter(key, value))
|
|
33
|
+
if (filter(key, value))
|
|
35
34
|
filtered[key] = value;
|
|
36
|
-
}
|
|
37
35
|
}
|
|
38
36
|
return filtered;
|
|
39
37
|
};
|
|
38
|
+
const readBackend = () => {
|
|
39
|
+
const value = backend.read();
|
|
40
|
+
return value !== null && typeof value === "object" ? value : {};
|
|
41
|
+
};
|
|
40
42
|
/**
|
|
41
|
-
*
|
|
43
|
+
* Builds the next store state from `remote`. With `keepLocalOnly`, a synced key the
|
|
44
|
+
* backend does not hold is left in place instead of being deleted; that is the
|
|
45
|
+
* connect-time reconciliation. Otherwise `remote` is the whole synced state.
|
|
42
46
|
*/
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
finally {
|
|
55
|
-
isUpdatingFromStore = false;
|
|
47
|
+
const mergeStates = (current, remote, keepLocalOnly) => {
|
|
48
|
+
const synced = filterState(current);
|
|
49
|
+
const target = keepLocalOnly ? { ...synced, ...remote } : remote;
|
|
50
|
+
const patched = patchState(synced, target);
|
|
51
|
+
if (patched === synced)
|
|
52
|
+
return current;
|
|
53
|
+
const merged = { ...current, ...patched };
|
|
54
|
+
for (const key of Object.keys(synced)) {
|
|
55
|
+
if (!(key in patched))
|
|
56
|
+
delete merged[key];
|
|
56
57
|
}
|
|
58
|
+
return merged;
|
|
57
59
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
*/
|
|
61
|
-
const syncToStore = () => {
|
|
62
|
-
if (isUpdatingFromStore)
|
|
60
|
+
const syncToBackend = () => {
|
|
61
|
+
if (applyingRemote)
|
|
63
62
|
return;
|
|
64
|
-
|
|
63
|
+
backend.write(filterState(adapter.getState()));
|
|
64
|
+
};
|
|
65
|
+
const applyRemote = (remote, keepLocalOnly) => {
|
|
66
|
+
applyingRemote = true;
|
|
65
67
|
try {
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
adapter.setState(mergedState, true);
|
|
68
|
+
const current = adapter.getState();
|
|
69
|
+
const merged = mergeStates(current, remote, keepLocalOnly);
|
|
70
|
+
if (merged !== current)
|
|
71
|
+
adapter.setState(merged);
|
|
71
72
|
}
|
|
72
73
|
finally {
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Merge Yjs state with current store state, preserving non-syncable properties
|
|
78
|
-
*/
|
|
79
|
-
const mergeStates = (current, fromYjs) => {
|
|
80
|
-
if (typeof current !== 'object' || current === null) {
|
|
81
|
-
return fromYjs;
|
|
82
|
-
}
|
|
83
|
-
const currentObj = current;
|
|
84
|
-
const yjsObj = fromYjs;
|
|
85
|
-
// Start with current state (preserves functions, etc.)
|
|
86
|
-
const merged = { ...currentObj };
|
|
87
|
-
// Apply Yjs state using patching for proper deep merging
|
|
88
|
-
const patchedData = patchState({ ...merged }, yjsObj);
|
|
89
|
-
// Restore non-syncable properties (like functions)
|
|
90
|
-
for (const [key, value] of Object.entries(currentObj)) {
|
|
91
|
-
if (!filter(key, value)) {
|
|
92
|
-
patchedData[key] = value;
|
|
93
|
-
}
|
|
74
|
+
applyingRemote = false;
|
|
94
75
|
}
|
|
95
|
-
return patchedData;
|
|
96
76
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*/
|
|
100
|
-
const handleYjsChange = () => {
|
|
101
|
-
syncToStore();
|
|
77
|
+
const syncToStore = () => {
|
|
78
|
+
applyRemote(filterState(readBackend()), false);
|
|
102
79
|
};
|
|
103
80
|
return {
|
|
104
81
|
connect: () => {
|
|
105
82
|
if (connected)
|
|
106
83
|
return;
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
84
|
+
const remote = filterState(readBackend());
|
|
85
|
+
const local = filterState(adapter.getState());
|
|
86
|
+
const remoteKeys = new Set(Object.keys(remote));
|
|
87
|
+
const missing = Object.keys(local).filter((key) => !remoteKeys.has(key));
|
|
88
|
+
if (seed === "if-empty" && missing.length > 0) {
|
|
89
|
+
const seeded = { ...remote };
|
|
90
|
+
for (const key of missing)
|
|
91
|
+
seeded[key] = local[key];
|
|
92
|
+
backend.write(seeded);
|
|
93
|
+
}
|
|
94
|
+
applyRemote(remote, true);
|
|
95
|
+
backendUnsubscribe = backend.subscribe(syncToStore);
|
|
96
|
+
storeUnsubscribe = adapter.subscribe(syncToBackend);
|
|
119
97
|
connected = true;
|
|
120
98
|
},
|
|
121
99
|
disconnect: () => {
|
|
122
100
|
if (!connected)
|
|
123
101
|
return;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
storeUnsubscribe();
|
|
129
|
-
storeUnsubscribe = null;
|
|
130
|
-
}
|
|
102
|
+
backendUnsubscribe?.();
|
|
103
|
+
backendUnsubscribe = null;
|
|
104
|
+
storeUnsubscribe?.();
|
|
105
|
+
storeUnsubscribe = null;
|
|
131
106
|
connected = false;
|
|
132
107
|
},
|
|
133
|
-
getYMap: () => yMap,
|
|
134
108
|
isConnected: () => connected,
|
|
135
109
|
};
|
|
136
110
|
}
|
package/dist/sync-engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-engine.js","sourceRoot":"","sources":["../src/sync-engine.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"sync-engine.js","sourceRoot":"","sources":["../src/sync-engine.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C;;;;;;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
|
2
|
+
* Core types for the state-manager and CRDT-backend agnostic sync engine.
|
|
3
|
+
* These interfaces let any store be kept in sync through any replicated backend.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Unsubscribe function returned by subscribe
|
|
@@ -9,47 +9,73 @@ export type Unsubscribe = () => void;
|
|
|
9
9
|
/**
|
|
10
10
|
* Adapter interface that bridges a specific state manager with the sync engine.
|
|
11
11
|
* Implement this interface to add support for any state manager (Zustand, Redux, MobX, etc.)
|
|
12
|
+
*
|
|
13
|
+
* State must be plain JSON: objects, arrays, strings, numbers, booleans, and null.
|
|
14
|
+
* Functions are dropped by the default filter; other values such as Date, Map, or Set
|
|
15
|
+
* are neither diffed nor synced.
|
|
12
16
|
*/
|
|
13
|
-
export interface StoreAdapter<S> {
|
|
17
|
+
export interface StoreAdapter<S extends object> {
|
|
14
18
|
/** Get the current state from the store */
|
|
15
19
|
getState: () => S;
|
|
16
20
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
21
|
+
* Replace the store state. Called only for changes coming from the backend; the
|
|
22
|
+
* engine ignores store notifications raised while it runs, so the adapter needs no
|
|
23
|
+
* echo suppression of its own.
|
|
20
24
|
*/
|
|
21
|
-
setState: (state: S
|
|
25
|
+
setState: (state: S) => void;
|
|
22
26
|
/**
|
|
23
|
-
* Subscribe to store changes that should
|
|
27
|
+
* Subscribe to store changes that should be written to the backend.
|
|
24
28
|
* @returns Unsubscribe function
|
|
25
29
|
*/
|
|
26
30
|
subscribe: (onStoreChange: () => void) => Unsubscribe;
|
|
27
|
-
/** Get the initial state of the store */
|
|
28
|
-
getInitialState: () => S;
|
|
29
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Backend that holds the synced subtree in a CRDT or any other replicated store.
|
|
34
|
+
* The engine only ever exchanges plain JSON with it.
|
|
35
|
+
*/
|
|
36
|
+
export interface CrdtBackend {
|
|
37
|
+
/** Plain JSON snapshot of the synced subtree. Must not alias backend internals. */
|
|
38
|
+
read: () => unknown;
|
|
39
|
+
/**
|
|
40
|
+
* Make the backend equal to `next` in one atomic transaction.
|
|
41
|
+
* The backend decides the granularity of the operations; `getChanges` is exported for that.
|
|
42
|
+
*/
|
|
43
|
+
write: (next: unknown) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Notify about changes that did not come through this backend's own `write`.
|
|
46
|
+
* @returns Unsubscribe function
|
|
47
|
+
*/
|
|
48
|
+
subscribe: (onRemoteChange: () => void) => Unsubscribe;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Whether `connect()` may write the store's synced keys that the backend does not hold.
|
|
52
|
+
* Reconciliation is per key over the filtered view: a key the backend holds always wins
|
|
53
|
+
* over the store's value, a key only the store holds always stays in the store.
|
|
54
|
+
* - `'if-empty'`: seed the keys the backend lacks, in one write (default)
|
|
55
|
+
* - `'never'`: leave seeding to the caller; the keys are written on the next local change
|
|
56
|
+
*/
|
|
57
|
+
export type SeedStrategy = "if-empty" | "never";
|
|
30
58
|
/**
|
|
31
59
|
* Configuration options for the sync engine
|
|
32
60
|
*/
|
|
33
61
|
export interface SyncEngineConfig {
|
|
34
|
-
/** Name of the Y.Map in the Y.Doc to store the state */
|
|
35
|
-
name: string;
|
|
36
62
|
/**
|
|
37
|
-
* Filter function to determine which state keys should be synced.
|
|
63
|
+
* Filter function to determine which state keys should be synced, in both directions.
|
|
38
64
|
* Return true to sync the key, false to exclude it.
|
|
39
65
|
* By default, functions are excluded from sync.
|
|
40
66
|
*/
|
|
41
67
|
filter?: (key: string, value: unknown) => boolean;
|
|
68
|
+
/** Seeding strategy used by `connect()`; defaults to `'if-empty'` */
|
|
69
|
+
seed?: SeedStrategy;
|
|
42
70
|
}
|
|
43
71
|
/**
|
|
44
|
-
* The sync engine interface - manages bidirectional sync between store and
|
|
72
|
+
* The sync engine interface - manages bidirectional sync between a store and a backend
|
|
45
73
|
*/
|
|
46
74
|
export interface SyncEngine {
|
|
47
75
|
/** Start synchronization */
|
|
48
76
|
connect: () => void;
|
|
49
77
|
/** Stop synchronization and cleanup */
|
|
50
78
|
disconnect: () => void;
|
|
51
|
-
/** Get the underlying Y.Map */
|
|
52
|
-
getYMap: () => unknown;
|
|
53
79
|
/** Check if engine is connected */
|
|
54
80
|
isConnected: () => boolean;
|
|
55
81
|
}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC;AAErC;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,MAAM;IAC5C,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC,CAAC;IAElB;;;;OAIG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAE7B;;;OAGG;IACH,SAAS,EAAE,CAAC,aAAa,EAAE,MAAM,IAAI,KAAK,WAAW,CAAC;CACvD;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,mFAAmF;IACnF,IAAI,EAAE,MAAM,OAAO,CAAC;IAEpB;;;OAGG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IAE/B;;;OAGG;IACH,SAAS,EAAE,CAAC,cAAc,EAAE,MAAM,IAAI,KAAK,WAAW,CAAC;CACxD;AAED;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,OAAO,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IAClD,qEAAqE;IACrE,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,4BAA4B;IAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,uCAAuC;IACvC,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,mCAAmC;IACnC,WAAW,EAAE,MAAM,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,EAAE,OAAO,OAAO,KAAG,OAEhE,CAAC"}
|
package/dist/types.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Core types for the state-manager agnostic
|
|
3
|
-
* These interfaces
|
|
2
|
+
* Core types for the state-manager and CRDT-backend agnostic sync engine.
|
|
3
|
+
* These interfaces let any store be kept in sync through any replicated backend.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Default filter that excludes functions from sync
|
|
7
7
|
*/
|
|
8
8
|
export const defaultSyncFilter = (_key, value) => {
|
|
9
|
-
return typeof value !==
|
|
9
|
+
return typeof value !== "function";
|
|
10
10
|
};
|
|
11
11
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAyFH;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAE,KAAc,EAAW,EAAE;IACzE,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;AACrC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homeostate/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "State-manager agnostic sync engine between a store adapter and a
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "State-manager and CRDT-backend agnostic sync engine between a store adapter and a CrdtBackend",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"url": "https://github.com/mixedrays/homeostate/issues"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
|
-
"yjs",
|
|
18
17
|
"crdt",
|
|
19
18
|
"sync",
|
|
20
19
|
"state-management",
|
|
@@ -32,17 +31,12 @@
|
|
|
32
31
|
"dist",
|
|
33
32
|
"README.md",
|
|
34
33
|
"LICENSE",
|
|
35
|
-
"THIRD_PARTY_NOTICES.md"
|
|
34
|
+
"THIRD_PARTY_NOTICES.md",
|
|
35
|
+
"CHANGELOG.md"
|
|
36
36
|
],
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"peerDependencies": {
|
|
41
|
-
"yjs": "^13.6.0"
|
|
42
|
-
},
|
|
43
|
-
"devDependencies": {
|
|
44
|
-
"yjs": "^13.6.23"
|
|
45
|
-
},
|
|
46
40
|
"scripts": {
|
|
47
41
|
"build": "tsc -b"
|
|
48
42
|
}
|
package/dist/mapping.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as Y from 'yjs';
|
|
2
|
-
/**
|
|
3
|
-
* Converts a normal JavaScript array to a YArray shared type. Any nested
|
|
4
|
-
* objects or arrays are turned into YMaps and YArrays, respectively.
|
|
5
|
-
*
|
|
6
|
-
* @param array The array to transform into a YArray
|
|
7
|
-
* @returns A YArray.
|
|
8
|
-
*/
|
|
9
|
-
export declare const arrayToYArray: (array: unknown[]) => Y.Array<unknown>;
|
|
10
|
-
/**
|
|
11
|
-
* Converts a normal JavaScript object into a YMap shared type. Any nested
|
|
12
|
-
* objects or arrays are turned into YMaps or YArrays, respectively.
|
|
13
|
-
*
|
|
14
|
-
* @param object The object to turn into a YMap shared type.
|
|
15
|
-
* @returns A YMap.
|
|
16
|
-
*/
|
|
17
|
-
export declare const objectToYMap: (object: Record<string, unknown>) => Y.Map<unknown>;
|
|
18
|
-
export declare const stringToYText: (string: string) => Y.Text;
|
|
19
|
-
//# sourceMappingURL=mapping.d.ts.map
|
package/dist/mapping.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,EAAE,KAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAW/D,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,CAAC,CAAC,GAAG,CAAC,OAAO,CAW3E,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,KAAG,CAAC,CAAC,IAA0B,CAAC"}
|
package/dist/mapping.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import * as Y from 'yjs';
|
|
2
|
-
/**
|
|
3
|
-
* Converts a normal JavaScript array to a YArray shared type. Any nested
|
|
4
|
-
* objects or arrays are turned into YMaps and YArrays, respectively.
|
|
5
|
-
*
|
|
6
|
-
* @param array The array to transform into a YArray
|
|
7
|
-
* @returns A YArray.
|
|
8
|
-
*/
|
|
9
|
-
export const arrayToYArray = (array) => {
|
|
10
|
-
const yarray = new Y.Array();
|
|
11
|
-
array.forEach((value) => {
|
|
12
|
-
if (value instanceof Array)
|
|
13
|
-
yarray.push([arrayToYArray(value)]);
|
|
14
|
-
else if (value !== null && typeof value === 'object')
|
|
15
|
-
yarray.push([objectToYMap(value)]);
|
|
16
|
-
else if (typeof value === 'string')
|
|
17
|
-
yarray.push([stringToYText(value)]);
|
|
18
|
-
else
|
|
19
|
-
yarray.push([value]);
|
|
20
|
-
});
|
|
21
|
-
return yarray;
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Converts a normal JavaScript object into a YMap shared type. Any nested
|
|
25
|
-
* objects or arrays are turned into YMaps or YArrays, respectively.
|
|
26
|
-
*
|
|
27
|
-
* @param object The object to turn into a YMap shared type.
|
|
28
|
-
* @returns A YMap.
|
|
29
|
-
*/
|
|
30
|
-
export const objectToYMap = (object) => {
|
|
31
|
-
const ymap = new Y.Map();
|
|
32
|
-
Object.entries(object).forEach(([property, value]) => {
|
|
33
|
-
if (value instanceof Array)
|
|
34
|
-
ymap.set(property, arrayToYArray(value));
|
|
35
|
-
else if (value !== null && typeof value === 'object')
|
|
36
|
-
ymap.set(property, objectToYMap(value));
|
|
37
|
-
else if (typeof value === 'string')
|
|
38
|
-
ymap.set(property, stringToYText(value));
|
|
39
|
-
else
|
|
40
|
-
ymap.set(property, value);
|
|
41
|
-
});
|
|
42
|
-
return ymap;
|
|
43
|
-
};
|
|
44
|
-
export const stringToYText = (string) => new Y.Text(string);
|
|
45
|
-
//# sourceMappingURL=mapping.js.map
|
package/dist/mapping.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mapping.js","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAgB,EAAoB,EAAE;IAClE,MAAM,MAAM,GAAG,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;IAE7B,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACtB,IAAI,KAAK,YAAY,KAAK;YAAE,MAAM,CAAC,IAAI,CAAC,CAAC,aAAa,CAAC,KAAK,C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