@effect-vfs/core 0.3.0 → 0.4.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 +36 -149
- package/dist/BytePath.d.ts +34 -2
- package/dist/BytePath.d.ts.map +1 -1
- package/dist/BytePath.js +1 -1
- package/dist/LiveVolume.d.ts +101 -0
- package/dist/LiveVolume.d.ts.map +1 -0
- package/dist/LiveVolume.js +72 -0
- package/dist/Snapshot.d.ts +60 -2
- package/dist/Snapshot.d.ts.map +1 -1
- package/dist/Snapshot.js +59 -1
- package/dist/SnapshotDelta.d.ts +113 -3
- package/dist/SnapshotDelta.d.ts.map +1 -1
- package/dist/SnapshotDelta.js +112 -2
- package/dist/VirtualFileSystem.d.ts +1224 -90
- package/dist/VirtualFileSystem.d.ts.map +1 -1
- package/dist/VirtualFileSystem.js +678 -20
- package/dist/VirtualFileSystemError.d.ts +54 -0
- package/dist/VirtualFileSystemError.d.ts.map +1 -0
- package/dist/VirtualFileSystemError.js +49 -0
- package/dist/index.d.ts +15 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/internal/bytePath.d.ts.map +1 -1
- package/dist/internal/bytePath.js +5 -10
- package/dist/internal/bytes.d.ts +6 -0
- package/dist/internal/bytes.d.ts.map +1 -0
- package/dist/internal/bytes.js +17 -0
- package/dist/internal/canonicalBase64.d.ts +13 -5
- package/dist/internal/canonicalBase64.d.ts.map +1 -1
- package/dist/internal/canonicalBase64.js +28 -6
- package/dist/internal/image.d.ts +76 -90
- package/dist/internal/image.d.ts.map +1 -1
- package/dist/internal/image.js +98 -89
- package/dist/internal/liveImage.d.ts +286 -0
- package/dist/internal/liveImage.d.ts.map +1 -0
- package/dist/internal/liveImage.js +176 -0
- package/dist/internal/metadata.d.ts +28 -0
- package/dist/internal/metadata.d.ts.map +1 -0
- package/dist/internal/metadata.js +29 -0
- package/dist/internal/snapshotDelta.d.ts.map +1 -1
- package/dist/internal/snapshotDelta.js +346 -300
- package/dist/internal/snapshotDeltaModel.d.ts +2 -2
- package/dist/internal/snapshotDeltaModel.d.ts.map +1 -1
- package/dist/internal/snapshotDeltaModel.js +3 -1
- package/dist/internal/virtualFileSystem/errors.d.ts +6 -20
- package/dist/internal/virtualFileSystem/errors.d.ts.map +1 -1
- package/dist/internal/virtualFileSystem/errors.js +22 -7
- package/dist/internal/virtualFileSystem/fixture.d.ts +4 -1
- package/dist/internal/virtualFileSystem/fixture.d.ts.map +1 -1
- package/dist/internal/virtualFileSystem/fixture.js +80 -74
- package/dist/internal/virtualFileSystem/overlayContent.d.ts.map +1 -1
- package/dist/internal/virtualFileSystem/overlayContent.js +9 -2
- package/dist/internal/virtualFileSystem/overlayDiff.d.ts +2 -11
- package/dist/internal/virtualFileSystem/overlayDiff.d.ts.map +1 -1
- package/dist/internal/virtualFileSystem/overlayDiff.js +45 -71
- package/dist/internal/virtualFileSystem/path.d.ts +15 -14
- package/dist/internal/virtualFileSystem/path.d.ts.map +1 -1
- package/dist/internal/virtualFileSystem/path.js +57 -54
- package/dist/internal/virtualFileSystem/stagedState.d.ts +22 -0
- package/dist/internal/virtualFileSystem/stagedState.d.ts.map +1 -0
- package/dist/internal/virtualFileSystem/stagedState.js +62 -0
- package/dist/internal/virtualFileSystem/testHooks.d.ts.map +1 -1
- package/dist/internal/virtualFileSystem/watchHub.d.ts +3 -3
- package/dist/internal/virtualFileSystem/watchHub.d.ts.map +1 -1
- package/dist/internal/virtualFileSystem/watchHub.js +45 -24
- package/dist/internal/virtualFileSystem.d.ts +307 -23
- package/dist/internal/virtualFileSystem.d.ts.map +1 -1
- package/dist/internal/virtualFileSystem.js +1738 -525
- package/package.json +23 -5
package/dist/Snapshot.js
CHANGED
|
@@ -12,13 +12,43 @@ import * as Schema from "effect/Schema";
|
|
|
12
12
|
/**
|
|
13
13
|
* Type identifier for opaque filesystem snapshots.
|
|
14
14
|
*
|
|
15
|
-
* @category type
|
|
15
|
+
* @category type IDs
|
|
16
16
|
* @since 0.1.0
|
|
17
17
|
*/
|
|
18
18
|
export const SnapshotTypeId = "@effect-vfs/core/Snapshot";
|
|
19
19
|
/**
|
|
20
20
|
* Describes a snapshot encoding, decoding, structure, or resource-limit failure.
|
|
21
21
|
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
25
|
+
* import * as NodeCrypto from "@effect/platform-node-shared/NodeCrypto"
|
|
26
|
+
* import { ByteSize, Effect } from "effect"
|
|
27
|
+
*
|
|
28
|
+
* // Decoding is a trust boundary. `code` says what went wrong and `field` says
|
|
29
|
+
* // which input or limit it was, so a caller can decline just the bad payload.
|
|
30
|
+
* const program = Effect.gen(function*() {
|
|
31
|
+
* const volume = yield* Vfs.make()
|
|
32
|
+
* const bytes = yield* Vfs.encodeSnapshot(yield* volume.snapshot)
|
|
33
|
+
*
|
|
34
|
+
* return yield* Vfs.decodeSnapshot(bytes, {
|
|
35
|
+
* maxEncodedBytes: ByteSize.bytes(16),
|
|
36
|
+
* maxRecords: 10_000,
|
|
37
|
+
* maxEntries: 10_000,
|
|
38
|
+
* maxDecodedBytes: ByteSize.megabytes(16)
|
|
39
|
+
* }).pipe(
|
|
40
|
+
* Effect.as("accepted"),
|
|
41
|
+
* Effect.catchTag("ImageError", (error) =>
|
|
42
|
+
* error.code === "LimitExceeded"
|
|
43
|
+
* ? Effect.succeed(`declined at ${error.field}`)
|
|
44
|
+
* : Effect.fail(error))
|
|
45
|
+
* )
|
|
46
|
+
* })
|
|
47
|
+
*
|
|
48
|
+
* Effect.runPromise(program.pipe(Effect.provide(NodeCrypto.layer))).then(console.log)
|
|
49
|
+
* // declined at encodedBytes
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
22
52
|
* @category errors
|
|
23
53
|
* @since 0.1.0
|
|
24
54
|
*/
|
|
@@ -27,6 +57,34 @@ export class ImageError extends Data.TaggedError("ImageError") {
|
|
|
27
57
|
/**
|
|
28
58
|
* Schema for the mandatory resource limits applied while decoding a snapshot.
|
|
29
59
|
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
63
|
+
* import * as NodeCrypto from "@effect/platform-node-shared/NodeCrypto"
|
|
64
|
+
* import { ByteSize, Effect } from "effect"
|
|
65
|
+
*
|
|
66
|
+
* // All four are required: each bounds a different resource. `maxEncodedBytes`
|
|
67
|
+
* // caps the wire payload before parsing; `maxDecodedBytes` caps memory after it.
|
|
68
|
+
* const limits: Vfs.DecodeLimits = {
|
|
69
|
+
* maxEncodedBytes: ByteSize.megabytes(4),
|
|
70
|
+
* maxRecords: 10_000,
|
|
71
|
+
* maxEntries: 10_000,
|
|
72
|
+
* maxDecodedBytes: ByteSize.megabytes(16)
|
|
73
|
+
* }
|
|
74
|
+
*
|
|
75
|
+
* const program = Effect.gen(function*() {
|
|
76
|
+
* const volume = yield* Vfs.make()
|
|
77
|
+
* const bytes = yield* Vfs.encodeSnapshot(yield* volume.snapshot)
|
|
78
|
+
*
|
|
79
|
+
* yield* Vfs.decodeSnapshot(bytes, limits)
|
|
80
|
+
*
|
|
81
|
+
* return "accepted"
|
|
82
|
+
* })
|
|
83
|
+
*
|
|
84
|
+
* Effect.runPromise(program.pipe(Effect.provide(NodeCrypto.layer))).then(console.log)
|
|
85
|
+
* // accepted
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
30
88
|
* @category schemas
|
|
31
89
|
* @since 0.1.0
|
|
32
90
|
*/
|
package/dist/SnapshotDelta.d.ts
CHANGED
|
@@ -9,14 +9,14 @@ import { BytePath } from "./BytePath.js";
|
|
|
9
9
|
/**
|
|
10
10
|
* Type identifier for opaque snapshot deltas.
|
|
11
11
|
*
|
|
12
|
-
* @category type
|
|
12
|
+
* @category type IDs
|
|
13
13
|
* @since 0.1.0
|
|
14
14
|
*/
|
|
15
15
|
export declare const SnapshotDeltaTypeId: "@effect-vfs/core/SnapshotDelta";
|
|
16
16
|
/**
|
|
17
17
|
* Type identifier for opaque snapshot deltas.
|
|
18
18
|
*
|
|
19
|
-
* @category type
|
|
19
|
+
* @category type IDs
|
|
20
20
|
* @since 0.1.0
|
|
21
21
|
*/
|
|
22
22
|
export type SnapshotDeltaTypeId = typeof SnapshotDeltaTypeId;
|
|
@@ -70,6 +70,39 @@ export type SnapshotDifference = typeof SnapshotDifference.Type;
|
|
|
70
70
|
* Independent snapshots do not preserve shared lineage, so moves are reported
|
|
71
71
|
* as a removal and an addition rather than an inferred rename.
|
|
72
72
|
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
76
|
+
* import * as NodeCrypto from "@effect/platform-node-shared/NodeCrypto"
|
|
77
|
+
* import { Effect } from "effect"
|
|
78
|
+
*
|
|
79
|
+
* const program = Effect.gen(function*() {
|
|
80
|
+
* const volume = yield* Vfs.make()
|
|
81
|
+
* const caller = yield* volume.caller()
|
|
82
|
+
*
|
|
83
|
+
* yield* caller.writeFile("/f", new Uint8Array([1]), {
|
|
84
|
+
* access: "write",
|
|
85
|
+
* create: "exclusive"
|
|
86
|
+
* })
|
|
87
|
+
*
|
|
88
|
+
* const base = yield* volume.snapshot
|
|
89
|
+
*
|
|
90
|
+
* yield* caller.writeFile("/f", new Uint8Array([2, 3]), { access: "write", truncate: true })
|
|
91
|
+
* yield* caller.chmod("/f", 0o600)
|
|
92
|
+
*
|
|
93
|
+
* const delta = yield* Vfs.diffSnapshots(base, yield* volume.snapshot)
|
|
94
|
+
* const changes = yield* Vfs.inspectSnapshotDelta(base, delta)
|
|
95
|
+
*
|
|
96
|
+
* // `Updated` carries which fields moved; `Added` and `Removed` carry a kind.
|
|
97
|
+
* const change = changes[0]!
|
|
98
|
+
*
|
|
99
|
+
* return change._tag === "Updated" ? change.differences : change.kind
|
|
100
|
+
* }).pipe(Effect.provide(NodeCrypto.layer))
|
|
101
|
+
*
|
|
102
|
+
* Effect.runPromise(program).then(console.log)
|
|
103
|
+
* // [ 'content', 'mode' ]
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
73
106
|
* @category schemas
|
|
74
107
|
* @since 0.1.0
|
|
75
108
|
*/
|
|
@@ -95,6 +128,32 @@ export type SnapshotChange = typeof SnapshotChange.Type;
|
|
|
95
128
|
/**
|
|
96
129
|
* Schema for snapshot-delta inspection options.
|
|
97
130
|
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
134
|
+
* import * as NodeCrypto from "@effect/platform-node-shared/NodeCrypto"
|
|
135
|
+
* import { Effect } from "effect"
|
|
136
|
+
*
|
|
137
|
+
* const program = Effect.gen(function*() {
|
|
138
|
+
* const volume = yield* Vfs.make()
|
|
139
|
+
* const caller = yield* volume.caller()
|
|
140
|
+
* const base = yield* volume.snapshot
|
|
141
|
+
*
|
|
142
|
+
* yield* caller.mkdir("/work")
|
|
143
|
+
*
|
|
144
|
+
* const delta = yield* Vfs.diffSnapshots(base, yield* volume.snapshot)
|
|
145
|
+
*
|
|
146
|
+
* // Timestamps are excluded by default, since they change on every write.
|
|
147
|
+
* const plain = yield* Vfs.inspectSnapshotDelta(base, delta)
|
|
148
|
+
* const timed = yield* Vfs.inspectSnapshotDelta(base, delta, { includeTimestamps: true })
|
|
149
|
+
*
|
|
150
|
+
* return [plain.length, timed.length]
|
|
151
|
+
* }).pipe(Effect.provide(NodeCrypto.layer))
|
|
152
|
+
*
|
|
153
|
+
* Effect.runPromise(program).then(console.log)
|
|
154
|
+
* // [ 1, 2 ]
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
98
157
|
* @category schemas
|
|
99
158
|
* @since 0.1.0
|
|
100
159
|
*/
|
|
@@ -115,6 +174,32 @@ declare const SnapshotDeltaError_base: new <A extends Record<string, any> = {}>(
|
|
|
115
174
|
/**
|
|
116
175
|
* A valid snapshot delta was inspected or applied against a valid but semantically different base.
|
|
117
176
|
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
180
|
+
* import * as NodeCrypto from "@effect/platform-node-shared/NodeCrypto"
|
|
181
|
+
* import { Effect } from "effect"
|
|
182
|
+
*
|
|
183
|
+
* const program = Effect.gen(function*() {
|
|
184
|
+
* const volume = yield* Vfs.make()
|
|
185
|
+
* const caller = yield* volume.caller()
|
|
186
|
+
* const base = yield* volume.snapshot
|
|
187
|
+
*
|
|
188
|
+
* yield* caller.mkdir("/work")
|
|
189
|
+
*
|
|
190
|
+
* // Omitting limits uses `default`; `constrained` suits memory-sensitive hosts.
|
|
191
|
+
* const tight = { ...Vfs.SnapshotDeltaLimits.constrained, maxOutputRecords: 0 }
|
|
192
|
+
*
|
|
193
|
+
* return yield* Vfs.diffSnapshots(base, yield* volume.snapshot, tight).pipe(
|
|
194
|
+
* Effect.as("diffed"),
|
|
195
|
+
* Effect.catchTag("ImageError", (error) => Effect.succeed(`${error.code} at ${error.field}`))
|
|
196
|
+
* )
|
|
197
|
+
* }).pipe(Effect.provide(NodeCrypto.layer))
|
|
198
|
+
*
|
|
199
|
+
* Effect.runPromise(program).then(console.log)
|
|
200
|
+
* // LimitExceeded at outputRecords
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
118
203
|
* @category errors
|
|
119
204
|
* @since 0.1.0
|
|
120
205
|
*/
|
|
@@ -141,7 +226,11 @@ declare const SnapshotDeltaLimitsSchema: Schema.Struct<{
|
|
|
141
226
|
* @since 0.1.0
|
|
142
227
|
*/
|
|
143
228
|
export type SnapshotDeltaLimits = typeof SnapshotDeltaLimitsSchema.Type;
|
|
144
|
-
/**
|
|
229
|
+
/**
|
|
230
|
+
* Constructs and freezes a complete snapshot-delta resource policy.
|
|
231
|
+
*
|
|
232
|
+
* @internal
|
|
233
|
+
*/
|
|
145
234
|
export declare const makeSnapshotDeltaLimits: (limits: SnapshotDeltaLimits) => SnapshotDeltaLimits;
|
|
146
235
|
/**
|
|
147
236
|
* Schema for a complete snapshot-delta resource policy, with frozen presets.
|
|
@@ -149,6 +238,27 @@ export declare const makeSnapshotDeltaLimits: (limits: SnapshotDeltaLimits) => S
|
|
|
149
238
|
* The constrained preset is intended for memory-sensitive environments. The
|
|
150
239
|
* default preset permits larger snapshots and payloads while remaining finite.
|
|
151
240
|
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```ts
|
|
243
|
+
* import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
244
|
+
* import * as NodeCrypto from "@effect/platform-node-shared/NodeCrypto"
|
|
245
|
+
* import { Effect } from "effect"
|
|
246
|
+
*
|
|
247
|
+
* const program = Effect.gen(function*() {
|
|
248
|
+
* const volume = yield* Vfs.make()
|
|
249
|
+
* const base = yield* volume.snapshot
|
|
250
|
+
*
|
|
251
|
+
* yield* (yield* volume.caller()).mkdir("/work")
|
|
252
|
+
*
|
|
253
|
+
* // Omitting limits uses `default`; pass `constrained` where memory is tight.
|
|
254
|
+
* return yield* Vfs.diffSnapshots(
|
|
255
|
+
* base,
|
|
256
|
+
* yield* volume.snapshot,
|
|
257
|
+
* Vfs.SnapshotDeltaLimits.constrained
|
|
258
|
+
* )
|
|
259
|
+
* }).pipe(Effect.provide(NodeCrypto.layer))
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
152
262
|
* @category schemas
|
|
153
263
|
* @since 0.1.0
|
|
154
264
|
*/
|
|
@@ -1 +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;AAGxC;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,gCAA+D,CAAA;AAEjG;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAA;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,mBAAmB,CAAA;CACpD;AAED;;;;;GAKG;AACH,eAAO,MAAM,aAAa,8CAA0D,CAAA;AAEpF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,4DAAoD,CAAA;AAEjF;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,gBAAgB,CAAC,IAAI,CAAA;AAE3D;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,4IAY7B,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAC,IAAI,CAAA;AAI/D
|
|
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;AAGxC;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,gCAA+D,CAAA;AAEjG;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAA;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,mBAAmB,CAAA;CACpD;AAED;;;;;GAKG;AACH,eAAO,MAAM,aAAa,8CAA0D,CAAA;AAEpF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,4DAAoD,CAAA;AAEjF;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,gBAAgB,CAAC,IAAI,CAAA;AAE3D;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,4IAY7B,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAC,IAAI,CAAA;AAI/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;IASzB,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAC,IAAI,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,sBAAsB;IACjC,6FAA6F;;EAE7F,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,OAAO,sBAAsB,CAAC,IAAI,CAAA;;;;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,kBAAmB,SAAQ,wBAAuC;IAC7E,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;CAC9B,CAAC;CAAG;AAEL,QAAA,MAAM,yBAAyB;;;;;;;;;;;EAW7B,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,yBAAyB,CAAC,IAAI,CAAA;AAEvE;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,WAAY,mBAAmB,KAAG,mBACxC,CAAA;AA4B9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAG9B,CAAA"}
|
package/dist/SnapshotDelta.js
CHANGED
|
@@ -11,7 +11,7 @@ import * as Internal from "./internal/snapshotDeltaModel.js";
|
|
|
11
11
|
/**
|
|
12
12
|
* Type identifier for opaque snapshot deltas.
|
|
13
13
|
*
|
|
14
|
-
* @category type
|
|
14
|
+
* @category type IDs
|
|
15
15
|
* @since 0.1.0
|
|
16
16
|
*/
|
|
17
17
|
export const SnapshotDeltaTypeId = Internal.SnapshotDeltaTypeId;
|
|
@@ -55,6 +55,39 @@ const SnapshotDifferences = Schema.Array(SnapshotDifference).check(Schema.isMinL
|
|
|
55
55
|
* Independent snapshots do not preserve shared lineage, so moves are reported
|
|
56
56
|
* as a removal and an addition rather than an inferred rename.
|
|
57
57
|
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
61
|
+
* import * as NodeCrypto from "@effect/platform-node-shared/NodeCrypto"
|
|
62
|
+
* import { Effect } from "effect"
|
|
63
|
+
*
|
|
64
|
+
* const program = Effect.gen(function*() {
|
|
65
|
+
* const volume = yield* Vfs.make()
|
|
66
|
+
* const caller = yield* volume.caller()
|
|
67
|
+
*
|
|
68
|
+
* yield* caller.writeFile("/f", new Uint8Array([1]), {
|
|
69
|
+
* access: "write",
|
|
70
|
+
* create: "exclusive"
|
|
71
|
+
* })
|
|
72
|
+
*
|
|
73
|
+
* const base = yield* volume.snapshot
|
|
74
|
+
*
|
|
75
|
+
* yield* caller.writeFile("/f", new Uint8Array([2, 3]), { access: "write", truncate: true })
|
|
76
|
+
* yield* caller.chmod("/f", 0o600)
|
|
77
|
+
*
|
|
78
|
+
* const delta = yield* Vfs.diffSnapshots(base, yield* volume.snapshot)
|
|
79
|
+
* const changes = yield* Vfs.inspectSnapshotDelta(base, delta)
|
|
80
|
+
*
|
|
81
|
+
* // `Updated` carries which fields moved; `Added` and `Removed` carry a kind.
|
|
82
|
+
* const change = changes[0]!
|
|
83
|
+
*
|
|
84
|
+
* return change._tag === "Updated" ? change.differences : change.kind
|
|
85
|
+
* }).pipe(Effect.provide(NodeCrypto.layer))
|
|
86
|
+
*
|
|
87
|
+
* Effect.runPromise(program).then(console.log)
|
|
88
|
+
* // [ 'content', 'mode' ]
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
58
91
|
* @category schemas
|
|
59
92
|
* @since 0.1.0
|
|
60
93
|
*/
|
|
@@ -71,6 +104,32 @@ export const SnapshotChange = Schema.Union([
|
|
|
71
104
|
/**
|
|
72
105
|
* Schema for snapshot-delta inspection options.
|
|
73
106
|
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
110
|
+
* import * as NodeCrypto from "@effect/platform-node-shared/NodeCrypto"
|
|
111
|
+
* import { Effect } from "effect"
|
|
112
|
+
*
|
|
113
|
+
* const program = Effect.gen(function*() {
|
|
114
|
+
* const volume = yield* Vfs.make()
|
|
115
|
+
* const caller = yield* volume.caller()
|
|
116
|
+
* const base = yield* volume.snapshot
|
|
117
|
+
*
|
|
118
|
+
* yield* caller.mkdir("/work")
|
|
119
|
+
*
|
|
120
|
+
* const delta = yield* Vfs.diffSnapshots(base, yield* volume.snapshot)
|
|
121
|
+
*
|
|
122
|
+
* // Timestamps are excluded by default, since they change on every write.
|
|
123
|
+
* const plain = yield* Vfs.inspectSnapshotDelta(base, delta)
|
|
124
|
+
* const timed = yield* Vfs.inspectSnapshotDelta(base, delta, { includeTimestamps: true })
|
|
125
|
+
*
|
|
126
|
+
* return [plain.length, timed.length]
|
|
127
|
+
* }).pipe(Effect.provide(NodeCrypto.layer))
|
|
128
|
+
*
|
|
129
|
+
* Effect.runPromise(program).then(console.log)
|
|
130
|
+
* // [ 1, 2 ]
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
74
133
|
* @category schemas
|
|
75
134
|
* @since 0.1.0
|
|
76
135
|
*/
|
|
@@ -81,6 +140,32 @@ export const SnapshotChangesOptions = Schema.Struct({
|
|
|
81
140
|
/**
|
|
82
141
|
* A valid snapshot delta was inspected or applied against a valid but semantically different base.
|
|
83
142
|
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
146
|
+
* import * as NodeCrypto from "@effect/platform-node-shared/NodeCrypto"
|
|
147
|
+
* import { Effect } from "effect"
|
|
148
|
+
*
|
|
149
|
+
* const program = Effect.gen(function*() {
|
|
150
|
+
* const volume = yield* Vfs.make()
|
|
151
|
+
* const caller = yield* volume.caller()
|
|
152
|
+
* const base = yield* volume.snapshot
|
|
153
|
+
*
|
|
154
|
+
* yield* caller.mkdir("/work")
|
|
155
|
+
*
|
|
156
|
+
* // Omitting limits uses `default`; `constrained` suits memory-sensitive hosts.
|
|
157
|
+
* const tight = { ...Vfs.SnapshotDeltaLimits.constrained, maxOutputRecords: 0 }
|
|
158
|
+
*
|
|
159
|
+
* return yield* Vfs.diffSnapshots(base, yield* volume.snapshot, tight).pipe(
|
|
160
|
+
* Effect.as("diffed"),
|
|
161
|
+
* Effect.catchTag("ImageError", (error) => Effect.succeed(`${error.code} at ${error.field}`))
|
|
162
|
+
* )
|
|
163
|
+
* }).pipe(Effect.provide(NodeCrypto.layer))
|
|
164
|
+
*
|
|
165
|
+
* Effect.runPromise(program).then(console.log)
|
|
166
|
+
* // LimitExceeded at outputRecords
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
84
169
|
* @category errors
|
|
85
170
|
* @since 0.1.0
|
|
86
171
|
*/
|
|
@@ -98,7 +183,11 @@ const SnapshotDeltaLimitsSchema = Schema.Struct({
|
|
|
98
183
|
maxOutputBytes: Schema.ByteSize,
|
|
99
184
|
maxInheritedRecords: Schema.Natural
|
|
100
185
|
});
|
|
101
|
-
/**
|
|
186
|
+
/**
|
|
187
|
+
* Constructs and freezes a complete snapshot-delta resource policy.
|
|
188
|
+
*
|
|
189
|
+
* @internal
|
|
190
|
+
*/
|
|
102
191
|
export const makeSnapshotDeltaLimits = (limits) => Object.freeze({ ...limits });
|
|
103
192
|
const constrained = makeSnapshotDeltaLimits({
|
|
104
193
|
maxEncodedBytes: ByteSize.mebibytes(2),
|
|
@@ -130,6 +219,27 @@ const defaultLimits = makeSnapshotDeltaLimits({
|
|
|
130
219
|
* The constrained preset is intended for memory-sensitive environments. The
|
|
131
220
|
* default preset permits larger snapshots and payloads while remaining finite.
|
|
132
221
|
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
225
|
+
* import * as NodeCrypto from "@effect/platform-node-shared/NodeCrypto"
|
|
226
|
+
* import { Effect } from "effect"
|
|
227
|
+
*
|
|
228
|
+
* const program = Effect.gen(function*() {
|
|
229
|
+
* const volume = yield* Vfs.make()
|
|
230
|
+
* const base = yield* volume.snapshot
|
|
231
|
+
*
|
|
232
|
+
* yield* (yield* volume.caller()).mkdir("/work")
|
|
233
|
+
*
|
|
234
|
+
* // Omitting limits uses `default`; pass `constrained` where memory is tight.
|
|
235
|
+
* return yield* Vfs.diffSnapshots(
|
|
236
|
+
* base,
|
|
237
|
+
* yield* volume.snapshot,
|
|
238
|
+
* Vfs.SnapshotDeltaLimits.constrained
|
|
239
|
+
* )
|
|
240
|
+
* }).pipe(Effect.provide(NodeCrypto.layer))
|
|
241
|
+
* ```
|
|
242
|
+
*
|
|
133
243
|
* @category schemas
|
|
134
244
|
* @since 0.1.0
|
|
135
245
|
*/
|