@prestack/thread 0.1.21 → 0.1.22

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 (137) hide show
  1. package/CHANGELOG.md +109 -0
  2. package/dist/core/attach.js +21 -0
  3. package/dist/core/descend.js +6 -3
  4. package/dist/core/generators/commit.js +55 -3
  5. package/dist/core/generators/dev.d.ts +1 -0
  6. package/dist/core/generators/dev.js +68 -0
  7. package/dist/core/tree.d.ts +1 -0
  8. package/dist/core/tree.js +7 -1
  9. package/dist/derivation/generators/build.d.ts +3 -1
  10. package/dist/derivation/generators/build.js +103 -22
  11. package/dist/derivation/generators/release.js +74 -26
  12. package/dist/derivation/release.js +3 -3
  13. package/dist/integrations/cli.js +69 -10
  14. package/dist/integrations/pglite.js +13 -3
  15. package/dist/integrations/target.d.ts +3 -0
  16. package/dist/integrity/attach.js +1 -5
  17. package/dist/integrity/slopnators/sl_stale_path.js +10 -0
  18. package/dist/operations/access.js +3 -2
  19. package/dist/operations/capabilities.d.ts +2 -0
  20. package/dist/operations/capabilities.js +2 -0
  21. package/dist/operations/generators/capability.js +234 -24
  22. package/dist/operations/generators/compile.js +150 -50
  23. package/dist/operations/generators/seed.d.ts +3 -0
  24. package/dist/operations/generators/seed.js +25 -3
  25. package/dist/operations/nodes.d.ts +2 -2
  26. package/package.json +1 -1
  27. package/dist/core/actor.ts +0 -21
  28. package/dist/core/attach.ts +0 -613
  29. package/dist/core/chain.ts +0 -145
  30. package/dist/core/condition.ts +0 -227
  31. package/dist/core/descend.ts +0 -1185
  32. package/dist/core/errors/catalogue.ts +0 -314
  33. package/dist/core/errors/classes.ts +0 -51
  34. package/dist/core/errors/error.ts +0 -152
  35. package/dist/core/errors/namespaces.ts +0 -19
  36. package/dist/core/finding.ts +0 -37
  37. package/dist/core/generators/commit.ts +0 -157
  38. package/dist/core/init.ts +0 -222
  39. package/dist/core/invoked.ts +0 -52
  40. package/dist/core/round.ts +0 -74
  41. package/dist/core/rows.ts +0 -506
  42. package/dist/core/scope.ts +0 -20
  43. package/dist/core/thread.ts +0 -29
  44. package/dist/core/tree.ts +0 -90
  45. package/dist/core/types.ts +0 -351
  46. package/dist/derivation/attach.ts +0 -57
  47. package/dist/derivation/generators/build.ts +0 -371
  48. package/dist/derivation/generators/check.ts +0 -118
  49. package/dist/derivation/generators/determinism.ts +0 -145
  50. package/dist/derivation/generators/release.ts +0 -236
  51. package/dist/derivation/release.ts +0 -43
  52. package/dist/integrations/attach.ts +0 -187
  53. package/dist/integrations/cli.ts +0 -606
  54. package/dist/integrations/declared.ts +0 -34
  55. package/dist/integrations/disk.ts +0 -466
  56. package/dist/integrations/generators/read.ts +0 -127
  57. package/dist/integrations/generators/vault.ts +0 -210
  58. package/dist/integrations/https.ts +0 -216
  59. package/dist/integrations/pglite.ts +0 -206
  60. package/dist/integrations/secret.ts +0 -54
  61. package/dist/integrations/target.ts +0 -672
  62. package/dist/integrations/vault.ts +0 -148
  63. package/dist/integrity/attach.ts +0 -150
  64. package/dist/integrity/check-threads.ts +0 -166
  65. package/dist/integrity/constraint.ts +0 -1246
  66. package/dist/integrity/generators/compiler.ts +0 -138
  67. package/dist/integrity/generators/gate.ts +0 -227
  68. package/dist/integrity/generators/issues.ts +0 -160
  69. package/dist/integrity/generators/publish.ts +0 -233
  70. package/dist/integrity/generators/trial.ts +0 -359
  71. package/dist/integrity/lint.ts +0 -214
  72. package/dist/integrity/lsp/bin.ts +0 -44
  73. package/dist/integrity/lsp/diagnostics.ts +0 -92
  74. package/dist/integrity/lsp/findings.ts +0 -63
  75. package/dist/integrity/lsp/lint.ts +0 -124
  76. package/dist/integrity/lsp/protocol.ts +0 -78
  77. package/dist/integrity/lsp/server.ts +0 -224
  78. package/dist/integrity/slopnator.ts +0 -324
  79. package/dist/integrity/slopnators/sl_broken_lineage.ts +0 -38
  80. package/dist/integrity/slopnators/sl_declared_elsewhere.ts +0 -60
  81. package/dist/integrity/slopnators/sl_derived_drift.ts +0 -101
  82. package/dist/integrity/slopnators/sl_door_in_a_node.ts +0 -250
  83. package/dist/integrity/slopnators/sl_hardcoded_style.ts +0 -55
  84. package/dist/integrity/slopnators/sl_inert_island.ts +0 -84
  85. package/dist/integrity/slopnators/sl_inert_slopnator.ts +0 -93
  86. package/dist/integrity/slopnators/sl_missing_row.ts +0 -140
  87. package/dist/integrity/slopnators/sl_no_barrel.ts +0 -48
  88. package/dist/integrity/slopnators/sl_no_child_process.ts +0 -100
  89. package/dist/integrity/slopnators/sl_no_comment.ts +0 -43
  90. package/dist/integrity/slopnators/sl_no_dispatch_bypass.ts +0 -276
  91. package/dist/integrity/slopnators/sl_no_import_cycle.ts +0 -66
  92. package/dist/integrity/slopnators/sl_no_such_command.ts +0 -81
  93. package/dist/integrity/slopnators/sl_only_takes_a_literal.ts +0 -63
  94. package/dist/integrity/slopnators/sl_outside_an_operation.ts +0 -25
  95. package/dist/integrity/slopnators/sl_screen_holds_only_declared.ts +0 -70
  96. package/dist/integrity/slopnators/sl_secret_literal.ts +0 -68
  97. package/dist/integrity/slopnators/sl_stale_path.ts +0 -178
  98. package/dist/integrity/slopnators/sl_twice_meant.ts +0 -57
  99. package/dist/integrity/slopnators/sl_twice_parented.ts +0 -82
  100. package/dist/integrity/slopnators/sl_undeclared_crossing.ts +0 -481
  101. package/dist/integrity/slopnators/sl_undeclared_destination.ts +0 -113
  102. package/dist/integrity/slopnators/sl_undeclared_element.ts +0 -44
  103. package/dist/integrity/slopnators/sl_undeclared_list.ts +0 -358
  104. package/dist/integrity/slopnators/sl_undeclared_node.ts +0 -75
  105. package/dist/integrity/slopnators/sl_undeclared_operation.ts +0 -257
  106. package/dist/integrity/slopnators/sl_undeclared_variant.ts +0 -152
  107. package/dist/integrity/slopnators/sl_undeclared_webhook.ts +0 -108
  108. package/dist/integrity/slopnators/sl_underived_route.ts +0 -72
  109. package/dist/integrity/slopnators/sl_undescribed.ts +0 -65
  110. package/dist/integrity/slopnators/sl_ungoverned_island.ts +0 -60
  111. package/dist/integrity/slopnators/sl_unlisted_program.ts +0 -46
  112. package/dist/integrity/slopnators/sl_unnamed_island.ts +0 -41
  113. package/dist/integrity/slopnators/sl_unpaired_member.ts +0 -139
  114. package/dist/integrity/slopnators/sl_unpaired_slopnator.ts +0 -71
  115. package/dist/integrity/slopnators/sl_unprefixed_member.ts +0 -110
  116. package/dist/integrity/slopnators/sl_unthreaded.ts +0 -421
  117. package/dist/integrity/slopnators/sl_untranslated_key.ts +0 -140
  118. package/dist/integrity/slopnators/sl_unvaulted_secret.ts +0 -132
  119. package/dist/integrity/slopnators/sl_unversioned.ts +0 -52
  120. package/dist/integrity/sweep.ts +0 -395
  121. package/dist/knowledge/attach.ts +0 -327
  122. package/dist/knowledge/generators/docsgen.ts +0 -186
  123. package/dist/knowledge/generators/glossary.ts +0 -73
  124. package/dist/knowledge/glossary.ts +0 -6
  125. package/dist/operations/access.ts +0 -131
  126. package/dist/operations/attach.ts +0 -408
  127. package/dist/operations/capabilities.ts +0 -88
  128. package/dist/operations/dispatch.ts +0 -294
  129. package/dist/operations/error-results.ts +0 -31
  130. package/dist/operations/generators/capability.ts +0 -1054
  131. package/dist/operations/generators/compile.ts +0 -701
  132. package/dist/operations/generators/permits.ts +0 -229
  133. package/dist/operations/generators/seed.ts +0 -359
  134. package/dist/operations/generators/trial.ts +0 -666
  135. package/dist/operations/nodes.ts +0 -53
  136. package/dist/operations/operations.ts +0 -91
  137. package/dist/operations/result.ts +0 -28
@@ -1,314 +0,0 @@
1
-
2
-
3
- import { defineError } from './error.ts'
4
-
5
- export const AuthUnauthenticated = defineError({
6
- code: 'auth.unauthenticated',
7
- class: 'UNAUTHENTICATED',
8
- })
9
-
10
- export const AuthInvalidCredentials = defineError({
11
- code: 'auth.invalid_credentials',
12
- class: 'UNAUTHENTICATED',
13
- })
14
-
15
- export const AuthTokenExpired = defineError({
16
- code: 'auth.token_expired',
17
- class: 'UNAUTHENTICATED',
18
- })
19
-
20
- export const AuthTokenReused = defineError({
21
- code: 'auth.token_reused',
22
- class: 'UNAUTHENTICATED',
23
- })
24
-
25
- export const AuthSessionRevoked = defineError({
26
- code: 'auth.session_revoked',
27
- class: 'UNAUTHENTICATED',
28
- })
29
-
30
- export const AuthDenied = defineError({
31
- code: 'auth.denied',
32
- class: 'PERMISSION_DENIED',
33
- })
34
-
35
- export const QuotaExceeded = defineError({
36
- code: 'quota.exceeded',
37
- class: 'RESOURCE_EXHAUSTED',
38
-
39
- status: 402,
40
- })
41
-
42
- export const QuotaReservationExpired = defineError({
43
- code: 'quota.reservation_expired',
44
- class: 'ABORTED',
45
- })
46
-
47
- export const RateLimitExceeded = defineError({
48
- code: 'rate_limit.exceeded',
49
- class: 'RESOURCE_EXHAUSTED',
50
- })
51
-
52
- export const FeatureNotInPlan = defineError({
53
- code: 'feature.not_in_plan',
54
- class: 'PERMISSION_DENIED',
55
- })
56
-
57
- export const DbNotFound = defineError({
58
- code: 'db.not_found',
59
- class: 'NOT_FOUND',
60
- })
61
-
62
- export const DbConstraintViolation = defineError({
63
- code: 'db.constraint_violation',
64
- class: 'FAILED_PRECONDITION',
65
- })
66
-
67
- export const DbAlreadyExists = defineError({
68
- code: 'db.already_exists',
69
- class: 'ALREADY_EXISTS',
70
- })
71
-
72
- export const DbConflict = defineError({
73
- code: 'db.conflict',
74
- class: 'ABORTED',
75
-
76
- status: 412,
77
- })
78
-
79
- export const DbMigrationChecksumMismatch = defineError({
80
- code: 'db.migration_checksum_mismatch',
81
- class: 'FAILED_PRECONDITION',
82
- })
83
-
84
- export const DbDestructiveWithoutDryRun = defineError({
85
- code: 'db.destructive_without_dry_run',
86
- class: 'FAILED_PRECONDITION',
87
- })
88
-
89
- export const DbRoundTripBudgetExceeded = defineError({
90
- code: 'db.round_trip_budget_exceeded',
91
- class: 'INTERNAL',
92
- })
93
-
94
- export const DbCursorInvalid = defineError({
95
- code: 'db.cursor_invalid',
96
- class: 'INVALID_ARGUMENT',
97
- })
98
-
99
- export const DbCursorExpired = defineError({
100
- code: 'db.cursor_expired',
101
- class: 'INVALID_ARGUMENT',
102
- })
103
-
104
- export const WorkflowNodeFailed = defineError({
105
- code: 'workflow.node_failed',
106
- class: 'INTERNAL',
107
- })
108
-
109
- export const WorkflowInvalidTransition = defineError({
110
- code: 'workflow.invalid_transition',
111
- class: 'FAILED_PRECONDITION',
112
- })
113
-
114
- export const WorkflowCompensationFailed = defineError({
115
- code: 'workflow.compensation_failed',
116
- class: 'INTERNAL',
117
- })
118
-
119
- export const WorkflowAlreadyRunning = defineError({
120
- code: 'workflow.already_running',
121
- class: 'ALREADY_EXISTS',
122
- })
123
-
124
- export const QueueJobFailed = defineError({
125
- code: 'queue.job_failed',
126
- class: 'INTERNAL',
127
- })
128
-
129
- export const QueueDlqExhausted = defineError({
130
- code: 'queue.dlq_exhausted',
131
- class: 'INTERNAL',
132
- })
133
-
134
- export const AiProviderUnavailable = defineError({
135
- code: 'ai.provider_unavailable',
136
- class: 'UNAVAILABLE',
137
- })
138
-
139
- export const AiSchemaValidationFailed = defineError({
140
- code: 'ai.schema_validation_failed',
141
- class: 'INTERNAL',
142
- })
143
-
144
- export const AiToolNotInMask = defineError({
145
- code: 'ai.tool_not_in_mask',
146
- class: 'PERMISSION_DENIED',
147
- })
148
-
149
- export const AiNodeCapExceeded = defineError({
150
- code: 'ai.node_cap_exceeded',
151
- class: 'RESOURCE_EXHAUSTED',
152
- })
153
-
154
- export const SearchIndexFailed = defineError({
155
- code: 'search.index_failed',
156
- class: 'INTERNAL',
157
- })
158
-
159
- export const SearchQueryInvalid = defineError({
160
- code: 'search.query_invalid',
161
- class: 'INVALID_ARGUMENT',
162
- })
163
-
164
- export const CommsChannelKindUndeclared = defineError({
165
- code: 'comms.channel_kind_undeclared',
166
- class: 'FAILED_PRECONDITION',
167
- })
168
-
169
- export const CommsChannelKindUndescribed = defineError({
170
- code: 'comms.channel_kind_undescribed',
171
- class: 'FAILED_PRECONDITION',
172
- })
173
-
174
- export const CommsChannelKindUnlabelled = defineError({
175
- code: 'comms.channel_kind_unlabelled',
176
- class: 'FAILED_PRECONDITION',
177
- })
178
-
179
- export const CommsChannelKindUndocumented = defineError({
180
- code: 'comms.channel_kind_undocumented',
181
- class: 'FAILED_PRECONDITION',
182
- })
183
-
184
- export const CommsChannelKindDuplicate = defineError({
185
- code: 'comms.channel_kind_duplicate',
186
- class: 'ALREADY_EXISTS',
187
- })
188
-
189
- export const ConfigInvalid = defineError({
190
- code: 'config.invalid',
191
- class: 'FAILED_PRECONDITION',
192
- })
193
-
194
- export const ConfigMissingEnv = defineError({
195
- code: 'config.missing_env',
196
- class: 'FAILED_PRECONDITION',
197
- })
198
-
199
- export const ConfigSecretInPublicVar = defineError({
200
- code: 'config.secret_in_public_var',
201
- class: 'FAILED_PRECONDITION',
202
- })
203
-
204
- export const ConfigCredentialInvalid = defineError({
205
- code: 'config.credential_invalid',
206
- class: 'UNAUTHENTICATED',
207
- })
208
-
209
- export const ConfigScopeMissing = defineError({
210
- code: 'config.scope_missing',
211
- class: 'PERMISSION_DENIED',
212
- })
213
-
214
- export const ConfigResourceNotFound = defineError({
215
- code: 'config.resource_not_found',
216
- class: 'NOT_FOUND',
217
- })
218
-
219
- export const ConfigDestinationIncompatible = defineError({
220
- code: 'config.destination_incompatible',
221
- class: 'FAILED_PRECONDITION',
222
- status: 406,
223
- })
224
-
225
- export const ConfigBlocksExit = defineError({
226
- code: 'config.blocks_exit',
227
- class: 'FAILED_PRECONDITION',
228
- status: 422,
229
- })
230
-
231
- export const NetTimeout = defineError({
232
- code: 'net.timeout',
233
- class: 'DEADLINE_EXCEEDED',
234
- })
235
-
236
- export const NetUpstreamUnavailable = defineError({
237
- code: 'net.upstream_unavailable',
238
- class: 'UNAVAILABLE',
239
- })
240
-
241
- export const NetDestinationRefused = defineError({
242
- code: 'net.destination_refused',
243
- class: 'INVALID_ARGUMENT',
244
- })
245
-
246
- export const InternalUnexpected = defineError({
247
- code: 'internal.unexpected',
248
- class: 'INTERNAL',
249
- })
250
-
251
- export const InternalNotImplemented = defineError({
252
- code: 'internal.not_implemented',
253
- class: 'UNIMPLEMENTED',
254
- })
255
-
256
- export const InternalInvalidArgument = defineError({
257
- code: 'internal.invalid_argument',
258
- class: 'INVALID_ARGUMENT',
259
- })
260
-
261
- export const PLATFORM_ERRORS = [
262
- AuthUnauthenticated,
263
- AuthInvalidCredentials,
264
- AuthTokenExpired,
265
- AuthTokenReused,
266
- AuthSessionRevoked,
267
- AuthDenied,
268
- QuotaExceeded,
269
- QuotaReservationExpired,
270
- RateLimitExceeded,
271
- FeatureNotInPlan,
272
- DbNotFound,
273
- DbConstraintViolation,
274
- DbAlreadyExists,
275
- DbConflict,
276
- DbMigrationChecksumMismatch,
277
- DbDestructiveWithoutDryRun,
278
- DbRoundTripBudgetExceeded,
279
- DbCursorInvalid,
280
- DbCursorExpired,
281
- WorkflowNodeFailed,
282
- WorkflowInvalidTransition,
283
- WorkflowCompensationFailed,
284
- WorkflowAlreadyRunning,
285
- QueueJobFailed,
286
- QueueDlqExhausted,
287
- AiProviderUnavailable,
288
- AiSchemaValidationFailed,
289
- AiToolNotInMask,
290
- AiNodeCapExceeded,
291
- SearchIndexFailed,
292
- SearchQueryInvalid,
293
- CommsChannelKindUndeclared,
294
- CommsChannelKindUndescribed,
295
- CommsChannelKindUnlabelled,
296
- CommsChannelKindUndocumented,
297
- CommsChannelKindDuplicate,
298
- ConfigInvalid,
299
- ConfigMissingEnv,
300
- ConfigSecretInPublicVar,
301
- ConfigCredentialInvalid,
302
- ConfigScopeMissing,
303
- ConfigResourceNotFound,
304
- ConfigDestinationIncompatible,
305
- ConfigBlocksExit,
306
- NetTimeout,
307
- NetUpstreamUnavailable,
308
- NetDestinationRefused,
309
- InternalUnexpected,
310
- InternalNotImplemented,
311
- InternalInvalidArgument,
312
- ] as const
313
-
314
- export type PlatformErrorCode = (typeof PLATFORM_ERRORS)[number]['def']['code']
@@ -1,51 +0,0 @@
1
-
2
-
3
- export interface ErrorClassDef {
4
-
5
- readonly status: number
6
-
7
- readonly retryable: boolean
8
- }
9
-
10
- export const ERROR_CLASSES = {
11
-
12
- OK: { status: 200, retryable: false },
13
-
14
- CANCELLED: { status: 499, retryable: false },
15
-
16
- UNKNOWN: { status: 500, retryable: false },
17
-
18
- INVALID_ARGUMENT: { status: 400, retryable: false },
19
-
20
- DEADLINE_EXCEEDED: { status: 504, retryable: true },
21
-
22
- NOT_FOUND: { status: 404, retryable: false },
23
-
24
- ALREADY_EXISTS: { status: 409, retryable: false },
25
-
26
- PERMISSION_DENIED: { status: 403, retryable: false },
27
-
28
- RESOURCE_EXHAUSTED: { status: 429, retryable: true },
29
-
30
- FAILED_PRECONDITION: { status: 400, retryable: false },
31
-
32
- ABORTED: { status: 409, retryable: true },
33
-
34
- OUT_OF_RANGE: { status: 400, retryable: false },
35
-
36
- UNIMPLEMENTED: { status: 501, retryable: false },
37
-
38
- INTERNAL: { status: 500, retryable: false },
39
-
40
- UNAVAILABLE: { status: 503, retryable: true },
41
-
42
- UNAUTHENTICATED: { status: 401, retryable: false },
43
- } as const satisfies Record<string, ErrorClassDef>
44
-
45
- export type ErrorClass = keyof typeof ERROR_CLASSES
46
-
47
- export const ERROR_CLASS_NAMES = Object.keys(ERROR_CLASSES) as readonly ErrorClass[]
48
-
49
- export function classDef(cls: ErrorClass): ErrorClassDef {
50
- return ERROR_CLASSES[cls]
51
- }
@@ -1,152 +0,0 @@
1
-
2
-
3
- import { classDef, type ErrorClass } from './classes.ts'
4
-
5
- import type { ErrorCode } from './namespaces.ts'
6
-
7
- export type { ErrorCode } from './namespaces.ts'
8
-
9
- export interface ErrorDef<C extends ErrorCode = ErrorCode> {
10
- readonly code: C
11
- readonly class: ErrorClass
12
- readonly status: number
13
-
14
- readonly titleKey: string
15
- readonly retryable: boolean
16
- }
17
-
18
- export interface DefineErrorInput<C extends ErrorCode = ErrorCode> {
19
- readonly code: C
20
- readonly class: ErrorClass
21
-
22
- readonly status?: number
23
-
24
- readonly retryable?: boolean
25
-
26
- readonly titleKey?: string
27
- }
28
-
29
- export interface PlatformErrorInit {
30
-
31
- readonly detail?: string
32
-
33
- readonly instance?: string
34
-
35
- readonly because?: string
36
- readonly traceId?: string
37
-
38
- readonly retryAfter?: number
39
- readonly cause?: unknown
40
-
41
- readonly extensions?: Readonly<Record<string, unknown>>
42
- }
43
-
44
- export class PlatformError<C extends ErrorCode = ErrorCode> extends Error {
45
- readonly def: ErrorDef<C>
46
- readonly detail?: string
47
- readonly instance?: string
48
- readonly because?: string
49
- readonly traceId?: string
50
- readonly retryAfter?: number
51
- readonly extensions: Readonly<Record<string, unknown>>
52
-
53
- constructor(def: ErrorDef<C>, init: PlatformErrorInit = {}) {
54
-
55
- super(def.code, init.cause === undefined ? undefined : { cause: init.cause })
56
- this.name = 'PlatformError'
57
- this.def = def
58
- this.detail = init.detail
59
- this.instance = init.instance
60
- this.because = init.because
61
- this.traceId = init.traceId
62
- this.retryAfter = init.retryAfter
63
- this.extensions = init.extensions ?? {}
64
- }
65
-
66
- get code(): C {
67
- return this.def.code
68
- }
69
-
70
- get status(): number {
71
- return this.def.status
72
- }
73
-
74
- get retryable(): boolean {
75
- return this.def.retryable
76
- }
77
- }
78
-
79
- export function isPlatformError(value: unknown): value is PlatformError {
80
- return value instanceof PlatformError
81
- }
82
-
83
- export type ErrorFactory<C extends ErrorCode = ErrorCode> = ((
84
- init?: PlatformErrorInit,
85
- ) => PlatformError<C>) & {
86
- readonly def: ErrorDef<C>
87
-
88
- readonly is: (value: unknown) => value is PlatformError<C>
89
- }
90
-
91
- export class DuplicateErrorCodeError extends Error {
92
- constructor(code: string) {
93
- super(`duplicate error code: ${code}`)
94
- this.name = 'DuplicateErrorCodeError'
95
- }
96
- }
97
-
98
- export class ErrorCatalog {
99
- readonly #byCode = new Map<ErrorCode, ErrorDef>()
100
-
101
- define<const C extends ErrorCode>(input: DefineErrorInput<C>): ErrorFactory<C> {
102
- if (this.#byCode.has(input.code)) {
103
-
104
- throw new DuplicateErrorCodeError(input.code)
105
- }
106
-
107
- const cls = classDef(input.class)
108
- const def: ErrorDef<C> = {
109
- code: input.code,
110
- class: input.class,
111
- status: input.status ?? cls.status,
112
- retryable: input.retryable ?? cls.retryable,
113
- titleKey: input.titleKey ?? `errors.${input.code}.title`,
114
- }
115
- this.#byCode.set(def.code, def)
116
-
117
- const factory = ((init?: PlatformErrorInit) => new PlatformError(def, init)) as {
118
- (init?: PlatformErrorInit): PlatformError<C>
119
- def: ErrorDef<C>
120
- is: (value: unknown) => value is PlatformError<C>
121
- }
122
- factory.def = def
123
- factory.is = (value: unknown): value is PlatformError<C> =>
124
- isPlatformError(value) && value.def.code === def.code
125
-
126
- return factory as ErrorFactory<C>
127
- }
128
-
129
- get(code: string): ErrorDef | undefined {
130
- return this.#byCode.get(code as ErrorCode)
131
- }
132
-
133
- has(code: string): boolean {
134
- return this.#byCode.has(code as ErrorCode)
135
- }
136
-
137
- all(): readonly ErrorDef[] {
138
- return [...this.#byCode.values()].sort((a, b) => a.code.localeCompare(b.code))
139
- }
140
-
141
- get size(): number {
142
- return this.#byCode.size
143
- }
144
- }
145
-
146
- export const catalog = new ErrorCatalog()
147
-
148
- export function defineError<const C extends ErrorCode>(
149
- input: DefineErrorInput<C>,
150
- ): ErrorFactory<C> {
151
- return catalog.define(input)
152
- }
@@ -1,19 +0,0 @@
1
- export const NAMESPACES = [
2
- 'auth',
3
- 'quota',
4
- 'rate_limit',
5
- 'feature',
6
- 'db',
7
- 'workflow',
8
- 'queue',
9
- 'ai',
10
- 'search',
11
- 'comms',
12
- 'config',
13
- 'net',
14
- 'internal',
15
- ] as const
16
-
17
- export type Namespace = (typeof NAMESPACES)[number]
18
-
19
- export type ErrorCode = `${Namespace}.${string}`
@@ -1,37 +0,0 @@
1
- import { stdout } from 'node:process'
2
-
3
- export interface Finding {
4
- readonly detail: string
5
- readonly instead: string
6
- readonly file?: string
7
- readonly at?: { readonly line?: number; readonly column?: number }
8
- readonly severity?: 'forbidden' | 'warning'
9
- }
10
-
11
- export const forbids = (finding: Finding): boolean => finding.severity !== 'warning'
12
-
13
- function locate(finding: Finding): string {
14
- if (finding.file === undefined) return ''
15
- const line = finding.at?.line
16
- const column = finding.at?.column
17
- const position = line === undefined ? '' : `:${String(line)}${column === undefined ? '' : `:${String(column)}`}`
18
- return ` (${finding.file}${position})`
19
- }
20
-
21
- export function runChecker(name: string, findings: readonly Finding[], measured: string): void {
22
- if (findings.length === 0) {
23
- stdout.write(`${name}: ${measured} — no findings.\n`)
24
- return
25
- }
26
-
27
- const lines = findings.map(
28
- (finding) => ` ${forbids(finding) ? '' : 'warning: '}${finding.detail}${locate(finding)}\n Instead: ${finding.instead}`,
29
- )
30
- const forbidding = findings.filter(forbids).length
31
- stdout.write(
32
- `${name}: ${String(findings.length)} finding${findings.length === 1 ? '' : 's'}` +
33
- `${forbidding === findings.length ? '' : `, ${String(findings.length - forbidding)} of them warnings`} — ${measured}\n\n` +
34
- `${lines.join('\n')}\n`,
35
- )
36
- if (forbidding > 0) process.exitCode = 1
37
- }