rqlite-js 2.6.0 → 3.0.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.
Files changed (98) hide show
  1. package/README.md +207 -29
  2. package/dist/index.cjs +904 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +329 -0
  5. package/dist/index.d.ts +329 -0
  6. package/dist/index.js +865 -0
  7. package/dist/index.js.map +1 -0
  8. package/docs/MIGRATION-v2-to-v3.md +71 -0
  9. package/package.json +56 -35
  10. package/src/api/backup/index.ts +69 -0
  11. package/src/api/backup-formats.ts +8 -0
  12. package/src/api/client/index.ts +97 -0
  13. package/src/api/consistency-levels.ts +10 -0
  14. package/src/api/data/index.ts +87 -0
  15. package/src/api/paths.ts +13 -0
  16. package/src/api/query-params.ts +15 -0
  17. package/src/api/results/data-result-error.ts +41 -0
  18. package/src/api/results/data-result.ts +91 -0
  19. package/src/api/results/data-results.ts +91 -0
  20. package/src/api/results/index.ts +7 -0
  21. package/src/api/results/result-fields.ts +14 -0
  22. package/src/api/status/index.ts +53 -0
  23. package/src/http-request/auth-keys.ts +14 -0
  24. package/src/http-request/content-types.ts +4 -0
  25. package/src/http-request/errors.ts +17 -0
  26. package/src/http-request/http-headers.ts +19 -0
  27. package/src/http-request/http-methods.ts +12 -0
  28. package/src/http-request/index.ts +676 -0
  29. package/src/http-request/retryable.ts +41 -0
  30. package/src/index.ts +38 -0
  31. package/lib/api/backup/index.js +0 -72
  32. package/lib/api/backup/index.js.map +0 -1
  33. package/lib/api/backup/test.unit.js +0 -45
  34. package/lib/api/backup/test.unit.js.map +0 -1
  35. package/lib/api/backup-formats.js +0 -16
  36. package/lib/api/backup-formats.js.map +0 -1
  37. package/lib/api/client/index.js +0 -105
  38. package/lib/api/client/index.js.map +0 -1
  39. package/lib/api/client/test.unit.js +0 -53
  40. package/lib/api/client/test.unit.js.map +0 -1
  41. package/lib/api/consistency-levels.js +0 -30
  42. package/lib/api/consistency-levels.js.map +0 -1
  43. package/lib/api/data/index.js +0 -108
  44. package/lib/api/data/index.js.map +0 -1
  45. package/lib/api/data/test.unit.js +0 -98
  46. package/lib/api/data/test.unit.js.map +0 -1
  47. package/lib/api/paths.js +0 -33
  48. package/lib/api/paths.js.map +0 -1
  49. package/lib/api/query-params.js +0 -43
  50. package/lib/api/query-params.js.map +0 -1
  51. package/lib/api/results/data-result-error.js +0 -62
  52. package/lib/api/results/data-result-error.js.map +0 -1
  53. package/lib/api/results/data-result.js +0 -141
  54. package/lib/api/results/data-result.js.map +0 -1
  55. package/lib/api/results/data-results.js +0 -142
  56. package/lib/api/results/data-results.js.map +0 -1
  57. package/lib/api/results/index.js +0 -8
  58. package/lib/api/results/index.js.map +0 -1
  59. package/lib/api/results/result-fields.js +0 -47
  60. package/lib/api/results/result-fields.js.map +0 -1
  61. package/lib/api/results/test.unit.js +0 -238
  62. package/lib/api/results/test.unit.js.map +0 -1
  63. package/lib/api/status/index.js +0 -67
  64. package/lib/api/status/index.js.map +0 -1
  65. package/lib/api/status/test.unit.js +0 -57
  66. package/lib/api/status/test.unit.js.map +0 -1
  67. package/lib/http-request/auth-keys.js +0 -15
  68. package/lib/http-request/auth-keys.js.map +0 -1
  69. package/lib/http-request/content-types.js +0 -5
  70. package/lib/http-request/content-types.js.map +0 -1
  71. package/lib/http-request/errors.js +0 -17
  72. package/lib/http-request/errors.js.map +0 -1
  73. package/lib/http-request/http-headers.js +0 -20
  74. package/lib/http-request/http-headers.js.map +0 -1
  75. package/lib/http-request/http-methods.js +0 -40
  76. package/lib/http-request/http-methods.js.map +0 -1
  77. package/lib/http-request/index.js +0 -764
  78. package/lib/http-request/index.js.map +0 -1
  79. package/lib/http-request/retryable.js +0 -42
  80. package/lib/http-request/retryable.js.map +0 -1
  81. package/lib/http-request/test.unit.js +0 -560
  82. package/lib/http-request/test.unit.js.map +0 -1
  83. package/lib/index.js +0 -39
  84. package/lib/index.js.map +0 -1
  85. package/lib/test/api-data-execute-nock.js +0 -142
  86. package/lib/test/api-data-execute-nock.js.map +0 -1
  87. package/lib/test/api-data-query-nock.js +0 -210
  88. package/lib/test/api-data-query-nock.js.map +0 -1
  89. package/lib/test/backups/backup-nock.js +0 -29
  90. package/lib/test/backups/backup-nock.js.map +0 -1
  91. package/lib/test/backups/restore-nock.js +0 -30
  92. package/lib/test/backups/restore-nock.js.map +0 -1
  93. package/lib/test/env.js +0 -15
  94. package/lib/test/env.js.map +0 -1
  95. package/lib/test/unit/index.unit.js +0 -27
  96. package/lib/test/unit/index.unit.js.map +0 -1
  97. package/lib/test.integration.js +0 -238
  98. package/lib/test.integration.js.map +0 -1
@@ -0,0 +1,329 @@
1
+ import { Readable } from "node:stream";
2
+ import { Agent } from "node:http";
3
+ import { Agent as Agent$1 } from "node:https";
4
+
5
+ //#region src/http-request/index.d.ts
6
+
7
+ type HttpAuthentication = {
8
+ username?: string;
9
+ password?: string;
10
+ };
11
+ type HttpRequestOptions = {
12
+ auth?: HttpAuthentication;
13
+ body?: unknown;
14
+ headers?: Record<string, string>;
15
+ httpMethod?: string;
16
+ query?: Record<string, unknown>;
17
+ stream?: boolean;
18
+ timeout?: number;
19
+ uri?: string;
20
+ useLeader?: boolean;
21
+ retries?: number;
22
+ maxRedirects?: number;
23
+ attempt?: number;
24
+ retryAttempt?: number;
25
+ redirectAttempt?: number;
26
+ attemptHostIndex?: number;
27
+ exponentailBackoffBase?: number;
28
+ exponentailBackoffExponent?: number;
29
+ json?: boolean;
30
+ httpAgent?: Agent | DispatcherLike;
31
+ httpsAgent?: Agent$1 | DispatcherLike;
32
+ };
33
+ /** Minimal undici/Node fetch dispatcher shape */
34
+ type DispatcherLike = {
35
+ dispatch?: (...args: unknown[]) => unknown;
36
+ close?: () => Promise<void>;
37
+ destroy?: () => Promise<void>;
38
+ };
39
+ type HttpResponse = {
40
+ status: number;
41
+ body: unknown;
42
+ };
43
+ type HttpRequestConstructorOptions = {
44
+ authentication?: HttpAuthentication;
45
+ activeHostRoundRobin?: boolean;
46
+ httpAgent?: Agent | DispatcherLike;
47
+ httpsAgent?: Agent$1 | DispatcherLike;
48
+ retryableErrorCodes?: Set<string> | string[];
49
+ retryableStatusCodes?: Set<number> | number[];
50
+ retryableHttpMethods?: Set<string> | string[];
51
+ exponentailBackoffBase?: number;
52
+ exponentailBackoffExponent?: number;
53
+ };
54
+ /**
55
+ * Generic HTTP Request class which all RQLiteJS clients should extend
56
+ */
57
+ declare class HttpRequest {
58
+ activeHostIndex: number;
59
+ activeHostRoundRobin: boolean;
60
+ absoluteUriPattern: RegExp;
61
+ hosts: string[];
62
+ httpAgent?: Agent | DispatcherLike;
63
+ httpsAgent?: Agent$1 | DispatcherLike;
64
+ leaderHostIndex: number;
65
+ retryableErrorCodes: Set<string>;
66
+ retryableStatusCodes: Set<number>;
67
+ retryableHttpMethods: Set<string>;
68
+ exponentailBackoffBase: number;
69
+ exponentailBackoffExponent: number;
70
+ authentication: Map<string, string>;
71
+ constructor(hosts: string[] | string, options?: HttpRequestConstructorOptions);
72
+ setAuthentication(authentication?: HttpAuthentication): void;
73
+ setExponentailBackoffBase(exponentailBackoffBase: number): void;
74
+ getExponentailBackoffBase(): number;
75
+ setExponentailBackoffExponent(exponentailBackoffExponent: number): void;
76
+ getExponentailBackoffExponent(): number;
77
+ setRetryableErrorCodes(retryableErrorCodes: Set<string>): void;
78
+ getRetryableErrorCodes(): Set<string>;
79
+ setRetryableStatusCodes(retryableStatusCodes: Set<number>): void;
80
+ getRetryableStatusCodes(): Set<number>;
81
+ setRetryableHttpMethods(retryableHttpMethods: Set<string>): void;
82
+ getRetryableHttpMethods(): Set<string>;
83
+ setHttpAgent(httpAgent: Agent | DispatcherLike): void;
84
+ getHttpAgent(): Agent | DispatcherLike | undefined;
85
+ setHttpsAgent(httpsAgent: Agent$1 | DispatcherLike): void;
86
+ getHttpsAgent(): Agent$1 | DispatcherLike | undefined;
87
+ setHosts(hosts: string[] | string): void;
88
+ getHosts(): string[];
89
+ findHostIndex(host: string): number;
90
+ getActiveHost(useLeader?: boolean): string;
91
+ setActiveHostIndex(activeHostIndex: number): number;
92
+ getLeaderHostIndex(): number;
93
+ setLeaderHostIndex(leaderHostIndex: number): number;
94
+ getActiveHostIndex(): number;
95
+ setActiveHostRoundRobin(activeHostRoundRobin: boolean): void;
96
+ getActiveHostRoundRobin(): boolean;
97
+ getNextActiveHostIndex(activeHostIndex?: number): number;
98
+ setNextActiveHostIndex(): void;
99
+ getTotalHosts(): number;
100
+ uriIsAbsolute(uri: string): boolean;
101
+ requestIsRetryable(options?: {
102
+ statusCode?: number;
103
+ errorCode?: string;
104
+ httpMethod?: string;
105
+ }): boolean;
106
+ /**
107
+ * Perform an HTTP request using the provided options
108
+ */
109
+ fetch(options?: HttpRequestOptions): Promise<HttpResponse | Readable>;
110
+ get(...args: any[]): Promise<HttpResponse | Readable>;
111
+ post(...args: any[]): Promise<HttpResponse | Readable>;
112
+ }
113
+ //#endregion
114
+ //#region src/api/client/index.d.ts
115
+ type ApiClientRequestOptions = {
116
+ useLeader?: boolean;
117
+ level?: string;
118
+ pretty?: boolean;
119
+ timings?: boolean;
120
+ atomic?: boolean;
121
+ transaction?: boolean;
122
+ raw?: boolean;
123
+ };
124
+ /**
125
+ * Base API client for RQLite which abstracts the HTTP calls from the user
126
+ */
127
+ declare class ApiClient extends HttpRequest {
128
+ /**
129
+ * Perform a RQLite data API get request
130
+ * @see https://rqlite.io/docs/api/api/
131
+ */
132
+ get(...args: any[]): Promise<HttpResponse>;
133
+ /**
134
+ * Perform a RQLite data API post request
135
+ * @see https://rqlite.io/docs/api/api/
136
+ */
137
+ post(...args: any[]): Promise<HttpResponse>;
138
+ }
139
+ //#endregion
140
+ //#region src/api/results/result-fields.d.ts
141
+ /**
142
+ * RQLite JSON response field name constants
143
+ * @module api/results/result-fields
144
+ * @see https://rqlite.io/docs/api/api/
145
+ */
146
+ declare const RESULT_FIELD_TIME = "time";
147
+ declare const RESULT_FIELD_ROWS_AFFECTED = "rows_affected";
148
+ declare const RESULT_FIELD_LAST_INSERT_ID = "last_insert_id";
149
+ declare const RESULT_FIELD_COLUMNS = "columns";
150
+ declare const RESULT_FIELD_VALUES = "values";
151
+ declare const RESULT_FIELD_RESULTS = "results";
152
+ //#endregion
153
+ //#region src/api/results/data-result.d.ts
154
+ type RqliteSingleResult = {
155
+ [RESULT_FIELD_TIME]?: number | string;
156
+ [RESULT_FIELD_ROWS_AFFECTED]?: number | string;
157
+ [RESULT_FIELD_LAST_INSERT_ID]?: number;
158
+ [RESULT_FIELD_COLUMNS]?: string[];
159
+ [RESULT_FIELD_VALUES]?: unknown[][];
160
+ [key: string]: unknown;
161
+ };
162
+ /**
163
+ * A class that represents one data result from an RQLite query or execute API call
164
+ * @see https://rqlite.io/docs/api/api/
165
+ */
166
+ declare class DataResult {
167
+ time: number;
168
+ lastInsertId?: number;
169
+ rowsAffected: number;
170
+ data: Record<string, unknown>;
171
+ constructor(result: RqliteSingleResult, valuesIndex?: number);
172
+ get(property: string): unknown;
173
+ getTime(): number;
174
+ getLastInsertId(): number | undefined;
175
+ getRowsAffected(): number;
176
+ toObject(): Record<string, unknown>;
177
+ toArray(): unknown[];
178
+ toColumnsArray(): string[];
179
+ toString(): string;
180
+ }
181
+ //#endregion
182
+ //#region src/api/results/data-result-error.d.ts
183
+ /**
184
+ * A class that represents one data error result from an RQLite query or execute API call
185
+ * @see https://rqlite.io/docs/api/api/
186
+ */
187
+ declare class DataResultError extends Error {
188
+ code: string;
189
+ errorV2?: Record<string, unknown>;
190
+ constructor(message: string, errorV2?: Record<string, unknown>);
191
+ getErrorV2(): Record<string, unknown> | undefined;
192
+ toObject(): Record<string, unknown>;
193
+ toString(): string;
194
+ }
195
+ //#endregion
196
+ //#region src/api/results/data-results.d.ts
197
+ type RqliteApiData = {
198
+ [RESULT_FIELD_TIME]?: number | string;
199
+ [RESULT_FIELD_RESULTS]: RqliteSingleResult[];
200
+ };
201
+ /**
202
+ * A class to manage a list of results from an RQLite query or execute API response
203
+ * @see https://rqlite.io/docs/api/api/
204
+ */
205
+ declare class DataResults {
206
+ time: number;
207
+ results: Array<DataResult | DataResultError>;
208
+ constructor(data: RqliteApiData);
209
+ setApiData(data: RqliteApiData): void;
210
+ hasError(): boolean;
211
+ getFirstError(): DataResultError | undefined;
212
+ getTime(): number;
213
+ get(index: number): DataResult | DataResultError | undefined;
214
+ getResults(): Array<DataResult | DataResultError>;
215
+ toArray(): Record<string, unknown>[];
216
+ toString(): string;
217
+ }
218
+ //#endregion
219
+ //#region src/api/paths.d.ts
220
+ /**
221
+ * RQLite HTTP API path constants
222
+ * @module api/paths
223
+ * @see https://rqlite.io/docs/api/api/
224
+ * @see https://rqlite.io/docs/guides/backup/
225
+ * @see https://rqlite.io/docs/guides/monitoring-rqlite/
226
+ */
227
+ declare const PATH_QUERY = "/db/query";
228
+ declare const PATH_EXECUTE = "/db/execute";
229
+ declare const PATH_LOAD = "/db/load";
230
+ declare const PATH_BACKUP = "/db/backup";
231
+ declare const PATH_STATUS = "/status";
232
+ //#endregion
233
+ //#region src/api/consistency-levels.d.ts
234
+ /**
235
+ * RQLite read consistency level constants
236
+ * @module api/consistency-levels
237
+ * @see https://rqlite.io/docs/api/read-consistency/
238
+ */
239
+ declare const CONSISTENCY_LEVEL_NONE = "none";
240
+ declare const CONSISTENCY_LEVEL_STRONG = "strong";
241
+ declare const CONSISTENCY_LEVEL_LINEARIZABLE = "linearizable";
242
+ declare const CONSISTENCY_LEVEL_WEAK = "weak";
243
+ //#endregion
244
+ //#region src/api/data/index.d.ts
245
+ type DataRequestBaseOptions = {
246
+ raw?: boolean;
247
+ };
248
+ type QueryRequestOptions = ApiClientRequestOptions & DataRequestBaseOptions;
249
+ type ExecuteRequestOptions = ApiClientRequestOptions & DataRequestBaseOptions;
250
+ /**
251
+ * Data api client to perform RQLite queries
252
+ */
253
+ declare class DataApiClient extends ApiClient {
254
+ /**
255
+ * Send an RQLite query API request to the RQLite server
256
+ * @see https://rqlite.io/docs/api/api/
257
+ * @see https://rqlite.io/docs/api/read-consistency/
258
+ */
259
+ query(sql: string | string[], options?: QueryRequestOptions): Promise<DataResults | HttpResponse>;
260
+ /**
261
+ * Send an RQLite execute API request to the RQLite server
262
+ * @see https://rqlite.io/docs/api/api/
263
+ */
264
+ execute(sql: string | string[], options?: ExecuteRequestOptions): Promise<DataResults | HttpResponse>;
265
+ }
266
+ //#endregion
267
+ //#region src/api/backup-formats.d.ts
268
+ /**
269
+ * RQLite backup data format constants
270
+ * @module api/backup-formats
271
+ * @see https://rqlite.io/docs/guides/backup/
272
+ */
273
+ declare const BACKUP_DATA_FORMAT_SQL = "sql";
274
+ declare const BACKUP_DATA_FORMAT_DUMP = "dump";
275
+ //#endregion
276
+ //#region src/api/backup/index.d.ts
277
+ /**
278
+ * Backup api client to perform RQLite back up and load operations
279
+ */
280
+ declare class BackupApiClient extends HttpRequest {
281
+ /**
282
+ * Perform a SQL dump backup from the RQLite server
283
+ * @see https://rqlite.io/docs/guides/backup/
284
+ * @see module:api/backup-formats
285
+ */
286
+ backup(format?: string): Promise<Readable>;
287
+ /**
288
+ * Perform a SQL restore by sending data the RQLite server
289
+ * @see https://rqlite.io/docs/guides/backup/
290
+ * @see module:api/backup-formats
291
+ */
292
+ load(data: Buffer | string, format?: string): Promise<Readable>;
293
+ }
294
+ //#endregion
295
+ //#region src/api/status/index.d.ts
296
+ type StatusRequestOptions = {
297
+ raw?: boolean;
298
+ attemptHostIndex?: number;
299
+ useLeader?: boolean;
300
+ };
301
+ type StatusAllHostsResponse = {
302
+ response: HttpResponse;
303
+ host: string;
304
+ };
305
+ /**
306
+ * Data api client to perform RQLite status queries
307
+ */
308
+ declare class StatusApiClient extends ApiClient {
309
+ /**
310
+ * Get the RQLite server status which defaults to the leader host
311
+ * @see https://rqlite.io/docs/guides/monitoring-rqlite/
312
+ */
313
+ status(options?: StatusRequestOptions): Promise<HttpResponse>;
314
+ /**
315
+ * Get the RQLite server status for all hosts
316
+ * @see https://rqlite.io/docs/guides/monitoring-rqlite/
317
+ */
318
+ statusAllHosts(options?: StatusRequestOptions): Promise<StatusAllHostsResponse[]>;
319
+ }
320
+ //#endregion
321
+ //#region src/index.d.ts
322
+ declare const _default: {
323
+ DataApiClient: typeof DataApiClient;
324
+ BackupApiClient: typeof BackupApiClient;
325
+ StatusApiClient: typeof StatusApiClient;
326
+ };
327
+ //#endregion
328
+ export { BACKUP_DATA_FORMAT_DUMP, BACKUP_DATA_FORMAT_SQL, BackupApiClient, CONSISTENCY_LEVEL_LINEARIZABLE, CONSISTENCY_LEVEL_NONE, CONSISTENCY_LEVEL_STRONG, CONSISTENCY_LEVEL_WEAK, DataApiClient, PATH_BACKUP, PATH_EXECUTE, PATH_LOAD, PATH_QUERY, PATH_STATUS, StatusApiClient, _default as default };
329
+ //# sourceMappingURL=index.d.ts.map