@akterjs/cli 0.0.0-stage → 0.1.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/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-C4cXx4Fr.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-_21Xi6HU.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,160 @@
|
|
|
1
|
+
import { Bt as hash, F as PipeInspectableProto, It as equals, Kt as symbol, Lt as symbol$1, cn as isString, qt as hasProperty } from "./Option-DkxSnBhp.mjs";
|
|
2
|
+
import { ut as make$1 } from "./Array-B4kuTQeW.mjs";
|
|
3
|
+
// ../../node_modules/.pnpm/effect@4.1.2_patch_hash=0e61176203bb1256381ce1c5b488d7951983ce38ff698647d3f4617383abbf07/node_modules/effect/dist/internal/redacted.js
|
|
4
|
+
/** @internal */
|
|
5
|
+
const redactedRegistry = /*#__PURE__*/ new WeakMap();
|
|
6
|
+
/** @internal */
|
|
7
|
+
const value$1 = (self) => {
|
|
8
|
+
if (redactedRegistry.has(self)) return redactedRegistry.get(self);
|
|
9
|
+
else throw new Error("Unable to get redacted value" + (self.label ? ` with label: "${self.label}"` : ""));
|
|
10
|
+
};
|
|
11
|
+
/** @internal */
|
|
12
|
+
const stringOrRedacted = (val) => typeof val === "string" ? val : value$1(val);
|
|
13
|
+
// ../../node_modules/.pnpm/effect@4.1.2_patch_hash=0e61176203bb1256381ce1c5b488d7951983ce38ff698647d3f4617383abbf07/node_modules/effect/dist/Redacted.js
|
|
14
|
+
/**
|
|
15
|
+
* Wraps sensitive values so normal output does not reveal them.
|
|
16
|
+
*
|
|
17
|
+
* A `Redacted<A>` shows a redacted placeholder in string, JSON, and inspection
|
|
18
|
+
* output, while still storing the original value for trusted code that needs to
|
|
19
|
+
* recover it. This helps reduce accidental leaks in logs and diagnostics. This
|
|
20
|
+
* module includes constructors, runtime checks, value recovery, wiping of stored
|
|
21
|
+
* values, and comparison helpers that avoid exposing the wrapped value at the
|
|
22
|
+
* call site.
|
|
23
|
+
*
|
|
24
|
+
* @stability stable
|
|
25
|
+
* @since 3.3.0
|
|
26
|
+
*/
|
|
27
|
+
const TypeId = "~effect/Redacted";
|
|
28
|
+
/**
|
|
29
|
+
* Returns `true` if a value is a `Redacted` wrapper.
|
|
30
|
+
*
|
|
31
|
+
* **When to use**
|
|
32
|
+
*
|
|
33
|
+
* Use to validate unknown input and narrow it to `Redacted`.
|
|
34
|
+
*
|
|
35
|
+
* **Details**
|
|
36
|
+
*
|
|
37
|
+
* When this function returns `true`, TypeScript narrows the value to
|
|
38
|
+
* `Redacted<unknown>`.
|
|
39
|
+
*
|
|
40
|
+
* **Example** (Checking for redacted values)
|
|
41
|
+
*
|
|
42
|
+
* ```ts import.meta.vitest
|
|
43
|
+
* import { Redacted } from "effect"
|
|
44
|
+
*
|
|
45
|
+
* const secret = Redacted.make("my-secret")
|
|
46
|
+
* const plainString = "not-secret"
|
|
47
|
+
*
|
|
48
|
+
* Redacted.isRedacted(secret) // => true
|
|
49
|
+
* Redacted.isRedacted(plainString) // => false
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @stability stable
|
|
53
|
+
* @category guards
|
|
54
|
+
* @since 3.3.0
|
|
55
|
+
*/
|
|
56
|
+
const isRedacted = (u) => hasProperty(u, TypeId);
|
|
57
|
+
/**
|
|
58
|
+
* Creates a `Redacted` wrapper for a sensitive value.
|
|
59
|
+
*
|
|
60
|
+
* **When to use**
|
|
61
|
+
*
|
|
62
|
+
* Use to wrap a sensitive value so normal string, JSON, and inspection output
|
|
63
|
+
* is redacted.
|
|
64
|
+
*
|
|
65
|
+
* **Details**
|
|
66
|
+
*
|
|
67
|
+
* The wrapper redacts string, JSON, and inspection output to reduce accidental
|
|
68
|
+
* disclosure. The original value remains retrievable with `Redacted.value`
|
|
69
|
+
* until the wrapper is wiped or becomes unreachable.
|
|
70
|
+
*
|
|
71
|
+
* **Example** (Creating a redacted value)
|
|
72
|
+
*
|
|
73
|
+
* ```ts import.meta.vitest
|
|
74
|
+
* import { Redacted } from "effect"
|
|
75
|
+
*
|
|
76
|
+
* const API_KEY = Redacted.make("1234567890")
|
|
77
|
+
* String(API_KEY) // => "<redacted>"
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @stability stable
|
|
81
|
+
* @category constructors
|
|
82
|
+
* @since 3.3.0
|
|
83
|
+
*/
|
|
84
|
+
const make = (value, options) => {
|
|
85
|
+
const self = Object.create(Proto);
|
|
86
|
+
if (options?.label) self.label = options.label;
|
|
87
|
+
redactedRegistry.set(self, value);
|
|
88
|
+
return self;
|
|
89
|
+
};
|
|
90
|
+
const Proto = {
|
|
91
|
+
[TypeId]: { _A: (_) => _ },
|
|
92
|
+
label: void 0,
|
|
93
|
+
...PipeInspectableProto,
|
|
94
|
+
toJSON() {
|
|
95
|
+
return this.toString();
|
|
96
|
+
},
|
|
97
|
+
toString() {
|
|
98
|
+
return `<redacted${isString(this.label) ? ":" + this.label : ""}>`;
|
|
99
|
+
},
|
|
100
|
+
[symbol]() {
|
|
101
|
+
return hash(redactedRegistry.get(this));
|
|
102
|
+
},
|
|
103
|
+
[symbol$1](that) {
|
|
104
|
+
return isRedacted(that) && equals(redactedRegistry.get(this), redactedRegistry.get(that));
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Retrieves the original value from a `Redacted` instance. Use this function
|
|
109
|
+
* with caution, as it exposes the sensitive data.
|
|
110
|
+
*
|
|
111
|
+
* **When to use**
|
|
112
|
+
*
|
|
113
|
+
* Use when you need the underlying sensitive value at a trusted boundary.
|
|
114
|
+
*
|
|
115
|
+
* **Example** (Retrieving a redacted value)
|
|
116
|
+
*
|
|
117
|
+
* ```ts import.meta.vitest
|
|
118
|
+
* import { Redacted } from "effect"
|
|
119
|
+
*
|
|
120
|
+
* const API_KEY = Redacted.make("1234567890")
|
|
121
|
+
*
|
|
122
|
+
* Redacted.value(API_KEY) // => "1234567890"
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @stability stable
|
|
126
|
+
* @category getters
|
|
127
|
+
* @since 3.3.0
|
|
128
|
+
*/
|
|
129
|
+
const value = value$1;
|
|
130
|
+
/**
|
|
131
|
+
* Generates an equivalence relation for `Redacted<A>` values based on an
|
|
132
|
+
* equivalence relation for the underlying values `A`. This function is useful
|
|
133
|
+
* for comparing `Redacted` instances without exposing their contents.
|
|
134
|
+
*
|
|
135
|
+
* **When to use**
|
|
136
|
+
*
|
|
137
|
+
* Use when you need to compare wrapped secrets through an approved equality
|
|
138
|
+
* rule without exposing the underlying values at each comparison site.
|
|
139
|
+
*
|
|
140
|
+
* **Example** (Comparing redacted values)
|
|
141
|
+
*
|
|
142
|
+
* ```ts import.meta.vitest
|
|
143
|
+
* import { Equivalence, Redacted } from "effect"
|
|
144
|
+
*
|
|
145
|
+
* const API_KEY1 = Redacted.make("1234567890")
|
|
146
|
+
* const API_KEY2 = Redacted.make("1-34567890")
|
|
147
|
+
* const API_KEY3 = Redacted.make("1234567890")
|
|
148
|
+
*
|
|
149
|
+
* const equivalence = Redacted.makeEquivalence(Equivalence.strictEqual<string>())
|
|
150
|
+
*
|
|
151
|
+
* equivalence(API_KEY1, API_KEY2) // => false
|
|
152
|
+
* equivalence(API_KEY1, API_KEY3) // => true
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @stability stable
|
|
156
|
+
* @category instances
|
|
157
|
+
* @since 4.0.0
|
|
158
|
+
*/
|
|
159
|
+
const makeEquivalence = (isEquivalent) => make$1((x, y) => isEquivalent(value(x), value(y)));
|
|
160
|
+
export { stringOrRedacted as a, value as i, make as n, makeEquivalence as r, isRedacted as t };
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { en as sync } from "./Effect-CKFpqbmw.mjs";
|
|
2
|
+
import { F as PipeInspectableProto, Sn as identity, bn as dual } from "./Option-DkxSnBhp.mjs";
|
|
3
|
+
import { n as set$1, t as make$1 } from "./MutableRef-D4Qv592C.mjs";
|
|
4
|
+
// ../../node_modules/.pnpm/effect@4.1.2_patch_hash=0e61176203bb1256381ce1c5b488d7951983ce38ff698647d3f4617383abbf07/node_modules/effect/dist/Ref.js
|
|
5
|
+
/**
|
|
6
|
+
* Stores fiber-safe mutable state inside Effect programs.
|
|
7
|
+
*
|
|
8
|
+
* A `Ref<A>` holds one value and exposes reads, writes, and atomic
|
|
9
|
+
* transformations as effects, so state changes compose with Effect's
|
|
10
|
+
* concurrency model. This module includes constructors, safe and unsafe reads,
|
|
11
|
+
* set and get-and-set helpers, update and modify helpers, and conditional
|
|
12
|
+
* update variants that leave the value unchanged when an `Option.none` result
|
|
13
|
+
* is returned.
|
|
14
|
+
*
|
|
15
|
+
* @stability stable
|
|
16
|
+
* @since 2.0.0
|
|
17
|
+
*/
|
|
18
|
+
const RefProto = {
|
|
19
|
+
["~effect/Ref"]: { _A: identity },
|
|
20
|
+
...PipeInspectableProto,
|
|
21
|
+
toJSON() {
|
|
22
|
+
return {
|
|
23
|
+
_id: "Ref",
|
|
24
|
+
ref: this.ref
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new Ref with the specified initial value (unsafe version).
|
|
30
|
+
*
|
|
31
|
+
* **When to use**
|
|
32
|
+
*
|
|
33
|
+
* Use when you need immediate synchronous construction and can guarantee
|
|
34
|
+
* that creating the `Ref` outside of `Effect` is safe.
|
|
35
|
+
*
|
|
36
|
+
* **Gotchas**
|
|
37
|
+
*
|
|
38
|
+
* Prefer `Ref.make` for Effect-wrapped creation in Effect programs.
|
|
39
|
+
*
|
|
40
|
+
* **Example** (Creating a ref unsafely)
|
|
41
|
+
*
|
|
42
|
+
* ```ts import.meta.vitest
|
|
43
|
+
* import { Ref } from "effect"
|
|
44
|
+
*
|
|
45
|
+
* const counter = Ref.makeUnsafe(0)
|
|
46
|
+
* Ref.getUnsafe(counter) // => 0
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @stability stable
|
|
50
|
+
* @category constructors
|
|
51
|
+
* @since 4.0.0
|
|
52
|
+
*/
|
|
53
|
+
const makeUnsafe = (value) => {
|
|
54
|
+
const self = Object.create(RefProto);
|
|
55
|
+
self.ref = make$1(value);
|
|
56
|
+
return self;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new Ref with the specified initial value.
|
|
60
|
+
*
|
|
61
|
+
* **When to use**
|
|
62
|
+
*
|
|
63
|
+
* Use to create a `Ref` for shared mutable state inside an Effect program.
|
|
64
|
+
*
|
|
65
|
+
* **Example** (Creating a ref)
|
|
66
|
+
*
|
|
67
|
+
* ```ts import.meta.vitest
|
|
68
|
+
* import { Effect, Ref } from "effect"
|
|
69
|
+
*
|
|
70
|
+
* const program = Effect.gen(function*() {
|
|
71
|
+
* const ref = yield* Ref.make(42)
|
|
72
|
+
* return yield* Ref.get(ref)
|
|
73
|
+
* })
|
|
74
|
+
*
|
|
75
|
+
* await Effect.runPromise(program) // => 42
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @see {@link makeUnsafe} for synchronous construction outside Effect code
|
|
79
|
+
*
|
|
80
|
+
* @stability stable
|
|
81
|
+
* @category constructors
|
|
82
|
+
* @since 2.0.0
|
|
83
|
+
*/
|
|
84
|
+
const make = (value) => sync(() => makeUnsafe(value));
|
|
85
|
+
/**
|
|
86
|
+
* Gets the current value of the Ref.
|
|
87
|
+
*
|
|
88
|
+
* **When to use**
|
|
89
|
+
*
|
|
90
|
+
* Use to read the current `Ref` value without changing it.
|
|
91
|
+
*
|
|
92
|
+
* **Example** (Getting the current value)
|
|
93
|
+
*
|
|
94
|
+
* ```ts import.meta.vitest
|
|
95
|
+
* import { Effect, Ref } from "effect"
|
|
96
|
+
*
|
|
97
|
+
* const program = Effect.gen(function*() {
|
|
98
|
+
* const ref = yield* Ref.make(42)
|
|
99
|
+
* return yield* Ref.get(ref)
|
|
100
|
+
* })
|
|
101
|
+
*
|
|
102
|
+
* await Effect.runPromise(program) // => 42
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @see {@link set} for replacing the current value
|
|
106
|
+
*
|
|
107
|
+
* @stability stable
|
|
108
|
+
* @category getters
|
|
109
|
+
* @since 2.0.0
|
|
110
|
+
*/
|
|
111
|
+
const get = (self) => sync(() => self.ref.current);
|
|
112
|
+
/**
|
|
113
|
+
* Sets the value of the Ref to the specified value.
|
|
114
|
+
*
|
|
115
|
+
* **When to use**
|
|
116
|
+
*
|
|
117
|
+
* Use to replace the current `Ref` value with a known value.
|
|
118
|
+
*
|
|
119
|
+
* **Example** (Setting a value)
|
|
120
|
+
*
|
|
121
|
+
* ```ts import.meta.vitest
|
|
122
|
+
* import { Effect, Ref } from "effect"
|
|
123
|
+
*
|
|
124
|
+
* const program = Effect.gen(function*() {
|
|
125
|
+
* const ref = yield* Ref.make(0)
|
|
126
|
+
* yield* Ref.set(ref, 42)
|
|
127
|
+
* return yield* Ref.get(ref)
|
|
128
|
+
* })
|
|
129
|
+
*
|
|
130
|
+
* const program2 = Effect.gen(function*() {
|
|
131
|
+
* const ref = yield* Ref.make(0)
|
|
132
|
+
* yield* Ref.set(ref, 100)
|
|
133
|
+
* return yield* Ref.get(ref)
|
|
134
|
+
* })
|
|
135
|
+
*
|
|
136
|
+
* await Effect.runPromise(program) // => 42
|
|
137
|
+
* await Effect.runPromise(program2) // => 100
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @see {@link getAndSet} for setting while returning the previous value
|
|
141
|
+
* @see {@link setAndGet} for setting while returning the new value
|
|
142
|
+
*
|
|
143
|
+
* @stability stable
|
|
144
|
+
* @category mutations
|
|
145
|
+
* @since 2.0.0
|
|
146
|
+
*/
|
|
147
|
+
const set = /*#__PURE__*/ dual(2, (self, value) => sync(() => set$1(self.ref, value)));
|
|
148
|
+
/**
|
|
149
|
+
* Modifies the value of the Ref atomically using the given function.
|
|
150
|
+
*
|
|
151
|
+
* **When to use**
|
|
152
|
+
*
|
|
153
|
+
* Use to compute both a separate return value and the next stored `Ref` value
|
|
154
|
+
* in one atomic update.
|
|
155
|
+
*
|
|
156
|
+
* **Details**
|
|
157
|
+
*
|
|
158
|
+
* The function receives the current value and returns a tuple of
|
|
159
|
+
* `[result, newValue]`. The Ref is updated with `newValue`, and `result` is
|
|
160
|
+
* returned by the effect.
|
|
161
|
+
*
|
|
162
|
+
* **Example** (Modifying a value atomically)
|
|
163
|
+
*
|
|
164
|
+
* ```ts import.meta.vitest
|
|
165
|
+
* import { Effect, Ref } from "effect"
|
|
166
|
+
*
|
|
167
|
+
* const program = Effect.gen(function*() {
|
|
168
|
+
* const counter = yield* Ref.make(10)
|
|
169
|
+
*
|
|
170
|
+
* const result = yield* Ref.modify(counter, (n) => [
|
|
171
|
+
* `Previous value was ${n}`,
|
|
172
|
+
* n * 2
|
|
173
|
+
* ])
|
|
174
|
+
* const current = yield* Ref.get(counter)
|
|
175
|
+
* return [result, current]
|
|
176
|
+
* })
|
|
177
|
+
*
|
|
178
|
+
* const program2 = Effect.gen(function*() {
|
|
179
|
+
* const state = yield* Ref.make({ count: 0, total: 0 })
|
|
180
|
+
* return yield* Ref.modify(state, (s) => [
|
|
181
|
+
* s.count,
|
|
182
|
+
* { count: s.count + 1, total: s.total + s.count + 1 }
|
|
183
|
+
* ])
|
|
184
|
+
* })
|
|
185
|
+
*
|
|
186
|
+
* await Effect.runPromise(program) // => ["Previous value was 10", 20]
|
|
187
|
+
* await Effect.runPromise(program2) // => 0
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @see {@link updateAndGet} for returning the new stored value
|
|
191
|
+
* @see {@link modifySome} for optionally updating while returning a separate result
|
|
192
|
+
*
|
|
193
|
+
* @stability stable
|
|
194
|
+
* @category mutations
|
|
195
|
+
* @since 2.0.0
|
|
196
|
+
*/
|
|
197
|
+
const modify = /*#__PURE__*/ dual(2, (self, f) => sync(() => {
|
|
198
|
+
const [b, a] = f(self.ref.current);
|
|
199
|
+
self.ref.current = a;
|
|
200
|
+
return b;
|
|
201
|
+
}));
|
|
202
|
+
/**
|
|
203
|
+
* Updates the value of the Ref atomically using the given function.
|
|
204
|
+
*
|
|
205
|
+
* **When to use**
|
|
206
|
+
*
|
|
207
|
+
* Use to apply a `Ref` state transition without returning a value.
|
|
208
|
+
*
|
|
209
|
+
* **Example** (Updating a value)
|
|
210
|
+
*
|
|
211
|
+
* ```ts import.meta.vitest
|
|
212
|
+
* import { Effect, Ref } from "effect"
|
|
213
|
+
*
|
|
214
|
+
* const program = Effect.gen(function*() {
|
|
215
|
+
* const counter = yield* Ref.make(5)
|
|
216
|
+
*
|
|
217
|
+
* yield* Ref.update(counter, (n) => n * 2)
|
|
218
|
+
* return yield* Ref.get(counter)
|
|
219
|
+
* })
|
|
220
|
+
*
|
|
221
|
+
* const program2 = Effect.gen(function*() {
|
|
222
|
+
* const counter = yield* Ref.make(5)
|
|
223
|
+
* yield* Ref.update(counter, (n: number) => n + 10)
|
|
224
|
+
* return yield* Ref.get(counter)
|
|
225
|
+
* })
|
|
226
|
+
*
|
|
227
|
+
* await Effect.runPromise(program) // => 10
|
|
228
|
+
* await Effect.runPromise(program2) // => 15
|
|
229
|
+
* ```
|
|
230
|
+
*
|
|
231
|
+
* @see {@link updateAndGet} for returning the new value
|
|
232
|
+
* @see {@link getAndUpdate} for returning the previous value
|
|
233
|
+
*
|
|
234
|
+
* @stability stable
|
|
235
|
+
* @category mutations
|
|
236
|
+
* @since 2.0.0
|
|
237
|
+
*/
|
|
238
|
+
const update = /*#__PURE__*/ dual(2, (self, f) => sync(() => {
|
|
239
|
+
self.ref.current = f(self.ref.current);
|
|
240
|
+
}));
|
|
241
|
+
/**
|
|
242
|
+
* Gets the current value of the Ref synchronously (unsafe version).
|
|
243
|
+
*
|
|
244
|
+
* **When to use**
|
|
245
|
+
*
|
|
246
|
+
* Use when you need immediate synchronous access and can guarantee that
|
|
247
|
+
* reading the `Ref` outside of `Effect` is safe.
|
|
248
|
+
*
|
|
249
|
+
* **Gotchas**
|
|
250
|
+
*
|
|
251
|
+
* Prefer `Ref.get` for Effect-wrapped access in Effect programs.
|
|
252
|
+
*
|
|
253
|
+
* **Example** (Reading a ref unsafely)
|
|
254
|
+
*
|
|
255
|
+
* ```ts import.meta.vitest
|
|
256
|
+
* import { Ref } from "effect"
|
|
257
|
+
*
|
|
258
|
+
* const counter = Ref.makeUnsafe(42)
|
|
259
|
+
* Ref.getUnsafe(counter) // => 42
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @stability stable
|
|
263
|
+
* @category getters
|
|
264
|
+
* @since 4.0.0
|
|
265
|
+
*/
|
|
266
|
+
const getUnsafe = (self) => self.ref.current;
|
|
267
|
+
export { modify as a, makeUnsafe as i, getUnsafe as n, set as o, make as r, update as s, get as t };
|