@terrascale/sdk 0.0.0-stage → 0.0.2

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 (89) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/LICENSE +202 -0
  3. package/README.md +202 -2
  4. package/package.json +152 -4
  5. package/sdk-v1-route-manifest.json +2330 -0
  6. package/src/admin.js +9 -0
  7. package/src/better-auth.js +14 -0
  8. package/src/config.js +121 -0
  9. package/src/database-codec.js +845 -0
  10. package/src/database-types.js +237 -0
  11. package/src/database-view.js +423 -0
  12. package/src/database.js +2 -0
  13. package/src/http.js +898 -0
  14. package/src/index.js +62 -0
  15. package/src/local/authentication.js +47 -0
  16. package/src/local/better-auth.js +517 -0
  17. package/src/local/cli.js +51 -0
  18. package/src/local/context.js +23 -0
  19. package/src/local/environment.js +109 -0
  20. package/src/local/index.js +206 -0
  21. package/src/local/legacy-client.js +411 -0
  22. package/src/local/router.js +999 -0
  23. package/src/local/server.js +664 -0
  24. package/src/local/store.js +530 -0
  25. package/src/local/test-environment.js +74 -0
  26. package/src/management-contracts.js +72 -0
  27. package/src/management.js +12 -0
  28. package/src/native-origin.js +75 -0
  29. package/src/postgres.js +496 -0
  30. package/src/react/core.js +743 -0
  31. package/src/react/index.js +99 -0
  32. package/src/result.js +251 -0
  33. package/src/schema.js +366 -0
  34. package/src/sql.js +996 -0
  35. package/src/svelte/index.js +129 -0
  36. package/src/tanstack/index.js +512 -0
  37. package/src/ts-auth-discovery.js +207 -0
  38. package/src/ts-auth.js +3498 -0
  39. package/src/v1/decode.js +118 -0
  40. package/src/v1/errors.js +185 -0
  41. package/src/v1/filter.js +230 -0
  42. package/src/v1/ids.js +119 -0
  43. package/src/v1/json.js +335 -0
  44. package/src/v1/routes.js +57 -0
  45. package/src/v1/shapes.js +145 -0
  46. package/src/v1/terrabase-v1.js +722 -0
  47. package/src/v1/transport.js +324 -0
  48. package/types/admin.d.ts +6 -0
  49. package/types/better-auth.d.ts +8 -0
  50. package/types/config.d.ts +58 -0
  51. package/types/database-codec.d.ts +111 -0
  52. package/types/database-types.d.ts +213 -0
  53. package/types/database-view.d.ts +184 -0
  54. package/types/database.d.ts +2 -0
  55. package/types/http.d.ts +47 -0
  56. package/types/index.d.ts +43 -0
  57. package/types/local/authentication.d.ts +11 -0
  58. package/types/local/better-auth.d.ts +33 -0
  59. package/types/local/cli.d.ts +2 -0
  60. package/types/local/context.d.ts +14 -0
  61. package/types/local/environment.d.ts +23 -0
  62. package/types/local/index.d.ts +96 -0
  63. package/types/local/legacy-client.d.ts +94 -0
  64. package/types/local/router.d.ts +66 -0
  65. package/types/local/server.d.ts +54 -0
  66. package/types/local/store.d.ts +106 -0
  67. package/types/local/test-environment.d.ts +25 -0
  68. package/types/management-contracts.d.ts +44 -0
  69. package/types/management.d.ts +6 -0
  70. package/types/native-origin.d.ts +23 -0
  71. package/types/postgres.d.ts +124 -0
  72. package/types/react/core.d.ts +366 -0
  73. package/types/react/index.d.ts +54 -0
  74. package/types/result.d.ts +161 -0
  75. package/types/schema.d.ts +145 -0
  76. package/types/sql.d.ts +288 -0
  77. package/types/svelte/index.d.ts +81 -0
  78. package/types/tanstack/index.d.ts +166 -0
  79. package/types/ts-auth-discovery.d.ts +19 -0
  80. package/types/ts-auth.d.ts +1826 -0
  81. package/types/v1/decode.d.ts +119 -0
  82. package/types/v1/errors.d.ts +107 -0
  83. package/types/v1/filter.d.ts +148 -0
  84. package/types/v1/ids.d.ts +44 -0
  85. package/types/v1/json.d.ts +92 -0
  86. package/types/v1/routes.d.ts +26 -0
  87. package/types/v1/shapes.d.ts +78 -0
  88. package/types/v1/terrabase-v1.d.ts +374 -0
  89. package/types/v1/transport.d.ts +117 -0
@@ -0,0 +1,366 @@
1
+ /**
2
+ * @template TValue
3
+ * @typedef {{ readonly kind: "snapshot" | "data"; readonly value: TValue }
4
+ * | { readonly kind: "reset"; readonly reset: ReactiveReset<TValue> }
5
+ * | { readonly kind: "error"; readonly error: unknown }} ReactiveHttpEvent
6
+ */
7
+ /**
8
+ * Typed boundary for the owning HTTP contract. Implementations perform the
9
+ * documented request and polling protocol; this adapter only maps events to
10
+ * the hook's observer and propagates AbortSignal.
11
+ *
12
+ * @template TRequest, TValue
13
+ * @typedef {{
14
+ * readonly subscribe: (
15
+ * request: TRequest,
16
+ * observer: { readonly event: (event: ReactiveHttpEvent<TValue>) => void },
17
+ * context: ReactiveSubscriptionContext,
18
+ * ) => ReactiveDisposer | void | Promise<ReactiveDisposer | void>;
19
+ * }} ReactiveHttpTransport
20
+ */
21
+ /**
22
+ * @template TRequest, TValue
23
+ * @param {ReactiveHttpTransport<TRequest, TValue>} transport
24
+ * @param {TRequest} request
25
+ * @param {string | readonly unknown[]} [key]
26
+ * @returns {ReactiveQuerySource<TValue>}
27
+ */
28
+ export function createReactiveHttpQuery<TRequest, TValue>(transport: ReactiveHttpTransport<TRequest, TValue>, request: TRequest, key?: string | readonly unknown[]): ReactiveQuerySource<TValue>;
29
+ /** @typedef {import("../database-view.js").DatabaseQueryCallbacks} DatabaseQueryCallbacks */
30
+ /** @typedef {import("../database-view.js").DatabaseQueryOptions} DatabaseQueryOptions */
31
+ /** @typedef {import("../database-view.js").DatabaseQuerySource} DatabaseQuerySource */
32
+ /** @typedef {import("../database-view.js").DatabaseViewBinding} DatabaseViewBinding */
33
+ /** @typedef {import("../database-view.js").DatabaseViewPosition} DatabaseViewPosition */
34
+ /** @typedef {import("../database-view.js").DatabaseViewSnapshot} DatabaseViewSnapshot */
35
+ /**
36
+ * A subscription cleanup returned by a typed reactive transport.
37
+ *
38
+ * @typedef {(() => void) | { readonly dispose: () => void } | { readonly unsubscribe: () => void }} ReactiveDisposer
39
+ */
40
+ /**
41
+ * @typedef {{
42
+ * readonly signal: AbortSignal;
43
+ * }} ReactiveSubscriptionContext
44
+ */
45
+ /**
46
+ * @template TValue
47
+ * @typedef {{
48
+ * readonly next: (value: TValue) => void;
49
+ * readonly error: (error: unknown) => void;
50
+ * readonly reset: (reset: ReactiveReset<TValue>) => void;
51
+ * }} ReactiveQueryCallbacks
52
+ */
53
+ /**
54
+ * The operation owned by the public reactive contract. It may use HTTP
55
+ * long-polling or WebSocket delivery; the hook does not know or care which.
56
+ *
57
+ * @template TValue
58
+ * @typedef {{
59
+ * readonly key?: string | readonly unknown[];
60
+ * readonly subscribe: (
61
+ * observer: ReactiveQueryCallbacks<TValue>,
62
+ * context: ReactiveSubscriptionContext,
63
+ * ) => ReactiveDisposer | void | Promise<ReactiveDisposer | void>;
64
+ * }} ReactiveQuerySource
65
+ */
66
+ /**
67
+ * @typedef {"checkpoint-expired"
68
+ * | "retention-advanced"
69
+ * | "generation-changed"
70
+ * | "checkpoint-not-current"
71
+ * | "view-diverged"
72
+ * | "oversized"
73
+ * | "invalid-operations"
74
+ * | "invalid-checkpoint"
75
+ * | "backpressure"
76
+ * | (string & {})} ReactiveResetReason
77
+ */
78
+ /**
79
+ * A server-authorized reset. The checkpoint remains opaque to the hook.
80
+ *
81
+ * @template TValue
82
+ * @typedef {{
83
+ * readonly reason: ReactiveResetReason;
84
+ * readonly data?: TValue;
85
+ * readonly checkpoint?: string | Uint8Array;
86
+ * readonly code?: string;
87
+ * readonly message?: string;
88
+ * }} ReactiveReset
89
+ */
90
+ /** @typedef {"subscription" | "transport" | "remote" | "cancelled" | "mutation"} ReactiveErrorKind */
91
+ /**
92
+ * @typedef {{
93
+ * readonly kind: ReactiveErrorKind;
94
+ * readonly code: string;
95
+ * readonly message: string;
96
+ * readonly cause?: unknown;
97
+ * readonly terraScale?: TerraScaleError;
98
+ * readonly database?: Extract<DatabaseResult<never>, { readonly ok: false }>["error"];
99
+ * }} ReactiveError
100
+ */
101
+ /** @typedef {"pending" | "success" | "error" | "reset"} ReactiveQueryStatus */
102
+ /**
103
+ * @template TValue
104
+ * @typedef {{
105
+ * readonly status: ReactiveQueryStatus;
106
+ * readonly data: TValue | undefined;
107
+ * readonly error: ReactiveError | undefined;
108
+ * readonly reset: ReactiveReset<TValue> | undefined;
109
+ * readonly isLoading: boolean;
110
+ * readonly isFetching: boolean;
111
+ * readonly isStale: boolean;
112
+ * }} ReactiveQueryState
113
+ */
114
+ /**
115
+ * @template TValue
116
+ * @typedef {{
117
+ * readonly enabled?: boolean;
118
+ * readonly initialData?: TValue;
119
+ * }} ReactiveQueryOptions
120
+ */
121
+ /**
122
+ * Framework-neutral query observer used by useQuery and SSR-safe tests.
123
+ *
124
+ * @template TValue
125
+ */
126
+ export class ReactiveQueryObserver<TValue> {
127
+ /**
128
+ * @param {ReactiveQuerySource<TValue>} source
129
+ * @param {ReactiveQueryOptions<TValue>} [options]
130
+ */
131
+ constructor(source: ReactiveQuerySource<TValue>, options?: ReactiveQueryOptions<TValue>);
132
+ /** @returns {ReactiveQueryState<TValue>} */
133
+ getSnapshot: () => ReactiveQueryState<TValue>;
134
+ /** @returns {ReactiveQueryState<TValue>} */
135
+ getServerSnapshot: () => ReactiveQueryState<TValue>;
136
+ /**
137
+ * Updates the small, hook-facing option set without replacing the external
138
+ * store. React may render a hook with a new options object while preserving
139
+ * the observer; an `enabled` transition must therefore start/stop delivery
140
+ * at the subscription boundary instead of leaving a stale subscription.
141
+ *
142
+ * @param {ReactiveQueryOptions<TValue>} [options]
143
+ * @returns {void}
144
+ */
145
+ updateOptions(options?: ReactiveQueryOptions<TValue>): void;
146
+ /**
147
+ * @param {() => void} listener
148
+ * @returns {() => void}
149
+ */
150
+ subscribe: (listener: () => void) => () => void;
151
+ /** @returns {void} */
152
+ start(): void;
153
+ /**
154
+ * Aborts HTTP polling and disposes the current transport subscription.
155
+ *
156
+ * @returns {void}
157
+ */
158
+ dispose(): void;
159
+ /**
160
+ * Restart only while an enabled query has live observers.
161
+ *
162
+ * @returns {void}
163
+ */
164
+ refetch(): void;
165
+ #private;
166
+ }
167
+ /**
168
+ * @typedef {{
169
+ * readonly signal: AbortSignal;
170
+ * readonly idempotencyKey: string;
171
+ * }} ReactiveMutationContext
172
+ */
173
+ /** @typedef {void | (() => void) | { readonly rollback: () => void }} OptimisticRollback */
174
+ /**
175
+ * @template TValue, TVariables
176
+ * @typedef {{
177
+ * readonly mutationFn: (
178
+ * variables: TVariables,
179
+ * context: ReactiveMutationContext,
180
+ * ) => Promise<TValue | TerraScaleResult<TValue> | DatabaseResult<TValue>>;
181
+ * readonly idempotencyKey?: string | ((variables: TVariables) => string);
182
+ * readonly onMutate?: (variables: TVariables, context: ReactiveMutationContext) => OptimisticRollback | Promise<OptimisticRollback>;
183
+ * }} ReactiveMutationOptions
184
+ */
185
+ /** @typedef {"idle" | "pending" | "success" | "error" | "cancelled"} ReactiveMutationStatus */
186
+ /**
187
+ * @template TValue
188
+ * @typedef {{
189
+ * readonly status: ReactiveMutationStatus;
190
+ * readonly data: TValue | undefined;
191
+ * readonly error: ReactiveError | undefined;
192
+ * readonly idempotencyKey: string | undefined;
193
+ * readonly isPending: boolean;
194
+ * }} ReactiveMutationState
195
+ */
196
+ /**
197
+ * @template TValue, TVariables
198
+ */
199
+ export class ReactiveMutationObserver<TValue, TVariables> {
200
+ /**
201
+ * @param {ReactiveMutationOptions<TValue, TVariables>} options
202
+ */
203
+ constructor(options: ReactiveMutationOptions<TValue, TVariables>);
204
+ /**
205
+ * Keep callbacks current when a component re-renders without replacing the
206
+ * observer (the normal `useMutation` lifecycle). A mutation already running
207
+ * captures the callbacks it started with, so a render cannot redirect an
208
+ * in-flight durable request.
209
+ *
210
+ * @param {ReactiveMutationOptions<TValue, TVariables>} options
211
+ * @returns {void}
212
+ */
213
+ updateOptions(options: ReactiveMutationOptions<TValue, TVariables>): void;
214
+ /** @returns {ReactiveMutationState<TValue>} */
215
+ getSnapshot: () => ReactiveMutationState<TValue>;
216
+ /**
217
+ * @param {() => void} listener
218
+ * @returns {() => void}
219
+ */
220
+ subscribe: (listener: () => void) => () => void;
221
+ /**
222
+ * @param {TVariables} variables
223
+ * @returns {Promise<TValue>}
224
+ */
225
+ mutateAsync(variables: TVariables): Promise<TValue>;
226
+ /**
227
+ * @param {TVariables} variables
228
+ * @returns {void}
229
+ */
230
+ mutate(variables: TVariables): void;
231
+ /**
232
+ * Cancels the durable request and immediately rolls back its presentation.
233
+ *
234
+ * @returns {void}
235
+ */
236
+ cancel(): void;
237
+ /** @returns {void} */
238
+ reset(): void;
239
+ /** @returns {void} */
240
+ dispose(): void;
241
+ #private;
242
+ }
243
+ export class ReactiveMutationError extends Error {
244
+ /**
245
+ * @param {string} code
246
+ * @param {string} message
247
+ * @param {unknown} [cause]
248
+ */
249
+ constructor(code: string, message: string, cause?: unknown);
250
+ /** @override @readonly */
251
+ override readonly name: "ReactiveMutationError";
252
+ /** @readonly @type {string} */
253
+ readonly code: string;
254
+ /** @override @readonly @type {unknown} */
255
+ override readonly cause: unknown;
256
+ }
257
+ export type ReactiveHttpEvent<TValue> = {
258
+ readonly kind: "snapshot" | "data";
259
+ readonly value: TValue;
260
+ } | {
261
+ readonly kind: "reset";
262
+ readonly reset: ReactiveReset<TValue>;
263
+ } | {
264
+ readonly kind: "error";
265
+ readonly error: unknown;
266
+ };
267
+ /**
268
+ * Typed boundary for the owning HTTP contract. Implementations perform the
269
+ * documented request and polling protocol; this adapter only maps events to
270
+ * the hook's observer and propagates AbortSignal.
271
+ */
272
+ export type ReactiveHttpTransport<TRequest, TValue> = {
273
+ readonly subscribe: (request: TRequest, observer: {
274
+ readonly event: (event: ReactiveHttpEvent<TValue>) => void;
275
+ }, context: ReactiveSubscriptionContext) => ReactiveDisposer | void | Promise<ReactiveDisposer | void>;
276
+ };
277
+ export type DatabaseQueryCallbacks = import("../database-view.js").DatabaseQueryCallbacks;
278
+ export type DatabaseQueryOptions = import("../database-view.js").DatabaseQueryOptions;
279
+ export type DatabaseQuerySource = import("../database-view.js").DatabaseQuerySource;
280
+ export type DatabaseViewBinding = import("../database-view.js").DatabaseViewBinding;
281
+ export type DatabaseViewPosition = import("../database-view.js").DatabaseViewPosition;
282
+ export type DatabaseViewSnapshot = import("../database-view.js").DatabaseViewSnapshot;
283
+ /**
284
+ * A subscription cleanup returned by a typed reactive transport.
285
+ */
286
+ export type ReactiveDisposer = (() => void) | {
287
+ readonly dispose: () => void;
288
+ } | {
289
+ readonly unsubscribe: () => void;
290
+ };
291
+ export type ReactiveSubscriptionContext = {
292
+ readonly signal: AbortSignal;
293
+ };
294
+ export type ReactiveQueryCallbacks<TValue> = {
295
+ readonly next: (value: TValue) => void;
296
+ readonly error: (error: unknown) => void;
297
+ readonly reset: (reset: ReactiveReset<TValue>) => void;
298
+ };
299
+ /**
300
+ * The operation owned by the public reactive contract. It may use HTTP
301
+ * long-polling or WebSocket delivery; the hook does not know or care which.
302
+ */
303
+ export type ReactiveQuerySource<TValue> = {
304
+ readonly key?: string | readonly unknown[];
305
+ readonly subscribe: (observer: ReactiveQueryCallbacks<TValue>, context: ReactiveSubscriptionContext) => ReactiveDisposer | void | Promise<ReactiveDisposer | void>;
306
+ };
307
+ export type ReactiveResetReason = "checkpoint-expired" | "retention-advanced" | "generation-changed" | "checkpoint-not-current" | "view-diverged" | "oversized" | "invalid-operations" | "invalid-checkpoint" | "backpressure" | (string & {});
308
+ /**
309
+ * A server-authorized reset. The checkpoint remains opaque to the hook.
310
+ */
311
+ export type ReactiveReset<TValue> = {
312
+ readonly reason: ReactiveResetReason;
313
+ readonly data?: TValue;
314
+ readonly checkpoint?: string | Uint8Array;
315
+ readonly code?: string;
316
+ readonly message?: string;
317
+ };
318
+ export type ReactiveErrorKind = "subscription" | "transport" | "remote" | "cancelled" | "mutation";
319
+ export type ReactiveError = {
320
+ readonly kind: ReactiveErrorKind;
321
+ readonly code: string;
322
+ readonly message: string;
323
+ readonly cause?: unknown;
324
+ readonly terraScale?: TerraScaleError;
325
+ readonly database?: Extract<DatabaseResult<never>, {
326
+ readonly ok: false;
327
+ }>["error"];
328
+ };
329
+ export type ReactiveQueryStatus = "pending" | "success" | "error" | "reset";
330
+ export type ReactiveQueryState<TValue> = {
331
+ readonly status: ReactiveQueryStatus;
332
+ readonly data: TValue | undefined;
333
+ readonly error: ReactiveError | undefined;
334
+ readonly reset: ReactiveReset<TValue> | undefined;
335
+ readonly isLoading: boolean;
336
+ readonly isFetching: boolean;
337
+ readonly isStale: boolean;
338
+ };
339
+ export type ReactiveQueryOptions<TValue> = {
340
+ readonly enabled?: boolean;
341
+ readonly initialData?: TValue;
342
+ };
343
+ export type ReactiveMutationContext = {
344
+ readonly signal: AbortSignal;
345
+ readonly idempotencyKey: string;
346
+ };
347
+ export type OptimisticRollback = void | (() => void) | {
348
+ readonly rollback: () => void;
349
+ };
350
+ export type ReactiveMutationOptions<TValue, TVariables> = {
351
+ readonly mutationFn: (variables: TVariables, context: ReactiveMutationContext) => Promise<TValue | TerraScaleResult<TValue> | DatabaseResult<TValue>>;
352
+ readonly idempotencyKey?: string | ((variables: TVariables) => string);
353
+ readonly onMutate?: (variables: TVariables, context: ReactiveMutationContext) => OptimisticRollback | Promise<OptimisticRollback>;
354
+ };
355
+ export type ReactiveMutationStatus = "idle" | "pending" | "success" | "error" | "cancelled";
356
+ export type ReactiveMutationState<TValue> = {
357
+ readonly status: ReactiveMutationStatus;
358
+ readonly data: TValue | undefined;
359
+ readonly error: ReactiveError | undefined;
360
+ readonly idempotencyKey: string | undefined;
361
+ readonly isPending: boolean;
362
+ };
363
+ import type { TerraScaleError } from "../result.js";
364
+ import type { DatabaseResult } from "../database-types.js";
365
+ import type { TerraScaleResult } from "../result.js";
366
+ export { createDatabaseQuery, DatabaseSubscriptionError, DatabaseSubscriptionView } from "../database-view.js";
@@ -0,0 +1,54 @@
1
+ /**
2
+ * React's external-store primitive gives useQuery one SSR-safe snapshot and
3
+ * makes every server update flow through the typed reactive subscription.
4
+ * Keep the source object stable between renders.
5
+ *
6
+ * @template TValue
7
+ * @param {ReactiveQuerySource<TValue>} source
8
+ * @param {ReactiveQueryOptions<TValue>} [options]
9
+ * @returns {ReactiveQueryState<TValue> & { readonly refetch: () => void }}
10
+ */
11
+ export function useQuery<TValue>(source: ReactiveQuerySource<TValue>, options?: ReactiveQueryOptions<TValue>): ReactiveQueryState<TValue> & {
12
+ readonly refetch: () => void;
13
+ };
14
+ /**
15
+ * @template TValue, TVariables
16
+ * @typedef {ReactiveMutationState<TValue> & {
17
+ * readonly mutate: (variables: TVariables) => void;
18
+ * readonly mutateAsync: (variables: TVariables) => Promise<TValue>;
19
+ * readonly cancel: () => void;
20
+ * readonly reset: () => void;
21
+ * }} UseMutationResult
22
+ */
23
+ /**
24
+ * A durable mutation always receives one idempotency identity and AbortSignal.
25
+ * The optional onMutate result is a reversible presentation rollback; it is
26
+ * never an offline queue and is removed on either acceptance or rejection.
27
+ *
28
+ * @template TValue
29
+ * @template [TVariables=void]
30
+ * @param {ReactiveMutationOptions<TValue, TVariables>} options
31
+ * @returns {UseMutationResult<TValue, TVariables>}
32
+ */
33
+ export function useMutation<TValue, TVariables = void>(options: ReactiveMutationOptions<TValue, TVariables>): UseMutationResult<TValue, TVariables>;
34
+ /**
35
+ * Explicitly disposes a mutation observer created outside a React tree.
36
+ *
37
+ * @template TValue, TVariables
38
+ * @param {ReactiveMutationObserver<TValue, TVariables>} observer
39
+ * @returns {void}
40
+ */
41
+ export function disposeMutation<TValue, TVariables>(observer: ReactiveMutationObserver<TValue, TVariables>): void;
42
+ export * from "./core.js";
43
+ export type UseMutationResult<TValue, TVariables> = ReactiveMutationState<TValue> & {
44
+ readonly mutate: (variables: TVariables) => void;
45
+ readonly mutateAsync: (variables: TVariables) => Promise<TValue>;
46
+ readonly cancel: () => void;
47
+ readonly reset: () => void;
48
+ };
49
+ import type { ReactiveQuerySource } from "./core.js";
50
+ import type { ReactiveQueryOptions } from "./core.js";
51
+ import type { ReactiveQueryState } from "./core.js";
52
+ import type { ReactiveMutationOptions } from "./core.js";
53
+ import { ReactiveMutationObserver } from "./core.js";
54
+ import type { ReactiveMutationState } from "./core.js";
@@ -0,0 +1,161 @@
1
+ /**
2
+ * @typedef {(
3
+ * | "authentication"
4
+ * | "authorization"
5
+ * | "conflict"
6
+ * | "domain"
7
+ * | "invalid-response"
8
+ * | "not-found"
9
+ * | "rate-limit"
10
+ * | "server"
11
+ * | "transport"
12
+ * | "unavailable"
13
+ * | "validation"
14
+ * )} TerraScaleErrorKind
15
+ */
16
+ /**
17
+ * The stable category names published by the TerraScale error envelope.
18
+ * @typedef {(
19
+ * | "Validation"
20
+ * | "Authentication"
21
+ * | "Authorization"
22
+ * | "NotFound"
23
+ * | "Conflict"
24
+ * | "RateLimit"
25
+ * | "Schema"
26
+ * | "Query"
27
+ * | "Placement"
28
+ * | "AutoFix"
29
+ * | "AutoIndex"
30
+ * | "Sandbox"
31
+ * | "System"
32
+ * )} TerraScaleErrorCategory
33
+ */
34
+ /**
35
+ * @typedef {{
36
+ * readonly path?: string;
37
+ * readonly message: string;
38
+ * readonly code?: string;
39
+ * }} TerraScaleValidationIssue
40
+ */
41
+ /**
42
+ * `fix` is optional producer-provided remediation from the published error body.
43
+ * `retryAfter` is the retry delay from the Retry-After header, in milliseconds,
44
+ * when the server sent one.
45
+ * @typedef {{
46
+ * readonly kind: TerraScaleErrorKind;
47
+ * readonly code: string;
48
+ * readonly message: string;
49
+ * readonly fix?: string | undefined;
50
+ * readonly retryAfter?: number | undefined;
51
+ * readonly category?: TerraScaleErrorCategory | undefined;
52
+ * readonly detail?: string | undefined;
53
+ * readonly suggestedAction?: string | undefined;
54
+ * readonly docsUrl?: string | undefined;
55
+ * readonly traceId?: string | undefined;
56
+ * readonly status?: number | undefined;
57
+ * readonly target?: string | undefined;
58
+ * readonly requestId?: string | undefined;
59
+ * readonly validation?: readonly TerraScaleValidationIssue[] | undefined;
60
+ * readonly details?: unknown | undefined;
61
+ * }} TerraScaleError
62
+ */
63
+ /**
64
+ * @template TValue
65
+ * @typedef {{
66
+ * readonly ok: true;
67
+ * readonly routeName: string;
68
+ * readonly status: number;
69
+ * readonly headers: Headers;
70
+ * readonly value: TValue;
71
+ * }} TerraScaleSuccess
72
+ */
73
+ /**
74
+ * @typedef {{
75
+ * readonly ok: false;
76
+ * readonly routeName: string;
77
+ * readonly status?: number | undefined;
78
+ * readonly headers?: Headers | undefined;
79
+ * readonly error: TerraScaleError;
80
+ * readonly body?: unknown | undefined;
81
+ * }} TerraScaleFailure
82
+ */
83
+ /**
84
+ * @template TValue
85
+ * @typedef {TerraScaleFailure | TerraScaleSuccess<TValue>} TerraScaleResult
86
+ */
87
+ /**
88
+ * @template TValue
89
+ * @param {string} routeName
90
+ * @param {number} status
91
+ * @param {Headers} headers
92
+ * @param {TValue} value
93
+ * @returns {TerraScaleSuccess<TValue>}
94
+ */
95
+ export function ok<TValue>(routeName: string, status: number, headers: Headers, value: TValue): TerraScaleSuccess<TValue>;
96
+ /**
97
+ * @param {string} routeName
98
+ * @param {TerraScaleError} error
99
+ * @param {number} [status]
100
+ * @param {Headers} [headers]
101
+ * @param {unknown} [body]
102
+ * @returns {TerraScaleFailure}
103
+ */
104
+ export function err(routeName: string, error: TerraScaleError, status?: number, headers?: Headers, body?: unknown): TerraScaleFailure;
105
+ /**
106
+ * Makes values safe to retain in a public result. Error bodies and transport
107
+ * failures are producer-controlled and may contain credentials even when the
108
+ * published error contract does not. Keep this deliberately conservative:
109
+ * sensitive fields are replaced and secret-bearing URLs are never preserved.
110
+ * @param {unknown} value
111
+ * @returns {unknown}
112
+ */
113
+ export function sanitizeDiagnostic(value: unknown): unknown;
114
+ export type TerraScaleErrorKind = ("authentication" | "authorization" | "conflict" | "domain" | "invalid-response" | "not-found" | "rate-limit" | "server" | "transport" | "unavailable" | "validation");
115
+ /**
116
+ * The stable category names published by the TerraScale error envelope.
117
+ */
118
+ export type TerraScaleErrorCategory = ("Validation" | "Authentication" | "Authorization" | "NotFound" | "Conflict" | "RateLimit" | "Schema" | "Query" | "Placement" | "AutoFix" | "AutoIndex" | "Sandbox" | "System");
119
+ export type TerraScaleValidationIssue = {
120
+ readonly path?: string;
121
+ readonly message: string;
122
+ readonly code?: string;
123
+ };
124
+ /**
125
+ * `fix` is optional producer-provided remediation from the published error body.
126
+ * `retryAfter` is the retry delay from the Retry-After header, in milliseconds,
127
+ * when the server sent one.
128
+ */
129
+ export type TerraScaleError = {
130
+ readonly kind: TerraScaleErrorKind;
131
+ readonly code: string;
132
+ readonly message: string;
133
+ readonly fix?: string | undefined;
134
+ readonly retryAfter?: number | undefined;
135
+ readonly category?: TerraScaleErrorCategory | undefined;
136
+ readonly detail?: string | undefined;
137
+ readonly suggestedAction?: string | undefined;
138
+ readonly docsUrl?: string | undefined;
139
+ readonly traceId?: string | undefined;
140
+ readonly status?: number | undefined;
141
+ readonly target?: string | undefined;
142
+ readonly requestId?: string | undefined;
143
+ readonly validation?: readonly TerraScaleValidationIssue[] | undefined;
144
+ readonly details?: unknown | undefined;
145
+ };
146
+ export type TerraScaleSuccess<TValue> = {
147
+ readonly ok: true;
148
+ readonly routeName: string;
149
+ readonly status: number;
150
+ readonly headers: Headers;
151
+ readonly value: TValue;
152
+ };
153
+ export type TerraScaleFailure = {
154
+ readonly ok: false;
155
+ readonly routeName: string;
156
+ readonly status?: number | undefined;
157
+ readonly headers?: Headers | undefined;
158
+ readonly error: TerraScaleError;
159
+ readonly body?: unknown | undefined;
160
+ };
161
+ export type TerraScaleResult<TValue> = TerraScaleFailure | TerraScaleSuccess<TValue>;