@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,791 @@
|
|
|
1
|
+
import { Bt as hash, Ct as NodeInspectSymbol, Kt as symbol, Lt as symbol$1, On as pipeArguments, Sn as identity, Wt as structure, bn as dual, in as isNumber, qt as hasProperty } from "./Option-DkxSnBhp.mjs";
|
|
2
|
+
import { d as make$1, m as min$1, p as max$1, u as isLessThanOrEqualTo$1 } from "./Order-C1JC991I.mjs";
|
|
3
|
+
// ../../node_modules/.pnpm/effect@4.1.2_patch_hash=0e61176203bb1256381ce1c5b488d7951983ce38ff698647d3f4617383abbf07/node_modules/effect/dist/Duration.js
|
|
4
|
+
const TypeId = "~effect/Duration";
|
|
5
|
+
const bigint0 = /*#__PURE__*/ BigInt(0);
|
|
6
|
+
const bigint1 = /*#__PURE__*/ BigInt(1);
|
|
7
|
+
const bigint2 = /*#__PURE__*/ BigInt(2);
|
|
8
|
+
const bigint10 = /*#__PURE__*/ BigInt(10);
|
|
9
|
+
const bigint24 = /*#__PURE__*/ BigInt(24);
|
|
10
|
+
const bigint60 = /*#__PURE__*/ BigInt(60);
|
|
11
|
+
const bigint1e3 = /*#__PURE__*/ BigInt(1e3);
|
|
12
|
+
const bigint1e6 = /*#__PURE__*/ BigInt(1e6);
|
|
13
|
+
const bigint1e9 = /*#__PURE__*/ BigInt(1e9);
|
|
14
|
+
const bigintNanosPerMinute = /*#__PURE__*/ BigInt(6e10);
|
|
15
|
+
const bigintNanosPerHour = /*#__PURE__*/ BigInt(36e11);
|
|
16
|
+
const bigintNanosPerDay = /*#__PURE__*/ BigInt(864e11);
|
|
17
|
+
const bigintNanosPerWeek = /*#__PURE__*/ BigInt(6048e11);
|
|
18
|
+
const roundTiesAwayFromZero = (input) => BigInt(Math.sign(input) * Math.round(Math.abs(input)));
|
|
19
|
+
const roundMillisToNanos = (millis) => Number.isInteger(millis) ? BigInt(millis) * bigint1e6 : roundTiesAwayFromZero(millis * 1e6);
|
|
20
|
+
const fromNanosNumber = (nanos) => make(Number.isFinite(nanos) ? roundTiesAwayFromZero(nanos) : nanos);
|
|
21
|
+
const nanosToUnit = (nanos, divisor) => {
|
|
22
|
+
const value = Number(nanos);
|
|
23
|
+
if (Number.isFinite(value)) return value / divisor;
|
|
24
|
+
const scale = BigInt(divisor);
|
|
25
|
+
return Number(nanos / scale) + Number(nanos % scale) / divisor;
|
|
26
|
+
};
|
|
27
|
+
const parseNanos = (input, scale) => {
|
|
28
|
+
const decimalIndex = input.indexOf(".");
|
|
29
|
+
if (decimalIndex === -1) return BigInt(input) * scale;
|
|
30
|
+
const isNegative = input[0] === "-";
|
|
31
|
+
const fractional = input.slice(decimalIndex + 1);
|
|
32
|
+
const fractionalScale = bigint10 ** BigInt(fractional.length);
|
|
33
|
+
const scaled = (BigInt(input.slice(isNegative ? 1 : 0, decimalIndex)) * fractionalScale + BigInt(fractional)) * scale;
|
|
34
|
+
return divideTiesAwayFromZero(isNegative ? -scaled : scaled, fractionalScale);
|
|
35
|
+
};
|
|
36
|
+
const divideTiesAwayFromZero = (numerator, denominator) => {
|
|
37
|
+
const absolute = numerator < bigint0 ? -numerator : numerator;
|
|
38
|
+
const rounded = absolute / denominator + (absolute % denominator * bigint2 >= denominator ? bigint1 : bigint0);
|
|
39
|
+
return numerator < bigint0 ? -rounded : rounded;
|
|
40
|
+
};
|
|
41
|
+
const fromMillisString = (input, scale) => {
|
|
42
|
+
const millis = Number(input) * scale;
|
|
43
|
+
if (!Number.isFinite(millis)) return make(millis);
|
|
44
|
+
const nanos = parseNanos(input, BigInt(scale) * bigint1e6);
|
|
45
|
+
return make(Number.isInteger(millis) && BigInt(millis) * bigint1e6 === nanos ? millis : nanos);
|
|
46
|
+
};
|
|
47
|
+
const DURATION_REGEXP = /^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/;
|
|
48
|
+
/**
|
|
49
|
+
* Decodes a `Duration.Input` into a `Duration`.
|
|
50
|
+
*
|
|
51
|
+
* **When to use**
|
|
52
|
+
*
|
|
53
|
+
* Use when the input has already been validated or comes from a trusted source
|
|
54
|
+
* and throwing is acceptable for invalid duration syntax.
|
|
55
|
+
*
|
|
56
|
+
* **Gotchas**
|
|
57
|
+
*
|
|
58
|
+
* If the input is not a valid `Duration.Input`, it throws an error.
|
|
59
|
+
*
|
|
60
|
+
* **Example** (Decoding duration inputs)
|
|
61
|
+
*
|
|
62
|
+
* ```ts import.meta.vitest
|
|
63
|
+
* import { Duration } from "effect"
|
|
64
|
+
*
|
|
65
|
+
* Duration.fromInputUnsafe(1000) // => Duration.millis(1000)
|
|
66
|
+
* Duration.fromInputUnsafe("5 seconds") // => Duration.seconds(5)
|
|
67
|
+
* Duration.fromInputUnsafe("Infinity") // => Duration.infinity
|
|
68
|
+
* Duration.fromInputUnsafe([2, 500_000_000]) // => Duration.nanos(2_500_000_000n)
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @stability stable
|
|
72
|
+
* @category constructors
|
|
73
|
+
* @since 4.0.0
|
|
74
|
+
*/
|
|
75
|
+
const fromInputUnsafe = (input) => {
|
|
76
|
+
switch (typeof input) {
|
|
77
|
+
case "number": return millis(input);
|
|
78
|
+
case "bigint": return nanos(input);
|
|
79
|
+
case "string": {
|
|
80
|
+
if (input === "Infinity") return infinity;
|
|
81
|
+
if (input === "-Infinity") return negativeInfinity;
|
|
82
|
+
const match = DURATION_REGEXP.exec(input);
|
|
83
|
+
if (!match) break;
|
|
84
|
+
const [_, valueStr, unit] = match;
|
|
85
|
+
if (unit === "nano" || unit === "nanos") return nanos(parseNanos(valueStr, bigint1));
|
|
86
|
+
if (unit === "micro" || unit === "micros") return nanos(parseNanos(valueStr, bigint1e3));
|
|
87
|
+
switch (unit) {
|
|
88
|
+
case "milli":
|
|
89
|
+
case "millis": return fromMillisString(valueStr, 1);
|
|
90
|
+
case "second":
|
|
91
|
+
case "seconds": return fromMillisString(valueStr, 1e3);
|
|
92
|
+
case "minute":
|
|
93
|
+
case "minutes": return fromMillisString(valueStr, 6e4);
|
|
94
|
+
case "hour":
|
|
95
|
+
case "hours": return fromMillisString(valueStr, 36e5);
|
|
96
|
+
case "day":
|
|
97
|
+
case "days": return fromMillisString(valueStr, 864e5);
|
|
98
|
+
case "week":
|
|
99
|
+
case "weeks": return fromMillisString(valueStr, 6048e5);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case "object": {
|
|
104
|
+
if (input === null) break;
|
|
105
|
+
if (TypeId in input) return input;
|
|
106
|
+
if (Array.isArray(input)) {
|
|
107
|
+
if (input.length !== 2 || !input.every(isNumber)) return invalid(input);
|
|
108
|
+
if (Number.isNaN(input[0]) || Number.isNaN(input[1])) return zero;
|
|
109
|
+
if (input[0] === -Infinity || input[1] === -Infinity) return negativeInfinity;
|
|
110
|
+
if (input[0] === Infinity || input[1] === Infinity) return infinity;
|
|
111
|
+
const nanos = input[0] * 1e9 + input[1];
|
|
112
|
+
return Number.isFinite(nanos) && Number.isInteger(input[0]) && Number.isInteger(input[1]) ? make(BigInt(input[0]) * bigint1e9 + BigInt(input[1])) : fromNanosNumber(nanos);
|
|
113
|
+
}
|
|
114
|
+
const obj = input;
|
|
115
|
+
let millis = 0;
|
|
116
|
+
if (obj.weeks) millis += obj.weeks * 6048e5;
|
|
117
|
+
if (obj.days) millis += obj.days * 864e5;
|
|
118
|
+
if (obj.hours) millis += obj.hours * 36e5;
|
|
119
|
+
if (obj.minutes) millis += obj.minutes * 6e4;
|
|
120
|
+
if (obj.seconds) millis += obj.seconds * 1e3;
|
|
121
|
+
if (obj.milliseconds) millis += obj.milliseconds;
|
|
122
|
+
if (!obj.microseconds && !obj.nanoseconds) {
|
|
123
|
+
if (!Number.isFinite(millis)) return make(millis);
|
|
124
|
+
const exact = sumObjectNanos(obj);
|
|
125
|
+
return exact === void 0 || BigInt(millis) * bigint1e6 === exact ? make(millis) : make(exact);
|
|
126
|
+
}
|
|
127
|
+
const nanos = millis * 1e6 + (obj.microseconds ?? 0) * 1e3 + (obj.nanoseconds ?? 0);
|
|
128
|
+
const exact = Number.isFinite(nanos) ? sumObjectNanos(obj) : void 0;
|
|
129
|
+
return exact === void 0 ? fromNanosNumber(nanos) : make(exact);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return invalid(input);
|
|
133
|
+
};
|
|
134
|
+
const isIntegerOrUnset = (n) => !n || Number.isInteger(n);
|
|
135
|
+
const sumObjectNanos = (obj) => {
|
|
136
|
+
if (!isIntegerOrUnset(obj.weeks) || !isIntegerOrUnset(obj.days) || !isIntegerOrUnset(obj.hours) || !isIntegerOrUnset(obj.minutes) || !isIntegerOrUnset(obj.seconds) || !isIntegerOrUnset(obj.milliseconds) || !isIntegerOrUnset(obj.microseconds) || !isIntegerOrUnset(obj.nanoseconds)) return void 0;
|
|
137
|
+
let nanos = bigint0;
|
|
138
|
+
if (obj.weeks) nanos += BigInt(obj.weeks) * bigintNanosPerWeek;
|
|
139
|
+
if (obj.days) nanos += BigInt(obj.days) * bigintNanosPerDay;
|
|
140
|
+
if (obj.hours) nanos += BigInt(obj.hours) * bigintNanosPerHour;
|
|
141
|
+
if (obj.minutes) nanos += BigInt(obj.minutes) * bigintNanosPerMinute;
|
|
142
|
+
if (obj.seconds) nanos += BigInt(obj.seconds) * bigint1e9;
|
|
143
|
+
if (obj.milliseconds) nanos += BigInt(obj.milliseconds) * bigint1e6;
|
|
144
|
+
if (obj.microseconds) nanos += BigInt(obj.microseconds) * bigint1e3;
|
|
145
|
+
if (obj.nanoseconds) nanos += BigInt(obj.nanoseconds);
|
|
146
|
+
return nanos;
|
|
147
|
+
};
|
|
148
|
+
const invalid = (input) => {
|
|
149
|
+
throw new Error(`Invalid Input: ${input}`);
|
|
150
|
+
};
|
|
151
|
+
const zeroDurationValue = {
|
|
152
|
+
_tag: "Millis",
|
|
153
|
+
millis: 0
|
|
154
|
+
};
|
|
155
|
+
const infinityDurationValue = { _tag: "Infinity" };
|
|
156
|
+
const negativeInfinityDurationValue = { _tag: "NegativeInfinity" };
|
|
157
|
+
const DurationProto = {
|
|
158
|
+
[TypeId]: TypeId,
|
|
159
|
+
[symbol]() {
|
|
160
|
+
switch (this.value._tag) {
|
|
161
|
+
case "Millis": return hash(roundMillisToNanos(this.value.millis));
|
|
162
|
+
case "Nanos": return hash(this.value.nanos);
|
|
163
|
+
default: return structure(this.value);
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
[symbol$1](that) {
|
|
167
|
+
return isDuration(that) && equals(this, that);
|
|
168
|
+
},
|
|
169
|
+
toString() {
|
|
170
|
+
switch (this.value._tag) {
|
|
171
|
+
case "Infinity": return "Infinity";
|
|
172
|
+
case "NegativeInfinity": return "-Infinity";
|
|
173
|
+
case "Nanos": return `${this.value.nanos} nanos`;
|
|
174
|
+
case "Millis": return `${this.value.millis} millis`;
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
toJSON() {
|
|
178
|
+
switch (this.value._tag) {
|
|
179
|
+
case "Millis": return {
|
|
180
|
+
_id: "Duration",
|
|
181
|
+
_tag: "Millis",
|
|
182
|
+
millis: this.value.millis
|
|
183
|
+
};
|
|
184
|
+
case "Nanos": return {
|
|
185
|
+
_id: "Duration",
|
|
186
|
+
_tag: "Nanos",
|
|
187
|
+
nanos: String(this.value.nanos)
|
|
188
|
+
};
|
|
189
|
+
case "Infinity": return {
|
|
190
|
+
_id: "Duration",
|
|
191
|
+
_tag: "Infinity"
|
|
192
|
+
};
|
|
193
|
+
case "NegativeInfinity": return {
|
|
194
|
+
_id: "Duration",
|
|
195
|
+
_tag: "NegativeInfinity"
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
[NodeInspectSymbol]() {
|
|
200
|
+
return this.toJSON();
|
|
201
|
+
},
|
|
202
|
+
pipe() {
|
|
203
|
+
return pipeArguments(this, arguments);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const make = (input) => {
|
|
207
|
+
const duration = Object.create(DurationProto);
|
|
208
|
+
if (typeof input === "number") {
|
|
209
|
+
if (isNaN(input) || input === 0 || Object.is(input, -0)) duration.value = zeroDurationValue;
|
|
210
|
+
else if (!Number.isFinite(input)) duration.value = input > 0 ? infinityDurationValue : negativeInfinityDurationValue;
|
|
211
|
+
else if (!Number.isInteger(input)) duration.value = {
|
|
212
|
+
_tag: "Nanos",
|
|
213
|
+
nanos: roundMillisToNanos(input)
|
|
214
|
+
};
|
|
215
|
+
else duration.value = {
|
|
216
|
+
_tag: "Millis",
|
|
217
|
+
millis: input
|
|
218
|
+
};
|
|
219
|
+
} else if (input === bigint0) duration.value = zeroDurationValue;
|
|
220
|
+
else duration.value = {
|
|
221
|
+
_tag: "Nanos",
|
|
222
|
+
nanos: input
|
|
223
|
+
};
|
|
224
|
+
return duration;
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Checks whether a value is a Duration.
|
|
228
|
+
*
|
|
229
|
+
* **Example** (Checking for durations)
|
|
230
|
+
*
|
|
231
|
+
* ```ts import.meta.vitest
|
|
232
|
+
* import { Duration } from "effect"
|
|
233
|
+
*
|
|
234
|
+
* Duration.isDuration(Duration.seconds(1)) // => true
|
|
235
|
+
* Duration.isDuration(1000) // => false
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* @stability stable
|
|
239
|
+
* @category guards
|
|
240
|
+
* @since 2.0.0
|
|
241
|
+
*/
|
|
242
|
+
const isDuration = (u) => hasProperty(u, TypeId);
|
|
243
|
+
/**
|
|
244
|
+
* Checks whether a Duration is finite (not infinite).
|
|
245
|
+
*
|
|
246
|
+
* **Example** (Checking finite durations)
|
|
247
|
+
*
|
|
248
|
+
* ```ts import.meta.vitest
|
|
249
|
+
* import { Duration } from "effect"
|
|
250
|
+
*
|
|
251
|
+
* Duration.isFinite(Duration.seconds(5)) // => true
|
|
252
|
+
* Duration.isFinite(Duration.infinity) // => false
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* @stability stable
|
|
256
|
+
* @category predicates
|
|
257
|
+
* @since 2.0.0
|
|
258
|
+
*/
|
|
259
|
+
const isFinite = (self) => self.value._tag !== "Infinity" && self.value._tag !== "NegativeInfinity";
|
|
260
|
+
/**
|
|
261
|
+
* Checks whether a Duration is zero.
|
|
262
|
+
*
|
|
263
|
+
* **Example** (Checking for zero durations)
|
|
264
|
+
*
|
|
265
|
+
* ```ts import.meta.vitest
|
|
266
|
+
* import { Duration } from "effect"
|
|
267
|
+
*
|
|
268
|
+
* Duration.isZero(Duration.zero) // => true
|
|
269
|
+
* Duration.isZero(Duration.seconds(1)) // => false
|
|
270
|
+
* ```
|
|
271
|
+
*
|
|
272
|
+
* @stability stable
|
|
273
|
+
* @category predicates
|
|
274
|
+
* @since 3.5.0
|
|
275
|
+
*/
|
|
276
|
+
const isZero = (self) => {
|
|
277
|
+
switch (self.value._tag) {
|
|
278
|
+
case "Millis": return self.value.millis === 0;
|
|
279
|
+
case "Nanos": return self.value.nanos === bigint0;
|
|
280
|
+
case "Infinity":
|
|
281
|
+
case "NegativeInfinity": return false;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* Returns `true` if the duration is negative (strictly less than zero).
|
|
286
|
+
*
|
|
287
|
+
* **Example** (Checking for negative durations)
|
|
288
|
+
*
|
|
289
|
+
* ```ts import.meta.vitest
|
|
290
|
+
* import { Duration } from "effect"
|
|
291
|
+
*
|
|
292
|
+
* Duration.isNegative(Duration.seconds(-5)) // => true
|
|
293
|
+
* Duration.isNegative(Duration.zero) // => false
|
|
294
|
+
* Duration.isNegative(Duration.negativeInfinity) // => true
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* @stability stable
|
|
298
|
+
* @category predicates
|
|
299
|
+
* @since 4.0.0
|
|
300
|
+
*/
|
|
301
|
+
const isNegative = (self) => {
|
|
302
|
+
switch (self.value._tag) {
|
|
303
|
+
case "Millis": return self.value.millis < 0;
|
|
304
|
+
case "Nanos": return self.value.nanos < bigint0;
|
|
305
|
+
case "NegativeInfinity": return true;
|
|
306
|
+
case "Infinity": return false;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* Returns the absolute value of the duration.
|
|
311
|
+
*
|
|
312
|
+
* **Example** (Taking absolute duration values)
|
|
313
|
+
*
|
|
314
|
+
* ```ts import.meta.vitest
|
|
315
|
+
* import { Duration } from "effect"
|
|
316
|
+
*
|
|
317
|
+
* Duration.abs(Duration.seconds(-5)) // => Duration.seconds(5)
|
|
318
|
+
* Duration.abs(Duration.negativeInfinity) // => Duration.infinity
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @stability stable
|
|
322
|
+
* @category math
|
|
323
|
+
* @since 4.0.0
|
|
324
|
+
*/
|
|
325
|
+
const abs = (self) => {
|
|
326
|
+
switch (self.value._tag) {
|
|
327
|
+
case "Infinity":
|
|
328
|
+
case "NegativeInfinity": return infinity;
|
|
329
|
+
case "Millis": return self.value.millis < 0 ? make(-self.value.millis) : self;
|
|
330
|
+
case "Nanos": return self.value.nanos < bigint0 ? make(-self.value.nanos) : self;
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* A Duration representing zero time.
|
|
335
|
+
*
|
|
336
|
+
* **Example** (Referencing the zero duration)
|
|
337
|
+
*
|
|
338
|
+
* ```ts import.meta.vitest
|
|
339
|
+
* import { Duration } from "effect"
|
|
340
|
+
*
|
|
341
|
+
* Duration.toMillis(Duration.zero) // => 0
|
|
342
|
+
* ```
|
|
343
|
+
*
|
|
344
|
+
* @stability stable
|
|
345
|
+
* @category constructors
|
|
346
|
+
* @since 2.0.0
|
|
347
|
+
*/
|
|
348
|
+
const zero = /*#__PURE__*/ make(0);
|
|
349
|
+
/**
|
|
350
|
+
* A Duration representing infinite time.
|
|
351
|
+
*
|
|
352
|
+
* **Example** (Referencing infinite duration)
|
|
353
|
+
*
|
|
354
|
+
* ```ts import.meta.vitest
|
|
355
|
+
* import { Duration } from "effect"
|
|
356
|
+
*
|
|
357
|
+
* Duration.toMillis(Duration.infinity) // => Infinity
|
|
358
|
+
* ```
|
|
359
|
+
*
|
|
360
|
+
* @stability stable
|
|
361
|
+
* @category constructors
|
|
362
|
+
* @since 2.0.0
|
|
363
|
+
*/
|
|
364
|
+
const infinity = /*#__PURE__*/ make(Infinity);
|
|
365
|
+
/**
|
|
366
|
+
* A Duration representing negative infinite time.
|
|
367
|
+
*
|
|
368
|
+
* **Example** (Referencing negative infinite duration)
|
|
369
|
+
*
|
|
370
|
+
* ```ts import.meta.vitest
|
|
371
|
+
* import { Duration } from "effect"
|
|
372
|
+
*
|
|
373
|
+
* Duration.toMillis(Duration.negativeInfinity) // => -Infinity
|
|
374
|
+
* ```
|
|
375
|
+
*
|
|
376
|
+
* @stability stable
|
|
377
|
+
* @category constructors
|
|
378
|
+
* @since 4.0.0
|
|
379
|
+
*/
|
|
380
|
+
const negativeInfinity = /*#__PURE__*/ make(-Infinity);
|
|
381
|
+
/**
|
|
382
|
+
* Creates a Duration from nanoseconds.
|
|
383
|
+
*
|
|
384
|
+
* **Example** (Creating durations from nanoseconds)
|
|
385
|
+
*
|
|
386
|
+
* ```ts import.meta.vitest
|
|
387
|
+
* import { Duration } from "effect"
|
|
388
|
+
*
|
|
389
|
+
* Duration.nanos(500_000_000n) // => Duration.nanos(500_000_000n)
|
|
390
|
+
* ```
|
|
391
|
+
*
|
|
392
|
+
* @stability stable
|
|
393
|
+
* @category constructors
|
|
394
|
+
* @since 2.0.0
|
|
395
|
+
*/
|
|
396
|
+
const nanos = (nanos) => make(nanos);
|
|
397
|
+
/**
|
|
398
|
+
* Creates a Duration from milliseconds.
|
|
399
|
+
*
|
|
400
|
+
* **Example** (Creating durations from milliseconds)
|
|
401
|
+
*
|
|
402
|
+
* ```ts import.meta.vitest
|
|
403
|
+
* import { Duration } from "effect"
|
|
404
|
+
*
|
|
405
|
+
* Duration.toMillis(Duration.millis(1000)) // => 1000
|
|
406
|
+
* ```
|
|
407
|
+
*
|
|
408
|
+
* @stability stable
|
|
409
|
+
* @category constructors
|
|
410
|
+
* @since 2.0.0
|
|
411
|
+
*/
|
|
412
|
+
const millis = (millis) => make(millis);
|
|
413
|
+
/**
|
|
414
|
+
* Creates a Duration from seconds.
|
|
415
|
+
*
|
|
416
|
+
* **Example** (Creating durations from seconds)
|
|
417
|
+
*
|
|
418
|
+
* ```ts import.meta.vitest
|
|
419
|
+
* import { Duration } from "effect"
|
|
420
|
+
*
|
|
421
|
+
* Duration.toMillis(Duration.seconds(30)) // => 30_000
|
|
422
|
+
* ```
|
|
423
|
+
*
|
|
424
|
+
* @stability stable
|
|
425
|
+
* @category constructors
|
|
426
|
+
* @since 2.0.0
|
|
427
|
+
*/
|
|
428
|
+
const seconds = (seconds) => make(seconds * 1e3);
|
|
429
|
+
/**
|
|
430
|
+
* Converts a Duration to milliseconds.
|
|
431
|
+
*
|
|
432
|
+
* **Example** (Converting durations to milliseconds)
|
|
433
|
+
*
|
|
434
|
+
* ```ts import.meta.vitest
|
|
435
|
+
* import { Duration } from "effect"
|
|
436
|
+
*
|
|
437
|
+
* Duration.toMillis(Duration.seconds(5)) // => 5000
|
|
438
|
+
* Duration.toMillis(Duration.minutes(2)) // => 120_000
|
|
439
|
+
* ```
|
|
440
|
+
*
|
|
441
|
+
* @stability stable
|
|
442
|
+
* @category getters
|
|
443
|
+
* @since 2.0.0
|
|
444
|
+
*/
|
|
445
|
+
const toMillis = (self) => match(fromInputUnsafe(self), {
|
|
446
|
+
onMillis: identity,
|
|
447
|
+
onNanos: (nanos) => nanosToUnit(nanos, 1e6),
|
|
448
|
+
onInfinity: () => Infinity,
|
|
449
|
+
onNegativeInfinity: () => -Infinity
|
|
450
|
+
});
|
|
451
|
+
/**
|
|
452
|
+
* Converts a Duration to seconds.
|
|
453
|
+
*
|
|
454
|
+
* **Example** (Converting durations to seconds)
|
|
455
|
+
*
|
|
456
|
+
* ```ts import.meta.vitest
|
|
457
|
+
* import { Duration } from "effect"
|
|
458
|
+
*
|
|
459
|
+
* Duration.toSeconds(Duration.millis(5000)) // => 5
|
|
460
|
+
* Duration.toSeconds(Duration.minutes(2)) // => 120
|
|
461
|
+
* ```
|
|
462
|
+
*
|
|
463
|
+
* @stability stable
|
|
464
|
+
* @category getters
|
|
465
|
+
* @since 2.0.0
|
|
466
|
+
*/
|
|
467
|
+
const toSeconds = (self) => match(fromInputUnsafe(self), {
|
|
468
|
+
onMillis: (millis) => millis / 1e3,
|
|
469
|
+
onNanos: (nanos) => nanosToUnit(nanos, 1e9),
|
|
470
|
+
onInfinity: () => Infinity,
|
|
471
|
+
onNegativeInfinity: () => -Infinity
|
|
472
|
+
});
|
|
473
|
+
/**
|
|
474
|
+
* Gets the duration in nanoseconds as a bigint.
|
|
475
|
+
*
|
|
476
|
+
* **When to use**
|
|
477
|
+
*
|
|
478
|
+
* Use when the duration is known to be finite and you need the nanosecond value
|
|
479
|
+
* as a `bigint`.
|
|
480
|
+
*
|
|
481
|
+
* **Details**
|
|
482
|
+
*
|
|
483
|
+
* Millisecond-backed fractional durations are rounded to the nearest
|
|
484
|
+
* nanosecond, with ties away from zero.
|
|
485
|
+
*
|
|
486
|
+
* **Gotchas**
|
|
487
|
+
*
|
|
488
|
+
* If the duration is infinite, it throws an error.
|
|
489
|
+
*
|
|
490
|
+
* **Example** (Reading nanoseconds unsafely)
|
|
491
|
+
*
|
|
492
|
+
* ```ts import.meta.vitest
|
|
493
|
+
* import { Duration } from "effect"
|
|
494
|
+
*
|
|
495
|
+
* Duration.toNanosUnsafe(Duration.seconds(2)) // => 2_000_000_000n
|
|
496
|
+
*
|
|
497
|
+
* // Duration.toNanosUnsafe(Duration.infinity)
|
|
498
|
+
* // throws Error: "Cannot convert infinite duration to nanos"
|
|
499
|
+
* ```
|
|
500
|
+
*
|
|
501
|
+
* @stability stable
|
|
502
|
+
* @category getters
|
|
503
|
+
* @since 4.0.0
|
|
504
|
+
*/
|
|
505
|
+
const toNanosUnsafe = (input) => {
|
|
506
|
+
const self = fromInputUnsafe(input);
|
|
507
|
+
switch (self.value._tag) {
|
|
508
|
+
case "Infinity":
|
|
509
|
+
case "NegativeInfinity": throw new Error("Cannot convert infinite duration to nanos");
|
|
510
|
+
case "Nanos": return self.value.nanos;
|
|
511
|
+
case "Millis": return roundMillisToNanos(self.value.millis);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
/**
|
|
515
|
+
* Pattern matches on the representation of a `Duration`.
|
|
516
|
+
*
|
|
517
|
+
* **Details**
|
|
518
|
+
*
|
|
519
|
+
* Provide handlers for millisecond-backed values, nanosecond-backed values,
|
|
520
|
+
* and positive infinity. Use `onNegativeInfinity` to handle negative infinity
|
|
521
|
+
* separately; otherwise negative infinity is handled by `onInfinity`.
|
|
522
|
+
*
|
|
523
|
+
* **Example** (Pattern matching on duration representations)
|
|
524
|
+
*
|
|
525
|
+
* ```ts import.meta.vitest
|
|
526
|
+
* import { Duration } from "effect"
|
|
527
|
+
*
|
|
528
|
+
* Duration.match(Duration.seconds(5), {
|
|
529
|
+
* onMillis: (millis) => `${millis} milliseconds`,
|
|
530
|
+
* onNanos: (nanos) => `${nanos} nanoseconds`,
|
|
531
|
+
* onInfinity: () => "infinite"
|
|
532
|
+
* }) // => "5000 milliseconds"
|
|
533
|
+
* ```
|
|
534
|
+
*
|
|
535
|
+
* @stability stable
|
|
536
|
+
* @category pattern matching
|
|
537
|
+
* @since 2.0.0
|
|
538
|
+
*/
|
|
539
|
+
const match = /*#__PURE__*/ dual(2, (self, options) => {
|
|
540
|
+
switch (self.value._tag) {
|
|
541
|
+
case "Millis": return options.onMillis(self.value.millis);
|
|
542
|
+
case "Nanos": return options.onNanos(self.value.nanos);
|
|
543
|
+
case "Infinity": return options.onInfinity();
|
|
544
|
+
case "NegativeInfinity": return (options.onNegativeInfinity ?? options.onInfinity)();
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
/**
|
|
548
|
+
* Pattern matches on two `Duration`s, providing handlers that receive both values.
|
|
549
|
+
*
|
|
550
|
+
* **Example** (Pattern matching on duration pairs)
|
|
551
|
+
*
|
|
552
|
+
* ```ts import.meta.vitest
|
|
553
|
+
* import { Duration } from "effect"
|
|
554
|
+
*
|
|
555
|
+
* Duration.matchPair(Duration.seconds(3), Duration.seconds(2), {
|
|
556
|
+
* onMillis: (a, b) => a + b,
|
|
557
|
+
* onNanos: (a, b) => Number(a + b),
|
|
558
|
+
* onInfinity: () => Infinity
|
|
559
|
+
* }) // => 5000
|
|
560
|
+
* ```
|
|
561
|
+
*
|
|
562
|
+
* @stability stable
|
|
563
|
+
* @category pattern matching
|
|
564
|
+
* @since 4.0.0
|
|
565
|
+
*/
|
|
566
|
+
const matchPair = /*#__PURE__*/ dual(3, (self, that, options) => {
|
|
567
|
+
if (self.value._tag === "Infinity" || self.value._tag === "NegativeInfinity" || that.value._tag === "Infinity" || that.value._tag === "NegativeInfinity") return options.onInfinity(self, that);
|
|
568
|
+
if (self.value._tag === "Millis") return that.value._tag === "Millis" ? options.onMillis(self.value.millis, that.value.millis) : options.onNanos(toNanosUnsafe(self), that.value.nanos);
|
|
569
|
+
else return options.onNanos(self.value.nanos, toNanosUnsafe(that));
|
|
570
|
+
});
|
|
571
|
+
/**
|
|
572
|
+
* Provides an `Order` instance for comparing `Duration` values.
|
|
573
|
+
*
|
|
574
|
+
* **Details**
|
|
575
|
+
*
|
|
576
|
+
* `NegativeInfinity` < any finite value < `Infinity`.
|
|
577
|
+
*
|
|
578
|
+
* **Example** (Sorting durations)
|
|
579
|
+
*
|
|
580
|
+
* ```ts import.meta.vitest
|
|
581
|
+
* import { Duration } from "effect"
|
|
582
|
+
*
|
|
583
|
+
* const durations = [
|
|
584
|
+
* Duration.seconds(3),
|
|
585
|
+
* Duration.seconds(1),
|
|
586
|
+
* Duration.seconds(2)
|
|
587
|
+
* ]
|
|
588
|
+
* durations.sort((a, b) => Duration.Order(a, b)).map(Duration.toSeconds) // => [1, 2, 3]
|
|
589
|
+
* ```
|
|
590
|
+
*
|
|
591
|
+
* @stability stable
|
|
592
|
+
* @category instances
|
|
593
|
+
* @since 2.0.0
|
|
594
|
+
*/
|
|
595
|
+
const Order = /*#__PURE__*/ make$1((self, that) => matchPair(self, that, {
|
|
596
|
+
onMillis: (self, that) => self < that ? -1 : self > that ? 1 : 0,
|
|
597
|
+
onNanos: (self, that) => self < that ? -1 : self > that ? 1 : 0,
|
|
598
|
+
onInfinity: (self, that) => {
|
|
599
|
+
if (self.value._tag === that.value._tag) return 0;
|
|
600
|
+
if (self.value._tag === "Infinity") return 1;
|
|
601
|
+
if (self.value._tag === "NegativeInfinity") return -1;
|
|
602
|
+
if (that.value._tag === "Infinity") return -1;
|
|
603
|
+
return 1;
|
|
604
|
+
}
|
|
605
|
+
}));
|
|
606
|
+
/**
|
|
607
|
+
* Provides an `Equivalence` instance for comparing `Duration` values.
|
|
608
|
+
*
|
|
609
|
+
* **Example** (Comparing durations for equivalence)
|
|
610
|
+
*
|
|
611
|
+
* ```ts import.meta.vitest
|
|
612
|
+
* import { Duration } from "effect"
|
|
613
|
+
*
|
|
614
|
+
* Duration.Equivalence(Duration.seconds(5), Duration.millis(5000)) // => true
|
|
615
|
+
* ```
|
|
616
|
+
*
|
|
617
|
+
* @stability stable
|
|
618
|
+
* @category instances
|
|
619
|
+
* @since 2.0.0
|
|
620
|
+
*/
|
|
621
|
+
const Equivalence = (self, that) => matchPair(self, that, {
|
|
622
|
+
onMillis: (self, that) => self === that,
|
|
623
|
+
onNanos: (self, that) => self === that,
|
|
624
|
+
onInfinity: (self, that) => self.value._tag === that.value._tag
|
|
625
|
+
});
|
|
626
|
+
/**
|
|
627
|
+
* Returns the smaller of two Durations.
|
|
628
|
+
*
|
|
629
|
+
* **Example** (Selecting the shorter duration)
|
|
630
|
+
*
|
|
631
|
+
* ```ts import.meta.vitest
|
|
632
|
+
* import { Duration } from "effect"
|
|
633
|
+
*
|
|
634
|
+
* Duration.min(Duration.seconds(5), Duration.seconds(3)) // => Duration.seconds(3)
|
|
635
|
+
* ```
|
|
636
|
+
*
|
|
637
|
+
* @stability stable
|
|
638
|
+
* @category ordering
|
|
639
|
+
* @since 2.0.0
|
|
640
|
+
*/
|
|
641
|
+
const min = /*#__PURE__*/ min$1(Order);
|
|
642
|
+
/**
|
|
643
|
+
* Returns the larger of two Durations.
|
|
644
|
+
*
|
|
645
|
+
* **Example** (Selecting the longer duration)
|
|
646
|
+
*
|
|
647
|
+
* ```ts import.meta.vitest
|
|
648
|
+
* import { Duration } from "effect"
|
|
649
|
+
*
|
|
650
|
+
* Duration.max(Duration.seconds(5), Duration.seconds(3)) // => Duration.seconds(5)
|
|
651
|
+
* ```
|
|
652
|
+
*
|
|
653
|
+
* @stability stable
|
|
654
|
+
* @category ordering
|
|
655
|
+
* @since 2.0.0
|
|
656
|
+
*/
|
|
657
|
+
const max = /*#__PURE__*/ max$1(Order);
|
|
658
|
+
/**
|
|
659
|
+
* Checks whether the first Duration is less than or equal to the second.
|
|
660
|
+
*
|
|
661
|
+
* **Example** (Comparing durations with less than or equal)
|
|
662
|
+
*
|
|
663
|
+
* ```ts import.meta.vitest
|
|
664
|
+
* import { Duration } from "effect"
|
|
665
|
+
*
|
|
666
|
+
* Duration.isLessThanOrEqualTo(
|
|
667
|
+
* Duration.seconds(5),
|
|
668
|
+
* Duration.seconds(5)
|
|
669
|
+
* ) // => true
|
|
670
|
+
* ```
|
|
671
|
+
*
|
|
672
|
+
* @stability stable
|
|
673
|
+
* @category predicates
|
|
674
|
+
* @since 4.0.0
|
|
675
|
+
*/
|
|
676
|
+
const isLessThanOrEqualTo = /*#__PURE__*/ isLessThanOrEqualTo$1(Order);
|
|
677
|
+
/**
|
|
678
|
+
* Checks whether two Durations are equal.
|
|
679
|
+
*
|
|
680
|
+
* **Example** (Checking duration equality)
|
|
681
|
+
*
|
|
682
|
+
* ```ts import.meta.vitest
|
|
683
|
+
* import { Duration } from "effect"
|
|
684
|
+
*
|
|
685
|
+
* Duration.equals(Duration.seconds(5), Duration.millis(5000)) // => true
|
|
686
|
+
* ```
|
|
687
|
+
*
|
|
688
|
+
* @stability stable
|
|
689
|
+
* @category predicates
|
|
690
|
+
* @since 2.0.0
|
|
691
|
+
*/
|
|
692
|
+
const equals = /*#__PURE__*/ dual(2, (self, that) => Equivalence(self, that));
|
|
693
|
+
/**
|
|
694
|
+
* Decomposes a `Duration` into normalized signed components.
|
|
695
|
+
*
|
|
696
|
+
* **Details**
|
|
697
|
+
*
|
|
698
|
+
* Finite durations are returned as `{ days, hours, minutes, seconds, millis,
|
|
699
|
+
* nanos }`. Infinite durations return every component as `Infinity` or
|
|
700
|
+
* `-Infinity`.
|
|
701
|
+
*
|
|
702
|
+
* **Example** (Decomposing durations into parts)
|
|
703
|
+
*
|
|
704
|
+
* ```ts import.meta.vitest
|
|
705
|
+
* import { Duration } from "effect"
|
|
706
|
+
*
|
|
707
|
+
* // Create a complex duration by adding multiple parts
|
|
708
|
+
* const duration = Duration.sum(
|
|
709
|
+
* Duration.sum(
|
|
710
|
+
* Duration.sum(Duration.days(1), Duration.hours(2)),
|
|
711
|
+
* Duration.sum(Duration.minutes(30), Duration.seconds(45))
|
|
712
|
+
* ),
|
|
713
|
+
* Duration.millis(123)
|
|
714
|
+
* )
|
|
715
|
+
* Duration.parts(duration) // => ({ days: 1, hours: 2, minutes: 30, seconds: 45, millis: 123, nanos: 0 })
|
|
716
|
+
*
|
|
717
|
+
* const complex = Duration.sum(Duration.hours(25), Duration.minutes(90))
|
|
718
|
+
* Duration.parts(complex) // => ({ days: 1, hours: 2, minutes: 30, seconds: 0, millis: 0, nanos: 0 })
|
|
719
|
+
* ```
|
|
720
|
+
*
|
|
721
|
+
* @stability stable
|
|
722
|
+
* @category converting
|
|
723
|
+
* @since 3.8.0
|
|
724
|
+
*/
|
|
725
|
+
const parts = (self) => {
|
|
726
|
+
if (self.value._tag === "Infinity") return {
|
|
727
|
+
days: Infinity,
|
|
728
|
+
hours: Infinity,
|
|
729
|
+
minutes: Infinity,
|
|
730
|
+
seconds: Infinity,
|
|
731
|
+
millis: Infinity,
|
|
732
|
+
nanos: Infinity
|
|
733
|
+
};
|
|
734
|
+
if (self.value._tag === "NegativeInfinity") return {
|
|
735
|
+
days: -Infinity,
|
|
736
|
+
hours: -Infinity,
|
|
737
|
+
minutes: -Infinity,
|
|
738
|
+
seconds: -Infinity,
|
|
739
|
+
millis: -Infinity,
|
|
740
|
+
nanos: -Infinity
|
|
741
|
+
};
|
|
742
|
+
const n = toNanosUnsafe(self);
|
|
743
|
+
const neg = n < bigint0;
|
|
744
|
+
const a = neg ? -n : n;
|
|
745
|
+
const ms = a / bigint1e6;
|
|
746
|
+
const sec = ms / bigint1e3;
|
|
747
|
+
const min = sec / bigint60;
|
|
748
|
+
const hr = min / bigint60;
|
|
749
|
+
const d = hr / bigint24;
|
|
750
|
+
const sign = neg ? -1 : 1;
|
|
751
|
+
return {
|
|
752
|
+
days: sign * Number(d),
|
|
753
|
+
hours: sign * Number(hr % bigint24),
|
|
754
|
+
minutes: sign * Number(min % bigint60),
|
|
755
|
+
seconds: sign * Number(sec % bigint60),
|
|
756
|
+
millis: sign * Number(ms % bigint1e3),
|
|
757
|
+
nanos: sign * Number(a % bigint1e6)
|
|
758
|
+
};
|
|
759
|
+
};
|
|
760
|
+
/**
|
|
761
|
+
* Converts a `Duration` to a human readable string.
|
|
762
|
+
*
|
|
763
|
+
* **Example** (Formatting durations)
|
|
764
|
+
*
|
|
765
|
+
* ```ts import.meta.vitest
|
|
766
|
+
* import { Duration } from "effect"
|
|
767
|
+
*
|
|
768
|
+
* Duration.format(Duration.millis(1000)) // => "1s"
|
|
769
|
+
* Duration.format(Duration.millis(1001)) // => "1s 1ms"
|
|
770
|
+
* ```
|
|
771
|
+
*
|
|
772
|
+
* @stability stable
|
|
773
|
+
* @category converting
|
|
774
|
+
* @since 2.0.0
|
|
775
|
+
*/
|
|
776
|
+
const format = (self) => {
|
|
777
|
+
if (self.value._tag === "Infinity") return "Infinity";
|
|
778
|
+
if (self.value._tag === "NegativeInfinity") return "-Infinity";
|
|
779
|
+
if (isZero(self)) return "0";
|
|
780
|
+
if (isNegative(self)) return "-" + format(abs(self));
|
|
781
|
+
const fragments = parts(self);
|
|
782
|
+
const pieces = [];
|
|
783
|
+
if (fragments.days !== 0) pieces.push(`${fragments.days}d`);
|
|
784
|
+
if (fragments.hours !== 0) pieces.push(`${fragments.hours}h`);
|
|
785
|
+
if (fragments.minutes !== 0) pieces.push(`${fragments.minutes}m`);
|
|
786
|
+
if (fragments.seconds !== 0) pieces.push(`${fragments.seconds}s`);
|
|
787
|
+
if (fragments.millis !== 0) pieces.push(`${fragments.millis}ms`);
|
|
788
|
+
if (fragments.nanos !== 0) pieces.push(`${fragments.nanos}ns`);
|
|
789
|
+
return pieces.join(" ");
|
|
790
|
+
};
|
|
791
|
+
export { isFinite as a, max as c, nanos as d, negativeInfinity as f, zero as g, toSeconds as h, isDuration as i, millis as l, toMillis as m, fromInputUnsafe as n, isLessThanOrEqualTo as o, seconds as p, infinity as r, isZero as s, format as t, min as u };
|