@effect-vfs/core 0.0.1 → 0.2.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/README.md +145 -9
- package/dist/BytePath.d.ts +21 -0
- package/dist/BytePath.d.ts.map +1 -0
- package/dist/BytePath.js +16 -0
- package/dist/Snapshot.d.ts +2 -2
- package/dist/Snapshot.js +2 -2
- package/dist/SnapshotDelta.d.ts +126 -0
- package/dist/SnapshotDelta.d.ts.map +1 -0
- package/dist/SnapshotDelta.js +112 -0
- package/dist/VirtualFileSystem.d.ts +232 -22
- package/dist/VirtualFileSystem.d.ts.map +1 -1
- package/dist/VirtualFileSystem.js +344 -95
- package/dist/internal/canonicalBase64.d.ts +7 -0
- package/dist/internal/canonicalBase64.d.ts.map +1 -0
- package/dist/internal/canonicalBase64.js +11 -0
- package/dist/internal/content.d.ts +25 -0
- package/dist/internal/content.d.ts.map +1 -0
- package/dist/internal/content.js +26 -0
- package/dist/internal/image.d.ts +7 -5
- package/dist/internal/image.d.ts.map +1 -1
- package/dist/internal/image.js +10 -14
- package/dist/internal/overlayChanges.d.ts +50 -0
- package/dist/internal/overlayChanges.d.ts.map +1 -0
- package/dist/internal/overlayChanges.js +146 -0
- package/dist/internal/overlayTesting.d.ts +12 -0
- package/dist/internal/overlayTesting.d.ts.map +1 -0
- package/dist/internal/overlayTesting.js +12 -0
- package/dist/internal/snapshotDelta.d.ts +88 -0
- package/dist/internal/snapshotDelta.d.ts.map +1 -0
- package/dist/internal/snapshotDelta.js +589 -0
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -10,16 +10,16 @@ Effect's standard `FileSystem` service, use [`@effect-vfs/memory`](https://www.n
|
|
|
10
10
|
which adapts this package to that interface.
|
|
11
11
|
|
|
12
12
|
The package implements a documented subset of POSIX behavior. It does not claim full POSIX conformance. See the
|
|
13
|
-
[implemented profile](https://github.com/lloydrichards/effect-virtual-fs/blob/main/.
|
|
13
|
+
[implemented profile](https://github.com/lloydrichards/effect-virtual-fs/blob/main/.okf/profiles/implemented-filesystem.md)
|
|
14
14
|
for the exact permission, path, timestamp, quota, and atomicity rules.
|
|
15
15
|
|
|
16
16
|
## Install
|
|
17
17
|
|
|
18
18
|
```sh
|
|
19
|
-
npm install @effect-vfs/core effect@4.0.0-rc.
|
|
19
|
+
npm install @effect-vfs/core effect@4.0.0-rc.114
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
Version `0.1.0` targets the exact peer version `effect@4.0.0-rc.
|
|
22
|
+
Version `0.1.0` targets the exact peer version `effect@4.0.0-rc.114`.
|
|
23
23
|
|
|
24
24
|
## The mental model
|
|
25
25
|
|
|
@@ -40,15 +40,15 @@ lifetime are explicit values that can be composed in one Effect program.
|
|
|
40
40
|
|
|
41
41
|
```ts
|
|
42
42
|
import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
43
|
-
import { Effect } from "effect"
|
|
43
|
+
import { ByteSize, Effect } from "effect"
|
|
44
44
|
|
|
45
45
|
const utf8 = new TextEncoder()
|
|
46
46
|
|
|
47
47
|
const program = Effect.scoped(Effect.gen(function*() {
|
|
48
48
|
const volume = yield* Vfs.make({
|
|
49
49
|
maxEntries: 100,
|
|
50
|
-
maxBytes:
|
|
51
|
-
maxFileBytes:
|
|
50
|
+
maxBytes: ByteSize.megabytes(1),
|
|
51
|
+
maxFileBytes: ByteSize.kilobytes(100)
|
|
52
52
|
})
|
|
53
53
|
|
|
54
54
|
const admin = yield* volume.caller()
|
|
@@ -129,12 +129,13 @@ resettable sandboxes.
|
|
|
129
129
|
```ts
|
|
130
130
|
import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
131
131
|
import { Effect } from "effect"
|
|
132
|
+
import * as ByteSize from "effect/ByteSize"
|
|
132
133
|
|
|
133
134
|
const decodeLimits = {
|
|
134
|
-
maxEncodedBytes:
|
|
135
|
+
maxEncodedBytes: ByteSize.megabytes(1),
|
|
135
136
|
maxRecords: 1_000,
|
|
136
137
|
maxEntries: 1_000,
|
|
137
|
-
maxDecodedBytes:
|
|
138
|
+
maxDecodedBytes: ByteSize.megabytes(1)
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
const program = Effect.gen(function*() {
|
|
@@ -174,6 +175,141 @@ Snapshot decoding requires explicit work limits because encoded bytes may come f
|
|
|
174
175
|
contains the reachable namespace and metadata. It excludes callers, open handles, cursor positions, watch
|
|
175
176
|
subscriptions, and unlinked content. Each restored volume is independent.
|
|
176
177
|
|
|
178
|
+
## Branch from one immutable snapshot
|
|
179
|
+
|
|
180
|
+
Use `makeOverlay` when several writable workspaces start from the same snapshot. Untouched regular-file contents are
|
|
181
|
+
shared internally. A content change copies that whole file for the editing workspace; namespace and metadata state are
|
|
182
|
+
always private. Logical quotas still count the complete visible volume, including shared base files and unlinked-open
|
|
183
|
+
contents.
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
187
|
+
import { Effect } from "effect"
|
|
188
|
+
import * as ByteSize from "effect/ByteSize"
|
|
189
|
+
|
|
190
|
+
const branch = Effect.gen(function*() {
|
|
191
|
+
const template = yield* Vfs.fromFixture({
|
|
192
|
+
entries: [
|
|
193
|
+
{ kind: "directory", path: "/project" },
|
|
194
|
+
{ kind: "file", path: "/project/settings.json", bytes: new Uint8Array() }
|
|
195
|
+
]
|
|
196
|
+
})
|
|
197
|
+
const base = yield* template.snapshot
|
|
198
|
+
const workspace = yield* Vfs.makeOverlay(base, { maxBytes: ByteSize.megabytes(1) })
|
|
199
|
+
const fs = yield* workspace.caller()
|
|
200
|
+
|
|
201
|
+
yield* fs.rename("/project/settings.json", "/project/preferences.json")
|
|
202
|
+
return yield* workspace.capture()
|
|
203
|
+
})
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
`makeOverlay(base, options)` returns a reusable Effect. Each execution creates a fresh workspace from `base`; it does
|
|
207
|
+
not memoize or reset an earlier workspace. Invalid volume options fail with `ConfigurationError`, while failure to
|
|
208
|
+
inspect the base snapshot fails with `ImageError`.
|
|
209
|
+
|
|
210
|
+
`changes()` reports final differences from the base. It hides timestamp-only differences unless called with
|
|
211
|
+
`{ includeTimestamps: true }`. Renames are paired only from retained object identity; equal contents are never treated
|
|
212
|
+
as rename evidence. Paths in summaries are `BytePath` values, so inspect them with `pathToBytes` when names may not be
|
|
213
|
+
UTF-8. Although `OverlayChange` and its options have schemas, a summary is an in-process value containing opaque
|
|
214
|
+
`BytePath` objects. The schema is not a portable summary encoding.
|
|
215
|
+
|
|
216
|
+
`capture()` returns a complete version 1 snapshot and matching summary from one committed state. Later writes change
|
|
217
|
+
neither result. The snapshot works with `encodeSnapshot`, `fromSnapshot`, and `@effect-vfs/persistence` checkpoints.
|
|
218
|
+
Restoring it recovers the complete filesystem state, not the earlier overlay base relationship or summary. To reset,
|
|
219
|
+
create a fresh overlay from the base and replace your application reference; existing callers, handles, and watches
|
|
220
|
+
remain attached to the old workspace until their own lifetimes end.
|
|
221
|
+
|
|
222
|
+
The Effects returned by `changes(options)` and `capture(options)` are also reusable. Each execution observes the
|
|
223
|
+
workspace again. Invalid summary options fail with `ConfigurationError`; failure to construct the complete observed
|
|
224
|
+
snapshot fails with `ImageError`. Reusing a previously completed `capture()` result does not observe later writes.
|
|
225
|
+
|
|
226
|
+
## Store and apply exact snapshot deltas
|
|
227
|
+
|
|
228
|
+
Use `diffSnapshots` when you need a portable description of the exact difference between two immutable snapshots.
|
|
229
|
+
The result is an opaque `SnapshotDelta`: inspect it for a path-oriented summary, encode it with Effect Schema, or apply
|
|
230
|
+
it to a semantically identical base to reconstruct the target snapshot.
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
234
|
+
import * as NodeCrypto from "@effect/platform-node/NodeCrypto"
|
|
235
|
+
import { Effect, Schema } from "effect"
|
|
236
|
+
import * as ByteSize from "effect/ByteSize"
|
|
237
|
+
|
|
238
|
+
const Delta = Vfs.SnapshotDeltaFromBytes()
|
|
239
|
+
|
|
240
|
+
const program = Effect.gen(function*() {
|
|
241
|
+
const baseVolume = yield* Vfs.fromFixture({
|
|
242
|
+
entries: [{ kind: "file", path: "/old.txt", bytes: new TextEncoder().encode("before") }]
|
|
243
|
+
})
|
|
244
|
+
const targetVolume = yield* Vfs.fromFixture({
|
|
245
|
+
entries: [{ kind: "file", path: "/new.txt", bytes: new TextEncoder().encode("after") }]
|
|
246
|
+
})
|
|
247
|
+
const base = yield* baseVolume.snapshot
|
|
248
|
+
const target = yield* targetVolume.snapshot
|
|
249
|
+
|
|
250
|
+
const delta = yield* Vfs.diffSnapshots(base, target)
|
|
251
|
+
const changes = yield* Vfs.inspectSnapshotDelta(base, delta)
|
|
252
|
+
const bytes = yield* Schema.encodeEffect(Delta)(delta)
|
|
253
|
+
const decoded = yield* Schema.decodeEffect(Delta)(bytes)
|
|
254
|
+
const restored = yield* Vfs.applySnapshotDelta(base, decoded)
|
|
255
|
+
|
|
256
|
+
return { changes, restored }
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
await Effect.runPromise(program.pipe(Effect.provide(NodeCrypto.layer)))
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Inspection verifies the delta against its semantic base before reporting what the two snapshots prove. It does not guess renames from equal contents or paths: a move is a
|
|
263
|
+
`Removed` change followed by an `Added` change. `Updated` records identify changed semantic fields, including content,
|
|
264
|
+
metadata, symbolic-link targets, and hard-link topology. Summaries do not contain replay payloads; the opaque delta does.
|
|
265
|
+
|
|
266
|
+
Each delta records the semantic identity of its required base. Inspecting or applying it against a different valid snapshot fails with a
|
|
267
|
+
`SnapshotDeltaError` whose `code` is `BaseMismatch`. Equivalent snapshots are accepted even if their encoded bytes or
|
|
268
|
+
internal record identifiers differ. Applying a delta returns another immutable `Snapshot`; call `fromSnapshot` when
|
|
269
|
+
you need a writable volume.
|
|
270
|
+
|
|
271
|
+
Creation, inspection, encoding, decoding, and application use finite `SnapshotDeltaLimits.default` limits when none are supplied.
|
|
272
|
+
Delta creation, inspection, and application require Effect's platform-neutral `Crypto.Crypto` service for SHA-256 base identity.
|
|
273
|
+
Provide the official Node, Bun, browser, or Deno crypto layer at the application edge; the core never imports a host
|
|
274
|
+
crypto implementation. Memory-sensitive applications can use one policy throughout the workflow:
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
const limits = Vfs.SnapshotDeltaLimits.constrained
|
|
278
|
+
const Delta = Vfs.SnapshotDeltaFromBytes(limits)
|
|
279
|
+
|
|
280
|
+
const constrained = Effect.gen(function*() {
|
|
281
|
+
const delta = yield* Vfs.diffSnapshots(base, target, limits)
|
|
282
|
+
const bytes = yield* Schema.encodeEffect(Delta)(delta)
|
|
283
|
+
const decoded = yield* Schema.decodeEffect(Delta)(bytes)
|
|
284
|
+
return yield* Vfs.applySnapshotDelta(base, decoded, limits)
|
|
285
|
+
})
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
Both presets are frozen complete policies. The shipped values are:
|
|
289
|
+
|
|
290
|
+
| limit | `constrained` | `default` |
|
|
291
|
+
| ----------------------------------- | ------------: | --------: |
|
|
292
|
+
| encoded bytes | 2 MiB | 16 MiB |
|
|
293
|
+
| canonical identity bytes | 4 MiB | 32 MiB |
|
|
294
|
+
| stored records plus summary changes | 6,500 | 50,000 |
|
|
295
|
+
| decoded delta bytes | 512 KiB | 8 MiB |
|
|
296
|
+
| base records | 6,500 | 50,000 |
|
|
297
|
+
| target records | 6,500 | 50,000 |
|
|
298
|
+
| namespace entries | 6,500 | 100,000 |
|
|
299
|
+
| output records | 6,500 | 50,000 |
|
|
300
|
+
| output payload bytes | 256 KiB | 4 MiB |
|
|
301
|
+
| inherited records | 6,500 | 50,000 |
|
|
302
|
+
|
|
303
|
+
These are conservative finite defaults, not universal workspace-size or memory guarantees. To tune one dimension,
|
|
304
|
+
spread a preset into a complete `SnapshotDeltaLimits` value and replace that field.
|
|
305
|
+
|
|
306
|
+
```ts
|
|
307
|
+
const limits = {
|
|
308
|
+
...Vfs.SnapshotDeltaLimits.default,
|
|
309
|
+
maxOutputBytes: ByteSize.mebibytes(8)
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
177
313
|
## Use scoped handles for incremental I/O
|
|
178
314
|
|
|
179
315
|
Whole-file operations are convenient, but handles give each open file an independent `bigint` cursor and support
|
|
@@ -280,4 +416,4 @@ candidate.
|
|
|
280
416
|
- `sync` checks handle liveness. An in-memory volume provides no host or crash durability.
|
|
281
417
|
|
|
282
418
|
For the complete contract, read the
|
|
283
|
-
[implemented profile](https://github.com/lloydrichards/effect-virtual-fs/blob/main/.
|
|
419
|
+
[implemented profile](https://github.com/lloydrichards/effect-virtual-fs/blob/main/.okf/profiles/implemented-filesystem.md).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
export declare const BytePathId: unique symbol;
|
|
3
|
+
/**
|
|
4
|
+
* An opaque path that preserves arbitrary non-NUL bytes without UTF-8 conversion.
|
|
5
|
+
*
|
|
6
|
+
* @category models
|
|
7
|
+
* @since 0.1.0
|
|
8
|
+
*/
|
|
9
|
+
export interface BytePath {
|
|
10
|
+
readonly [BytePathId]: true;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Schema for an opaque byte-preserving filesystem path.
|
|
14
|
+
*
|
|
15
|
+
* @category schemas
|
|
16
|
+
* @since 0.1.0
|
|
17
|
+
*/
|
|
18
|
+
export declare const BytePath: Schema.declare<BytePath, BytePath>;
|
|
19
|
+
export declare const make: (bytes: Uint8Array) => BytePath;
|
|
20
|
+
export declare const getBytes: (path: BytePath) => Uint8Array | undefined;
|
|
21
|
+
//# sourceMappingURL=BytePath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BytePath.d.ts","sourceRoot":"","sources":["../src/BytePath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,eAAO,MAAM,UAAU,eAAsC,CAAA;AAI7D;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,CAAC,UAAU,CAAC,EAAE,IAAI,CAAA;CAC5B;AAED;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,oCAEpB,CAAA;AAED,eAAO,MAAM,IAAI,UAAW,UAAU,KAAG,QAIxC,CAAA;AAED,eAAO,MAAM,QAAQ,SAAU,QAAQ,KAAG,UAAU,GAAG,SAAgC,CAAA"}
|
package/dist/BytePath.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
export const BytePathId = Symbol("@effect-vfs/core/BytePath");
|
|
3
|
+
const bytePaths = new WeakMap();
|
|
4
|
+
/**
|
|
5
|
+
* Schema for an opaque byte-preserving filesystem path.
|
|
6
|
+
*
|
|
7
|
+
* @category schemas
|
|
8
|
+
* @since 0.1.0
|
|
9
|
+
*/
|
|
10
|
+
export const BytePath = Schema.declare((value) => typeof value === "object" && value !== null && bytePaths.has(value));
|
|
11
|
+
export const make = (bytes) => {
|
|
12
|
+
const path = Object.freeze({ [BytePathId]: true });
|
|
13
|
+
bytePaths.set(path, bytes);
|
|
14
|
+
return path;
|
|
15
|
+
};
|
|
16
|
+
export const getBytes = (path) => bytePaths.get(path);
|
package/dist/Snapshot.d.ts
CHANGED
|
@@ -46,13 +46,13 @@ export declare class ImageError extends ImageError_base<{
|
|
|
46
46
|
*/
|
|
47
47
|
export declare const DecodeLimits: Schema.Struct<{
|
|
48
48
|
/** Maximum accepted encoded input length in bytes. */
|
|
49
|
-
readonly maxEncodedBytes: Schema.
|
|
49
|
+
readonly maxEncodedBytes: Schema.ByteSize;
|
|
50
50
|
/** Maximum number of stored metadata and content records. */
|
|
51
51
|
readonly maxRecords: Schema.Finite;
|
|
52
52
|
/** Maximum number of namespace entries. */
|
|
53
53
|
readonly maxEntries: Schema.Finite;
|
|
54
54
|
/** Maximum combined decoded byte content. */
|
|
55
|
-
readonly maxDecodedBytes: Schema.
|
|
55
|
+
readonly maxDecodedBytes: Schema.ByteSize;
|
|
56
56
|
}>;
|
|
57
57
|
/**
|
|
58
58
|
* Resource limits applied while decoding a snapshot.
|
package/dist/Snapshot.js
CHANGED
|
@@ -33,11 +33,11 @@ export class ImageError extends Data.TaggedError("ImageError") {
|
|
|
33
33
|
*/
|
|
34
34
|
export const DecodeLimits = Schema.Struct({
|
|
35
35
|
/** Maximum accepted encoded input length in bytes. */
|
|
36
|
-
maxEncodedBytes:
|
|
36
|
+
maxEncodedBytes: Schema.ByteSize,
|
|
37
37
|
/** Maximum number of stored metadata and content records. */
|
|
38
38
|
maxRecords: Natural,
|
|
39
39
|
/** Maximum number of namespace entries. */
|
|
40
40
|
maxEntries: Natural,
|
|
41
41
|
/** Maximum combined decoded byte content. */
|
|
42
|
-
maxDecodedBytes:
|
|
42
|
+
maxDecodedBytes: Schema.ByteSize
|
|
43
43
|
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opaque portable snapshot deltas and their public inspection models.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as ByteSize from "effect/ByteSize";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
import { BytePath } from "./BytePath.js";
|
|
9
|
+
/** Type identifier for opaque snapshot deltas. */
|
|
10
|
+
export declare const SnapshotDeltaTypeId: unique symbol;
|
|
11
|
+
/** Type identifier for opaque snapshot deltas. */
|
|
12
|
+
export type SnapshotDeltaTypeId = typeof SnapshotDeltaTypeId;
|
|
13
|
+
/** An immutable, opaque description of the exact difference between two snapshots. */
|
|
14
|
+
export interface SnapshotDelta {
|
|
15
|
+
readonly [SnapshotDeltaTypeId]: SnapshotDeltaTypeId;
|
|
16
|
+
}
|
|
17
|
+
/** @internal */
|
|
18
|
+
export declare const makeSnapshotDelta: (value: object) => SnapshotDelta;
|
|
19
|
+
/** @internal */
|
|
20
|
+
export declare const snapshotDeltaValue: (delta: SnapshotDelta) => object | undefined;
|
|
21
|
+
/** Schema for an already validated opaque snapshot delta. */
|
|
22
|
+
export declare const SnapshotDelta: Schema.declare<SnapshotDelta, SnapshotDelta>;
|
|
23
|
+
/** Schema for filesystem entry kinds reported by snapshot inspection. */
|
|
24
|
+
export declare const SnapshotNodeKind: Schema.Literals<readonly ["directory", "file", "symlink"]>;
|
|
25
|
+
/** A filesystem entry kind reported by snapshot inspection. */
|
|
26
|
+
export type SnapshotNodeKind = typeof SnapshotNodeKind.Type;
|
|
27
|
+
/** Schema for semantic fields that can differ between snapshots. */
|
|
28
|
+
export declare const SnapshotDifference: Schema.Literals<readonly ["kind", "content", "target", "hardLinks", "mode", "uid", "gid", "atimeNs", "mtimeNs", "ctimeNs", "birthtimeNs"]>;
|
|
29
|
+
/** A semantic field that differs between two snapshots. */
|
|
30
|
+
export type SnapshotDifference = typeof SnapshotDifference.Type;
|
|
31
|
+
/**
|
|
32
|
+
* Schema for a path-oriented difference between two snapshots.
|
|
33
|
+
*
|
|
34
|
+
* Independent snapshots do not preserve shared lineage, so moves are reported
|
|
35
|
+
* as a removal and an addition rather than an inferred rename.
|
|
36
|
+
*/
|
|
37
|
+
export declare const SnapshotChange: Schema.Union<readonly [Schema.TaggedStruct<"Added", {
|
|
38
|
+
readonly path: Schema.declare<BytePath, BytePath>;
|
|
39
|
+
readonly kind: Schema.Literals<readonly ["directory", "file", "symlink"]>;
|
|
40
|
+
}>, Schema.TaggedStruct<"Removed", {
|
|
41
|
+
readonly path: Schema.declare<BytePath, BytePath>;
|
|
42
|
+
readonly kind: Schema.Literals<readonly ["directory", "file", "symlink"]>;
|
|
43
|
+
}>, Schema.TaggedStruct<"Updated", {
|
|
44
|
+
readonly path: Schema.declare<BytePath, BytePath>;
|
|
45
|
+
readonly beforeKind: Schema.Literals<readonly ["directory", "file", "symlink"]>;
|
|
46
|
+
readonly afterKind: Schema.Literals<readonly ["directory", "file", "symlink"]>;
|
|
47
|
+
readonly differences: Schema.$Array<Schema.Literals<readonly ["kind", "content", "target", "hardLinks", "mode", "uid", "gid", "atimeNs", "mtimeNs", "ctimeNs", "birthtimeNs"]>>;
|
|
48
|
+
}>]>;
|
|
49
|
+
/** A path-oriented semantic difference between two snapshots. */
|
|
50
|
+
export type SnapshotChange = typeof SnapshotChange.Type;
|
|
51
|
+
/** Schema for snapshot-delta inspection options. */
|
|
52
|
+
export declare const SnapshotChangesOptions: Schema.Struct<{
|
|
53
|
+
/** Include access, modification, change, and birth-time differences. Defaults to `false`. */
|
|
54
|
+
readonly includeTimestamps: Schema.optionalKey<Schema.Boolean>;
|
|
55
|
+
}>;
|
|
56
|
+
/** Filtering options for snapshot-delta inspection. */
|
|
57
|
+
export type SnapshotChangesOptions = typeof SnapshotChangesOptions.Type;
|
|
58
|
+
declare const SnapshotDeltaError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
59
|
+
readonly _tag: "SnapshotDeltaError";
|
|
60
|
+
} & Readonly<A>;
|
|
61
|
+
/** A valid snapshot delta was inspected or applied against a valid but semantically different base. */
|
|
62
|
+
export declare class SnapshotDeltaError extends SnapshotDeltaError_base<{
|
|
63
|
+
readonly code: "BaseMismatch";
|
|
64
|
+
}> {
|
|
65
|
+
}
|
|
66
|
+
declare const SnapshotDeltaLimitsSchema: Schema.Struct<{
|
|
67
|
+
readonly maxEncodedBytes: Schema.ByteSize;
|
|
68
|
+
readonly maxIdentityBytes: Schema.ByteSize;
|
|
69
|
+
readonly maxDeltaRecords: Schema.Finite;
|
|
70
|
+
readonly maxDecodedDeltaBytes: Schema.ByteSize;
|
|
71
|
+
readonly maxBaseRecords: Schema.Finite;
|
|
72
|
+
readonly maxTargetRecords: Schema.Finite;
|
|
73
|
+
readonly maxEntries: Schema.Finite;
|
|
74
|
+
readonly maxOutputRecords: Schema.Finite;
|
|
75
|
+
readonly maxOutputBytes: Schema.ByteSize;
|
|
76
|
+
readonly maxInheritedRecords: Schema.Finite;
|
|
77
|
+
}>;
|
|
78
|
+
/** Resource limits shared by delta creation, inspection, encoding, decoding, and application. */
|
|
79
|
+
export type SnapshotDeltaLimits = typeof SnapshotDeltaLimitsSchema.Type;
|
|
80
|
+
/** Constructs and freezes a complete snapshot-delta resource policy. @internal */
|
|
81
|
+
export declare const makeSnapshotDeltaLimits: (limits: SnapshotDeltaLimits) => SnapshotDeltaLimits;
|
|
82
|
+
/**
|
|
83
|
+
* Schema for a complete snapshot-delta resource policy, with frozen presets.
|
|
84
|
+
*
|
|
85
|
+
* The constrained preset is intended for memory-sensitive environments. The
|
|
86
|
+
* default preset permits larger snapshots and payloads while remaining finite.
|
|
87
|
+
*/
|
|
88
|
+
export declare const SnapshotDeltaLimits: Schema.Struct<{
|
|
89
|
+
readonly maxEncodedBytes: Schema.ByteSize;
|
|
90
|
+
readonly maxIdentityBytes: Schema.ByteSize;
|
|
91
|
+
readonly maxDeltaRecords: Schema.Finite;
|
|
92
|
+
readonly maxDecodedDeltaBytes: Schema.ByteSize;
|
|
93
|
+
readonly maxBaseRecords: Schema.Finite;
|
|
94
|
+
readonly maxTargetRecords: Schema.Finite;
|
|
95
|
+
readonly maxEntries: Schema.Finite;
|
|
96
|
+
readonly maxOutputRecords: Schema.Finite;
|
|
97
|
+
readonly maxOutputBytes: Schema.ByteSize;
|
|
98
|
+
readonly maxInheritedRecords: Schema.Finite;
|
|
99
|
+
}> & {
|
|
100
|
+
constrained: {
|
|
101
|
+
readonly maxEncodedBytes: ByteSize.ByteSize;
|
|
102
|
+
readonly maxIdentityBytes: ByteSize.ByteSize;
|
|
103
|
+
readonly maxDeltaRecords: number;
|
|
104
|
+
readonly maxDecodedDeltaBytes: ByteSize.ByteSize;
|
|
105
|
+
readonly maxBaseRecords: number;
|
|
106
|
+
readonly maxTargetRecords: number;
|
|
107
|
+
readonly maxEntries: number;
|
|
108
|
+
readonly maxOutputRecords: number;
|
|
109
|
+
readonly maxOutputBytes: ByteSize.ByteSize;
|
|
110
|
+
readonly maxInheritedRecords: number;
|
|
111
|
+
};
|
|
112
|
+
default: {
|
|
113
|
+
readonly maxEncodedBytes: ByteSize.ByteSize;
|
|
114
|
+
readonly maxIdentityBytes: ByteSize.ByteSize;
|
|
115
|
+
readonly maxDeltaRecords: number;
|
|
116
|
+
readonly maxDecodedDeltaBytes: ByteSize.ByteSize;
|
|
117
|
+
readonly maxBaseRecords: number;
|
|
118
|
+
readonly maxTargetRecords: number;
|
|
119
|
+
readonly maxEntries: number;
|
|
120
|
+
readonly maxOutputRecords: number;
|
|
121
|
+
readonly maxOutputBytes: ByteSize.ByteSize;
|
|
122
|
+
readonly maxInheritedRecords: number;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
export {};
|
|
126
|
+
//# sourceMappingURL=SnapshotDelta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnapshotDelta.d.ts","sourceRoot":"","sources":["../src/SnapshotDelta.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAE3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAQxC,kDAAkD;AAClD,eAAO,MAAM,mBAAmB,eAA2C,CAAA;AAC3E,kDAAkD;AAClD,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAA;AAE5D,sFAAsF;AACtF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,mBAAmB,CAAA;CACpD;AAID,gBAAgB;AAChB,eAAO,MAAM,iBAAiB,UAAW,MAAM,KAAG,aAIjD,CAAA;AAED,gBAAgB;AAChB,eAAO,MAAM,kBAAkB,UAAW,aAAa,KAAG,MAAM,GAAG,SAAsC,CAAA;AAEzG,6DAA6D;AAC7D,eAAO,MAAM,aAAa,8CAEzB,CAAA;AAED,yEAAyE;AACzE,eAAO,MAAM,gBAAgB,4DAAoD,CAAA;AACjF,+DAA+D;AAC/D,MAAM,MAAM,gBAAgB,GAAG,OAAO,gBAAgB,CAAC,IAAI,CAAA;AAE3D,oEAAoE;AACpE,eAAO,MAAM,kBAAkB,4IAY7B,CAAA;AACF,2DAA2D;AAC3D,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAC,IAAI,CAAA;AAI/D;;;;;GAKG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;IASzB,CAAA;AACF,iEAAiE;AACjE,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAC,IAAI,CAAA;AAEvD,oDAAoD;AACpD,eAAO,MAAM,sBAAsB;IACjC,6FAA6F;;EAE7F,CAAA;AACF,uDAAuD;AACvD,MAAM,MAAM,sBAAsB,GAAG,OAAO,sBAAsB,CAAC,IAAI,CAAA;;;;AAEvE,uGAAuG;AACvG,qBAAa,kBAAmB,SAAQ,wBAAuC;IAC7E,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;CAC9B,CAAC;CAAG;AAEL,QAAA,MAAM,yBAAyB;;;;;;;;;;;EAW7B,CAAA;AACF,iGAAiG;AACjG,MAAM,MAAM,mBAAmB,GAAG,OAAO,yBAAyB,CAAC,IAAI,CAAA;AAEvE,kFAAkF;AAClF,eAAO,MAAM,uBAAuB,WAAY,mBAAmB,KAAG,mBACxC,CAAA;AA2B9B;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAG9B,CAAA"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opaque portable snapshot deltas and their public inspection models.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.1.0
|
|
5
|
+
*/
|
|
6
|
+
import * as ByteSize from "effect/ByteSize";
|
|
7
|
+
import * as Data from "effect/Data";
|
|
8
|
+
import * as Schema from "effect/Schema";
|
|
9
|
+
import { BytePath } from "./BytePath.js";
|
|
10
|
+
const Natural = Schema.Finite.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0), Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER));
|
|
11
|
+
/** Type identifier for opaque snapshot deltas. */
|
|
12
|
+
export const SnapshotDeltaTypeId = Symbol("@effect-vfs/core/SnapshotDelta");
|
|
13
|
+
const snapshotDeltas = new WeakMap();
|
|
14
|
+
/** @internal */
|
|
15
|
+
export const makeSnapshotDelta = (value) => {
|
|
16
|
+
const delta = Object.freeze({ [SnapshotDeltaTypeId]: SnapshotDeltaTypeId });
|
|
17
|
+
snapshotDeltas.set(delta, value);
|
|
18
|
+
return delta;
|
|
19
|
+
};
|
|
20
|
+
/** @internal */
|
|
21
|
+
export const snapshotDeltaValue = (delta) => snapshotDeltas.get(delta);
|
|
22
|
+
/** Schema for an already validated opaque snapshot delta. */
|
|
23
|
+
export const SnapshotDelta = Schema.declare((value) => typeof value === "object" && value !== null && snapshotDeltas.has(value));
|
|
24
|
+
/** Schema for filesystem entry kinds reported by snapshot inspection. */
|
|
25
|
+
export const SnapshotNodeKind = Schema.Literals(["directory", "file", "symlink"]);
|
|
26
|
+
/** Schema for semantic fields that can differ between snapshots. */
|
|
27
|
+
export const SnapshotDifference = Schema.Literals([
|
|
28
|
+
"kind",
|
|
29
|
+
"content",
|
|
30
|
+
"target",
|
|
31
|
+
"hardLinks",
|
|
32
|
+
"mode",
|
|
33
|
+
"uid",
|
|
34
|
+
"gid",
|
|
35
|
+
"atimeNs",
|
|
36
|
+
"mtimeNs",
|
|
37
|
+
"ctimeNs",
|
|
38
|
+
"birthtimeNs"
|
|
39
|
+
]);
|
|
40
|
+
const SnapshotDifferences = Schema.Array(SnapshotDifference).check(Schema.isMinLength(1));
|
|
41
|
+
/**
|
|
42
|
+
* Schema for a path-oriented difference between two snapshots.
|
|
43
|
+
*
|
|
44
|
+
* Independent snapshots do not preserve shared lineage, so moves are reported
|
|
45
|
+
* as a removal and an addition rather than an inferred rename.
|
|
46
|
+
*/
|
|
47
|
+
export const SnapshotChange = Schema.Union([
|
|
48
|
+
Schema.TaggedStruct("Added", { path: BytePath, kind: SnapshotNodeKind }),
|
|
49
|
+
Schema.TaggedStruct("Removed", { path: BytePath, kind: SnapshotNodeKind }),
|
|
50
|
+
Schema.TaggedStruct("Updated", {
|
|
51
|
+
path: BytePath,
|
|
52
|
+
beforeKind: SnapshotNodeKind,
|
|
53
|
+
afterKind: SnapshotNodeKind,
|
|
54
|
+
differences: SnapshotDifferences
|
|
55
|
+
})
|
|
56
|
+
]);
|
|
57
|
+
/** Schema for snapshot-delta inspection options. */
|
|
58
|
+
export const SnapshotChangesOptions = Schema.Struct({
|
|
59
|
+
/** Include access, modification, change, and birth-time differences. Defaults to `false`. */
|
|
60
|
+
includeTimestamps: Schema.optionalKey(Schema.Boolean)
|
|
61
|
+
});
|
|
62
|
+
/** A valid snapshot delta was inspected or applied against a valid but semantically different base. */
|
|
63
|
+
export class SnapshotDeltaError extends Data.TaggedError("SnapshotDeltaError") {
|
|
64
|
+
}
|
|
65
|
+
const SnapshotDeltaLimitsSchema = Schema.Struct({
|
|
66
|
+
maxEncodedBytes: Schema.ByteSize,
|
|
67
|
+
maxIdentityBytes: Schema.ByteSize,
|
|
68
|
+
maxDeltaRecords: Natural,
|
|
69
|
+
maxDecodedDeltaBytes: Schema.ByteSize,
|
|
70
|
+
maxBaseRecords: Natural,
|
|
71
|
+
maxTargetRecords: Natural,
|
|
72
|
+
maxEntries: Natural,
|
|
73
|
+
maxOutputRecords: Natural,
|
|
74
|
+
maxOutputBytes: Schema.ByteSize,
|
|
75
|
+
maxInheritedRecords: Natural
|
|
76
|
+
});
|
|
77
|
+
/** Constructs and freezes a complete snapshot-delta resource policy. @internal */
|
|
78
|
+
export const makeSnapshotDeltaLimits = (limits) => Object.freeze({ ...limits });
|
|
79
|
+
const constrained = makeSnapshotDeltaLimits({
|
|
80
|
+
maxEncodedBytes: ByteSize.mebibytes(2),
|
|
81
|
+
maxIdentityBytes: ByteSize.mebibytes(4),
|
|
82
|
+
maxDeltaRecords: 6_500,
|
|
83
|
+
maxDecodedDeltaBytes: ByteSize.kibibytes(512),
|
|
84
|
+
maxBaseRecords: 6_500,
|
|
85
|
+
maxTargetRecords: 6_500,
|
|
86
|
+
maxEntries: 6_500,
|
|
87
|
+
maxOutputRecords: 6_500,
|
|
88
|
+
maxOutputBytes: ByteSize.kibibytes(256),
|
|
89
|
+
maxInheritedRecords: 6_500
|
|
90
|
+
});
|
|
91
|
+
const defaultLimits = makeSnapshotDeltaLimits({
|
|
92
|
+
maxEncodedBytes: ByteSize.mebibytes(16),
|
|
93
|
+
maxIdentityBytes: ByteSize.mebibytes(32),
|
|
94
|
+
maxDeltaRecords: 50_000,
|
|
95
|
+
maxDecodedDeltaBytes: ByteSize.mebibytes(8),
|
|
96
|
+
maxBaseRecords: 50_000,
|
|
97
|
+
maxTargetRecords: 50_000,
|
|
98
|
+
maxEntries: 100_000,
|
|
99
|
+
maxOutputRecords: 50_000,
|
|
100
|
+
maxOutputBytes: ByteSize.mebibytes(4),
|
|
101
|
+
maxInheritedRecords: 50_000
|
|
102
|
+
});
|
|
103
|
+
/**
|
|
104
|
+
* Schema for a complete snapshot-delta resource policy, with frozen presets.
|
|
105
|
+
*
|
|
106
|
+
* The constrained preset is intended for memory-sensitive environments. The
|
|
107
|
+
* default preset permits larger snapshots and payloads while remaining finite.
|
|
108
|
+
*/
|
|
109
|
+
export const SnapshotDeltaLimits = Object.assign(SnapshotDeltaLimitsSchema, {
|
|
110
|
+
constrained,
|
|
111
|
+
default: defaultLimits
|
|
112
|
+
});
|