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,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse only the current closed native8 descriptor, without widening its lease or capabilities.
|
|
3
|
+
* @param {unknown} payload
|
|
4
|
+
* @param {DatabaseScope} expected
|
|
5
|
+
* @param {number} [nowMs]
|
|
6
|
+
* @returns {TerraBaseRoutingDocument}
|
|
7
|
+
*/
|
|
8
|
+
export function parseTerraBaseRoutingDocument(payload: unknown, expected: DatabaseScope, nowMs?: number): TerraBaseRoutingDocument;
|
|
9
|
+
/** @import { FetchLike } from "./config.js" */
|
|
10
|
+
/** @import { DatabaseScope } from "./database-types.js" */
|
|
11
|
+
/** Frozen authenticated native receiver; no alternate metadata origin is admitted. */
|
|
12
|
+
export const terraBaseDiscoveryOrigin: "https://atlas.terrascale.tech";
|
|
13
|
+
/** @typedef {typeof capabilityNames[number]} TerraBaseRoutingCapability */
|
|
14
|
+
/** @typedef {Readonly<Record<TerraBaseRoutingCapability, boolean>>} TerraBaseRoutingCapabilities */
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {{
|
|
17
|
+
* readonly region: string;
|
|
18
|
+
* readonly url: string;
|
|
19
|
+
* readonly priority: number;
|
|
20
|
+
* readonly catalog: { readonly digest: string };
|
|
21
|
+
* readonly capabilities: TerraBaseRoutingCapabilities;
|
|
22
|
+
* readonly security_writer: null;
|
|
23
|
+
* }} TerraBaseRoutingEndpoint
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {{
|
|
27
|
+
* readonly schema_version: 1;
|
|
28
|
+
* readonly scope: DatabaseScope;
|
|
29
|
+
* readonly authority: {
|
|
30
|
+
* readonly deployment_id: string;
|
|
31
|
+
* readonly cell: string;
|
|
32
|
+
* readonly publisher_id: string;
|
|
33
|
+
* readonly publisher_generation: bigint;
|
|
34
|
+
* };
|
|
35
|
+
* readonly revision: bigint;
|
|
36
|
+
* readonly published_at: number;
|
|
37
|
+
* readonly expires_at: number;
|
|
38
|
+
* readonly refreshSeconds: number;
|
|
39
|
+
* readonly residency: readonly string[] | null;
|
|
40
|
+
* readonly endpoints: readonly TerraBaseRoutingEndpoint[];
|
|
41
|
+
* }} TerraBaseRoutingDocument
|
|
42
|
+
*/
|
|
43
|
+
export class TerraBaseDiscoveryError extends Error {
|
|
44
|
+
/**
|
|
45
|
+
* @param {string} code
|
|
46
|
+
* @param {number} [status]
|
|
47
|
+
*/
|
|
48
|
+
constructor(code: string, status?: number);
|
|
49
|
+
/**
|
|
50
|
+
* @readonly
|
|
51
|
+
* @type {string}
|
|
52
|
+
*/
|
|
53
|
+
readonly code: string;
|
|
54
|
+
/**
|
|
55
|
+
* @readonly
|
|
56
|
+
* @type {number | undefined}
|
|
57
|
+
*/
|
|
58
|
+
readonly status: number | undefined;
|
|
59
|
+
}
|
|
60
|
+
/** Per-scope observation floors survive lease expiry and credential rotation for this client. */
|
|
61
|
+
export class TerraBaseDiscoveryRouter {
|
|
62
|
+
/**
|
|
63
|
+
* @param {DatabaseScope} scope
|
|
64
|
+
* @param {FetchLike} [fetch]
|
|
65
|
+
* @param {number} [timeoutMs]
|
|
66
|
+
*/
|
|
67
|
+
constructor(scope: DatabaseScope, fetch?: FetchLike, timeoutMs?: number);
|
|
68
|
+
/**
|
|
69
|
+
* @param {string} apiKey
|
|
70
|
+
* @param {readonly TerraBaseRoutingCapability[]} required
|
|
71
|
+
* @param {AbortSignal} [callerSignal]
|
|
72
|
+
* @returns {Promise<TerraBaseRoutingEndpoint>}
|
|
73
|
+
*/
|
|
74
|
+
resolve(apiKey: string, required: readonly TerraBaseRoutingCapability[], callerSignal?: AbortSignal): Promise<TerraBaseRoutingEndpoint>;
|
|
75
|
+
/**
|
|
76
|
+
* Recheck immediately before native dispatch, including concurrently advanced floors.
|
|
77
|
+
* @param {TerraBaseRoutingEndpoint} endpoint
|
|
78
|
+
* @returns {void}
|
|
79
|
+
*/
|
|
80
|
+
assertCurrent(endpoint: TerraBaseRoutingEndpoint): void;
|
|
81
|
+
#private;
|
|
82
|
+
}
|
|
83
|
+
export type TerraBaseRoutingCapability = (typeof capabilityNames)[number];
|
|
84
|
+
export type TerraBaseRoutingCapabilities = Readonly<Record<TerraBaseRoutingCapability, boolean>>;
|
|
85
|
+
export type TerraBaseRoutingEndpoint = {
|
|
86
|
+
readonly region: string;
|
|
87
|
+
readonly url: string;
|
|
88
|
+
readonly priority: number;
|
|
89
|
+
readonly catalog: {
|
|
90
|
+
readonly digest: string;
|
|
91
|
+
};
|
|
92
|
+
readonly capabilities: TerraBaseRoutingCapabilities;
|
|
93
|
+
readonly security_writer: null;
|
|
94
|
+
};
|
|
95
|
+
export type TerraBaseRoutingDocument = {
|
|
96
|
+
readonly schema_version: 1;
|
|
97
|
+
readonly scope: DatabaseScope;
|
|
98
|
+
readonly authority: {
|
|
99
|
+
readonly deployment_id: string;
|
|
100
|
+
readonly cell: string;
|
|
101
|
+
readonly publisher_id: string;
|
|
102
|
+
readonly publisher_generation: bigint;
|
|
103
|
+
};
|
|
104
|
+
readonly revision: bigint;
|
|
105
|
+
readonly published_at: number;
|
|
106
|
+
readonly expires_at: number;
|
|
107
|
+
readonly refreshSeconds: number;
|
|
108
|
+
readonly residency: readonly string[] | null;
|
|
109
|
+
readonly endpoints: readonly TerraBaseRoutingEndpoint[];
|
|
110
|
+
};
|
|
111
|
+
import type { DatabaseScope } from "./database-types.js";
|
|
112
|
+
import type { FetchLike } from "./config.js";
|
|
113
|
+
declare const capabilityNames: readonly ["client_v1", "read", "query", "subscriptions", "write", "conditional_mutation", "atomic_groups", "security_state"];
|
|
114
|
+
export {};
|
package/types/http.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Private transport for the named hosted identity and OIDC operations. */
|
|
2
|
+
export class TsAuthHttp {
|
|
3
|
+
/**
|
|
4
|
+
* @param {TsAuthRuntimeConfig} config
|
|
5
|
+
* @param {{ readonly authReverseProxy?: boolean }} [options]
|
|
6
|
+
*/
|
|
7
|
+
constructor(config: TsAuthRuntimeConfig, options?: {
|
|
8
|
+
readonly authReverseProxy?: boolean;
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* @readonly
|
|
12
|
+
* @type {ResolvedTsAuthRuntimeConfig}
|
|
13
|
+
*/
|
|
14
|
+
readonly config: ResolvedTsAuthRuntimeConfig;
|
|
15
|
+
/**
|
|
16
|
+
* @template TResponse
|
|
17
|
+
* @template [TBody=unknown]
|
|
18
|
+
* @param {TsAuthRequest<TBody>} options
|
|
19
|
+
* @returns {Promise<TerraScaleResult<TResponse>>}
|
|
20
|
+
*/
|
|
21
|
+
request<TResponse, TBody = unknown>(options: TsAuthRequest<TBody>): Promise<TerraScaleResult<TResponse>>;
|
|
22
|
+
#private;
|
|
23
|
+
}
|
|
24
|
+
export type ParsedBody = {
|
|
25
|
+
readonly ok: true;
|
|
26
|
+
readonly value: unknown;
|
|
27
|
+
} | {
|
|
28
|
+
readonly ok: false;
|
|
29
|
+
readonly errorMessage: string;
|
|
30
|
+
};
|
|
31
|
+
export type TsAuthRouteName = `tsauth.${string}`;
|
|
32
|
+
export type TsAuthHttpMethod = "DELETE" | "GET" | "PATCH" | "POST" | "PUT";
|
|
33
|
+
export type TsAuthRequest<TBody> = {
|
|
34
|
+
readonly method: TsAuthHttpMethod;
|
|
35
|
+
readonly path: string;
|
|
36
|
+
readonly routeName: TsAuthRouteName;
|
|
37
|
+
readonly query?: object | undefined;
|
|
38
|
+
readonly body?: TBody | undefined;
|
|
39
|
+
readonly formBody?: URLSearchParams | string | undefined;
|
|
40
|
+
readonly userinfoAccessToken?: string | undefined;
|
|
41
|
+
readonly resourceIntrospectionBasic?: string | undefined;
|
|
42
|
+
readonly signal?: AbortSignal | undefined;
|
|
43
|
+
};
|
|
44
|
+
import type { ResolvedTsAuthRuntimeConfig } from "./config.js";
|
|
45
|
+
import type { TerraScaleResult } from "./result.js";
|
|
46
|
+
import type { TsAuthRuntimeConfig } from "./config.js";
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export * from "./schema.js";
|
|
2
|
+
export * from "./sql.js";
|
|
3
|
+
export type TerraBaseClientConfig = import("./database.js").TerraBaseClientConfig;
|
|
4
|
+
export type PreparedDatabaseCommit = import("./database.js").PreparedDatabaseCommit;
|
|
5
|
+
export type DatabaseRequestOptions = import("./database.js").DatabaseRequestOptions;
|
|
6
|
+
export type CanonicalUuid = import("./database-types.js").CanonicalUuid;
|
|
7
|
+
export type DatabaseScope = import("./database-types.js").DatabaseScope;
|
|
8
|
+
export type CollectionBinding = import("./database-types.js").CollectionBinding;
|
|
9
|
+
export type DatabaseValue = import("./database-types.js").DatabaseValue;
|
|
10
|
+
export type DatabaseField = import("./database-types.js").DatabaseField;
|
|
11
|
+
export type DatabaseObserved = import("./database-types.js").DatabaseObserved;
|
|
12
|
+
export type DatabaseEvent = import("./database-types.js").DatabaseEvent;
|
|
13
|
+
export type DatabaseAuthority = import("./database-types.js").DatabaseAuthority;
|
|
14
|
+
export type DatabaseCondition = import("./database-types.js").DatabaseCondition;
|
|
15
|
+
export type DatabaseWriteValue = import("./database-types.js").DatabaseWriteValue;
|
|
16
|
+
export type DatabaseWrite = import("./database-types.js").DatabaseWrite;
|
|
17
|
+
export type DatabaseTransactionId = import("./database-types.js").DatabaseTransactionId;
|
|
18
|
+
export type DatabaseCommit = import("./database-types.js").DatabaseCommit;
|
|
19
|
+
export type DatabaseSibling = import("./database-types.js").DatabaseSibling;
|
|
20
|
+
export type DatabasePoint = import("./database-types.js").DatabasePoint;
|
|
21
|
+
export type DatabaseQueryValue = import("./database-types.js").DatabaseQueryValue;
|
|
22
|
+
export type DatabaseQueryPredicate = import("./database-types.js").DatabaseQueryPredicate;
|
|
23
|
+
export type DatabaseQuery = import("./database-types.js").DatabaseQuery;
|
|
24
|
+
export type DatabaseQueryRow = import("./database-types.js").DatabaseQueryRow;
|
|
25
|
+
export type DatabaseQueryPage = import("./database-types.js").DatabaseQueryPage;
|
|
26
|
+
export type DatabaseCommitReceipt = import("./database-types.js").DatabaseCommitReceipt;
|
|
27
|
+
export type DatabaseTransactionIdentity = import("./database-types.js").DatabaseTransactionIdentity;
|
|
28
|
+
export type DatabaseTransactionStatus = import("./database-types.js").DatabaseTransactionStatus;
|
|
29
|
+
export type DatabaseResult<T> = import("./database-types.js").DatabaseResult<T>;
|
|
30
|
+
export type DatabaseSubscriptionRequest = import("./database-types.js").DatabaseSubscriptionRequest;
|
|
31
|
+
export type DatabaseSubscriptionEffect = import("./database-types.js").DatabaseSubscriptionEffect;
|
|
32
|
+
export type DatabaseSubscriptionGroup = import("./database-types.js").DatabaseSubscriptionGroup;
|
|
33
|
+
export type DatabaseSubscriptionResponse = import("./database-types.js").DatabaseSubscriptionResponse;
|
|
34
|
+
export type TerraBaseRoutingCapability = import("./discovery.js").TerraBaseRoutingCapability;
|
|
35
|
+
export type TerraBaseRoutingCapabilities = import("./discovery.js").TerraBaseRoutingCapabilities;
|
|
36
|
+
export type TerraBaseRoutingEndpoint = import("./discovery.js").TerraBaseRoutingEndpoint;
|
|
37
|
+
export type TerraBaseRoutingDocument = import("./discovery.js").TerraBaseRoutingDocument;
|
|
38
|
+
export type TerraScaleBlockedCapability = import("./management-contracts.js").TerraScaleBlockedCapability;
|
|
39
|
+
export type TerraScaleResult<TValue> = import("./result.js").TerraScaleResult<TValue>;
|
|
40
|
+
export type TerraScaleError = import("./result.js").TerraScaleError;
|
|
41
|
+
export type TerraScaleFailure = import("./result.js").TerraScaleFailure;
|
|
42
|
+
export type TerraScaleSuccess<TValue> = import("./result.js").TerraScaleSuccess<TValue>;
|
|
43
|
+
export type DatabaseQueryOptions = import("./database-view.js").DatabaseQueryOptions;
|
|
44
|
+
export type DatabaseViewBinding = import("./database-view.js").DatabaseViewBinding;
|
|
45
|
+
export type DatabaseViewPosition = import("./database-view.js").DatabaseViewPosition;
|
|
46
|
+
export type DatabaseViewSnapshot = import("./database-view.js").DatabaseViewSnapshot;
|
|
47
|
+
export type DatabaseQueryCallbacks = import("./database-view.js").DatabaseQueryCallbacks;
|
|
48
|
+
export type DatabaseQuerySource = import("./database-view.js").DatabaseQuerySource;
|
|
49
|
+
export { createTerraBaseClient, TerraBaseClient } from "./database.js";
|
|
50
|
+
export { terraBaseDiscoveryOrigin, parseTerraBaseRoutingDocument, TerraBaseDiscoveryError, TerraBaseDiscoveryRouter } from "./discovery.js";
|
|
51
|
+
export { terraScaleReleaseBlockers, TerraScaleCapabilityUnavailableError } from "./management-contracts.js";
|
|
52
|
+
export { createDatabaseQuery, DatabaseSubscriptionView, DatabaseSubscriptionError } from "./database-view.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {unknown} value
|
|
3
|
+
* @returns {string}
|
|
4
|
+
*/
|
|
5
|
+
export function normalizeLocalBearerToken(value: unknown): string;
|
|
6
|
+
/**
|
|
7
|
+
* @param {string | null} authorization
|
|
8
|
+
* @param {string} expectedToken
|
|
9
|
+
* @returns {boolean}
|
|
10
|
+
*/
|
|
11
|
+
export function matchesLocalBearerAuthorization(authorization: string | null, expectedToken: string): boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** @import { CleanedWhere, CustomAdapter, DBAdapter, JoinConfig } from "@better-auth/core/db/adapter" */
|
|
2
|
+
/** @import { BetterAuthOptions } from "@better-auth/core" */
|
|
3
|
+
/** @import { TerraScaleSqliteStore } from "./store.js" */
|
|
4
|
+
/** @typedef {Record<string, unknown>} Row */
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {Parameters<
|
|
7
|
+
* NonNullable<Parameters<typeof createAdapterFactory>[0]["adapter"]>
|
|
8
|
+
* >[0]} FactoryConfig
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {(
|
|
12
|
+
* options: BetterAuthOptions,
|
|
13
|
+
* ) => DBAdapter<BetterAuthOptions>} LocalBetterAuthAdapterFactory
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Better Auth 1.7.2 over explicitly enabled development SQLite only.
|
|
17
|
+
*
|
|
18
|
+
* @param {TerraScaleSqliteStore} store
|
|
19
|
+
* @returns {LocalBetterAuthAdapterFactory}
|
|
20
|
+
*/
|
|
21
|
+
export function createLocalBetterAuthAdapter(store: TerraScaleSqliteStore): LocalBetterAuthAdapterFactory;
|
|
22
|
+
export class LocalAuthConstraintError extends Error {
|
|
23
|
+
constructor();
|
|
24
|
+
/** @readonly */
|
|
25
|
+
readonly code: "unique_conflict";
|
|
26
|
+
}
|
|
27
|
+
export type Row = Record<string, unknown>;
|
|
28
|
+
export type FactoryConfig = Parameters<NonNullable<Parameters<typeof createAdapterFactory>[0]["adapter"]>>[0];
|
|
29
|
+
export type LocalBetterAuthAdapterFactory = (options: BetterAuthOptions) => DBAdapter<BetterAuthOptions>;
|
|
30
|
+
import type { TerraScaleSqliteStore } from "./store.js";
|
|
31
|
+
import { createAdapterFactory } from "@better-auth/core/db/adapter";
|
|
32
|
+
import type { BetterAuthOptions } from "@better-auth/core";
|
|
33
|
+
import type { DBAdapter } from "@better-auth/core/db/adapter";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @typedef {"permissive" | "required"} LocalAuthenticationMode */
|
|
2
|
+
/**
|
|
3
|
+
* @param {unknown} value
|
|
4
|
+
* @param {number} [status]
|
|
5
|
+
* @returns {Response}
|
|
6
|
+
*/
|
|
7
|
+
export function jsonResponse(value: unknown, status?: number): Response;
|
|
8
|
+
/**
|
|
9
|
+
* @param {number} status
|
|
10
|
+
* @param {string} code
|
|
11
|
+
* @returns {Response}
|
|
12
|
+
*/
|
|
13
|
+
export function problemResponse(status: number, code: string): Response;
|
|
14
|
+
export type LocalAuthenticationMode = "permissive" | "required";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Readonly<Record<string, string | undefined>>} [environment]
|
|
3
|
+
* @returns {void}
|
|
4
|
+
*/
|
|
5
|
+
export function assertLocalSqliteEnvironment(environment?: Readonly<Record<string, string | undefined>>): void;
|
|
6
|
+
export const localSqlitePresenceIndicators: readonly ["CI", "CONTINUOUS_INTEGRATION", "GITHUB_ACTIONS", "GITLAB_CI", "FORGEJO_ACTIONS", "GITEA_ACTIONS", "TF_BUILD", "BUILDKITE", "CIRCLECI", "JENKINS_URL", "TEAMCITY_VERSION", "VERCEL", "NETLIFY", "CF_PAGES", "RENDER", "FLY_APP_NAME", "K_SERVICE", "CLOUD_RUN_JOB", "KUBERNETES_SERVICE_HOST", "AWS_LAMBDA_FUNCTION_NAME", "AWS_EXECUTION_ENV", "ECS_CONTAINER_METADATA_URI", "ECS_CONTAINER_METADATA_URI_V4", "WEBSITE_INSTANCE_ID", "WEBSITE_SITE_NAME", "FUNCTIONS_WORKER_RUNTIME", "DYNO", "HEROKU_APP_NAME", "RAILWAY_ENVIRONMENT", "RAILWAY_SERVICE_ID", "NOMAD_ALLOC_ID", "TERRASCALE_DEPLOYMENT", "TERRASCALE_QUALIFICATION"];
|
|
7
|
+
/**
|
|
8
|
+
* Explicit opt-in for a hosted development environment.
|
|
9
|
+
*
|
|
10
|
+
* Hosting platforms set a presence indicator on every workload, including
|
|
11
|
+
* development environments, so the SDK cannot tell a hosted dev environment
|
|
12
|
+
* from production by presence alone. Setting this variable to a true value
|
|
13
|
+
* relaxes *platform* indicators only: CI, qualification, and every stage
|
|
14
|
+
* indicator (`NODE_ENV=production`, `STAGE=staging`, …) still refuse.
|
|
15
|
+
*/
|
|
16
|
+
export const localSqliteHostedOptIn: "TERRASCALE_LOCAL_SQLITE_ALLOW_HOSTED";
|
|
17
|
+
/**
|
|
18
|
+
* Presence indicators the opt-in never relaxes.
|
|
19
|
+
*
|
|
20
|
+
* @type {ReadonlySet<string>}
|
|
21
|
+
*/
|
|
22
|
+
export const localSqliteUnrelaxableIndicators: ReadonlySet<string>;
|
|
23
|
+
export const localSqliteStageIndicators: readonly ["NODE_ENV", "APP_ENV", "ENVIRONMENT", "STAGE", "DEPLOY_ENV", "DEPLOYMENT_ENVIRONMENT", "TERRASCALE_ENV", "TERRASCALE_ENVIRONMENT", "VERCEL_ENV"];
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {TerraScaleSqliteRuntimeOptions} options
|
|
3
|
+
* @returns {TerraScaleSqliteRuntime}
|
|
4
|
+
*/
|
|
5
|
+
export function createTerraScaleSqliteRuntime(options: TerraScaleSqliteRuntimeOptions): TerraScaleSqliteRuntime;
|
|
6
|
+
/** @import { TerraBaseClient, TerraBaseClientConfig } from "../database.js" */
|
|
7
|
+
/** @import { CollectionBinding, DatabaseScope } from "../database-types.js" */
|
|
8
|
+
/** @typedef {import("./context.js").LocalAuthenticationMode} LocalAuthenticationMode */
|
|
9
|
+
/** @typedef {import("./server.js").LocalServerAddress} LocalServerAddress */
|
|
10
|
+
/** @typedef {import("./better-auth.js").LocalBetterAuthAdapterFactory} LocalBetterAuthAdapterFactory */
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {{
|
|
13
|
+
* readonly sqlite: { readonly enabled: true; readonly databasePath: string };
|
|
14
|
+
* readonly scope?: DatabaseScope;
|
|
15
|
+
* readonly authentication?: LocalAuthenticationMode;
|
|
16
|
+
* readonly bearerToken?: string;
|
|
17
|
+
* readonly allowRemote?: boolean;
|
|
18
|
+
* }} TerraScaleSqliteRuntimeOptions
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {{
|
|
22
|
+
* readonly host?: string;
|
|
23
|
+
* readonly port?: number;
|
|
24
|
+
* }} TerraScaleLocalListenOptions
|
|
25
|
+
*/
|
|
26
|
+
/** Explicit Node development backend. Never load this entrypoint in deployment or qualification. */
|
|
27
|
+
export class TerraScaleSqliteRuntime {
|
|
28
|
+
/**
|
|
29
|
+
* @param {TerraScaleSqliteRuntimeOptions} options
|
|
30
|
+
*/
|
|
31
|
+
constructor(options: TerraScaleSqliteRuntimeOptions);
|
|
32
|
+
/**
|
|
33
|
+
* @readonly
|
|
34
|
+
* @type {DatabaseScope}
|
|
35
|
+
*/
|
|
36
|
+
readonly scope: DatabaseScope;
|
|
37
|
+
/** @returns {string} */
|
|
38
|
+
get databasePath(): string;
|
|
39
|
+
/** @returns {LocalServerAddress | undefined} */
|
|
40
|
+
get address(): LocalServerAddress | undefined;
|
|
41
|
+
get authority(): Readonly<{
|
|
42
|
+
mode: "single_writer";
|
|
43
|
+
generation: 1n;
|
|
44
|
+
writer: {
|
|
45
|
+
readonly replica: string;
|
|
46
|
+
readonly incarnation: string;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
/**
|
|
50
|
+
* @param {CollectionBinding} binding
|
|
51
|
+
* @returns {Promise<void>}
|
|
52
|
+
*/
|
|
53
|
+
bindCollection(binding: CollectionBinding): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* @param {Pick<TerraBaseClientConfig, "requestTimeoutMs">} [options]
|
|
56
|
+
* @returns {TerraBaseClient}
|
|
57
|
+
*/
|
|
58
|
+
createClient(options?: Pick<TerraBaseClientConfig, "requestTimeoutMs">): TerraBaseClient;
|
|
59
|
+
/** @returns {Promise<LocalBetterAuthAdapterFactory>} */
|
|
60
|
+
createBetterAuthAdapter(): Promise<LocalBetterAuthAdapterFactory>;
|
|
61
|
+
/**
|
|
62
|
+
* @param {TerraScaleLocalListenOptions} [options]
|
|
63
|
+
* @returns {Promise<LocalServerAddress>}
|
|
64
|
+
*/
|
|
65
|
+
start(options?: TerraScaleLocalListenOptions): Promise<LocalServerAddress>;
|
|
66
|
+
/** @returns {Promise<void>} */
|
|
67
|
+
stop(): Promise<void>;
|
|
68
|
+
/** @returns {Promise<void>} */
|
|
69
|
+
reset(): Promise<void>;
|
|
70
|
+
/** @returns {Promise<void>} */
|
|
71
|
+
close(): Promise<void>;
|
|
72
|
+
#private;
|
|
73
|
+
}
|
|
74
|
+
export type LocalAuthenticationMode = import("./context.js").LocalAuthenticationMode;
|
|
75
|
+
export type LocalServerAddress = import("./server.js").LocalServerAddress;
|
|
76
|
+
export type LocalBetterAuthAdapterFactory = import("./better-auth.js").LocalBetterAuthAdapterFactory;
|
|
77
|
+
export type TerraScaleSqliteRuntimeOptions = {
|
|
78
|
+
readonly sqlite: {
|
|
79
|
+
readonly enabled: true;
|
|
80
|
+
readonly databasePath: string;
|
|
81
|
+
};
|
|
82
|
+
readonly scope?: DatabaseScope;
|
|
83
|
+
readonly authentication?: LocalAuthenticationMode;
|
|
84
|
+
readonly bearerToken?: string;
|
|
85
|
+
readonly allowRemote?: boolean;
|
|
86
|
+
};
|
|
87
|
+
export type TerraScaleLocalListenOptions = {
|
|
88
|
+
readonly host?: string;
|
|
89
|
+
readonly port?: number;
|
|
90
|
+
};
|
|
91
|
+
import type { DatabaseScope } from "../database-types.js";
|
|
92
|
+
import type { CollectionBinding } from "../database-types.js";
|
|
93
|
+
import type { TerraBaseClientConfig } from "../database.js";
|
|
94
|
+
import type { TerraBaseClient } from "../database.js";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Development implementation of the admitted native grammar, never producer qualification. */
|
|
2
|
+
export class TerraScaleLocalRouter {
|
|
3
|
+
/**
|
|
4
|
+
* @param {TerraScaleSqliteStore} store
|
|
5
|
+
* @param {DatabaseScope} scope
|
|
6
|
+
* @param {{
|
|
7
|
+
* readonly authentication: LocalAuthenticationMode;
|
|
8
|
+
* readonly bearerToken?: string;
|
|
9
|
+
* }} options
|
|
10
|
+
*/
|
|
11
|
+
constructor(store: TerraScaleSqliteStore, scope: DatabaseScope, options: {
|
|
12
|
+
readonly authentication: LocalAuthenticationMode;
|
|
13
|
+
readonly bearerToken?: string;
|
|
14
|
+
});
|
|
15
|
+
get authority(): Readonly<{
|
|
16
|
+
mode: "single_writer";
|
|
17
|
+
generation: 1n;
|
|
18
|
+
writer: {
|
|
19
|
+
readonly replica: string;
|
|
20
|
+
readonly incarnation: string;
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* @param {CollectionBinding} binding
|
|
25
|
+
* @returns {void}
|
|
26
|
+
*/
|
|
27
|
+
bindCollection(binding: CollectionBinding): void;
|
|
28
|
+
/**
|
|
29
|
+
* @readonly
|
|
30
|
+
* @type {FetchLike}
|
|
31
|
+
*/
|
|
32
|
+
readonly fetch: FetchLike;
|
|
33
|
+
/**
|
|
34
|
+
* @param {Request} request
|
|
35
|
+
* @returns {Promise<Response>}
|
|
36
|
+
*/
|
|
37
|
+
handle(request: Request): Promise<Response>;
|
|
38
|
+
#private;
|
|
39
|
+
}
|
|
40
|
+
export type JsonObject = Record<string, unknown>;
|
|
41
|
+
export type WirePoint = JsonObject;
|
|
42
|
+
export type Change = {
|
|
43
|
+
readonly sequence: string;
|
|
44
|
+
readonly entries: readonly {
|
|
45
|
+
readonly collection: string;
|
|
46
|
+
readonly document: string;
|
|
47
|
+
readonly before: WirePoint;
|
|
48
|
+
readonly after: WirePoint;
|
|
49
|
+
}[];
|
|
50
|
+
};
|
|
51
|
+
export type Snapshot = {
|
|
52
|
+
readonly route: string;
|
|
53
|
+
readonly predicate: string;
|
|
54
|
+
readonly limit: number;
|
|
55
|
+
readonly sequence: string;
|
|
56
|
+
readonly rows: readonly {
|
|
57
|
+
readonly document: string;
|
|
58
|
+
readonly point: WirePoint;
|
|
59
|
+
}[];
|
|
60
|
+
readonly expires: number;
|
|
61
|
+
};
|
|
62
|
+
import type { CollectionBinding } from "../database-types.js";
|
|
63
|
+
import type { FetchLike } from "../config.js";
|
|
64
|
+
import type { TerraScaleSqliteStore } from "./store.js";
|
|
65
|
+
import type { DatabaseScope } from "../database-types.js";
|
|
66
|
+
import type { LocalAuthenticationMode } from "./context.js";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The local HTTP endpoint exposed by a running server.
|
|
3
|
+
*
|
|
4
|
+
* @typedef {Readonly<{
|
|
5
|
+
* readonly origin: string;
|
|
6
|
+
* readonly host: string;
|
|
7
|
+
* readonly port: number;
|
|
8
|
+
* }>} LocalServerAddress
|
|
9
|
+
*/
|
|
10
|
+
/** @typedef {(request: Request) => Promise<Response>} LocalRequestHandler */
|
|
11
|
+
/** @typedef {Readonly<{ host?: string; port?: number }>} StartOptions */
|
|
12
|
+
/** @typedef {boolean | Readonly<{ allowRemote?: boolean }>} ConstructorOptions */
|
|
13
|
+
/** @typedef {ReturnType<typeof createServer>} ServerLike */
|
|
14
|
+
/**
|
|
15
|
+
* A small Node-only bridge for handlers that speak the Fetch API.
|
|
16
|
+
*
|
|
17
|
+
* The handler is deliberately the sole routing authority. In particular, this
|
|
18
|
+
* adapter does not reserve a health route (or any other private route).
|
|
19
|
+
*/
|
|
20
|
+
export class TerraScaleLocalHttpServer {
|
|
21
|
+
/**
|
|
22
|
+
* @param {LocalRequestHandler} handler
|
|
23
|
+
* @param {ConstructorOptions} [options]
|
|
24
|
+
*/
|
|
25
|
+
constructor(handler: LocalRequestHandler, options?: ConstructorOptions);
|
|
26
|
+
/** @returns {LocalServerAddress | undefined} */
|
|
27
|
+
get address(): LocalServerAddress | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* @param {StartOptions} [options]
|
|
30
|
+
* @returns {Promise<LocalServerAddress>}
|
|
31
|
+
*/
|
|
32
|
+
start(options?: StartOptions): Promise<LocalServerAddress>;
|
|
33
|
+
/** @returns {Promise<void>} */
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
#private;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The local HTTP endpoint exposed by a running server.
|
|
39
|
+
*/
|
|
40
|
+
export type LocalServerAddress = Readonly<{
|
|
41
|
+
readonly origin: string;
|
|
42
|
+
readonly host: string;
|
|
43
|
+
readonly port: number;
|
|
44
|
+
}>;
|
|
45
|
+
export type LocalRequestHandler = (request: Request) => Promise<Response>;
|
|
46
|
+
export type StartOptions = Readonly<{
|
|
47
|
+
host?: string;
|
|
48
|
+
port?: number;
|
|
49
|
+
}>;
|
|
50
|
+
export type ConstructorOptions = boolean | Readonly<{
|
|
51
|
+
allowRemote?: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
export type ServerLike = ReturnType<typeof createServer>;
|
|
54
|
+
import { createServer } from "node:http";
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small synchronous JSON record store for Node local adapters.
|
|
3
|
+
*
|
|
4
|
+
* This module intentionally imports node:sqlite and must not be used from a
|
|
5
|
+
* browser bundle. The database handle is kept private so consumers cannot
|
|
6
|
+
* bypass the store's serialization and transaction invariants.
|
|
7
|
+
*/
|
|
8
|
+
export class TerraScaleSqliteStore {
|
|
9
|
+
/**
|
|
10
|
+
* @param {string} databasePath
|
|
11
|
+
*/
|
|
12
|
+
constructor(databasePath: string);
|
|
13
|
+
/**
|
|
14
|
+
* @readonly
|
|
15
|
+
* @type {string}
|
|
16
|
+
*/
|
|
17
|
+
readonly databasePath: string;
|
|
18
|
+
/** @returns {void} */
|
|
19
|
+
close(): void;
|
|
20
|
+
/** @returns {void} */
|
|
21
|
+
reset(): void;
|
|
22
|
+
/**
|
|
23
|
+
* @template T
|
|
24
|
+
* @param {string} namespace
|
|
25
|
+
* @param {string} scope
|
|
26
|
+
* @param {string} id
|
|
27
|
+
* @returns {T | undefined}
|
|
28
|
+
*/
|
|
29
|
+
get<T>(namespace: string, scope: string, id: string): T | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* @template T
|
|
32
|
+
* @param {string} namespace
|
|
33
|
+
* @param {string} scope
|
|
34
|
+
* @returns {T[]}
|
|
35
|
+
*/
|
|
36
|
+
list<T>(namespace: string, scope: string): T[];
|
|
37
|
+
/**
|
|
38
|
+
* @template T
|
|
39
|
+
* @param {string} namespace
|
|
40
|
+
* @returns {readonly {
|
|
41
|
+
* readonly scope: string;
|
|
42
|
+
* readonly id: string;
|
|
43
|
+
* readonly value: T;
|
|
44
|
+
* }[]}
|
|
45
|
+
*/
|
|
46
|
+
listNamespace<T>(namespace: string): readonly {
|
|
47
|
+
readonly scope: string;
|
|
48
|
+
readonly id: string;
|
|
49
|
+
readonly value: T;
|
|
50
|
+
}[];
|
|
51
|
+
/**
|
|
52
|
+
* @template T
|
|
53
|
+
* @param {string} namespace
|
|
54
|
+
* @param {string} scope
|
|
55
|
+
* @param {string} id
|
|
56
|
+
* @param {T} value
|
|
57
|
+
* @returns {void}
|
|
58
|
+
*/
|
|
59
|
+
put<T>(namespace: string, scope: string, id: string, value: T): void;
|
|
60
|
+
/**
|
|
61
|
+
* @param {string} namespace
|
|
62
|
+
* @param {string} scope
|
|
63
|
+
* @param {string} id
|
|
64
|
+
* @returns {boolean}
|
|
65
|
+
*/
|
|
66
|
+
delete(namespace: string, scope: string, id: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* @param {string} namespace
|
|
69
|
+
* @returns {void}
|
|
70
|
+
*/
|
|
71
|
+
clearNamespace(namespace: string): void;
|
|
72
|
+
/**
|
|
73
|
+
* @template T
|
|
74
|
+
* @param {string} key
|
|
75
|
+
* @returns {T | undefined}
|
|
76
|
+
*/
|
|
77
|
+
getMeta<T>(key: string): T | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* @template T
|
|
80
|
+
* @param {string} key
|
|
81
|
+
* @param {T} value
|
|
82
|
+
* @returns {void}
|
|
83
|
+
*/
|
|
84
|
+
setMeta<T>(key: string, value: T): void;
|
|
85
|
+
/**
|
|
86
|
+
* Serialize local native requests and async auth callbacks on this connection.
|
|
87
|
+
*
|
|
88
|
+
* @template T
|
|
89
|
+
* @param {() => Promise<T> | T} work
|
|
90
|
+
* @returns {Promise<T>}
|
|
91
|
+
*/
|
|
92
|
+
exclusive<T>(work: () => Promise<T> | T): Promise<T>;
|
|
93
|
+
/**
|
|
94
|
+
* @template T
|
|
95
|
+
* @param {() => Promise<T>} work
|
|
96
|
+
* @returns {Promise<T>}
|
|
97
|
+
*/
|
|
98
|
+
transactionAsync<T>(work: () => Promise<T>): Promise<T>;
|
|
99
|
+
/**
|
|
100
|
+
* @template T
|
|
101
|
+
* @param {() => T} work
|
|
102
|
+
* @returns {T}
|
|
103
|
+
*/
|
|
104
|
+
transaction<T>(work: () => T): T;
|
|
105
|
+
#private;
|
|
106
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** @import { TerraScaleSqliteRuntimeOptions } from "./index.js" */
|
|
2
|
+
/** @import { DatabaseCommit, DatabaseField, DatabasePoint } from "../database-types.js" */
|
|
3
|
+
/**
|
|
4
|
+
* @param {Omit<TerraScaleSqliteRuntimeOptions, "sqlite">} [options]
|
|
5
|
+
*/
|
|
6
|
+
export function localFixture(options?: Omit<TerraScaleSqliteRuntimeOptions, "sqlite">): Promise<{
|
|
7
|
+
runtime: import("./index.js").TerraScaleSqliteRuntime;
|
|
8
|
+
client: import("../database.js").TerraBaseClient;
|
|
9
|
+
collection: `${string}-${string}-${string}-${string}-${string}`;
|
|
10
|
+
binding: {
|
|
11
|
+
collection: `${string}-${string}-${string}-${string}-${string}`;
|
|
12
|
+
schema_generation: bigint;
|
|
13
|
+
schema_digest: string;
|
|
14
|
+
};
|
|
15
|
+
directory: string;
|
|
16
|
+
databasePath: string;
|
|
17
|
+
commit: (document: string, fields: readonly DatabaseField[], point?: DatabasePoint) => DatabaseCommit;
|
|
18
|
+
close: () => Promise<void>;
|
|
19
|
+
}>;
|
|
20
|
+
/** Local development tests never relax CI/deployment/qualification guards. */
|
|
21
|
+
export const localSqliteUnitTestsAllowed: boolean;
|
|
22
|
+
import type { TerraScaleSqliteRuntimeOptions } from "./index.js";
|
|
23
|
+
import type { DatabaseField } from "../database-types.js";
|
|
24
|
+
import type { DatabasePoint } from "../database-types.js";
|
|
25
|
+
import type { DatabaseCommit } from "../database-types.js";
|