@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,145 @@
1
+ /**
2
+ * Field IDs must come from the application's reviewed collection binding.
3
+ *
4
+ * @param {number} id
5
+ * @param {string} name
6
+ * @param {FieldType} type
7
+ * @param {FieldOptions} [options]
8
+ * @returns {FieldDef}
9
+ */
10
+ export function defineField(id: number, name: string, type: FieldType, options?: FieldOptions): FieldDef;
11
+ /**
12
+ * @param {string} name
13
+ * @param {CollectionOptions} [options]
14
+ * @returns {CollectionBuilder}
15
+ */
16
+ export function collection(name: string, options?: CollectionOptions): CollectionBuilder;
17
+ /**
18
+ * @param {readonly (CollectionSchema | CollectionBuilder)[]} entries
19
+ * @returns {SchemaBuilder}
20
+ */
21
+ export function defineSchema(entries: readonly (CollectionSchema | CollectionBuilder)[]): SchemaBuilder;
22
+ /**
23
+ * @param {SchemaJson | SchemaBuilder} schema
24
+ * @returns {string}
25
+ */
26
+ export function serializeSchema(schema: SchemaJson | SchemaBuilder): string;
27
+ /**
28
+ * @param {SchemaJson} schema
29
+ * @returns {SchemaJson}
30
+ */
31
+ export function normalizeSchema(schema: SchemaJson): SchemaJson;
32
+ /**
33
+ * @param {SchemaJson} schema
34
+ * @returns {void}
35
+ */
36
+ export function validateSchema(schema: SchemaJson): void;
37
+ /**
38
+ * @param {CollectionSchema} schema
39
+ * @returns {void}
40
+ */
41
+ export function validateCollection(schema: CollectionSchema): void;
42
+ /**
43
+ * Validate native values using the accepted codec; never coerce integers or bytes.
44
+ *
45
+ * @param {CollectionSchema} schema
46
+ * @param {Readonly<Record<string, DatabaseValue>>} record
47
+ * @returns {readonly DatabaseField[]}
48
+ */
49
+ export function encodeSchemaFields(schema: CollectionSchema, record: Readonly<Record<string, DatabaseValue>>): readonly DatabaseField[];
50
+ /** @import { DatabaseField, DatabaseValue } from "./database-types.js" */
51
+ /** Pure local declarations. These are not server catalog or migration requests. */
52
+ export const FieldTypes: Readonly<{
53
+ readonly bool: "bool";
54
+ readonly i64: "i64";
55
+ readonly utf8: "utf8";
56
+ readonly bytes: "bytes";
57
+ readonly map: "map";
58
+ readonly array: "array";
59
+ }>;
60
+ export class SchemaValidationError extends Error {
61
+ /**
62
+ * @param {string} message
63
+ */
64
+ constructor(message: string);
65
+ }
66
+ /** Persistent fluent builder; each branch keeps its own declarations. */
67
+ export class CollectionBuilder {
68
+ /**
69
+ * @param {string} name
70
+ * @param {CollectionOptions} [options]
71
+ */
72
+ constructor(name: string, options?: CollectionOptions);
73
+ /**
74
+ * @param {number} id
75
+ * @param {string} name
76
+ * @param {FieldType} type
77
+ * @param {FieldOptions} [options]
78
+ * @returns {CollectionBuilder}
79
+ */
80
+ field(id: number, name: string, type: FieldType, options?: FieldOptions): CollectionBuilder;
81
+ /**
82
+ * @returns {CollectionSchema}
83
+ */
84
+ build(): CollectionSchema;
85
+ /**
86
+ * @returns {string}
87
+ */
88
+ toJSON(): string;
89
+ #private;
90
+ }
91
+ export class SchemaBuilder {
92
+ /**
93
+ * @param {readonly (CollectionSchema | CollectionBuilder)[]} [entries]
94
+ */
95
+ constructor(entries?: readonly (CollectionSchema | CollectionBuilder)[]);
96
+ /**
97
+ * @param {CollectionSchema | CollectionBuilder} entry
98
+ * @returns {SchemaBuilder}
99
+ */
100
+ addCollection(entry: CollectionSchema | CollectionBuilder): SchemaBuilder;
101
+ /**
102
+ * @param {string} name
103
+ * @param {CollectionOptions} [options]
104
+ * @returns {SchemaBuilder}
105
+ */
106
+ collection(name: string, options?: CollectionOptions): SchemaBuilder;
107
+ /**
108
+ * @returns {SchemaJson}
109
+ */
110
+ build(): SchemaJson;
111
+ /**
112
+ * @returns {void}
113
+ */
114
+ validate(): void;
115
+ /**
116
+ * @returns {string}
117
+ */
118
+ toJSON(): string;
119
+ #private;
120
+ }
121
+ export type FieldType = (typeof FieldTypes)[keyof typeof FieldTypes];
122
+ export type FieldOptions = {
123
+ readonly required?: boolean;
124
+ };
125
+ /**
126
+ * `required` refers to field presence; explicit native null remains distinct.
127
+ */
128
+ export type FieldDef = {
129
+ readonly id: number;
130
+ readonly name: string;
131
+ readonly type: FieldType;
132
+ readonly required: boolean;
133
+ };
134
+ export type CollectionSchema = {
135
+ readonly name: string;
136
+ readonly fields: readonly FieldDef[];
137
+ };
138
+ export type SchemaJson = {
139
+ readonly collections: readonly CollectionSchema[];
140
+ };
141
+ export type CollectionOptions = {
142
+ readonly fields?: readonly FieldDef[];
143
+ };
144
+ import type { DatabaseValue } from "./database-types.js";
145
+ import type { DatabaseField } from "./database-types.js";
package/types/sql.d.ts ADDED
@@ -0,0 +1,288 @@
1
+ /**
2
+ * @template {SqlCollectionSchema} S
3
+ * @overload
4
+ * @param {S} schema
5
+ * @returns {SelectBuilder<S>}
6
+ */
7
+ export function select<S extends SqlCollectionSchema>(schema: S): SelectBuilder<S>;
8
+ /**
9
+ * @overload
10
+ * @param {readonly string[]} [columns]
11
+ * @returns {SelectBuilder}
12
+ */
13
+ export function select(columns?: readonly string[] | undefined): SelectBuilder;
14
+ /**
15
+ * @template {SqlCollectionSchema} S
16
+ * @param {S} schema
17
+ * @returns {SelectBuilder<S>}
18
+ */
19
+ export function selectSchema<S extends SqlCollectionSchema>(schema: S): SelectBuilder<S>;
20
+ /**
21
+ * @param {string} sql
22
+ * @param {readonly SqlParameter[]} [parameters]
23
+ * @returns {Query}
24
+ */
25
+ export function raw(sql: string, parameters?: readonly SqlParameter[]): Query;
26
+ /**
27
+ * Validate the client-side read-only SQL allow-list and positional bindings.
28
+ *
29
+ * @param {string} sql
30
+ * @param {readonly SqlParameter[]} [parameters]
31
+ * @returns {void}
32
+ */
33
+ export function validateSql(sql: string, parameters?: readonly SqlParameter[]): void;
34
+ export type Direction = (typeof Direction)[keyof typeof Direction];
35
+ /** @import { CollectionSchema, FieldDef, FieldType } from "./schema.js" */
36
+ /**
37
+ * @typedef {Pick<FieldDef, "name" | "type"> &
38
+ * Partial<Omit<FieldDef, "name" | "type">>} SqlFieldDef
39
+ */
40
+ /**
41
+ * @typedef {{
42
+ * readonly name: string;
43
+ * readonly fields: readonly SqlFieldDef[];
44
+ * } & Partial<Omit<CollectionSchema, "name" | "fields">>} SqlCollectionSchema
45
+ */
46
+ /**
47
+ * @template {SqlCollectionSchema} S
48
+ * @typedef {S["fields"][number]} SchemaField
49
+ */
50
+ /**
51
+ * @template {SqlCollectionSchema} S
52
+ * @typedef {SchemaField<S>} QueryField
53
+ */
54
+ export const Direction: Readonly<{
55
+ readonly Asc: "ASC";
56
+ readonly Desc: "DESC";
57
+ }>;
58
+ /** @typedef {(typeof Direction)[keyof typeof Direction]} Direction */
59
+ /** @typedef {boolean | bigint | number | string | Uint8Array | null} SqlScalar */
60
+ /** @typedef {SqlScalar} SqlParameter */
61
+ export class SqlValidationError extends Error {
62
+ /**
63
+ * @param {string} message
64
+ */
65
+ constructor(message: string);
66
+ /**
67
+ * @override
68
+ * @readonly
69
+ */
70
+ override readonly name: "SqlValidationError";
71
+ /** @readonly */
72
+ readonly code: "invalid_sql";
73
+ }
74
+ /** A validated, parameterized read-only SQL statement. */
75
+ export class Query {
76
+ /**
77
+ * @param {string} sql
78
+ * @param {readonly SqlParameter[]} [parameters]
79
+ * @returns {Query}
80
+ */
81
+ static raw(sql: string, parameters?: readonly SqlParameter[]): Query;
82
+ /**
83
+ * @param {readonly string[]} [columns]
84
+ * @returns {SelectBuilder}
85
+ */
86
+ static select(columns?: readonly string[]): SelectBuilder;
87
+ /**
88
+ * @template {SqlCollectionSchema} S
89
+ * @param {S} schema
90
+ * @returns {SelectBuilder<S>}
91
+ */
92
+ static selectSchema<S extends SqlCollectionSchema>(schema: S): SelectBuilder<S>;
93
+ /**
94
+ * @private
95
+ * @param {string} sql
96
+ * @param {readonly SqlParameter[]} parameters
97
+ */
98
+ private constructor();
99
+ /**
100
+ * @readonly
101
+ * @type {string}
102
+ */
103
+ readonly statement: string;
104
+ /**
105
+ * @returns {readonly SqlParameter[]}
106
+ */
107
+ get parameters(): readonly SqlParameter[];
108
+ /**
109
+ * @returns {QueryDescriptor}
110
+ */
111
+ toDescriptor(): QueryDescriptor;
112
+ #private;
113
+ }
114
+ /**
115
+ * Schema-bound SELECT builder.
116
+ *
117
+ * @template {SqlCollectionSchema} [S=SqlCollectionSchema]
118
+ */
119
+ export class SelectBuilder<S extends SqlCollectionSchema = SqlCollectionSchema> {
120
+ /**
121
+ * @param {readonly string[]} columns
122
+ * @returns {SelectBuilder}
123
+ */
124
+ static fromColumns(columns: readonly string[]): SelectBuilder;
125
+ /**
126
+ * @template {SqlCollectionSchema} T
127
+ * @param {T} schema
128
+ * @returns {SelectBuilder<T>}
129
+ */
130
+ static fromSchema<T extends SqlCollectionSchema>(schema: T): SelectBuilder<T>;
131
+ /**
132
+ * @private
133
+ * @param {{
134
+ * columns: readonly string[];
135
+ * from?: string | undefined;
136
+ * schema?: S | undefined;
137
+ * predicates?: readonly string[];
138
+ * order?: readonly (readonly [string, Direction])[];
139
+ * limit?: number | undefined;
140
+ * offset?: number | undefined;
141
+ * parameters?: readonly SqlParameter[];
142
+ * schemaBound?: boolean;
143
+ * }} input
144
+ */
145
+ private constructor();
146
+ /**
147
+ * @param {QueryField<S>} field
148
+ * @returns {SelectBuilder<S>}
149
+ */
150
+ column(field: QueryField<S>): SelectBuilder<S>;
151
+ /**
152
+ * @param {readonly QueryField<S>[]} fields
153
+ * @returns {SelectBuilder<S>}
154
+ */
155
+ columns(fields: readonly QueryField<S>[]): SelectBuilder<S>;
156
+ /**
157
+ * @param {string} collection
158
+ * @returns {SelectBuilder<S>}
159
+ */
160
+ from(collection: string): SelectBuilder<S>;
161
+ /**
162
+ * @template {SqlParameter} T
163
+ * @param {QueryField<S>} field
164
+ * @param {T} value
165
+ * @returns {SelectBuilder<S>}
166
+ */
167
+ whereEq<T extends SqlParameter>(field: QueryField<S>, value: T): SelectBuilder<S>;
168
+ /**
169
+ * @template {SqlParameter} T
170
+ * @param {QueryField<S>} field
171
+ * @param {T} value
172
+ * @returns {SelectBuilder<S>}
173
+ */
174
+ whereNe<T extends SqlParameter>(field: QueryField<S>, value: T): SelectBuilder<S>;
175
+ /**
176
+ * @template {SqlParameter} T
177
+ * @param {QueryField<S>} field
178
+ * @param {T} value
179
+ * @returns {SelectBuilder<S>}
180
+ */
181
+ whereGt<T extends SqlParameter>(field: QueryField<S>, value: T): SelectBuilder<S>;
182
+ /**
183
+ * @template {SqlParameter} T
184
+ * @param {QueryField<S>} field
185
+ * @param {T} value
186
+ * @returns {SelectBuilder<S>}
187
+ */
188
+ whereGte<T extends SqlParameter>(field: QueryField<S>, value: T): SelectBuilder<S>;
189
+ /**
190
+ * @template {SqlParameter} T
191
+ * @param {QueryField<S>} field
192
+ * @param {T} value
193
+ * @returns {SelectBuilder<S>}
194
+ */
195
+ whereLt<T extends SqlParameter>(field: QueryField<S>, value: T): SelectBuilder<S>;
196
+ /**
197
+ * @template {SqlParameter} T
198
+ * @param {QueryField<S>} field
199
+ * @param {T} value
200
+ * @returns {SelectBuilder<S>}
201
+ */
202
+ whereLte<T extends SqlParameter>(field: QueryField<S>, value: T): SelectBuilder<S>;
203
+ /**
204
+ * @template {SqlParameter} T
205
+ * @param {QueryField<S>} field
206
+ * @param {T} value
207
+ * @returns {SelectBuilder<S>}
208
+ */
209
+ whereLike<T extends SqlParameter>(field: QueryField<S>, value: T): SelectBuilder<S>;
210
+ /**
211
+ * @template {SqlParameter} T
212
+ * @param {QueryField<S>} field
213
+ * @param {readonly T[]} values
214
+ * @returns {SelectBuilder<S>}
215
+ */
216
+ whereIn<T extends SqlParameter>(field: QueryField<S>, values: readonly T[]): SelectBuilder<S>;
217
+ /**
218
+ * @param {SchemaField<S>} field
219
+ * @param {Direction} [direction]
220
+ * @returns {SelectBuilder<S>}
221
+ */
222
+ orderByField(field: SchemaField<S>, direction?: Direction): SelectBuilder<S>;
223
+ /**
224
+ * @param {string} column
225
+ * @param {Direction} [direction]
226
+ * @returns {SelectBuilder<S>}
227
+ */
228
+ orderBy(column: string, direction?: Direction): SelectBuilder<S>;
229
+ /**
230
+ * @param {number} value
231
+ * @returns {SelectBuilder<S>}
232
+ */
233
+ limit(value: number): SelectBuilder<S>;
234
+ /**
235
+ * @param {number} value
236
+ * @returns {SelectBuilder<S>}
237
+ */
238
+ offset(value: number): SelectBuilder<S>;
239
+ /**
240
+ * @param {{
241
+ * readonly limit: number;
242
+ * readonly offset?: number | undefined;
243
+ * }} options
244
+ * @returns {SelectBuilder<S>}
245
+ */
246
+ paginate(options: {
247
+ readonly limit: number;
248
+ readonly offset?: number | undefined;
249
+ }): SelectBuilder<S>;
250
+ /**
251
+ * @param {number} page
252
+ * @param {number} pageSize
253
+ * @returns {SelectBuilder<S>}
254
+ */
255
+ page(page: number, pageSize: number): SelectBuilder<S>;
256
+ /**
257
+ * @returns {Query}
258
+ */
259
+ build(): Query;
260
+ /**
261
+ * @returns {QueryDescriptor}
262
+ */
263
+ toDescriptor(): QueryDescriptor;
264
+ #private;
265
+ }
266
+ /**
267
+ * Validate the client-side read-only SQL allow-list and positional bindings.
268
+ *
269
+ * @param {string} sql
270
+ * @param {readonly SqlParameter[]} [parameters]
271
+ * @returns {void}
272
+ */
273
+ export function validate_sql(sql: string, parameters?: readonly SqlParameter[]): void;
274
+ export type QueryDescriptor = {
275
+ readonly statement: string;
276
+ readonly parameters: readonly SqlParameter[];
277
+ };
278
+ export type SqlFieldDef = Pick<FieldDef, "name" | "type"> & Partial<Omit<FieldDef, "name" | "type">>;
279
+ export type SqlCollectionSchema = {
280
+ readonly name: string;
281
+ readonly fields: readonly SqlFieldDef[];
282
+ } & Partial<Omit<CollectionSchema, "name" | "fields">>;
283
+ export type SchemaField<S extends SqlCollectionSchema> = S["fields"][number];
284
+ export type QueryField<S extends SqlCollectionSchema> = SchemaField<S>;
285
+ export type SqlScalar = boolean | bigint | number | string | Uint8Array | null;
286
+ export type SqlParameter = SqlScalar;
287
+ import type { FieldDef } from "./schema.js";
288
+ import type { CollectionSchema } from "./schema.js";
@@ -0,0 +1,81 @@
1
+ /**
2
+ * The Svelte store contract; `$store` auto-subscription binds to it directly.
3
+ *
4
+ * @typedef {() => void} SvelteUnsubscriber
5
+ */
6
+ /**
7
+ * @template TValue
8
+ * @typedef {(value: TValue) => void} SvelteSubscriber
9
+ */
10
+ /**
11
+ * @template TValue
12
+ * @typedef {{
13
+ * readonly subscribe: (run: SvelteSubscriber<TValue>) => SvelteUnsubscriber;
14
+ * }} SvelteReadable
15
+ */
16
+ /**
17
+ * A query store; `refetch` restarts delivery from a fresh generation, like
18
+ * the React `refetch`.
19
+ *
20
+ * @template TValue
21
+ * @typedef {SvelteReadable<ReactiveQueryState<TValue>> & {
22
+ * readonly refetch: () => void;
23
+ * }} SvelteQuery
24
+ */
25
+ /**
26
+ * One reactive query as a Svelte store. The observer lifecycle follows the
27
+ * store subscription count, so `$query` in a component starts delivery on
28
+ * mount and disposes the transport on unmount. Keep the source object stable
29
+ * between renders.
30
+ *
31
+ * @template TValue
32
+ * @param {ReactiveQuerySource<TValue>} source
33
+ * @param {ReactiveQueryOptions<TValue>} [options]
34
+ * @returns {SvelteQuery<TValue>}
35
+ */
36
+ export function createQuery<TValue>(source: ReactiveQuerySource<TValue>, options?: ReactiveQueryOptions<TValue>): SvelteQuery<TValue>;
37
+ /**
38
+ * @template TValue, TVariables
39
+ * @typedef {SvelteReadable<ReactiveMutationState<TValue>> & {
40
+ * readonly mutate: (variables: TVariables) => void;
41
+ * readonly mutateAsync: (variables: TVariables) => Promise<TValue>;
42
+ * readonly cancel: () => void;
43
+ * readonly reset: () => void;
44
+ * }} SvelteMutation
45
+ */
46
+ /**
47
+ * A durable mutation as a Svelte store; `$mutation.isPending` drives the UI.
48
+ *
49
+ * @template TValue
50
+ * @template [TVariables=void]
51
+ * @param {ReactiveMutationOptions<TValue, TVariables>} options
52
+ * @returns {SvelteMutation<TValue, TVariables>}
53
+ */
54
+ export function createMutation<TValue, TVariables = void>(options: ReactiveMutationOptions<TValue, TVariables>): SvelteMutation<TValue, TVariables>;
55
+ export * from "../react/core.js";
56
+ /**
57
+ * The Svelte store contract; `$store` auto-subscription binds to it directly.
58
+ */
59
+ export type SvelteUnsubscriber = () => void;
60
+ export type SvelteSubscriber<TValue> = (value: TValue) => void;
61
+ export type SvelteReadable<TValue> = {
62
+ readonly subscribe: (run: SvelteSubscriber<TValue>) => SvelteUnsubscriber;
63
+ };
64
+ /**
65
+ * A query store; `refetch` restarts delivery from a fresh generation, like
66
+ * the React `refetch`.
67
+ */
68
+ export type SvelteQuery<TValue> = SvelteReadable<ReactiveQueryState<TValue>> & {
69
+ readonly refetch: () => void;
70
+ };
71
+ export type SvelteMutation<TValue, TVariables> = SvelteReadable<ReactiveMutationState<TValue>> & {
72
+ readonly mutate: (variables: TVariables) => void;
73
+ readonly mutateAsync: (variables: TVariables) => Promise<TValue>;
74
+ readonly cancel: () => void;
75
+ readonly reset: () => void;
76
+ };
77
+ import type { ReactiveQuerySource } from "../react/core.js";
78
+ import type { ReactiveQueryOptions } from "../react/core.js";
79
+ import type { ReactiveMutationOptions } from "../react/core.js";
80
+ import type { ReactiveQueryState } from "../react/core.js";
81
+ import type { ReactiveMutationState } from "../react/core.js";
@@ -0,0 +1,166 @@
1
+ /**
2
+ * @deprecated Retired SQLite/Rust adapter; no C# shape adapter is provided.
3
+ * Options for `createCollection(terrascaleCollectionOptions(...))`.
4
+ *
5
+ * @template {object} T
6
+ * @template {string | number} [TKey=string]
7
+ * @param {TerraScaleTanStackAdapterOptions<T, TKey>} options
8
+ * @returns {TerraScaleTanStackCollectionOptions<T, TKey> & { readonly adapter: TerraScaleTanStackCollectionSync<T, TKey> }}
9
+ */
10
+ export function terrascaleCollectionOptions<T extends object, TKey extends string | number = string>(options: TerraScaleTanStackAdapterOptions<T, TKey>): TerraScaleTanStackCollectionOptions<T, TKey> & {
11
+ readonly adapter: TerraScaleTanStackCollectionSync<T, TKey>;
12
+ };
13
+ /**
14
+ * Every complete native cut owns its mapped values until collection acknowledgment.
15
+ *
16
+ * @template {object} T
17
+ * @template {string | number} [TKey=string]
18
+ */
19
+ export class TerraScaleTanStackCollectionPublisher<T extends object, TKey extends string | number = string> {
20
+ /**
21
+ * @param {TerraScaleTanStackSyncParams<T, TKey>} params
22
+ * @param {(row: DatabaseQueryRow) => T} mapRow
23
+ * @param {(item: T) => TKey} getKey
24
+ */
25
+ constructor(params: TerraScaleTanStackSyncParams<T, TKey>, mapRow: (row: DatabaseQueryRow) => T, getKey: (item: T) => TKey);
26
+ /** @returns {DatabaseViewPosition | undefined} */
27
+ getPosition(): DatabaseViewPosition | undefined;
28
+ /** @returns {void} */
29
+ reset(): void;
30
+ /** @returns {void} */
31
+ dispose(): void;
32
+ /**
33
+ * @param {DatabaseViewSnapshot} snapshot
34
+ * @param {AbortSignal} [externalSignal]
35
+ * @returns {Promise<void>}
36
+ */
37
+ publish(snapshot: DatabaseViewSnapshot, externalSignal?: AbortSignal): Promise<void>;
38
+ #private;
39
+ }
40
+ export class TerraScaleTanStackMutationError extends Error {
41
+ /**
42
+ * @param {Extract<DatabaseResult<DatabaseCommitReceipt>, { readonly ok: false }>["error"]} detail
43
+ */
44
+ constructor(detail: Extract<DatabaseResult<DatabaseCommitReceipt>, {
45
+ readonly ok: false;
46
+ }>["error"]);
47
+ /** @override @readonly */
48
+ override readonly name: "TerraScaleTanStackMutationError";
49
+ /** @readonly @type {Extract<DatabaseResult<DatabaseCommitReceipt>, { readonly ok: false }>["error"]} */
50
+ readonly detail: Extract<DatabaseResult<DatabaseCommitReceipt>, {
51
+ readonly ok: false;
52
+ }>["error"];
53
+ /** @returns {string} */
54
+ get code(): string;
55
+ }
56
+ /**
57
+ * Native HTTP snapshot/poll collection adapter. All durable writes reach the server.
58
+ *
59
+ * @template {object} T
60
+ * @template {string | number} [TKey=string]
61
+ */
62
+ export class TerraScaleTanStackCollectionSync<T extends object, TKey extends string | number = string> {
63
+ /**
64
+ * @param {TerraScaleTanStackAdapterOptions<T, TKey>} options
65
+ */
66
+ constructor(options: TerraScaleTanStackAdapterOptions<T, TKey>);
67
+ /** @returns {TerraScaleTanStackCollectionOptions<T, TKey>} */
68
+ get options(): TerraScaleTanStackCollectionOptions<T, TKey>;
69
+ /** @returns {string | undefined} */
70
+ getCheckpoint(): string | undefined;
71
+ /**
72
+ * Reconnect correctness starts with a fresh, complete authorized snapshot.
73
+ *
74
+ * @returns {void}
75
+ */
76
+ resubscribe(): void;
77
+ /** @returns {void} */
78
+ dispose(): void;
79
+ #private;
80
+ }
81
+ /**
82
+ * Structural TanStack DB callbacks keep this optional integration dependency free.
83
+ */
84
+ export type TerraScaleTanStackChange<T extends object, TKey extends string | number> = {
85
+ readonly type: "insert" | "update";
86
+ readonly value: T;
87
+ } | {
88
+ readonly type: "delete";
89
+ readonly key: TKey;
90
+ };
91
+ export type TerraScaleTanStackSyncParams<T extends object, TKey extends string | number> = {
92
+ readonly collection: unknown;
93
+ readonly begin: (options?: {
94
+ readonly immediate?: boolean;
95
+ }) => void;
96
+ readonly write: (message: TerraScaleTanStackChange<T, TKey>) => void;
97
+ readonly commit: (signal?: AbortSignal) => true | Promise<void>;
98
+ readonly markReady: () => void;
99
+ readonly markError: (error?: unknown) => void;
100
+ readonly truncate: () => void;
101
+ };
102
+ export type TerraScaleTanStackMutation<T extends object = Record<string, unknown>> = {
103
+ readonly mutationId?: string;
104
+ readonly key: string | number;
105
+ readonly original?: Partial<T>;
106
+ readonly modified: T;
107
+ readonly changes?: Partial<T>;
108
+ readonly type: "insert" | "update" | "delete";
109
+ readonly metadata?: unknown;
110
+ };
111
+ export type TerraScaleTanStackTransaction<T extends object = Record<string, unknown>> = {
112
+ readonly id?: string;
113
+ readonly mutations: readonly TerraScaleTanStackMutation<T>[];
114
+ readonly metadata?: Record<string, unknown>;
115
+ };
116
+ export type TerraScaleTanStackMutationRequest<T extends object, TKey extends string | number> = {
117
+ readonly operation: "insert" | "update" | "delete";
118
+ readonly idempotencyKey: string;
119
+ readonly transactionId: string;
120
+ readonly transaction: TerraScaleTanStackTransaction<T>;
121
+ readonly scope: DatabaseScope;
122
+ readonly collection: string;
123
+ readonly signal: AbortSignal;
124
+ readonly keyOf: (item: T) => TKey;
125
+ };
126
+ export type TerraScaleTanStackCollectionOptions<T extends object, TKey extends string | number = string> = {
127
+ readonly id?: string;
128
+ readonly getKey: (item: T) => TKey;
129
+ readonly sync: {
130
+ readonly rowUpdateMode: "full";
131
+ readonly sync: (params: TerraScaleTanStackSyncParams<T, TKey>) => () => void;
132
+ };
133
+ readonly onInsert: (params: {
134
+ readonly transaction: TerraScaleTanStackTransaction<T>;
135
+ }) => Promise<DatabaseCommitReceipt>;
136
+ readonly onUpdate: (params: {
137
+ readonly transaction: TerraScaleTanStackTransaction<T>;
138
+ }) => Promise<DatabaseCommitReceipt>;
139
+ readonly onDelete: (params: {
140
+ readonly transaction: TerraScaleTanStackTransaction<T>;
141
+ }) => Promise<DatabaseCommitReceipt>;
142
+ };
143
+ /**
144
+ * `mapRow` maps the complete native point explicitly; conflicts are never
145
+ * flattened. `prepareMutation` prepares through this same client. The adapter
146
+ * sends the resulting commit to the server once; TanStack owns its reversible
147
+ * optimistic presentation.
148
+ */
149
+ export type TerraScaleTanStackAdapterOptions<T extends object, TKey extends string | number = string> = DatabaseQueryOptions & {
150
+ readonly client: TerraBaseClient;
151
+ readonly mapRow: (row: DatabaseQueryRow) => T;
152
+ readonly getKey: (item: T) => TKey;
153
+ readonly id?: string;
154
+ readonly prepareMutation?: (request: TerraScaleTanStackMutationRequest<T, TKey>) => Promise<PreparedDatabaseCommit>;
155
+ readonly idempotencyKey?: (transaction: TerraScaleTanStackTransaction<T>) => string;
156
+ readonly signal?: AbortSignal;
157
+ };
158
+ import type { DatabaseViewPosition } from "../database-view.js";
159
+ import type { DatabaseViewSnapshot } from "../database-view.js";
160
+ import type { DatabaseQueryRow } from "../database-types.js";
161
+ import type { DatabaseCommitReceipt } from "../database-types.js";
162
+ import type { DatabaseResult } from "../database-types.js";
163
+ import type { DatabaseScope } from "../database-types.js";
164
+ import type { DatabaseQueryOptions } from "../database-view.js";
165
+ import type { TerraBaseClient } from "../local/legacy-client.js";
166
+ import type { PreparedDatabaseCommit } from "../local/legacy-client.js";
@@ -0,0 +1,19 @@
1
+ /**
2
+ * ts-auth issues from its regional host, https://<region>.auth.terrascale.tech.
3
+ * Behind the Atlas proxy that issuer's region is called directly: Atlas could
4
+ * rank another region, which is another issuer.
5
+ * @param {string} issuer
6
+ * @returns {string | undefined}
7
+ */
8
+ export function regionalIssuerOrigin(issuer: string): string | undefined;
9
+ /** The public auth routing document, validated before any credentials are sent. */
10
+ export class TsAuthEndpointDiscovery {
11
+ /** @param {typeof globalThis.fetch} fetchHandler */
12
+ constructor(fetchHandler: typeof globalThis.fetch);
13
+ /**
14
+ * @param {AbortSignal} [signal]
15
+ * @returns {Promise<readonly string[]>}
16
+ */
17
+ endpoints(signal?: AbortSignal): Promise<readonly string[]>;
18
+ #private;
19
+ }