effect-app 4.0.0-beta.2 → 4.0.0-beta.200
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/CHANGELOG.md +960 -0
- package/dist/Array.d.ts +1 -1
- package/dist/Chunk.d.ts +1 -1
- package/dist/Chunk.d.ts.map +1 -1
- package/dist/Config/SecretURL.d.ts +1 -1
- package/dist/Config/SecretURL.d.ts.map +1 -1
- package/dist/Config/SecretURL.js +2 -2
- package/dist/Config/internal/configSecretURL.d.ts +1 -1
- package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
- package/dist/Config.d.ts +7 -0
- package/dist/Config.d.ts.map +1 -0
- package/dist/Config.js +6 -0
- package/dist/ConfigProvider.d.ts +39 -0
- package/dist/ConfigProvider.d.ts.map +1 -0
- package/dist/ConfigProvider.js +42 -0
- package/dist/Context.d.ts +40 -0
- package/dist/Context.d.ts.map +1 -0
- package/dist/Context.js +67 -0
- package/dist/Effect.d.ts +9 -10
- package/dist/Effect.d.ts.map +1 -1
- package/dist/Effect.js +3 -6
- package/dist/Function.d.ts +1 -1
- package/dist/Function.d.ts.map +1 -1
- package/dist/Inputify.type.d.ts +1 -1
- package/dist/Layer.d.ts +7 -6
- package/dist/Layer.d.ts.map +1 -1
- package/dist/Layer.js +1 -1
- package/dist/NonEmptySet.d.ts +1 -1
- package/dist/NonEmptySet.d.ts.map +1 -1
- package/dist/Option.d.ts +1 -1
- package/dist/Option.d.ts.map +1 -1
- package/dist/Pure.d.ts +5 -5
- package/dist/Pure.d.ts.map +1 -1
- package/dist/Pure.js +13 -13
- package/dist/Schema/Class.d.ts +66 -20
- package/dist/Schema/Class.d.ts.map +1 -1
- package/dist/Schema/Class.js +189 -22
- package/dist/Schema/FastCheck.d.ts +1 -1
- package/dist/Schema/FastCheck.d.ts.map +1 -1
- package/dist/Schema/Methods.d.ts +1 -1
- package/dist/Schema/SchemaParser.d.ts +5 -0
- package/dist/Schema/SchemaParser.d.ts.map +1 -0
- package/dist/Schema/SchemaParser.js +6 -0
- package/dist/Schema/SpecialJsonSchema.d.ts +33 -0
- package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -0
- package/dist/Schema/SpecialJsonSchema.js +122 -0
- package/dist/Schema/SpecialOpenApi.d.ts +32 -0
- package/dist/Schema/SpecialOpenApi.d.ts.map +1 -0
- package/dist/Schema/SpecialOpenApi.js +123 -0
- package/dist/Schema/brand.d.ts +14 -6
- package/dist/Schema/brand.d.ts.map +1 -1
- package/dist/Schema/brand.js +1 -1
- package/dist/Schema/email.d.ts +1 -1
- package/dist/Schema/email.d.ts.map +1 -1
- package/dist/Schema/email.js +9 -5
- package/dist/Schema/ext.d.ts +121 -48
- package/dist/Schema/ext.d.ts.map +1 -1
- package/dist/Schema/ext.js +134 -52
- package/dist/Schema/moreStrings.d.ts +117 -17
- package/dist/Schema/moreStrings.d.ts.map +1 -1
- package/dist/Schema/moreStrings.js +19 -18
- package/dist/Schema/numbers.d.ts +127 -15
- package/dist/Schema/numbers.d.ts.map +1 -1
- package/dist/Schema/numbers.js +10 -12
- package/dist/Schema/phoneNumber.d.ts +1 -1
- package/dist/Schema/phoneNumber.d.ts.map +1 -1
- package/dist/Schema/phoneNumber.js +8 -4
- package/dist/Schema/schema.d.ts +1 -1
- package/dist/Schema/strings.d.ts +37 -5
- package/dist/Schema/strings.d.ts.map +1 -1
- package/dist/Schema/strings.js +1 -5
- package/dist/Schema.d.ts +159 -58
- package/dist/Schema.d.ts.map +1 -1
- package/dist/Schema.js +136 -68
- package/dist/Set.d.ts +1 -1
- package/dist/Set.d.ts.map +1 -1
- package/dist/TypeTest.d.ts +1 -1
- package/dist/Types.d.ts +1 -1
- package/dist/Widen.type.d.ts +1 -1
- package/dist/_ext/Array.d.ts +1 -1
- package/dist/_ext/Array.d.ts.map +1 -1
- package/dist/_ext/date.d.ts +1 -1
- package/dist/_ext/misc.d.ts +1 -1
- package/dist/_ext/ord.ext.d.ts +1 -1
- package/dist/_ext/ord.ext.d.ts.map +1 -1
- package/dist/builtin.d.ts +1 -1
- package/dist/builtin.d.ts.map +1 -1
- package/dist/client/InvalidationKeys.d.ts +29 -0
- package/dist/client/InvalidationKeys.d.ts.map +1 -0
- package/dist/client/InvalidationKeys.js +33 -0
- package/dist/client/apiClientFactory.d.ts +18 -32
- package/dist/client/apiClientFactory.d.ts.map +1 -1
- package/dist/client/apiClientFactory.js +98 -36
- package/dist/client/clientFor.d.ts +51 -17
- package/dist/client/clientFor.d.ts.map +1 -1
- package/dist/client/clientFor.js +9 -1
- package/dist/client/errors.d.ts +49 -25
- package/dist/client/errors.d.ts.map +1 -1
- package/dist/client/errors.js +43 -17
- package/dist/client/makeClient.d.ts +468 -32
- package/dist/client/makeClient.d.ts.map +1 -1
- package/dist/client/makeClient.js +61 -34
- package/dist/client.d.ts +2 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -1
- package/dist/faker.d.ts +1 -1
- package/dist/faker.d.ts.map +1 -1
- package/dist/http/Request.d.ts +2 -2
- package/dist/http/Request.d.ts.map +1 -1
- package/dist/http/Request.js +5 -5
- package/dist/http/internal/lib.d.ts +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/ids.d.ts +9 -9
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +3 -2
- package/dist/index.d.ts +5 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -9
- package/dist/logger.d.ts +1 -1
- package/dist/middleware.d.ts +16 -9
- package/dist/middleware.d.ts.map +1 -1
- package/dist/middleware.js +13 -9
- package/dist/rpc/Invalidation.d.ts +397 -0
- package/dist/rpc/Invalidation.d.ts.map +1 -0
- package/dist/rpc/Invalidation.js +150 -0
- package/dist/rpc/MiddlewareMaker.d.ts +6 -5
- package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
- package/dist/rpc/MiddlewareMaker.js +51 -28
- package/dist/rpc/RpcContextMap.d.ts +3 -3
- package/dist/rpc/RpcContextMap.d.ts.map +1 -1
- package/dist/rpc/RpcContextMap.js +4 -4
- package/dist/rpc/RpcMiddleware.d.ts +6 -5
- package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/rpc/RpcMiddleware.js +1 -1
- package/dist/rpc.d.ts +2 -2
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +2 -2
- package/dist/transform.d.ts +1 -1
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +3 -3
- package/dist/utils/effectify.d.ts +1 -1
- package/dist/utils/extend.d.ts +1 -1
- package/dist/utils/extend.d.ts.map +1 -1
- package/dist/utils/gen.d.ts +2 -2
- package/dist/utils/gen.d.ts.map +1 -1
- package/dist/utils/logLevel.d.ts +2 -2
- package/dist/utils/logLevel.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +3 -3
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +3 -3
- package/dist/utils.d.ts +48 -10
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +33 -8
- package/dist/validation/validators.d.ts +1 -1
- package/dist/validation/validators.d.ts.map +1 -1
- package/dist/validation.d.ts +1 -1
- package/dist/validation.d.ts.map +1 -1
- package/package.json +46 -28
- package/src/Config/SecretURL.ts +2 -1
- package/src/Config.ts +14 -0
- package/src/ConfigProvider.ts +48 -0
- package/src/{ServiceMap.ts → Context.ts} +58 -64
- package/src/Effect.ts +12 -14
- package/src/Layer.ts +6 -5
- package/src/Pure.ts +17 -18
- package/src/Schema/Class.ts +268 -62
- package/src/Schema/SchemaParser.ts +12 -0
- package/src/Schema/SpecialJsonSchema.ts +137 -0
- package/src/Schema/SpecialOpenApi.ts +130 -0
- package/src/Schema/brand.ts +21 -7
- package/src/Schema/email.ts +10 -3
- package/src/Schema/ext.ts +226 -86
- package/src/Schema/moreStrings.ts +37 -32
- package/src/Schema/numbers.ts +14 -16
- package/src/Schema/phoneNumber.ts +8 -2
- package/src/Schema/strings.ts +4 -8
- package/src/Schema.ts +350 -107
- package/src/client/InvalidationKeys.ts +50 -0
- package/src/client/apiClientFactory.ts +227 -136
- package/src/client/clientFor.ts +86 -29
- package/src/client/errors.ts +61 -26
- package/src/client/makeClient.ts +530 -80
- package/src/client.ts +1 -0
- package/src/http/Request.ts +7 -4
- package/src/ids.ts +3 -2
- package/src/index.ts +5 -11
- package/src/middleware.ts +12 -10
- package/src/rpc/Invalidation.ts +221 -0
- package/src/rpc/MiddlewareMaker.ts +61 -51
- package/src/rpc/README.md +2 -2
- package/src/rpc/RpcContextMap.ts +6 -5
- package/src/rpc/RpcMiddleware.ts +6 -5
- package/src/rpc.ts +1 -1
- package/src/transform.ts +2 -2
- package/src/utils/gen.ts +1 -1
- package/src/utils/logger.ts +2 -2
- package/src/utils.ts +73 -15
- package/test/dist/moreStrings.test.d.ts.map +1 -0
- package/test/dist/rpc.test.d.ts.map +1 -1
- package/test/dist/secretURL.test.d.ts.map +1 -0
- package/test/dist/special.test.d.ts.map +1 -0
- package/test/moreStrings.test.ts +17 -0
- package/test/rpc.test.ts +38 -6
- package/test/schema.test.ts +609 -4
- package/test/secretURL.test.ts +157 -0
- package/test/special.test.ts +1023 -0
- package/test/utils.test.ts +6 -6
- package/tsconfig.base.json +3 -4
- package/tsconfig.json +0 -1
- package/tsconfig.json.bak +2 -2
- package/tsconfig.src.json +29 -29
- package/tsconfig.test.json +2 -2
- package/dist/Operations.d.ts +0 -87
- package/dist/Operations.d.ts.map +0 -1
- package/dist/Operations.js +0 -29
- package/dist/ServiceMap.d.ts +0 -44
- package/dist/ServiceMap.d.ts.map +0 -1
- package/dist/ServiceMap.js +0 -91
- package/dist/Struct.d.ts +0 -44
- package/dist/Struct.d.ts.map +0 -1
- package/dist/Struct.js +0 -29
- package/eslint.config.mjs +0 -26
- package/src/Operations.ts +0 -55
- package/src/Struct.ts +0 -54
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { pipe } from "effect"
|
|
1
|
+
import { Effect, pipe } from "effect"
|
|
2
2
|
import type { Refinement } from "effect-app/Function"
|
|
3
3
|
import { extendM } from "effect-app/utils"
|
|
4
4
|
import * as S from "effect/Schema"
|
|
@@ -6,7 +6,7 @@ import type { Simplify } from "effect/Types"
|
|
|
6
6
|
import { customRandom, nanoid, urlAlphabet } from "nanoid"
|
|
7
7
|
import validator from "validator"
|
|
8
8
|
import { fromBrand, nominal } from "./brand.js"
|
|
9
|
-
import {
|
|
9
|
+
import { withDefaultMake, type WithDefaults } from "./ext.js"
|
|
10
10
|
import { type B } from "./schema.js"
|
|
11
11
|
import type { NonEmptyString255Brand, NonEmptyStringBrand } from "./strings.js"
|
|
12
12
|
|
|
@@ -27,9 +27,8 @@ export type NonEmptyString50 = string & NonEmptyString50Brand
|
|
|
27
27
|
*/
|
|
28
28
|
export const NonEmptyString50 = nonEmptyString.pipe(
|
|
29
29
|
S.check(S.isMaxLength(50)),
|
|
30
|
-
fromBrand(nominal<NonEmptyString50>(), {
|
|
30
|
+
fromBrand<NonEmptyString50>(nominal<NonEmptyString50>(), {
|
|
31
31
|
identifier: "NonEmptyString50",
|
|
32
|
-
title: "NonEmptyString50",
|
|
33
32
|
jsonSchema: {}
|
|
34
33
|
}),
|
|
35
34
|
withDefaultMake
|
|
@@ -50,9 +49,8 @@ export type NonEmptyString64 = string & NonEmptyString64Brand
|
|
|
50
49
|
*/
|
|
51
50
|
export const NonEmptyString64 = nonEmptyString.pipe(
|
|
52
51
|
S.check(S.isMaxLength(64)),
|
|
53
|
-
fromBrand(nominal<NonEmptyString64>(), {
|
|
52
|
+
fromBrand<NonEmptyString64>(nominal<NonEmptyString64>(), {
|
|
54
53
|
identifier: "NonEmptyString64",
|
|
55
|
-
title: "NonEmptyString64",
|
|
56
54
|
jsonSchema: {}
|
|
57
55
|
}),
|
|
58
56
|
withDefaultMake
|
|
@@ -74,9 +72,8 @@ export type NonEmptyString80 = string & NonEmptyString80Brand
|
|
|
74
72
|
|
|
75
73
|
export const NonEmptyString80 = nonEmptyString.pipe(
|
|
76
74
|
S.check(S.isMaxLength(80)),
|
|
77
|
-
fromBrand(nominal<NonEmptyString80>(), {
|
|
75
|
+
fromBrand<NonEmptyString80>(nominal<NonEmptyString80>(), {
|
|
78
76
|
identifier: "NonEmptyString80",
|
|
79
|
-
title: "NonEmptyString80",
|
|
80
77
|
jsonSchema: {}
|
|
81
78
|
}),
|
|
82
79
|
withDefaultMake
|
|
@@ -97,9 +94,8 @@ export type NonEmptyString100 = string & NonEmptyString100Brand
|
|
|
97
94
|
*/
|
|
98
95
|
export const NonEmptyString100 = nonEmptyString.pipe(
|
|
99
96
|
S.check(S.isMaxLength(100)),
|
|
100
|
-
fromBrand(nominal<NonEmptyString100>(), {
|
|
97
|
+
fromBrand<NonEmptyString100>(nominal<NonEmptyString100>(), {
|
|
101
98
|
identifier: "NonEmptyString100",
|
|
102
|
-
title: "NonEmptyString100",
|
|
103
99
|
jsonSchema: {}
|
|
104
100
|
}),
|
|
105
101
|
withDefaultMake
|
|
@@ -121,7 +117,10 @@ export type Min3String255 = string & Min3String255Brand
|
|
|
121
117
|
export const Min3String255 = pipe(
|
|
122
118
|
S.String,
|
|
123
119
|
S.check(S.isMinLength(3), S.isMaxLength(255)),
|
|
124
|
-
fromBrand(nominal<Min3String255>(), {
|
|
120
|
+
fromBrand<Min3String255>(nominal<Min3String255>(), {
|
|
121
|
+
identifier: "Min3String255",
|
|
122
|
+
jsonSchema: {}
|
|
123
|
+
}),
|
|
125
124
|
withDefaultMake
|
|
126
125
|
)
|
|
127
126
|
|
|
@@ -140,11 +139,10 @@ const minLength = 6
|
|
|
140
139
|
const maxLength = 50
|
|
141
140
|
const size = 21
|
|
142
141
|
const length = 10 * size
|
|
143
|
-
const StringIdArb = ():
|
|
142
|
+
const StringIdArb = (): S.LazyArbitrary<StringId> => (fc) =>
|
|
144
143
|
fc
|
|
145
144
|
.uint8Array({ minLength: length, maxLength: length })
|
|
146
|
-
.map((_
|
|
147
|
-
|
|
145
|
+
.map((_) => customRandom(urlAlphabet, size, (size) => _.subarray(0, size))() as StringId)
|
|
148
146
|
/**
|
|
149
147
|
* A string that is at least 6 characters long and a maximum of 50.
|
|
150
148
|
*/
|
|
@@ -152,16 +150,15 @@ export const StringId = extendM(
|
|
|
152
150
|
pipe(
|
|
153
151
|
S.String,
|
|
154
152
|
S.check(S.isMinLength(minLength), S.isMaxLength(maxLength)),
|
|
155
|
-
fromBrand(nominal<StringId>(), {
|
|
153
|
+
fromBrand<StringId>(nominal<StringId>(), {
|
|
156
154
|
identifier: "StringId",
|
|
157
|
-
|
|
158
|
-
arbitrary: StringIdArb,
|
|
155
|
+
toArbitrary: () => (fc) => StringIdArb()(fc),
|
|
159
156
|
jsonSchema: {}
|
|
160
157
|
})
|
|
161
158
|
),
|
|
162
159
|
(s) => ({
|
|
163
160
|
make: makeStringId,
|
|
164
|
-
withDefault: s.pipe(
|
|
161
|
+
withDefault: s.pipe(S.withConstructorDefault(Effect.sync(makeStringId)))
|
|
165
162
|
})
|
|
166
163
|
)
|
|
167
164
|
.pipe(withDefaultMake)
|
|
@@ -178,19 +175,20 @@ export function prefixedStringId<Brand extends StringId>() {
|
|
|
178
175
|
) => {
|
|
179
176
|
type FullPrefix = `${Prefix}${Separator}`
|
|
180
177
|
const pref = `${prefix}${separator ?? "-"}` as FullPrefix
|
|
181
|
-
const arb = ():
|
|
178
|
+
const arb = (): S.LazyArbitrary<string & Brand> => (fc) =>
|
|
182
179
|
StringIdArb()(fc).map(
|
|
183
|
-
(x
|
|
180
|
+
(x) => (pref + x.substring(0, 50 - pref.length)) as Brand
|
|
184
181
|
)
|
|
185
182
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
186
|
-
const s
|
|
183
|
+
const s = StringId
|
|
187
184
|
.pipe(
|
|
188
185
|
S.refine((x: string): x is string & Brand => x.startsWith(pref), {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
186
|
+
identifier: name
|
|
187
|
+
}),
|
|
188
|
+
S.annotate({
|
|
189
|
+
toArbitrary: () => (fc) => arb()(fc)
|
|
192
190
|
})
|
|
193
|
-
)
|
|
191
|
+
)
|
|
194
192
|
const schema = s.pipe(withDefaultMake)
|
|
195
193
|
const make = () => (pref + StringId.make().substring(0, 50 - pref.length)) as Brand
|
|
196
194
|
|
|
@@ -207,7 +205,9 @@ export function prefixedStringId<Brand extends StringId>() {
|
|
|
207
205
|
*/
|
|
208
206
|
prefixSafe: <REST extends string>(str: `${Prefix}${Separator}${REST}`) => ex(str),
|
|
209
207
|
prefix,
|
|
210
|
-
withDefault: schema.pipe(
|
|
208
|
+
withDefault: schema.pipe(S.withConstructorDefault<S.Codec<Brand, string> & S.WithoutConstructorDefault>(
|
|
209
|
+
Effect.sync(make)
|
|
210
|
+
))
|
|
211
211
|
})
|
|
212
212
|
)
|
|
213
213
|
}
|
|
@@ -217,10 +217,10 @@ export const brandedStringId = <
|
|
|
217
217
|
Brand extends StringIdBrand
|
|
218
218
|
>() =>
|
|
219
219
|
withDefaultMake(
|
|
220
|
-
Object.assign(Object.create(StringId), StringId) as S.Codec<string & Brand> & {
|
|
220
|
+
Object.assign(Object.create(StringId), StringId) as S.Codec<string & Brand, string> & {
|
|
221
221
|
make: () => string & Brand
|
|
222
|
-
withDefault:
|
|
223
|
-
} & WithDefaults<S.Codec<string & Brand>>
|
|
222
|
+
withDefault: S.withConstructorDefault<S.Codec<string & Brand, string> & S.WithoutConstructorDefault>
|
|
223
|
+
} & WithDefaults<S.Codec<string & Brand, string>>
|
|
224
224
|
)
|
|
225
225
|
|
|
226
226
|
export interface PrefixedStringUtils<
|
|
@@ -232,7 +232,7 @@ export interface PrefixedStringUtils<
|
|
|
232
232
|
readonly unsafeFrom: (str: string) => Brand
|
|
233
233
|
prefixSafe: <REST extends string>(str: `${Prefix}${Separator}${REST}`) => Brand
|
|
234
234
|
readonly prefix: Prefix
|
|
235
|
-
readonly withDefault:
|
|
235
|
+
readonly withDefault: S.withConstructorDefault<S.Codec<Brand, string> & S.WithoutConstructorDefault>
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
export interface UrlBrand extends Simplify<B.Brand<"Url"> & NonEmptyStringBrand> {}
|
|
@@ -246,11 +246,16 @@ const isUrl: Refinement<string, Url> = (s: string): s is Url => {
|
|
|
246
246
|
export const Url = S
|
|
247
247
|
.String
|
|
248
248
|
.pipe(
|
|
249
|
+
S.annotate({
|
|
250
|
+
title: "Url",
|
|
251
|
+
format: "uri"
|
|
252
|
+
}),
|
|
249
253
|
S.refine(isUrl, {
|
|
250
|
-
arbitrary: (): any => (fc: any) => fc.webUrl().map((_: any) => _ as Url),
|
|
251
254
|
identifier: "Url",
|
|
252
|
-
title: "Url",
|
|
253
255
|
jsonSchema: { format: "uri" }
|
|
254
256
|
}),
|
|
257
|
+
S.annotate({
|
|
258
|
+
toArbitrary: () => (fc) => fc.webUrl().map((_) => _ as Url)
|
|
259
|
+
}),
|
|
255
260
|
withDefaultMake
|
|
256
261
|
)
|
package/src/Schema/numbers.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { Effect } from "effect"
|
|
1
2
|
import { extendM } from "effect-app/utils"
|
|
2
3
|
import * as S from "effect/Schema"
|
|
3
4
|
import type { Simplify } from "effect/Types"
|
|
4
5
|
import { fromBrand, nominal } from "./brand.js"
|
|
5
|
-
import {
|
|
6
|
+
import { withDefaultMake } from "./ext.js"
|
|
6
7
|
import { type B } from "./schema.js"
|
|
7
8
|
|
|
8
9
|
export interface PositiveIntBrand
|
|
@@ -11,10 +12,10 @@ export interface PositiveIntBrand
|
|
|
11
12
|
export const PositiveInt = extendM(
|
|
12
13
|
S.Int.pipe(
|
|
13
14
|
S.check(S.isGreaterThan(0)),
|
|
14
|
-
fromBrand(nominal<PositiveInt>(), { identifier: "PositiveInt",
|
|
15
|
+
fromBrand<PositiveInt>(nominal<PositiveInt>(), { identifier: "PositiveInt", jsonSchema: {} }),
|
|
15
16
|
withDefaultMake
|
|
16
17
|
),
|
|
17
|
-
(s) => ({ withDefault: s.pipe(
|
|
18
|
+
(s) => ({ withDefault: s.pipe(S.withConstructorDefault(Effect.sync(() => s(1)))) })
|
|
18
19
|
)
|
|
19
20
|
export type PositiveInt = number & PositiveIntBrand
|
|
20
21
|
|
|
@@ -22,53 +23,50 @@ export interface NonNegativeIntBrand extends Simplify<B.Brand<"NonNegativeInt">
|
|
|
22
23
|
export const NonNegativeInt = extendM(
|
|
23
24
|
S.Int.pipe(
|
|
24
25
|
S.check(S.isGreaterThanOrEqualTo(0)),
|
|
25
|
-
fromBrand(nominal<NonNegativeInt>(), {
|
|
26
|
+
fromBrand<NonNegativeInt>(nominal<NonNegativeInt>(), {
|
|
26
27
|
identifier: "NonNegativeInt",
|
|
27
|
-
title: "NonNegativeInt",
|
|
28
28
|
jsonSchema: {}
|
|
29
29
|
}),
|
|
30
30
|
withDefaultMake
|
|
31
31
|
),
|
|
32
|
-
(s) => ({ withDefault: s.pipe(
|
|
32
|
+
(s) => ({ withDefault: s.pipe(S.withConstructorDefault(Effect.sync(() => s(0)))) })
|
|
33
33
|
)
|
|
34
34
|
export type NonNegativeInt = number & NonNegativeIntBrand
|
|
35
35
|
|
|
36
36
|
export interface IntBrand extends Simplify<B.Brand<"Int">> {}
|
|
37
37
|
export const Int = extendM(
|
|
38
|
-
S.Int.pipe(fromBrand(nominal<Int>(), { identifier: "Int",
|
|
39
|
-
(s) => ({ withDefault: s.pipe(
|
|
38
|
+
S.Int.pipe(fromBrand<Int>(nominal<Int>(), { identifier: "Int", jsonSchema: {} }), withDefaultMake),
|
|
39
|
+
(s) => ({ withDefault: s.pipe(S.withConstructorDefault(Effect.sync(() => s(0)))) })
|
|
40
40
|
)
|
|
41
41
|
export type Int = number & IntBrand
|
|
42
42
|
|
|
43
43
|
export interface PositiveNumberBrand extends Simplify<B.Brand<"PositiveNumber"> & NonNegativeNumberBrand> {}
|
|
44
44
|
export const PositiveNumber = extendM(
|
|
45
|
-
S.
|
|
45
|
+
S.Finite.pipe(
|
|
46
46
|
S.check(S.isGreaterThan(0)),
|
|
47
|
-
fromBrand(nominal<PositiveNumber>(), {
|
|
47
|
+
fromBrand<PositiveNumber>(nominal<PositiveNumber>(), {
|
|
48
48
|
identifier: "PositiveNumber",
|
|
49
|
-
title: "PositiveNumber",
|
|
50
49
|
jsonSchema: {}
|
|
51
50
|
}),
|
|
52
51
|
withDefaultMake
|
|
53
52
|
),
|
|
54
|
-
(s) => ({ withDefault: s.pipe(
|
|
53
|
+
(s) => ({ withDefault: s.pipe(S.withConstructorDefault(Effect.sync(() => s(1)))) })
|
|
55
54
|
)
|
|
56
55
|
export type PositiveNumber = number & PositiveNumberBrand
|
|
57
56
|
|
|
58
57
|
export interface NonNegativeNumberBrand extends Simplify<B.Brand<"NonNegativeNumber">> {}
|
|
59
58
|
export const NonNegativeNumber = extendM(
|
|
60
59
|
S
|
|
61
|
-
.
|
|
60
|
+
.Finite
|
|
62
61
|
.pipe(
|
|
63
62
|
S.check(S.isGreaterThanOrEqualTo(0)),
|
|
64
|
-
fromBrand(nominal<NonNegativeNumber>(), {
|
|
63
|
+
fromBrand<NonNegativeNumber>(nominal<NonNegativeNumber>(), {
|
|
65
64
|
identifier: "NonNegativeNumber",
|
|
66
|
-
title: "NonNegativeNumber",
|
|
67
65
|
jsonSchema: {}
|
|
68
66
|
}),
|
|
69
67
|
withDefaultMake
|
|
70
68
|
),
|
|
71
|
-
(s) => ({ withDefault: s.pipe(
|
|
69
|
+
(s) => ({ withDefault: s.pipe(S.withConstructorDefault(Effect.sync(() => s(0)))) })
|
|
72
70
|
)
|
|
73
71
|
export type NonNegativeNumber = number & NonNegativeNumberBrand
|
|
74
72
|
|
|
@@ -13,12 +13,18 @@ export type PhoneNumber = string & PhoneNumberBrand
|
|
|
13
13
|
export const PhoneNumber = S
|
|
14
14
|
.String
|
|
15
15
|
.pipe(
|
|
16
|
+
S.annotate({
|
|
17
|
+
title: "PhoneNumber",
|
|
18
|
+
description: "a phone number with at least 7 digits",
|
|
19
|
+
format: "phone"
|
|
20
|
+
}),
|
|
16
21
|
S.refine(isValidPhone as Refinement<string, PhoneNumber>, {
|
|
17
22
|
identifier: "PhoneNumber",
|
|
18
|
-
title: "PhoneNumber",
|
|
19
23
|
description: "a phone number with at least 7 digits",
|
|
20
|
-
arbitrary: () => (fc: any) => Numbers(7, 10)(fc).map((_: any) => _ as PhoneNumber),
|
|
21
24
|
jsonSchema: { format: "phone" }
|
|
22
25
|
}),
|
|
26
|
+
S.annotate({
|
|
27
|
+
toArbitrary: () => (fc) => Numbers(7, 10)(fc).map((_) => _ as PhoneNumber)
|
|
28
|
+
}),
|
|
23
29
|
withDefaultMake
|
|
24
30
|
)
|
package/src/Schema/strings.ts
CHANGED
|
@@ -9,9 +9,8 @@ export type NonEmptyString = string & NonEmptyStringBrand
|
|
|
9
9
|
export const NonEmptyString = S
|
|
10
10
|
.NonEmptyString
|
|
11
11
|
.pipe(
|
|
12
|
-
fromBrand(nominal<NonEmptyString>(), {
|
|
12
|
+
fromBrand<NonEmptyString>(nominal<NonEmptyString>(), {
|
|
13
13
|
identifier: "NonEmptyString",
|
|
14
|
-
title: "NonEmptyString",
|
|
15
14
|
jsonSchema: {}
|
|
16
15
|
}),
|
|
17
16
|
withDefaultMake
|
|
@@ -23,9 +22,8 @@ export const NonEmptyString64k = S
|
|
|
23
22
|
.NonEmptyString
|
|
24
23
|
.pipe(
|
|
25
24
|
S.check(S.isMaxLength(64 * 1024)),
|
|
26
|
-
fromBrand(nominal<NonEmptyString64k>(), {
|
|
25
|
+
fromBrand<NonEmptyString64k>(nominal<NonEmptyString64k>(), {
|
|
27
26
|
identifier: "NonEmptyString64k",
|
|
28
|
-
title: "NonEmptyString64k",
|
|
29
27
|
jsonSchema: {}
|
|
30
28
|
}),
|
|
31
29
|
withDefaultMake
|
|
@@ -37,9 +35,8 @@ export const NonEmptyString2k = S
|
|
|
37
35
|
.NonEmptyString
|
|
38
36
|
.pipe(
|
|
39
37
|
S.check(S.isMaxLength(2 * 1024)),
|
|
40
|
-
fromBrand(nominal<NonEmptyString2k>(), {
|
|
38
|
+
fromBrand<NonEmptyString2k>(nominal<NonEmptyString2k>(), {
|
|
41
39
|
identifier: "NonEmptyString2k",
|
|
42
|
-
title: "NonEmptyString2k",
|
|
43
40
|
jsonSchema: {}
|
|
44
41
|
}),
|
|
45
42
|
withDefaultMake
|
|
@@ -51,9 +48,8 @@ export const NonEmptyString255 = S
|
|
|
51
48
|
.NonEmptyString
|
|
52
49
|
.pipe(
|
|
53
50
|
S.check(S.isMaxLength(255)),
|
|
54
|
-
fromBrand(nominal<NonEmptyString255>(), {
|
|
51
|
+
fromBrand<NonEmptyString255>(nominal<NonEmptyString255>(), {
|
|
55
52
|
identifier: "NonEmptyString255",
|
|
56
|
-
title: "NonEmptyString255",
|
|
57
53
|
jsonSchema: {}
|
|
58
54
|
}),
|
|
59
55
|
withDefaultMake
|