effect-app 0.152.0

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 (169) hide show
  1. package/.eslintrc.cjs +11 -0
  2. package/.prettierignore +6 -0
  3. package/CHANGELOG.md +4106 -0
  4. package/_cjs/Config/SecretURL.cjs +58 -0
  5. package/_cjs/Config/SecretURL.cjs.map +1 -0
  6. package/_cjs/Config/internal/configSecretURL.cjs +88 -0
  7. package/_cjs/Config/internal/configSecretURL.cjs.map +1 -0
  8. package/_cjs/Inputify.type.cjs +6 -0
  9. package/_cjs/Inputify.type.cjs.map +1 -0
  10. package/_cjs/Operations.cjs +76 -0
  11. package/_cjs/Operations.cjs.map +1 -0
  12. package/_cjs/Pure.cjs +201 -0
  13. package/_cjs/Pure.cjs.map +1 -0
  14. package/_cjs/Request.cjs +76 -0
  15. package/_cjs/Request.cjs.map +1 -0
  16. package/_cjs/Widen.type.cjs +6 -0
  17. package/_cjs/Widen.type.cjs.map +1 -0
  18. package/_cjs/_ext/date.cjs +64 -0
  19. package/_cjs/_ext/date.cjs.map +1 -0
  20. package/_cjs/_ext/misc.cjs +121 -0
  21. package/_cjs/_ext/misc.cjs.map +1 -0
  22. package/_cjs/_global.cjs +24 -0
  23. package/_cjs/_global.cjs.map +1 -0
  24. package/_cjs/_global.ext.cjs +5 -0
  25. package/_cjs/_global.ext.cjs.map +1 -0
  26. package/_cjs/_global.schema.cjs +4 -0
  27. package/_cjs/_global.schema.cjs.map +1 -0
  28. package/_cjs/client/QueryResult.cjs +116 -0
  29. package/_cjs/client/QueryResult.cjs.map +1 -0
  30. package/_cjs/client/clientFor.cjs +159 -0
  31. package/_cjs/client/clientFor.cjs.map +1 -0
  32. package/_cjs/client/config.cjs +21 -0
  33. package/_cjs/client/config.cjs.map +1 -0
  34. package/_cjs/client/errors.cjs +116 -0
  35. package/_cjs/client/errors.cjs.map +1 -0
  36. package/_cjs/client/fetch.cjs +178 -0
  37. package/_cjs/client/fetch.cjs.map +1 -0
  38. package/_cjs/client.cjs +61 -0
  39. package/_cjs/client.cjs.map +1 -0
  40. package/_cjs/faker.cjs +31 -0
  41. package/_cjs/faker.cjs.map +1 -0
  42. package/_cjs/ids.cjs +24 -0
  43. package/_cjs/ids.cjs.map +1 -0
  44. package/_cjs/index.cjs +27 -0
  45. package/_cjs/index.cjs.map +1 -0
  46. package/_cjs/refinements.cjs +97 -0
  47. package/_cjs/refinements.cjs.map +1 -0
  48. package/_cjs/schema.cjs +50 -0
  49. package/_cjs/schema.cjs.map +1 -0
  50. package/_cjs/schema.test.cjs +9 -0
  51. package/_cjs/schema.test.cjs.map +1 -0
  52. package/_cjs/service.cjs +97 -0
  53. package/_cjs/service.cjs.map +1 -0
  54. package/_cjs/utils.cjs +17 -0
  55. package/_cjs/utils.cjs.map +1 -0
  56. package/_src/Config/SecretURL.ts +103 -0
  57. package/_src/Config/internal/configSecretURL.ts +85 -0
  58. package/_src/Inputify.type.ts +13 -0
  59. package/_src/Operations.ts +70 -0
  60. package/_src/Pure.ts +525 -0
  61. package/_src/Request.ts +106 -0
  62. package/_src/Widen.type.ts +28 -0
  63. package/_src/_ext/date.ts +84 -0
  64. package/_src/_ext/misc.ts +161 -0
  65. package/_src/_global/stm.ts.bak +35 -0
  66. package/_src/_global.ext.ts +3 -0
  67. package/_src/_global.schema.ts +106 -0
  68. package/_src/_global.ts +119 -0
  69. package/_src/client/QueryResult.ts +120 -0
  70. package/_src/client/clientFor.ts +260 -0
  71. package/_src/client/config.ts +13 -0
  72. package/_src/client/errors.ts +129 -0
  73. package/_src/client/fetch.ts +253 -0
  74. package/_src/client.ts +7 -0
  75. package/_src/faker.ts +32 -0
  76. package/_src/ids.ts +35 -0
  77. package/_src/index.ts +4 -0
  78. package/_src/refinements.ts +92 -0
  79. package/_src/schema/_schema.ts.bak +208 -0
  80. package/_src/schema/api/date.ts.bak +78 -0
  81. package/_src/schema/api.ts.bak +20 -0
  82. package/_src/schema/overrides.ts.bak +76 -0
  83. package/_src/schema/shared.ts.bak +334 -0
  84. package/_src/schema.test.ts +3 -0
  85. package/_src/schema.ts +37 -0
  86. package/_src/service.ts +119 -0
  87. package/_src/utils.ts +1 -0
  88. package/dist/Config/SecretURL.d.ts +82 -0
  89. package/dist/Config/SecretURL.d.ts.map +1 -0
  90. package/dist/Config/SecretURL.js +49 -0
  91. package/dist/Config/internal/configSecretURL.d.ts +24 -0
  92. package/dist/Config/internal/configSecretURL.d.ts.map +1 -0
  93. package/dist/Config/internal/configSecretURL.js +75 -0
  94. package/dist/Inputify.type.d.ts +10 -0
  95. package/dist/Inputify.type.d.ts.map +1 -0
  96. package/dist/Inputify.type.js +2 -0
  97. package/dist/Operations.d.ts +170 -0
  98. package/dist/Operations.d.ts.map +1 -0
  99. package/dist/Operations.js +87 -0
  100. package/dist/Pure.d.ts +169 -0
  101. package/dist/Pure.d.ts.map +1 -0
  102. package/dist/Pure.js +167 -0
  103. package/dist/Request.d.ts +49 -0
  104. package/dist/Request.d.ts.map +1 -0
  105. package/dist/Request.js +58 -0
  106. package/dist/Widen.type.d.ts +19 -0
  107. package/dist/Widen.type.d.ts.map +1 -0
  108. package/dist/Widen.type.js +2 -0
  109. package/dist/_ext/date.d.ts +71 -0
  110. package/dist/_ext/date.d.ts.map +1 -0
  111. package/dist/_ext/date.js +58 -0
  112. package/dist/_ext/misc.d.ts +77 -0
  113. package/dist/_ext/misc.d.ts.map +1 -0
  114. package/dist/_ext/misc.js +98 -0
  115. package/dist/_global.d.ts +70 -0
  116. package/dist/_global.d.ts.map +1 -0
  117. package/dist/_global.ext.d.ts +3 -0
  118. package/dist/_global.ext.d.ts.map +1 -0
  119. package/dist/_global.ext.js +4 -0
  120. package/dist/_global.js +76 -0
  121. package/dist/_global.schema.d.ts +6 -0
  122. package/dist/_global.schema.d.ts.map +1 -0
  123. package/dist/_global.schema.js +6 -0
  124. package/dist/client/QueryResult.d.ts +85 -0
  125. package/dist/client/QueryResult.d.ts.map +1 -0
  126. package/dist/client/QueryResult.js +85 -0
  127. package/dist/client/clientFor.d.ts +44 -0
  128. package/dist/client/clientFor.d.ts.map +1 -0
  129. package/dist/client/clientFor.js +144 -0
  130. package/dist/client/config.d.ts +14 -0
  131. package/dist/client/config.d.ts.map +1 -0
  132. package/dist/client/config.js +11 -0
  133. package/dist/client/errors.d.ts +206 -0
  134. package/dist/client/errors.d.ts.map +1 -0
  135. package/dist/client/errors.js +130 -0
  136. package/dist/client/fetch.d.ts +61 -0
  137. package/dist/client/fetch.d.ts.map +1 -0
  138. package/dist/client/fetch.js +127 -0
  139. package/dist/client.d.ts +6 -0
  140. package/dist/client.d.ts.map +1 -0
  141. package/dist/client.js +7 -0
  142. package/dist/faker.d.ts +7 -0
  143. package/dist/faker.d.ts.map +1 -0
  144. package/dist/faker.js +24 -0
  145. package/dist/ids.d.ts +32 -0
  146. package/dist/ids.d.ts.map +1 -0
  147. package/dist/ids.js +17 -0
  148. package/dist/index.d.ts +4 -0
  149. package/dist/index.d.ts.map +1 -0
  150. package/dist/index.js +4 -0
  151. package/dist/refinements.d.ts +57 -0
  152. package/dist/refinements.d.ts.map +1 -0
  153. package/dist/refinements.js +85 -0
  154. package/dist/schema.d.ts +7 -0
  155. package/dist/schema.d.ts.map +1 -0
  156. package/dist/schema.js +22 -0
  157. package/dist/schema.test.d.ts.map +1 -0
  158. package/dist/service.d.ts +47 -0
  159. package/dist/service.d.ts.map +1 -0
  160. package/dist/service.js +83 -0
  161. package/dist/utils.d.ts +2 -0
  162. package/dist/utils.d.ts.map +1 -0
  163. package/dist/utils.js +2 -0
  164. package/package.json +315 -0
  165. package/tsconfig.json +114 -0
  166. package/tsconfig.json.bak +47 -0
  167. package/tsplus.config.json +7 -0
  168. package/vitest.config.ts +5 -0
  169. package/wallaby.cjs +1 -0
@@ -0,0 +1,334 @@
1
+ /* eslint-disable @typescript-eslint/ban-types */
2
+ import { pipe } from "@effect-app/core/Function"
3
+ import type { Refinement } from "@effect-app/core/Function"
4
+ import type {
5
+ ApiOf,
6
+ ApiSelfType,
7
+ DefaultSchema,
8
+ Field,
9
+ NonEmptyString,
10
+ NonEmptyString50Brand,
11
+ Parser,
12
+ SchemaDefaultSchema,
13
+ SchemaUPI,
14
+ Utils
15
+ } from "effect-app/schema"
16
+ import {
17
+ annotate,
18
+ brand,
19
+ defaultProp,
20
+ EParserFor,
21
+ extendWithUtils,
22
+ extendWithUtilsAnd,
23
+ leafE,
24
+ makeAnnotation,
25
+ named,
26
+ nonEmptyStringFromString,
27
+ refine
28
+ } from "effect-app/schema"
29
+ import type * as FC from "fast-check"
30
+ import { customRandom, nanoid, urlAlphabet } from "nanoid"
31
+ import validator from "validator"
32
+ import { curriedMagix } from "../Function.js"
33
+ import type { NonEmptyString255Brand, To, UnionBrand } from "./_schema.js"
34
+ import {
35
+ Arbitrary,
36
+ arbitrary,
37
+ customE,
38
+ Email as Email_,
39
+ fakerArb,
40
+ fromString,
41
+ makeConstrainedFromString,
42
+ NonEmptyString255,
43
+ PositiveInt,
44
+ string,
45
+ stringNumber,
46
+ withDefaults
47
+ } from "./_schema.js"
48
+
49
+ export const stringPositiveIntIdentifier = makeAnnotation<{}>()
50
+
51
+ export const StringPositiveInt: DefaultSchema<unknown, PositiveInt, PositiveInt, string, {}> = pipe(
52
+ stringNumber[">>>"](PositiveInt),
53
+ withDefaults,
54
+ annotate(stringPositiveIntIdentifier, {})
55
+ )
56
+ export type StringPositiveInt = PositiveInt
57
+
58
+ /**
59
+ * A string that is at least 3 character long and a maximum of 255.
60
+ */
61
+ export interface Min3String255Brand extends NonEmptyString255Brand {
62
+ readonly Min3String255: unique symbol
63
+ }
64
+
65
+ /**
66
+ * A string that is at least 3 character long and a maximum of 255.
67
+ */
68
+ export type Min3String255 = string & Min3String255Brand
69
+
70
+ /**
71
+ * A string that is at least 3 character long and a maximum of 255.
72
+ */
73
+ export const Min3String255FromString = pipe(
74
+ makeConstrainedFromString<Min3String255>(3, 255),
75
+ arbitrary((FC) =>
76
+ FC
77
+ .lorem({ mode: "words", maxCount: 2 })
78
+ .filter((x) => x.length < 255 && x.length >= 3)
79
+ .map((x) => x as Min3String255)
80
+ ),
81
+ // arbitrary removes brand benefit
82
+ brand<Min3String255>()
83
+ )
84
+
85
+ /**
86
+ * A string that is at least 3 character long and a maximum of 255.
87
+ */
88
+ export const Min3String255 = extendWithUtils(
89
+ pipe(string[">>>"](Min3String255FromString), brand<Min3String255>())
90
+ )
91
+
92
+ /**
93
+ * A string that is at least 6 characters long and a maximum of 50.
94
+ */
95
+ export interface StringIdBrand extends NonEmptyString50Brand, Min3String255Brand {
96
+ readonly StringId: unique symbol
97
+ }
98
+
99
+ /**
100
+ * A string that is at least 6 characters long and a maximum of 50.
101
+ */
102
+ export type StringId = string & StringIdBrand
103
+
104
+ const MIN_LENGTH = 6
105
+ const MAX_LENGTH = 50
106
+ const size = 21
107
+ const length = 10 * size
108
+ export const stringIdFromString = pipe(
109
+ makeConstrainedFromString<StringId>(MIN_LENGTH, MAX_LENGTH),
110
+ arbitrary((FC) =>
111
+ FC
112
+ .uint8Array({ minLength: length, maxLength: length })
113
+ .map((_) => customRandom(urlAlphabet, size, (size) => _.subarray(0, size))() as StringId)
114
+ ),
115
+ // arbitrary removes the benefit of Brand,
116
+ brand<StringId>()
117
+ )
118
+
119
+ /**
120
+ * A string that is at least 6 characters long and a maximum of 50.
121
+ */
122
+ export interface StringIdSchema extends
123
+ SchemaDefaultSchema<
124
+ unknown,
125
+ StringId,
126
+ string,
127
+ string,
128
+ ApiSelfType<StringId>
129
+ >
130
+ {}
131
+ const StringIdSchema: StringIdSchema = string[">>>"](stringIdFromString).pipe(
132
+ brand<StringId>()
133
+ )
134
+ const makeStringId = (): StringId => nanoid() as unknown as StringId
135
+ export const StringId = extendWithUtilsAnd(StringIdSchema, () => ({
136
+ make: makeStringId,
137
+ withDefault: defaultProp(StringIdSchema, makeStringId)
138
+ }))
139
+
140
+ const stringIdArb = Arbitrary.for(StringId)
141
+
142
+ export const prefixedStringIdUnsafe = (prefix: string) => StringId(prefix + StringId.make())
143
+
144
+ export const prefixedStringIdUnsafeThunk = (prefix: string) => () => prefixedStringIdUnsafe(prefix)
145
+
146
+ export interface PrefixedStringIdSchema<
147
+ Brand extends StringId,
148
+ Prefix extends string,
149
+ Separator extends string
150
+ > extends
151
+ SchemaWithUtils<
152
+ SchemaDefaultSchema<unknown, Brand, string, string, ApiSelfType<StringId>>
153
+ >,
154
+ PrefixedStringUtils<Brand, Prefix, Separator>
155
+ {}
156
+
157
+ export type SchemaWithUtils<Schema extends SchemaUPI> = Schema & Utils<Schema>
158
+
159
+ export function prefixedStringId<Brand extends StringId>() {
160
+ return <Prefix extends string, Separator extends string = "-">(
161
+ prefix: Prefix,
162
+ name: string,
163
+ separator?: Separator
164
+ ): PrefixedStringIdSchema<Brand, Prefix, Separator> => {
165
+ type FullPrefix = `${Prefix}${Separator}`
166
+ // type PrefixedId = `${FullPrefix}${string}`
167
+
168
+ const pref = `${prefix}${separator ?? "-"}` as FullPrefix
169
+ const refinement = (x: StringId): x is Brand => x.startsWith(pref)
170
+ const fromString = pipe(
171
+ stringIdFromString,
172
+ refine(
173
+ refinement,
174
+ (n) => leafE(customE(n, `a StringId prefixed with '${pref}'`))
175
+ ),
176
+ arbitrary((FC) =>
177
+ stringIdArb(FC).map(
178
+ (x) => (pref + x.substring(0, MAX_LENGTH - pref.length)) as Brand
179
+ )
180
+ )
181
+ )
182
+
183
+ const schema = string[">>>"](fromString).pipe(named(name)).pipe(brand<Brand>())
184
+ const make = () => (pref + StringId.make()) as Brand
185
+
186
+ return extendWithUtilsAnd(
187
+ schema,
188
+ (ex): PrefixedStringUtils<Brand, Prefix, Separator> => ({
189
+ EParser: EParserFor(ex),
190
+ make,
191
+ /**
192
+ * Automatically adds the prefix.
193
+ */
194
+ unsafeFrom: (str: string) => ex(pref + str),
195
+ /**
196
+ * Must provide a literal string starting with prefix.
197
+ */
198
+ prefixSafe: <REST extends string>(str: `${Prefix}${Separator}${REST}`) => ex(str),
199
+ prefix,
200
+ eq: Equivalence.string as Equivalence<Brand>,
201
+ withDefault: defaultProp(schema, make)
202
+ })
203
+ )
204
+ }
205
+ }
206
+
207
+ export const brandedStringId = <Brand extends StringId>() =>
208
+ extendWithUtilsAnd(StringId.pipe(brand<Brand>()), (s) => {
209
+ const make = (): Brand => StringId.make() as unknown as Brand
210
+
211
+ return ({
212
+ EParser: EParserFor(s),
213
+ make,
214
+ eq: Equivalence.string as Equivalence<Brand>,
215
+ withDefault: defaultProp(s, make)
216
+ })
217
+ })
218
+
219
+ export interface PrefixedStringUtils<
220
+ Brand extends StringId,
221
+ Prefix extends string,
222
+ Separator extends string
223
+ > {
224
+ readonly EParser: Parser.Parser<string, any, Brand>
225
+ readonly make: () => Brand
226
+ readonly unsafeFrom: (str: string) => Brand
227
+ prefixSafe: <REST extends string>(str: `${Prefix}${Separator}${REST}`) => Brand
228
+ readonly prefix: Prefix
229
+ eq: Equivalence<Brand>
230
+ readonly withDefault: Field<
231
+ SchemaDefaultSchema<unknown, Brand, string, string, ApiOf<PrefixedStringIdSchema<Brand, Prefix, Separator>>>,
232
+ "required",
233
+ None<any>,
234
+ Some<["constructor", () => Brand]>
235
+ >
236
+ }
237
+
238
+ export interface UrlBrand {
239
+ readonly Url: unique symbol
240
+ }
241
+
242
+ export type Url = NonEmptyString & UrlBrand
243
+ // eslint-disable-next-line @typescript-eslint/ban-types
244
+ export const UrlFromStringIdentifier = makeAnnotation<{}>()
245
+
246
+ const isUrl: Refinement<string, Url> = (s: string): s is Url => {
247
+ return validator.default.isURL(s, { require_tld: false })
248
+ }
249
+
250
+ // eslint-disable-next-line @typescript-eslint/ban-types
251
+ export const UrlFromString: DefaultSchema<string, Url, string, string, {}> = pipe(
252
+ fromString,
253
+ arbitrary((FC) => FC.webUrl()),
254
+ refine(isUrl, (n) => leafE(customE(n, "a valid Web URL according to | RFC 3986 and | WHATWG URL Standard"))),
255
+ brand<Url>(),
256
+ annotate(UrlFromStringIdentifier, {})
257
+ )
258
+ // eslint-disable-next-line @typescript-eslint/ban-types
259
+ export const UrlIdentifier = makeAnnotation<{}>()
260
+
261
+ export const Url = extendWithUtils(
262
+ pipe(
263
+ string[">>>"](UrlFromString),
264
+ // eslint-disable-next-line @typescript-eslint/unbound-method
265
+ arbitrary((FC) => fakerArb((faker) => faker.internet.url)(FC) as FC.Arbitrary<Url>),
266
+ brand<Url>(),
267
+ annotate(UrlIdentifier, {})
268
+ )
269
+ )
270
+
271
+ export const avatarUrl = pipe(string[">>>"](nonEmptyStringFromString))
272
+ .pipe(
273
+ arbitrary(
274
+ // eslint-disable-next-line @typescript-eslint/unbound-method
275
+ (FC) => fakerArb((faker) => faker.internet.avatar)(FC) as FC.Arbitrary<Url>
276
+ )
277
+ )
278
+ .pipe(brand<avatarUrl>())
279
+
280
+ export type avatarUrl = NonEmptyString & UnionBrand
281
+
282
+ export const customUrlFromString = (pool: readonly Url[]) =>
283
+ pipe(
284
+ UrlFromString,
285
+ arbitrary((FC) => FC.oneof(...pool.map(FC.constant))),
286
+ brand<Url>()
287
+ )
288
+
289
+ export const customUrl = (pool: readonly Url[]) => pipe(string[">>>"](customUrlFromString(pool)), brand<Url>())
290
+
291
+ // for now be less restrictive about the PhoneNumber
292
+ const PhoneNumber_ = StringId
293
+ export const PhoneNumber = PhoneNumber_
294
+ .pipe(
295
+ arbitrary((FC) =>
296
+ // eslint-disable-next-line @typescript-eslint/unbound-method
297
+ fakerArb((faker) => faker.phone.number)(FC).map((x) => x as StringId)
298
+ )
299
+ )
300
+ .pipe(brand<PhoneNumber>())
301
+
302
+ export type PhoneNumber = StringId & UnionBrand
303
+
304
+ const endsWith = curriedMagix(
305
+ (e: Email) => (s: string) => e.toLowerCase().endsWith(s.toLowerCase())
306
+ )
307
+ const Email__ = Object.assign(
308
+ extendWithUtils(
309
+ Email_
310
+ .pipe(
311
+ arbitrary((FC) =>
312
+ // eslint-disable-next-line @typescript-eslint/unbound-method
313
+ fakerArb((faker) => faker.internet.email)(FC).map((x) => x as Email)
314
+ )
315
+ )
316
+ .pipe(brand<Email>())
317
+ ),
318
+ {
319
+ eq: { equals: (a: Email, b: Email) => a.toLowerCase() === b.toLowerCase() },
320
+ endsWith,
321
+ toDomain: (email: Email) => NonEmptyString255(email.split("@")[1]),
322
+ isDomain: curriedMagix(
323
+ (e: Email) => (domain: string) => endsWith._("@" + domain, e)
324
+ ),
325
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
326
+ toDisplayName: (e: Email) => e.split("@")[0]
327
+ }
328
+ )
329
+ type EmailSchema__ = typeof Email__
330
+ export interface EmailSchema extends EmailSchema__ {}
331
+ export const Email: EmailSchema = Email__
332
+ export type Email = To<typeof Email_> & {
333
+ split: (separator: "@") => [NonEmptyString255, NonEmptyString255]
334
+ }
@@ -0,0 +1,3 @@
1
+ test("works", () => {
2
+ console.log(StringId.make())
3
+ })
package/_src/schema.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { isValidEmail, isValidPhone } from "@effect-app/core/validation"
2
+ import { type A, type Email as EmailT, fromBrand, nominal, type PhoneNumber as PhoneNumberT } from "@effect-app/schema"
3
+ import { fakerArb } from "./faker.js"
4
+
5
+ export const Email = S
6
+ .string
7
+ .pipe(
8
+ S.filter(isValidEmail, {
9
+ title: "Email",
10
+ description: "an email according to RFC 5322",
11
+ jsonSchema: { format: "email" },
12
+ // eslint-disable-next-line @typescript-eslint/unbound-method
13
+ arbitrary: (): A.Arbitrary<string> => fakerArb((faker) => faker.internet.exampleEmail)
14
+ }),
15
+ fromBrand(nominal<Email>(), { jsonSchema: {} }),
16
+ S.withDefaults
17
+ )
18
+
19
+ export type Email = EmailT
20
+
21
+ export const PhoneNumber = S
22
+ .string
23
+ .pipe(
24
+ S.filter(isValidPhone, {
25
+ title: "PhoneNumber",
26
+ description: "a phone number with at least 7 digits",
27
+ jsonSchema: { format: "phone" },
28
+ // eslint-disable-next-line @typescript-eslint/unbound-method
29
+ arbitrary: (): A.Arbitrary<string> => fakerArb((faker) => faker.phone.number)
30
+ }),
31
+ fromBrand(nominal<PhoneNumber>(), { jsonSchema: {} }),
32
+ S.withDefaults
33
+ )
34
+
35
+ export type PhoneNumber = PhoneNumberT
36
+
37
+ export * from "@effect-app/schema"
@@ -0,0 +1,119 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable @typescript-eslint/ban-types */
3
+ /**
4
+ * We're doing the long way around here with assignTag, TagBase & TagBaseTagged,
5
+ * because there's a typescript compiler issue where it will complain about Equal.symbol, and Hash.symbol not being accessible.
6
+ * https://github.com/microsoft/TypeScript/issues/52644
7
+ */
8
+
9
+ import type { TagTypeId as TagTypeIdOriginal } from "effect/Context"
10
+
11
+ export const ServiceTag = Symbol()
12
+ export type ServiceTag = typeof ServiceTag
13
+
14
+ export abstract class PhantomTypeParameter<Identifier extends keyof any, InstantiatedType> {
15
+ protected abstract readonly [ServiceTag]: {
16
+ readonly [NameP in Identifier]: (_: InstantiatedType) => InstantiatedType
17
+ }
18
+ }
19
+
20
+ /**
21
+ * @tsplus type ServiceTagged
22
+ */
23
+ export abstract class ServiceTagged<ServiceKey> extends PhantomTypeParameter<string, ServiceKey> {}
24
+
25
+ /**
26
+ * @tsplus static ServiceTagged make
27
+ */
28
+ export function makeService<T extends ServiceTagged<any>>(_: Omit<T, ServiceTag>) {
29
+ return _ as T
30
+ }
31
+
32
+ /**
33
+ * @tsplus fluent effect/data/Context/Tag make
34
+ */
35
+ export function make<T extends ServiceTagged<any>, I = T>(_: Tag<I, T>, t: Omit<T, ServiceTag>) {
36
+ return t as T
37
+ }
38
+
39
+ export const TagTypeId: TagTypeIdOriginal = Symbol.for("effect/Context/Tag") as unknown as TagTypeIdOriginal
40
+ export type TagTypeId = typeof TagTypeId
41
+
42
+ let i = 0
43
+ const randomId = () => "unknown-service-" + i++
44
+
45
+ export function assignTag<Id, Service = Id>(key?: string) {
46
+ return <S extends object>(cls: S): S & Tag<Id, Service> => {
47
+ const tag = GenericTag<Id, Service>(key ?? randomId())
48
+ const t = Object.assign(cls, Object.getPrototypeOf(tag), tag)
49
+ const limit = Error.stackTraceLimit
50
+ Error.stackTraceLimit = 4 // TODO
51
+ const creationError = new Error()
52
+ Error.stackTraceLimit = limit
53
+ // the stack is used to get the location of the tag definition, if a service is not found in the registry
54
+ Object.defineProperty(t, "stack", {
55
+ get() {
56
+ // remove one line as assignTag is generally used inside a class constructor function
57
+ return creationError.stack?.split("\n").slice(1).join("\n")
58
+ }
59
+ })
60
+ return t
61
+ }
62
+ }
63
+
64
+ export function TagClass<Id, ServiceImpl, Service = Id>(key?: string) {
65
+ const c: { new(service: ServiceImpl): Readonly<ServiceImpl> } = class {
66
+ constructor(service: ServiceImpl) {
67
+ Object.assign(this, service)
68
+ }
69
+ // static readonly Id: Id
70
+ } as any
71
+
72
+ return assignTag<Id, Service>(key)(c)
73
+ }
74
+
75
+ export const TagClassMake = <Id, Service = Id>() =>
76
+ <ServiceImpl, R, E>(
77
+ make: Effect<ServiceImpl, E, R>,
78
+ key?: string
79
+ ) => {
80
+ const c: {
81
+ new(service: ServiceImpl): Readonly<ServiceImpl>
82
+ toLayer: () => Layer<Service, E, R>
83
+ toLayerScoped: () => Layer<Service, E, Exclude<R, Scope>>
84
+ } = class {
85
+ constructor(service: ServiceImpl) {
86
+ Object.assign(this, service)
87
+ }
88
+ // works around an issue where defining layer on the class messes up and causes the Tag to infer to `any, any` :/
89
+ static toLayer() {
90
+ return make.toLayer(this as any)
91
+ }
92
+
93
+ static toLayerScoped() {
94
+ return make.toLayerScoped(this as any)
95
+ }
96
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
+ } as any
98
+
99
+ return assignTag<Id, Service>(key)(c)
100
+ }
101
+
102
+ export function TagClassLegacy<Id, Service = Id>(key?: string) {
103
+ abstract class TagClassLegacy {}
104
+
105
+ return assignTag<Id, Service>(key)(TagClassLegacy)
106
+ }
107
+
108
+ /** @deprecated use `Id` of TagClass for unique id */
109
+ export function ServiceTaggedClass<Id, Service = Id>() {
110
+ return <Key extends PropertyKey>(_: Key) => {
111
+ abstract class ServiceTaggedClassC {
112
+ static make = (t: Omit<Service, Key>) => {
113
+ return t as Service
114
+ }
115
+ }
116
+
117
+ return assignTag<Id, Service>()(ServiceTaggedClassC)
118
+ }
119
+ }
package/_src/utils.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "@effect-app/core/utils"
@@ -0,0 +1,82 @@
1
+ import { Config } from "effect/Config";
2
+ /**
3
+ * @since 1.0.0
4
+ */
5
+ import type * as Chunk from "effect/Chunk";
6
+ import type * as Equal from "effect/Equal";
7
+ import type { SecretTypeId } from "effect/Secret";
8
+ /**
9
+ * @tsplus type SecretURL
10
+ * @since 1.0.0
11
+ * @category models
12
+ */
13
+ export interface SecretURL extends SecretURL.Proto, Equal.Equal {
14
+ /** @internal */
15
+ readonly raw: Array<number>;
16
+ }
17
+ /**
18
+ * @tsplus type SecretURL.Ops
19
+ */
20
+ export interface SecretURLOps {
21
+ }
22
+ export declare const SecretURL: SecretURLOps;
23
+ /**
24
+ * @since 1.0.0
25
+ */
26
+ export declare namespace SecretURL {
27
+ /**
28
+ * @since 1.0.0
29
+ * @category models
30
+ */
31
+ interface Proto {
32
+ readonly [SecretTypeId]: SecretTypeId;
33
+ }
34
+ }
35
+ /**
36
+ * @tsplus static SecretURL.Ops isSecretURL
37
+ * @since 1.0.0
38
+ * @category refinements
39
+ * @tsplus location "@effect-app/prelude/Config/SecretURL"
40
+ */
41
+ export declare const isSecretURL: (u: unknown) => u is SecretURL;
42
+ /**
43
+ * @tsplus static SecretURL.Ops make
44
+ * @since 1.0.0
45
+ * @category constructors
46
+ * @tsplus location "@effect-app/prelude/Config/SecretURL"
47
+ */
48
+ export declare const make: (bytes: Array<number>) => SecretURL;
49
+ /**
50
+ * @tsplus static SecretURL.Ops fromChunk
51
+ * @since 1.0.0
52
+ * @category constructors
53
+ * @tsplus location "@effect-app/prelude/Config/SecretURL"
54
+ */
55
+ export declare const fromChunk: (chunk: Chunk.Chunk<string>) => SecretURL;
56
+ /**
57
+ * @tsplus static SecretURL.Ops fromString
58
+ * @since 1.0.0
59
+ * @category constructors
60
+ * @tsplus location "@effect-app/prelude/Config/SecretURL"
61
+ */
62
+ export declare const fromString: (text: string) => SecretURL;
63
+ /**
64
+ * @tsplus getter SecretURL value
65
+ * @since 1.0.0
66
+ * @category getters
67
+ * @tsplus location "@effect-app/prelude/Config/SecretURL"
68
+ */
69
+ export declare const value: (self: SecretURL) => string;
70
+ /**
71
+ * @tsplus fluent SecretURL unsafeWipe
72
+ * @since 1.0.0
73
+ * @category unsafe
74
+ * @tsplus location "@effect-app/prelude/Config/SecretURL"
75
+ */
76
+ export declare const unsafeWipe: (self: SecretURL) => void;
77
+ /**
78
+ * @tsplus static effect/io/Config.Ops secretURL
79
+ * @tsplus location "@effect-app/prelude/Config/SecretURL"
80
+ */
81
+ export declare const secretURL: (name?: string) => Config<SecretURL>;
82
+ //# sourceMappingURL=SecretURL.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SecretURL.d.ts","sourceRoot":"","sources":["../../_src/Config/SecretURL.ts"],"names":[],"mappings":";AAAA;;GAEG;AACH,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAejD;;;;GAIG;AACH,MAAM,WAAW,SAAU,SAAQ,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK;IAC7D,gBAAgB;IAChB,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;CAAG;AAEhC,eAAO,MAAM,SAAS,EAAE,YAAiB,CAAA;AAEzC;;GAEG;AACH,MAAM,CAAC,OAAO,WAAW,SAAS,CAAC;IACjC;;;OAGG;IACH,UAAiB,KAAK;QACpB,QAAQ,CAAC,CAAC,YAAY,CAAC,EAAE,YAAY,CAAA;KACtC;CACF;;;;;;;AAOD,eAAO,MAAM,WAAW,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,CAAC,IAAI,SAAgC,CAAA;;;;;;;AAO/E,eAAO,MAAM,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,SAAyB,CAAA;;;;;;;AAOtE,eAAO,MAAM,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,SAA8B,CAAA;;;;;;;AAOtF,eAAO,MAAM,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAA+B,CAAA;;;;;;;AAO1E,eAAO,MAAM,KAAK,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,MAAuB,CAAA;;;;;;;AAOhE,eAAO,MAAM,UAAU,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAA0B,CAAA;;;;;AAKxE,eAAO,MAAM,SAAS,UAAW,MAAM,KAAG,OAAO,SAAS,CAMzD,CAAA"}
@@ -0,0 +1,49 @@
1
+ import * as tsplus_module_1 from "effect/Config";
2
+ import * as Either from "effect/Either";
3
+ import * as internal from "./internal/configSecretURL.js";
4
+ export const SecretURL = {};
5
+ /**
6
+ * @tsplus static SecretURL.Ops isSecretURL
7
+ * @since 1.0.0
8
+ * @category refinements
9
+ */
10
+ export const isSecretURL = internal.isSecretURL;
11
+ /**
12
+ * @tsplus static SecretURL.Ops make
13
+ * @since 1.0.0
14
+ * @category constructors
15
+ */
16
+ export const make = internal.make;
17
+ /**
18
+ * @tsplus static SecretURL.Ops fromChunk
19
+ * @since 1.0.0
20
+ * @category constructors
21
+ */
22
+ export const fromChunk = internal.fromChunk;
23
+ /**
24
+ * @tsplus static SecretURL.Ops fromString
25
+ * @since 1.0.0
26
+ * @category constructors
27
+ */
28
+ const fromString_1 = internal.fromString;
29
+ export const fromString = fromString_1;
30
+ /**
31
+ * @tsplus getter SecretURL value
32
+ * @since 1.0.0
33
+ * @category getters
34
+ */
35
+ export const value = internal.value;
36
+ /**
37
+ * @tsplus fluent SecretURL unsafeWipe
38
+ * @since 1.0.0
39
+ * @category unsafe
40
+ */
41
+ export const unsafeWipe = internal.unsafeWipe;
42
+ /**
43
+ * @tsplus static effect/io/Config.Ops secretURL
44
+ */
45
+ export const secretURL = (name) => {
46
+ const config = tsplus_module_1.primitive("a secret property", (text) => Either.right(fromString_1(text)));
47
+ return name === undefined ? config : tsplus_module_1.nested(config, name);
48
+ };
49
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiU2VjcmV0VVJMLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vX3NyYy9Db25maWcvU2VjcmV0VVJMLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFJQSxPQUFPLEtBQUssTUFBTSxNQUFNLGVBQWUsQ0FBQTtBQUd2QyxPQUFPLEtBQUssUUFBUSxNQUFNLCtCQUErQixDQUFBO0FBNkJ6RCxNQUFNLENBQUMsTUFBTSxTQUFTLEdBQWlCLEVBQUUsQ0FBQTtBQWV6Qzs7OztHQUlHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sV0FBVyxHQUFtQyxRQUFRLENBQUMsV0FBVyxDQUFBO0FBRS9FOzs7O0dBSUc7QUFDSCxNQUFNLENBQUMsTUFBTSxJQUFJLEdBQXdDLFFBQVEsQ0FBQyxJQUFJLENBQUE7QUFFdEU7Ozs7R0FJRztBQUNILE1BQU0sQ0FBQyxNQUFNLFNBQVMsR0FBOEMsUUFBUSxDQUFDLFNBQVMsQ0FBQTtBQUV0Rjs7OztHQUlHO0FBQ0ksTUFBTSxlQUEwQyxRQUFRLENBQUMsVUFBVSxDQUFBO2FBQTdELFVBQVU7QUFFdkI7Ozs7R0FJRztBQUNILE1BQU0sQ0FBQyxNQUFNLEtBQUssR0FBZ0MsUUFBUSxDQUFDLEtBQUssQ0FBQTtBQUVoRTs7OztHQUlHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUE4QixRQUFRLENBQUMsVUFBVSxDQUFBO0FBRXhFOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sU0FBUyxHQUFHLENBQUMsSUFBYSxFQUFxQixFQUFFO0lBQzVELE1BQU0sTUFBTSxHQUFHLDBCQUNiLG1CQUFtQixFQUNuQixDQUFDLElBQUksRUFBRSxFQUFFLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxhQUFXLElBQUksQ0FBQyxDQUFDLENBQ3pDLENBQUE7SUFDRCxPQUFPLElBQUksS0FBSyxTQUFTLENBQUMsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUMsdUJBQUEsTUFBTSxFQUFRLElBQUksQ0FBQyxDQUFBO0FBQzFELENBQUMsQ0FBQSJ9
@@ -0,0 +1,24 @@
1
+ import * as Chunk from "effect/Chunk";
2
+ import * as EQ from "effect/Equal";
3
+ import * as Hash from "effect/Hash";
4
+ import { SecretTypeId } from "effect/Secret";
5
+ import type * as SecretURL from "../SecretURL.js";
6
+ /** @internal */
7
+ export declare const proto: {
8
+ [SecretTypeId]: symbol;
9
+ [Hash.symbol](this: SecretURL.SecretURL): number;
10
+ [EQ.symbol](this: SecretURL.SecretURL, that: unknown): boolean;
11
+ };
12
+ /** @internal */
13
+ export declare const isSecretURL: (u: unknown) => u is SecretURL.SecretURL;
14
+ /** @internal */
15
+ export declare const make: (bytes: Array<number>) => SecretURL.SecretURL;
16
+ /** @internal */
17
+ export declare const fromChunk: (chunk: Chunk.Chunk<string>) => SecretURL.SecretURL;
18
+ /** @internal */
19
+ export declare const fromString: (text: string) => SecretURL.SecretURL;
20
+ /** @internal */
21
+ export declare const value: (self: SecretURL.SecretURL) => string;
22
+ /** @internal */
23
+ export declare const unsafeWipe: (self: SecretURL.SecretURL) => void;
24
+ //# sourceMappingURL=configSecretURL.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configSecretURL.d.ts","sourceRoot":"","sources":["../../../_src/Config/internal/configSecretURL.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,EAAE,MAAM,cAAc,CAAA;AAElC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAKjD,gBAAgB;AAChB,eAAO,MAAM,KAAK;;wBAEI,mBAAmB,GAAG,MAAM;sBAM9B,mBAAmB,QAAQ,OAAO,GAAG,OAAO;CAG/D,CAAA;AAED,gBAAgB;AAChB,eAAO,MAAM,WAAW,MAAO,OAAO,6BAErC,CAAA;AAED,gBAAgB;AAChB,eAAO,MAAM,IAAI,UAAW,MAAM,MAAM,CAAC,KAAG,mBAgC3C,CAAA;AAED,gBAAgB;AAChB,eAAO,MAAM,SAAS,UAAW,WAAW,CAAC,MAAM,CAAC,KAAG,mBAEtD,CAAA;AAED,gBAAgB;AAChB,eAAO,MAAM,UAAU,SAAU,MAAM,KAAG,mBAEzC,CAAA;AAED,gBAAgB;AAChB,eAAO,MAAM,KAAK,SAAU,mBAAmB,KAAG,MAEjD,CAAA;AAED,gBAAgB;AAChB,eAAO,MAAM,UAAU,SAAU,mBAAmB,KAAG,IAItD,CAAA"}