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.
Files changed (56) hide show
  1. package/dist/FileSystem.d.ts +1 -1
  2. package/dist/FileSystem.d.ts.map +1 -1
  3. package/dist/FileSystem.js +3 -3
  4. package/dist/FileSystem.js.map +1 -1
  5. package/dist/Filter.d.ts +30 -1
  6. package/dist/Filter.d.ts.map +1 -1
  7. package/dist/Filter.js +15 -0
  8. package/dist/Filter.js.map +1 -1
  9. package/dist/PlatformError.d.ts +8 -7
  10. package/dist/PlatformError.d.ts.map +1 -1
  11. package/dist/PlatformError.js +2 -2
  12. package/dist/PlatformError.js.map +1 -1
  13. package/dist/Schedule.d.ts +12 -2
  14. package/dist/Schedule.d.ts.map +1 -1
  15. package/dist/Schedule.js +13 -0
  16. package/dist/Schedule.js.map +1 -1
  17. package/dist/Schema.d.ts +3 -3
  18. package/dist/Schema.d.ts.map +1 -1
  19. package/dist/Types.d.ts +6 -6
  20. package/dist/Types.d.ts.map +1 -1
  21. package/dist/unstable/http/HttpBody.d.ts +2 -2
  22. package/dist/unstable/http/HttpBody.d.ts.map +1 -1
  23. package/dist/unstable/http/HttpBody.js +6 -6
  24. package/dist/unstable/http/HttpBody.js.map +1 -1
  25. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  26. package/dist/unstable/http/HttpClientRequest.js +2 -2
  27. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  28. package/dist/unstable/http/HttpServerResponse.js +1 -1
  29. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  30. package/dist/unstable/persistence/KeyValueStore.js +2 -2
  31. package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
  32. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  33. package/dist/unstable/reactivity/Atom.js +12 -9
  34. package/dist/unstable/reactivity/Atom.js.map +1 -1
  35. package/dist/unstable/reactivity/Hydration.d.ts +39 -0
  36. package/dist/unstable/reactivity/Hydration.d.ts.map +1 -0
  37. package/dist/unstable/reactivity/Hydration.js +76 -0
  38. package/dist/unstable/reactivity/Hydration.js.map +1 -0
  39. package/dist/unstable/reactivity/index.d.ts +4 -0
  40. package/dist/unstable/reactivity/index.d.ts.map +1 -1
  41. package/dist/unstable/reactivity/index.js +4 -0
  42. package/dist/unstable/reactivity/index.js.map +1 -1
  43. package/package.json +1 -1
  44. package/src/FileSystem.ts +3 -4
  45. package/src/Filter.ts +48 -1
  46. package/src/PlatformError.ts +5 -5
  47. package/src/Schedule.ts +20 -2
  48. package/src/Schema.ts +3 -3
  49. package/src/Types.ts +3 -2
  50. package/src/unstable/http/HttpBody.ts +6 -6
  51. package/src/unstable/http/HttpClientRequest.ts +2 -2
  52. package/src/unstable/http/HttpServerResponse.ts +1 -1
  53. package/src/unstable/persistence/KeyValueStore.ts +2 -2
  54. package/src/unstable/reactivity/Atom.ts +7 -5
  55. package/src/unstable/reactivity/Hydration.ts +112 -0
  56. 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 makeFormData = (body: globalThis.FormData): FormData => new FormData(body)
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 makeFormDataRecord = (entries: FormDataInput): FormData => {
312
- const formData = new globalThis.FormData()
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(formData, key, item)
316
+ appendFormDataValue(data, key, item)
317
317
  }
318
318
  } else {
319
- appendFormDataValue(formData, key, value as FormDataCoercible)
319
+ appendFormDataValue(data, key, value as FormDataCoercible)
320
320
  }
321
321
  }
322
- return makeFormData(formData)
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.makeFormData(body)))
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.makeFormDataRecord(entries))
849
+ setBody(self, HttpBody.formDataRecord(entries))
850
850
  )
851
851
 
852
852
  /**
@@ -327,7 +327,7 @@ export const formData = (
327
327
  statusText: options?.statusText,
328
328
  headers: options?.headers && Headers.fromInput(options.headers),
329
329
  cookies: options?.cookies,
330
- body: Body.makeFormData(body)
330
+ body: Body.formData(body)
331
331
  })
332
332
 
333
333
  /**
@@ -312,7 +312,7 @@ export const layerFileSystem = (
312
312
  fs.readFileString(keyPath(key)),
313
313
  "PlatformError",
314
314
  (cause) =>
315
- cause.reason._tag === "SystemError" && cause.reason.kind === "NotFound" ? Effect.undefined : Effect.fail(
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 === "SystemError" && cause.reason.kind === "NotFound" ? Effect.undefined : Effect.fail(
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
- Object.assign(Object.create(Object.getPrototypeOf(self)), {
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(options.schema),
2301
- decode: Schema.decodeSync(options.schema)
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
+ }
@@ -29,6 +29,11 @@ export * as AtomRef from "./AtomRef.ts"
29
29
  */
30
30
  export * as AtomRegistry from "./AtomRegistry.ts"
31
31
 
32
+ /**
33
+ * @since 4.0.0
34
+ */
35
+ export * as Hydration from "./Hydration.ts"
36
+
32
37
  /**
33
38
  * @since 4.0.0
34
39
  */