@openlfcp/shared-objects 0.1.0-rc.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/LICENSE ADDED
@@ -0,0 +1,201 @@
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 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 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 those 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
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # @openlfcp/shared-objects
2
+
3
+ The TypeScript implementation of
4
+ [SHARED-OBJECTS-PROFILE-01](https://github.com/openlfcp/spec/blob/main/profiles/SHARED-OBJECTS-PROFILE-01.md)
5
+ (`org.openlfcp.shared-objects.v1`):
6
+
7
+ - the Task model, intent mutators and profile validation over logical state
8
+ (LFCP-030);
9
+ - the Automerge binding `SharedObjectsReplica` (LFCP-031): one semantic intent
10
+ is one Automerge change written by the §8 actor, scalar conflicts stay
11
+ visible, tags and assignees are add-wins sets, deletion is a tombstone, and
12
+ unknown data survives every write;
13
+ - the §11 Data Unit and §13 Snapshot plaintext framing, with checks that the
14
+ framed bytes are one valid Automerge change or a full save.
15
+
16
+ LFCP verification, decryption and authorization happen before a change
17
+ reaches the replica (§95). The replica has no Markdown or editor concepts.
18
+
19
+ ## Scope
20
+
21
+ Part of the OpenLFCP TypeScript SDK, which implements the OpenLFCP MVP 0.1
22
+ subset of [LFCP-WIRE-01](https://github.com/openlfcp/spec/blob/main/wire/LFCP-WIRE-01.md)
23
+ at `mvp-0.1-baseline.8`, not every deferred WIRE-01 feature. It does not
24
+ claim full LFCP-WIRE-01 conformance. This is a release candidate
25
+ (`0.1.0-rc.1`, npm dist-tag `next`): APIs may still change.
26
+
27
+ ## Automerge and WebAssembly
28
+
29
+ The package depends on `@automerge/automerge` **3.5.0**, pinned exactly,
30
+ which is the profile's Automerge compatibility target. No other sdk-ts
31
+ package may use Automerge (`scripts/check-boundaries.mjs`).
32
+
33
+ Automerge is Rust compiled to WebAssembly. This package imports the plain
34
+ `@automerge/automerge` specifier and stays synchronous: Automerge's
35
+ conditional exports choose how each runtime loads the wasm, and the
36
+ host's bundler handles the rest.
37
+
38
+ | Runtime | Export condition | How the wasm loads |
39
+ | --- | --- | --- |
40
+ | Node.js (tests, CLI, Electron main) | `node` | Read from the package with `fs` at import time, synchronously |
41
+ | Bundlers with ESM wasm support (Vite with `vite-plugin-wasm`, webpack 5 `asyncWebAssembly`) | `browser` | Imported as a `.wasm` module by the bundler |
42
+ | webpack without wasm configuration | `webpack` | Inlined as base64 and instantiated synchronously |
43
+ | Cloudflare Workers | `workerd` | Imported as a wasm module |
44
+ | Anything else (plain ESM) | `import` | Inlined as base64 (about 4.6 MB of JavaScript), instantiated synchronously |
45
+
46
+ A host whose bundler cannot import `.wasm` files can resolve the base64
47
+ build instead, or alias `@automerge/automerge` to `@automerge/automerge/slim`.
48
+ With the slim build it must `await initializeAutomerge()` (exported here: it
49
+ imports the base64 wasm dynamically, decodes it in a few milliseconds where
50
+ Automerge's own helper takes about 200 ms, and compiles it asynchronously) before
51
+ first using this package; on every other build that call is a no-op. It is
52
+ idempotent and safe to call concurrently (one shared in-flight promise; a
53
+ failure clears it, so a later call retries). Calling any other export
54
+ before it resolves on the slim build is not guarded: the host awaits it
55
+ first (the Obsidian plugin does so in its startup, before any replica
56
+ exists). The
57
+ Obsidian plugin uses the slim build this way (LFCP-059): Chromium refuses to
58
+ compile more than 4 KB of wasm synchronously on a renderer's main thread,
59
+ which the base64 build would do.
60
+
61
+ ## Rules decided in baseline.4
62
+
63
+ These followed the reference corpus generator as provisional rules and are
64
+ normative since `mvp-0.1-baseline.4` (ADR 0003). The source cites them by
65
+ section and decision ID:
66
+
67
+ - **G-SC3** (§30): every profile string is an Automerge scalar string
68
+ (`ImmutableString`), never collaborative Text. A known field stored as Text
69
+ is `PROFILE_INVALID` / `INVALID_FIELD_TYPE`.
70
+ - **G-SC4** (§58): an intent that writes a value already present deletes it
71
+ first, so it is a real concurrent write: a re-add wins over a concurrent
72
+ removal, and a restore conflicts with a concurrent delete. Because of that delete+put, Automerge's property order differs
73
+ between the writer and receivers, so `root()` returns keys in canonical
74
+ (code-unit) order at every level: `JSON.stringify(root())` is comparable
75
+ across replicas holding the same state.
76
+ - **G-EP7** (§14.1): replica state is a deterministic function of the set of
77
+ accepted changes (`fromChanges`, `rebuildWithout`).
78
+ - **SO-SEC1** (§8, §11): a Data Unit carries only changes of its signer's §8
79
+ actor; any other is `PROFILE_INVALID` / `CHANGE_ACTOR_MISMATCH`.
80
+ - **SOG-2** (§74.1): one diagnostic per field value, the first in the table's
81
+ order, with `IMMUTABLE_FIELD_MUTATED` last (`firstPerField`).
82
+
83
+ ## Links
84
+
85
+ - Specification: [openlfcp/spec](https://github.com/openlfcp/spec)
86
+ - Source and the other SDK packages: [openlfcp/sdk-ts](https://github.com/openlfcp/sdk-ts)
87
+ - Issues: [openlfcp/sdk-ts/issues](https://github.com/openlfcp/sdk-ts/issues)
88
+
89
+ ## License
90
+
91
+ Apache-2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,37 @@
1
+ /** A checked Automerge change: its bytes and decoded header. */
2
+ export interface CheckedChange {
3
+ readonly bytes: Uint8Array;
4
+ /** Hex SHA-256 change hash (the Automerge change identity). */
5
+ readonly hash: string;
6
+ /** Hex actor ID. */
7
+ readonly actor: string;
8
+ readonly seq: number;
9
+ /** Hex hashes of the changes this one depends on. */
10
+ readonly deps: readonly string[];
11
+ /** Hex IDs of the other actors the change refers to (§11.1: each must be known to the document). */
12
+ readonly otherActors: readonly string[];
13
+ }
14
+ /**
15
+ * Checks that `bytes` is exactly one valid Automerge change (§11, §12) and
16
+ * returns it decoded. Rejects with PROFILE_INVALID / INVALID_AUTOMERGE_BYTES: a chunk that is not a
17
+ * change (a document chunk is a full save, §13), bytes Automerge cannot
18
+ * parse, trailing bytes such as a second concatenated change, and a
19
+ * checksum that does not match the change hash. Automerge JS 3.5.0 parses
20
+ * a change without verifying its checksum, so the check is done here.
21
+ */
22
+ export declare function checkChange(bytes: Uint8Array): CheckedChange;
23
+ /**
24
+ * Checks that `bytes` starts as an Automerge full save (a document chunk,
25
+ * §13). Whether the whole image loads, checksums included, is decided by
26
+ * Automerge's load.
27
+ */
28
+ export declare function checkSaveHeader(bytes: Uint8Array): void;
29
+ /** §11: the Data Unit plaintext [1, change] of one checked Automerge change. */
30
+ export declare function frameChange(change: Uint8Array): Uint8Array;
31
+ /** §11: the one Automerge change a Data Unit plaintext carries, checked. Throws PROFILE_INVALID / INVALID_AUTOMERGE_BYTES. */
32
+ export declare function unframeChange(plaintext: Uint8Array): CheckedChange;
33
+ /** §13: the Snapshot plaintext [1, save] of an Automerge full save. */
34
+ export declare function frameSnapshot(save: Uint8Array): Uint8Array;
35
+ /** §13: the Automerge full save a Snapshot plaintext carries (header checked). Throws PROFILE_INVALID / INVALID_AUTOMERGE_BYTES. */
36
+ export declare function unframeSnapshot(plaintext: Uint8Array): Uint8Array;
37
+ //# sourceMappingURL=automerge-bytes.d.ts.map
@@ -0,0 +1,95 @@
1
+ import * as A from "@automerge/automerge";
2
+ import { toHex } from "@openlfcp/core";
3
+ import { checkChangeExpansion } from "./chunk-limits.js";
4
+ import { ProfileInvalidError } from "./profile-invalid.js";
5
+ import { frameProfilePayload, unframeProfilePayload } from "./values.js";
6
+ /**
7
+ * Automerge byte checks of the SHARED-OBJECTS-PROFILE-01 payloads (LFCP-031):
8
+ * a Data Unit plaintext carries exactly one Automerge change (§11, §12), a
9
+ * Snapshot plaintext one Automerge full save (§13). The framing itself is
10
+ * frameProfilePayload / unframeProfilePayload (LFCP-030); this adds the
11
+ * check that the framed bytes are what they claim to be.
12
+ *
13
+ * Automerge storage chunks start with the magic bytes 85 6f 4a 83, a 4-byte
14
+ * checksum (the first 4 bytes of the chunk hash) and a chunk type: 0 for a
15
+ * document (a full save), 1 for a change, 2 for a compressed change.
16
+ */
17
+ const MAGIC = [0x85, 0x6f, 0x4a, 0x83];
18
+ const CHUNK_DOCUMENT = 0;
19
+ const CHUNK_CHANGE = 1;
20
+ const CHUNK_COMPRESSED_CHANGE = 2;
21
+ const HEADER = 9; // magic, checksum, chunk type
22
+ /** §11, §13, §74.1: PROFILE_INVALID / INVALID_AUTOMERGE_BYTES. */
23
+ const reject = (why) => {
24
+ throw new ProfileInvalidError("INVALID_AUTOMERGE_BYTES", why);
25
+ };
26
+ function chunkType(bytes, what) {
27
+ if (bytes.length < HEADER || MAGIC.some((b, i) => bytes[i] !== b))
28
+ return reject(`${what} is not an Automerge chunk`);
29
+ return bytes[8];
30
+ }
31
+ /**
32
+ * Checks that `bytes` is exactly one valid Automerge change (§11, §12) and
33
+ * returns it decoded. Rejects with PROFILE_INVALID / INVALID_AUTOMERGE_BYTES: a chunk that is not a
34
+ * change (a document chunk is a full save, §13), bytes Automerge cannot
35
+ * parse, trailing bytes such as a second concatenated change, and a
36
+ * checksum that does not match the change hash. Automerge JS 3.5.0 parses
37
+ * a change without verifying its checksum, so the check is done here.
38
+ */
39
+ export function checkChange(bytes) {
40
+ const type = chunkType(bytes, "the change");
41
+ if (type === CHUNK_COMPRESSED_CHANGE)
42
+ reject("a compressed Automerge change (chunk type 2): a change is uncompressed (§11)");
43
+ if (type !== CHUNK_CHANGE)
44
+ reject(`chunk type ${type} is not an Automerge change (§11)`);
45
+ // §11.1: what the change expands to and its structure, before Automerge decodes it.
46
+ const expansion = checkChangeExpansion(bytes);
47
+ let decoded;
48
+ try {
49
+ decoded = A.decodeChange(bytes);
50
+ }
51
+ catch (e) {
52
+ return reject(`invalid Automerge change bytes (§11): ${e.message}`);
53
+ }
54
+ if (toHex(bytes.subarray(4, 8)) !== decoded.hash.slice(0, 8))
55
+ reject("the Automerge change checksum does not match its hash (§11)");
56
+ return Object.freeze({
57
+ bytes: Uint8Array.from(bytes),
58
+ hash: decoded.hash,
59
+ actor: decoded.actor,
60
+ seq: decoded.seq,
61
+ deps: Object.freeze([...decoded.deps]),
62
+ otherActors: expansion.otherActors,
63
+ });
64
+ }
65
+ /**
66
+ * Checks that `bytes` starts as an Automerge full save (a document chunk,
67
+ * §13). Whether the whole image loads, checksums included, is decided by
68
+ * Automerge's load.
69
+ */
70
+ export function checkSaveHeader(bytes) {
71
+ const type = chunkType(bytes, "the Snapshot image");
72
+ if (type !== CHUNK_DOCUMENT)
73
+ reject(`chunk type ${type} is not an Automerge document (full save, §13)`);
74
+ }
75
+ /** §11: the Data Unit plaintext [1, change] of one checked Automerge change. */
76
+ export function frameChange(change) {
77
+ checkChange(change);
78
+ return frameProfilePayload(change);
79
+ }
80
+ /** §11: the one Automerge change a Data Unit plaintext carries, checked. Throws PROFILE_INVALID / INVALID_AUTOMERGE_BYTES. */
81
+ export function unframeChange(plaintext) {
82
+ return checkChange(unframeProfilePayload(plaintext));
83
+ }
84
+ /** §13: the Snapshot plaintext [1, save] of an Automerge full save. */
85
+ export function frameSnapshot(save) {
86
+ checkSaveHeader(save);
87
+ return frameProfilePayload(save);
88
+ }
89
+ /** §13: the Automerge full save a Snapshot plaintext carries (header checked). Throws PROFILE_INVALID / INVALID_AUTOMERGE_BYTES. */
90
+ export function unframeSnapshot(plaintext) {
91
+ const save = unframeProfilePayload(plaintext);
92
+ checkSaveHeader(save);
93
+ return save;
94
+ }
95
+ //# sourceMappingURL=automerge-bytes.js.map
@@ -0,0 +1,58 @@
1
+ /** The exact limits of a change (§11.1): writers stay within them, receivers reject above. */
2
+ export declare const CHANGE_LIMITS: Readonly<{
3
+ maxRows: 16384;
4
+ maxGroupSum: 262144;
5
+ maxStringBytes: number;
6
+ maxDeps: 1024;
7
+ maxActors: 1024;
8
+ }>;
9
+ /**
10
+ * The floor of a Snapshot's limits (§13.1): every receiver accepts at least
11
+ * these. A receiver MAY configure higher limits; above its own it rejects
12
+ * the Snapshot before the engine and falls back to the data round.
13
+ */
14
+ export declare const SNAPSHOT_LIMITS_FLOOR: Readonly<{
15
+ maxRows: 262144;
16
+ maxGroupSum: 262144;
17
+ maxStringBytes: number;
18
+ maxInflatedBytes: number;
19
+ maxDeps: 1024;
20
+ maxActors: 1024;
21
+ }>;
22
+ export type SnapshotLimits = typeof SNAPSHOT_LIMITS_FLOOR;
23
+ /** §11.2: no object of a document is deeper than this (the root is depth 0). */
24
+ export declare const MAX_DOCUMENT_DEPTH = 256;
25
+ /** The operation actions that create an object (§11.2): makeMap, makeList, makeText, makeTable. */
26
+ export declare const OBJECT_ACTIONS: ReadonlySet<number>;
27
+ /** What a chunk expands to (for tests and diagnostics). */
28
+ export interface ChunkExpansion {
29
+ /** The largest value count of any column (a change's op count is its action column's). */
30
+ readonly maxRows: number;
31
+ readonly groupSum: number;
32
+ readonly stringBytes: number;
33
+ /** Column data bytes after inflation (a change has no deflated columns). */
34
+ readonly columnBytes: number;
35
+ /** Each column's spec (id << 4 | deflate << 3 | type) and value count, in chunk order. */
36
+ readonly columns: readonly {
37
+ readonly spec: number;
38
+ readonly rows: number;
39
+ }[];
40
+ /** A change's other actors (hex), in order: actor index i + 1 (§11.1). Empty for a Snapshot. */
41
+ readonly otherActors: readonly string[];
42
+ /** A Snapshot's deepest object (§11.2); 0 for a change (its depths depend on the document). */
43
+ readonly maxDepth: number;
44
+ }
45
+ /**
46
+ * §11.1: checks an uncompressed change chunk (type 1) against the exact
47
+ * change limits before the engine sees it. Throws PROFILE_INVALID /
48
+ * INVALID_AUTOMERGE_BYTES; returns what it expands to.
49
+ */
50
+ export declare function checkChangeExpansion(bytes: Uint8Array): ChunkExpansion;
51
+ /**
52
+ * §13.1: checks a Snapshot's save (exactly one document chunk) against
53
+ * `limits` (at least SNAPSHOT_LIMITS_FLOOR) before the engine sees it,
54
+ * inflating deflated columns under a running cap. Throws PROFILE_INVALID /
55
+ * INVALID_AUTOMERGE_BYTES.
56
+ */
57
+ export declare function checkSnapshotExpansion(bytes: Uint8Array, limits?: SnapshotLimits): ChunkExpansion;
58
+ //# sourceMappingURL=chunk-limits.d.ts.map