effect-app 4.0.0-beta.2 → 4.0.0-beta.20

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 (68) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/dist/Operations.d.ts +14 -14
  3. package/dist/Pure.js +1 -1
  4. package/dist/Schema/brand.d.ts +8 -5
  5. package/dist/Schema/brand.d.ts.map +1 -1
  6. package/dist/Schema/brand.js +1 -1
  7. package/dist/Schema/email.d.ts.map +1 -1
  8. package/dist/Schema/email.js +4 -3
  9. package/dist/Schema/ext.d.ts +26 -25
  10. package/dist/Schema/ext.d.ts.map +1 -1
  11. package/dist/Schema/ext.js +13 -20
  12. package/dist/Schema/moreStrings.d.ts +6 -6
  13. package/dist/Schema/moreStrings.d.ts.map +1 -1
  14. package/dist/Schema/moreStrings.js +6 -4
  15. package/dist/Schema/phoneNumber.d.ts.map +1 -1
  16. package/dist/Schema/phoneNumber.js +3 -2
  17. package/dist/Schema.d.ts +27 -24
  18. package/dist/Schema.d.ts.map +1 -1
  19. package/dist/Schema.js +23 -22
  20. package/dist/ServiceMap.d.ts +3 -3
  21. package/dist/ServiceMap.d.ts.map +1 -1
  22. package/dist/ServiceMap.js +1 -1
  23. package/dist/client/apiClientFactory.d.ts.map +1 -1
  24. package/dist/client/apiClientFactory.js +8 -9
  25. package/dist/client/errors.d.ts.map +1 -1
  26. package/dist/client/errors.js +1 -1
  27. package/dist/client/makeClient.d.ts +6 -6
  28. package/dist/client/makeClient.d.ts.map +1 -1
  29. package/dist/client/makeClient.js +3 -14
  30. package/dist/ids.d.ts +6 -6
  31. package/dist/ids.d.ts.map +1 -1
  32. package/dist/ids.js +1 -1
  33. package/dist/index.d.ts +0 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +1 -2
  36. package/dist/rpc/MiddlewareMaker.d.ts +1 -1
  37. package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
  38. package/dist/rpc/MiddlewareMaker.js +1 -1
  39. package/dist/rpc/RpcMiddleware.d.ts +1 -1
  40. package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
  41. package/dist/utils.d.ts +18 -0
  42. package/dist/utils.d.ts.map +1 -1
  43. package/dist/utils.js +24 -5
  44. package/package.json +3 -7
  45. package/src/Pure.ts +2 -2
  46. package/src/Schema/brand.ts +13 -7
  47. package/src/Schema/email.ts +4 -2
  48. package/src/Schema/ext.ts +46 -38
  49. package/src/Schema/moreStrings.ts +16 -13
  50. package/src/Schema/phoneNumber.ts +3 -1
  51. package/src/Schema.ts +56 -40
  52. package/src/ServiceMap.ts +7 -6
  53. package/src/client/apiClientFactory.ts +12 -15
  54. package/src/client/errors.ts +12 -3
  55. package/src/client/makeClient.ts +6 -19
  56. package/src/ids.ts +1 -1
  57. package/src/index.ts +0 -1
  58. package/src/rpc/MiddlewareMaker.ts +2 -1
  59. package/src/rpc/RpcMiddleware.ts +2 -2
  60. package/src/utils.ts +26 -4
  61. package/test/dist/moreStrings.test.d.ts.map +1 -0
  62. package/test/dist/rpc.test.d.ts.map +1 -1
  63. package/test/moreStrings.test.ts +17 -0
  64. package/test/schema.test.ts +32 -1
  65. package/dist/Struct.d.ts +0 -44
  66. package/dist/Struct.d.ts.map +0 -1
  67. package/dist/Struct.js +0 -29
  68. package/src/Struct.ts +0 -54
package/src/utils.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-function-type */
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
3
  /* eslint-disable @typescript-eslint/no-redundant-type-constituents */
4
- import { Effect, Exit, Fiber, Option, Record } from "effect"
4
+ import { Cause, Effect, Exit, Fiber, Option, Record } from "effect"
5
5
  import { dual } from "effect/Function"
6
- import { isFunction } from "effect/Predicate"
6
+ import { isFunction, isObject } from "effect/Predicate"
7
7
  import * as Result from "effect/Result"
8
8
  import type { GetFieldType, NumericDictionary, PropertyPath } from "lodash"
9
9
  import { identity, pipe } from "./Function.js"
@@ -924,8 +924,8 @@ export const runtimeFiberAsPromise = <A, E>(fiber: Fiber.Fiber<A, E>, signal?: A
924
924
  if (Exit.isSuccess(exit)) {
925
925
  resolve(exit.value)
926
926
  } else {
927
- // errors really should be of type Error, so we wrap in FiberFailure just as default Effect
928
- reject(exit.cause)
927
+ // eslint-disable-next-line
928
+ reject(Cause.squash(exit.cause))
929
929
  }
930
930
  })
931
931
  )
@@ -950,3 +950,25 @@ export type UnionToTuples<T, U = T> = [T] extends [never] ? []
950
950
  | [T, ...UnionToTuples<Exclude<U, T>>]
951
951
  | UnionToTuples<Exclude<U, T>>
952
952
  : []
953
+
954
+ const genConstructor = (function*() {}).constructor
955
+
956
+ /**
957
+ * @example
958
+ * ```ts
959
+ * import { Utils } from "effect"
960
+ *
961
+ * function* generatorFn() {
962
+ * yield 1
963
+ * yield 2
964
+ * }
965
+ *
966
+ * console.log(Utils.isGeneratorFunction(generatorFn)) // true
967
+ * console.log(Utils.isGeneratorFunction(() => {})) // false
968
+ * ```
969
+ *
970
+ * @category predicates
971
+ * @since 3.11.0
972
+ */
973
+ export const isGeneratorFunction = (u: unknown): u is (...args: Array<any>) => Generator<any, any, any> =>
974
+ isObject(u) && u.constructor === genConstructor
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moreStrings.test.d.ts","sourceRoot":"","sources":["../moreStrings.test.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"rpc.test.d.ts","sourceRoot":"","sources":["../rpc.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACrF,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;;;;;;;;;;;;;;;;;;;;;;;;AAE7C,qBAAa,iBAAkB,SAAQ,sBAIrC;CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIL,qBAAa,KAAM,SAAQ,UAQzB;CAAG"}
1
+ {"version":3,"file":"rpc.test.d.ts","sourceRoot":"","sources":["../rpc.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACrF,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;;;;;;;;;;;;;;;;;;;;;;;;AAE7C,qBAAa,iBAAkB,SAAQ,sBAIrC;CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIL,qBAAa,KAAM,SAAQ,UAQzB;CAAG"}
@@ -0,0 +1,17 @@
1
+ import { S } from "effect-app"
2
+ import * as fc from "fast-check"
3
+ import { urlAlphabet } from "nanoid"
4
+ import { test } from "vitest"
5
+
6
+ const nanoidAlphabet = new Set(urlAlphabet)
7
+
8
+ const isNanoId = (value: string) => value.length === 21 && Array.from(value).every((char) => nanoidAlphabet.has(char))
9
+
10
+ test("StringId arbitrary generates nanoid-shaped values", () => {
11
+ fc.assert(
12
+ fc.property(S.toArbitrary(S.StringId), (value) => {
13
+ expect(isNanoId(value)).toBe(true)
14
+ expect(S.is(S.StringId)(value)).toBe(true)
15
+ })
16
+ )
17
+ })
@@ -1,6 +1,6 @@
1
1
  // import { generateFromArbitrary } from "@effect-app/infra/test"
2
2
  import { Array, S } from "effect-app"
3
- import { test } from "vitest"
3
+ import { expect, test } from "vitest"
4
4
 
5
5
  const A = S.Struct({ a: S.NonEmptyString255, email: S.NullOr(S.Email) })
6
6
  test("works", () => {
@@ -23,3 +23,34 @@ test("literal default works", () => {
23
23
  const s2 = S.Struct({ l: l2.withDefault })
24
24
  expect(s2.makeUnsafe({}).l).toBe("b")
25
25
  })
26
+
27
+ test("tagged union derives tag map and tags from v4 literal ast", () => {
28
+ const schema = S.TaggedUnion(
29
+ S.TaggedStruct("A", { a: S.String }),
30
+ S.TaggedStruct("B", { b: S.Number }),
31
+ S.TaggedStruct("C", { c: S.Boolean })
32
+ )
33
+ const caseA = schema.tagMap["A"]
34
+ const caseB = schema.tagMap["B"]
35
+ const caseC = schema.tagMap["C"]
36
+ const isAOrB = schema.isAnyOf("A", "B")
37
+
38
+ expect(caseA.fields._tag.ast.literal).toBe("A")
39
+ expect(caseB.fields._tag.ast.literal).toBe("B")
40
+ expect(caseC.fields._tag.ast.literal).toBe("C")
41
+ expect(S.decodeSync(schema.tags)("A")).toBe("A")
42
+ expect(S.decodeSync(schema.tags)("B")).toBe("B")
43
+ expect(S.decodeSync(schema.tags)("C")).toBe("C")
44
+ expect(() => S.decodeUnknownSync(schema.tags)("D")).toThrow()
45
+
46
+ expect(schema.isA.A({ _tag: "A", a: "ok" })).toBe(true)
47
+ expect(schema.isA.A({ _tag: "B", b: 1 })).toBe(false)
48
+ expect(schema.isA.B({ _tag: "B", b: 1 })).toBe(true)
49
+ expect(schema.isA.B({ _tag: "A", a: "ok" })).toBe(false)
50
+ expect(schema.isA.C({ _tag: "C", c: true })).toBe(true)
51
+ expect(schema.isA.C({ _tag: "A", a: "ok" })).toBe(false)
52
+
53
+ expect(isAOrB({ _tag: "A", a: "ok" })).toBe(true)
54
+ expect(isAOrB({ _tag: "B", b: 1 })).toBe(true)
55
+ expect(isAOrB({ _tag: "C", c: true })).toBe(false)
56
+ })
package/dist/Struct.d.ts DELETED
@@ -1,44 +0,0 @@
1
- import type { Types } from "effect";
2
- export * from "effect/Struct";
3
- /**
4
- * Create a new object by picking properties of an existing object.
5
- *
6
- * @example
7
- * import { pick } from "effect/Struct"
8
- * import { pipe } from "effect/Function"
9
- *
10
- * assert.deepStrictEqual(pipe({ a: "a", b: 1, c: true }, pick("a", "b")), { a: "a", b: 1 })
11
- * assert.deepStrictEqual(pick({ a: "a", b: 1, c: true }, "a", "b"), { a: "a", b: 1 })
12
- *
13
- * @since 2.0.0
14
- */
15
- export declare const pick: {
16
- <Keys extends Array<PropertyKey>>(keys: Keys): <S extends {
17
- [K in Keys[number]]?: any;
18
- }>(s: S) => Types.MatchRecord<S, {
19
- [K in Keys[number]]?: S[K];
20
- }, Pick<S, Keys[number]>>;
21
- <S extends object, Keys extends Array<keyof S>>(s: S, keys: Keys): Types.MatchRecord<S, {
22
- [K in Keys[number]]?: S[K];
23
- }, Pick<S, Keys[number]>>;
24
- };
25
- export type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
26
- /**
27
- * Create a new object by omitting properties of an existing object.
28
- *
29
- * @example
30
- * import { omit } from "effect/Struct"
31
- * import { pipe } from "effect/Function"
32
- *
33
- * assert.deepStrictEqual(pipe({ a: "a", b: 1, c: true }, omit("c")), { a: "a", b: 1 })
34
- * assert.deepStrictEqual(omit({ a: "a", b: 1, c: true }, "c"), { a: "a", b: 1 })
35
- *
36
- * @since 2.0.0
37
- */
38
- export declare const omit: {
39
- <Keys extends Array<PropertyKey>>(keys: Keys): <S extends {
40
- [K in Keys[number]]?: any;
41
- }>(s: S) => DistributiveOmit<S, Keys[number]>;
42
- <S extends object, Keys extends Array<keyof S>>(s: S, keys: Keys): DistributiveOmit<S, Keys[number]>;
43
- };
44
- //# sourceMappingURL=Struct.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Struct.d.ts","sourceRoot":"","sources":["../src/Struct.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAGnC,cAAc,eAAe,CAAA;AAE7B;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,IAAI,EAAE;IACjB,CAAC,IAAI,SAAS,KAAK,CAAC,WAAW,CAAC,EAC9B,IAAI,EAAE,IAAI,GACT,CAAC,CAAC,SAAS;SAAG,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG;KAAE,EACzC,CAAC,EAAE,CAAC,KACD,KAAK,CAAC,WAAW,CAAC,CAAC,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Struct from "effect/Struct";
2
- export * from "effect/Struct";
3
- /**
4
- * Create a new object by picking properties of an existing object.
5
- *
6
- * @example
7
- * import { pick } from "effect/Struct"
8
- * import { pipe } from "effect/Function"
9
- *
10
- * assert.deepStrictEqual(pipe({ a: "a", b: 1, c: true }, pick("a", "b")), { a: "a", b: 1 })
11
- * assert.deepStrictEqual(pick({ a: "a", b: 1, c: true }, "a", "b"), { a: "a", b: 1 })
12
- *
13
- * @since 2.0.0
14
- */
15
- export const pick = Struct.pick;
16
- /**
17
- * Create a new object by omitting properties of an existing object.
18
- *
19
- * @example
20
- * import { omit } from "effect/Struct"
21
- * import { pipe } from "effect/Function"
22
- *
23
- * assert.deepStrictEqual(pipe({ a: "a", b: 1, c: true }, omit("c")), { a: "a", b: 1 })
24
- * assert.deepStrictEqual(omit({ a: "a", b: 1, c: true }, "c"), { a: "a", b: 1 })
25
- *
26
- * @since 2.0.0
27
- */
28
- export const omit = Struct.omit;
29
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU3RydWN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL1N0cnVjdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEtBQUssTUFBTSxNQUFNLGVBQWUsQ0FBQTtBQUV2QyxjQUFjLGVBQWUsQ0FBQTtBQUU3Qjs7Ozs7Ozs7Ozs7R0FXRztBQUNILE1BQU0sQ0FBQyxNQUFNLElBQUksR0FVYixNQUFNLENBQUMsSUFBSSxDQUFBO0FBS2Y7Ozs7Ozs7Ozs7O0dBV0c7QUFDSCxNQUFNLENBQUMsTUFBTSxJQUFJLEdBUWIsTUFBTSxDQUFDLElBQVcsQ0FBQSJ9
package/src/Struct.ts DELETED
@@ -1,54 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import type { Types } from "effect"
3
- import * as Struct from "effect/Struct"
4
-
5
- export * from "effect/Struct"
6
-
7
- /**
8
- * Create a new object by picking properties of an existing object.
9
- *
10
- * @example
11
- * import { pick } from "effect/Struct"
12
- * import { pipe } from "effect/Function"
13
- *
14
- * assert.deepStrictEqual(pipe({ a: "a", b: 1, c: true }, pick("a", "b")), { a: "a", b: 1 })
15
- * assert.deepStrictEqual(pick({ a: "a", b: 1, c: true }, "a", "b"), { a: "a", b: 1 })
16
- *
17
- * @since 2.0.0
18
- */
19
- export const pick: {
20
- <Keys extends Array<PropertyKey>>(
21
- keys: Keys
22
- ): <S extends { [K in Keys[number]]?: any }>(
23
- s: S
24
- ) => Types.MatchRecord<S, { [K in Keys[number]]?: S[K] }, Pick<S, Keys[number]>>
25
- <S extends object, Keys extends Array<keyof S>>(
26
- s: S,
27
- keys: Keys
28
- ): Types.MatchRecord<S, { [K in Keys[number]]?: S[K] }, Pick<S, Keys[number]>>
29
- } = Struct.pick
30
-
31
- export type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K>
32
- : never
33
-
34
- /**
35
- * Create a new object by omitting properties of an existing object.
36
- *
37
- * @example
38
- * import { omit } from "effect/Struct"
39
- * import { pipe } from "effect/Function"
40
- *
41
- * assert.deepStrictEqual(pipe({ a: "a", b: 1, c: true }, omit("c")), { a: "a", b: 1 })
42
- * assert.deepStrictEqual(omit({ a: "a", b: 1, c: true }, "c"), { a: "a", b: 1 })
43
- *
44
- * @since 2.0.0
45
- */
46
- export const omit: {
47
- <Keys extends Array<PropertyKey>>(
48
- keys: Keys
49
- ): <S extends { [K in Keys[number]]?: any }>(s: S) => DistributiveOmit<S, Keys[number]>
50
- <S extends object, Keys extends Array<keyof S>>(
51
- s: S,
52
- keys: Keys
53
- ): DistributiveOmit<S, Keys[number]>
54
- } = Struct.omit as any