@arden-hq/revisions 0.0.0-stage → 0.1.2

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.
Files changed (87) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +84 -2
  3. package/dist/domain/change-set.d.ts +34 -0
  4. package/dist/domain/change-set.d.ts.map +1 -0
  5. package/dist/domain/change-set.js +206 -0
  6. package/dist/domain/change-set.js.map +1 -0
  7. package/dist/domain/codec.d.ts +17 -0
  8. package/dist/domain/codec.d.ts.map +1 -0
  9. package/dist/domain/codec.js +188 -0
  10. package/dist/domain/codec.js.map +1 -0
  11. package/dist/domain/errors.d.ts +61 -0
  12. package/dist/domain/errors.d.ts.map +1 -0
  13. package/dist/domain/errors.js +44 -0
  14. package/dist/domain/errors.js.map +1 -0
  15. package/dist/domain/format.d.ts +72 -0
  16. package/dist/domain/format.d.ts.map +1 -0
  17. package/dist/domain/format.js +93 -0
  18. package/dist/domain/format.js.map +1 -0
  19. package/dist/domain/integrity.d.ts +7 -0
  20. package/dist/domain/integrity.d.ts.map +1 -0
  21. package/dist/domain/integrity.js +100 -0
  22. package/dist/domain/integrity.js.map +1 -0
  23. package/dist/domain/model.d.ts +114 -0
  24. package/dist/domain/model.d.ts.map +1 -0
  25. package/dist/domain/model.js +145 -0
  26. package/dist/domain/model.js.map +1 -0
  27. package/dist/domain/query.d.ts +31 -0
  28. package/dist/domain/query.d.ts.map +1 -0
  29. package/dist/domain/query.js +168 -0
  30. package/dist/domain/query.js.map +1 -0
  31. package/dist/domain/transaction.d.ts +26 -0
  32. package/dist/domain/transaction.d.ts.map +1 -0
  33. package/dist/domain/transaction.js +93 -0
  34. package/dist/domain/transaction.js.map +1 -0
  35. package/dist/domain/tree.d.ts +6 -0
  36. package/dist/domain/tree.d.ts.map +1 -0
  37. package/dist/domain/tree.js +59 -0
  38. package/dist/domain/tree.js.map +1 -0
  39. package/dist/effect/index.d.ts +10 -0
  40. package/dist/effect/index.d.ts.map +1 -0
  41. package/dist/effect/index.js +4 -0
  42. package/dist/effect/index.js.map +1 -0
  43. package/dist/repository/commit.d.ts +12 -0
  44. package/dist/repository/commit.d.ts.map +1 -0
  45. package/dist/repository/commit.js +164 -0
  46. package/dist/repository/commit.js.map +1 -0
  47. package/dist/repository/history.d.ts +21 -0
  48. package/dist/repository/history.d.ts.map +1 -0
  49. package/dist/repository/history.js +152 -0
  50. package/dist/repository/history.js.map +1 -0
  51. package/dist/repository/service.d.ts +114 -0
  52. package/dist/repository/service.d.ts.map +1 -0
  53. package/dist/repository/service.js +374 -0
  54. package/dist/repository/service.js.map +1 -0
  55. package/dist/repository/state.d.ts +27 -0
  56. package/dist/repository/state.d.ts.map +1 -0
  57. package/dist/repository/state.js +72 -0
  58. package/dist/repository/state.js.map +1 -0
  59. package/dist/repository/transaction.d.ts +27 -0
  60. package/dist/repository/transaction.d.ts.map +1 -0
  61. package/dist/repository/transaction.js +372 -0
  62. package/dist/repository/transaction.js.map +1 -0
  63. package/dist/storage/files.d.ts +17 -0
  64. package/dist/storage/files.d.ts.map +1 -0
  65. package/dist/storage/files.js +179 -0
  66. package/dist/storage/files.js.map +1 -0
  67. package/dist/storage/maintenance-adapter.d.ts +5 -0
  68. package/dist/storage/maintenance-adapter.d.ts.map +1 -0
  69. package/dist/storage/maintenance-adapter.js +177 -0
  70. package/dist/storage/maintenance-adapter.js.map +1 -0
  71. package/dist/storage/maintenance-reader.d.ts +17 -0
  72. package/dist/storage/maintenance-reader.d.ts.map +1 -0
  73. package/dist/storage/maintenance-reader.js +82 -0
  74. package/dist/storage/maintenance-reader.js.map +1 -0
  75. package/dist/storage/maintenance.d.ts +113 -0
  76. package/dist/storage/maintenance.d.ts.map +1 -0
  77. package/dist/storage/maintenance.js +445 -0
  78. package/dist/storage/maintenance.js.map +1 -0
  79. package/dist/storage/node.d.ts +7 -0
  80. package/dist/storage/node.d.ts.map +1 -0
  81. package/dist/storage/node.js +53 -0
  82. package/dist/storage/node.js.map +1 -0
  83. package/dist/storage/service.d.ts +88 -0
  84. package/dist/storage/service.d.ts.map +1 -0
  85. package/dist/storage/service.js +506 -0
  86. package/dist/storage/service.js.map +1 -0
  87. package/package.json +63 -4
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,85 @@
1
- # Temporary Holding Version
1
+ # `@arden-hq/revisions`
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
+ Durable, content-addressed history for files that an application manages. `@arden-hq/server` uses it.
4
+
5
+ The files stay in a normal working directory. The library keeps immutable history, stable resource IDs, atomic changes, diffs and recovery. All managed writes go through the repository.
6
+
7
+ It is smaller than Git. It has one linear history. It has no branches, remotes, staging or merges.
8
+
9
+ The one entry is `@arden-hq/revisions/effect`. It exports the `ManagedFileRepository` Effect service, `managedFileRepositoryNodeLayer` and the tagged errors. Effect is a peer dependency.
10
+
11
+ ## Example
12
+
13
+ ```ts
14
+ import { Effect } from "effect"
15
+ import { ManagedFileRepository, managedFileRepositoryNodeLayer } from "@arden-hq/revisions/effect"
16
+
17
+ const program = Effect.gen(function* () {
18
+ const revisions = yield* ManagedFileRepository
19
+ yield* revisions.commit({
20
+ actor: "editor",
21
+ origin: "desktop",
22
+ reason: "Create the guide",
23
+ expectedHead: null,
24
+ enforceExpectedHead: true,
25
+ operations: [
26
+ { _tag: "Create", resourceId: "guide", path: "docs/guide.md", content: new TextEncoder().encode("# Guide\n") }
27
+ ]
28
+ })
29
+ return yield* revisions.read("guide")
30
+ })
31
+
32
+ Effect.runPromise(program.pipe(Effect.provide(managedFileRepositoryNodeLayer({ workingRoot: "./content" }))))
33
+ ```
34
+
35
+ `resourceId` is the stable identity. `path` can change. Content is bytes. History lives in `<workingRoot>/.managed-history`.
36
+
37
+ ## Rules
38
+
39
+ - All operations in one `commit` apply together or not at all. The operations are `Create`, `Update`, `Move`, `Archive` and `Restore`.
40
+ - Every operation except `Create` names the `expectedVersion` it replaces. A stale version fails with `RevisionConflictError`.
41
+ - `expectedHead` guards the whole repository. Leave it out for no check.
42
+ - Every commit has an `idempotencyKey`. The same key with the same request returns the first commit with `replayed: true`. The same key with a different request fails with `IdempotencyConflictError`.
43
+ - `previewWorkingChanges` and `adoptWorkingChanges` turn edits made outside the library into one guarded revision. Adoption fails if anything changed after the preview.
44
+ - Reads use the current revision. Pass `at` to read an older one.
45
+ - `listResources` and `findByPath` hide archived resources unless you pass `includeArchived`.
46
+
47
+ ## Service members
48
+
49
+ | Task | Members |
50
+ | --- | --- |
51
+ | Current state | `currentRevision`, `get`, `findByPath`, `listResources` |
52
+ | Content | `read`, `readVersion`, `contentSize` |
53
+ | Writes | `commit`, `idempotencyReceipt`, `finalizeIdempotencyReceipt` |
54
+ | External edits | `previewWorkingChanges`, `adoptWorkingChanges` |
55
+ | History | `history`, `inspectCommit`, `isReachable`, `restoreFromCommit` |
56
+ | Diffs | `diff`, `diffPage`, `diffVersionsPage` |
57
+ | Maintenance | `integrityReport`, `storageReport`, `collect` |
58
+
59
+ ## Errors
60
+
61
+ Every error has a `_tag`. The union is `RevisionError`. The tags are `RevisionConflictError`, `UnsafePathError`, `InvalidRevisionInputError`, `NoChangesError`, `RevisionContentLimitError`, `IdempotencyConflictError`, `CorruptRepositoryError`, `RevisionStorageError` and `RepositoryClosedError`.
62
+
63
+ A write installs content, working files and the new revision as one recoverable step. Opening the repository finishes safe prepared steps. A rollback conflict goes to `conflicts/` for inspection. Use `integrityReport` for a full check. `currentRevision` and `isReachable` do not scan objects.
64
+
65
+ ## Limits
66
+
67
+ - Use it in Node, Bun and Electron main or utility processes. Do not use it in a browser or a renderer.
68
+ - Managed paths are relative POSIX paths. Unsafe symlinks and hardlinks are rejected.
69
+ - The storage root must be a trusted folder.
70
+ - Processes share the repository through a heartbeat lock. A second process that holds the lock makes a write fail with `RevisionConflictError`.
71
+
72
+ ## Layout
73
+
74
+ - `src/domain/` holds the model, format, validation and queries.
75
+ - `src/repository/` holds the service and its transactions.
76
+ - `src/storage/` holds the filesystem adapter, recovery and maintenance.
77
+ - `src/effect/` holds the package entry.
78
+
79
+ ## Build
80
+
81
+ ```bash
82
+ bun run build
83
+ bun run typecheck
84
+ bun run test
85
+ ```
@@ -0,0 +1,34 @@
1
+ import { Effect } from "effect";
2
+ import { ChangeSet, ResourceChange, ResourceVersion } from "./model.js";
3
+ import { CorruptRepositoryError, InvalidRevisionInputError, NoChangesError, RevisionConflictError, UnsafePathError } from "./errors.js";
4
+ import type { JsonRecord } from "./format.js";
5
+ /** The immutable resource map consumed by the pure change-set algorithms. */
6
+ export type ResourceSnapshot = ReadonlyMap<string, ResourceVersion>;
7
+ /** One active-file publication delta. */
8
+ export interface MaterializationRow {
9
+ readonly path: string;
10
+ readonly oldBlob: string | null;
11
+ readonly newBlob: string | null;
12
+ }
13
+ /** Pure result of applying one validated change set. */
14
+ export interface AppliedChangeSet {
15
+ readonly resulting: ResourceSnapshot;
16
+ readonly changes: readonly ResourceChange[];
17
+ readonly payloads: ReadonlyMap<string, Uint8Array>;
18
+ readonly rows: readonly MaterializationRow[];
19
+ }
20
+ /** Content-addressed request identities used by idempotent persistence. */
21
+ export interface RequestIdentity {
22
+ readonly request: JsonRecord;
23
+ readonly requestHash: string;
24
+ readonly keyHash: string;
25
+ }
26
+ type ChangeSetError = CorruptRepositoryError | InvalidRevisionInputError | NoChangesError | RevisionConflictError | UnsafePathError;
27
+ /** Calculate file publication rows from two materialized resource snapshots. */
28
+ export declare const materializationRows: (before: ResourceSnapshot, after: ResourceSnapshot) => Effect.Effect<readonly MaterializationRow[], RevisionConflictError, never>;
29
+ /** Apply Create/Update/Move/Archive/Restore to an immutable snapshot. */
30
+ export declare const applyChangeSet: (value: ChangeSet, current: ResourceSnapshot) => Effect.Effect<AppliedChangeSet, ChangeSetError, never>;
31
+ /** Build the deterministic request and idempotency hashes used by persistence. */
32
+ export declare const requestIdentity: (value: ChangeSet) => Effect.Effect<RequestIdentity, InvalidRevisionInputError | UnsafePathError, never>;
33
+ export {};
34
+ //# sourceMappingURL=change-set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"change-set.d.ts","sourceRoot":"","sources":["../../src/domain/change-set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AAEvC,OAAO,EACL,SAAS,EAET,cAAc,EACd,eAAe,EAGhB,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,cAAc,EACd,qBAAqB,EACrB,eAAe,EAChB,MAAM,aAAa,CAAA;AAEpB,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,aAAa,CAAA;AAIxD,6EAA6E;AAC7E,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;AAEnE,yCAAyC;AACzC,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAChC;AAED,wDAAwD;AACxD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAA;IACpC,QAAQ,CAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAA;IAC3C,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAClD,QAAQ,CAAC,IAAI,EAAE,SAAS,kBAAkB,EAAE,CAAA;CAC7C;AAED,2EAA2E;AAC3E,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAA;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB;AAED,KAAK,cAAc,GACf,sBAAsB,GACtB,yBAAyB,GACzB,cAAc,GACd,qBAAqB,GACrB,eAAe,CAAA;AAwDnB,gFAAgF;AAChF,eAAO,MAAM,mBAAmB,mIAc9B,CAAA;AAwDF,yEAAyE;AACzE,eAAO,MAAM,cAAc,yGAoGzB,CAAA;AA8BF,kFAAkF;AAClF,eAAO,MAAM,eAAe,0GAwB1B,CAAA"}
@@ -0,0 +1,206 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { ChangeSet, Operation as OperationSchema, ResourceChange, ResourceVersion, makeVersion, normalizeRelativePath } from "./model.js";
3
+ import { CorruptRepositoryError, InvalidRevisionInputError, NoChangesError, RevisionConflictError, UnsafePathError } from "./errors.js";
4
+ import { canonicalJsonl, encodeUtf8 } from "./format.js";
5
+ import { compareCodePoints } from "@arden-hq/std/json";
6
+ import { sha256Hex } from "@arden-hq/std/hash";
7
+ const failInput = (message) => Effect.fail(new InvalidRevisionInputError({ message }));
8
+ const failConflict = (message) => Effect.fail(new RevisionConflictError({ message }));
9
+ const failCorrupt = (message) => Effect.fail(new CorruptRepositoryError({ message }));
10
+ const failNoChanges = (message) => Effect.fail(new NoChangesError({ message }));
11
+ const bytesEqual = (left, right) => left.length === right.length && left.every((value, index) => value === right[index]);
12
+ const rejectAncestorCollisions = (paths) => {
13
+ const sorted = [...paths].sort(compareCodePoints);
14
+ for (const [index, path] of sorted.entries()) {
15
+ const candidate = sorted[index + 1];
16
+ if (candidate?.startsWith(`${path}/`) === true) {
17
+ return failConflict(`managed file paths overlap: ${path} and ${candidate}`);
18
+ }
19
+ }
20
+ return Effect.succeed(undefined);
21
+ };
22
+ const validateActivePaths = Effect.fn("validateActivePaths")(function* (resources) {
23
+ const paths = [...resources.values()]
24
+ .filter((version) => version.state === "active")
25
+ .map((version) => version.path);
26
+ if (new Set(paths).size !== paths.length) {
27
+ return yield* failConflict("two active resources cannot share one path");
28
+ }
29
+ yield* rejectAncestorCollisions(paths);
30
+ });
31
+ const activePathBlobs = Effect.fn("activePathBlobs")(function* (resources) {
32
+ const paths = new Map();
33
+ for (const version of resources.values()) {
34
+ if (version.state !== "active")
35
+ continue;
36
+ if (paths.has(version.path))
37
+ return yield* failConflict("two active resources cannot share one path");
38
+ paths.set(version.path, version.blobId);
39
+ }
40
+ yield* rejectAncestorCollisions(paths.keys());
41
+ return paths;
42
+ });
43
+ /** Calculate file publication rows from two materialized resource snapshots. */
44
+ export const materializationRows = Effect.fn("materializationRows")(function* (before, after) {
45
+ const oldPaths = yield* activePathBlobs(before);
46
+ const newPaths = yield* activePathBlobs(after);
47
+ const paths = [...new Set([...oldPaths.keys(), ...newPaths.keys()])].sort(compareCodePoints);
48
+ return paths
49
+ .filter((path) => oldPaths.get(path) !== newPaths.get(path))
50
+ .map((path) => ({
51
+ path,
52
+ oldBlob: oldPaths.get(path) ?? null,
53
+ newBlob: newPaths.get(path) ?? null
54
+ }));
55
+ });
56
+ const validateOperationSchema = Effect.fn("validateOperationSchema")(function* (operation) {
57
+ return yield* Schema.decodeUnknownEffect(OperationSchema)(operation).pipe(Effect.mapError(() => new InvalidRevisionInputError({
58
+ message: "operations contain an invalid revision operation"
59
+ })));
60
+ });
61
+ const validateChangeSet = Effect.fn("validateChangeSet")(function* (value) {
62
+ const changeSet = yield* Schema.decodeUnknownEffect(ChangeSet)(value).pipe(Effect.mapError(() => new InvalidRevisionInputError({ message: "change set has an invalid shape" })));
63
+ for (const operation of changeSet.operations)
64
+ yield* validateOperationSchema(operation);
65
+ if (changeSet.expectedHead !== null &&
66
+ changeSet.expectedHead !== undefined &&
67
+ changeSet.enforceExpectedHead === true) {
68
+ return yield* failInput("enforceExpectedHead is only valid when expectedHead is empty");
69
+ }
70
+ return changeSet;
71
+ });
72
+ const requireActive = (version, operation) => version.state === "active"
73
+ ? Effect.succeed(undefined)
74
+ : failConflict(`cannot ${operation} archived resource ${version.resourceId}`);
75
+ const recordPayload = (payloads, content) => {
76
+ const copy = new Uint8Array(content);
77
+ const blobId = sha256Hex(copy);
78
+ const existing = payloads.get(blobId);
79
+ if (existing !== undefined && !bytesEqual(existing, copy)) {
80
+ return failCorrupt(`SHA-256 collision for blob ${blobId}`);
81
+ }
82
+ payloads.set(blobId, copy);
83
+ return Effect.succeed(blobId);
84
+ };
85
+ /** Apply Create/Update/Move/Archive/Restore to an immutable snapshot. */
86
+ export const applyChangeSet = Effect.fn("applyChangeSet")(function* (value, current) {
87
+ const changeSet = yield* validateChangeSet(value);
88
+ yield* validateActivePaths(current);
89
+ const ordered = [...changeSet.operations].sort((left, right) => compareCodePoints(left.resourceId, right.resourceId));
90
+ const resourceIds = ordered.map((operation) => operation.resourceId);
91
+ if (new Set(resourceIds).size !== resourceIds.length) {
92
+ return yield* failInput("a change set may touch each resource only once");
93
+ }
94
+ const resulting = new Map(current);
95
+ const changes = [];
96
+ const payloads = new Map();
97
+ for (const operation of ordered) {
98
+ const before = current.get(operation.resourceId);
99
+ let after;
100
+ let action;
101
+ if (operation._tag === "Create") {
102
+ if (before !== undefined)
103
+ return yield* failConflict(`resource already exists: ${operation.resourceId}`);
104
+ const blobId = yield* recordPayload(payloads, operation.content);
105
+ after = yield* makeVersion(operation.resourceId, operation.path, blobId, "active", null);
106
+ action = "create";
107
+ }
108
+ else {
109
+ if (before === undefined)
110
+ return yield* failConflict(`resource does not exist: ${operation.resourceId}`);
111
+ if (before.versionId !== operation.expectedVersion) {
112
+ return yield* failConflict(`resource ${operation.resourceId} changed: expected ${operation.expectedVersion}, found ${before.versionId}`);
113
+ }
114
+ if (operation._tag === "Update") {
115
+ yield* requireActive(before, "update");
116
+ const blobId = yield* recordPayload(payloads, operation.content);
117
+ after = yield* makeVersion(operation.resourceId, before.path, blobId, "active", before.versionId);
118
+ action = "update";
119
+ }
120
+ else if (operation._tag === "Move") {
121
+ yield* requireActive(before, "move");
122
+ const blobId = operation.content === undefined
123
+ ? before.blobId
124
+ : yield* recordPayload(payloads, operation.content);
125
+ after = yield* makeVersion(operation.resourceId, operation.path, blobId, "active", before.versionId);
126
+ action = "move";
127
+ }
128
+ else if (operation._tag === "Archive") {
129
+ yield* requireActive(before, "archive");
130
+ after = yield* makeVersion(operation.resourceId, before.path, before.blobId, "archived", before.versionId);
131
+ action = "archive";
132
+ }
133
+ else {
134
+ const blobId = operation.content === undefined
135
+ ? before.blobId
136
+ : yield* recordPayload(payloads, operation.content);
137
+ const path = operation.path === undefined ? before.path : operation.path;
138
+ after = yield* makeVersion(operation.resourceId, path, blobId, "active", before.versionId);
139
+ action = "restore";
140
+ }
141
+ }
142
+ if (before !== undefined && isSameSubstance(before, after)) {
143
+ return yield* failNoChanges(`${action} produces no change for ${operation.resourceId}`);
144
+ }
145
+ resulting.set(operation.resourceId, after);
146
+ changes.push(new ResourceChange({
147
+ action,
148
+ before: before ?? null,
149
+ after
150
+ }));
151
+ }
152
+ yield* validateActivePaths(resulting);
153
+ const rows = yield* materializationRows(current, resulting);
154
+ return { resulting, changes, payloads, rows };
155
+ });
156
+ const isSameSubstance = (before, after) => before.path === after.path && before.blobId === after.blobId && before.state === after.state;
157
+ const operationRequestRecord = Effect.fn("operationRequestRecord")(function* (operation) {
158
+ const base = {
159
+ resource_id: operation.resourceId,
160
+ operation: operation._tag.toLowerCase()
161
+ };
162
+ if (operation._tag === "Create") {
163
+ base.path = yield* normalizeRelativePath(operation.path);
164
+ base.content_hash = sha256Hex(operation.content);
165
+ }
166
+ else {
167
+ base.expected_version = operation.expectedVersion;
168
+ if (operation._tag === "Update") {
169
+ base.content_hash = sha256Hex(operation.content);
170
+ }
171
+ else if (operation._tag === "Move") {
172
+ base.path = yield* normalizeRelativePath(operation.path);
173
+ base.content_hash = operation.content === undefined ? null : sha256Hex(operation.content);
174
+ }
175
+ else if (operation._tag === "Restore") {
176
+ base.path = operation.path === undefined ? null : yield* normalizeRelativePath(operation.path);
177
+ base.content_hash = operation.content === undefined ? null : sha256Hex(operation.content);
178
+ }
179
+ }
180
+ return base;
181
+ });
182
+ /** Build the deterministic request and idempotency hashes used by persistence. */
183
+ export const requestIdentity = Effect.fn("requestIdentity")(function* (value) {
184
+ const changeSet = yield* validateChangeSet(value);
185
+ const operations = [];
186
+ const ordered = [...changeSet.operations].sort((left, right) => compareCodePoints(left.resourceId, right.resourceId));
187
+ for (const operation of ordered)
188
+ operations.push(yield* operationRequestRecord(operation));
189
+ const request = {
190
+ version: 1,
191
+ actor: changeSet.actor,
192
+ origin: changeSet.origin,
193
+ reason: changeSet.reason,
194
+ expected_head: changeSet.expectedHead ?? null,
195
+ operations
196
+ };
197
+ if (changeSet.enforceExpectedHead === true)
198
+ request.enforce_expected_head = true;
199
+ const encoded = canonicalJsonl(request);
200
+ return {
201
+ request,
202
+ requestHash: sha256Hex(encoded),
203
+ keyHash: sha256Hex(encodeUtf8(changeSet.idempotencyKey))
204
+ };
205
+ });
206
+ //# sourceMappingURL=change-set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"change-set.js","sourceRoot":"","sources":["../../src/domain/change-set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEvC,OAAO,EACL,SAAS,EACT,SAAS,IAAI,eAAe,EAC5B,cAAc,EACd,eAAe,EACf,WAAW,EACX,qBAAqB,EACtB,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,cAAc,EACd,qBAAqB,EACrB,eAAe,EAChB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAkC9C,MAAM,SAAS,GAAG,CAAC,OAAe,EAAmD,EAAE,CACrF,MAAM,CAAC,IAAI,CAAC,IAAI,yBAAyB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAA;AAEzD,MAAM,YAAY,GAAG,CAAC,OA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AAiB,CAAC,KAAK,CAAC,CAAA;IACjD,MAAM,UAAU,GAAiB,EAAE,CAAA;IACnC,MAAM,OAAO,GAAG,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAC7D,iBAAiB,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CACrD,CAAA;IACD,KAAK,MAAM,SAAS,IAAI,OAAO;QAAE,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAA;IAC1F,MAAM,OAAO,GAA8B;QACzC,OAAO,EAAE,CAAC;QACV,KAAK,EAAE,SAAS,CAAC,KAAK;QACtB,MAAM,EAAE,SAAS,CAAC,MAAM;QACxB,MAAM,EAAE,SAAS,CAAC,MAAM;QACxB,aAAa,EAAE,SAAS,CAAC,YAAY,IAAI,IAAI;QAC7C,UAAU;KACX,CAAA;IACD,IAAI,SAAS,CAAC,mBAAmB,KAAK,IAAI;QAAE,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAA;IAChF,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,CAAA;IACvC,OAAO;QACL,OAAO;QACP,WAAW,EAAE,SAAS,CAAC,OAAO,CAAC;QAC/B,OAAO,EAAE,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;KACzD,CAAA;AACH,CAAC,CAAC,CAAA"}
@@ -0,0 +1,17 @@
1
+ import { Effect } from "effect";
2
+ import { Commit } from "./model.js";
3
+ import { CorruptRepositoryError } from "./errors.js";
4
+ import type { CommitRecord, JsonRecord, TreeRecord } from "./format.js";
5
+ /** Decode one canonical JSONL object and reject non-canonical bytes. */
6
+ export declare const decodeCanonicalJsonl: (content: Uint8Array<ArrayBufferLike>) => Effect.Effect<JsonRecord, CorruptRepositoryError, never>;
7
+ /** Parse a v2 tree record, including strict entry shapes and state values. */
8
+ export declare const parseTreeRecord: (value: unknown) => Effect.Effect<TreeRecord, CorruptRepositoryError, never>;
9
+ /** Parse a v2 commit record and validate canonical timestamp precision. */
10
+ export declare const parseCommitRecord: (value: unknown) => Effect.Effect<CommitRecord, CorruptRepositoryError, never>;
11
+ /** Parse a canonical commit object and attach its content-addressed identifier. */
12
+ export declare const parseCommitObject: (objectId: string, content: Uint8Array<ArrayBufferLike>) => Effect.Effect<Commit, CorruptRepositoryError, never>;
13
+ /** Encode a validated commit record into its exact v2 canonical bytes. */
14
+ export declare const encodeCommitRecord: (record: CommitRecord) => Uint8Array;
15
+ /** Encode a validated tree record into its exact v2 canonical bytes. */
16
+ export declare const encodeTreeRecord: (record: TreeRecord) => Uint8Array;
17
+ //# sourceMappingURL=codec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/domain/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAkB,MAAM,QAAQ,CAAA;AAEzD,OAAO,EACL,MAAM,EAKP,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEpD,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EAEV,UAAU,EAEX,MAAM,aAAa,CAAA;AA2EpB,wEAAwE;AACxE,eAAO,MAAM,oBAAoB,oGAoB/B,CAAA;AAgDF,8EAA8E;AAC9E,eAAO,MAAM,eAAe,8EAyC1B,CAAA;AAEF,2EAA2E;AAC3E,eAAO,MAAM,iBAAiB,gFA2B5B,CAAA;AAEF,mFAAmF;AACnF,eAAO,MAAM,iBAAiB,kHAuB5B,CAAA;AAEF,0EAA0E;AAC1E,eAAO,MAAM,kBAAkB,WAAY,YAAY,KAAG,UACT,CAAA;AAEjD,wEAAwE;AACxE,eAAO,MAAM,gBAAgB,WAAY,UAAU,KAAG,UACL,CAAA"}