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.
- package/LICENSE +202 -0
- package/README.md +143 -0
- package/package.json +159 -0
- package/sdk-current-contract.json +27 -0
- package/sdk-route-manifest.json +67 -0
- package/src/admin.js +9 -0
- package/src/better-auth.js +14 -0
- package/src/config.js +121 -0
- package/src/database-codec.js +845 -0
- package/src/database-types.js +237 -0
- package/src/database-view.js +422 -0
- package/src/database.js +420 -0
- package/src/discovery.js +374 -0
- package/src/http.js +887 -0
- package/src/index.js +79 -0
- package/src/local/authentication.js +47 -0
- package/src/local/better-auth.js +517 -0
- package/src/local/cli.js +51 -0
- package/src/local/context.js +23 -0
- package/src/local/environment.js +109 -0
- package/src/local/index.js +204 -0
- package/src/local/router.js +999 -0
- package/src/local/server.js +664 -0
- package/src/local/store.js +530 -0
- package/src/local/test-environment.js +74 -0
- package/src/management-contracts.js +72 -0
- package/src/management.js +12 -0
- package/src/native-origin.js +75 -0
- package/src/postgres.js +494 -0
- package/src/react/core.js +743 -0
- package/src/react/index.js +99 -0
- package/src/result.js +251 -0
- package/src/schema.js +366 -0
- package/src/sql.js +996 -0
- package/src/svelte/index.js +129 -0
- package/src/tanstack/index.js +511 -0
- package/src/ts-auth-discovery.js +190 -0
- package/src/ts-auth.js +3497 -0
- package/types/admin.d.ts +6 -0
- package/types/better-auth.d.ts +8 -0
- package/types/config.d.ts +58 -0
- package/types/database-codec.d.ts +111 -0
- package/types/database-types.d.ts +213 -0
- package/types/database-view.d.ts +183 -0
- package/types/database.d.ts +98 -0
- package/types/discovery.d.ts +114 -0
- package/types/http.d.ts +46 -0
- package/types/index.d.ts +52 -0
- package/types/local/authentication.d.ts +11 -0
- package/types/local/better-auth.d.ts +33 -0
- package/types/local/cli.d.ts +2 -0
- package/types/local/context.d.ts +14 -0
- package/types/local/environment.d.ts +23 -0
- package/types/local/index.d.ts +94 -0
- package/types/local/router.d.ts +66 -0
- package/types/local/server.d.ts +54 -0
- package/types/local/store.d.ts +106 -0
- package/types/local/test-environment.d.ts +25 -0
- package/types/management-contracts.d.ts +44 -0
- package/types/management.d.ts +6 -0
- package/types/native-origin.d.ts +23 -0
- package/types/postgres.d.ts +123 -0
- package/types/react/core.d.ts +366 -0
- package/types/react/index.d.ts +54 -0
- package/types/result.d.ts +161 -0
- package/types/schema.d.ts +145 -0
- package/types/sql.d.ts +288 -0
- package/types/svelte/index.d.ts +81 -0
- package/types/tanstack/index.d.ts +165 -0
- package/types/ts-auth-discovery.d.ts +11 -0
- package/types/ts-auth.d.ts +1826 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for `createCollection(terrascaleCollectionOptions(...))`.
|
|
3
|
+
*
|
|
4
|
+
* @template {object} T
|
|
5
|
+
* @template {string | number} [TKey=string]
|
|
6
|
+
* @param {TerraScaleTanStackAdapterOptions<T, TKey>} options
|
|
7
|
+
* @returns {TerraScaleTanStackCollectionOptions<T, TKey> & { readonly adapter: TerraScaleTanStackCollectionSync<T, TKey> }}
|
|
8
|
+
*/
|
|
9
|
+
export function terrascaleCollectionOptions<T extends object, TKey extends string | number = string>(options: TerraScaleTanStackAdapterOptions<T, TKey>): TerraScaleTanStackCollectionOptions<T, TKey> & {
|
|
10
|
+
readonly adapter: TerraScaleTanStackCollectionSync<T, TKey>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Every complete native cut owns its mapped values until collection acknowledgment.
|
|
14
|
+
*
|
|
15
|
+
* @template {object} T
|
|
16
|
+
* @template {string | number} [TKey=string]
|
|
17
|
+
*/
|
|
18
|
+
export class TerraScaleTanStackCollectionPublisher<T extends object, TKey extends string | number = string> {
|
|
19
|
+
/**
|
|
20
|
+
* @param {TerraScaleTanStackSyncParams<T, TKey>} params
|
|
21
|
+
* @param {(row: DatabaseQueryRow) => T} mapRow
|
|
22
|
+
* @param {(item: T) => TKey} getKey
|
|
23
|
+
*/
|
|
24
|
+
constructor(params: TerraScaleTanStackSyncParams<T, TKey>, mapRow: (row: DatabaseQueryRow) => T, getKey: (item: T) => TKey);
|
|
25
|
+
/** @returns {DatabaseViewPosition | undefined} */
|
|
26
|
+
getPosition(): DatabaseViewPosition | undefined;
|
|
27
|
+
/** @returns {void} */
|
|
28
|
+
reset(): void;
|
|
29
|
+
/** @returns {void} */
|
|
30
|
+
dispose(): void;
|
|
31
|
+
/**
|
|
32
|
+
* @param {DatabaseViewSnapshot} snapshot
|
|
33
|
+
* @param {AbortSignal} [externalSignal]
|
|
34
|
+
* @returns {Promise<void>}
|
|
35
|
+
*/
|
|
36
|
+
publish(snapshot: DatabaseViewSnapshot, externalSignal?: AbortSignal): Promise<void>;
|
|
37
|
+
#private;
|
|
38
|
+
}
|
|
39
|
+
export class TerraScaleTanStackMutationError extends Error {
|
|
40
|
+
/**
|
|
41
|
+
* @param {Extract<DatabaseResult<DatabaseCommitReceipt>, { readonly ok: false }>["error"]} detail
|
|
42
|
+
*/
|
|
43
|
+
constructor(detail: Extract<DatabaseResult<DatabaseCommitReceipt>, {
|
|
44
|
+
readonly ok: false;
|
|
45
|
+
}>["error"]);
|
|
46
|
+
/** @override @readonly */
|
|
47
|
+
override readonly name: "TerraScaleTanStackMutationError";
|
|
48
|
+
/** @readonly @type {Extract<DatabaseResult<DatabaseCommitReceipt>, { readonly ok: false }>["error"]} */
|
|
49
|
+
readonly detail: Extract<DatabaseResult<DatabaseCommitReceipt>, {
|
|
50
|
+
readonly ok: false;
|
|
51
|
+
}>["error"];
|
|
52
|
+
/** @returns {string} */
|
|
53
|
+
get code(): string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Native HTTP snapshot/poll collection adapter. All durable writes reach the server.
|
|
57
|
+
*
|
|
58
|
+
* @template {object} T
|
|
59
|
+
* @template {string | number} [TKey=string]
|
|
60
|
+
*/
|
|
61
|
+
export class TerraScaleTanStackCollectionSync<T extends object, TKey extends string | number = string> {
|
|
62
|
+
/**
|
|
63
|
+
* @param {TerraScaleTanStackAdapterOptions<T, TKey>} options
|
|
64
|
+
*/
|
|
65
|
+
constructor(options: TerraScaleTanStackAdapterOptions<T, TKey>);
|
|
66
|
+
/** @returns {TerraScaleTanStackCollectionOptions<T, TKey>} */
|
|
67
|
+
get options(): TerraScaleTanStackCollectionOptions<T, TKey>;
|
|
68
|
+
/** @returns {string | undefined} */
|
|
69
|
+
getCheckpoint(): string | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Reconnect correctness starts with a fresh, complete authorized snapshot.
|
|
72
|
+
*
|
|
73
|
+
* @returns {void}
|
|
74
|
+
*/
|
|
75
|
+
resubscribe(): void;
|
|
76
|
+
/** @returns {void} */
|
|
77
|
+
dispose(): void;
|
|
78
|
+
#private;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Structural TanStack DB callbacks keep this optional integration dependency free.
|
|
82
|
+
*/
|
|
83
|
+
export type TerraScaleTanStackChange<T extends object, TKey extends string | number> = {
|
|
84
|
+
readonly type: "insert" | "update";
|
|
85
|
+
readonly value: T;
|
|
86
|
+
} | {
|
|
87
|
+
readonly type: "delete";
|
|
88
|
+
readonly key: TKey;
|
|
89
|
+
};
|
|
90
|
+
export type TerraScaleTanStackSyncParams<T extends object, TKey extends string | number> = {
|
|
91
|
+
readonly collection: unknown;
|
|
92
|
+
readonly begin: (options?: {
|
|
93
|
+
readonly immediate?: boolean;
|
|
94
|
+
}) => void;
|
|
95
|
+
readonly write: (message: TerraScaleTanStackChange<T, TKey>) => void;
|
|
96
|
+
readonly commit: (signal?: AbortSignal) => true | Promise<void>;
|
|
97
|
+
readonly markReady: () => void;
|
|
98
|
+
readonly markError: (error?: unknown) => void;
|
|
99
|
+
readonly truncate: () => void;
|
|
100
|
+
};
|
|
101
|
+
export type TerraScaleTanStackMutation<T extends object = Record<string, unknown>> = {
|
|
102
|
+
readonly mutationId?: string;
|
|
103
|
+
readonly key: string | number;
|
|
104
|
+
readonly original?: Partial<T>;
|
|
105
|
+
readonly modified: T;
|
|
106
|
+
readonly changes?: Partial<T>;
|
|
107
|
+
readonly type: "insert" | "update" | "delete";
|
|
108
|
+
readonly metadata?: unknown;
|
|
109
|
+
};
|
|
110
|
+
export type TerraScaleTanStackTransaction<T extends object = Record<string, unknown>> = {
|
|
111
|
+
readonly id?: string;
|
|
112
|
+
readonly mutations: readonly TerraScaleTanStackMutation<T>[];
|
|
113
|
+
readonly metadata?: Record<string, unknown>;
|
|
114
|
+
};
|
|
115
|
+
export type TerraScaleTanStackMutationRequest<T extends object, TKey extends string | number> = {
|
|
116
|
+
readonly operation: "insert" | "update" | "delete";
|
|
117
|
+
readonly idempotencyKey: string;
|
|
118
|
+
readonly transactionId: string;
|
|
119
|
+
readonly transaction: TerraScaleTanStackTransaction<T>;
|
|
120
|
+
readonly scope: DatabaseScope;
|
|
121
|
+
readonly collection: string;
|
|
122
|
+
readonly signal: AbortSignal;
|
|
123
|
+
readonly keyOf: (item: T) => TKey;
|
|
124
|
+
};
|
|
125
|
+
export type TerraScaleTanStackCollectionOptions<T extends object, TKey extends string | number = string> = {
|
|
126
|
+
readonly id?: string;
|
|
127
|
+
readonly getKey: (item: T) => TKey;
|
|
128
|
+
readonly sync: {
|
|
129
|
+
readonly rowUpdateMode: "full";
|
|
130
|
+
readonly sync: (params: TerraScaleTanStackSyncParams<T, TKey>) => () => void;
|
|
131
|
+
};
|
|
132
|
+
readonly onInsert: (params: {
|
|
133
|
+
readonly transaction: TerraScaleTanStackTransaction<T>;
|
|
134
|
+
}) => Promise<DatabaseCommitReceipt>;
|
|
135
|
+
readonly onUpdate: (params: {
|
|
136
|
+
readonly transaction: TerraScaleTanStackTransaction<T>;
|
|
137
|
+
}) => Promise<DatabaseCommitReceipt>;
|
|
138
|
+
readonly onDelete: (params: {
|
|
139
|
+
readonly transaction: TerraScaleTanStackTransaction<T>;
|
|
140
|
+
}) => Promise<DatabaseCommitReceipt>;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* `mapRow` maps the complete native point explicitly; conflicts are never
|
|
144
|
+
* flattened. `prepareMutation` prepares through this same client. The adapter
|
|
145
|
+
* sends the resulting commit to the server once; TanStack owns its reversible
|
|
146
|
+
* optimistic presentation.
|
|
147
|
+
*/
|
|
148
|
+
export type TerraScaleTanStackAdapterOptions<T extends object, TKey extends string | number = string> = DatabaseQueryOptions & {
|
|
149
|
+
readonly client: TerraBaseClient;
|
|
150
|
+
readonly mapRow: (row: DatabaseQueryRow) => T;
|
|
151
|
+
readonly getKey: (item: T) => TKey;
|
|
152
|
+
readonly id?: string;
|
|
153
|
+
readonly prepareMutation?: (request: TerraScaleTanStackMutationRequest<T, TKey>) => Promise<PreparedDatabaseCommit>;
|
|
154
|
+
readonly idempotencyKey?: (transaction: TerraScaleTanStackTransaction<T>) => string;
|
|
155
|
+
readonly signal?: AbortSignal;
|
|
156
|
+
};
|
|
157
|
+
import type { DatabaseViewPosition } from "../database-view.js";
|
|
158
|
+
import type { DatabaseViewSnapshot } from "../database-view.js";
|
|
159
|
+
import type { DatabaseQueryRow } from "../database-types.js";
|
|
160
|
+
import type { DatabaseCommitReceipt } from "../database-types.js";
|
|
161
|
+
import type { DatabaseResult } from "../database-types.js";
|
|
162
|
+
import type { DatabaseScope } from "../database-types.js";
|
|
163
|
+
import type { DatabaseQueryOptions } from "../database-view.js";
|
|
164
|
+
import type { TerraBaseClient } from "../database.js";
|
|
165
|
+
import type { PreparedDatabaseCommit } from "../database.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The public auth routing document, validated before any credentials are sent. */
|
|
2
|
+
export class TsAuthEndpointDiscovery {
|
|
3
|
+
/** @param {typeof globalThis.fetch} fetchHandler */
|
|
4
|
+
constructor(fetchHandler: typeof globalThis.fetch);
|
|
5
|
+
/**
|
|
6
|
+
* @param {AbortSignal} [signal]
|
|
7
|
+
* @returns {Promise<readonly string[]>}
|
|
8
|
+
*/
|
|
9
|
+
endpoints(signal?: AbortSignal): Promise<readonly string[]>;
|
|
10
|
+
#private;
|
|
11
|
+
}
|