effect 4.0.0-beta.3 → 4.0.0-beta.5
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/FileSystem.d.ts +1 -1
- package/dist/FileSystem.d.ts.map +1 -1
- package/dist/FileSystem.js +3 -3
- package/dist/FileSystem.js.map +1 -1
- package/dist/Filter.d.ts +30 -1
- package/dist/Filter.d.ts.map +1 -1
- package/dist/Filter.js +15 -0
- package/dist/Filter.js.map +1 -1
- package/dist/PlatformError.d.ts +8 -7
- package/dist/PlatformError.d.ts.map +1 -1
- package/dist/PlatformError.js +2 -2
- package/dist/PlatformError.js.map +1 -1
- package/dist/Schedule.d.ts +12 -2
- package/dist/Schedule.d.ts.map +1 -1
- package/dist/Schedule.js +13 -0
- package/dist/Schedule.js.map +1 -1
- package/dist/Schema.d.ts +3 -3
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Types.d.ts +6 -6
- package/dist/Types.d.ts.map +1 -1
- package/dist/unstable/http/HttpBody.d.ts +2 -2
- package/dist/unstable/http/HttpBody.d.ts.map +1 -1
- package/dist/unstable/http/HttpBody.js +6 -6
- package/dist/unstable/http/HttpBody.js.map +1 -1
- package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
- package/dist/unstable/http/HttpClientRequest.js +2 -2
- package/dist/unstable/http/HttpClientRequest.js.map +1 -1
- package/dist/unstable/http/HttpServerResponse.js +1 -1
- package/dist/unstable/http/HttpServerResponse.js.map +1 -1
- package/dist/unstable/persistence/KeyValueStore.js +2 -2
- package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
- package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
- package/dist/unstable/reactivity/Atom.js +12 -9
- package/dist/unstable/reactivity/Atom.js.map +1 -1
- package/dist/unstable/reactivity/Hydration.d.ts +39 -0
- package/dist/unstable/reactivity/Hydration.d.ts.map +1 -0
- package/dist/unstable/reactivity/Hydration.js +76 -0
- package/dist/unstable/reactivity/Hydration.js.map +1 -0
- package/dist/unstable/reactivity/index.d.ts +4 -0
- package/dist/unstable/reactivity/index.d.ts.map +1 -1
- package/dist/unstable/reactivity/index.js +4 -0
- package/dist/unstable/reactivity/index.js.map +1 -1
- package/package.json +1 -1
- package/src/FileSystem.ts +3 -4
- package/src/Filter.ts +48 -1
- package/src/PlatformError.ts +5 -5
- package/src/Schedule.ts +20 -2
- package/src/Schema.ts +3 -3
- package/src/Types.ts +3 -2
- package/src/unstable/http/HttpBody.ts +6 -6
- package/src/unstable/http/HttpClientRequest.ts +2 -2
- package/src/unstable/http/HttpServerResponse.ts +1 -1
- package/src/unstable/persistence/KeyValueStore.ts +2 -2
- package/src/unstable/reactivity/Atom.ts +7 -5
- package/src/unstable/reactivity/Hydration.ts +112 -0
- package/src/unstable/reactivity/index.ts +5 -0
|
@@ -279,7 +279,7 @@ export class FormData extends Proto {
|
|
|
279
279
|
* @since 4.0.0
|
|
280
280
|
* @category constructors
|
|
281
281
|
*/
|
|
282
|
-
export const
|
|
282
|
+
export const formData = (body: globalThis.FormData): FormData => new FormData(body)
|
|
283
283
|
|
|
284
284
|
/**
|
|
285
285
|
* @since 4.0.0
|
|
@@ -308,18 +308,18 @@ const appendFormDataValue = (formData: globalThis.FormData, key: string, value:
|
|
|
308
308
|
* @since 4.0.0
|
|
309
309
|
* @category constructors
|
|
310
310
|
*/
|
|
311
|
-
export const
|
|
312
|
-
const
|
|
311
|
+
export const formDataRecord = (entries: FormDataInput): FormData => {
|
|
312
|
+
const data = new globalThis.FormData()
|
|
313
313
|
for (const [key, value] of Object.entries(entries)) {
|
|
314
314
|
if (Array.isArray(value)) {
|
|
315
315
|
for (const item of value) {
|
|
316
|
-
appendFormDataValue(
|
|
316
|
+
appendFormDataValue(data, key, item)
|
|
317
317
|
}
|
|
318
318
|
} else {
|
|
319
|
-
appendFormDataValue(
|
|
319
|
+
appendFormDataValue(data, key, value as FormDataCoercible)
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
|
-
return
|
|
322
|
+
return formData(data)
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
/**
|
|
@@ -826,7 +826,7 @@ export const bodyFormData: {
|
|
|
826
826
|
* @category combinators
|
|
827
827
|
*/
|
|
828
828
|
(self: HttpClientRequest, body: FormData): HttpClientRequest
|
|
829
|
-
} = dual(2, (self: HttpClientRequest, body: FormData): HttpClientRequest => setBody(self, HttpBody.
|
|
829
|
+
} = dual(2, (self: HttpClientRequest, body: FormData): HttpClientRequest => setBody(self, HttpBody.formData(body)))
|
|
830
830
|
|
|
831
831
|
/**
|
|
832
832
|
* @since 4.0.0
|
|
@@ -846,7 +846,7 @@ export const bodyFormDataRecord: {
|
|
|
846
846
|
} = dual(
|
|
847
847
|
2,
|
|
848
848
|
(self: HttpClientRequest, entries: HttpBody.FormDataInput): HttpClientRequest =>
|
|
849
|
-
setBody(self, HttpBody.
|
|
849
|
+
setBody(self, HttpBody.formDataRecord(entries))
|
|
850
850
|
)
|
|
851
851
|
|
|
852
852
|
/**
|
|
@@ -312,7 +312,7 @@ export const layerFileSystem = (
|
|
|
312
312
|
fs.readFileString(keyPath(key)),
|
|
313
313
|
"PlatformError",
|
|
314
314
|
(cause) =>
|
|
315
|
-
cause.reason._tag === "
|
|
315
|
+
cause.reason._tag === "NotFound" ? Effect.undefined : Effect.fail(
|
|
316
316
|
new KeyValueStoreError({
|
|
317
317
|
method: "get",
|
|
318
318
|
key,
|
|
@@ -326,7 +326,7 @@ export const layerFileSystem = (
|
|
|
326
326
|
fs.readFile(keyPath(key)),
|
|
327
327
|
"PlatformError",
|
|
328
328
|
(cause) =>
|
|
329
|
-
cause.reason._tag === "
|
|
329
|
+
cause.reason._tag === "NotFound" ? Effect.undefined : Effect.fail(
|
|
330
330
|
new KeyValueStoreError({
|
|
331
331
|
method: "getUint8Array",
|
|
332
332
|
key,
|
|
@@ -2291,16 +2291,18 @@ export const serializable: {
|
|
|
2291
2291
|
} = dual(2, <R extends Atom<any>, A, I>(self: R, options: {
|
|
2292
2292
|
readonly key: string
|
|
2293
2293
|
readonly schema: Schema.Codec<A, I>
|
|
2294
|
-
}): R & Serializable<any> =>
|
|
2295
|
-
|
|
2294
|
+
}): R & Serializable<any> => {
|
|
2295
|
+
const codecJson = Schema.toCodecJson(options.schema)
|
|
2296
|
+
return Object.assign(Object.create(Object.getPrototypeOf(self)), {
|
|
2296
2297
|
...self,
|
|
2297
2298
|
label: self.label ?? [options.key, new Error().stack?.split("\n")[5] ?? ""],
|
|
2298
2299
|
[SerializableTypeId]: {
|
|
2299
2300
|
key: options.key,
|
|
2300
|
-
encode: Schema.encodeSync(
|
|
2301
|
-
decode: Schema.decodeSync(
|
|
2301
|
+
encode: Schema.encodeSync(codecJson),
|
|
2302
|
+
decode: Schema.decodeSync(codecJson)
|
|
2302
2303
|
}
|
|
2303
|
-
})
|
|
2304
|
+
})
|
|
2305
|
+
})
|
|
2304
2306
|
|
|
2305
2307
|
/**
|
|
2306
2308
|
* @since 4.0.0
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 4.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as AsyncResult from "./AsyncResult.ts"
|
|
5
|
+
import * as Atom from "./Atom.ts"
|
|
6
|
+
import type * as AtomRegistry from "./AtomRegistry.ts"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @since 4.0.0
|
|
10
|
+
* @category models
|
|
11
|
+
*/
|
|
12
|
+
export interface DehydratedAtom {
|
|
13
|
+
readonly "~effect/reactivity/DehydratedAtom": true
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @since 4.0.0
|
|
18
|
+
* @category models
|
|
19
|
+
*/
|
|
20
|
+
export interface DehydratedAtomValue extends DehydratedAtom {
|
|
21
|
+
readonly key: string
|
|
22
|
+
readonly value: unknown
|
|
23
|
+
readonly dehydratedAt: number
|
|
24
|
+
readonly resultPromise?: Promise<unknown> | undefined
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @since 4.0.0
|
|
29
|
+
* @category dehydration
|
|
30
|
+
*/
|
|
31
|
+
export const dehydrate = (
|
|
32
|
+
registry: AtomRegistry.AtomRegistry,
|
|
33
|
+
options?: {
|
|
34
|
+
/**
|
|
35
|
+
* How to encode `AsyncResult.Initial` values. Default is "ignore".
|
|
36
|
+
*/
|
|
37
|
+
readonly encodeInitialAs?: "ignore" | "promise" | "value-only" | undefined
|
|
38
|
+
}
|
|
39
|
+
): Array<DehydratedAtom> => {
|
|
40
|
+
const encodeInitialResultMode = options?.encodeInitialAs ?? "ignore"
|
|
41
|
+
const arr: Array<DehydratedAtomValue> = []
|
|
42
|
+
const now = Date.now()
|
|
43
|
+
registry.getNodes().forEach((node, key) => {
|
|
44
|
+
if (!Atom.isSerializable(node.atom)) return
|
|
45
|
+
const atom = node.atom
|
|
46
|
+
const value = node.value()
|
|
47
|
+
const isInitial = AsyncResult.isAsyncResult(value) && AsyncResult.isInitial(value)
|
|
48
|
+
if (encodeInitialResultMode === "ignore" && isInitial) return
|
|
49
|
+
const encodedValue = atom[Atom.SerializableTypeId].encode(value)
|
|
50
|
+
|
|
51
|
+
// Create a promise that resolves when the atom moves out of Initial state
|
|
52
|
+
let resultPromise: Promise<unknown> | undefined
|
|
53
|
+
if (encodeInitialResultMode === "promise" && isInitial) {
|
|
54
|
+
resultPromise = new Promise((resolve) => {
|
|
55
|
+
const unsubscribe = registry.subscribe(atom, (newValue) => {
|
|
56
|
+
if (AsyncResult.isAsyncResult(newValue) && !AsyncResult.isInitial(newValue)) {
|
|
57
|
+
resolve(atom[Atom.SerializableTypeId].encode(newValue))
|
|
58
|
+
unsubscribe()
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
arr.push({
|
|
65
|
+
"~effect/reactivity/DehydratedAtom": true,
|
|
66
|
+
key: key as string,
|
|
67
|
+
value: encodedValue,
|
|
68
|
+
dehydratedAt: now,
|
|
69
|
+
resultPromise
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
return arr as any
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @since 4.0.0
|
|
77
|
+
* @category dehydration
|
|
78
|
+
*/
|
|
79
|
+
export const toValues = (state: ReadonlyArray<DehydratedAtom>): Array<DehydratedAtomValue> => state as any
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @since 4.0.0
|
|
83
|
+
* @category hydration
|
|
84
|
+
*/
|
|
85
|
+
export const hydrate = (
|
|
86
|
+
registry: AtomRegistry.AtomRegistry,
|
|
87
|
+
dehydratedState: Iterable<DehydratedAtom>
|
|
88
|
+
): void => {
|
|
89
|
+
for (const datom of (dehydratedState as Iterable<DehydratedAtomValue>)) {
|
|
90
|
+
registry.setSerializable(datom.key, datom.value)
|
|
91
|
+
|
|
92
|
+
// If there's a resultPromise, it means this was in Initial state when dehydrated
|
|
93
|
+
// and we should wait for it to resolve to a non-Initial state, then update the registry
|
|
94
|
+
if (!datom.resultPromise) continue
|
|
95
|
+
datom.resultPromise.then((resolvedValue) => {
|
|
96
|
+
// Try to update the existing node directly instead of using setSerializable
|
|
97
|
+
const nodes = registry.getNodes()
|
|
98
|
+
const node = nodes.get(datom.key)
|
|
99
|
+
if (node) {
|
|
100
|
+
// Decode the resolved value using the node's atom serializable decoder
|
|
101
|
+
const atom = node.atom as any
|
|
102
|
+
if (atom[Atom.SerializableTypeId]) {
|
|
103
|
+
const decoded = atom[Atom.SerializableTypeId].decode(resolvedValue)
|
|
104
|
+
;(node as any).setValue(decoded)
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
// Fallback to setSerializable if node doesn't exist yet
|
|
108
|
+
registry.setSerializable(datom.key, resolvedValue)
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
}
|