@effect-vfs/core 0.4.0 → 0.6.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 +39 -32
- package/dist/BytePath.d.ts +114 -4
- package/dist/BytePath.d.ts.map +1 -1
- package/dist/BytePath.js +155 -0
- package/dist/Caller.d.ts +391 -0
- package/dist/Caller.d.ts.map +1 -0
- package/dist/Caller.js +199 -0
- package/dist/FileHandle.d.ts +50 -0
- package/dist/FileHandle.d.ts.map +1 -0
- package/dist/FileHandle.js +28 -0
- package/dist/Fixture.d.ts +155 -0
- package/dist/Fixture.d.ts.map +1 -0
- package/dist/Fixture.js +65 -0
- package/dist/LiveVolume.d.ts +15 -22
- package/dist/LiveVolume.d.ts.map +1 -1
- package/dist/LiveVolume.js +19 -15
- package/dist/Metadata.d.ts +186 -0
- package/dist/Metadata.d.ts.map +1 -0
- package/dist/Metadata.js +125 -0
- package/dist/Snapshot.d.ts +31 -53
- package/dist/Snapshot.d.ts.map +1 -1
- package/dist/Snapshot.js +26 -49
- package/dist/SnapshotDelta.d.ts +24 -39
- package/dist/SnapshotDelta.d.ts.map +1 -1
- package/dist/SnapshotDelta.js +14 -35
- package/dist/Target.d.ts +225 -0
- package/dist/Target.d.ts.map +1 -0
- package/dist/Target.js +92 -0
- package/dist/Testing.d.ts +128 -0
- package/dist/Testing.d.ts.map +1 -0
- package/dist/Testing.js +111 -0
- package/dist/VfsError.d.ts +199 -0
- package/dist/VfsError.d.ts.map +1 -0
- package/dist/VfsError.js +164 -0
- package/dist/VirtualFileSystem.d.ts +628 -347
- package/dist/VirtualFileSystem.d.ts.map +1 -1
- package/dist/VirtualFileSystem.js +450 -117
- package/dist/Volume.d.ts +211 -0
- package/dist/Volume.d.ts.map +1 -0
- package/dist/Volume.js +172 -0
- package/dist/Watch.d.ts +68 -0
- package/dist/Watch.d.ts.map +1 -0
- package/dist/Watch.js +46 -0
- package/dist/index.d.ts +56 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +56 -1
- package/dist/internal/budget.d.ts +90 -0
- package/dist/internal/budget.d.ts.map +1 -0
- package/dist/internal/budget.js +70 -0
- package/dist/internal/bytePath.d.ts +2 -0
- package/dist/internal/bytePath.d.ts.map +1 -1
- package/dist/internal/bytePath.js +3 -2
- package/dist/internal/bytes.d.ts +3 -0
- package/dist/internal/bytes.d.ts.map +1 -1
- package/dist/internal/bytes.js +4 -2
- package/dist/internal/canonicalBase64.d.ts +1 -4
- package/dist/internal/canonicalBase64.d.ts.map +1 -1
- package/dist/internal/canonicalBase64.js +9 -13
- package/dist/internal/errors.d.ts +54 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/errors.js +91 -0
- package/dist/internal/{virtualFileSystem/fixture.d.ts → fixture.d.ts} +8 -8
- package/dist/internal/fixture.d.ts.map +1 -0
- package/dist/internal/fixture.js +133 -0
- package/dist/internal/hex128.d.ts +12 -0
- package/dist/internal/hex128.d.ts.map +1 -0
- package/dist/internal/hex128.js +7 -0
- package/dist/internal/hmac.d.ts +5 -0
- package/dist/internal/hmac.d.ts.map +1 -0
- package/dist/internal/hmac.js +150 -0
- package/dist/internal/image.d.ts +14 -117
- package/dist/internal/image.d.ts.map +1 -1
- package/dist/internal/image.js +137 -167
- package/dist/internal/inodeTable.d.ts +20 -0
- package/dist/internal/inodeTable.d.ts.map +1 -0
- package/dist/internal/inodeTable.js +48 -0
- package/dist/internal/lines.d.ts +36 -0
- package/dist/internal/lines.d.ts.map +1 -0
- package/dist/internal/lines.js +115 -0
- package/dist/internal/liveImage.d.ts +19 -278
- package/dist/internal/liveImage.d.ts.map +1 -1
- package/dist/internal/liveImage.js +75 -166
- package/dist/internal/merkle.d.ts +45 -0
- package/dist/internal/merkle.d.ts.map +1 -0
- package/dist/internal/merkle.js +179 -0
- package/dist/internal/metadata.d.ts +2 -13
- package/dist/internal/metadata.d.ts.map +1 -1
- package/dist/internal/metadata.js +5 -15
- package/dist/internal/{virtualFileSystem/overlayDiff.d.ts → overlayDiff.d.ts} +3 -3
- package/dist/internal/overlayDiff.d.ts.map +1 -0
- package/dist/internal/{virtualFileSystem/overlayDiff.js → overlayDiff.js} +1 -4
- package/dist/internal/{virtualFileSystem/path.d.ts → path.d.ts} +19 -7
- package/dist/internal/path.d.ts.map +1 -0
- package/dist/internal/{virtualFileSystem/path.js → path.js} +39 -25
- package/dist/internal/snapshotDelta.d.ts +61 -60
- package/dist/internal/snapshotDelta.d.ts.map +1 -1
- package/dist/internal/snapshotDelta.js +612 -504
- package/dist/internal/snapshotDeltaModel.d.ts.map +1 -1
- package/dist/internal/snapshotDeltaModel.js +0 -1
- package/dist/internal/stagedState.d.ts +18 -0
- package/dist/internal/stagedState.d.ts.map +1 -0
- package/dist/internal/stagedState.js +18 -0
- package/dist/internal/testSeams.d.ts +17 -0
- package/dist/internal/testSeams.d.ts.map +1 -0
- package/dist/internal/testSeams.js +20 -0
- package/dist/internal/tree.d.ts +225 -0
- package/dist/internal/tree.d.ts.map +1 -0
- package/dist/internal/tree.js +385 -0
- package/dist/internal/turnstile.d.ts +8 -0
- package/dist/internal/turnstile.d.ts.map +1 -0
- package/dist/internal/turnstile.js +43 -0
- package/dist/internal/virtualFileSystem.d.ts +41 -491
- package/dist/internal/virtualFileSystem.d.ts.map +1 -1
- package/dist/internal/virtualFileSystem.js +2118 -2471
- package/dist/internal/volumeState.d.ts +110 -0
- package/dist/internal/volumeState.d.ts.map +1 -0
- package/dist/internal/volumeState.js +204 -0
- package/dist/internal/watchHub.d.ts +25 -0
- package/dist/internal/watchHub.d.ts.map +1 -0
- package/dist/internal/watchHub.js +68 -0
- package/package.json +53 -9
- package/dist/VirtualFileSystemError.d.ts +0 -54
- package/dist/VirtualFileSystemError.d.ts.map +0 -1
- package/dist/VirtualFileSystemError.js +0 -49
- package/dist/internal/virtualFileSystem/errors.d.ts +0 -12
- package/dist/internal/virtualFileSystem/errors.d.ts.map +0 -1
- package/dist/internal/virtualFileSystem/errors.js +0 -47
- package/dist/internal/virtualFileSystem/fixture.d.ts.map +0 -1
- package/dist/internal/virtualFileSystem/fixture.js +0 -150
- package/dist/internal/virtualFileSystem/overlayContent.d.ts +0 -15
- package/dist/internal/virtualFileSystem/overlayContent.d.ts.map +0 -1
- package/dist/internal/virtualFileSystem/overlayContent.js +0 -29
- package/dist/internal/virtualFileSystem/overlayDiff.d.ts.map +0 -1
- package/dist/internal/virtualFileSystem/path.d.ts.map +0 -1
- package/dist/internal/virtualFileSystem/stagedState.d.ts +0 -22
- package/dist/internal/virtualFileSystem/stagedState.d.ts.map +0 -1
- package/dist/internal/virtualFileSystem/stagedState.js +0 -62
- package/dist/internal/virtualFileSystem/testHooks.d.ts +0 -20
- package/dist/internal/virtualFileSystem/testHooks.d.ts.map +0 -1
- package/dist/internal/virtualFileSystem/testHooks.js +0 -23
- package/dist/internal/virtualFileSystem/watchHub.d.ts +0 -16
- package/dist/internal/virtualFileSystem/watchHub.d.ts.map +0 -1
- package/dist/internal/virtualFileSystem/watchHub.js +0 -54
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one error family of `@effect-vfs/core`. Every failure a volume, caller,
|
|
3
|
+
* handle, snapshot codec, delta codec, or live store reports is a `VfsError`
|
|
4
|
+
* whose `code` says what went wrong, whose `operation` names the verb or
|
|
5
|
+
* constructor, and which may name the offending option `field`, the `path`
|
|
6
|
+
* it was addressing, and the underlying `cause` it classifies.
|
|
7
|
+
*
|
|
8
|
+
* @since 0.6.0
|
|
9
|
+
*/
|
|
10
|
+
import * as Schema from "effect/Schema";
|
|
11
|
+
import type { BytePath } from "./BytePath.js";
|
|
12
|
+
/**
|
|
13
|
+
* Schema for the codes an operation on a volume, caller, or handle reports.
|
|
14
|
+
*
|
|
15
|
+
* @category schemas
|
|
16
|
+
* @since 0.6.0
|
|
17
|
+
*/
|
|
18
|
+
export declare const FsCode: Schema.Literals<readonly ["NotFound", "AlreadyExists", "NotEmpty", "NotDirectory", "AccessDenied", "NotPermitted", "InvalidHandle", "ForeignHandle", "InvalidReference", "ForeignReference", "StaleReference", "ClosedCaller", "InvalidArgument", "InvalidPathEncoding", "PathTooLong", "NoSpace", "IsDirectory", "FileTooLarge", "NoData", "SymlinkLoop", "UnrepresentableName", "StorageRejected", "OutcomeUnknown", "VolumeUnavailable", "VolumeBusy"]>;
|
|
19
|
+
/**
|
|
20
|
+
* A code an operation on a volume, caller, or handle reports.
|
|
21
|
+
*
|
|
22
|
+
* @category models
|
|
23
|
+
* @since 0.6.0
|
|
24
|
+
*/
|
|
25
|
+
export type FsCode = typeof FsCode.Type;
|
|
26
|
+
/**
|
|
27
|
+
* Schema for the codes a snapshot, fixture, live image, or delta codec reports.
|
|
28
|
+
*
|
|
29
|
+
* @category schemas
|
|
30
|
+
* @since 0.6.0
|
|
31
|
+
*/
|
|
32
|
+
export declare const ImageCode: Schema.Literals<readonly ["InvalidEncoding", "UnsupportedVersion", "InvalidStructure", "LimitExceeded"]>;
|
|
33
|
+
/**
|
|
34
|
+
* A code a snapshot, fixture, live image, or delta codec reports.
|
|
35
|
+
*
|
|
36
|
+
* @category models
|
|
37
|
+
* @since 0.6.0
|
|
38
|
+
*/
|
|
39
|
+
export type ImageCode = typeof ImageCode.Type;
|
|
40
|
+
/**
|
|
41
|
+
* Schema for the code a delta reports when its base does not match.
|
|
42
|
+
*
|
|
43
|
+
* @category schemas
|
|
44
|
+
* @since 0.6.0
|
|
45
|
+
*/
|
|
46
|
+
export declare const DeltaCode: Schema.Literals<readonly ["BaseMismatch"]>;
|
|
47
|
+
/**
|
|
48
|
+
* The code a delta reports when its base does not match.
|
|
49
|
+
*
|
|
50
|
+
* @category models
|
|
51
|
+
* @since 0.6.0
|
|
52
|
+
*/
|
|
53
|
+
export type DeltaCode = typeof DeltaCode.Type;
|
|
54
|
+
/**
|
|
55
|
+
* Schema for the codes a live image store reports while opening or recovering a volume.
|
|
56
|
+
*
|
|
57
|
+
* @category schemas
|
|
58
|
+
* @since 0.6.0
|
|
59
|
+
*/
|
|
60
|
+
export declare const StoreCode: Schema.Literals<readonly ["Storage", "Ownership", "IncompatibleStore", "CorruptStore"]>;
|
|
61
|
+
/**
|
|
62
|
+
* A code a live image store reports while opening or recovering a volume.
|
|
63
|
+
*
|
|
64
|
+
* @category models
|
|
65
|
+
* @since 0.6.0
|
|
66
|
+
*/
|
|
67
|
+
export type StoreCode = typeof StoreCode.Type;
|
|
68
|
+
/**
|
|
69
|
+
* Schema for every code a `VfsError` can carry.
|
|
70
|
+
*
|
|
71
|
+
* @category schemas
|
|
72
|
+
* @since 0.6.0
|
|
73
|
+
*/
|
|
74
|
+
export declare const VfsCode: Schema.Literals<readonly ["NotFound", "AlreadyExists", "NotEmpty", "NotDirectory", "AccessDenied", "NotPermitted", "InvalidHandle", "ForeignHandle", "InvalidReference", "ForeignReference", "StaleReference", "ClosedCaller", "InvalidArgument", "InvalidPathEncoding", "PathTooLong", "NoSpace", "IsDirectory", "FileTooLarge", "NoData", "SymlinkLoop", "UnrepresentableName", "StorageRejected", "OutcomeUnknown", "VolumeUnavailable", "VolumeBusy", "InvalidEncoding", "UnsupportedVersion", "InvalidStructure", "LimitExceeded", "BaseMismatch", "Storage", "Ownership", "IncompatibleStore", "CorruptStore"]>;
|
|
75
|
+
/**
|
|
76
|
+
* Every code a `VfsError` can carry.
|
|
77
|
+
*
|
|
78
|
+
* @category models
|
|
79
|
+
* @since 0.6.0
|
|
80
|
+
*/
|
|
81
|
+
export type VfsCode = typeof VfsCode.Type;
|
|
82
|
+
/**
|
|
83
|
+
* Schema for the path an error names, carried as an opaque `BytePath` and
|
|
84
|
+
* encoded as base64 bytes so the error survives a wire.
|
|
85
|
+
*
|
|
86
|
+
* @category schemas
|
|
87
|
+
* @since 0.6.0
|
|
88
|
+
*/
|
|
89
|
+
export declare const ErrorPath: Schema.decodeTo<Schema.declare<BytePath, BytePath>, Schema.Uint8ArrayFromBase64, never, never>;
|
|
90
|
+
declare const VfsError_base: Schema.Class<VfsError, Schema.TaggedStruct<"VfsError", {
|
|
91
|
+
/** What went wrong. */
|
|
92
|
+
readonly code: Schema.Literals<readonly ["NotFound", "AlreadyExists", "NotEmpty", "NotDirectory", "AccessDenied", "NotPermitted", "InvalidHandle", "ForeignHandle", "InvalidReference", "ForeignReference", "StaleReference", "ClosedCaller", "InvalidArgument", "InvalidPathEncoding", "PathTooLong", "NoSpace", "IsDirectory", "FileTooLarge", "NoData", "SymlinkLoop", "UnrepresentableName", "StorageRejected", "OutcomeUnknown", "VolumeUnavailable", "VolumeBusy", "InvalidEncoding", "UnsupportedVersion", "InvalidStructure", "LimitExceeded", "BaseMismatch", "Storage", "Ownership", "IncompatibleStore", "CorruptStore"]>;
|
|
93
|
+
/** The verb or constructor that failed. */
|
|
94
|
+
readonly operation: Schema.String;
|
|
95
|
+
/** The option or input area the failure concerns, when one is known. */
|
|
96
|
+
readonly field: Schema.optionalKey<Schema.String>;
|
|
97
|
+
/** The path the operation was addressing, when it named one. */
|
|
98
|
+
readonly path: Schema.optionalKey<Schema.decodeTo<Schema.declare<BytePath, BytePath>, Schema.Uint8ArrayFromBase64, never, never>>;
|
|
99
|
+
/** The underlying failure this error classifies, when one exists. */
|
|
100
|
+
readonly cause: Schema.optionalKey<Schema.Defect>;
|
|
101
|
+
}>, import("effect/Cause").YieldableError>;
|
|
102
|
+
/**
|
|
103
|
+
* A failure reported by any part of the virtual filesystem.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
108
|
+
* import { Effect } from "effect"
|
|
109
|
+
*
|
|
110
|
+
* const program = Effect.gen(function*() {
|
|
111
|
+
* const fs = yield* (yield* Vfs.make()).caller()
|
|
112
|
+
*
|
|
113
|
+
* return yield* fs.readFile("/missing").pipe(
|
|
114
|
+
* Effect.catchTag("VfsError", (error) => Effect.succeed(`${error.operation}: ${error.code}`))
|
|
115
|
+
* )
|
|
116
|
+
* })
|
|
117
|
+
*
|
|
118
|
+
* Effect.runPromise(program).then(console.log)
|
|
119
|
+
* // readFile: NotFound
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @category errors
|
|
123
|
+
* @since 0.6.0
|
|
124
|
+
*/
|
|
125
|
+
export declare class VfsError extends VfsError_base {
|
|
126
|
+
get message(): string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* A `VfsError` whose code is one an operation on a volume, caller, or handle reports.
|
|
130
|
+
*
|
|
131
|
+
* @category models
|
|
132
|
+
* @since 0.6.0
|
|
133
|
+
*/
|
|
134
|
+
export type FsFailure = VfsError & {
|
|
135
|
+
readonly code: FsCode;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* A `VfsError` whose code is one a snapshot, fixture, live image, or delta codec reports.
|
|
139
|
+
*
|
|
140
|
+
* @category models
|
|
141
|
+
* @since 0.6.0
|
|
142
|
+
*/
|
|
143
|
+
export type ImageFailure = VfsError & {
|
|
144
|
+
readonly code: ImageCode;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* A `VfsError` whose code is one a live image store reports.
|
|
148
|
+
*
|
|
149
|
+
* @category models
|
|
150
|
+
* @since 0.6.0
|
|
151
|
+
*/
|
|
152
|
+
export type StoreFailure = VfsError & {
|
|
153
|
+
readonly code: StoreCode;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* A `VfsError` reporting a rejected option, always `InvalidArgument` with the offending `field`.
|
|
157
|
+
*
|
|
158
|
+
* @category models
|
|
159
|
+
* @since 0.6.0
|
|
160
|
+
*/
|
|
161
|
+
export type ArgumentFailure = VfsError & {
|
|
162
|
+
readonly code: "InvalidArgument";
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* What a `VfsError` is built from: a code, the operation that failed, and whichever of field, path and cause
|
|
166
|
+
* apply.
|
|
167
|
+
*
|
|
168
|
+
* @category models
|
|
169
|
+
* @since 0.6.0
|
|
170
|
+
*/
|
|
171
|
+
export interface Props<C extends VfsCode> {
|
|
172
|
+
readonly code: C;
|
|
173
|
+
readonly operation: string;
|
|
174
|
+
readonly field?: string | undefined;
|
|
175
|
+
readonly path?: BytePath | undefined;
|
|
176
|
+
readonly cause?: unknown;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Builds a `VfsError` whose type carries its code, so a service can fail with a narrowed alias such as
|
|
180
|
+
* `StoreFailure` or `ArgumentFailure` without a cast. An absent field, path or cause stays absent.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```ts
|
|
184
|
+
* import { VfsError } from "@effect-vfs/core"
|
|
185
|
+
*
|
|
186
|
+
* const failure: VfsError.StoreFailure = VfsError.make({ code: "Storage", operation: "MyStore.load" })
|
|
187
|
+
*
|
|
188
|
+
* console.log(failure.message)
|
|
189
|
+
* // MyStore.load failed with Storage
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @category constructors
|
|
193
|
+
* @since 0.6.0
|
|
194
|
+
*/
|
|
195
|
+
export declare const make: <C extends VfsCode>(props: Props<C>) => VfsError & {
|
|
196
|
+
readonly code: C;
|
|
197
|
+
};
|
|
198
|
+
export {};
|
|
199
|
+
//# sourceMappingURL=VfsError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VfsError.d.ts","sourceRoot":"","sources":["../src/VfsError.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAM7C;;;;;GAKG;AACH,eAAO,MAAM,MAAM,4bA+BjB,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,IAAI,CAAA;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,SAAS,0GAAkG,CAAA;AAExH;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAA;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,SAAS,4CAAoC,CAAA;AAE1D;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAA;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,SAAS,yFAAiF,CAAA;AAEvG;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,OAAO,SAAS,CAAC,IAAI,CAAA;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,OAAO,ulBAKlB,CAAA;AAEF;;;;;GAKG;AACH,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA;AAEzC;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,gGAUrB,CAAA;;IA0BC,uBAAuB;;IAEvB,2CAA2C;;IAE3C,wEAAwE;;IAExE,gEAAgE;;IAEhE,qEAAqE;;;AAhCvE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,QAAS,SAAQ,aAW5B;IACA,IAAa,OAAO,IAAI,MAAM,CAE7B;CACF;AAED;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAE5D;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,CAAA;AAElE;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,CAAA;AAElE;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAA;CAAE,CAAA;AAE7E;;;;;;GAMG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC,SAAS,OAAO;IACtC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IAChB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACnC,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAA;IACpC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CACzB;AAUD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,OAAO,SAAS,KAAK,CAAC,CAAC,CAAC,KAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;CAYtF,CAAA"}
|
package/dist/VfsError.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one error family of `@effect-vfs/core`. Every failure a volume, caller,
|
|
3
|
+
* handle, snapshot codec, delta codec, or live store reports is a `VfsError`
|
|
4
|
+
* whose `code` says what went wrong, whose `operation` names the verb or
|
|
5
|
+
* constructor, and which may name the offending option `field`, the `path`
|
|
6
|
+
* it was addressing, and the underlying `cause` it classifies.
|
|
7
|
+
*
|
|
8
|
+
* @since 0.6.0
|
|
9
|
+
*/
|
|
10
|
+
import * as Schema from "effect/Schema";
|
|
11
|
+
import * as SchemaTransformation from "effect/SchemaTransformation";
|
|
12
|
+
import * as Internal from "./internal/bytePath.js";
|
|
13
|
+
// Declared from the byte-path internals rather than the BytePath module, which imports this one for its failures.
|
|
14
|
+
const BytePathSchema = Schema.declare(Internal.isBytePath);
|
|
15
|
+
/**
|
|
16
|
+
* Schema for the codes an operation on a volume, caller, or handle reports.
|
|
17
|
+
*
|
|
18
|
+
* @category schemas
|
|
19
|
+
* @since 0.6.0
|
|
20
|
+
*/
|
|
21
|
+
export const FsCode = Schema.Literals([
|
|
22
|
+
"NotFound",
|
|
23
|
+
"AlreadyExists",
|
|
24
|
+
"NotEmpty",
|
|
25
|
+
"NotDirectory",
|
|
26
|
+
// EACCES: the mode bits deny the access.
|
|
27
|
+
"AccessDenied",
|
|
28
|
+
// EPERM: the change needs ownership or privilege, whatever the mode bits say.
|
|
29
|
+
"NotPermitted",
|
|
30
|
+
"InvalidHandle",
|
|
31
|
+
"ForeignHandle",
|
|
32
|
+
"InvalidReference",
|
|
33
|
+
"ForeignReference",
|
|
34
|
+
"StaleReference",
|
|
35
|
+
"ClosedCaller",
|
|
36
|
+
"InvalidArgument",
|
|
37
|
+
"InvalidPathEncoding",
|
|
38
|
+
"PathTooLong",
|
|
39
|
+
"NoSpace",
|
|
40
|
+
"IsDirectory",
|
|
41
|
+
"FileTooLarge",
|
|
42
|
+
"NoData",
|
|
43
|
+
"SymlinkLoop",
|
|
44
|
+
"UnrepresentableName",
|
|
45
|
+
// A durable provider knows the mutation was not committed.
|
|
46
|
+
"StorageRejected",
|
|
47
|
+
// A commit or publication failed after its outcome ceased to be knowable to the caller.
|
|
48
|
+
"OutcomeUnknown",
|
|
49
|
+
// The provider stopped serving operations until recovery establishes its state.
|
|
50
|
+
"VolumeUnavailable",
|
|
51
|
+
"VolumeBusy"
|
|
52
|
+
]);
|
|
53
|
+
/**
|
|
54
|
+
* Schema for the codes a snapshot, fixture, live image, or delta codec reports.
|
|
55
|
+
*
|
|
56
|
+
* @category schemas
|
|
57
|
+
* @since 0.6.0
|
|
58
|
+
*/
|
|
59
|
+
export const ImageCode = Schema.Literals(["InvalidEncoding", "UnsupportedVersion", "InvalidStructure", "LimitExceeded"]);
|
|
60
|
+
/**
|
|
61
|
+
* Schema for the code a delta reports when its base does not match.
|
|
62
|
+
*
|
|
63
|
+
* @category schemas
|
|
64
|
+
* @since 0.6.0
|
|
65
|
+
*/
|
|
66
|
+
export const DeltaCode = Schema.Literals(["BaseMismatch"]);
|
|
67
|
+
/**
|
|
68
|
+
* Schema for the codes a live image store reports while opening or recovering a volume.
|
|
69
|
+
*
|
|
70
|
+
* @category schemas
|
|
71
|
+
* @since 0.6.0
|
|
72
|
+
*/
|
|
73
|
+
export const StoreCode = Schema.Literals(["Storage", "Ownership", "IncompatibleStore", "CorruptStore"]);
|
|
74
|
+
/**
|
|
75
|
+
* Schema for every code a `VfsError` can carry.
|
|
76
|
+
*
|
|
77
|
+
* @category schemas
|
|
78
|
+
* @since 0.6.0
|
|
79
|
+
*/
|
|
80
|
+
export const VfsCode = Schema.Literals([
|
|
81
|
+
...FsCode.literals,
|
|
82
|
+
...ImageCode.literals,
|
|
83
|
+
...DeltaCode.literals,
|
|
84
|
+
...StoreCode.literals
|
|
85
|
+
]);
|
|
86
|
+
/**
|
|
87
|
+
* Schema for the path an error names, carried as an opaque `BytePath` and
|
|
88
|
+
* encoded as base64 bytes so the error survives a wire.
|
|
89
|
+
*
|
|
90
|
+
* @category schemas
|
|
91
|
+
* @since 0.6.0
|
|
92
|
+
*/
|
|
93
|
+
export const ErrorPath = Schema.Uint8ArrayFromBase64.check(Schema.makeFilter((bytes) => Internal.isPathBytes(bytes) ? undefined : "must be non-empty and hold no NUL")).pipe(Schema.decodeTo(BytePathSchema, SchemaTransformation.transform({
|
|
94
|
+
decode: (bytes) => Internal.make(bytes.slice()),
|
|
95
|
+
encode: (path) => Internal.getBytes(path) ?? new Uint8Array()
|
|
96
|
+
})));
|
|
97
|
+
/**
|
|
98
|
+
* A failure reported by any part of the virtual filesystem.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* import { VirtualFileSystem as Vfs } from "@effect-vfs/core"
|
|
103
|
+
* import { Effect } from "effect"
|
|
104
|
+
*
|
|
105
|
+
* const program = Effect.gen(function*() {
|
|
106
|
+
* const fs = yield* (yield* Vfs.make()).caller()
|
|
107
|
+
*
|
|
108
|
+
* return yield* fs.readFile("/missing").pipe(
|
|
109
|
+
* Effect.catchTag("VfsError", (error) => Effect.succeed(`${error.operation}: ${error.code}`))
|
|
110
|
+
* )
|
|
111
|
+
* })
|
|
112
|
+
*
|
|
113
|
+
* Effect.runPromise(program).then(console.log)
|
|
114
|
+
* // readFile: NotFound
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @category errors
|
|
118
|
+
* @since 0.6.0
|
|
119
|
+
*/
|
|
120
|
+
export class VfsError extends Schema.TaggedError()("VfsError", {
|
|
121
|
+
/** What went wrong. */
|
|
122
|
+
code: VfsCode,
|
|
123
|
+
/** The verb or constructor that failed. */
|
|
124
|
+
operation: Schema.String,
|
|
125
|
+
/** The option or input area the failure concerns, when one is known. */
|
|
126
|
+
field: Schema.optionalKey(Schema.String),
|
|
127
|
+
/** The path the operation was addressing, when it named one. */
|
|
128
|
+
path: Schema.optionalKey(ErrorPath),
|
|
129
|
+
/** The underlying failure this error classifies, when one exists. */
|
|
130
|
+
cause: Schema.optionalKey(Schema.Defect())
|
|
131
|
+
}) {
|
|
132
|
+
get message() {
|
|
133
|
+
return `${this.operation} failed with ${this.code}${this.field === undefined ? "" : ` at ${this.field}`}`;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Builds a `VfsError` whose type carries its code, so a service can fail with a narrowed alias such as
|
|
138
|
+
* `StoreFailure` or `ArgumentFailure` without a cast. An absent field, path or cause stays absent.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* import { VfsError } from "@effect-vfs/core"
|
|
143
|
+
*
|
|
144
|
+
* const failure: VfsError.StoreFailure = VfsError.make({ code: "Storage", operation: "MyStore.load" })
|
|
145
|
+
*
|
|
146
|
+
* console.log(failure.message)
|
|
147
|
+
* // MyStore.load failed with Storage
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @category constructors
|
|
151
|
+
* @since 0.6.0
|
|
152
|
+
*/
|
|
153
|
+
export const make = (props) => {
|
|
154
|
+
const fields = { code: props.code, operation: props.operation };
|
|
155
|
+
if (props.field !== undefined)
|
|
156
|
+
fields.field = props.field;
|
|
157
|
+
if (props.path !== undefined)
|
|
158
|
+
fields.path = props.path;
|
|
159
|
+
if (props.cause !== undefined)
|
|
160
|
+
fields.cause = props.cause;
|
|
161
|
+
// SAFETY: the error was built from `props.code`, which is a C.
|
|
162
|
+
// oxlint-disable-next-line effecttsgo/unsafe-effect-type-assertion -- see the invariant above.
|
|
163
|
+
return new VfsError(fields);
|
|
164
|
+
};
|