@saasqlite/client 0.0.1

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.
@@ -0,0 +1,251 @@
1
+ import { Socket } from "node:net";
2
+
3
+ //#region src/errors.d.ts
4
+ type SaaSQLiteErrorPayload = {
5
+ code: string;
6
+ message: string;
7
+ details?: unknown;
8
+ queryId?: string;
9
+ sqliteCode?: string;
10
+ };
11
+ declare class SaaSQLiteError extends Error {
12
+ code: string;
13
+ details?: unknown;
14
+ queryId?: string;
15
+ sqliteCode?: string;
16
+ cause?: unknown;
17
+ constructor(code: string, message: string, options?: {
18
+ details?: unknown;
19
+ queryId?: string;
20
+ sqliteCode?: string;
21
+ cause?: unknown;
22
+ });
23
+ toJSON(): SaaSQLiteErrorPayload;
24
+ }
25
+ //#endregion
26
+ //#region src/transport.d.ts
27
+ type QueryResult = {
28
+ resultType: "select";
29
+ columns: string[];
30
+ rows: Row[];
31
+ } | {
32
+ resultType: "run";
33
+ rowsAffected: number;
34
+ lastInsertRowid: number;
35
+ };
36
+ interface Transport {
37
+ query(sql: string, params: unknown[]): Promise<QueryResult>;
38
+ batch(statements: BatchStatement[]): Promise<BatchResult[]>;
39
+ close(): Promise<void>;
40
+ }
41
+ type HttpTransportOptions = {
42
+ url: string;
43
+ token: string;
44
+ timeoutMs?: number;
45
+ };
46
+ declare class HttpTransport implements Transport {
47
+ private readonly baseUrl;
48
+ private readonly token;
49
+ private readonly timeoutMs;
50
+ private closed;
51
+ constructor(opts: HttpTransportOptions);
52
+ private request;
53
+ query(sql: string, params: unknown[]): Promise<QueryResult>;
54
+ batch(statements: BatchStatement[]): Promise<BatchResult[]>;
55
+ close(): Promise<void>;
56
+ }
57
+ //#endregion
58
+ //#region src/statement.d.ts
59
+ type Row = Record<string, unknown>;
60
+ type Params = unknown[] | Record<string, unknown>;
61
+ type RunResult = {
62
+ changes: number;
63
+ lastInsertRowid: number | bigint | null;
64
+ };
65
+ type BatchStatement = {
66
+ sql: string;
67
+ params?: unknown[];
68
+ };
69
+ type BatchResult = {
70
+ type: string;
71
+ result: unknown;
72
+ } | {
73
+ code: string;
74
+ message: string;
75
+ };
76
+ declare class Statement {
77
+ readonly sql: string;
78
+ private readonly transport;
79
+ private readonly timeoutMs;
80
+ readonly source: string;
81
+ readonly reader: boolean;
82
+ readonly readonly: boolean;
83
+ private _busy;
84
+ private _changes;
85
+ private _pluck;
86
+ private _raw;
87
+ private _expand;
88
+ private _boundParams;
89
+ constructor(sql: string, transport: Transport, timeoutMs: number);
90
+ get busy(): boolean;
91
+ get changes(): number;
92
+ pluck(enable?: boolean): this;
93
+ raw(enable?: boolean): this;
94
+ expand(enable?: boolean): this;
95
+ private get rowMode();
96
+ bind(...params: unknown[]): this;
97
+ columns(): Array<{
98
+ name: string;
99
+ column: string | null;
100
+ table: string | null;
101
+ database: string | null;
102
+ type: string | null;
103
+ }>;
104
+ get<T = Row>(...params: unknown[]): Promise<T | undefined>;
105
+ all<T = Row>(...params: unknown[]): Promise<T[]>;
106
+ run(...params: unknown[]): Promise<RunResult>;
107
+ iterate(...params: unknown[]): AsyncIterator<Row>;
108
+ private resolveParams;
109
+ private executeRequest;
110
+ }
111
+ //#endregion
112
+ //#region src/transaction.d.ts
113
+ declare class Transaction {
114
+ private readonly db;
115
+ constructor(db: SaaSQLite);
116
+ prepare(sql: string): Statement;
117
+ exec(sql: string): Promise<this>;
118
+ run(sql: string, ...params: unknown[]): Promise<any>;
119
+ get<T = Record<string, unknown>>(sql: string, ...params: unknown[]): Promise<T | undefined>;
120
+ all<T = Record<string, unknown>>(sql: string, ...params: unknown[]): Promise<T[]>;
121
+ }
122
+ //#endregion
123
+ //#region src/socket-transport.d.ts
124
+ type SocketTransportOptions = {
125
+ sock: string;
126
+ password: string;
127
+ timeoutMs?: number;
128
+ };
129
+ declare class SocketTransport implements Transport {
130
+ private readonly sockPath;
131
+ private readonly password;
132
+ private readonly timeoutMs;
133
+ private closed;
134
+ constructor(opts: SocketTransportOptions);
135
+ private withSocket;
136
+ query(sql: string, params: unknown[]): Promise<QueryResult>;
137
+ batch(statements: BatchStatement[]): Promise<BatchResult[]>;
138
+ close(): Promise<void>;
139
+ }
140
+ //#endregion
141
+ //#region src/client.d.ts
142
+ /**
143
+ * Default SaaSQLite gateway (remote cloud endpoint).
144
+ */
145
+ declare const DEFAULT_GATEWAY_URL = "https://api.saasqlite.com";
146
+ /**
147
+ * Public constructor options.
148
+ */
149
+ type SaaSQLiteOptions = {
150
+ timeoutMs?: number;
151
+ /**
152
+ * Gateway base URL (e.g. `https://api.saasqlite.com` or a self-hosted
153
+ * gateway). Defaults to `$SAASQLITE_GATEWAY_URL` if set, otherwise
154
+ * `https://api.saasqlite.com`. Ignored when the first constructor
155
+ * argument is already a full http(s) URL.
156
+ */
157
+ gatewayUrl?: string;
158
+ };
159
+ /**
160
+ * Resolve the gateway base URL for a public-API constructor call.
161
+ * Precedence: full http(s) URL passed as databaseId > options.gatewayUrl
162
+ * > $SAASQLITE_GATEWAY_URL > DEFAULT_GATEWAY_URL.
163
+ */
164
+ declare function resolveGatewayUrl(databaseId: string, opts?: SaaSQLiteOptions): string;
165
+ /**
166
+ * Internal transport options (not part of public API docs).
167
+ */
168
+ type SaaSQLiteInternalOptions = HttpTransportOptions | SocketTransportOptions;
169
+ type PragmaOptions = {
170
+ simple?: boolean;
171
+ };
172
+ declare class SaaSQLite {
173
+ private readonly _transport;
174
+ private readonly _timeoutMs;
175
+ private _closed;
176
+ private _txDepth;
177
+ get open(): boolean;
178
+ readonly name: string;
179
+ constructor(databaseId: string, apiKey: string, options?: SaaSQLiteOptions);
180
+ constructor(options: SaaSQLiteInternalOptions);
181
+ exec(sql: string): Promise<this>;
182
+ prepare(sql: string): Statement;
183
+ pragma(sql: string): Promise<Row[]>;
184
+ pragma(sql: string, options: PragmaOptions): Promise<unknown>;
185
+ transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>;
186
+ query<T = Row>(sql: string, params?: Params): Promise<T[]>;
187
+ get<T = Row>(sql: string, params?: Params): Promise<T | undefined>;
188
+ all<T = Row>(sql: string, params?: Params): Promise<T[]>;
189
+ run(sql: string, params?: Params): Promise<RunResult>;
190
+ batch(statements: BatchStatement[]): Promise<BatchResult[]>;
191
+ close(): Promise<void>;
192
+ function(_name: string, ..._args: unknown[]): this;
193
+ aggregate(_name: string, ..._args: unknown[]): this;
194
+ table(_name: string, ..._args: unknown[]): this;
195
+ loadExtension(_path: string): this;
196
+ backup(_destination: string): Promise<unknown>;
197
+ serialize(): Buffer;
198
+ checkpoint(): this;
199
+ defaultSafeIntegers(_enabled?: boolean): this;
200
+ unsafeMode(_enabled?: boolean): this;
201
+ verbose(_fn?: (...args: unknown[]) => void): this;
202
+ private assertOpen;
203
+ }
204
+ //#endregion
205
+ //#region src/params.d.ts
206
+ type ParamObject = Record<string, unknown>;
207
+ declare function resolveParams(sql: string, params: unknown[] | ParamObject | undefined): {
208
+ sql: string;
209
+ positionalParams: unknown[];
210
+ };
211
+ declare function countParameters(sql: string): number;
212
+ //#endregion
213
+ //#region src/protocol.d.ts
214
+ declare const CMD_QUERY = 0,
215
+ CMD_BATCH = 1,
216
+ CMD_HEALTH = 2;
217
+ declare const STATUS_OK = 0,
218
+ STATUS_ERR = 1;
219
+ declare const RESULT_SELECT = 0,
220
+ RESULT_RUN = 1;
221
+ declare const VAL_NULL = 0,
222
+ VAL_INT64 = 1,
223
+ VAL_FLOAT64 = 2,
224
+ VAL_TEXT = 3,
225
+ VAL_BLOB = 4;
226
+ declare class Reader {
227
+ private buf;
228
+ read(s: Socket, n: number): Promise<Buffer>;
229
+ }
230
+ declare function w32(b: Buffer, o: number, v: number): void;
231
+ declare function r32(b: Buffer, o: number): number;
232
+ declare function w64(b: Buffer, o: number, v: number): void;
233
+ declare function r64(b: Buffer, o: number): number;
234
+ declare function wF64(b: Buffer, o: number, v: number): void;
235
+ declare function rF64(b: Buffer, o: number): number;
236
+ declare function encParam(p: unknown): Buffer;
237
+ declare function encQuery(sql: string, params: unknown[]): Buffer;
238
+ declare function encBatch(stmts: BatchStatement[]): Buffer;
239
+ declare function encHealth(): Buffer;
240
+ declare function readVal(r: Reader, s: Socket): Promise<unknown>;
241
+ declare function readSelect(r: Reader, s: Socket): Promise<{
242
+ columns: string[];
243
+ rows: Row[];
244
+ }>;
245
+ declare function readRun(r: Reader, s: Socket): Promise<{
246
+ rowsAffected: number;
247
+ lastInsertRowid: number;
248
+ }>;
249
+ declare function checkStatus(r: Reader, s: Socket): Promise<void>;
250
+ //#endregion
251
+ export { type BatchResult, type BatchStatement, CMD_BATCH, CMD_HEALTH, CMD_QUERY, DEFAULT_GATEWAY_URL, HttpTransport, type HttpTransportOptions, type Params, type PragmaOptions, type QueryResult, RESULT_RUN, RESULT_SELECT, Reader, type Row, type RunResult, STATUS_ERR, STATUS_OK, SaaSQLite, SaaSQLiteError, type SaaSQLiteErrorPayload, type SaaSQLiteOptions, SocketTransport, type SocketTransportOptions, Statement, Transaction, type Transport, VAL_BLOB, VAL_FLOAT64, VAL_INT64, VAL_NULL, VAL_TEXT, checkStatus, countParameters, encBatch, encHealth, encParam, encQuery, r32, r64, rF64, readRun, readSelect, readVal, resolveGatewayUrl, resolveParams, w32, w64, wF64 };
@@ -0,0 +1,251 @@
1
+ import { Socket } from "node:net";
2
+
3
+ //#region src/errors.d.ts
4
+ type SaaSQLiteErrorPayload = {
5
+ code: string;
6
+ message: string;
7
+ details?: unknown;
8
+ queryId?: string;
9
+ sqliteCode?: string;
10
+ };
11
+ declare class SaaSQLiteError extends Error {
12
+ code: string;
13
+ details?: unknown;
14
+ queryId?: string;
15
+ sqliteCode?: string;
16
+ cause?: unknown;
17
+ constructor(code: string, message: string, options?: {
18
+ details?: unknown;
19
+ queryId?: string;
20
+ sqliteCode?: string;
21
+ cause?: unknown;
22
+ });
23
+ toJSON(): SaaSQLiteErrorPayload;
24
+ }
25
+ //#endregion
26
+ //#region src/transport.d.ts
27
+ type QueryResult = {
28
+ resultType: "select";
29
+ columns: string[];
30
+ rows: Row[];
31
+ } | {
32
+ resultType: "run";
33
+ rowsAffected: number;
34
+ lastInsertRowid: number;
35
+ };
36
+ interface Transport {
37
+ query(sql: string, params: unknown[]): Promise<QueryResult>;
38
+ batch(statements: BatchStatement[]): Promise<BatchResult[]>;
39
+ close(): Promise<void>;
40
+ }
41
+ type HttpTransportOptions = {
42
+ url: string;
43
+ token: string;
44
+ timeoutMs?: number;
45
+ };
46
+ declare class HttpTransport implements Transport {
47
+ private readonly baseUrl;
48
+ private readonly token;
49
+ private readonly timeoutMs;
50
+ private closed;
51
+ constructor(opts: HttpTransportOptions);
52
+ private request;
53
+ query(sql: string, params: unknown[]): Promise<QueryResult>;
54
+ batch(statements: BatchStatement[]): Promise<BatchResult[]>;
55
+ close(): Promise<void>;
56
+ }
57
+ //#endregion
58
+ //#region src/statement.d.ts
59
+ type Row = Record<string, unknown>;
60
+ type Params = unknown[] | Record<string, unknown>;
61
+ type RunResult = {
62
+ changes: number;
63
+ lastInsertRowid: number | bigint | null;
64
+ };
65
+ type BatchStatement = {
66
+ sql: string;
67
+ params?: unknown[];
68
+ };
69
+ type BatchResult = {
70
+ type: string;
71
+ result: unknown;
72
+ } | {
73
+ code: string;
74
+ message: string;
75
+ };
76
+ declare class Statement {
77
+ readonly sql: string;
78
+ private readonly transport;
79
+ private readonly timeoutMs;
80
+ readonly source: string;
81
+ readonly reader: boolean;
82
+ readonly readonly: boolean;
83
+ private _busy;
84
+ private _changes;
85
+ private _pluck;
86
+ private _raw;
87
+ private _expand;
88
+ private _boundParams;
89
+ constructor(sql: string, transport: Transport, timeoutMs: number);
90
+ get busy(): boolean;
91
+ get changes(): number;
92
+ pluck(enable?: boolean): this;
93
+ raw(enable?: boolean): this;
94
+ expand(enable?: boolean): this;
95
+ private get rowMode();
96
+ bind(...params: unknown[]): this;
97
+ columns(): Array<{
98
+ name: string;
99
+ column: string | null;
100
+ table: string | null;
101
+ database: string | null;
102
+ type: string | null;
103
+ }>;
104
+ get<T = Row>(...params: unknown[]): Promise<T | undefined>;
105
+ all<T = Row>(...params: unknown[]): Promise<T[]>;
106
+ run(...params: unknown[]): Promise<RunResult>;
107
+ iterate(...params: unknown[]): AsyncIterator<Row>;
108
+ private resolveParams;
109
+ private executeRequest;
110
+ }
111
+ //#endregion
112
+ //#region src/transaction.d.ts
113
+ declare class Transaction {
114
+ private readonly db;
115
+ constructor(db: SaaSQLite);
116
+ prepare(sql: string): Statement;
117
+ exec(sql: string): Promise<this>;
118
+ run(sql: string, ...params: unknown[]): Promise<any>;
119
+ get<T = Record<string, unknown>>(sql: string, ...params: unknown[]): Promise<T | undefined>;
120
+ all<T = Record<string, unknown>>(sql: string, ...params: unknown[]): Promise<T[]>;
121
+ }
122
+ //#endregion
123
+ //#region src/socket-transport.d.ts
124
+ type SocketTransportOptions = {
125
+ sock: string;
126
+ password: string;
127
+ timeoutMs?: number;
128
+ };
129
+ declare class SocketTransport implements Transport {
130
+ private readonly sockPath;
131
+ private readonly password;
132
+ private readonly timeoutMs;
133
+ private closed;
134
+ constructor(opts: SocketTransportOptions);
135
+ private withSocket;
136
+ query(sql: string, params: unknown[]): Promise<QueryResult>;
137
+ batch(statements: BatchStatement[]): Promise<BatchResult[]>;
138
+ close(): Promise<void>;
139
+ }
140
+ //#endregion
141
+ //#region src/client.d.ts
142
+ /**
143
+ * Default SaaSQLite gateway (remote cloud endpoint).
144
+ */
145
+ declare const DEFAULT_GATEWAY_URL = "https://api.saasqlite.com";
146
+ /**
147
+ * Public constructor options.
148
+ */
149
+ type SaaSQLiteOptions = {
150
+ timeoutMs?: number;
151
+ /**
152
+ * Gateway base URL (e.g. `https://api.saasqlite.com` or a self-hosted
153
+ * gateway). Defaults to `$SAASQLITE_GATEWAY_URL` if set, otherwise
154
+ * `https://api.saasqlite.com`. Ignored when the first constructor
155
+ * argument is already a full http(s) URL.
156
+ */
157
+ gatewayUrl?: string;
158
+ };
159
+ /**
160
+ * Resolve the gateway base URL for a public-API constructor call.
161
+ * Precedence: full http(s) URL passed as databaseId > options.gatewayUrl
162
+ * > $SAASQLITE_GATEWAY_URL > DEFAULT_GATEWAY_URL.
163
+ */
164
+ declare function resolveGatewayUrl(databaseId: string, opts?: SaaSQLiteOptions): string;
165
+ /**
166
+ * Internal transport options (not part of public API docs).
167
+ */
168
+ type SaaSQLiteInternalOptions = HttpTransportOptions | SocketTransportOptions;
169
+ type PragmaOptions = {
170
+ simple?: boolean;
171
+ };
172
+ declare class SaaSQLite {
173
+ private readonly _transport;
174
+ private readonly _timeoutMs;
175
+ private _closed;
176
+ private _txDepth;
177
+ get open(): boolean;
178
+ readonly name: string;
179
+ constructor(databaseId: string, apiKey: string, options?: SaaSQLiteOptions);
180
+ constructor(options: SaaSQLiteInternalOptions);
181
+ exec(sql: string): Promise<this>;
182
+ prepare(sql: string): Statement;
183
+ pragma(sql: string): Promise<Row[]>;
184
+ pragma(sql: string, options: PragmaOptions): Promise<unknown>;
185
+ transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>;
186
+ query<T = Row>(sql: string, params?: Params): Promise<T[]>;
187
+ get<T = Row>(sql: string, params?: Params): Promise<T | undefined>;
188
+ all<T = Row>(sql: string, params?: Params): Promise<T[]>;
189
+ run(sql: string, params?: Params): Promise<RunResult>;
190
+ batch(statements: BatchStatement[]): Promise<BatchResult[]>;
191
+ close(): Promise<void>;
192
+ function(_name: string, ..._args: unknown[]): this;
193
+ aggregate(_name: string, ..._args: unknown[]): this;
194
+ table(_name: string, ..._args: unknown[]): this;
195
+ loadExtension(_path: string): this;
196
+ backup(_destination: string): Promise<unknown>;
197
+ serialize(): Buffer;
198
+ checkpoint(): this;
199
+ defaultSafeIntegers(_enabled?: boolean): this;
200
+ unsafeMode(_enabled?: boolean): this;
201
+ verbose(_fn?: (...args: unknown[]) => void): this;
202
+ private assertOpen;
203
+ }
204
+ //#endregion
205
+ //#region src/params.d.ts
206
+ type ParamObject = Record<string, unknown>;
207
+ declare function resolveParams(sql: string, params: unknown[] | ParamObject | undefined): {
208
+ sql: string;
209
+ positionalParams: unknown[];
210
+ };
211
+ declare function countParameters(sql: string): number;
212
+ //#endregion
213
+ //#region src/protocol.d.ts
214
+ declare const CMD_QUERY = 0,
215
+ CMD_BATCH = 1,
216
+ CMD_HEALTH = 2;
217
+ declare const STATUS_OK = 0,
218
+ STATUS_ERR = 1;
219
+ declare const RESULT_SELECT = 0,
220
+ RESULT_RUN = 1;
221
+ declare const VAL_NULL = 0,
222
+ VAL_INT64 = 1,
223
+ VAL_FLOAT64 = 2,
224
+ VAL_TEXT = 3,
225
+ VAL_BLOB = 4;
226
+ declare class Reader {
227
+ private buf;
228
+ read(s: Socket, n: number): Promise<Buffer>;
229
+ }
230
+ declare function w32(b: Buffer, o: number, v: number): void;
231
+ declare function r32(b: Buffer, o: number): number;
232
+ declare function w64(b: Buffer, o: number, v: number): void;
233
+ declare function r64(b: Buffer, o: number): number;
234
+ declare function wF64(b: Buffer, o: number, v: number): void;
235
+ declare function rF64(b: Buffer, o: number): number;
236
+ declare function encParam(p: unknown): Buffer;
237
+ declare function encQuery(sql: string, params: unknown[]): Buffer;
238
+ declare function encBatch(stmts: BatchStatement[]): Buffer;
239
+ declare function encHealth(): Buffer;
240
+ declare function readVal(r: Reader, s: Socket): Promise<unknown>;
241
+ declare function readSelect(r: Reader, s: Socket): Promise<{
242
+ columns: string[];
243
+ rows: Row[];
244
+ }>;
245
+ declare function readRun(r: Reader, s: Socket): Promise<{
246
+ rowsAffected: number;
247
+ lastInsertRowid: number;
248
+ }>;
249
+ declare function checkStatus(r: Reader, s: Socket): Promise<void>;
250
+ //#endregion
251
+ export { type BatchResult, type BatchStatement, CMD_BATCH, CMD_HEALTH, CMD_QUERY, DEFAULT_GATEWAY_URL, HttpTransport, type HttpTransportOptions, type Params, type PragmaOptions, type QueryResult, RESULT_RUN, RESULT_SELECT, Reader, type Row, type RunResult, STATUS_ERR, STATUS_OK, SaaSQLite, SaaSQLiteError, type SaaSQLiteErrorPayload, type SaaSQLiteOptions, SocketTransport, type SocketTransportOptions, Statement, Transaction, type Transport, VAL_BLOB, VAL_FLOAT64, VAL_INT64, VAL_NULL, VAL_TEXT, checkStatus, countParameters, encBatch, encHealth, encParam, encQuery, r32, r64, rF64, readRun, readSelect, readVal, resolveGatewayUrl, resolveParams, w32, w64, wF64 };