effect 4.0.0-beta.36 → 4.0.0-beta.38

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 (125) hide show
  1. package/dist/Cause.d.ts +31 -0
  2. package/dist/Cause.d.ts.map +1 -1
  3. package/dist/Cause.js +19 -0
  4. package/dist/Cause.js.map +1 -1
  5. package/dist/Channel.d.ts +2 -2
  6. package/dist/Channel.d.ts.map +1 -1
  7. package/dist/Effect.d.ts +1 -16
  8. package/dist/Effect.d.ts.map +1 -1
  9. package/dist/Effect.js.map +1 -1
  10. package/dist/Schedule.d.ts.map +1 -1
  11. package/dist/Schedule.js +19 -1
  12. package/dist/Schedule.js.map +1 -1
  13. package/dist/Schema.d.ts +20 -48
  14. package/dist/Schema.d.ts.map +1 -1
  15. package/dist/Schema.js +9 -13
  16. package/dist/Schema.js.map +1 -1
  17. package/dist/SchemaAST.d.ts +5 -0
  18. package/dist/SchemaAST.d.ts.map +1 -1
  19. package/dist/SchemaAST.js.map +1 -1
  20. package/dist/SchemaParser.d.ts +22 -66
  21. package/dist/SchemaParser.d.ts.map +1 -1
  22. package/dist/SchemaParser.js +7 -2
  23. package/dist/SchemaParser.js.map +1 -1
  24. package/dist/Sink.d.ts +5 -2
  25. package/dist/Sink.d.ts.map +1 -1
  26. package/dist/Sink.js.map +1 -1
  27. package/dist/Stream.d.ts +1 -1
  28. package/dist/Stream.d.ts.map +1 -1
  29. package/dist/internal/effect.js +15 -1
  30. package/dist/internal/effect.js.map +1 -1
  31. package/dist/unstable/cli/Prompt.js +16 -6
  32. package/dist/unstable/cli/Prompt.js.map +1 -1
  33. package/dist/unstable/cluster/EntityAddress.d.ts.map +1 -1
  34. package/dist/unstable/cluster/EntityAddress.js +1 -1
  35. package/dist/unstable/cluster/EntityAddress.js.map +1 -1
  36. package/dist/unstable/cluster/Runner.d.ts.map +1 -1
  37. package/dist/unstable/cluster/Runner.js +1 -1
  38. package/dist/unstable/cluster/Runner.js.map +1 -1
  39. package/dist/unstable/cluster/RunnerAddress.d.ts.map +1 -1
  40. package/dist/unstable/cluster/RunnerAddress.js +1 -1
  41. package/dist/unstable/cluster/RunnerAddress.js.map +1 -1
  42. package/dist/unstable/cluster/ShardId.js +3 -3
  43. package/dist/unstable/cluster/ShardId.js.map +1 -1
  44. package/dist/unstable/devtools/DevToolsClient.d.ts.map +1 -1
  45. package/dist/unstable/devtools/DevToolsClient.js +4 -3
  46. package/dist/unstable/devtools/DevToolsClient.js.map +1 -1
  47. package/dist/unstable/devtools/DevToolsSchema.d.ts +2 -3
  48. package/dist/unstable/devtools/DevToolsSchema.d.ts.map +1 -1
  49. package/dist/unstable/devtools/DevToolsSchema.js +11 -1
  50. package/dist/unstable/devtools/DevToolsSchema.js.map +1 -1
  51. package/dist/unstable/eventlog/EventJournal.js +2 -2
  52. package/dist/unstable/eventlog/EventJournal.js.map +1 -1
  53. package/dist/unstable/eventlog/EventLog.js +1 -1
  54. package/dist/unstable/eventlog/EventLog.js.map +1 -1
  55. package/dist/unstable/eventlog/SqlEventLogJournal.js +2 -2
  56. package/dist/unstable/eventlog/SqlEventLogJournal.js.map +1 -1
  57. package/dist/unstable/http/HttpClientRequest.d.ts +24 -2
  58. package/dist/unstable/http/HttpClientRequest.d.ts.map +1 -1
  59. package/dist/unstable/http/HttpClientRequest.js +97 -0
  60. package/dist/unstable/http/HttpClientRequest.js.map +1 -1
  61. package/dist/unstable/http/HttpServerResponse.d.ts.map +1 -1
  62. package/dist/unstable/http/HttpServerResponse.js +2 -1
  63. package/dist/unstable/http/HttpServerResponse.js.map +1 -1
  64. package/dist/unstable/httpapi/HttpApiBuilder.js +9 -8
  65. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  66. package/dist/unstable/httpapi/HttpApiClient.d.ts +36 -20
  67. package/dist/unstable/httpapi/HttpApiClient.d.ts.map +1 -1
  68. package/dist/unstable/httpapi/HttpApiClient.js +49 -18
  69. package/dist/unstable/httpapi/HttpApiClient.js.map +1 -1
  70. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts +186 -67
  71. package/dist/unstable/httpapi/HttpApiEndpoint.d.ts.map +1 -1
  72. package/dist/unstable/httpapi/HttpApiEndpoint.js +44 -29
  73. package/dist/unstable/httpapi/HttpApiEndpoint.js.map +1 -1
  74. package/dist/unstable/httpapi/HttpApiSchema.d.ts +5 -0
  75. package/dist/unstable/httpapi/HttpApiSchema.d.ts.map +1 -1
  76. package/dist/unstable/httpapi/HttpApiSchema.js +20 -2
  77. package/dist/unstable/httpapi/HttpApiSchema.js.map +1 -1
  78. package/dist/unstable/httpapi/OpenApi.d.ts.map +1 -1
  79. package/dist/unstable/httpapi/OpenApi.js +2 -5
  80. package/dist/unstable/httpapi/OpenApi.js.map +1 -1
  81. package/dist/unstable/reactivity/AtomHttpApi.d.ts +11 -7
  82. package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
  83. package/dist/unstable/reactivity/AtomHttpApi.js +6 -6
  84. package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
  85. package/dist/unstable/schema/VariantSchema.d.ts +1 -1
  86. package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
  87. package/dist/unstable/sql/Migrator.d.ts.map +1 -1
  88. package/dist/unstable/sql/Migrator.js +2 -2
  89. package/dist/unstable/sql/Migrator.js.map +1 -1
  90. package/dist/unstable/sql/SqlError.d.ts +229 -9
  91. package/dist/unstable/sql/SqlError.d.ts.map +1 -1
  92. package/dist/unstable/sql/SqlError.js +256 -6
  93. package/dist/unstable/sql/SqlError.js.map +1 -1
  94. package/package.json +1 -1
  95. package/src/Cause.ts +35 -0
  96. package/src/Channel.ts +2 -2
  97. package/src/Effect.ts +1 -16
  98. package/src/Schedule.ts +20 -8
  99. package/src/Schema.ts +14 -22
  100. package/src/SchemaAST.ts +6 -0
  101. package/src/SchemaParser.ts +32 -31
  102. package/src/Sink.ts +5 -2
  103. package/src/Stream.ts +1 -1
  104. package/src/internal/effect.ts +27 -2
  105. package/src/unstable/cli/Prompt.ts +15 -6
  106. package/src/unstable/cluster/EntityAddress.ts +1 -1
  107. package/src/unstable/cluster/Runner.ts +1 -1
  108. package/src/unstable/cluster/RunnerAddress.ts +1 -1
  109. package/src/unstable/cluster/ShardId.ts +2 -2
  110. package/src/unstable/devtools/DevToolsClient.ts +23 -18
  111. package/src/unstable/devtools/DevToolsSchema.ts +13 -1
  112. package/src/unstable/eventlog/EventJournal.ts +2 -2
  113. package/src/unstable/eventlog/EventLog.ts +1 -1
  114. package/src/unstable/eventlog/SqlEventLogJournal.ts +2 -2
  115. package/src/unstable/http/HttpClientRequest.ts +104 -2
  116. package/src/unstable/http/HttpServerResponse.ts +8 -4
  117. package/src/unstable/httpapi/HttpApiBuilder.ts +15 -9
  118. package/src/unstable/httpapi/HttpApiClient.ts +118 -55
  119. package/src/unstable/httpapi/HttpApiEndpoint.ts +164 -36
  120. package/src/unstable/httpapi/HttpApiSchema.ts +20 -2
  121. package/src/unstable/httpapi/OpenApi.ts +2 -6
  122. package/src/unstable/reactivity/AtomHttpApi.ts +22 -17
  123. package/src/unstable/schema/VariantSchema.ts +1 -1
  124. package/src/unstable/sql/Migrator.ts +7 -5
  125. package/src/unstable/sql/SqlError.ts +360 -8
@@ -1,21 +1,378 @@
1
1
  /**
2
2
  * @since 4.0.0
3
3
  */
4
+ import * as Predicate from "../../Predicate.ts"
4
5
  import * as Schema from "../../Schema.ts"
5
6
 
6
- const TypeId = "~effect/sql/SqlError"
7
+ const TypeId = "~effect/sql/SqlError" as const
8
+ const ReasonTypeId = "~effect/sql/SqlError/Reason" as const
9
+
10
+ const ReasonFields = {
11
+ cause: Schema.Defect,
12
+ message: Schema.optional(Schema.String),
13
+ operation: Schema.optional(Schema.String)
14
+ }
15
+
16
+ /**
17
+ * @since 4.0.0
18
+ */
19
+ export class ConnectionError extends Schema.TaggedErrorClass<ConnectionError>("effect/sql/SqlError/ConnectionError")(
20
+ "ConnectionError",
21
+ ReasonFields
22
+ ) {
23
+ /**
24
+ * @since 4.0.0
25
+ */
26
+ readonly [ReasonTypeId] = ReasonTypeId
27
+
28
+ /**
29
+ * @since 4.0.0
30
+ */
31
+ get isRetryable(): boolean {
32
+ return true
33
+ }
34
+ }
35
+
36
+ /**
37
+ * @since 4.0.0
38
+ */
39
+ export class AuthenticationError extends Schema.TaggedErrorClass<AuthenticationError>(
40
+ "effect/sql/SqlError/AuthenticationError"
41
+ )("AuthenticationError", ReasonFields) {
42
+ /**
43
+ * @since 4.0.0
44
+ */
45
+ readonly [ReasonTypeId] = ReasonTypeId
46
+
47
+ /**
48
+ * @since 4.0.0
49
+ */
50
+ get isRetryable(): boolean {
51
+ return false
52
+ }
53
+ }
54
+
55
+ /**
56
+ * @since 4.0.0
57
+ */
58
+ export class AuthorizationError extends Schema.TaggedErrorClass<AuthorizationError>(
59
+ "effect/sql/SqlError/AuthorizationError"
60
+ )("AuthorizationError", ReasonFields) {
61
+ /**
62
+ * @since 4.0.0
63
+ */
64
+ readonly [ReasonTypeId] = ReasonTypeId
65
+
66
+ /**
67
+ * @since 4.0.0
68
+ */
69
+ get isRetryable(): boolean {
70
+ return false
71
+ }
72
+ }
73
+
74
+ /**
75
+ * @since 4.0.0
76
+ */
77
+ export class SqlSyntaxError extends Schema.TaggedErrorClass<SqlSyntaxError>("effect/sql/SqlError/SqlSyntaxError")(
78
+ "SqlSyntaxError",
79
+ ReasonFields
80
+ ) {
81
+ /**
82
+ * @since 4.0.0
83
+ */
84
+ readonly [ReasonTypeId] = ReasonTypeId
85
+
86
+ /**
87
+ * @since 4.0.0
88
+ */
89
+ get isRetryable(): boolean {
90
+ return false
91
+ }
92
+ }
93
+
94
+ /**
95
+ * @since 4.0.0
96
+ */
97
+ export class ConstraintError extends Schema.TaggedErrorClass<ConstraintError>("effect/sql/SqlError/ConstraintError")(
98
+ "ConstraintError",
99
+ ReasonFields
100
+ ) {
101
+ /**
102
+ * @since 4.0.0
103
+ */
104
+ readonly [ReasonTypeId] = ReasonTypeId
105
+
106
+ /**
107
+ * @since 4.0.0
108
+ */
109
+ get isRetryable(): boolean {
110
+ return false
111
+ }
112
+ }
113
+
114
+ /**
115
+ * @since 4.0.0
116
+ */
117
+ export class DeadlockError extends Schema.TaggedErrorClass<DeadlockError>("effect/sql/SqlError/DeadlockError")(
118
+ "DeadlockError",
119
+ ReasonFields
120
+ ) {
121
+ /**
122
+ * @since 4.0.0
123
+ */
124
+ readonly [ReasonTypeId] = ReasonTypeId
125
+
126
+ /**
127
+ * @since 4.0.0
128
+ */
129
+ get isRetryable(): boolean {
130
+ return true
131
+ }
132
+ }
133
+
134
+ /**
135
+ * @since 4.0.0
136
+ */
137
+ export class SerializationError extends Schema.TaggedErrorClass<SerializationError>(
138
+ "effect/sql/SqlError/SerializationError"
139
+ )("SerializationError", ReasonFields) {
140
+ /**
141
+ * @since 4.0.0
142
+ */
143
+ readonly [ReasonTypeId] = ReasonTypeId
144
+
145
+ /**
146
+ * @since 4.0.0
147
+ */
148
+ get isRetryable(): boolean {
149
+ return true
150
+ }
151
+ }
152
+
153
+ /**
154
+ * @since 4.0.0
155
+ */
156
+ export class LockTimeoutError extends Schema.TaggedErrorClass<LockTimeoutError>("effect/sql/SqlError/LockTimeoutError")(
157
+ "LockTimeoutError",
158
+ ReasonFields
159
+ ) {
160
+ /**
161
+ * @since 4.0.0
162
+ */
163
+ readonly [ReasonTypeId] = ReasonTypeId
164
+
165
+ /**
166
+ * @since 4.0.0
167
+ */
168
+ get isRetryable(): boolean {
169
+ return true
170
+ }
171
+ }
172
+
173
+ /**
174
+ * @since 4.0.0
175
+ */
176
+ export class StatementTimeoutError extends Schema.TaggedErrorClass<StatementTimeoutError>(
177
+ "effect/sql/SqlError/StatementTimeoutError"
178
+ )("StatementTimeoutError", ReasonFields) {
179
+ /**
180
+ * @since 4.0.0
181
+ */
182
+ readonly [ReasonTypeId] = ReasonTypeId
183
+
184
+ /**
185
+ * @since 4.0.0
186
+ */
187
+ get isRetryable(): boolean {
188
+ return true
189
+ }
190
+ }
191
+
192
+ /**
193
+ * @since 4.0.0
194
+ */
195
+ export class UnknownError extends Schema.TaggedErrorClass<UnknownError>("effect/sql/SqlError/UnknownError")(
196
+ "UnknownError",
197
+ ReasonFields
198
+ ) {
199
+ /**
200
+ * @since 4.0.0
201
+ */
202
+ readonly [ReasonTypeId] = ReasonTypeId
203
+
204
+ /**
205
+ * @since 4.0.0
206
+ */
207
+ get isRetryable(): boolean {
208
+ return false
209
+ }
210
+ }
211
+
212
+ /**
213
+ * @since 4.0.0
214
+ */
215
+ export type SqlErrorReason =
216
+ | ConnectionError
217
+ | AuthenticationError
218
+ | AuthorizationError
219
+ | SqlSyntaxError
220
+ | ConstraintError
221
+ | DeadlockError
222
+ | SerializationError
223
+ | LockTimeoutError
224
+ | StatementTimeoutError
225
+ | UnknownError
226
+
227
+ /**
228
+ * @since 4.0.0
229
+ */
230
+ export const SqlErrorReason: Schema.Union<[
231
+ typeof ConnectionError,
232
+ typeof AuthenticationError,
233
+ typeof AuthorizationError,
234
+ typeof SqlSyntaxError,
235
+ typeof ConstraintError,
236
+ typeof DeadlockError,
237
+ typeof SerializationError,
238
+ typeof LockTimeoutError,
239
+ typeof StatementTimeoutError,
240
+ typeof UnknownError
241
+ ]> = Schema.Union([
242
+ ConnectionError,
243
+ AuthenticationError,
244
+ AuthorizationError,
245
+ SqlSyntaxError,
246
+ ConstraintError,
247
+ DeadlockError,
248
+ SerializationError,
249
+ LockTimeoutError,
250
+ StatementTimeoutError,
251
+ UnknownError
252
+ ])
7
253
 
8
254
  /**
9
255
  * @since 4.0.0
10
256
  */
11
257
  export class SqlError extends Schema.TaggedErrorClass<SqlError>("effect/sql/SqlError")("SqlError", {
12
- cause: Schema.Defect,
13
- message: Schema.optional(Schema.String)
258
+ reason: SqlErrorReason
14
259
  }) {
15
260
  /**
16
261
  * @since 4.0.0
17
262
  */
18
263
  readonly [TypeId] = TypeId
264
+
265
+ /**
266
+ * @since 4.0.0
267
+ */
268
+ override readonly cause = this.reason
269
+
270
+ /**
271
+ * @since 4.0.0
272
+ */
273
+ override get message(): string {
274
+ return this.reason.message || this.reason._tag
275
+ }
276
+
277
+ /**
278
+ * @since 4.0.0
279
+ */
280
+ get isRetryable(): boolean {
281
+ return this.reason.isRetryable
282
+ }
283
+ }
284
+
285
+ /**
286
+ * @since 4.0.0
287
+ */
288
+ export const isSqlError = (u: unknown): u is SqlError => Predicate.hasProperty(u, TypeId)
289
+
290
+ /**
291
+ * @since 4.0.0
292
+ */
293
+ export const isSqlErrorReason = (u: unknown): u is SqlErrorReason => Predicate.hasProperty(u, ReasonTypeId)
294
+
295
+ type SqliteClassifyOptions = {
296
+ readonly message?: string | undefined
297
+ readonly operation?: string | undefined
298
+ }
299
+
300
+ const sqliteCodeFromCause = (cause: unknown): string | number | undefined => {
301
+ if (!Predicate.hasProperty(cause, "code")) {
302
+ return undefined
303
+ }
304
+ const code = cause.code
305
+ return typeof code === "string" || typeof code === "number" ? code : undefined
306
+ }
307
+
308
+ const sqliteNumericCodeFromCause = (cause: unknown): number | undefined => {
309
+ const code = sqliteCodeFromCause(cause)
310
+ if (typeof code === "number") {
311
+ return code
312
+ }
313
+ if (!Predicate.hasProperty(cause, "errno")) {
314
+ return undefined
315
+ }
316
+ const errno = cause.errno
317
+ return typeof errno === "number" ? errno : undefined
318
+ }
319
+
320
+ const matchesSqliteCode = (code: string, expected: string): boolean =>
321
+ code === expected || code.startsWith(expected + "_")
322
+
323
+ /**
324
+ * @since 4.0.0
325
+ */
326
+ export const classifySqliteError = (
327
+ cause: unknown,
328
+ { message, operation }: SqliteClassifyOptions = {}
329
+ ): SqlErrorReason => {
330
+ const props = {
331
+ cause,
332
+ message,
333
+ operation
334
+ }
335
+ const code = sqliteCodeFromCause(cause)
336
+
337
+ if (typeof code === "string") {
338
+ if (matchesSqliteCode(code, "SQLITE_AUTH")) {
339
+ return new AuthenticationError(props)
340
+ }
341
+ if (matchesSqliteCode(code, "SQLITE_PERM")) {
342
+ return new AuthorizationError(props)
343
+ }
344
+ if (matchesSqliteCode(code, "SQLITE_CONSTRAINT")) {
345
+ return new ConstraintError(props)
346
+ }
347
+ if (matchesSqliteCode(code, "SQLITE_BUSY") || matchesSqliteCode(code, "SQLITE_LOCKED")) {
348
+ return new LockTimeoutError(props)
349
+ }
350
+ if (matchesSqliteCode(code, "SQLITE_CANTOPEN")) {
351
+ return new ConnectionError(props)
352
+ }
353
+ }
354
+
355
+ const numericCode = sqliteNumericCodeFromCause(cause)
356
+ if (typeof numericCode === "number") {
357
+ const code = numericCode & 0xff
358
+ switch (code) {
359
+ case 23:
360
+ return new AuthenticationError(props)
361
+ case 3:
362
+ return new AuthorizationError(props)
363
+ case 19:
364
+ return new ConstraintError(props)
365
+ case 5:
366
+ case 6:
367
+ return new LockTimeoutError(props)
368
+ case 14:
369
+ return new ConnectionError(props)
370
+ default:
371
+ return new UnknownError(props)
372
+ }
373
+ }
374
+
375
+ return new UnknownError(props)
19
376
  }
20
377
 
21
378
  /**
@@ -27,11 +384,6 @@ export class ResultLengthMismatch
27
384
  actual: Schema.Number
28
385
  })
29
386
  {
30
- /**
31
- * @since 4.0.0
32
- */
33
- readonly [TypeId] = TypeId
34
-
35
387
  /**
36
388
  * @since 4.0.0
37
389
  */