@akterjs/cli 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +47 -2
- package/dist/Argument-D81dqizB.mjs +57 -0
- package/dist/Array-B4kuTQeW.mjs +2323 -0
- package/dist/Boolean-kILIvmhE.mjs +26 -0
- package/dist/ChildProcess-BCIwxPGc.mjs +577 -0
- package/dist/CliError-Cf5xqkkj.mjs +633 -0
- package/dist/Command-Dzq9KM-h.mjs +5135 -0
- package/dist/Config-B6OND9WR.mjs +854 -0
- package/dist/Console-BKHUkH6a.mjs +141 -0
- package/dist/Data-CeCULr0-.mjs +251 -0
- package/dist/Digest-CBd3uv5B.mjs +348 -0
- package/dist/Duration-EH9Vy4U6.mjs +791 -0
- package/dist/Effect-CKFpqbmw.mjs +12911 -0
- package/dist/FileSystem-4pPcEb_i.mjs +1366 -0
- package/dist/HttpClientError-BUeMWx70.mjs +303 -0
- package/dist/HttpClientResponse-D5ZKICVV.mjs +855 -0
- package/dist/Match-CGPLZYrV.mjs +434 -0
- package/dist/MutableHashMap-f8nW8AJR.mjs +376 -0
- package/dist/MutableHashSet-_HI572Ya.mjs +155 -0
- package/dist/MutableRef-D4Qv592C.mjs +107 -0
- package/dist/Number-BvkRkfc-.mjs +137 -0
- package/dist/Option-DkxSnBhp.mjs +3967 -0
- package/dist/Order-C1JC991I.mjs +481 -0
- package/dist/Path-Djdv_eF5.mjs +130 -0
- package/dist/Queue-CO5UQ6os.mjs +1394 -0
- package/dist/Redacted-RkJrG5Me.mjs +160 -0
- package/dist/Ref-BIPOxJNH.mjs +267 -0
- package/dist/Runtime-BInIAwK3.mjs +297 -0
- package/dist/Schema-MiKt5K1v.mjs +10999 -0
- package/dist/SecureRandom-B_U4ysO3.mjs +279 -0
- package/dist/Semaphore-DOVJ4ZGS.mjs +177 -0
- package/dist/Stdio-KylmOBX_.mjs +74 -0
- package/dist/Stream-bK9QIETN.mjs +4012 -0
- package/dist/String-q5dcsVe4.mjs +351 -0
- package/dist/TerminalCapabilities-w_44MAca.mjs +1769 -0
- package/dist/WebCrypto-ZI_GNVlw.mjs +33 -0
- package/dist/actor-call.service-CGM_vD9u.mjs +1269 -0
- package/dist/actor-client.adapter-Coem7gF1.mjs +3691 -0
- package/dist/akter-program.config-D8yb9xQP.mjs +7034 -0
- package/dist/akter.cli.mjs +5 -0
- package/dist/app-cli.config.mjs +49 -0
- package/dist/app-entry.pure.mjs +31 -0
- package/dist/archive/akter-archive.schema.mjs +65 -0
- package/dist/archive/akter-archive.service.mjs +309 -0
- package/dist/archive/archive-cli.config.mjs +45 -0
- package/dist/archive/archive-invalid.errors.mjs +5 -0
- package/dist/archive/archived-lineage.pure.mjs +13 -0
- package/dist/archive/tar.pure.mjs +291 -0
- package/dist/archive/zstd.adapter.mjs +46 -0
- package/dist/bench/bench-report.pure.mjs +120 -0
- package/dist/bench/bench-runner.pure.mjs +89 -0
- package/dist/bench/bench.service.mjs +301 -0
- package/dist/cli-runtime.layer-BqK2mmVL.mjs +1191 -0
- package/dist/cli-runtime.layer.mjs +1 -0
- package/dist/cloud-client.adapter-Cy1BjDbG.mjs +3186 -0
- package/dist/cloud-client.adapter-DOVMoYAj.mjs +304 -0
- package/dist/command/akter-commands.config.mjs +32 -0
- package/dist/command/akter-program.config.mjs +1 -0
- package/dist/credentials/credentials.service.mjs +226 -0
- package/dist/credentials/keychain.adapter.mjs +92 -0
- package/dist/credentials/login.config.mjs +251 -0
- package/dist/deploy/auth/api-attempt.service.mjs +30 -0
- package/dist/deploy/auth/token-refresh.errors.mjs +4 -0
- package/dist/deploy/build-bundle.adapter.mjs +133 -0
- package/dist/deploy/build-manifest.pure.mjs +44 -0
- package/dist/deploy/cloud-client.adapter.mjs +1 -0
- package/dist/deploy/cloud-url.pure.mjs +17 -0
- package/dist/deploy/deploy-failed.errors.mjs +17 -0
- package/dist/deploy/deploy.service.mjs +156 -0
- package/dist/deploy/request-failure.pure.mjs +87 -0
- package/dist/dev-runner.pure.mjs +30 -0
- package/dist/docs/doc-topics.pure.mjs +21 -0
- package/dist/docs/docs.config.mjs +1 -0
- package/dist/docs.config-D2amjsje.mjs +190 -0
- package/dist/docs.config-D3zzLzLR.mjs +190 -0
- package/dist/export/actor-export.service.mjs +267 -0
- package/dist/export/export-failed.errors.mjs +4 -0
- package/dist/export/export-failure.pure.mjs +18 -0
- package/dist/export/ordered-lines.pure.mjs +43 -0
- package/dist/export/ranged-download.pure.mjs +66 -0
- package/dist/export/snapshot-download.pure.mjs +86 -0
- package/dist/history-runner.pure.mjs +186 -0
- package/dist/history-since.pure.mjs +17 -0
- package/dist/hosted-runtime.layer-Cx3IPsEd.mjs +16358 -0
- package/dist/local/environment-cli.config.mjs +90 -0
- package/dist/local/environment-runner.pure.mjs +75 -0
- package/dist/local/local-cli.config.mjs +159 -0
- package/dist/logs/log-follow.config.mjs +21 -0
- package/dist/logs/log-follow.service.mjs +87 -0
- package/dist/logs/log-lines.pure.mjs +44 -0
- package/dist/migrate-runner.pure.mjs +28 -0
- package/dist/operation-input.pure-CS9iUhqK.mjs +1383 -0
- package/dist/operation-registry.pure-DVC8EDgj.mjs +283 -0
- package/dist/registry/actor-call.service.mjs +1 -0
- package/dist/registry/actor-commands.config.mjs +127 -0
- package/dist/registry/actor-refusal.pure.mjs +34 -0
- package/dist/registry/approval.service.mjs +80 -0
- package/dist/registry/cloud-commands.config.mjs +151 -0
- package/dist/registry/cloud-served.pure.mjs +31 -0
- package/dist/registry/operation-call.service.mjs +262 -0
- package/dist/registry/operation-input.pure.mjs +1 -0
- package/dist/registry/operation-output.pure.mjs +91 -0
- package/dist/registry/served-command.config.mjs +57 -0
- package/dist/runner-exited.errors.mjs +10 -0
- package/dist/terminal/cli-exit.errors.mjs +38 -0
- package/dist/terminal/cli-failure.pure.mjs +31 -0
- package/dist/terminal/confirm.adapter.mjs +27 -0
- package/package.json +61 -3
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { $i as encode, $t as suspend, M as fail$1, O as die, Ot as promise, Vn as effect, Xt as succeed, aa as Service, cn as tryPromise, dt as map, en as sync } from "./Effect-CKFpqbmw.mjs";
|
|
2
|
+
import { qt as hasProperty } from "./Option-DkxSnBhp.mjs";
|
|
3
|
+
import { i as TaggedError } from "./Data-CeCULr0-.mjs";
|
|
4
|
+
import { t as WebCrypto } from "./WebCrypto-ZI_GNVlw.mjs";
|
|
5
|
+
// ../../node_modules/.pnpm/effect@4.1.2_patch_hash=0e61176203bb1256381ce1c5b488d7951983ce38ff698647d3f4617383abbf07/node_modules/effect/dist/crypto/CryptoError.js
|
|
6
|
+
/**
|
|
7
|
+
* The `CryptoError` returned by the `effect/crypto` modules, and the reasons it
|
|
8
|
+
* carries.
|
|
9
|
+
*
|
|
10
|
+
* Every failure is one `CryptoError` whose `module` and `method` name the
|
|
11
|
+
* operation, such as `"Aead"` and `"decrypt"`, and whose `reason` says what
|
|
12
|
+
* went wrong: `InvalidArgument`, `InvalidKey`, `DecryptionFailed`,
|
|
13
|
+
* `Unsupported`, or `NotExtractable`.
|
|
14
|
+
*
|
|
15
|
+
* **Gotchas**
|
|
16
|
+
*
|
|
17
|
+
* The error is not serializable, so it cannot be a typed failure in an Rpc or
|
|
18
|
+
* HttpApi schema. Map it before it reaches a client, for example
|
|
19
|
+
* `DecryptionFailed` to a 401. Sending crypto failure detail to clients is how
|
|
20
|
+
* oracles leak.
|
|
21
|
+
*
|
|
22
|
+
* @stability unstable
|
|
23
|
+
* @since 4.0.0
|
|
24
|
+
*/
|
|
25
|
+
const TypeId = "~effect/crypto/CryptoError";
|
|
26
|
+
const ReasonTypeId = "~effect/crypto/CryptoError/Reason";
|
|
27
|
+
/**
|
|
28
|
+
* Reason for an argument that the operation rejects before using the key or
|
|
29
|
+
* data, such as a wrong nonce length, an out-of-range iteration count, or
|
|
30
|
+
* `info` passed to a key derivation other than HKDF.
|
|
31
|
+
*
|
|
32
|
+
* @stability unstable
|
|
33
|
+
* @category errors
|
|
34
|
+
* @since 4.0.0
|
|
35
|
+
*/
|
|
36
|
+
var InvalidArgument = class extends (/*#__PURE__*/ TaggedError("InvalidArgument")) {
|
|
37
|
+
/**
|
|
38
|
+
* Marks this value as a `CryptoError` reason for runtime guards.
|
|
39
|
+
*
|
|
40
|
+
* @since 4.0.0
|
|
41
|
+
*/
|
|
42
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
43
|
+
get message() {
|
|
44
|
+
return this.description;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Reason for key material that is rejected, such as a wrong raw key length,
|
|
49
|
+
* malformed DER, PEM, or JWK data, a `CryptoKey` that does not match the typed
|
|
50
|
+
* key, or a peer public key that produces an all-zero shared secret.
|
|
51
|
+
*
|
|
52
|
+
* @stability unstable
|
|
53
|
+
* @category errors
|
|
54
|
+
* @since 4.0.0
|
|
55
|
+
*/
|
|
56
|
+
var InvalidKey = class extends (/*#__PURE__*/ TaggedError("InvalidKey")) {
|
|
57
|
+
/**
|
|
58
|
+
* Marks this value as a `CryptoError` reason for runtime guards.
|
|
59
|
+
*
|
|
60
|
+
* @since 4.0.0
|
|
61
|
+
*/
|
|
62
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
63
|
+
get message() {
|
|
64
|
+
return this.description;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Reason for a decryption or unwrap that failed its integrity check, or a CBC
|
|
69
|
+
* ciphertext with bad padding or length.
|
|
70
|
+
*
|
|
71
|
+
* **Details**
|
|
72
|
+
*
|
|
73
|
+
* The reason is identical for every cause and carries no `cause` or runtime
|
|
74
|
+
* message, so callers cannot tell a tampered tag from bad padding. Keeping
|
|
75
|
+
* either would create a padding oracle.
|
|
76
|
+
*
|
|
77
|
+
* @stability unstable
|
|
78
|
+
* @category errors
|
|
79
|
+
* @since 4.0.0
|
|
80
|
+
*/
|
|
81
|
+
var DecryptionFailed = class extends (/*#__PURE__*/ TaggedError("DecryptionFailed")) {
|
|
82
|
+
/**
|
|
83
|
+
* Marks this value as a `CryptoError` reason for runtime guards.
|
|
84
|
+
*
|
|
85
|
+
* @since 4.0.0
|
|
86
|
+
*/
|
|
87
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
88
|
+
get message() {
|
|
89
|
+
return "Could not decrypt the data";
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Reason for an algorithm or key that a layer does not provide, such as
|
|
94
|
+
* Argon2id under `Kdf.layerWebCrypto`, or a `CryptoKey`-backed key passed to a
|
|
95
|
+
* layer that cannot use it.
|
|
96
|
+
*
|
|
97
|
+
* @stability unstable
|
|
98
|
+
* @category errors
|
|
99
|
+
* @since 4.0.0
|
|
100
|
+
*/
|
|
101
|
+
var Unsupported = class extends (/*#__PURE__*/ TaggedError("Unsupported")) {
|
|
102
|
+
/**
|
|
103
|
+
* Marks this value as a `CryptoError` reason for runtime guards.
|
|
104
|
+
*
|
|
105
|
+
* @since 4.0.0
|
|
106
|
+
*/
|
|
107
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
108
|
+
get message() {
|
|
109
|
+
return this.description;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Reason for exporting or wrapping a `CryptoKey` that was created as
|
|
114
|
+
* non-extractable.
|
|
115
|
+
*
|
|
116
|
+
* @stability unstable
|
|
117
|
+
* @category errors
|
|
118
|
+
* @since 4.0.0
|
|
119
|
+
*/
|
|
120
|
+
var NotExtractable = class extends (/*#__PURE__*/ TaggedError("NotExtractable")) {
|
|
121
|
+
/**
|
|
122
|
+
* Marks this value as a `CryptoError` reason for runtime guards.
|
|
123
|
+
*
|
|
124
|
+
* @since 4.0.0
|
|
125
|
+
*/
|
|
126
|
+
[ReasonTypeId] = ReasonTypeId;
|
|
127
|
+
get message() {
|
|
128
|
+
return this.description;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Error returned by the `effect/crypto` modules.
|
|
133
|
+
*
|
|
134
|
+
* **When to use**
|
|
135
|
+
*
|
|
136
|
+
* Use to handle failures from any `effect/crypto` operation, matching on
|
|
137
|
+
* `reason` to separate caller mistakes from failed decryption.
|
|
138
|
+
*
|
|
139
|
+
* **Details**
|
|
140
|
+
*
|
|
141
|
+
* `module` and `method` name the operation, such as `"Aead"` and `"decrypt"`.
|
|
142
|
+
* The message reads `"Aead.decrypt: <reason message>"`. The error's `cause`
|
|
143
|
+
* is the reason's `cause`, when it has one.
|
|
144
|
+
*
|
|
145
|
+
* **Example** (Recovering from failed decryption)
|
|
146
|
+
*
|
|
147
|
+
* ```ts import.meta.vitest
|
|
148
|
+
* import { Effect } from "effect"
|
|
149
|
+
* import { CryptoError } from "effect/crypto"
|
|
150
|
+
*
|
|
151
|
+
* const decrypt = Effect.fail(
|
|
152
|
+
* new CryptoError.CryptoError({
|
|
153
|
+
* module: "Aead",
|
|
154
|
+
* method: "decrypt",
|
|
155
|
+
* reason: new CryptoError.DecryptionFailed()
|
|
156
|
+
* })
|
|
157
|
+
* )
|
|
158
|
+
*
|
|
159
|
+
* const program = decrypt.pipe(
|
|
160
|
+
* Effect.catchReason("CryptoError", "DecryptionFailed", () => Effect.succeed("rejected"))
|
|
161
|
+
* )
|
|
162
|
+
*
|
|
163
|
+
* await Effect.runPromise(program) // => "rejected"
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @see {@link isCryptoError} for narrowing unknown values
|
|
167
|
+
*
|
|
168
|
+
* @stability unstable
|
|
169
|
+
* @category errors
|
|
170
|
+
* @since 4.0.0
|
|
171
|
+
*/
|
|
172
|
+
var CryptoError = class extends (/*#__PURE__*/ TaggedError("CryptoError")) {
|
|
173
|
+
/**
|
|
174
|
+
* Marks this value as a `CryptoError` for runtime guards.
|
|
175
|
+
*
|
|
176
|
+
* @since 4.0.0
|
|
177
|
+
*/
|
|
178
|
+
[TypeId] = TypeId;
|
|
179
|
+
/**
|
|
180
|
+
* The reason's cause, when it has one.
|
|
181
|
+
*
|
|
182
|
+
* @since 4.0.0
|
|
183
|
+
*/
|
|
184
|
+
cause = "cause" in this.reason ? this.reason.cause : void 0;
|
|
185
|
+
get message() {
|
|
186
|
+
return `${this.module}.${this.method}: ${this.reason.message}`;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
// ../../node_modules/.pnpm/effect@4.1.2_patch_hash=0e61176203bb1256381ce1c5b488d7951983ce38ff698647d3f4617383abbf07/node_modules/effect/dist/crypto/internal/webCrypto.js
|
|
190
|
+
/** @internal */
|
|
191
|
+
const subtleUnavailable = () => /* @__PURE__ */ new Error("crypto.subtle is unavailable; browsers expose it only in secure contexts");
|
|
192
|
+
/** @internal */
|
|
193
|
+
const fail = (module, method, reason) => fail$1(new CryptoError({
|
|
194
|
+
module,
|
|
195
|
+
method,
|
|
196
|
+
reason
|
|
197
|
+
}));
|
|
198
|
+
/** @internal */
|
|
199
|
+
const invalidKey = (module, method, description) => fail(module, method, new InvalidKey({ description }));
|
|
200
|
+
/** @internal */
|
|
201
|
+
const notExtractable = (module, method) => fail(module, method, new NotExtractable({ description: "The CryptoKey is not extractable" }));
|
|
202
|
+
/**
|
|
203
|
+
* Thrown inside {@link run} to fail with a typed reason instead of a defect,
|
|
204
|
+
* for checks that need the imported `CryptoKey`.
|
|
205
|
+
*
|
|
206
|
+
* @internal
|
|
207
|
+
*/
|
|
208
|
+
var Failure = class {
|
|
209
|
+
reason;
|
|
210
|
+
constructor(reason) {
|
|
211
|
+
this.reason = reason;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Maps an exception thrown by `crypto.subtle` in `module.layerWebCrypto` to a
|
|
216
|
+
* `CryptoError`.
|
|
217
|
+
*
|
|
218
|
+
* A {@link Failure} carries its own reason. `DataError` and
|
|
219
|
+
* `InvalidAccessError` are `InvalidKey`, and `NotSupportedError` is
|
|
220
|
+
* `Unsupported`, naming the algorithm and the layer. An `OperationError`
|
|
221
|
+
* becomes the reason from `onOperationError`, such as `DecryptionFailed` for a
|
|
222
|
+
* decryption. Any other exception is rethrown, which `Effect.tryPromise` turns
|
|
223
|
+
* into a defect.
|
|
224
|
+
*
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
227
|
+
const webCryptoError = (module, method, algorithm, cause, onOperationError) => toCryptoError(module, method, `${module}.layerWebCrypto`, algorithm, cause, onOperationError);
|
|
228
|
+
const toCryptoError = (module, method, provider, algorithm, cause, onOperationError) => {
|
|
229
|
+
const reason = reasonFor(method, provider, algorithm, cause, onOperationError);
|
|
230
|
+
if (reason === void 0) throw cause;
|
|
231
|
+
return new CryptoError({
|
|
232
|
+
module,
|
|
233
|
+
method,
|
|
234
|
+
reason
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
const reasonFor = (method, provider, algorithm, cause, onOperationError) => {
|
|
238
|
+
if (cause instanceof Failure) return cause.reason;
|
|
239
|
+
switch (hasProperty(cause, "name") ? cause.name : void 0) {
|
|
240
|
+
case "DataError": return new InvalidKey({
|
|
241
|
+
description: "Invalid key data",
|
|
242
|
+
cause
|
|
243
|
+
});
|
|
244
|
+
case "InvalidAccessError": return new InvalidKey({
|
|
245
|
+
description: `The key cannot be used for ${method}`,
|
|
246
|
+
cause
|
|
247
|
+
});
|
|
248
|
+
case "NotSupportedError": return new Unsupported({
|
|
249
|
+
description: `${provider} does not provide ${algorithm}`,
|
|
250
|
+
cause
|
|
251
|
+
});
|
|
252
|
+
case "OperationError": return onOperationError?.();
|
|
253
|
+
default: return;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Runs `f` on the `subtle` of a `Crypto` object in `module.layerWebCrypto`,
|
|
258
|
+
* dying when it is missing, as in an insecure browser context. Exceptions go
|
|
259
|
+
* through `onError`, which defaults to {@link webCryptoError}.
|
|
260
|
+
*
|
|
261
|
+
* @internal
|
|
262
|
+
*/
|
|
263
|
+
const run = (module, method, algorithm, crypto, f, onError = (cause) => webCryptoError(module, method, algorithm, cause)) => suspend(() => {
|
|
264
|
+
const subtle = crypto?.subtle;
|
|
265
|
+
if (subtle === void 0) return die(subtleUnavailable());
|
|
266
|
+
return tryPromise({
|
|
267
|
+
try: () => f(subtle),
|
|
268
|
+
catch: onError
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
/**
|
|
272
|
+
* {@link run} on the `WebCrypto` reference, for the top-level functions that
|
|
273
|
+
* have no layer to read it from. `crypto.subtle` is named as the provider
|
|
274
|
+
* that declined an algorithm.
|
|
275
|
+
*
|
|
276
|
+
* @internal
|
|
277
|
+
*/
|
|
278
|
+
const runWithReference = (module, method, algorithm, f) => WebCrypto.use((crypto) => run(module, method, algorithm, crypto, f, (cause) => toCryptoError(module, method, "crypto.subtle", algorithm, cause)));
|
|
279
|
+
// ../../node_modules/.pnpm/effect@4.1.2_patch_hash=0e61176203bb1256381ce1c5b488d7951983ce38ff698647d3f4617383abbf07/node_modules/effect/dist/crypto/internal/digest.js
|
|
280
|
+
/** @internal */
|
|
281
|
+
const webCryptoDigest = (crypto, algorithm, data) => {
|
|
282
|
+
const implementation = algorithm.implementation;
|
|
283
|
+
if (implementation !== void 0) return sync(() => implementation(data));
|
|
284
|
+
return suspend(() => {
|
|
285
|
+
const subtle = crypto?.subtle;
|
|
286
|
+
if (subtle === void 0) return die(subtleUnavailable());
|
|
287
|
+
return promise(async () => new Uint8Array(await subtle.digest(algorithm.name, data)));
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
/**
|
|
291
|
+
* SHA-256, with a 32-byte output.
|
|
292
|
+
*
|
|
293
|
+
* @stability unstable
|
|
294
|
+
* @category algorithms
|
|
295
|
+
* @since 4.0.0
|
|
296
|
+
*/
|
|
297
|
+
const sha256 = {
|
|
298
|
+
name: "SHA-256",
|
|
299
|
+
outputLength: 32,
|
|
300
|
+
implementation: void 0
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* Converts a hash name to an algorithm-name suffix: `"SHA-256"` to `"Sha256"`.
|
|
304
|
+
*
|
|
305
|
+
* @internal
|
|
306
|
+
*/
|
|
307
|
+
const nameSuffix = (hash) => hash.name.charAt(0) + hash.name.slice(1).toLowerCase().replace("-", "");
|
|
308
|
+
/**
|
|
309
|
+
* Service that computes message digests.
|
|
310
|
+
*
|
|
311
|
+
* **Example** (Hashing with SHA-256)
|
|
312
|
+
*
|
|
313
|
+
* ```ts import.meta.vitest
|
|
314
|
+
* import { Effect } from "effect"
|
|
315
|
+
* import { Digest } from "effect/crypto"
|
|
316
|
+
*
|
|
317
|
+
* const program = Effect.gen(function*() {
|
|
318
|
+
* const digest = yield* Digest.Digest
|
|
319
|
+
* return yield* digest.digestHex(Digest.sha256, new TextEncoder().encode("abc"))
|
|
320
|
+
* })
|
|
321
|
+
*
|
|
322
|
+
* const hex = await Effect.runPromise(program.pipe(Effect.provide(Digest.layerWebCrypto)))
|
|
323
|
+
* hex.length // => 64
|
|
324
|
+
* ```
|
|
325
|
+
*
|
|
326
|
+
* @stability unstable
|
|
327
|
+
* @category services
|
|
328
|
+
* @since 4.0.0
|
|
329
|
+
*/
|
|
330
|
+
var Digest = class extends (/*#__PURE__*/ Service()("effect/crypto/Digest")) {};
|
|
331
|
+
/**
|
|
332
|
+
* Layer that provides `Digest` on the `WebCrypto` reference.
|
|
333
|
+
*
|
|
334
|
+
* **Details**
|
|
335
|
+
*
|
|
336
|
+
* The SHA algorithms run on `crypto.subtle`, and MD5 on the pure TypeScript
|
|
337
|
+
* implementation. Without `crypto.subtle`, the layer still builds and MD5
|
|
338
|
+
* keeps working, but SHA digests die.
|
|
339
|
+
*
|
|
340
|
+
* @stability unstable
|
|
341
|
+
* @category layers
|
|
342
|
+
* @since 4.0.0
|
|
343
|
+
*/
|
|
344
|
+
const layerWebCrypto = /*#__PURE__*/ effect(Digest, /*#__PURE__*/ WebCrypto.use((crypto) => succeed({
|
|
345
|
+
digest: (algorithm, data) => webCryptoDigest(crypto, algorithm, data),
|
|
346
|
+
digestHex: (algorithm, data) => map(webCryptoDigest(crypto, algorithm, data), encode)
|
|
347
|
+
})));
|
|
348
|
+
export { webCryptoDigest as a, notExtractable as c, webCryptoError as d, DecryptionFailed as f, Unsupported as h, sha256 as i, run as l, InvalidKey as m, layerWebCrypto as n, fail as o, InvalidArgument as p, nameSuffix as r, invalidKey as s, Digest as t, runWithReference as u };
|