@texaryn/collaboration-yjs 0.0.0-stage → 0.1.0

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 ADDED
@@ -0,0 +1,13 @@
1
+ # @texaryn/collaboration-yjs
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2c2786f: Add an optional Yjs adapter for convergent scalar field editing, with runtime mutation observation, command guards, and atomic remote snapshots.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [2c2786f]
12
+ - Updated dependencies [2c2786f]
13
+ - @texaryn/core@0.15.0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2024-2026 Hamza Hamidi
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,57 @@
1
- # Temporary Holding Version
1
+ # @texaryn/collaboration-yjs
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Optional Yjs support for collaborative scalar field editing in Texaryn forms.
4
+ The application owns the `Y.Doc`, provider, authentication, and persistence.
5
+
6
+ Install both packages:
7
+
8
+ ```bash
9
+ pnpm add @texaryn/collaboration-yjs yjs
10
+ ```
11
+
12
+ ## Scope
13
+
14
+ The adapter shares edits to existing scalar fields. It stores an immutable
15
+ baseline snapshot and scalar overrides addressed by JSON Pointer. Concurrent
16
+ edits at different pointers merge. Concurrent edits at the same pointer use
17
+ Yjs map conflict resolution.
18
+
19
+ Array lengths and object properties stay fixed for the session. `Reset`,
20
+ `InsertItem`, `RemoveItem`, `MoveItem`, and object or array replacement are
21
+ rejected. Array controls are disabled while connected. Use
22
+ `initialization: 'none'` so conditional branch changes do not create local
23
+ defaults that are missing from the shared representation.
24
+
25
+ The host supplied `schemaVersion` must change whenever the schema, dialect,
26
+ UI hints, initialization policy, or collaboration format changes. A mismatch
27
+ stops the binding without disposing the host's Yjs document.
28
+
29
+ ## Attach a form
30
+
31
+ Create one Yjs document for the form, attach the provider you chose, then bind
32
+ the runtime:
33
+
34
+ ```ts
35
+ import * as Y from 'yjs'
36
+ import { createYjsFormSession } from '@texaryn/collaboration-yjs'
37
+
38
+ const doc = new Y.Doc()
39
+ const session = createYjsFormSession(runtime, {
40
+ doc,
41
+ schemaVersion: 'profile-form:3',
42
+ onCommandRejected(error) {
43
+ console.warn(error.message)
44
+ },
45
+ })
46
+
47
+ const result = session.status.getSnapshot()
48
+ if (result.status === 'failed') throw result.error
49
+
50
+ // When the form closes:
51
+ session.close()
52
+ doc.destroy()
53
+ ```
54
+
55
+ The session does not create or connect a network provider. It removes its own
56
+ observers and runtime hooks when closed and leaves the `Y.Doc` available to its
57
+ owner.
@@ -0,0 +1,27 @@
1
+ import type { FormRuntime, Store } from '@texaryn/core';
2
+ import * as Y from 'yjs';
3
+ export type YjsFormSessionStatus = {
4
+ status: 'connecting';
5
+ } | {
6
+ status: 'ready';
7
+ lastCommandRejection?: string;
8
+ lastNotificationError?: Error;
9
+ } | {
10
+ status: 'failed';
11
+ error: Error;
12
+ } | {
13
+ status: 'closed';
14
+ };
15
+ export interface YjsFormSessionOptions {
16
+ doc: Y.Doc;
17
+ schemaVersion: string;
18
+ documentKey?: string;
19
+ onCommandRejected?: (error: Error) => void;
20
+ onNotificationError?: (error: Error) => void;
21
+ }
22
+ export interface YjsFormSession {
23
+ readonly status: Store<YjsFormSessionStatus>;
24
+ close(): void;
25
+ }
26
+ export declare function createYjsFormSession(runtime: FormRuntime, options: YjsFormSessionOptions): YjsFormSession;
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAgB,WAAW,EAAsC,KAAK,EAAE,MAAM,eAAe,CAAA;AACzG,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAiBxB,MAAM,MAAM,oBAAoB,GAC5B;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,GACxB;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAAC,qBAAqB,CAAC,EAAE,KAAK,CAAA;CAAE,GACjF;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAClC;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,CAAA;AAExB,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAA;IACV,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAC1C,mBAAmB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;CAC7C;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,oBAAoB,CAAC,CAAA;IAC5C,KAAK,IAAI,IAAI,CAAA;CACd;AAgMD,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,qBAAqB,GAC7B,cAAc,CA8MhB"}
package/dist/index.js ADDED
@@ -0,0 +1,404 @@
1
+ import { createStore, getAtPointer, parsePointer, RemoteSnapshotNotificationError, setAtPointer, } from '@texaryn/core';
2
+ import * as Y from 'yjs';
3
+ const DEFAULT_DOCUMENT_KEY = 'texaryn-form-v1';
4
+ const MANIFEST_KEY = 'manifest';
5
+ const VALUE_PREFIX = 'value:';
6
+ const MAX_JSON_DEPTH = 64;
7
+ const MAX_JSON_VALUES = 100_000;
8
+ const MAX_ARRAY_ITEMS = 10_000;
9
+ const MAX_TOTAL_STRING_LENGTH = 1_000_000;
10
+ const MAX_OVERRIDES = 10_000;
11
+ function errorOf(value) {
12
+ return value instanceof Error ? value : new Error(String(value));
13
+ }
14
+ function isRecord(value) {
15
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
16
+ return false;
17
+ const prototype = Object.getPrototypeOf(value);
18
+ return prototype === Object.prototype || prototype === null;
19
+ }
20
+ function isScalar(value) {
21
+ return value === null || typeof value === 'string' || typeof value === 'boolean' ||
22
+ (typeof value === 'number' && Number.isFinite(value));
23
+ }
24
+ function cloneJson(value, budget, depth = 0, pointer = '') {
25
+ const state = budget ?? {
26
+ values: 0,
27
+ stringLength: 0,
28
+ active: new WeakSet(),
29
+ };
30
+ state.values++;
31
+ if (state.values > MAX_JSON_VALUES || depth > MAX_JSON_DEPTH) {
32
+ throw new Error(`Shared JSON exceeds the supported size or depth at "${pointer}".`);
33
+ }
34
+ if (isScalar(value)) {
35
+ if (typeof value === 'string') {
36
+ state.stringLength += value.length;
37
+ if (state.stringLength > MAX_TOTAL_STRING_LENGTH) {
38
+ throw new Error('Shared JSON exceeds the supported string size.');
39
+ }
40
+ }
41
+ return value;
42
+ }
43
+ if (typeof value !== 'object' || value === null) {
44
+ throw new Error(`Shared state contains a non-JSON value at "${pointer}".`);
45
+ }
46
+ if (state.active.has(value))
47
+ throw new Error('Shared state contains a cycle.');
48
+ state.active.add(value);
49
+ if (Array.isArray(value)) {
50
+ if (value.length > MAX_ARRAY_ITEMS || Object.getOwnPropertySymbols(value).length > 0 ||
51
+ Object.getOwnPropertyNames(value).length !== value.length + 1) {
52
+ throw new Error(`Shared array exceeds its supported shape at "${pointer}".`);
53
+ }
54
+ const result = [];
55
+ for (let index = 0; index < value.length; index++) {
56
+ if (!Object.hasOwn(value, index))
57
+ throw new Error(`Shared state contains a sparse array at "${pointer}".`);
58
+ const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
59
+ if (!descriptor?.enumerable || !('value' in descriptor)) {
60
+ throw new Error(`Shared state contains an accessor at "${pointer}/${index}".`);
61
+ }
62
+ result.push(cloneJson(descriptor.value, state, depth + 1, `${pointer}/${index}`));
63
+ }
64
+ state.active.delete(value);
65
+ return result;
66
+ }
67
+ if (!isRecord(value) || Object.getOwnPropertySymbols(value).length > 0 ||
68
+ Object.getOwnPropertyNames(value).length !== Object.keys(value).length) {
69
+ throw new Error(`Shared state contains a non-JSON object at "${pointer}".`);
70
+ }
71
+ const result = {};
72
+ for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
73
+ if (!descriptor.enumerable)
74
+ continue;
75
+ if (!('value' in descriptor))
76
+ throw new Error(`Shared state contains an accessor at "${pointer}/${key}".`);
77
+ state.stringLength += key.length;
78
+ if (state.stringLength > MAX_TOTAL_STRING_LENGTH) {
79
+ throw new Error('Shared JSON exceeds the supported string size.');
80
+ }
81
+ Object.defineProperty(result, key, {
82
+ value: cloneJson(descriptor.value, state, depth + 1, `${pointer}/${key}`),
83
+ enumerable: true,
84
+ configurable: true,
85
+ writable: true,
86
+ });
87
+ }
88
+ state.active.delete(value);
89
+ return result;
90
+ }
91
+ function escapePointerSegment(value) {
92
+ return value.replace(/~/g, '~0').replace(/\//g, '~1');
93
+ }
94
+ function canonicalPointer(pointer) {
95
+ const segments = parsePointer(pointer);
96
+ return segments.map((segment) => `/${escapePointerSegment(segment)}`).join('');
97
+ }
98
+ function assertScalarPath(baseline, pointer) {
99
+ if (pointer.length > 2048 || canonicalPointer(pointer) !== pointer) {
100
+ throw new Error(`Shared override has an invalid JSON Pointer: "${pointer}".`);
101
+ }
102
+ const value = getAtPointer(baseline, pointer);
103
+ if (!isScalar(value)) {
104
+ throw new Error(`Shared override does not address a baseline scalar: "${pointer}".`);
105
+ }
106
+ return value;
107
+ }
108
+ function assertOverrideBudget(overrides) {
109
+ if (overrides.size > MAX_OVERRIDES)
110
+ throw new Error('The shared document exceeds the override limit.');
111
+ let totalStringLength = 0;
112
+ for (const [pointer, value] of overrides) {
113
+ totalStringLength += pointer.length + (typeof value === 'string' ? value.length : 0);
114
+ if (totalStringLength > MAX_TOTAL_STRING_LENGTH) {
115
+ throw new Error('The shared document exceeds the supported override string size.');
116
+ }
117
+ }
118
+ }
119
+ function canonicalJson(value) {
120
+ if (Array.isArray(value))
121
+ return `[${value.map(canonicalJson).join(',')}]`;
122
+ if (isRecord(value)) {
123
+ return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(value[key])}`).join(',')}}`;
124
+ }
125
+ return JSON.stringify(value);
126
+ }
127
+ function readManifest(value) {
128
+ const manifest = cloneJson(value);
129
+ if (!isRecord(manifest) || manifest.protocol !== 1 || typeof manifest.schemaVersion !== 'string' ||
130
+ manifest.schemaVersion.length === 0 || !Object.hasOwn(manifest, 'baseline')) {
131
+ throw new Error('The shared document manifest is malformed or uses an unsupported protocol.');
132
+ }
133
+ const keys = Object.keys(manifest).sort();
134
+ if (keys.join(',') !== 'baseline,protocol,schemaVersion') {
135
+ throw new Error('The shared document manifest contains unsupported fields.');
136
+ }
137
+ return {
138
+ protocol: 1,
139
+ schemaVersion: manifest.schemaVersion,
140
+ baseline: manifest.baseline,
141
+ };
142
+ }
143
+ function readOverrides(root, baseline) {
144
+ const overrides = new Map();
145
+ for (const [key, value] of root.entries()) {
146
+ if (key === MANIFEST_KEY)
147
+ continue;
148
+ if (!key.startsWith(VALUE_PREFIX))
149
+ throw new Error(`The shared document contains an unsupported key: "${key}".`);
150
+ const pointer = key.slice(VALUE_PREFIX.length);
151
+ assertScalarPath(baseline, pointer);
152
+ const scalar = cloneJson(value);
153
+ if (!isScalar(scalar))
154
+ throw new Error(`Shared override is not a JSON scalar at "${pointer}".`);
155
+ overrides.set(pointer, scalar);
156
+ }
157
+ assertOverrideBudget(overrides);
158
+ return overrides;
159
+ }
160
+ function materialize(manifest, overrides) {
161
+ let data = cloneJson(manifest.baseline);
162
+ for (const [pointer, value] of overrides) {
163
+ data = setAtPointer(data, pointer, value);
164
+ }
165
+ return data;
166
+ }
167
+ function assertSharedSnapshotBudget(manifest, overrides) {
168
+ assertOverrideBudget(overrides);
169
+ cloneJson(materialize(manifest, overrides));
170
+ }
171
+ function dataMutationPointer(mutation) {
172
+ if (mutation.command?.type === 'SetValue') {
173
+ const node = mutation.beforeDocument.nodes[mutation.command.nodeId];
174
+ if (node?.type !== 'field' || node.dataPointer == null) {
175
+ throw new Error('The committed scalar edit has no field pointer.');
176
+ }
177
+ return [node.dataPointer];
178
+ }
179
+ if (mutation.command === undefined && mutation.changedPointers !== undefined) {
180
+ return [...mutation.changedPointers];
181
+ }
182
+ throw new Error('The runtime committed a data change outside the supported collaboration protocol.');
183
+ }
184
+ export function createYjsFormSession(runtime, options) {
185
+ const status = createStore({ status: 'connecting' });
186
+ const origin = {};
187
+ const documentKey = options.documentKey ?? DEFAULT_DOCUMENT_KEY;
188
+ const doc = options.doc;
189
+ const cleanups = [];
190
+ let root;
191
+ let closed = false;
192
+ let lastNotificationError;
193
+ function detach() {
194
+ for (const cleanup of cleanups.splice(0).reverse()) {
195
+ try {
196
+ cleanup();
197
+ }
198
+ catch {
199
+ continue;
200
+ }
201
+ }
202
+ }
203
+ function fail(reason) {
204
+ if (closed || status.getSnapshot().status === 'failed')
205
+ return;
206
+ const error = errorOf(reason);
207
+ closed = true;
208
+ detach();
209
+ try {
210
+ status.set({ status: 'failed', error });
211
+ }
212
+ catch {
213
+ return;
214
+ }
215
+ }
216
+ function close() {
217
+ if (closed)
218
+ return;
219
+ closed = true;
220
+ detach();
221
+ try {
222
+ status.set({ status: 'closed' });
223
+ }
224
+ catch {
225
+ return;
226
+ }
227
+ }
228
+ function reportNotificationError(reason) {
229
+ lastNotificationError = errorOf(reason);
230
+ const current = status.getSnapshot();
231
+ if (current.status === 'ready') {
232
+ try {
233
+ status.set({
234
+ status: 'ready',
235
+ ...(current.lastCommandRejection === undefined
236
+ ? {}
237
+ : { lastCommandRejection: current.lastCommandRejection }),
238
+ lastNotificationError,
239
+ });
240
+ }
241
+ catch {
242
+ // The collaboration session stays attached even when status observers fail.
243
+ }
244
+ }
245
+ try {
246
+ options.onNotificationError?.(lastNotificationError);
247
+ }
248
+ catch {
249
+ return;
250
+ }
251
+ }
252
+ function applySharedSnapshot(data) {
253
+ try {
254
+ runtime.applyRemoteSnapshot(data, { origin });
255
+ }
256
+ catch (error) {
257
+ if (!(error instanceof RemoteSnapshotNotificationError))
258
+ throw error;
259
+ reportNotificationError(error.notificationError);
260
+ }
261
+ }
262
+ try {
263
+ if (runtime.initializationPolicy !== 'none') {
264
+ throw new Error('Yjs collaboration requires a runtime created with initialization: none.');
265
+ }
266
+ if (typeof options.schemaVersion !== 'string' || options.schemaVersion.length === 0 ||
267
+ options.schemaVersion.length > 256) {
268
+ throw new Error('schemaVersion must contain 1 to 256 characters and be supplied by the host.');
269
+ }
270
+ if (!/^[A-Za-z0-9:_-]{1,128}$/.test(documentKey)) {
271
+ throw new Error('documentKey must contain 1 to 128 letters, numbers, colons, underscores or hyphens.');
272
+ }
273
+ root = doc.getMap(documentKey);
274
+ const localBaseline = cloneJson(runtime.data.getSnapshot());
275
+ let manifest;
276
+ if (!root.has(MANIFEST_KEY)) {
277
+ if (root.size !== 0)
278
+ throw new Error('The shared document has values but no manifest.');
279
+ manifest = { protocol: 1, schemaVersion: options.schemaVersion, baseline: localBaseline };
280
+ doc.transact(() => root.set(MANIFEST_KEY, manifest), origin);
281
+ }
282
+ else {
283
+ manifest = readManifest(root.get(MANIFEST_KEY));
284
+ if (manifest.protocol !== 1 || manifest.schemaVersion !== options.schemaVersion) {
285
+ throw new Error('The shared document schema or collaboration version does not match this runtime.');
286
+ }
287
+ if (canonicalJson(manifest.baseline) !== canonicalJson(localBaseline)) {
288
+ throw new Error('The shared document baseline does not match this runtime.');
289
+ }
290
+ }
291
+ const baseline = cloneJson(manifest.baseline);
292
+ const overrides = readOverrides(root, baseline);
293
+ assertSharedSnapshotBudget(manifest, overrides);
294
+ const initialSharedData = materialize(manifest, overrides);
295
+ if (canonicalJson(initialSharedData) !== canonicalJson(localBaseline)) {
296
+ applySharedSnapshot(initialSharedData);
297
+ }
298
+ cleanups.push(runtime.lockArrayStructure());
299
+ cleanups.push(runtime.registerCommandGuard((command, context) => {
300
+ if (command.type !== 'SetValue') {
301
+ if (command.type === 'Reset' || command.type === 'InsertItem' || command.type === 'RemoveItem' ||
302
+ command.type === 'MoveItem') {
303
+ return `${command.type} is disabled while scalar collaboration is active.`;
304
+ }
305
+ return undefined;
306
+ }
307
+ const node = context.document.nodes[command.nodeId];
308
+ if (node?.type !== 'field' || node.dataPointer == null ||
309
+ node.fieldType === 'array' || node.fieldType === 'object') {
310
+ return 'Only scalar fields can be edited while collaboration is active.';
311
+ }
312
+ if (!isScalar(command.value))
313
+ return 'The shared field value must be a JSON scalar.';
314
+ try {
315
+ const baselineValue = assertScalarPath(baseline, node.dataPointer);
316
+ const overrides = readOverrides(root, baseline);
317
+ if (canonicalJson(command.value) === canonicalJson(baselineValue)) {
318
+ overrides.delete(node.dataPointer);
319
+ }
320
+ else {
321
+ overrides.set(node.dataPointer, command.value);
322
+ }
323
+ assertSharedSnapshotBudget(manifest, overrides);
324
+ }
325
+ catch (error) {
326
+ return errorOf(error).message;
327
+ }
328
+ return undefined;
329
+ }, (reason) => {
330
+ status.set({ status: 'ready', lastCommandRejection: reason });
331
+ options.onCommandRejected?.(new Error(reason));
332
+ }));
333
+ cleanups.push(runtime.subscribeMutations((mutation) => {
334
+ if (mutation.origin === origin || closed)
335
+ return;
336
+ const pointers = dataMutationPointer(mutation);
337
+ const writes = [];
338
+ for (const pointer of pointers) {
339
+ assertScalarPath(baseline, pointer);
340
+ const value = cloneJson(getAtPointer(mutation.data, pointer));
341
+ if (!isScalar(value))
342
+ throw new Error(`The committed value is not scalar at "${pointer}".`);
343
+ const previous = getAtPointer(mutation.beforeData, pointer);
344
+ if (Object.is(previous, value))
345
+ continue;
346
+ writes.push([pointer, canonicalJson(value) === canonicalJson(assertScalarPath(baseline, pointer))
347
+ ? undefined
348
+ : value]);
349
+ }
350
+ if (writes.length === 0)
351
+ return;
352
+ const candidateOverrides = readOverrides(root, baseline);
353
+ for (const [pointer, value] of writes) {
354
+ if (value === undefined)
355
+ candidateOverrides.delete(pointer);
356
+ else
357
+ candidateOverrides.set(pointer, value);
358
+ }
359
+ assertSharedSnapshotBudget(manifest, candidateOverrides);
360
+ const current = status.getSnapshot();
361
+ if (current.status === 'ready' && current.lastCommandRejection !== undefined) {
362
+ status.set({ status: 'ready' });
363
+ }
364
+ doc.transact(() => {
365
+ for (const [pointer, value] of writes) {
366
+ const key = `${VALUE_PREFIX}${pointer}`;
367
+ if (value === undefined)
368
+ root.delete(key);
369
+ else
370
+ root.set(key, value);
371
+ }
372
+ }, origin);
373
+ }, fail));
374
+ const observer = (_event, transaction) => {
375
+ if (transaction.origin === origin || closed)
376
+ return;
377
+ try {
378
+ const currentManifest = readManifest(root.get(MANIFEST_KEY));
379
+ if (currentManifest.schemaVersion !== manifest.schemaVersion ||
380
+ canonicalJson(currentManifest.baseline) !== canonicalJson(baseline)) {
381
+ throw new Error('The shared document manifest no longer matches this session.');
382
+ }
383
+ const currentOverrides = readOverrides(root, baseline);
384
+ assertSharedSnapshotBudget(currentManifest, currentOverrides);
385
+ const sharedData = materialize(currentManifest, currentOverrides);
386
+ applySharedSnapshot(sharedData);
387
+ }
388
+ catch (error) {
389
+ fail(error);
390
+ }
391
+ };
392
+ root.observe(observer);
393
+ cleanups.push(() => root?.unobserve(observer));
394
+ status.set({
395
+ status: 'ready',
396
+ ...(lastNotificationError === undefined ? {} : { lastNotificationError }),
397
+ });
398
+ }
399
+ catch (error) {
400
+ fail(error);
401
+ }
402
+ return { status, close };
403
+ }
404
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,+BAA+B,EAC/B,YAAY,GACb,MAAM,eAAe,CAAA;AAEtB,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,MAAM,oBAAoB,GAAG,iBAAiB,CAAA;AAC9C,MAAM,YAAY,GAAG,UAAU,CAAA;AAC/B,MAAM,YAAY,GAAG,QAAQ,CAAA;AAC7B,MAAM,cAAc,GAAG,EAAE,CAAA;AACzB,MAAM,eAAe,GAAG,OAAO,CAAA;AAC/B,MAAM,eAAe,GAAG,MAAM,CAAA;AAC9B,MAAM,uBAAuB,GAAG,SAAS,CAAA;AACzC,MAAM,aAAa,GAAG,MAAM,CAAA;AA2B5B,SAAS,OAAO,CAAC,KAAc;IA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AA;YACjC,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,KAAK,CAAC,CAAA;YACb,CAAC;QACH,CAAC,CAAA;QACD,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QACtB,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAA;QAC9C,MAAM,CAAC,GAAG,CAAC;YACT,MAAM,EAAE,OAAO;YACf,GAAG,CAAC,qBAAqB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,qBAAqB,EAAE,CAAC;SAC1E,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,KAAK,CAAC,CAAA;IACb,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAA;AAC1B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@texaryn/collaboration-yjs",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Optional Yjs collaboration for scalar fields in Texaryn forms",
5
+ "keywords": [
6
+ "yjs",
7
+ "collaboration",
8
+ "json-schema",
9
+ "forms",
10
+ "texaryn"
11
+ ],
12
+ "type": "module",
13
+ "license": "Apache-2.0",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/texaryn/texaryn.git",
17
+ "directory": "packages/collaboration-yjs"
18
+ },
19
+ "homepage": "https://texaryn.github.io/texaryn/",
20
+ "bugs": {
21
+ "url": "https://github.com/texaryn/texaryn/issues"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "main": "./dist/index.js",
27
+ "types": "./dist/index.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "CHANGELOG.md"
37
+ ],
38
+ "dependencies": {
39
+ "@texaryn/core": "^0.15.0"
40
+ },
41
+ "peerDependencies": {
42
+ "yjs": "^13.6.33"
43
+ },
44
+ "devDependencies": {
45
+ "yjs": "13.6.33",
46
+ "@texaryn/schema-json": "0.8.3"
47
+ },
48
+ "scripts": {
49
+ "build": "tsc --build"
50
+ }
6
51
  }