terrascale 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +143 -0
  3. package/package.json +159 -0
  4. package/sdk-current-contract.json +27 -0
  5. package/sdk-route-manifest.json +67 -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 +422 -0
  12. package/src/database.js +420 -0
  13. package/src/discovery.js +374 -0
  14. package/src/http.js +887 -0
  15. package/src/index.js +79 -0
  16. package/src/local/authentication.js +47 -0
  17. package/src/local/better-auth.js +517 -0
  18. package/src/local/cli.js +51 -0
  19. package/src/local/context.js +23 -0
  20. package/src/local/environment.js +109 -0
  21. package/src/local/index.js +204 -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 +494 -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 +511 -0
  37. package/src/ts-auth-discovery.js +190 -0
  38. package/src/ts-auth.js +3497 -0
  39. package/types/admin.d.ts +6 -0
  40. package/types/better-auth.d.ts +8 -0
  41. package/types/config.d.ts +58 -0
  42. package/types/database-codec.d.ts +111 -0
  43. package/types/database-types.d.ts +213 -0
  44. package/types/database-view.d.ts +183 -0
  45. package/types/database.d.ts +98 -0
  46. package/types/discovery.d.ts +114 -0
  47. package/types/http.d.ts +46 -0
  48. package/types/index.d.ts +52 -0
  49. package/types/local/authentication.d.ts +11 -0
  50. package/types/local/better-auth.d.ts +33 -0
  51. package/types/local/cli.d.ts +2 -0
  52. package/types/local/context.d.ts +14 -0
  53. package/types/local/environment.d.ts +23 -0
  54. package/types/local/index.d.ts +94 -0
  55. package/types/local/router.d.ts +66 -0
  56. package/types/local/server.d.ts +54 -0
  57. package/types/local/store.d.ts +106 -0
  58. package/types/local/test-environment.d.ts +25 -0
  59. package/types/management-contracts.d.ts +44 -0
  60. package/types/management.d.ts +6 -0
  61. package/types/native-origin.d.ts +23 -0
  62. package/types/postgres.d.ts +123 -0
  63. package/types/react/core.d.ts +366 -0
  64. package/types/react/index.d.ts +54 -0
  65. package/types/result.d.ts +161 -0
  66. package/types/schema.d.ts +145 -0
  67. package/types/sql.d.ts +288 -0
  68. package/types/svelte/index.d.ts +81 -0
  69. package/types/tanstack/index.d.ts +165 -0
  70. package/types/ts-auth-discovery.d.ts +11 -0
  71. package/types/ts-auth.d.ts +1826 -0
@@ -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>;
@@ -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";