@tinycloud/sdk-services 3.8.0-beta.16 → 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.d.cts +4 -4
- package/dist/encryption/index.d.ts +4 -4
- package/dist/encryption/named-keys.d.cts +2 -2
- package/dist/encryption/named-keys.d.ts +2 -2
- 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 +51 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -115
- package/dist/index.d.ts +15 -115
- package/dist/index.js +51 -8
- 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.d.cts +4 -4
- package/dist/kv/index.d.ts +4 -4
- package/dist/kv/replication/index.d.cts +3 -3
- package/dist/kv/replication/index.d.ts +3 -3
- package/dist/{scope-1-8skVDk.d.ts → scope-BZr0QwxX.d.ts} +1 -1
- package/dist/{scope-Dv3IAXMr.d.cts → scope-DEgc9f-W.d.cts} +1 -1
- 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-DZBExWAf.d.ts → types-Bf91gup6.d.ts} +1 -1
- package/dist/{types-DAOyIbXu.d.ts → types-CSd0RYir.d.cts} +1 -1
- package/dist/{types-DAOyIbXu.d.cts → types-CSd0RYir.d.ts} +1 -1
- package/dist/{types-CBKrdtP8.d.cts → types-D4XbIfFJ.d.cts} +1 -1
- package/package.json +6 -1
package/dist/sql/index.d.cts
CHANGED
|
@@ -1,238 +1,7 @@
|
|
|
1
|
-
import { B as BaseService } from '../BaseService-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* SQL Service Types
|
|
6
|
-
*
|
|
7
|
-
* Type definitions for the SQL service operations.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Configuration for SQLService.
|
|
11
|
-
*/
|
|
12
|
-
interface SQLServiceConfig {
|
|
13
|
-
/**
|
|
14
|
-
* Default database name.
|
|
15
|
-
* If not set, operations default to "default".
|
|
16
|
-
*/
|
|
17
|
-
defaultDatabase?: string;
|
|
18
|
-
/**
|
|
19
|
-
* Timeout in milliseconds for each SQL request, including reading the
|
|
20
|
-
* response body. When it elapses the request is aborted and the operation
|
|
21
|
-
* returns an `ErrorCodes.TIMEOUT` error. Unset (the default), `0`, or
|
|
22
|
-
* `Infinity` means no timeout.
|
|
23
|
-
*/
|
|
24
|
-
timeout?: number;
|
|
25
|
-
/** Allow additional config properties */
|
|
26
|
-
[key: string]: unknown;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Options for SQL query operations.
|
|
30
|
-
*/
|
|
31
|
-
interface QueryOptions {
|
|
32
|
-
/**
|
|
33
|
-
* Custom abort signal for this operation.
|
|
34
|
-
*/
|
|
35
|
-
signal?: AbortSignal;
|
|
36
|
-
/** Maximum rows the node may return. Nodes without limit support ignore it. */
|
|
37
|
-
maxRows?: number;
|
|
38
|
-
/** Maximum serialized result bytes the node may return. */
|
|
39
|
-
maxBytes?: number;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Options for SQL execute operations.
|
|
43
|
-
*/
|
|
44
|
-
interface ExecuteOptions {
|
|
45
|
-
/**
|
|
46
|
-
* Schema initialization statements (CREATE TABLE IF NOT EXISTS ...).
|
|
47
|
-
* Executed before the main statement on first write.
|
|
48
|
-
*/
|
|
49
|
-
schema?: string[];
|
|
50
|
-
/**
|
|
51
|
-
* Custom abort signal for this operation.
|
|
52
|
-
*/
|
|
53
|
-
signal?: AbortSignal;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Options for SQL batch operations.
|
|
57
|
-
*/
|
|
58
|
-
interface BatchOptions {
|
|
59
|
-
/**
|
|
60
|
-
* Custom abort signal for this operation.
|
|
61
|
-
*/
|
|
62
|
-
signal?: AbortSignal;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* A SQL value: null, number, string, or binary data.
|
|
66
|
-
*/
|
|
67
|
-
type SqlValue = null | number | string | Uint8Array;
|
|
68
|
-
/**
|
|
69
|
-
* A SQL statement with optional parameters.
|
|
70
|
-
*/
|
|
71
|
-
interface SqlStatement {
|
|
72
|
-
sql: string;
|
|
73
|
-
params?: SqlValue[];
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Response from SQL query operations.
|
|
77
|
-
*/
|
|
78
|
-
interface QueryResponse<T = Record<string, unknown>> {
|
|
79
|
-
columns: string[];
|
|
80
|
-
rows: T[][];
|
|
81
|
-
rowCount: number;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Response from SQL execute operations.
|
|
85
|
-
*/
|
|
86
|
-
interface ExecuteResponse {
|
|
87
|
-
changes: number;
|
|
88
|
-
lastInsertRowId: number | null;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Response from SQL batch operations.
|
|
92
|
-
*/
|
|
93
|
-
interface BatchResponse {
|
|
94
|
-
results: ExecuteResponse[];
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* A versioned SQL migration owned by an application or SDK subsystem.
|
|
98
|
-
*/
|
|
99
|
-
interface SqlMigration {
|
|
100
|
-
/**
|
|
101
|
-
* Stable migration id within the namespace, e.g. "001_initial".
|
|
102
|
-
*/
|
|
103
|
-
id: string;
|
|
104
|
-
/**
|
|
105
|
-
* SQL statements to apply when this migration has not been recorded.
|
|
106
|
-
* Statements should be idempotent where SQLite supports it.
|
|
107
|
-
*/
|
|
108
|
-
sql: Array<string | SqlStatement>;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Options for applying SQL migrations.
|
|
112
|
-
*/
|
|
113
|
-
interface SqlMigrationApplyOptions {
|
|
114
|
-
/**
|
|
115
|
-
* Namespace for this migration set, usually an app id or SDK subsystem.
|
|
116
|
-
*/
|
|
117
|
-
namespace: string;
|
|
118
|
-
/**
|
|
119
|
-
* Ordered migration list.
|
|
120
|
-
*/
|
|
121
|
-
migrations: SqlMigration[];
|
|
122
|
-
/**
|
|
123
|
-
* Custom abort signal for migration operations.
|
|
124
|
-
*/
|
|
125
|
-
signal?: AbortSignal;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Result from applying SQL migrations.
|
|
129
|
-
*/
|
|
130
|
-
interface SqlMigrationApplyResponse {
|
|
131
|
-
database: string;
|
|
132
|
-
namespace: string;
|
|
133
|
-
status: "already_current" | "applied";
|
|
134
|
-
applied: string[];
|
|
135
|
-
skipped: string[];
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* SQL service action types.
|
|
139
|
-
*
|
|
140
|
-
* URNs derive from the canonical capability registry in `@tinycloud/bootstrap`
|
|
141
|
-
* (TC-112 single source of truth, vendored from tinycloud-node). `insert`,
|
|
142
|
-
* `update`, and `delete` were dropped — zero client refs and never accepted
|
|
143
|
-
* node-side. `select` is a deprecated alias of `read`. `execute`/`export` are
|
|
144
|
-
* request-kind artifacts, not grantable capabilities: the node routes them by
|
|
145
|
-
* request-body kind, so they are absent from the registry but kept here as the
|
|
146
|
-
* invocation ability the client sends today (wire alignment tracked in TC-114).
|
|
147
|
-
*/
|
|
148
|
-
declare const SQLAction: {
|
|
149
|
-
readonly READ: "tinycloud.sql/read";
|
|
150
|
-
readonly WRITE: "tinycloud.sql/write";
|
|
151
|
-
readonly SCHEMA: "tinycloud.sql/schema";
|
|
152
|
-
readonly ADMIN: "tinycloud.sql/admin";
|
|
153
|
-
readonly SELECT: "tinycloud.sql/select";
|
|
154
|
-
readonly EXECUTE: "tinycloud.sql/execute";
|
|
155
|
-
readonly EXPORT: "tinycloud.sql/export";
|
|
156
|
-
readonly ALL: "tinycloud.sql/*";
|
|
157
|
-
};
|
|
158
|
-
type SQLActionType = (typeof SQLAction)[keyof typeof SQLAction];
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* ISQLService - Interface for SQL service.
|
|
162
|
-
*
|
|
163
|
-
* Platform-agnostic interface for SQL database operations.
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Migration helper bound to a specific database.
|
|
168
|
-
*/
|
|
169
|
-
interface ISQLMigrations {
|
|
170
|
-
/**
|
|
171
|
-
* Apply ordered, app-owned migrations and record completed ids.
|
|
172
|
-
*/
|
|
173
|
-
apply(options: SqlMigrationApplyOptions): Promise<Result<SqlMigrationApplyResponse>>;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Database handle interface for operations on a specific named database.
|
|
177
|
-
*/
|
|
178
|
-
interface IDatabaseHandle {
|
|
179
|
-
/** The database name */
|
|
180
|
-
readonly name: string;
|
|
181
|
-
/** Versioned schema migration helper. */
|
|
182
|
-
readonly migrations: ISQLMigrations;
|
|
183
|
-
/**
|
|
184
|
-
* Execute a SQL query and return rows.
|
|
185
|
-
*/
|
|
186
|
-
query<T = Record<string, unknown>>(sql: string, params?: SqlValue[], options?: QueryOptions): Promise<Result<QueryResponse<T>>>;
|
|
187
|
-
/**
|
|
188
|
-
* Execute a SQL statement and return change count.
|
|
189
|
-
*/
|
|
190
|
-
execute(sql: string, params?: SqlValue[], options?: ExecuteOptions): Promise<Result<ExecuteResponse>>;
|
|
191
|
-
/**
|
|
192
|
-
* Execute multiple statements in a transaction.
|
|
193
|
-
*/
|
|
194
|
-
batch(statements: SqlStatement[], options?: BatchOptions): Promise<Result<BatchResponse>>;
|
|
195
|
-
/**
|
|
196
|
-
* Execute a named prepared statement from delegation caveats.
|
|
197
|
-
*/
|
|
198
|
-
executeStatement(name: string, params?: SqlValue[], options?: QueryOptions): Promise<Result<QueryResponse | ExecuteResponse>>;
|
|
199
|
-
/**
|
|
200
|
-
* Export the raw SQLite database file.
|
|
201
|
-
*/
|
|
202
|
-
export(options?: QueryOptions): Promise<Result<Blob>>;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* SQL service interface.
|
|
206
|
-
*
|
|
207
|
-
* Provides SQL database operations with:
|
|
208
|
-
* - Result type pattern (no throwing)
|
|
209
|
-
* - Named database handles
|
|
210
|
-
* - Configurable timeouts
|
|
211
|
-
* - Abort signal support
|
|
212
|
-
*/
|
|
213
|
-
interface ISQLService extends IService {
|
|
214
|
-
/**
|
|
215
|
-
* Get a handle to a named database.
|
|
216
|
-
* @param name - Database name (defaults to "default")
|
|
217
|
-
*/
|
|
218
|
-
db(name?: string): IDatabaseHandle;
|
|
219
|
-
/**
|
|
220
|
-
* Shortcut: query the default database.
|
|
221
|
-
*/
|
|
222
|
-
query<T = Record<string, unknown>>(sql: string, params?: SqlValue[], options?: QueryOptions): Promise<Result<QueryResponse<T>>>;
|
|
223
|
-
/**
|
|
224
|
-
* Shortcut: execute on the default database.
|
|
225
|
-
*/
|
|
226
|
-
execute(sql: string, params?: SqlValue[], options?: ExecuteOptions): Promise<Result<ExecuteResponse>>;
|
|
227
|
-
/**
|
|
228
|
-
* Shortcut: batch on the default database.
|
|
229
|
-
*/
|
|
230
|
-
batch(statements: SqlStatement[], options?: BatchOptions): Promise<Result<BatchResponse>>;
|
|
231
|
-
/**
|
|
232
|
-
* Service configuration.
|
|
233
|
-
*/
|
|
234
|
-
readonly config: SQLServiceConfig;
|
|
235
|
-
}
|
|
1
|
+
import { B as BaseService } from '../BaseService-O0iyuFLk.cjs';
|
|
2
|
+
import { f as Result } from '../types-CSd0RYir.cjs';
|
|
3
|
+
import { d as ISQLService, g as SQLServiceConfig, I as IDatabaseHandle, l as SqlValue, Q as QueryOptions, e as QueryResponse, E as ExecuteOptions, b as ExecuteResponse, k as SqlStatement, B as BatchOptions, a as BatchResponse, i as SqlMigrationApplyOptions, j as SqlMigrationApplyResponse, c as ISQLMigrations } from '../ISQLService-BOgWzHLT.cjs';
|
|
4
|
+
export { S as SQLAction, f as SQLActionType, h as SqlMigration } from '../ISQLService-BOgWzHLT.cjs';
|
|
236
5
|
|
|
237
6
|
/**
|
|
238
7
|
* SQLService - SQL database service implementation.
|
|
@@ -279,6 +48,7 @@ declare class SQLService extends BaseService implements ISQLService {
|
|
|
279
48
|
private actionsForSqlBatch;
|
|
280
49
|
private dedupeActions;
|
|
281
50
|
private invokeSQLAny;
|
|
51
|
+
private redactFailure;
|
|
282
52
|
private handleErrorResponse;
|
|
283
53
|
private mapHttpStatusToErrorCode;
|
|
284
54
|
}
|
|
@@ -308,4 +78,4 @@ declare class SQLMigrations implements ISQLMigrations {
|
|
|
308
78
|
apply(options: SqlMigrationApplyOptions): Promise<Result<SqlMigrationApplyResponse>>;
|
|
309
79
|
}
|
|
310
80
|
|
|
311
|
-
export {
|
|
81
|
+
export { BatchOptions, BatchResponse, DatabaseHandle, ExecuteOptions, ExecuteResponse, IDatabaseHandle, ISQLMigrations, ISQLService, QueryOptions, QueryResponse, SQLMigrations, SQLService, SQLServiceConfig, SqlMigrationApplyOptions, SqlMigrationApplyResponse, SqlStatement, SqlValue };
|
package/dist/sql/index.d.ts
CHANGED
|
@@ -1,238 +1,7 @@
|
|
|
1
|
-
import { B as BaseService } from '../BaseService-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* SQL Service Types
|
|
6
|
-
*
|
|
7
|
-
* Type definitions for the SQL service operations.
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Configuration for SQLService.
|
|
11
|
-
*/
|
|
12
|
-
interface SQLServiceConfig {
|
|
13
|
-
/**
|
|
14
|
-
* Default database name.
|
|
15
|
-
* If not set, operations default to "default".
|
|
16
|
-
*/
|
|
17
|
-
defaultDatabase?: string;
|
|
18
|
-
/**
|
|
19
|
-
* Timeout in milliseconds for each SQL request, including reading the
|
|
20
|
-
* response body. When it elapses the request is aborted and the operation
|
|
21
|
-
* returns an `ErrorCodes.TIMEOUT` error. Unset (the default), `0`, or
|
|
22
|
-
* `Infinity` means no timeout.
|
|
23
|
-
*/
|
|
24
|
-
timeout?: number;
|
|
25
|
-
/** Allow additional config properties */
|
|
26
|
-
[key: string]: unknown;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Options for SQL query operations.
|
|
30
|
-
*/
|
|
31
|
-
interface QueryOptions {
|
|
32
|
-
/**
|
|
33
|
-
* Custom abort signal for this operation.
|
|
34
|
-
*/
|
|
35
|
-
signal?: AbortSignal;
|
|
36
|
-
/** Maximum rows the node may return. Nodes without limit support ignore it. */
|
|
37
|
-
maxRows?: number;
|
|
38
|
-
/** Maximum serialized result bytes the node may return. */
|
|
39
|
-
maxBytes?: number;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Options for SQL execute operations.
|
|
43
|
-
*/
|
|
44
|
-
interface ExecuteOptions {
|
|
45
|
-
/**
|
|
46
|
-
* Schema initialization statements (CREATE TABLE IF NOT EXISTS ...).
|
|
47
|
-
* Executed before the main statement on first write.
|
|
48
|
-
*/
|
|
49
|
-
schema?: string[];
|
|
50
|
-
/**
|
|
51
|
-
* Custom abort signal for this operation.
|
|
52
|
-
*/
|
|
53
|
-
signal?: AbortSignal;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Options for SQL batch operations.
|
|
57
|
-
*/
|
|
58
|
-
interface BatchOptions {
|
|
59
|
-
/**
|
|
60
|
-
* Custom abort signal for this operation.
|
|
61
|
-
*/
|
|
62
|
-
signal?: AbortSignal;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* A SQL value: null, number, string, or binary data.
|
|
66
|
-
*/
|
|
67
|
-
type SqlValue = null | number | string | Uint8Array;
|
|
68
|
-
/**
|
|
69
|
-
* A SQL statement with optional parameters.
|
|
70
|
-
*/
|
|
71
|
-
interface SqlStatement {
|
|
72
|
-
sql: string;
|
|
73
|
-
params?: SqlValue[];
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Response from SQL query operations.
|
|
77
|
-
*/
|
|
78
|
-
interface QueryResponse<T = Record<string, unknown>> {
|
|
79
|
-
columns: string[];
|
|
80
|
-
rows: T[][];
|
|
81
|
-
rowCount: number;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Response from SQL execute operations.
|
|
85
|
-
*/
|
|
86
|
-
interface ExecuteResponse {
|
|
87
|
-
changes: number;
|
|
88
|
-
lastInsertRowId: number | null;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Response from SQL batch operations.
|
|
92
|
-
*/
|
|
93
|
-
interface BatchResponse {
|
|
94
|
-
results: ExecuteResponse[];
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* A versioned SQL migration owned by an application or SDK subsystem.
|
|
98
|
-
*/
|
|
99
|
-
interface SqlMigration {
|
|
100
|
-
/**
|
|
101
|
-
* Stable migration id within the namespace, e.g. "001_initial".
|
|
102
|
-
*/
|
|
103
|
-
id: string;
|
|
104
|
-
/**
|
|
105
|
-
* SQL statements to apply when this migration has not been recorded.
|
|
106
|
-
* Statements should be idempotent where SQLite supports it.
|
|
107
|
-
*/
|
|
108
|
-
sql: Array<string | SqlStatement>;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Options for applying SQL migrations.
|
|
112
|
-
*/
|
|
113
|
-
interface SqlMigrationApplyOptions {
|
|
114
|
-
/**
|
|
115
|
-
* Namespace for this migration set, usually an app id or SDK subsystem.
|
|
116
|
-
*/
|
|
117
|
-
namespace: string;
|
|
118
|
-
/**
|
|
119
|
-
* Ordered migration list.
|
|
120
|
-
*/
|
|
121
|
-
migrations: SqlMigration[];
|
|
122
|
-
/**
|
|
123
|
-
* Custom abort signal for migration operations.
|
|
124
|
-
*/
|
|
125
|
-
signal?: AbortSignal;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Result from applying SQL migrations.
|
|
129
|
-
*/
|
|
130
|
-
interface SqlMigrationApplyResponse {
|
|
131
|
-
database: string;
|
|
132
|
-
namespace: string;
|
|
133
|
-
status: "already_current" | "applied";
|
|
134
|
-
applied: string[];
|
|
135
|
-
skipped: string[];
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* SQL service action types.
|
|
139
|
-
*
|
|
140
|
-
* URNs derive from the canonical capability registry in `@tinycloud/bootstrap`
|
|
141
|
-
* (TC-112 single source of truth, vendored from tinycloud-node). `insert`,
|
|
142
|
-
* `update`, and `delete` were dropped — zero client refs and never accepted
|
|
143
|
-
* node-side. `select` is a deprecated alias of `read`. `execute`/`export` are
|
|
144
|
-
* request-kind artifacts, not grantable capabilities: the node routes them by
|
|
145
|
-
* request-body kind, so they are absent from the registry but kept here as the
|
|
146
|
-
* invocation ability the client sends today (wire alignment tracked in TC-114).
|
|
147
|
-
*/
|
|
148
|
-
declare const SQLAction: {
|
|
149
|
-
readonly READ: "tinycloud.sql/read";
|
|
150
|
-
readonly WRITE: "tinycloud.sql/write";
|
|
151
|
-
readonly SCHEMA: "tinycloud.sql/schema";
|
|
152
|
-
readonly ADMIN: "tinycloud.sql/admin";
|
|
153
|
-
readonly SELECT: "tinycloud.sql/select";
|
|
154
|
-
readonly EXECUTE: "tinycloud.sql/execute";
|
|
155
|
-
readonly EXPORT: "tinycloud.sql/export";
|
|
156
|
-
readonly ALL: "tinycloud.sql/*";
|
|
157
|
-
};
|
|
158
|
-
type SQLActionType = (typeof SQLAction)[keyof typeof SQLAction];
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* ISQLService - Interface for SQL service.
|
|
162
|
-
*
|
|
163
|
-
* Platform-agnostic interface for SQL database operations.
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Migration helper bound to a specific database.
|
|
168
|
-
*/
|
|
169
|
-
interface ISQLMigrations {
|
|
170
|
-
/**
|
|
171
|
-
* Apply ordered, app-owned migrations and record completed ids.
|
|
172
|
-
*/
|
|
173
|
-
apply(options: SqlMigrationApplyOptions): Promise<Result<SqlMigrationApplyResponse>>;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Database handle interface for operations on a specific named database.
|
|
177
|
-
*/
|
|
178
|
-
interface IDatabaseHandle {
|
|
179
|
-
/** The database name */
|
|
180
|
-
readonly name: string;
|
|
181
|
-
/** Versioned schema migration helper. */
|
|
182
|
-
readonly migrations: ISQLMigrations;
|
|
183
|
-
/**
|
|
184
|
-
* Execute a SQL query and return rows.
|
|
185
|
-
*/
|
|
186
|
-
query<T = Record<string, unknown>>(sql: string, params?: SqlValue[], options?: QueryOptions): Promise<Result<QueryResponse<T>>>;
|
|
187
|
-
/**
|
|
188
|
-
* Execute a SQL statement and return change count.
|
|
189
|
-
*/
|
|
190
|
-
execute(sql: string, params?: SqlValue[], options?: ExecuteOptions): Promise<Result<ExecuteResponse>>;
|
|
191
|
-
/**
|
|
192
|
-
* Execute multiple statements in a transaction.
|
|
193
|
-
*/
|
|
194
|
-
batch(statements: SqlStatement[], options?: BatchOptions): Promise<Result<BatchResponse>>;
|
|
195
|
-
/**
|
|
196
|
-
* Execute a named prepared statement from delegation caveats.
|
|
197
|
-
*/
|
|
198
|
-
executeStatement(name: string, params?: SqlValue[], options?: QueryOptions): Promise<Result<QueryResponse | ExecuteResponse>>;
|
|
199
|
-
/**
|
|
200
|
-
* Export the raw SQLite database file.
|
|
201
|
-
*/
|
|
202
|
-
export(options?: QueryOptions): Promise<Result<Blob>>;
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* SQL service interface.
|
|
206
|
-
*
|
|
207
|
-
* Provides SQL database operations with:
|
|
208
|
-
* - Result type pattern (no throwing)
|
|
209
|
-
* - Named database handles
|
|
210
|
-
* - Configurable timeouts
|
|
211
|
-
* - Abort signal support
|
|
212
|
-
*/
|
|
213
|
-
interface ISQLService extends IService {
|
|
214
|
-
/**
|
|
215
|
-
* Get a handle to a named database.
|
|
216
|
-
* @param name - Database name (defaults to "default")
|
|
217
|
-
*/
|
|
218
|
-
db(name?: string): IDatabaseHandle;
|
|
219
|
-
/**
|
|
220
|
-
* Shortcut: query the default database.
|
|
221
|
-
*/
|
|
222
|
-
query<T = Record<string, unknown>>(sql: string, params?: SqlValue[], options?: QueryOptions): Promise<Result<QueryResponse<T>>>;
|
|
223
|
-
/**
|
|
224
|
-
* Shortcut: execute on the default database.
|
|
225
|
-
*/
|
|
226
|
-
execute(sql: string, params?: SqlValue[], options?: ExecuteOptions): Promise<Result<ExecuteResponse>>;
|
|
227
|
-
/**
|
|
228
|
-
* Shortcut: batch on the default database.
|
|
229
|
-
*/
|
|
230
|
-
batch(statements: SqlStatement[], options?: BatchOptions): Promise<Result<BatchResponse>>;
|
|
231
|
-
/**
|
|
232
|
-
* Service configuration.
|
|
233
|
-
*/
|
|
234
|
-
readonly config: SQLServiceConfig;
|
|
235
|
-
}
|
|
1
|
+
import { B as BaseService } from '../BaseService-Ma2MwJAd.js';
|
|
2
|
+
import { f as Result } from '../types-CSd0RYir.js';
|
|
3
|
+
import { d as ISQLService, g as SQLServiceConfig, I as IDatabaseHandle, l as SqlValue, Q as QueryOptions, e as QueryResponse, E as ExecuteOptions, b as ExecuteResponse, k as SqlStatement, B as BatchOptions, a as BatchResponse, i as SqlMigrationApplyOptions, j as SqlMigrationApplyResponse, c as ISQLMigrations } from '../ISQLService-Aly1CBsW.js';
|
|
4
|
+
export { S as SQLAction, f as SQLActionType, h as SqlMigration } from '../ISQLService-Aly1CBsW.js';
|
|
236
5
|
|
|
237
6
|
/**
|
|
238
7
|
* SQLService - SQL database service implementation.
|
|
@@ -279,6 +48,7 @@ declare class SQLService extends BaseService implements ISQLService {
|
|
|
279
48
|
private actionsForSqlBatch;
|
|
280
49
|
private dedupeActions;
|
|
281
50
|
private invokeSQLAny;
|
|
51
|
+
private redactFailure;
|
|
282
52
|
private handleErrorResponse;
|
|
283
53
|
private mapHttpStatusToErrorCode;
|
|
284
54
|
}
|
|
@@ -308,4 +78,4 @@ declare class SQLMigrations implements ISQLMigrations {
|
|
|
308
78
|
apply(options: SqlMigrationApplyOptions): Promise<Result<SqlMigrationApplyResponse>>;
|
|
309
79
|
}
|
|
310
80
|
|
|
311
|
-
export {
|
|
81
|
+
export { BatchOptions, BatchResponse, DatabaseHandle, ExecuteOptions, ExecuteResponse, IDatabaseHandle, ISQLMigrations, ISQLService, QueryOptions, QueryResponse, SQLMigrations, SQLService, SQLServiceConfig, SqlMigrationApplyOptions, SqlMigrationApplyResponse, SqlStatement, SqlValue };
|
package/dist/sql/index.js
CHANGED
|
@@ -741,12 +741,13 @@ var SQLService = class extends BaseService {
|
|
|
741
741
|
request.signal
|
|
742
742
|
);
|
|
743
743
|
if (!response.ok) {
|
|
744
|
-
|
|
744
|
+
const failure = await this.handleErrorResponse(response, "query", dbName, [action]);
|
|
745
|
+
return this.redactFailure(failure, options?.redactErrors, response.status);
|
|
745
746
|
}
|
|
746
747
|
const data = await response.json();
|
|
747
748
|
return ok(data);
|
|
748
749
|
} catch (error) {
|
|
749
|
-
return err(wrapError("sql", error));
|
|
750
|
+
return this.redactFailure(err(wrapError("sql", error)), options?.redactErrors);
|
|
750
751
|
} finally {
|
|
751
752
|
request.dispose();
|
|
752
753
|
}
|
|
@@ -781,12 +782,13 @@ var SQLService = class extends BaseService {
|
|
|
781
782
|
request.signal
|
|
782
783
|
);
|
|
783
784
|
if (!response.ok) {
|
|
784
|
-
|
|
785
|
+
const failure = await this.handleErrorResponse(response, "execute", dbName, requestedActions);
|
|
786
|
+
return this.redactFailure(failure, options?.redactErrors, response.status);
|
|
785
787
|
}
|
|
786
788
|
const data = await response.json();
|
|
787
789
|
return ok(data);
|
|
788
790
|
} catch (error) {
|
|
789
|
-
return err(wrapError("sql", error));
|
|
791
|
+
return this.redactFailure(err(wrapError("sql", error)), options?.redactErrors);
|
|
790
792
|
} finally {
|
|
791
793
|
request.dispose();
|
|
792
794
|
}
|
|
@@ -807,12 +809,13 @@ var SQLService = class extends BaseService {
|
|
|
807
809
|
request.signal
|
|
808
810
|
);
|
|
809
811
|
if (!response.ok) {
|
|
810
|
-
|
|
812
|
+
const failure = await this.handleErrorResponse(response, "batch", dbName, requestedActions);
|
|
813
|
+
return this.redactFailure(failure, options?.redactErrors, response.status);
|
|
811
814
|
}
|
|
812
815
|
const data = await response.json();
|
|
813
816
|
return ok(data);
|
|
814
817
|
} catch (error) {
|
|
815
|
-
return err(wrapError("sql", error));
|
|
818
|
+
return this.redactFailure(err(wrapError("sql", error)), options?.redactErrors);
|
|
816
819
|
} finally {
|
|
817
820
|
request.dispose();
|
|
818
821
|
}
|
|
@@ -1008,6 +1011,18 @@ var SQLService = class extends BaseService {
|
|
|
1008
1011
|
}))
|
|
1009
1012
|
);
|
|
1010
1013
|
}
|
|
1014
|
+
redactFailure(result, redactErrors, status) {
|
|
1015
|
+
if (!redactErrors || result.ok) return result;
|
|
1016
|
+
const candidate = result.error.code;
|
|
1017
|
+
const code = typeof candidate === "string" && Object.prototype.hasOwnProperty.call(ErrorCodes, candidate) ? candidate : ErrorCodes.SQL_ERROR;
|
|
1018
|
+
const safeStatus = typeof status === "number" && Number.isInteger(status) && status >= 400 && status <= 599 ? status : void 0;
|
|
1019
|
+
return err(serviceError(
|
|
1020
|
+
code,
|
|
1021
|
+
"SQL operation failed",
|
|
1022
|
+
"sql",
|
|
1023
|
+
safeStatus === void 0 ? void 0 : { meta: { status: safeStatus } }
|
|
1024
|
+
));
|
|
1025
|
+
}
|
|
1011
1026
|
async handleErrorResponse(response, operation, dbName, requestedActions) {
|
|
1012
1027
|
const errorText = await response.text();
|
|
1013
1028
|
const meta = responseErrorMeta(response.status, response.statusText, errorText);
|