effect-app 4.0.0-beta.255 → 4.0.0-beta.257

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.
@@ -11,21 +11,21 @@
11
11
  import { extendM } from "effect-app/utils"
12
12
  import * as Effect from "effect/Effect"
13
13
  import * as S from "effect/Schema"
14
+ import type * as SchemaAST from "effect/SchemaAST"
14
15
  import type { Simplify } from "effect/Types"
15
- import { fromBrand, nominal } from "./brand.js"
16
- import { withDefaultMake, type WithDefaults } from "./ext.js"
16
+ import { type BrandedSchema, fromBrand, nominal } from "./brand.js"
17
+ import { withDefaultMake } from "./ext.js"
17
18
  import { type B } from "./schema.js"
18
19
 
19
- type BrandedNumberSchema<A extends number> = S.Codec<A, number> & WithDefaults<S.Codec<A, number>>
20
- type BrandedNumberSchemaWithConstructorDefault<A extends number> = BrandedNumberSchema<A> & {
21
- readonly withConstructorDefault: S.Codec<A, number>
22
- }
23
-
24
20
  export interface PositiveIntBrand
25
21
  extends Simplify<B.Brand<"PositiveInt"> & NonNegativeIntBrand & PositiveNumberBrand>
26
22
  {}
23
+ export type PositiveInt = number & PositiveIntBrand
27
24
  /** Positive integer. `.withConstructorDefault` => `1` (construction-only). */
28
- export interface PositiveIntSchema extends BrandedNumberSchemaWithConstructorDefault<PositiveInt> {}
25
+ export interface PositiveIntSchema extends BrandedSchema<S.Int, PositiveInt> {
26
+ (i: number, options?: SchemaAST.ParseOptions): PositiveInt
27
+ readonly withConstructorDefault: S.withConstructorDefault<BrandedSchema<S.Int, PositiveInt>>
28
+ }
29
29
  export const PositiveInt: PositiveIntSchema = extendM(
30
30
  S.Int.pipe(
31
31
  S.check(S.isGreaterThan(0)),
@@ -41,11 +41,14 @@ export const PositiveInt: PositiveIntSchema = extendM(
41
41
  withConstructorDefault: s.pipe(S.withConstructorDefault(Effect.sync(() => s(1))))
42
42
  })
43
43
  )
44
- export type PositiveInt = number & PositiveIntBrand
45
44
 
46
45
  export interface NonNegativeIntBrand extends Simplify<B.Brand<"NonNegativeInt"> & IntBrand & NonNegativeNumberBrand> {}
46
+ export type NonNegativeInt = number & NonNegativeIntBrand
47
47
  /** Non-negative integer. `.withConstructorDefault` => `0` (construction-only). */
48
- export interface NonNegativeIntSchema extends BrandedNumberSchemaWithConstructorDefault<NonNegativeInt> {}
48
+ export interface NonNegativeIntSchema extends BrandedSchema<S.Int, NonNegativeInt> {
49
+ (i: number, options?: SchemaAST.ParseOptions): NonNegativeInt
50
+ readonly withConstructorDefault: S.withConstructorDefault<BrandedSchema<S.Int, NonNegativeInt>>
51
+ }
49
52
  export const NonNegativeInt: NonNegativeIntSchema = extendM(
50
53
  S.Int.pipe(
51
54
  S.check(S.isGreaterThanOrEqualTo(0)),
@@ -64,11 +67,14 @@ export const NonNegativeInt: NonNegativeIntSchema = extendM(
64
67
  withConstructorDefault: s.pipe(S.withConstructorDefault(Effect.sync(() => s(0))))
65
68
  })
66
69
  )
67
- export type NonNegativeInt = number & NonNegativeIntBrand
68
70
 
69
71
  export interface IntBrand extends Simplify<B.Brand<"Int">> {}
72
+ export type Int = number & IntBrand
70
73
  /** Integer. `.withConstructorDefault` => `0` (construction-only). */
71
- export interface IntSchema extends BrandedNumberSchemaWithConstructorDefault<Int> {}
74
+ export interface IntSchema extends BrandedSchema<S.Int, Int> {
75
+ (i: number, options?: SchemaAST.ParseOptions): Int
76
+ readonly withConstructorDefault: S.withConstructorDefault<BrandedSchema<S.Int, Int>>
77
+ }
72
78
  export const Int: IntSchema = extendM(
73
79
  S.Int.pipe(fromBrand<Int>(nominal<Int>(), { identifier: "Int", jsonSchema: {} }), withDefaultMake),
74
80
  (s) => ({
@@ -80,11 +86,14 @@ export const Int: IntSchema = extendM(
80
86
  withConstructorDefault: s.pipe(S.withConstructorDefault(Effect.sync(() => s(0))))
81
87
  })
82
88
  )
83
- export type Int = number & IntBrand
84
89
 
85
90
  export interface PositiveNumberBrand extends Simplify<B.Brand<"PositiveNumber"> & NonNegativeNumberBrand> {}
91
+ export type PositiveNumber = number & PositiveNumberBrand
86
92
  /** Positive finite number. `.withConstructorDefault` => `1` (construction-only). */
87
- export interface PositiveNumberSchema extends BrandedNumberSchemaWithConstructorDefault<PositiveNumber> {}
93
+ export interface PositiveNumberSchema extends BrandedSchema<S.Finite, PositiveNumber> {
94
+ (i: number, options?: SchemaAST.ParseOptions): PositiveNumber
95
+ readonly withConstructorDefault: S.withConstructorDefault<BrandedSchema<S.Finite, PositiveNumber>>
96
+ }
88
97
  export const PositiveNumber: PositiveNumberSchema = extendM(
89
98
  S.Finite.pipe(
90
99
  S.check(S.isGreaterThan(0)),
@@ -103,11 +112,14 @@ export const PositiveNumber: PositiveNumberSchema = extendM(
103
112
  withConstructorDefault: s.pipe(S.withConstructorDefault(Effect.sync(() => s(1))))
104
113
  })
105
114
  )
106
- export type PositiveNumber = number & PositiveNumberBrand
107
115
 
108
116
  export interface NonNegativeNumberBrand extends Simplify<B.Brand<"NonNegativeNumber">> {}
117
+ export type NonNegativeNumber = number & NonNegativeNumberBrand
109
118
  /** Non-negative finite number. `.withConstructorDefault` => `0` (construction-only). */
110
- export interface NonNegativeNumberSchema extends BrandedNumberSchemaWithConstructorDefault<NonNegativeNumber> {}
119
+ export interface NonNegativeNumberSchema extends BrandedSchema<S.Finite, NonNegativeNumber> {
120
+ (i: number, options?: SchemaAST.ParseOptions): NonNegativeNumber
121
+ readonly withConstructorDefault: S.withConstructorDefault<BrandedSchema<S.Finite, NonNegativeNumber>>
122
+ }
111
123
  export const NonNegativeNumber: NonNegativeNumberSchema = extendM(
112
124
  S
113
125
  .Finite
@@ -128,7 +140,6 @@ export const NonNegativeNumber: NonNegativeNumberSchema = extendM(
128
140
  withConstructorDefault: s.pipe(S.withConstructorDefault(Effect.sync(() => s(0))))
129
141
  })
130
142
  )
131
- export type NonNegativeNumber = number & NonNegativeNumberBrand
132
143
 
133
144
  /** @deprecated Not an actual decimal */
134
145
  export const NonNegativeDecimal = NonNegativeNumber
@@ -1,14 +1,15 @@
1
1
  import type * as B from "effect/Brand"
2
2
  import * as S from "effect/Schema"
3
+ import type * as SchemaAST from "effect/SchemaAST"
3
4
  import type { Simplify } from "effect/Types"
4
- import { fromBrand, nominal } from "./brand.js"
5
- import { withDefaultMake, type WithDefaults } from "./ext.js"
6
-
7
- type BrandedStringSchema<A extends string> = S.Codec<A, string> & WithDefaults<S.Codec<A, string>>
5
+ import { type BrandedSchema, fromBrand, nominal } from "./brand.js"
6
+ import { withDefaultMake } from "./ext.js"
8
7
 
9
8
  export type NonEmptyStringBrand = B.Brand<"NonEmptyString">
10
9
  export type NonEmptyString = string & NonEmptyStringBrand
11
- export interface NonEmptyStringSchema extends BrandedStringSchema<NonEmptyString> {}
10
+ export interface NonEmptyStringSchema extends BrandedSchema<S.NonEmptyString, NonEmptyString> {
11
+ (i: string, options?: SchemaAST.ParseOptions): NonEmptyString
12
+ }
12
13
  export const NonEmptyString: NonEmptyStringSchema = S
13
14
  .NonEmptyString
14
15
  .pipe(
@@ -21,7 +22,9 @@ export const NonEmptyString: NonEmptyStringSchema = S
21
22
 
22
23
  export interface NonEmptyString64kBrand extends Simplify<B.Brand<"NonEmptyString64k"> & NonEmptyStringBrand> {}
23
24
  export type NonEmptyString64k = string & NonEmptyString64kBrand
24
- export interface NonEmptyString64kSchema extends BrandedStringSchema<NonEmptyString64k> {}
25
+ export interface NonEmptyString64kSchema extends BrandedSchema<S.NonEmptyString, NonEmptyString64k> {
26
+ (i: string, options?: SchemaAST.ParseOptions): NonEmptyString64k
27
+ }
25
28
  export const NonEmptyString64k: NonEmptyString64kSchema = S
26
29
  .NonEmptyString
27
30
  .pipe(
@@ -35,7 +38,9 @@ export const NonEmptyString64k: NonEmptyString64kSchema = S
35
38
 
36
39
  export interface NonEmptyString2kBrand extends Simplify<B.Brand<"NonEmptyString2k"> & NonEmptyString64kBrand> {}
37
40
  export type NonEmptyString2k = string & NonEmptyString2kBrand
38
- export interface NonEmptyString2kSchema extends BrandedStringSchema<NonEmptyString2k> {}
41
+ export interface NonEmptyString2kSchema extends BrandedSchema<S.NonEmptyString, NonEmptyString2k> {
42
+ (i: string, options?: SchemaAST.ParseOptions): NonEmptyString2k
43
+ }
39
44
  export const NonEmptyString2k: NonEmptyString2kSchema = S
40
45
  .NonEmptyString
41
46
  .pipe(
@@ -49,7 +54,9 @@ export const NonEmptyString2k: NonEmptyString2kSchema = S
49
54
 
50
55
  export interface NonEmptyString255Brand extends Simplify<B.Brand<"NonEmptyString255"> & NonEmptyString2kBrand> {}
51
56
  export type NonEmptyString255 = string & NonEmptyString255Brand
52
- export interface NonEmptyString255Schema extends BrandedStringSchema<NonEmptyString255> {}
57
+ export interface NonEmptyString255Schema extends BrandedSchema<S.NonEmptyString, NonEmptyString255> {
58
+ (i: string, options?: SchemaAST.ParseOptions): NonEmptyString255
59
+ }
53
60
  export const NonEmptyString255: NonEmptyString255Schema = S
54
61
  .NonEmptyString
55
62
  .pipe(
package/src/ids.ts CHANGED
@@ -24,7 +24,12 @@ export const RequestId = extendM(
24
24
  Object
25
25
  .assign(Object.create(NonEmptyString255) as {}, NonEmptyString255 as unknown as Codec<NonEmptyString255, string>),
26
26
  (s) => {
27
- const make = StringId.make as () => NonEmptyString255
27
+ function make(): NonEmptyString255
28
+ function make(input: string, options?: S.MakeOptions): NonEmptyString255
29
+ function make(input?: string, options?: S.MakeOptions): NonEmptyString255 {
30
+ const id = input === undefined ? StringId.make() : StringId.make(input, options)
31
+ return id as NonEmptyString255
32
+ }
28
33
  return ({
29
34
  make,
30
35
  /**