effect 3.0.0 → 3.0.2
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/dist/cjs/Array.js.map +1 -1
- package/dist/cjs/Brand.js +2 -2
- package/dist/cjs/Brand.js.map +1 -1
- package/dist/cjs/Cron.js +13 -13
- package/dist/cjs/Cron.js.map +1 -1
- package/dist/cjs/FiberHandle.js +19 -1
- package/dist/cjs/FiberHandle.js.map +1 -1
- package/dist/cjs/FiberMap.js +19 -1
- package/dist/cjs/FiberMap.js.map +1 -1
- package/dist/cjs/List.js +3 -3
- package/dist/cjs/List.js.map +1 -1
- package/dist/cjs/internal/cause.js +2 -2
- package/dist/cjs/internal/cause.js.map +1 -1
- package/dist/cjs/internal/configProvider.js +44 -44
- package/dist/cjs/internal/configProvider.js.map +1 -1
- package/dist/cjs/internal/core-effect.js +9 -9
- package/dist/cjs/internal/core-effect.js.map +1 -1
- package/dist/cjs/internal/core.js +9 -9
- package/dist/cjs/internal/core.js.map +1 -1
- package/dist/cjs/internal/differ/readonlyArrayPatch.js +6 -6
- package/dist/cjs/internal/differ/readonlyArrayPatch.js.map +1 -1
- package/dist/cjs/internal/metric/boundaries.js +4 -4
- package/dist/cjs/internal/metric/boundaries.js.map +1 -1
- package/dist/cjs/internal/metric/hook.js +16 -16
- package/dist/cjs/internal/metric/hook.js.map +1 -1
- package/dist/cjs/internal/metric/key.js +3 -3
- package/dist/cjs/internal/metric/key.js.map +1 -1
- package/dist/cjs/internal/metric/state.js +4 -4
- package/dist/cjs/internal/metric/state.js.map +1 -1
- package/dist/cjs/internal/metric.js +3 -3
- package/dist/cjs/internal/metric.js.map +1 -1
- package/dist/cjs/internal/queue.js +5 -5
- package/dist/cjs/internal/queue.js.map +1 -1
- package/dist/cjs/internal/redBlackTree/iterator.js +2 -2
- package/dist/cjs/internal/redBlackTree/iterator.js.map +1 -1
- package/dist/cjs/internal/secret.js +2 -2
- package/dist/cjs/internal/secret.js.map +1 -1
- package/dist/cjs/internal/sink.js +2 -2
- package/dist/cjs/internal/sink.js.map +1 -1
- package/dist/cjs/internal/stm/tPriorityQueue.js +11 -11
- package/dist/cjs/internal/stm/tPriorityQueue.js.map +1 -1
- package/dist/cjs/internal/version.js +1 -1
- package/dist/dts/Array.d.ts +4 -1
- package/dist/dts/Array.d.ts.map +1 -1
- package/dist/dts/Brand.d.ts.map +1 -1
- package/dist/dts/FiberHandle.d.ts.map +1 -1
- package/dist/dts/FiberMap.d.ts.map +1 -1
- package/dist/dts/List.d.ts.map +1 -1
- package/dist/esm/Array.js.map +1 -1
- package/dist/esm/Brand.js +2 -2
- package/dist/esm/Brand.js.map +1 -1
- package/dist/esm/Cron.js +13 -13
- package/dist/esm/Cron.js.map +1 -1
- package/dist/esm/FiberHandle.js +18 -0
- package/dist/esm/FiberHandle.js.map +1 -1
- package/dist/esm/FiberMap.js +18 -0
- package/dist/esm/FiberMap.js.map +1 -1
- package/dist/esm/List.js +3 -3
- package/dist/esm/List.js.map +1 -1
- package/dist/esm/internal/cause.js +2 -2
- package/dist/esm/internal/cause.js.map +1 -1
- package/dist/esm/internal/configProvider.js +44 -44
- package/dist/esm/internal/configProvider.js.map +1 -1
- package/dist/esm/internal/core-effect.js +9 -9
- package/dist/esm/internal/core-effect.js.map +1 -1
- package/dist/esm/internal/core.js +9 -9
- package/dist/esm/internal/core.js.map +1 -1
- package/dist/esm/internal/differ/readonlyArrayPatch.js +6 -6
- package/dist/esm/internal/differ/readonlyArrayPatch.js.map +1 -1
- package/dist/esm/internal/metric/boundaries.js +4 -4
- package/dist/esm/internal/metric/boundaries.js.map +1 -1
- package/dist/esm/internal/metric/hook.js +16 -16
- package/dist/esm/internal/metric/hook.js.map +1 -1
- package/dist/esm/internal/metric/key.js +3 -3
- package/dist/esm/internal/metric/key.js.map +1 -1
- package/dist/esm/internal/metric/state.js +4 -4
- package/dist/esm/internal/metric/state.js.map +1 -1
- package/dist/esm/internal/metric.js +3 -3
- package/dist/esm/internal/metric.js.map +1 -1
- package/dist/esm/internal/queue.js +5 -5
- package/dist/esm/internal/queue.js.map +1 -1
- package/dist/esm/internal/redBlackTree/iterator.js +2 -2
- package/dist/esm/internal/redBlackTree/iterator.js.map +1 -1
- package/dist/esm/internal/secret.js +2 -2
- package/dist/esm/internal/secret.js.map +1 -1
- package/dist/esm/internal/sink.js +2 -2
- package/dist/esm/internal/sink.js.map +1 -1
- package/dist/esm/internal/stm/tPriorityQueue.js +11 -11
- package/dist/esm/internal/stm/tPriorityQueue.js.map +1 -1
- package/dist/esm/internal/version.js +1 -1
- package/package.json +5 -2
- package/src/Array.ts +4 -1
- package/src/Brand.ts +2 -2
- package/src/Cron.ts +17 -17
- package/src/FiberHandle.ts +19 -0
- package/src/FiberMap.ts +19 -0
- package/src/List.ts +3 -3
- package/src/internal/cause.ts +2 -2
- package/src/internal/configProvider.ts +46 -46
- package/src/internal/core-effect.ts +9 -9
- package/src/internal/core.ts +10 -10
- package/src/internal/differ/readonlyArrayPatch.ts +6 -6
- package/src/internal/metric/boundaries.ts +5 -5
- package/src/internal/metric/hook.ts +17 -17
- package/src/internal/metric/key.ts +3 -3
- package/src/internal/metric/state.ts +5 -5
- package/src/internal/metric.ts +4 -4
- package/src/internal/queue.ts +6 -6
- package/src/internal/redBlackTree/iterator.ts +2 -2
- package/src/internal/secret.ts +2 -2
- package/src/internal/sink.ts +2 -2
- package/src/internal/stm/tPriorityQueue.ts +11 -11
- package/src/internal/version.ts +1 -1
package/src/internal/cause.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as Arr from "../Array.js"
|
|
2
2
|
import type * as Cause from "../Cause.js"
|
|
3
3
|
import * as Chunk from "../Chunk.js"
|
|
4
4
|
import * as Either from "../Either.js"
|
|
@@ -584,7 +584,7 @@ const flattenCauseLoop = (
|
|
|
584
584
|
while (1) {
|
|
585
585
|
const [parallel, sequential] = pipe(
|
|
586
586
|
causes,
|
|
587
|
-
|
|
587
|
+
Arr.reduce(
|
|
588
588
|
[HashSet.empty<unknown>(), Chunk.empty<Cause.Cause<unknown>>()] as const,
|
|
589
589
|
([parallel, sequential], cause) => {
|
|
590
590
|
const [par, seq] = evaluateCause(cause)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as Arr from "../Array.js"
|
|
2
2
|
import type * as Config from "../Config.js"
|
|
3
3
|
import type * as ConfigError from "../ConfigError.js"
|
|
4
4
|
import type * as ConfigProvider from "../ConfigProvider.js"
|
|
@@ -85,12 +85,12 @@ export const makeFlat = (
|
|
|
85
85
|
export const fromFlat = (flat: ConfigProvider.ConfigProvider.Flat): ConfigProvider.ConfigProvider =>
|
|
86
86
|
make({
|
|
87
87
|
load: (config) =>
|
|
88
|
-
core.flatMap(fromFlatLoop(flat,
|
|
89
|
-
Option.match(
|
|
88
|
+
core.flatMap(fromFlatLoop(flat, Arr.empty(), config, false), (chunk) =>
|
|
89
|
+
Option.match(Arr.head(chunk), {
|
|
90
90
|
onNone: () =>
|
|
91
91
|
core.fail(
|
|
92
92
|
configError.MissingData(
|
|
93
|
-
|
|
93
|
+
Arr.empty(),
|
|
94
94
|
`Expected a single value having structure: ${config}`
|
|
95
95
|
)
|
|
96
96
|
),
|
|
@@ -104,7 +104,7 @@ export const fromEnv = (
|
|
|
104
104
|
config?: Partial<ConfigProvider.ConfigProvider.FromEnvConfig>
|
|
105
105
|
): ConfigProvider.ConfigProvider => {
|
|
106
106
|
const { pathDelim, seqDelim } = Object.assign({}, { pathDelim: "_", seqDelim: "," }, config)
|
|
107
|
-
const makePathString = (path: ReadonlyArray<string>): string => pipe(path,
|
|
107
|
+
const makePathString = (path: ReadonlyArray<string>): string => pipe(path, Arr.join(pathDelim))
|
|
108
108
|
const unmakePathString = (pathString: string): ReadonlyArray<string> => pathString.split(pathDelim)
|
|
109
109
|
|
|
110
110
|
const getEnv = () =>
|
|
@@ -134,7 +134,7 @@ export const fromEnv = (
|
|
|
134
134
|
const keyPaths = keys.map((value) => unmakePathString(value.toUpperCase()))
|
|
135
135
|
const filteredKeyPaths = keyPaths.filter((keyPath) => {
|
|
136
136
|
for (let i = 0; i < path.length; i++) {
|
|
137
|
-
const pathComponent = pipe(path,
|
|
137
|
+
const pathComponent = pipe(path, Arr.unsafeGet(i))
|
|
138
138
|
const currentElement = keyPath[i]
|
|
139
139
|
if (currentElement === undefined || pathComponent !== currentElement) {
|
|
140
140
|
return false
|
|
@@ -154,7 +154,7 @@ export const fromMap = (
|
|
|
154
154
|
config?: Partial<ConfigProvider.ConfigProvider.FromMapConfig>
|
|
155
155
|
): ConfigProvider.ConfigProvider => {
|
|
156
156
|
const { pathDelim, seqDelim } = Object.assign({ seqDelim: ",", pathDelim: "." }, config)
|
|
157
|
-
const makePathString = (path: ReadonlyArray<string>): string => pipe(path,
|
|
157
|
+
const makePathString = (path: ReadonlyArray<string>): string => pipe(path, Arr.join(pathDelim))
|
|
158
158
|
const unmakePathString = (pathString: string): ReadonlyArray<string> => pathString.split(pathDelim)
|
|
159
159
|
const mapWithIndexSplit = splitIndexInKeys(
|
|
160
160
|
map,
|
|
@@ -180,10 +180,10 @@ export const fromMap = (
|
|
|
180
180
|
path: ReadonlyArray<string>
|
|
181
181
|
): Effect.Effect<HashSet.HashSet<string>, ConfigError.ConfigError> =>
|
|
182
182
|
core.sync(() => {
|
|
183
|
-
const keyPaths =
|
|
183
|
+
const keyPaths = Arr.fromIterable(mapWithIndexSplit.keys()).map(unmakePathString)
|
|
184
184
|
const filteredKeyPaths = keyPaths.filter((keyPath) => {
|
|
185
185
|
for (let i = 0; i < path.length; i++) {
|
|
186
|
-
const pathComponent = pipe(path,
|
|
186
|
+
const pathComponent = pipe(path, Arr.unsafeGet(i))
|
|
187
187
|
const currentElement = keyPath[i]
|
|
188
188
|
if (currentElement === undefined || pathComponent !== currentElement) {
|
|
189
189
|
return false
|
|
@@ -203,14 +203,14 @@ const extend = <A, B>(
|
|
|
203
203
|
left: ReadonlyArray<A>,
|
|
204
204
|
right: ReadonlyArray<B>
|
|
205
205
|
): [ReadonlyArray<A>, ReadonlyArray<B>] => {
|
|
206
|
-
const leftPad =
|
|
206
|
+
const leftPad = Arr.unfold(
|
|
207
207
|
left.length,
|
|
208
208
|
(index) =>
|
|
209
209
|
index >= right.length ?
|
|
210
210
|
Option.none() :
|
|
211
211
|
Option.some([leftDef(index), index + 1])
|
|
212
212
|
)
|
|
213
|
-
const rightPad =
|
|
213
|
+
const rightPad = Arr.unfold(
|
|
214
214
|
right.length,
|
|
215
215
|
(index) =>
|
|
216
216
|
index >= left.length ?
|
|
@@ -244,7 +244,7 @@ const fromFlatLoop = <A>(
|
|
|
244
244
|
const op = config as _config.ConfigPrimitive
|
|
245
245
|
switch (op._tag) {
|
|
246
246
|
case OpCodes.OP_CONSTANT: {
|
|
247
|
-
return core.succeed(
|
|
247
|
+
return core.succeed(Arr.of(op.value)) as Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
|
|
248
248
|
}
|
|
249
249
|
case OpCodes.OP_DESCRIBED: {
|
|
250
250
|
return core.suspend(
|
|
@@ -296,7 +296,7 @@ const fromFlatLoop = <A>(
|
|
|
296
296
|
return core.suspend(() =>
|
|
297
297
|
fromFlatLoop(
|
|
298
298
|
flat,
|
|
299
|
-
concat(prefix,
|
|
299
|
+
concat(prefix, Arr.of(op.name)),
|
|
300
300
|
op.config,
|
|
301
301
|
split
|
|
302
302
|
)
|
|
@@ -310,7 +310,7 @@ const fromFlatLoop = <A>(
|
|
|
310
310
|
flat.load(prefix, op, split),
|
|
311
311
|
core.flatMap((values) => {
|
|
312
312
|
if (values.length === 0) {
|
|
313
|
-
const name = pipe(
|
|
313
|
+
const name = pipe(Arr.last(prefix), Option.getOrElse(() => "<n/a>"))
|
|
314
314
|
return core.fail(configError.MissingData([], `Expected ${op.description} with name ${name}`))
|
|
315
315
|
}
|
|
316
316
|
return core.succeed(values)
|
|
@@ -329,20 +329,20 @@ const fromFlatLoop = <A>(
|
|
|
329
329
|
core.flatMap((indices) => {
|
|
330
330
|
if (indices.length === 0) {
|
|
331
331
|
return core.suspend(() =>
|
|
332
|
-
core.map(fromFlatLoop(flat, patchedPrefix, op.config, true),
|
|
332
|
+
core.map(fromFlatLoop(flat, patchedPrefix, op.config, true), Arr.of)
|
|
333
333
|
) as unknown as Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
|
|
334
334
|
}
|
|
335
335
|
return pipe(
|
|
336
336
|
core.forEachSequential(
|
|
337
337
|
indices,
|
|
338
|
-
(index) => fromFlatLoop(flat,
|
|
338
|
+
(index) => fromFlatLoop(flat, Arr.append(prefix, `[${index}]`), op.config, true)
|
|
339
339
|
),
|
|
340
340
|
core.map((chunkChunk) => {
|
|
341
|
-
const flattened =
|
|
341
|
+
const flattened = Arr.flatten(chunkChunk)
|
|
342
342
|
if (flattened.length === 0) {
|
|
343
|
-
return
|
|
343
|
+
return Arr.of(Arr.empty<A>())
|
|
344
344
|
}
|
|
345
|
-
return
|
|
345
|
+
return Arr.of(flattened)
|
|
346
346
|
})
|
|
347
347
|
) as unknown as Effect.Effect<ReadonlyArray<A>, ConfigError.ConfigError>
|
|
348
348
|
})
|
|
@@ -363,18 +363,18 @@ const fromFlatLoop = <A>(
|
|
|
363
363
|
core.forEachSequential((key) =>
|
|
364
364
|
fromFlatLoop(
|
|
365
365
|
flat,
|
|
366
|
-
concat(prefix,
|
|
366
|
+
concat(prefix, Arr.of(key)),
|
|
367
367
|
op.valueConfig,
|
|
368
368
|
split
|
|
369
369
|
)
|
|
370
370
|
),
|
|
371
371
|
core.map((matrix) => {
|
|
372
372
|
if (matrix.length === 0) {
|
|
373
|
-
return
|
|
373
|
+
return Arr.of(HashMap.empty())
|
|
374
374
|
}
|
|
375
375
|
return pipe(
|
|
376
376
|
transpose(matrix),
|
|
377
|
-
|
|
377
|
+
Arr.map((values) => HashMap.fromIterable(Arr.zip(Arr.fromIterable(keys), values)))
|
|
378
378
|
)
|
|
379
379
|
})
|
|
380
380
|
)
|
|
@@ -404,17 +404,17 @@ const fromFlatLoop = <A>(
|
|
|
404
404
|
return core.fail(right.left)
|
|
405
405
|
}
|
|
406
406
|
if (Either.isRight(left) && Either.isRight(right)) {
|
|
407
|
-
const path = pipe(prefix,
|
|
407
|
+
const path = pipe(prefix, Arr.join("."))
|
|
408
408
|
const fail = fromFlatLoopFail(prefix, path)
|
|
409
409
|
const [lefts, rights] = extend(
|
|
410
410
|
fail,
|
|
411
411
|
fail,
|
|
412
|
-
pipe(left.right,
|
|
413
|
-
pipe(right.right,
|
|
412
|
+
pipe(left.right, Arr.map(Either.right)),
|
|
413
|
+
pipe(right.right, Arr.map(Either.right))
|
|
414
414
|
)
|
|
415
415
|
return pipe(
|
|
416
416
|
lefts,
|
|
417
|
-
|
|
417
|
+
Arr.zip(rights),
|
|
418
418
|
core.forEachSequential(([left, right]) =>
|
|
419
419
|
pipe(
|
|
420
420
|
core.zip(left, right),
|
|
@@ -587,8 +587,8 @@ export const within = dual<
|
|
|
587
587
|
f: (self: ConfigProvider.ConfigProvider) => ConfigProvider.ConfigProvider
|
|
588
588
|
) => ConfigProvider.ConfigProvider
|
|
589
589
|
>(3, (self, path, f) => {
|
|
590
|
-
const unnest =
|
|
591
|
-
const nest =
|
|
590
|
+
const unnest = Arr.reduce(path, self, (provider, name) => unnested(provider, name))
|
|
591
|
+
const nest = Arr.reduceRight(path, f(unnest), (provider, name) => nested(provider, name))
|
|
592
592
|
return orElse(nest, () => self)
|
|
593
593
|
})
|
|
594
594
|
|
|
@@ -609,7 +609,7 @@ const parsePrimitive = <A>(
|
|
|
609
609
|
primitive.parse(text),
|
|
610
610
|
core.mapBoth({
|
|
611
611
|
onFailure: configError.prefixed(path),
|
|
612
|
-
onSuccess:
|
|
612
|
+
onSuccess: Arr.of
|
|
613
613
|
})
|
|
614
614
|
)
|
|
615
615
|
}
|
|
@@ -628,8 +628,8 @@ const indicesFrom = (quotedIndices: HashSet.HashSet<string>): Effect.Effect<Read
|
|
|
628
628
|
pipe(
|
|
629
629
|
core.forEachSequential(quotedIndices, parseQuotedIndex),
|
|
630
630
|
core.mapBoth({
|
|
631
|
-
onFailure: () =>
|
|
632
|
-
onSuccess:
|
|
631
|
+
onFailure: () => Arr.empty<number>(),
|
|
632
|
+
onSuccess: Arr.sort(number.Order)
|
|
633
633
|
}),
|
|
634
634
|
core.either,
|
|
635
635
|
core.map(Either.merge)
|
|
@@ -661,10 +661,10 @@ const splitIndexInKeys = (
|
|
|
661
661
|
for (const [pathString, value] of map) {
|
|
662
662
|
const keyWithIndex = pipe(
|
|
663
663
|
unmakePathString(pathString),
|
|
664
|
-
|
|
664
|
+
Arr.flatMap((key) =>
|
|
665
665
|
Option.match(splitIndexFrom(key), {
|
|
666
|
-
onNone: () =>
|
|
667
|
-
onSome: ([key, index]) =>
|
|
666
|
+
onNone: () => Arr.of(key),
|
|
667
|
+
onSome: ([key, index]) => Arr.make(key, `[${index}]`)
|
|
668
668
|
})
|
|
669
669
|
)
|
|
670
670
|
)
|
|
@@ -717,7 +717,7 @@ interface JsonArray extends Array<string | number | boolean | null | JsonArray |
|
|
|
717
717
|
/** @internal */
|
|
718
718
|
export const fromJson = (json: unknown): ConfigProvider.ConfigProvider => {
|
|
719
719
|
const hiddenDelimiter = "\ufeff"
|
|
720
|
-
const indexedEntries =
|
|
720
|
+
const indexedEntries = Arr.map(
|
|
721
721
|
getIndexedEntries(json as JsonMap),
|
|
722
722
|
([key, value]): [string, string] => [configPathToString(key).join(hiddenDelimiter), value]
|
|
723
723
|
)
|
|
@@ -759,38 +759,38 @@ const getIndexedEntries = (
|
|
|
759
759
|
value: string | number | boolean | JsonMap | JsonArray | null
|
|
760
760
|
): ReadonlyArray<[path: ReadonlyArray<KeyComponent>, value: string]> => {
|
|
761
761
|
if (typeof value === "string") {
|
|
762
|
-
return
|
|
762
|
+
return Arr.make([path, value] as [ReadonlyArray<KeyComponent>, string])
|
|
763
763
|
}
|
|
764
764
|
if (typeof value === "number" || typeof value === "boolean") {
|
|
765
|
-
return
|
|
765
|
+
return Arr.make([path, String(value)] as [ReadonlyArray<KeyComponent>, string])
|
|
766
766
|
}
|
|
767
|
-
if (
|
|
767
|
+
if (Arr.isArray(value)) {
|
|
768
768
|
return loopArray(path, value)
|
|
769
769
|
}
|
|
770
770
|
if (typeof value === "object" && value !== null) {
|
|
771
771
|
return loopObject(path, value)
|
|
772
772
|
}
|
|
773
|
-
return
|
|
773
|
+
return Arr.empty<[ReadonlyArray<KeyComponent>, string]>()
|
|
774
774
|
}
|
|
775
775
|
const loopArray = (
|
|
776
776
|
path: ReadonlyArray<KeyComponent>,
|
|
777
777
|
values: JsonArray
|
|
778
778
|
): ReadonlyArray<[path: ReadonlyArray<KeyComponent>, value: string]> =>
|
|
779
|
-
|
|
780
|
-
onEmpty: () =>
|
|
781
|
-
onNonEmpty:
|
|
779
|
+
Arr.match(values, {
|
|
780
|
+
onEmpty: () => Arr.make([path, "<nil>"] as [ReadonlyArray<KeyComponent>, string]),
|
|
781
|
+
onNonEmpty: Arr.flatMap((value, index) => loopAny(Arr.append(path, keyIndex(index)), value))
|
|
782
782
|
})
|
|
783
783
|
const loopObject = (
|
|
784
784
|
path: ReadonlyArray<KeyComponent>,
|
|
785
785
|
value: JsonMap
|
|
786
786
|
): ReadonlyArray<[path: ReadonlyArray<KeyComponent>, value: string]> =>
|
|
787
787
|
Object.entries(value).flatMap(([key, value]) => {
|
|
788
|
-
const newPath =
|
|
788
|
+
const newPath = Arr.append(path, keyName(key))
|
|
789
789
|
const result = loopAny(newPath, value)
|
|
790
|
-
if (
|
|
791
|
-
return
|
|
790
|
+
if (Arr.isEmptyReadonlyArray(result)) {
|
|
791
|
+
return Arr.make([newPath, ""] as [ReadonlyArray<KeyComponent>, string])
|
|
792
792
|
}
|
|
793
793
|
return result
|
|
794
794
|
})
|
|
795
|
-
return loopObject(
|
|
795
|
+
return loopObject(Arr.empty(), config)
|
|
796
796
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as Arr from "../Array.js"
|
|
2
2
|
import type * as Cause from "../Cause.js"
|
|
3
3
|
import * as Chunk from "../Chunk.js"
|
|
4
4
|
import * as Clock from "../Clock.js"
|
|
@@ -512,7 +512,7 @@ export const filterMap = dual<
|
|
|
512
512
|
>(2, (elements, pf) =>
|
|
513
513
|
core.map(
|
|
514
514
|
core.forEachSequential(elements, identity),
|
|
515
|
-
|
|
515
|
+
Arr.filterMap(pf)
|
|
516
516
|
))
|
|
517
517
|
|
|
518
518
|
/* @internal */
|
|
@@ -695,7 +695,7 @@ export const firstSuccessOf = <Eff extends Effect.Effect<any, any, any>>(
|
|
|
695
695
|
}
|
|
696
696
|
return pipe(
|
|
697
697
|
Chunk.tailNonEmpty(list),
|
|
698
|
-
|
|
698
|
+
Arr.reduce(Chunk.headNonEmpty(list), (left, right) => core.orElse(left, () => right) as Eff)
|
|
699
699
|
)
|
|
700
700
|
})
|
|
701
701
|
|
|
@@ -1020,7 +1020,7 @@ export const loop: {
|
|
|
1020
1020
|
): any =>
|
|
1021
1021
|
options.discard
|
|
1022
1022
|
? loopDiscard(initial, options.while, options.step, options.body)
|
|
1023
|
-
: core.map(loopInternal(initial, options.while, options.step, options.body),
|
|
1023
|
+
: core.map(loopInternal(initial, options.while, options.step, options.body), Arr.fromIterable)
|
|
1024
1024
|
|
|
1025
1025
|
const loopInternal = <Z, A, E, R>(
|
|
1026
1026
|
initial: Z,
|
|
@@ -1184,7 +1184,7 @@ export const orElseSucceed = dual<
|
|
|
1184
1184
|
export const parallelErrors = <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, Array<E>, R> =>
|
|
1185
1185
|
core.matchCauseEffect(self, {
|
|
1186
1186
|
onFailure: (cause) => {
|
|
1187
|
-
const errors =
|
|
1187
|
+
const errors = Arr.fromIterable(internalCause.failures(cause))
|
|
1188
1188
|
return errors.length === 0
|
|
1189
1189
|
? core.failCause(cause as Cause.Cause<never>)
|
|
1190
1190
|
: core.fail(errors)
|
|
@@ -1278,7 +1278,7 @@ export const reduce = dual<
|
|
|
1278
1278
|
zero: Z,
|
|
1279
1279
|
f: (z: Z, a: A, i: number) => Effect.Effect<Z, E, R>
|
|
1280
1280
|
) =>
|
|
1281
|
-
|
|
1281
|
+
Arr.fromIterable(elements).reduce(
|
|
1282
1282
|
(acc, el, i) => core.flatMap(acc, (a) => f(a, el, i)),
|
|
1283
1283
|
core.succeed(zero) as Effect.Effect<Z, E, R>
|
|
1284
1284
|
)
|
|
@@ -1298,7 +1298,7 @@ export const reduceRight = dual<
|
|
|
1298
1298
|
>(
|
|
1299
1299
|
3,
|
|
1300
1300
|
<A, Z, R, E>(elements: Iterable<A>, zero: Z, f: (a: A, z: Z, i: number) => Effect.Effect<Z, E, R>) =>
|
|
1301
|
-
|
|
1301
|
+
Arr.fromIterable(elements).reduceRight(
|
|
1302
1302
|
(acc, el, i) => core.flatMap(acc, (a) => f(el, a, i)),
|
|
1303
1303
|
core.succeed(zero) as Effect.Effect<Z, E, R>
|
|
1304
1304
|
)
|
|
@@ -1435,7 +1435,7 @@ export const labelMetrics = dual<
|
|
|
1435
1435
|
<A, E, R>(self: Effect.Effect<A, E, R>, labels: Iterable<MetricLabel.MetricLabel>) => Effect.Effect<A, E, R>
|
|
1436
1436
|
>(
|
|
1437
1437
|
2,
|
|
1438
|
-
(self, labels) => core.fiberRefLocallyWith(self, core.currentMetricLabels, (old) =>
|
|
1438
|
+
(self, labels) => core.fiberRefLocallyWith(self, core.currentMetricLabels, (old) => Arr.union(old, labels))
|
|
1439
1439
|
)
|
|
1440
1440
|
|
|
1441
1441
|
/* @internal */
|
|
@@ -2082,7 +2082,7 @@ export const unsafeMakeSpan = <XA, XE>(
|
|
|
2082
2082
|
...(options?.links ?? [])
|
|
2083
2083
|
] :
|
|
2084
2084
|
Chunk.toReadonlyArray(linksFromEnv.value) :
|
|
2085
|
-
options?.links ??
|
|
2085
|
+
options?.links ?? Arr.empty()
|
|
2086
2086
|
|
|
2087
2087
|
const span = tracer.span(
|
|
2088
2088
|
name,
|
package/src/internal/core.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as Arr from "../Array.js"
|
|
2
2
|
import type * as Cause from "../Cause.js"
|
|
3
3
|
import * as Chunk from "../Chunk.js"
|
|
4
4
|
import * as Context from "../Context.js"
|
|
@@ -886,8 +886,8 @@ export const forEachSequential: {
|
|
|
886
886
|
2,
|
|
887
887
|
<A, B, E, R>(self: Iterable<A>, f: (a: A, i: number) => Effect.Effect<B, E, R>): Effect.Effect<Array<B>, E, R> =>
|
|
888
888
|
suspend(() => {
|
|
889
|
-
const arr =
|
|
890
|
-
const ret =
|
|
889
|
+
const arr = Arr.fromIterable(self)
|
|
890
|
+
const ret = Arr.allocate<B>(arr.length)
|
|
891
891
|
let i = 0
|
|
892
892
|
return as(
|
|
893
893
|
whileLoop({
|
|
@@ -910,7 +910,7 @@ export const forEachSequentialDiscard: {
|
|
|
910
910
|
2,
|
|
911
911
|
<A, B, E, R>(self: Iterable<A>, f: (a: A, i: number) => Effect.Effect<B, E, R>): Effect.Effect<void, E, R> =>
|
|
912
912
|
suspend(() => {
|
|
913
|
-
const arr =
|
|
913
|
+
const arr = Arr.fromIterable(self)
|
|
914
914
|
let i = 0
|
|
915
915
|
return whileLoop({
|
|
916
916
|
while: () => i < arr.length,
|
|
@@ -1156,7 +1156,7 @@ export const partitionMap = <A, A1, A2>(
|
|
|
1156
1156
|
elements: Iterable<A>,
|
|
1157
1157
|
f: (a: A) => Either.Either<A2, A1>
|
|
1158
1158
|
): [left: Array<A1>, right: Array<A2>] =>
|
|
1159
|
-
|
|
1159
|
+
Arr.fromIterable(elements).reduceRight(
|
|
1160
1160
|
([lefts, rights], current) => {
|
|
1161
1161
|
const either = f(current)
|
|
1162
1162
|
switch (either._tag) {
|
|
@@ -1168,7 +1168,7 @@ export const partitionMap = <A, A1, A2>(
|
|
|
1168
1168
|
}
|
|
1169
1169
|
}
|
|
1170
1170
|
},
|
|
1171
|
-
[
|
|
1171
|
+
[Arr.empty<A1>(), Arr.empty<A2>()]
|
|
1172
1172
|
)
|
|
1173
1173
|
|
|
1174
1174
|
/* @internal */
|
|
@@ -2000,7 +2000,7 @@ export const withUnhandledErrorLogLevel = dual<
|
|
|
2000
2000
|
/** @internal */
|
|
2001
2001
|
export const currentMetricLabels: FiberRef.FiberRef<ReadonlyArray<MetricLabel.MetricLabel>> = globalValue(
|
|
2002
2002
|
Symbol.for("effect/FiberRef/currentMetricLabels"),
|
|
2003
|
-
() => fiberRefUnsafeMakeReadonlyArray(
|
|
2003
|
+
() => fiberRefUnsafeMakeReadonlyArray(Arr.empty())
|
|
2004
2004
|
)
|
|
2005
2005
|
|
|
2006
2006
|
/* @internal */
|
|
@@ -2110,8 +2110,8 @@ export const causeSquashWith = dual<
|
|
|
2110
2110
|
Chunk.head,
|
|
2111
2111
|
Option.match({
|
|
2112
2112
|
onNone: () => {
|
|
2113
|
-
const interrupts =
|
|
2114
|
-
|
|
2113
|
+
const interrupts = Arr.fromIterable(internalCause.interruptors(self)).flatMap((fiberId) =>
|
|
2114
|
+
Arr.fromIterable(FiberId.ids(fiberId)).map((id) => `#${id}`)
|
|
2115
2115
|
)
|
|
2116
2116
|
return new InterruptedException(interrupts ? `Interrupted by fibers: ${interrupts.join(", ")}` : void 0)
|
|
2117
2117
|
},
|
|
@@ -2694,7 +2694,7 @@ const exitCollectAllInternal = <A, E>(
|
|
|
2694
2694
|
}
|
|
2695
2695
|
return pipe(
|
|
2696
2696
|
Chunk.tailNonEmpty(list),
|
|
2697
|
-
|
|
2697
|
+
Arr.reduce(
|
|
2698
2698
|
pipe(Chunk.headNonEmpty(list), exitMap<A, Chunk.Chunk<A>>(Chunk.of)),
|
|
2699
2699
|
(accumulator, current) =>
|
|
2700
2700
|
pipe(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as Arr from "../../Array.js"
|
|
2
2
|
import type * as Differ from "../../Differ.js"
|
|
3
3
|
import * as Equal from "../../Equal.js"
|
|
4
4
|
import * as Dual from "../../Function.js"
|
|
@@ -135,7 +135,7 @@ export const diff = <Value, Patch>(
|
|
|
135
135
|
patch = combine(patch, makeSlice(0, i))
|
|
136
136
|
}
|
|
137
137
|
if (i < options.newValue.length) {
|
|
138
|
-
patch = combine(patch, makeAppend(
|
|
138
|
+
patch = combine(patch, makeAppend(Arr.drop(i)(options.newValue)))
|
|
139
139
|
}
|
|
140
140
|
return patch
|
|
141
141
|
}
|
|
@@ -173,10 +173,10 @@ export const patch = Dual.dual<
|
|
|
173
173
|
return oldValue
|
|
174
174
|
}
|
|
175
175
|
let readonlyArray = oldValue.slice()
|
|
176
|
-
let patches: Array<Differ.Differ.ReadonlyArray.Patch<Value, Patch>> =
|
|
177
|
-
while (
|
|
178
|
-
const head: Instruction =
|
|
179
|
-
const tail =
|
|
176
|
+
let patches: Array<Differ.Differ.ReadonlyArray.Patch<Value, Patch>> = Arr.of(self)
|
|
177
|
+
while (Arr.isNonEmptyArray(patches)) {
|
|
178
|
+
const head: Instruction = Arr.headNonEmpty(patches) as Instruction
|
|
179
|
+
const tail = Arr.tailNonEmpty(patches)
|
|
180
180
|
switch (head._tag) {
|
|
181
181
|
case "Empty": {
|
|
182
182
|
patches = tail
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as Arr from "../../Array.js"
|
|
2
2
|
import * as Chunk from "../../Chunk.js"
|
|
3
3
|
import * as Equal from "../../Equal.js"
|
|
4
4
|
import { pipe } from "../../Function.js"
|
|
@@ -44,8 +44,8 @@ export const isMetricBoundaries = (u: unknown): u is MetricBoundaries.MetricBoun
|
|
|
44
44
|
export const fromIterable = (iterable: Iterable<number>): MetricBoundaries.MetricBoundaries => {
|
|
45
45
|
const values = pipe(
|
|
46
46
|
iterable,
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
Arr.appendAll(Chunk.of(Number.POSITIVE_INFINITY)),
|
|
48
|
+
Arr.dedupe
|
|
49
49
|
)
|
|
50
50
|
return new MetricBoundariesImpl(values)
|
|
51
51
|
}
|
|
@@ -57,7 +57,7 @@ export const linear = (options: {
|
|
|
57
57
|
readonly count: number
|
|
58
58
|
}): MetricBoundaries.MetricBoundaries =>
|
|
59
59
|
pipe(
|
|
60
|
-
|
|
60
|
+
Arr.makeBy(options.count - 1, (i) => options.start + i * options.width),
|
|
61
61
|
Chunk.unsafeFromArray,
|
|
62
62
|
fromIterable
|
|
63
63
|
)
|
|
@@ -69,7 +69,7 @@ export const exponential = (options: {
|
|
|
69
69
|
readonly count: number
|
|
70
70
|
}): MetricBoundaries.MetricBoundaries =>
|
|
71
71
|
pipe(
|
|
72
|
-
|
|
72
|
+
Arr.makeBy(options.count - 1, (i) => options.start * Math.pow(options.factor, i)),
|
|
73
73
|
Chunk.unsafeFromArray,
|
|
74
74
|
fromIterable
|
|
75
75
|
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as Arr from "../../Array.js"
|
|
2
2
|
import * as Duration from "../../Duration.js"
|
|
3
3
|
import type { LazyArg } from "../../Function.js"
|
|
4
4
|
import { dual, pipe } from "../../Function.js"
|
|
@@ -123,8 +123,8 @@ export const histogram = (key: MetricKey.MetricKey.Histogram): MetricHook.Metric
|
|
|
123
123
|
|
|
124
124
|
pipe(
|
|
125
125
|
bounds,
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
Arr.sort(number.Order),
|
|
127
|
+
Arr.map((n, i) => {
|
|
128
128
|
boundaries[i] = n
|
|
129
129
|
})
|
|
130
130
|
)
|
|
@@ -162,7 +162,7 @@ export const histogram = (key: MetricKey.MetricKey.Histogram): MetricHook.Metric
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
const getBuckets = (): ReadonlyArray<readonly [number, number]> => {
|
|
165
|
-
const builder: Array<readonly [number, number]> =
|
|
165
|
+
const builder: Array<readonly [number, number]> = Arr.allocate(size) as any
|
|
166
166
|
let cumulated = 0
|
|
167
167
|
for (let i = 0; i < size; i++) {
|
|
168
168
|
const boundary = boundaries[i]
|
|
@@ -189,8 +189,8 @@ export const histogram = (key: MetricKey.MetricKey.Histogram): MetricHook.Metric
|
|
|
189
189
|
/** @internal */
|
|
190
190
|
export const summary = (key: MetricKey.MetricKey.Summary): MetricHook.MetricHook.Summary => {
|
|
191
191
|
const { error, maxAge, maxSize, quantiles } = key.keyType
|
|
192
|
-
const sortedQuantiles = pipe(quantiles,
|
|
193
|
-
const values =
|
|
192
|
+
const sortedQuantiles = pipe(quantiles, Arr.sort(number.Order))
|
|
193
|
+
const values = Arr.allocate<readonly [number, number]>(maxSize)
|
|
194
194
|
|
|
195
195
|
let head = 0
|
|
196
196
|
let count = 0
|
|
@@ -228,7 +228,7 @@ export const summary = (key: MetricKey.MetricKey.Summary): MetricHook.MetricHook
|
|
|
228
228
|
return calculateQuantiles(
|
|
229
229
|
error,
|
|
230
230
|
sortedQuantiles,
|
|
231
|
-
|
|
231
|
+
Arr.sort(builder, number.Order)
|
|
232
232
|
)
|
|
233
233
|
}
|
|
234
234
|
|
|
@@ -291,8 +291,8 @@ const calculateQuantiles = (
|
|
|
291
291
|
): ReadonlyArray<readonly [number, Option.Option<number>]> => {
|
|
292
292
|
// The number of samples examined
|
|
293
293
|
const sampleCount = sortedSamples.length
|
|
294
|
-
if (!
|
|
295
|
-
return
|
|
294
|
+
if (!Arr.isNonEmptyReadonlyArray(sortedQuantiles)) {
|
|
295
|
+
return Arr.empty()
|
|
296
296
|
}
|
|
297
297
|
const head = sortedQuantiles[0]
|
|
298
298
|
const tail = sortedQuantiles.slice(1)
|
|
@@ -304,7 +304,7 @@ const calculateQuantiles = (
|
|
|
304
304
|
head,
|
|
305
305
|
sortedSamples
|
|
306
306
|
)
|
|
307
|
-
const resolved =
|
|
307
|
+
const resolved = Arr.of(resolvedHead)
|
|
308
308
|
tail.forEach((quantile) => {
|
|
309
309
|
resolved.push(
|
|
310
310
|
resolveQuantile(
|
|
@@ -317,7 +317,7 @@ const calculateQuantiles = (
|
|
|
317
317
|
)
|
|
318
318
|
)
|
|
319
319
|
})
|
|
320
|
-
return
|
|
320
|
+
return Arr.map(resolved, (rq) => [rq.quantile, rq.value] as const)
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
/** @internal */
|
|
@@ -344,7 +344,7 @@ const resolveQuantile = (
|
|
|
344
344
|
// eslint-disable-next-line no-constant-condition
|
|
345
345
|
while (1) {
|
|
346
346
|
// If the remaining list of samples is empty, there is nothing more to resolve
|
|
347
|
-
if (!
|
|
347
|
+
if (!Arr.isNonEmptyReadonlyArray(rest_1)) {
|
|
348
348
|
return {
|
|
349
349
|
quantile: quantile_1,
|
|
350
350
|
value: Option.none(),
|
|
@@ -357,14 +357,14 @@ const resolveQuantile = (
|
|
|
357
357
|
if (quantile_1 === 1) {
|
|
358
358
|
return {
|
|
359
359
|
quantile: quantile_1,
|
|
360
|
-
value: Option.some(
|
|
360
|
+
value: Option.some(Arr.lastNonEmpty(rest_1)),
|
|
361
361
|
consumed: consumed_1 + rest_1.length,
|
|
362
362
|
rest: []
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
// Split into two chunks - the first chunk contains all elements of the same
|
|
366
366
|
// value as the chunk head
|
|
367
|
-
const sameHead =
|
|
367
|
+
const sameHead = Arr.span(rest_1, (n) => n <= rest_1[0])
|
|
368
368
|
// How many elements do we want to accept for this quantile
|
|
369
369
|
const desired = quantile_1 * sampleCount_1
|
|
370
370
|
// The error margin
|
|
@@ -378,7 +378,7 @@ const resolveQuantile = (
|
|
|
378
378
|
if (candConsumed < desired - allowedError) {
|
|
379
379
|
error_2 = error_1
|
|
380
380
|
sampleCount_2 = sampleCount_1
|
|
381
|
-
current_2 =
|
|
381
|
+
current_2 = Arr.head(rest_1)
|
|
382
382
|
consumed_2 = candConsumed
|
|
383
383
|
quantile_2 = quantile_1
|
|
384
384
|
rest_2 = sameHead[1]
|
|
@@ -406,7 +406,7 @@ const resolveQuantile = (
|
|
|
406
406
|
case "None": {
|
|
407
407
|
error_2 = error_1
|
|
408
408
|
sampleCount_2 = sampleCount_1
|
|
409
|
-
current_2 =
|
|
409
|
+
current_2 = Arr.head(rest_1)
|
|
410
410
|
consumed_2 = candConsumed
|
|
411
411
|
quantile_2 = quantile_1
|
|
412
412
|
rest_2 = sameHead[1]
|
|
@@ -423,7 +423,7 @@ const resolveQuantile = (
|
|
|
423
423
|
if (candError < prevError) {
|
|
424
424
|
error_2 = error_1
|
|
425
425
|
sampleCount_2 = sampleCount_1
|
|
426
|
-
current_2 =
|
|
426
|
+
current_2 = Arr.head(rest_1)
|
|
427
427
|
consumed_2 = candConsumed
|
|
428
428
|
quantile_2 = quantile_1
|
|
429
429
|
rest_2 = sameHead[1]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as Arr from "../../Array.js"
|
|
2
2
|
import type * as Duration from "../../Duration.js"
|
|
3
3
|
import * as Equal from "../../Equal.js"
|
|
4
4
|
import { dual, pipe } from "../../Function.js"
|
|
@@ -26,7 +26,7 @@ const metricKeyVariance = {
|
|
|
26
26
|
_Type: (_: never) => _
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const arrayEquivilence =
|
|
29
|
+
const arrayEquivilence = Arr.getEquivalence(Equal.equals)
|
|
30
30
|
|
|
31
31
|
/** @internal */
|
|
32
32
|
class MetricKeyImpl<out Type extends MetricKeyType.MetricKeyType<any, any>> implements MetricKey.MetricKey<Type> {
|
|
@@ -164,4 +164,4 @@ export const taggedWithLabels = dual<
|
|
|
164
164
|
>(2, (self, extraTags) =>
|
|
165
165
|
extraTags.length === 0
|
|
166
166
|
? self
|
|
167
|
-
: new MetricKeyImpl(self.name, self.keyType, self.description,
|
|
167
|
+
: new MetricKeyImpl(self.name, self.keyType, self.description, Arr.union(self.tags, extraTags)))
|