@tinycloud/sdk-services 3.8.0-beta.1 → 3.8.0-beta.18
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/dist/{BaseService-DO7vZ67k.d.ts → BaseService-Ma2MwJAd.d.ts} +1 -1
- package/dist/{BaseService-D-29xShG.d.cts → BaseService-O0iyuFLk.d.cts} +1 -1
- package/dist/IHooksService-4QNODVy6.d.cts +120 -0
- package/dist/IHooksService-CvTpJbQD.d.ts +120 -0
- package/dist/ISQLService-Aly1CBsW.d.ts +242 -0
- package/dist/ISQLService-BOgWzHLT.d.cts +242 -0
- package/dist/context.d.cts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/encryption/index.cjs +80 -7
- package/dist/encryption/index.cjs.map +1 -1
- package/dist/encryption/index.d.cts +23 -11
- package/dist/encryption/index.d.ts +23 -11
- package/dist/encryption/index.js +79 -7
- package/dist/encryption/index.js.map +1 -1
- package/dist/encryption/named-keys.cjs.map +1 -1
- package/dist/encryption/named-keys.d.cts +2 -2
- package/dist/encryption/named-keys.d.ts +2 -2
- package/dist/encryption/named-keys.js.map +1 -1
- package/dist/encryption/resource.cjs.map +1 -1
- package/dist/encryption/resource.js.map +1 -1
- package/dist/feed/index.cjs +787 -0
- package/dist/feed/index.cjs.map +1 -0
- package/dist/feed/index.d.cts +176 -0
- package/dist/feed/index.d.ts +176 -0
- package/dist/feed/index.js +739 -0
- package/dist/feed/index.js.map +1 -0
- package/dist/index.cjs +131 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -116
- package/dist/index.d.ts +16 -116
- package/dist/index.js +130 -15
- package/dist/index.js.map +1 -1
- package/dist/internal/decrypt-transport-response-error.d.cts +1 -1
- package/dist/internal/decrypt-transport-response-error.d.ts +1 -1
- package/dist/kv/index.cjs.map +1 -1
- package/dist/kv/index.d.cts +4 -4
- package/dist/kv/index.d.ts +4 -4
- package/dist/kv/index.js.map +1 -1
- package/dist/kv/replication/index.cjs +1 -0
- package/dist/kv/replication/index.cjs.map +1 -1
- package/dist/kv/replication/index.d.cts +3 -3
- package/dist/kv/replication/index.d.ts +3 -3
- package/dist/kv/replication/index.js +1 -0
- package/dist/kv/replication/index.js.map +1 -1
- package/dist/{scope-Cg00IaWk.d.ts → scope-BZr0QwxX.d.ts} +78 -3
- package/dist/{scope-Cjo4O0uO.d.cts → scope-DEgc9f-W.d.cts} +78 -3
- package/dist/sql/index.cjs +21 -6
- package/dist/sql/index.cjs.map +1 -1
- package/dist/sql/index.d.cts +6 -236
- package/dist/sql/index.d.ts +6 -236
- package/dist/sql/index.js +21 -6
- package/dist/sql/index.js.map +1 -1
- package/dist/telemetry/requestLog.d.cts +1 -1
- package/dist/telemetry/requestLog.d.ts +1 -1
- package/dist/{types-BGRzS1ob.d.ts → types-Bf91gup6.d.ts} +7 -2
- package/dist/{types-DAOyIbXu.d.cts → types-CSd0RYir.d.cts} +1 -1
- package/dist/{types-DAOyIbXu.d.ts → types-CSd0RYir.d.ts} +1 -1
- package/dist/{types-B_rbS4XE.d.cts → types-D4XbIfFJ.d.cts} +7 -2
- package/package.json +6 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as IService, I as IServiceContext, S as ServiceSession,
|
|
1
|
+
import { c as IService, I as IServiceContext, S as ServiceSession, g as ServiceError, h as ServiceHeaders, d as FetchRequestInit, e as FetchResponse, f as Result } from './types-CSd0RYir.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Base Service Types
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as IService, I as IServiceContext, S as ServiceSession,
|
|
1
|
+
import { c as IService, I as IServiceContext, S as ServiceSession, g as ServiceError, h as ServiceHeaders, d as FetchRequestInit, e as FetchResponse, f as Result } from './types-CSd0RYir.cjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Base Service Types
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { f as Result } from './types-CSd0RYir.cjs';
|
|
2
|
+
|
|
3
|
+
type HookServiceName = "kv" | "sql" | "duckdb";
|
|
4
|
+
interface HookSubscription {
|
|
5
|
+
space: string;
|
|
6
|
+
service: HookServiceName;
|
|
7
|
+
pathPrefix?: string;
|
|
8
|
+
abilities?: string[];
|
|
9
|
+
}
|
|
10
|
+
interface HookWebhookScope {
|
|
11
|
+
space: string;
|
|
12
|
+
service: HookServiceName;
|
|
13
|
+
pathPrefix?: string;
|
|
14
|
+
abilities?: string[];
|
|
15
|
+
}
|
|
16
|
+
interface HookWebhookRegistration extends HookWebhookScope {
|
|
17
|
+
callbackUrl: string;
|
|
18
|
+
secret: string;
|
|
19
|
+
}
|
|
20
|
+
interface HookWebhookRecord extends HookWebhookScope {
|
|
21
|
+
id: string;
|
|
22
|
+
subscriberDid?: string;
|
|
23
|
+
callbackUrl: string;
|
|
24
|
+
active: boolean;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
}
|
|
27
|
+
interface HookWebhookListOptions {
|
|
28
|
+
space?: string;
|
|
29
|
+
service?: HookServiceName;
|
|
30
|
+
pathPrefix?: string;
|
|
31
|
+
}
|
|
32
|
+
interface HookWebhookUnregisterOptions {
|
|
33
|
+
target?: HookWebhookScope;
|
|
34
|
+
}
|
|
35
|
+
interface HookEvent {
|
|
36
|
+
type: "write";
|
|
37
|
+
id: string;
|
|
38
|
+
space: string;
|
|
39
|
+
service: string;
|
|
40
|
+
ability: string;
|
|
41
|
+
path?: string;
|
|
42
|
+
/** Logical SQL/DuckDB resource; path may identify an encoded physical table. */
|
|
43
|
+
databasePath?: string;
|
|
44
|
+
actor: string;
|
|
45
|
+
epoch: string;
|
|
46
|
+
eventIndex: number;
|
|
47
|
+
timestamp: string;
|
|
48
|
+
}
|
|
49
|
+
interface HookStreamEvent {
|
|
50
|
+
event: string;
|
|
51
|
+
data: string;
|
|
52
|
+
id?: string;
|
|
53
|
+
}
|
|
54
|
+
interface SubscribeOptions {
|
|
55
|
+
ttlSeconds?: number;
|
|
56
|
+
signal?: AbortSignal;
|
|
57
|
+
/**
|
|
58
|
+
* Called once after the server confirms this authorized stream is ready,
|
|
59
|
+
* initially and after reconnect/renewal. Schedule durable-row reconciliation
|
|
60
|
+
* here; the callback is not awaited and readiness is never a write event.
|
|
61
|
+
*/
|
|
62
|
+
onReady?: () => void;
|
|
63
|
+
}
|
|
64
|
+
interface HooksServiceConfig extends Record<string, unknown> {
|
|
65
|
+
host?: string;
|
|
66
|
+
/** Shared-stream retry tuning; see {@link HookStreamRetryConfig}. */
|
|
67
|
+
streamRetry?: HookStreamRetryConfig;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Retry policy for the shared `/hooks/events` stream. When the stream fails
|
|
71
|
+
* (network error, 5xx, or an expired/rotated ticket rejected with 401/403)
|
|
72
|
+
* it is re-opened with exponential backoff: `HOOK_STREAM_RETRY_BASE_DELAY_MS`
|
|
73
|
+
* (~250 ms) doubling to `HOOK_STREAM_RETRY_MAX_DELAY_MS` (~30 s) with jitter.
|
|
74
|
+
* The retry streak resets after an event is received or a stream remains open
|
|
75
|
+
* for at least 5 seconds. Retries stop when no subscribers remain, when the
|
|
76
|
+
* service is aborted, or when minting the hook ticket is refused (the iterator
|
|
77
|
+
* throws that typed error instead).
|
|
78
|
+
*/
|
|
79
|
+
interface HookStreamRetryConfig {
|
|
80
|
+
/**
|
|
81
|
+
* Delay before retry attempt `attempt` (1-based). Defaults to the jittered
|
|
82
|
+
* exponential backoff described above. Must return milliseconds.
|
|
83
|
+
*/
|
|
84
|
+
delay?: (attempt: number) => number;
|
|
85
|
+
/**
|
|
86
|
+
* How a retry delay is awaited — the injectable clock. `delayMs` is the
|
|
87
|
+
* resolved delay for `attempt`; `signal` aborts the wait early when the
|
|
88
|
+
* subscription set changes or the service stops. Rejecting or throwing is
|
|
89
|
+
* treated like a completed wait. After a custom wait returns — whether it
|
|
90
|
+
* fulfilled, rejected or threw — the service still yields one event-loop
|
|
91
|
+
* turn so a persistently failing stream can never starve the process.
|
|
92
|
+
* Defaults to an abortable, unref'd `setTimeout`.
|
|
93
|
+
*/
|
|
94
|
+
wait?: (delayMs: number, attempt: number, signal: AbortSignal) => Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface IHooksService {
|
|
98
|
+
/**
|
|
99
|
+
* Stream hook events until `options.signal` aborts, the SDK signs out or
|
|
100
|
+
* the session ends, or the consumer stops iterating. Transient stream
|
|
101
|
+
* failures — network errors, 5xx, and an expired or rotated ticket rejected
|
|
102
|
+
* by `/hooks/events` (401/403) — are retried internally with backoff and
|
|
103
|
+
* never reach the iterator.
|
|
104
|
+
*
|
|
105
|
+
* The iterator throws when minting the hook ticket is refused. The thrown
|
|
106
|
+
* plain `ServiceError` carries `meta.status` with the refusing HTTP status,
|
|
107
|
+
* so `for await` consumers can branch on it. Stream diagnostics contain only
|
|
108
|
+
* SDK allow-listed identifiers; foreign error messages and causes are not
|
|
109
|
+
* copied.
|
|
110
|
+
* `options.onReady` schedules catch-up after each server-confirmed ready
|
|
111
|
+
* stream, including an unchanged ready stream joined by a late subscriber.
|
|
112
|
+
* Subscribe/consume before draining stored rows; notifications are not replay.
|
|
113
|
+
*/
|
|
114
|
+
subscribe(subscriptions: HookSubscription[], options?: SubscribeOptions): AsyncIterable<HookEvent>;
|
|
115
|
+
register(webhook: HookWebhookRegistration): Promise<Result<HookWebhookRecord>>;
|
|
116
|
+
list(options?: HookWebhookListOptions): Promise<Result<HookWebhookRecord[]>>;
|
|
117
|
+
unregister(id: string, options?: HookWebhookUnregisterOptions): Promise<Result<void>>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type { HookSubscription as H, IHooksService as I, SubscribeOptions as S, HooksServiceConfig as a, HookEvent as b, HookWebhookRegistration as c, HookWebhookRecord as d, HookWebhookListOptions as e, HookWebhookUnregisterOptions as f, HookServiceName as g, HookStreamEvent as h, HookStreamRetryConfig as i, HookWebhookScope as j };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { f as Result } from './types-CSd0RYir.js';
|
|
2
|
+
|
|
3
|
+
type HookServiceName = "kv" | "sql" | "duckdb";
|
|
4
|
+
interface HookSubscription {
|
|
5
|
+
space: string;
|
|
6
|
+
service: HookServiceName;
|
|
7
|
+
pathPrefix?: string;
|
|
8
|
+
abilities?: string[];
|
|
9
|
+
}
|
|
10
|
+
interface HookWebhookScope {
|
|
11
|
+
space: string;
|
|
12
|
+
service: HookServiceName;
|
|
13
|
+
pathPrefix?: string;
|
|
14
|
+
abilities?: string[];
|
|
15
|
+
}
|
|
16
|
+
interface HookWebhookRegistration extends HookWebhookScope {
|
|
17
|
+
callbackUrl: string;
|
|
18
|
+
secret: string;
|
|
19
|
+
}
|
|
20
|
+
interface HookWebhookRecord extends HookWebhookScope {
|
|
21
|
+
id: string;
|
|
22
|
+
subscriberDid?: string;
|
|
23
|
+
callbackUrl: string;
|
|
24
|
+
active: boolean;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
}
|
|
27
|
+
interface HookWebhookListOptions {
|
|
28
|
+
space?: string;
|
|
29
|
+
service?: HookServiceName;
|
|
30
|
+
pathPrefix?: string;
|
|
31
|
+
}
|
|
32
|
+
interface HookWebhookUnregisterOptions {
|
|
33
|
+
target?: HookWebhookScope;
|
|
34
|
+
}
|
|
35
|
+
interface HookEvent {
|
|
36
|
+
type: "write";
|
|
37
|
+
id: string;
|
|
38
|
+
space: string;
|
|
39
|
+
service: string;
|
|
40
|
+
ability: string;
|
|
41
|
+
path?: string;
|
|
42
|
+
/** Logical SQL/DuckDB resource; path may identify an encoded physical table. */
|
|
43
|
+
databasePath?: string;
|
|
44
|
+
actor: string;
|
|
45
|
+
epoch: string;
|
|
46
|
+
eventIndex: number;
|
|
47
|
+
timestamp: string;
|
|
48
|
+
}
|
|
49
|
+
interface HookStreamEvent {
|
|
50
|
+
event: string;
|
|
51
|
+
data: string;
|
|
52
|
+
id?: string;
|
|
53
|
+
}
|
|
54
|
+
interface SubscribeOptions {
|
|
55
|
+
ttlSeconds?: number;
|
|
56
|
+
signal?: AbortSignal;
|
|
57
|
+
/**
|
|
58
|
+
* Called once after the server confirms this authorized stream is ready,
|
|
59
|
+
* initially and after reconnect/renewal. Schedule durable-row reconciliation
|
|
60
|
+
* here; the callback is not awaited and readiness is never a write event.
|
|
61
|
+
*/
|
|
62
|
+
onReady?: () => void;
|
|
63
|
+
}
|
|
64
|
+
interface HooksServiceConfig extends Record<string, unknown> {
|
|
65
|
+
host?: string;
|
|
66
|
+
/** Shared-stream retry tuning; see {@link HookStreamRetryConfig}. */
|
|
67
|
+
streamRetry?: HookStreamRetryConfig;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Retry policy for the shared `/hooks/events` stream. When the stream fails
|
|
71
|
+
* (network error, 5xx, or an expired/rotated ticket rejected with 401/403)
|
|
72
|
+
* it is re-opened with exponential backoff: `HOOK_STREAM_RETRY_BASE_DELAY_MS`
|
|
73
|
+
* (~250 ms) doubling to `HOOK_STREAM_RETRY_MAX_DELAY_MS` (~30 s) with jitter.
|
|
74
|
+
* The retry streak resets after an event is received or a stream remains open
|
|
75
|
+
* for at least 5 seconds. Retries stop when no subscribers remain, when the
|
|
76
|
+
* service is aborted, or when minting the hook ticket is refused (the iterator
|
|
77
|
+
* throws that typed error instead).
|
|
78
|
+
*/
|
|
79
|
+
interface HookStreamRetryConfig {
|
|
80
|
+
/**
|
|
81
|
+
* Delay before retry attempt `attempt` (1-based). Defaults to the jittered
|
|
82
|
+
* exponential backoff described above. Must return milliseconds.
|
|
83
|
+
*/
|
|
84
|
+
delay?: (attempt: number) => number;
|
|
85
|
+
/**
|
|
86
|
+
* How a retry delay is awaited — the injectable clock. `delayMs` is the
|
|
87
|
+
* resolved delay for `attempt`; `signal` aborts the wait early when the
|
|
88
|
+
* subscription set changes or the service stops. Rejecting or throwing is
|
|
89
|
+
* treated like a completed wait. After a custom wait returns — whether it
|
|
90
|
+
* fulfilled, rejected or threw — the service still yields one event-loop
|
|
91
|
+
* turn so a persistently failing stream can never starve the process.
|
|
92
|
+
* Defaults to an abortable, unref'd `setTimeout`.
|
|
93
|
+
*/
|
|
94
|
+
wait?: (delayMs: number, attempt: number, signal: AbortSignal) => Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
interface IHooksService {
|
|
98
|
+
/**
|
|
99
|
+
* Stream hook events until `options.signal` aborts, the SDK signs out or
|
|
100
|
+
* the session ends, or the consumer stops iterating. Transient stream
|
|
101
|
+
* failures — network errors, 5xx, and an expired or rotated ticket rejected
|
|
102
|
+
* by `/hooks/events` (401/403) — are retried internally with backoff and
|
|
103
|
+
* never reach the iterator.
|
|
104
|
+
*
|
|
105
|
+
* The iterator throws when minting the hook ticket is refused. The thrown
|
|
106
|
+
* plain `ServiceError` carries `meta.status` with the refusing HTTP status,
|
|
107
|
+
* so `for await` consumers can branch on it. Stream diagnostics contain only
|
|
108
|
+
* SDK allow-listed identifiers; foreign error messages and causes are not
|
|
109
|
+
* copied.
|
|
110
|
+
* `options.onReady` schedules catch-up after each server-confirmed ready
|
|
111
|
+
* stream, including an unchanged ready stream joined by a late subscriber.
|
|
112
|
+
* Subscribe/consume before draining stored rows; notifications are not replay.
|
|
113
|
+
*/
|
|
114
|
+
subscribe(subscriptions: HookSubscription[], options?: SubscribeOptions): AsyncIterable<HookEvent>;
|
|
115
|
+
register(webhook: HookWebhookRegistration): Promise<Result<HookWebhookRecord>>;
|
|
116
|
+
list(options?: HookWebhookListOptions): Promise<Result<HookWebhookRecord[]>>;
|
|
117
|
+
unregister(id: string, options?: HookWebhookUnregisterOptions): Promise<Result<void>>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export type { HookSubscription as H, IHooksService as I, SubscribeOptions as S, HooksServiceConfig as a, HookEvent as b, HookWebhookRegistration as c, HookWebhookRecord as d, HookWebhookListOptions as e, HookWebhookUnregisterOptions as f, HookServiceName as g, HookStreamEvent as h, HookStreamRetryConfig as i, HookWebhookScope as j };
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { f as Result, c as IService } from './types-CSd0RYir.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SQL Service Types
|
|
5
|
+
*
|
|
6
|
+
* Type definitions for the SQL service operations.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for SQLService.
|
|
10
|
+
*/
|
|
11
|
+
interface SQLServiceConfig {
|
|
12
|
+
/**
|
|
13
|
+
* Default database name.
|
|
14
|
+
* If not set, operations default to "default".
|
|
15
|
+
*/
|
|
16
|
+
defaultDatabase?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Timeout in milliseconds for each SQL request, including reading the
|
|
19
|
+
* response body. When it elapses the request is aborted and the operation
|
|
20
|
+
* returns an `ErrorCodes.TIMEOUT` error. Unset (the default), `0`, or
|
|
21
|
+
* `Infinity` means no timeout.
|
|
22
|
+
*/
|
|
23
|
+
timeout?: number;
|
|
24
|
+
/** Allow additional config properties */
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Options for SQL query operations.
|
|
29
|
+
*/
|
|
30
|
+
interface QueryOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Custom abort signal for this operation.
|
|
33
|
+
*/
|
|
34
|
+
signal?: AbortSignal;
|
|
35
|
+
/** Maximum rows the node may return. Nodes without limit support ignore it. */
|
|
36
|
+
maxRows?: number;
|
|
37
|
+
/** Maximum serialized result bytes the node may return. */
|
|
38
|
+
maxBytes?: number;
|
|
39
|
+
/** Redact query failure details before return and ordinary service-error events. */
|
|
40
|
+
redactErrors?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Options for SQL execute operations.
|
|
44
|
+
*/
|
|
45
|
+
interface ExecuteOptions {
|
|
46
|
+
/**
|
|
47
|
+
* Schema initialization statements (CREATE TABLE IF NOT EXISTS ...).
|
|
48
|
+
* Executed before the main statement on first write.
|
|
49
|
+
*/
|
|
50
|
+
schema?: string[];
|
|
51
|
+
/**
|
|
52
|
+
* Custom abort signal for this operation.
|
|
53
|
+
*/
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
/** Redact execute failure details before return and ordinary service-error events. */
|
|
56
|
+
redactErrors?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Options for SQL batch operations.
|
|
60
|
+
*/
|
|
61
|
+
interface BatchOptions {
|
|
62
|
+
/**
|
|
63
|
+
* Custom abort signal for this operation.
|
|
64
|
+
*/
|
|
65
|
+
signal?: AbortSignal;
|
|
66
|
+
/** Redact batch failure details before return and ordinary service-error events. */
|
|
67
|
+
redactErrors?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A SQL value: null, number, string, or binary data.
|
|
71
|
+
*/
|
|
72
|
+
type SqlValue = null | number | string | Uint8Array;
|
|
73
|
+
/**
|
|
74
|
+
* A SQL statement with optional parameters.
|
|
75
|
+
*/
|
|
76
|
+
interface SqlStatement {
|
|
77
|
+
sql: string;
|
|
78
|
+
params?: SqlValue[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Response from SQL query operations.
|
|
82
|
+
*/
|
|
83
|
+
interface QueryResponse<T = Record<string, unknown>> {
|
|
84
|
+
columns: string[];
|
|
85
|
+
rows: T[][];
|
|
86
|
+
rowCount: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Response from SQL execute operations.
|
|
90
|
+
*/
|
|
91
|
+
interface ExecuteResponse {
|
|
92
|
+
changes: number;
|
|
93
|
+
lastInsertRowId: number | null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Response from SQL batch operations.
|
|
97
|
+
*/
|
|
98
|
+
interface BatchResponse {
|
|
99
|
+
results: ExecuteResponse[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* A versioned SQL migration owned by an application or SDK subsystem.
|
|
103
|
+
*/
|
|
104
|
+
interface SqlMigration {
|
|
105
|
+
/**
|
|
106
|
+
* Stable migration id within the namespace, e.g. "001_initial".
|
|
107
|
+
*/
|
|
108
|
+
id: string;
|
|
109
|
+
/**
|
|
110
|
+
* SQL statements to apply when this migration has not been recorded.
|
|
111
|
+
* Statements should be idempotent where SQLite supports it.
|
|
112
|
+
*/
|
|
113
|
+
sql: Array<string | SqlStatement>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Options for applying SQL migrations.
|
|
117
|
+
*/
|
|
118
|
+
interface SqlMigrationApplyOptions {
|
|
119
|
+
/**
|
|
120
|
+
* Namespace for this migration set, usually an app id or SDK subsystem.
|
|
121
|
+
*/
|
|
122
|
+
namespace: string;
|
|
123
|
+
/**
|
|
124
|
+
* Ordered migration list.
|
|
125
|
+
*/
|
|
126
|
+
migrations: SqlMigration[];
|
|
127
|
+
/**
|
|
128
|
+
* Custom abort signal for migration operations.
|
|
129
|
+
*/
|
|
130
|
+
signal?: AbortSignal;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Result from applying SQL migrations.
|
|
134
|
+
*/
|
|
135
|
+
interface SqlMigrationApplyResponse {
|
|
136
|
+
database: string;
|
|
137
|
+
namespace: string;
|
|
138
|
+
status: "already_current" | "applied";
|
|
139
|
+
applied: string[];
|
|
140
|
+
skipped: string[];
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* SQL service action types.
|
|
144
|
+
*
|
|
145
|
+
* URNs derive from the canonical capability registry in `@tinycloud/bootstrap`
|
|
146
|
+
* (TC-112 single source of truth, vendored from tinycloud-node). `insert`,
|
|
147
|
+
* `update`, and `delete` were dropped — zero client refs and never accepted
|
|
148
|
+
* node-side. `select` is a deprecated alias of `read`. `execute`/`export` are
|
|
149
|
+
* request-kind artifacts, not grantable capabilities: the node routes them by
|
|
150
|
+
* request-body kind, so they are absent from the registry but kept here as the
|
|
151
|
+
* invocation ability the client sends today (wire alignment tracked in TC-114).
|
|
152
|
+
*/
|
|
153
|
+
declare const SQLAction: {
|
|
154
|
+
readonly READ: "tinycloud.sql/read";
|
|
155
|
+
readonly WRITE: "tinycloud.sql/write";
|
|
156
|
+
readonly SCHEMA: "tinycloud.sql/schema";
|
|
157
|
+
readonly ADMIN: "tinycloud.sql/admin";
|
|
158
|
+
readonly SELECT: "tinycloud.sql/select";
|
|
159
|
+
readonly EXECUTE: "tinycloud.sql/execute";
|
|
160
|
+
readonly EXPORT: "tinycloud.sql/export";
|
|
161
|
+
readonly ALL: "tinycloud.sql/*";
|
|
162
|
+
};
|
|
163
|
+
type SQLActionType = (typeof SQLAction)[keyof typeof SQLAction];
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* ISQLService - Interface for SQL service.
|
|
167
|
+
*
|
|
168
|
+
* Platform-agnostic interface for SQL database operations.
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Migration helper bound to a specific database.
|
|
173
|
+
*/
|
|
174
|
+
interface ISQLMigrations {
|
|
175
|
+
/**
|
|
176
|
+
* Apply ordered, app-owned migrations and record completed ids.
|
|
177
|
+
*/
|
|
178
|
+
apply(options: SqlMigrationApplyOptions): Promise<Result<SqlMigrationApplyResponse>>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Database handle interface for operations on a specific named database.
|
|
182
|
+
*/
|
|
183
|
+
interface IDatabaseHandle {
|
|
184
|
+
/** The database name */
|
|
185
|
+
readonly name: string;
|
|
186
|
+
/** Versioned schema migration helper. */
|
|
187
|
+
readonly migrations: ISQLMigrations;
|
|
188
|
+
/**
|
|
189
|
+
* Execute a SQL query and return rows.
|
|
190
|
+
*/
|
|
191
|
+
query<T = Record<string, unknown>>(sql: string, params?: SqlValue[], options?: QueryOptions): Promise<Result<QueryResponse<T>>>;
|
|
192
|
+
/**
|
|
193
|
+
* Execute a SQL statement and return change count.
|
|
194
|
+
*/
|
|
195
|
+
execute(sql: string, params?: SqlValue[], options?: ExecuteOptions): Promise<Result<ExecuteResponse>>;
|
|
196
|
+
/**
|
|
197
|
+
* Execute multiple statements in a transaction.
|
|
198
|
+
*/
|
|
199
|
+
batch(statements: SqlStatement[], options?: BatchOptions): Promise<Result<BatchResponse>>;
|
|
200
|
+
/**
|
|
201
|
+
* Execute a named prepared statement from delegation caveats.
|
|
202
|
+
*/
|
|
203
|
+
executeStatement(name: string, params?: SqlValue[], options?: QueryOptions): Promise<Result<QueryResponse | ExecuteResponse>>;
|
|
204
|
+
/**
|
|
205
|
+
* Export the raw SQLite database file.
|
|
206
|
+
*/
|
|
207
|
+
export(options?: QueryOptions): Promise<Result<Blob>>;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* SQL service interface.
|
|
211
|
+
*
|
|
212
|
+
* Provides SQL database operations with:
|
|
213
|
+
* - Result type pattern (no throwing)
|
|
214
|
+
* - Named database handles
|
|
215
|
+
* - Configurable timeouts
|
|
216
|
+
* - Abort signal support
|
|
217
|
+
*/
|
|
218
|
+
interface ISQLService extends IService {
|
|
219
|
+
/**
|
|
220
|
+
* Get a handle to a named database.
|
|
221
|
+
* @param name - Database name (defaults to "default")
|
|
222
|
+
*/
|
|
223
|
+
db(name?: string): IDatabaseHandle;
|
|
224
|
+
/**
|
|
225
|
+
* Shortcut: query the default database.
|
|
226
|
+
*/
|
|
227
|
+
query<T = Record<string, unknown>>(sql: string, params?: SqlValue[], options?: QueryOptions): Promise<Result<QueryResponse<T>>>;
|
|
228
|
+
/**
|
|
229
|
+
* Shortcut: execute on the default database.
|
|
230
|
+
*/
|
|
231
|
+
execute(sql: string, params?: SqlValue[], options?: ExecuteOptions): Promise<Result<ExecuteResponse>>;
|
|
232
|
+
/**
|
|
233
|
+
* Shortcut: batch on the default database.
|
|
234
|
+
*/
|
|
235
|
+
batch(statements: SqlStatement[], options?: BatchOptions): Promise<Result<BatchResponse>>;
|
|
236
|
+
/**
|
|
237
|
+
* Service configuration.
|
|
238
|
+
*/
|
|
239
|
+
readonly config: SQLServiceConfig;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export { type BatchOptions as B, type ExecuteOptions as E, type IDatabaseHandle as I, type QueryOptions as Q, SQLAction as S, type BatchResponse as a, type ExecuteResponse as b, type ISQLMigrations as c, type ISQLService as d, type QueryResponse as e, type SQLActionType as f, type SQLServiceConfig as g, type SqlMigration as h, type SqlMigrationApplyOptions as i, type SqlMigrationApplyResponse as j, type SqlStatement as k, type SqlValue as l };
|