alepha 0.20.3 → 0.20.4

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 (217) hide show
  1. package/dist/api/audits/index.d.ts.map +1 -1
  2. package/dist/api/files/index.d.ts.map +1 -1
  3. package/dist/api/jobs/index.d.ts +14 -14
  4. package/dist/api/jobs/index.d.ts.map +1 -1
  5. package/dist/api/keys/index.d.ts +4 -4
  6. package/dist/api/organizations/index.d.ts.map +1 -1
  7. package/dist/api/parameters/index.d.ts +8 -3
  8. package/dist/api/parameters/index.d.ts.map +1 -1
  9. package/dist/api/parameters/index.js +20 -4
  10. package/dist/api/parameters/index.js.map +1 -1
  11. package/dist/api/payments/index.d.ts.map +1 -1
  12. package/dist/api/users/index.browser.js +6 -0
  13. package/dist/api/users/index.browser.js.map +1 -1
  14. package/dist/api/users/index.d.ts +5037 -139
  15. package/dist/api/users/index.d.ts.map +1 -1
  16. package/dist/api/users/index.js +58 -10
  17. package/dist/api/users/index.js.map +1 -1
  18. package/dist/bucket/index.d.ts +77 -107
  19. package/dist/bucket/index.d.ts.map +1 -1
  20. package/dist/bucket/index.js +148 -4
  21. package/dist/bucket/index.js.map +1 -1
  22. package/dist/bucket/index.workerd.js +7 -1
  23. package/dist/bucket/index.workerd.js.map +1 -1
  24. package/dist/cache/core/index.d.ts +26 -0
  25. package/dist/cache/core/index.d.ts.map +1 -1
  26. package/dist/cache/core/index.js +11 -1
  27. package/dist/cache/core/index.js.map +1 -1
  28. package/dist/cache/core/index.workerd.js +11 -1
  29. package/dist/cache/core/index.workerd.js.map +1 -1
  30. package/dist/cli/config/index.d.ts +7 -5
  31. package/dist/cli/config/index.d.ts.map +1 -1
  32. package/dist/cli/config/index.js +2 -3
  33. package/dist/cli/config/index.js.map +1 -1
  34. package/dist/cli/core/index.d.ts +420 -13
  35. package/dist/cli/core/index.d.ts.map +1 -1
  36. package/dist/cli/core/index.js +22 -511
  37. package/dist/cli/core/index.js.map +1 -1
  38. package/dist/cli/devtools/index.d.ts +4 -8
  39. package/dist/cli/devtools/index.d.ts.map +1 -1
  40. package/dist/cli/devtools/index.js +13 -15
  41. package/dist/cli/devtools/index.js.map +1 -1
  42. package/dist/cli/platform/index.d.ts +10 -13
  43. package/dist/cli/platform/index.d.ts.map +1 -1
  44. package/dist/cli/platform/index.js +18 -15
  45. package/dist/cli/platform/index.js.map +1 -1
  46. package/dist/cli/vendor/index.d.ts +10 -13
  47. package/dist/cli/vendor/index.d.ts.map +1 -1
  48. package/dist/cli/vendor/index.js +16 -13
  49. package/dist/cli/vendor/index.js.map +1 -1
  50. package/dist/core/index.browser.js +27 -3
  51. package/dist/core/index.browser.js.map +1 -1
  52. package/dist/core/index.d.ts +6 -3
  53. package/dist/core/index.d.ts.map +1 -1
  54. package/dist/core/index.js +27 -3
  55. package/dist/core/index.js.map +1 -1
  56. package/dist/core/index.native.js +27 -3
  57. package/dist/core/index.native.js.map +1 -1
  58. package/dist/core/index.workerd.js +27 -3
  59. package/dist/core/index.workerd.js.map +1 -1
  60. package/dist/datetime/index.d.ts +69 -10
  61. package/dist/datetime/index.d.ts.map +1 -1
  62. package/dist/datetime/index.js +135 -13
  63. package/dist/datetime/index.js.map +1 -1
  64. package/dist/email/smtp/index.js +10636 -2
  65. package/dist/email/smtp/index.js.map +1 -1
  66. package/dist/fake/index.d.ts +8085 -4
  67. package/dist/fake/index.d.ts.map +1 -1
  68. package/dist/fake/index.js +33554 -3
  69. package/dist/fake/index.js.map +1 -1
  70. package/dist/lock/core/index.d.ts +30 -2
  71. package/dist/lock/core/index.d.ts.map +1 -1
  72. package/dist/lock/core/index.js +35 -12
  73. package/dist/lock/core/index.js.map +1 -1
  74. package/dist/mcp/index.d.ts +238 -31
  75. package/dist/mcp/index.d.ts.map +1 -1
  76. package/dist/mcp/index.js +198 -71
  77. package/dist/mcp/index.js.map +1 -1
  78. package/dist/orm/core/index.browser.js +1 -1
  79. package/dist/orm/core/index.browser.js.map +1 -1
  80. package/dist/orm/core/index.bun.js +4 -3
  81. package/dist/orm/core/index.bun.js.map +1 -1
  82. package/dist/orm/core/index.d.ts +4877 -9
  83. package/dist/orm/core/index.d.ts.map +1 -1
  84. package/dist/orm/core/index.js +4 -3
  85. package/dist/orm/core/index.js.map +1 -1
  86. package/dist/orm/postgres/index.d.ts +608 -1
  87. package/dist/orm/postgres/index.d.ts.map +1 -1
  88. package/dist/react/core/index.d.ts +102 -1
  89. package/dist/react/core/index.d.ts.map +1 -1
  90. package/dist/react/core/index.js +65 -1
  91. package/dist/react/core/index.js.map +1 -1
  92. package/dist/react/form/index.d.ts +6 -0
  93. package/dist/react/form/index.d.ts.map +1 -1
  94. package/dist/react/form/index.js +7 -7
  95. package/dist/react/form/index.js.map +1 -1
  96. package/dist/react/i18n/index.d.ts +7 -1
  97. package/dist/react/i18n/index.d.ts.map +1 -1
  98. package/dist/react/i18n/index.js +6 -0
  99. package/dist/react/i18n/index.js.map +1 -1
  100. package/dist/react/router/index.browser.js +20 -2
  101. package/dist/react/router/index.browser.js.map +1 -1
  102. package/dist/react/router/index.d.ts +36 -4
  103. package/dist/react/router/index.d.ts.map +1 -1
  104. package/dist/react/router/index.js +20 -2
  105. package/dist/react/router/index.js.map +1 -1
  106. package/dist/react/testing/chunk-6Ep1yQYe.js +16 -0
  107. package/dist/react/testing/index.d.ts +411 -1
  108. package/dist/react/testing/index.d.ts.map +1 -1
  109. package/dist/react/testing/index.js +12293 -13
  110. package/dist/react/testing/index.js.map +1 -1
  111. package/dist/react/ui/index.d.ts +195 -1
  112. package/dist/react/ui/index.d.ts.map +1 -1
  113. package/dist/react/ui/index.js +61 -1
  114. package/dist/react/ui/index.js.map +1 -1
  115. package/dist/scheduler/index.d.ts +84 -3
  116. package/dist/scheduler/index.d.ts.map +1 -1
  117. package/dist/scheduler/index.js +390 -1
  118. package/dist/scheduler/index.js.map +1 -1
  119. package/dist/scheduler/index.workerd.js +390 -1
  120. package/dist/scheduler/index.workerd.js.map +1 -1
  121. package/dist/security/index.d.ts +325 -2
  122. package/dist/security/index.d.ts.map +1 -1
  123. package/dist/security/index.js +1361 -2
  124. package/dist/security/index.js.map +1 -1
  125. package/dist/server/auth/index.d.ts +1054 -1
  126. package/dist/server/auth/index.d.ts.map +1 -1
  127. package/dist/server/auth/index.js +1223 -1
  128. package/dist/server/auth/index.js.map +1 -1
  129. package/dist/server/core/index.browser.js +10 -3
  130. package/dist/server/core/index.browser.js.map +1 -1
  131. package/dist/server/core/index.d.ts.map +1 -1
  132. package/dist/server/core/index.js +28 -5
  133. package/dist/server/core/index.js.map +1 -1
  134. package/dist/server/metrics/index.d.ts +514 -1
  135. package/dist/server/metrics/index.d.ts.map +1 -1
  136. package/dist/server/metrics/index.js +4374 -4
  137. package/dist/server/metrics/index.js.map +1 -1
  138. package/dist/server/swagger/index.d.ts.map +1 -1
  139. package/dist/server/swagger/index.js +3 -4
  140. package/dist/server/swagger/index.js.map +1 -1
  141. package/dist/websocket/index.browser.js +11 -5
  142. package/dist/websocket/index.browser.js.map +1 -1
  143. package/dist/websocket/index.d.ts +3 -1
  144. package/dist/websocket/index.d.ts.map +1 -1
  145. package/dist/websocket/index.js +21 -6
  146. package/dist/websocket/index.js.map +1 -1
  147. package/package.json +671 -263
  148. package/src/api/parameters/services/ParameterProvider.ts +21 -4
  149. package/src/api/users/__tests__/SessionService.spec.ts +99 -0
  150. package/src/api/users/__tests__/UserJobs.spec.ts +67 -0
  151. package/src/api/users/atoms/realmAuthSettingsAtom.ts +15 -0
  152. package/src/api/users/entities/sessions.ts +6 -0
  153. package/src/api/users/jobs/UserJobs.ts +44 -17
  154. package/src/api/users/providers/RealmProvider.ts +4 -0
  155. package/src/api/users/services/SessionService.ts +27 -0
  156. package/src/bucket/__tests__/NodeS3BucketProvider.spec.ts +74 -0
  157. package/src/bucket/index.ts +19 -2
  158. package/src/bucket/primitives/$bucket.ts +9 -1
  159. package/src/bucket/providers/CloudflareR2Provider.ts +2 -137
  160. package/src/bucket/providers/NodeS3BucketProvider.ts +218 -0
  161. package/src/cache/core/index.ts +29 -0
  162. package/src/cache/core/primitives/$cache.ts +14 -1
  163. package/src/cli/config/defineConfig.ts +13 -15
  164. package/src/cli/core/__tests__/init.spec.ts +6 -7
  165. package/src/cli/core/services/ProjectScaffolder.ts +18 -14
  166. package/src/cli/core/tasks/BuildCloudflareTask.ts +5 -0
  167. package/src/cli/core/templates/agentMd.ts +2 -10
  168. package/src/cli/core/templates/saasAdminLayoutTsx.ts +3 -3
  169. package/src/cli/devtools/index.ts +12 -26
  170. package/src/cli/platform/index.ts +15 -24
  171. package/src/cli/vendor/atoms/vendorOptions.ts +1 -1
  172. package/src/cli/vendor/index.ts +14 -23
  173. package/src/core/Alepha.ts +11 -1
  174. package/src/core/helpers/ref.ts +18 -0
  175. package/src/core/index.shared.ts +1 -0
  176. package/src/core/providers/SchemaValidator.ts +9 -1
  177. package/src/core/providers/TypeProvider.ts +1 -2
  178. package/src/datetime/REFACTORING.md +118 -0
  179. package/src/datetime/providers/DateTimeProvider.ts +203 -24
  180. package/src/lock/core/index.ts +31 -0
  181. package/src/lock/core/primitives/$lock.ts +14 -1
  182. package/src/mcp/__tests__/jsonrpc.spec.ts +1 -1
  183. package/src/mcp/helpers/jsonrpc.ts +26 -1
  184. package/src/mcp/index.ts +10 -5
  185. package/src/mcp/interfaces/McpTypes.ts +83 -6
  186. package/src/mcp/primitives/$prompt.ts +18 -1
  187. package/src/mcp/primitives/$resource.ts +18 -1
  188. package/src/mcp/primitives/$tool.ts +83 -7
  189. package/src/mcp/providers/McpServerProvider.ts +74 -16
  190. package/src/mcp/transports/StreamableHttpMcpTransport.ts +226 -0
  191. package/src/orm/REFACTORING.md +330 -0
  192. package/src/orm/core/primitives/$transactional.ts +11 -0
  193. package/src/orm/core/schemas/updateSchema.ts +1 -1
  194. package/src/orm/core/services/PgRelationManager.ts +4 -2
  195. package/src/react/core/__tests__/useQuery.browser.spec.tsx +86 -0
  196. package/src/react/core/hooks/useQuery.ts +153 -0
  197. package/src/react/core/index.ts +1 -0
  198. package/src/react/form/services/FormModel.ts +15 -6
  199. package/src/react/form/services/parseField.ts +8 -0
  200. package/src/react/i18n/providers/I18nProvider.ts +8 -2
  201. package/src/react/router/__tests__/$page.spec.tsx +0 -16
  202. package/src/react/router/__tests__/ssr.spec.tsx +339 -0
  203. package/src/react/router/primitives/$page.ts +28 -4
  204. package/src/react/router/providers/ReactPageProvider.ts +27 -9
  205. package/src/react/ui/atoms/uiThemeListAtom.ts +36 -0
  206. package/src/react/ui/index.ts +6 -0
  207. package/src/react/ui/services/SchemaControl.ts +209 -0
  208. package/src/security/primitives/$issuer.ts +6 -3
  209. package/src/server/core/__tests__/ServerRouterProvider-serializationError.spec.ts +75 -0
  210. package/src/server/core/__tests__/ServerRouterProvider-validationError.spec.ts +306 -0
  211. package/src/server/core/errors/ValidationError.ts +13 -1
  212. package/src/server/core/primitives/$action.ts +16 -5
  213. package/src/server/core/providers/ServerRouterProvider.ts +26 -4
  214. package/src/server/swagger/providers/ServerSwaggerProvider.ts +5 -7
  215. package/src/websocket/providers/NodeWebSocketServerProvider.ts +10 -4
  216. package/src/websocket/services/WebSocketClient.ts +11 -5
  217. package/src/mcp/transports/SseMcpTransport.ts +0 -182
@@ -8,7 +8,6 @@ import { PgDatabase, PgSchema, PgTableExtraConfigValue } from "drizzle-orm/pg-co
8
8
  import { PostgresJsDatabase } from "drizzle-orm/postgres-js";
9
9
  import postgres from "postgres";
10
10
  import { BunSQLDatabase } from "drizzle-orm/bun-sql";
11
- import { PGlite } from "@electric-sql/pglite";
12
11
  import { PgliteDatabase } from "drizzle-orm/pglite";
13
12
 
14
13
  //#region ../../src/orm/postgres/services/PostgresModelBuilder.d.ts
@@ -214,6 +213,614 @@ declare class NodePostgresProvider extends PostgresProvider {
214
213
  protected ssl(url: URL): "require" | "allow" | "prefer" | "verify-full" | undefined;
215
214
  }
216
215
  //#endregion
216
+ //#region ../../../../node_modules/@electric-sql/pglite/dist/pglite-BZlQ7pL-.d.ts
217
+ type MessageName = 'parseComplete' | 'bindComplete' | 'closeComplete' | 'noData' | 'portalSuspended' | 'replicationStart' | 'emptyQuery' | 'copyDone' | 'copyData' | 'rowDescription' | 'parameterDescription' | 'parameterStatus' | 'backendKeyData' | 'notification' | 'readyForQuery' | 'commandComplete' | 'dataRow' | 'copyInResponse' | 'copyOutResponse' | 'authenticationOk' | 'authenticationMD5Password' | 'authenticationCleartextPassword' | 'authenticationSASL' | 'authenticationSASLContinue' | 'authenticationSASLFinal' | 'error' | 'notice';
218
+ type BackendMessage = {
219
+ name: MessageName;
220
+ length: number;
221
+ };
222
+ interface NoticeOrError {
223
+ message: string | undefined;
224
+ severity: string | undefined;
225
+ code: string | undefined;
226
+ detail: string | undefined;
227
+ hint: string | undefined;
228
+ position: string | undefined;
229
+ internalPosition: string | undefined;
230
+ internalQuery: string | undefined;
231
+ where: string | undefined;
232
+ schema: string | undefined;
233
+ table: string | undefined;
234
+ column: string | undefined;
235
+ dataType: string | undefined;
236
+ constraint: string | undefined;
237
+ file: string | undefined;
238
+ line: string | undefined;
239
+ routine: string | undefined;
240
+ }
241
+ declare class NoticeMessage implements BackendMessage, NoticeOrError {
242
+ readonly length: number;
243
+ readonly message: string | undefined;
244
+ constructor(length: number, message: string | undefined);
245
+ readonly name = "notice";
246
+ severity: string | undefined;
247
+ code: string | undefined;
248
+ detail: string | undefined;
249
+ hint: string | undefined;
250
+ position: string | undefined;
251
+ internalPosition: string | undefined;
252
+ internalQuery: string | undefined;
253
+ where: string | undefined;
254
+ schema: string | undefined;
255
+ table: string | undefined;
256
+ column: string | undefined;
257
+ dataType: string | undefined;
258
+ constraint: string | undefined;
259
+ file: string | undefined;
260
+ line: string | undefined;
261
+ routine: string | undefined;
262
+ }
263
+ type IDBFS = Emscripten.FileSystemType & {
264
+ quit: () => void;
265
+ dbs: Record<string, IDBDatabase>;
266
+ };
267
+ type FS = typeof FS & {
268
+ filesystems: {
269
+ MEMFS: Emscripten.FileSystemType;
270
+ NODEFS: Emscripten.FileSystemType;
271
+ IDBFS: IDBFS;
272
+ };
273
+ quit: () => void;
274
+ };
275
+ interface PostgresMod extends Omit<EmscriptenModule, 'preInit' | 'preRun' | 'postRun'> {
276
+ preInit: Array<{
277
+ (mod: PostgresMod): void;
278
+ }>;
279
+ preRun: Array<{
280
+ (mod: PostgresMod): void;
281
+ }>;
282
+ postRun: Array<{
283
+ (mod: PostgresMod): void;
284
+ }>;
285
+ thisProgram: string;
286
+ stdin: (() => number | null) | null;
287
+ FS: FS;
288
+ wasmMemory: WebAssembly.Memory;
289
+ PROXYFS: Emscripten.FileSystemType;
290
+ WASM_PREFIX: string;
291
+ pg_extensions: Record<string, Promise<Blob | null>>;
292
+ UTF8ToString: (ptr: number, maxBytesToRead?: number) => string;
293
+ stringToUTF8OnStack: (s: string) => number;
294
+ _pgl_set_system_fn: (system_fn: number) => void;
295
+ _pgl_set_popen_fn: (popen_fn: number) => void;
296
+ _pgl_set_pclose_fn: (pclose_fn: number) => void;
297
+ _pgl_set_rw_cbs: (read_cb: number, write_cb: number) => void;
298
+ _pgl_set_pipe_fn: (pipe_fn: number) => number;
299
+ _pgl_freopen: (filepath: number, mode: number, stream: number) => number;
300
+ _pgl_pq_flush: () => void;
301
+ _fopen: (path: number, mode: number) => number;
302
+ _fclose: (stream: number) => number;
303
+ _fflush: (stream: number) => void;
304
+ _pgl_proc_exit: (code: number) => number;
305
+ addFunction: (cb: (ptr: any, length: number) => void, signature: string) => number;
306
+ removeFunction: (f: number) => void;
307
+ callMain: (args?: string[]) => number;
308
+ _PostgresMainLoopOnce: () => void;
309
+ _PostgresMainLongJmp: () => void;
310
+ _PostgresSendReadyForQueryIfNecessary: () => void;
311
+ _ProcessStartupPacket: (Port: number, ssl_done: boolean, gss_done: boolean) => number;
312
+ _IsTransactionBlock: () => number;
313
+ _pgl_setPGliteActive: (newValue: number) => number;
314
+ _pgl_startPGlite: () => void;
315
+ _pgl_getMyProcPort: () => number;
316
+ _pgl_sendConnData: () => void;
317
+ ENV: any;
318
+ _emscripten_force_exit: (status: number) => void;
319
+ _pgl_run_atexit_funcs: () => void;
320
+ _pq_buffer_remaining_data: () => number;
321
+ }
322
+ type DumpTarCompressionOptions = 'none' | 'gzip' | 'auto';
323
+ /**
324
+ * Filesystem interface.
325
+ * All virtual filesystems that are compatible with PGlite must implement
326
+ * this interface.
327
+ */
328
+ interface Filesystem {
329
+ /**
330
+ * Initiate the filesystem and return the options to pass to the emscripten module.
331
+ */
332
+ init(pg: PGlite, emscriptenOptions: Partial<PostgresMod>): Promise<{
333
+ emscriptenOpts: Partial<PostgresMod>;
334
+ }>;
335
+ /**
336
+ * Sync the filesystem to any underlying storage.
337
+ */
338
+ syncToFs(relaxedDurability?: boolean): Promise<void>;
339
+ /**
340
+ * Sync the filesystem from any underlying storage.
341
+ */
342
+ initialSyncFs(): Promise<void>;
343
+ /**
344
+ * Dump the PGDATA dir from the filesystem to a gzipped tarball.
345
+ */
346
+ dumpTar(dbname: string, compression?: DumpTarCompressionOptions): Promise<File | Blob>;
347
+ /**
348
+ * Close the filesystem.
349
+ */
350
+ closeFs(): Promise<void>;
351
+ }
352
+ /**
353
+ * Base class for all emscripten built-in filesystems.
354
+ */
355
+ type DebugLevel = 0 | 1 | 2 | 3 | 4 | 5;
356
+ type RowMode = 'array' | 'object';
357
+ interface ParserOptions {
358
+ [pgType: number]: (value: string) => any;
359
+ }
360
+ interface SerializerOptions {
361
+ [pgType: number]: (value: any) => string;
362
+ }
363
+ interface QueryOptions {
364
+ rowMode?: RowMode;
365
+ parsers?: ParserOptions;
366
+ serializers?: SerializerOptions;
367
+ blob?: Blob | File;
368
+ onNotice?: (notice: NoticeMessage) => void;
369
+ paramTypes?: number[];
370
+ }
371
+ interface ExecProtocolOptions {
372
+ syncToFs?: boolean;
373
+ throwOnError?: boolean;
374
+ onNotice?: (notice: NoticeMessage) => void;
375
+ }
376
+ interface ExecProtocolOptionsStream {
377
+ syncToFs?: boolean;
378
+ onRawData: (data: Uint8Array) => void;
379
+ }
380
+ interface ExtensionSetupResult<TNamespace = any> {
381
+ emscriptenOpts?: any;
382
+ namespaceObj?: TNamespace;
383
+ bundlePath?: URL;
384
+ init?: () => Promise<void>;
385
+ close?: () => Promise<void>;
386
+ }
387
+ type ExtensionSetup<TNamespace = any> = (pg: PGliteInterface, emscriptenOpts: any, clientOnly?: boolean) => Promise<ExtensionSetupResult<TNamespace>>;
388
+ interface Extension<TNamespace = any> {
389
+ name: string;
390
+ setup: ExtensionSetup<TNamespace>;
391
+ }
392
+ type ExtensionNamespace<T> = T extends Extension<infer TNamespace> ? TNamespace : any;
393
+ type Extensions = {
394
+ [namespace: string]: Extension | URL;
395
+ };
396
+ type InitializedExtensions<TExtensions extends Extensions = Extensions> = { [K in keyof TExtensions]: ExtensionNamespace<TExtensions[K]> };
397
+ interface ExecProtocolResult {
398
+ messages: BackendMessage[];
399
+ data: Uint8Array;
400
+ }
401
+ interface PGliteOptions<TExtensions extends Extensions = Extensions> {
402
+ noInitDb?: boolean;
403
+ dataDir?: string;
404
+ username?: string;
405
+ database?: string;
406
+ fs?: Filesystem;
407
+ debug?: DebugLevel;
408
+ relaxedDurability?: boolean;
409
+ extensions?: TExtensions;
410
+ loadDataDir?: Blob | File;
411
+ initialMemory?: number;
412
+ pgliteWasmModule?: WebAssembly.Module;
413
+ initdbWasmModule?: WebAssembly.Module;
414
+ fsBundle?: Blob | File;
415
+ parsers?: ParserOptions;
416
+ serializers?: SerializerOptions;
417
+ startParams?: string[];
418
+ }
419
+ type PGliteInterface<T extends Extensions = Extensions> = InitializedExtensions<T> & {
420
+ readonly waitReady: Promise<void>;
421
+ readonly debug: DebugLevel;
422
+ readonly ready: boolean;
423
+ readonly closed: boolean;
424
+ close(): Promise<void>;
425
+ query<T>(query: string, params?: any[], options?: QueryOptions): Promise<Results<T>>;
426
+ sql<T>(sqlStrings: TemplateStringsArray, ...params: any[]): Promise<Results<T>>;
427
+ exec(query: string, options?: QueryOptions): Promise<Array<Results>>;
428
+ describeQuery(query: string): Promise<DescribeQueryResult>;
429
+ transaction<T>(callback: (tx: Transaction) => Promise<T>): Promise<T>;
430
+ execProtocolRaw(message: Uint8Array, options?: ExecProtocolOptions): Promise<Uint8Array>;
431
+ execProtocolRawStream(message: Uint8Array, options?: ExecProtocolOptionsStream): Promise<void>;
432
+ execProtocol(message: Uint8Array, options?: ExecProtocolOptions): Promise<ExecProtocolResult>;
433
+ runExclusive<T>(fn: () => Promise<T>): Promise<T>;
434
+ listen(channel: string, callback: (payload: string) => void, tx?: Transaction): Promise<(tx?: Transaction) => Promise<void>>;
435
+ unlisten(channel: string, callback?: (payload: string) => void, tx?: Transaction): Promise<void>;
436
+ onNotification(callback: (channel: string, payload: string) => void): () => void;
437
+ offNotification(callback: (channel: string, payload: string) => void): void;
438
+ dumpDataDir(compression?: DumpTarCompressionOptions): Promise<File | Blob>;
439
+ refreshArrayTypes(): Promise<void>;
440
+ };
441
+ type PGliteInterfaceExtensions<E> = E extends Extensions ? { [K in keyof E]: E[K] extends Extension ? Awaited<ReturnType<E[K]['setup']>>['namespaceObj'] extends infer N ? N extends undefined | null | void ? never : N : never : never } : Record<string, never>;
442
+ type Row<T = {
443
+ [key: string]: any;
444
+ }> = T;
445
+ type Results<T = {
446
+ [key: string]: any;
447
+ }> = {
448
+ rows: Row<T>[];
449
+ affectedRows?: number;
450
+ fields: {
451
+ name: string;
452
+ dataTypeID: number;
453
+ }[];
454
+ blob?: Blob;
455
+ };
456
+ interface Transaction {
457
+ query<T>(query: string, params?: any[], options?: QueryOptions): Promise<Results<T>>;
458
+ sql<T>(sqlStrings: TemplateStringsArray, ...params: any[]): Promise<Results<T>>;
459
+ exec(query: string, options?: QueryOptions): Promise<Array<Results>>;
460
+ rollback(): Promise<void>;
461
+ listen(channel: string, callback: (payload: string) => void): Promise<(tx?: Transaction) => Promise<void>>;
462
+ get closed(): boolean;
463
+ }
464
+ type DescribeQueryResult = {
465
+ queryParams: {
466
+ dataTypeID: number;
467
+ serializer: Serializer;
468
+ }[];
469
+ resultFields: {
470
+ name: string;
471
+ dataTypeID: number;
472
+ parser: Parser;
473
+ }[];
474
+ };
475
+ type Parser = (x: string, typeId?: number) => any;
476
+ type Serializer = (x: any) => string;
477
+ declare abstract class BasePGlite implements Pick<PGliteInterface, 'query' | 'sql' | 'exec' | 'transaction'> {
478
+ #private;
479
+ serializers: Record<number | string, Serializer>;
480
+ parsers: Record<number | string, Parser>;
481
+ abstract debug: DebugLevel;
482
+ /**
483
+ * Execute a postgres wire protocol message
484
+ * @param message The postgres wire protocol message to execute
485
+ * @returns The result of the query
486
+ */
487
+ abstract execProtocol(message: Uint8Array, {
488
+ syncToFs,
489
+ onNotice
490
+ }: ExecProtocolOptions): Promise<ExecProtocolResult>;
491
+ /**
492
+ * Execute a postgres wire protocol message
493
+ * @param message The postgres wire protocol message to execute
494
+ * @returns The parsed results of the query
495
+ */
496
+ abstract execProtocolStream(message: Uint8Array, {
497
+ syncToFs,
498
+ onNotice
499
+ }: ExecProtocolOptions): Promise<BackendMessage[]>;
500
+ /**
501
+ * Execute a postgres wire protocol message directly without wrapping the response.
502
+ * Only use if `execProtocol()` doesn't suite your needs.
503
+ *
504
+ * **Warning:** This bypasses PGlite's protocol wrappers that manage error/notice messages,
505
+ * transactions, and notification listeners. Only use if you need to bypass these wrappers and
506
+ * don't intend to use the above features.
507
+ *
508
+ * @param message The postgres wire protocol message to execute
509
+ * @returns The direct message data response produced by Postgres
510
+ */
511
+ abstract execProtocolRaw(message: Uint8Array, {
512
+ syncToFs
513
+ }: ExecProtocolOptions): Promise<Uint8Array>;
514
+ /**
515
+ * Execute a postgres wire protocol message directly without wrapping the response.
516
+ * Only use if `execProtocol()` doesn't suite your needs.
517
+ *
518
+ * **Warning:** This bypasses PGlite's protocol wrappers that manage error/notice messages,
519
+ * transactions, and notification listeners. Only use if you need to bypass these wrappers and
520
+ * don't intend to use the above features.
521
+ *
522
+ * @param message The postgres wire protocol message to execute
523
+ * @param options.onRawData Callback to receive streaming data
524
+ */
525
+ abstract execProtocolRawStream(message: Uint8Array, {
526
+ syncToFs,
527
+ onRawData
528
+ }: ExecProtocolOptionsStream): Promise<void>;
529
+ /**
530
+ * Sync the database to the filesystem
531
+ * @returns Promise that resolves when the database is synced to the filesystem
532
+ */
533
+ abstract syncToFs(): Promise<void>;
534
+ /**
535
+ * Handle a file attached to the current query
536
+ * @param file The file to handle
537
+ */
538
+ abstract _handleBlob(blob?: File | Blob): Promise<void>;
539
+ /**
540
+ * Get the written file
541
+ */
542
+ abstract _getWrittenBlob(): Promise<File | Blob | undefined>;
543
+ /**
544
+ * Cleanup the current file
545
+ */
546
+ abstract _cleanupBlob(): Promise<void>;
547
+ abstract _checkReady(): Promise<void>;
548
+ abstract _runExclusiveQuery<T>(fn: () => Promise<T>): Promise<T>;
549
+ abstract _runExclusiveTransaction<T>(fn: () => Promise<T>): Promise<T>;
550
+ /**
551
+ * Listen for notifications on a channel
552
+ */
553
+ abstract listen(channel: string, callback: (payload: string) => void, tx?: Transaction): Promise<(tx?: Transaction) => Promise<void>>;
554
+ /**
555
+ * Initialize the array types
556
+ * The oid if the type of an element and the typarray is the oid of the type of the
557
+ * array.
558
+ * We extract these from the database then create the serializers/parsers for
559
+ * each type.
560
+ * This should be called at the end of #init() in the implementing class.
561
+ */
562
+ _initArrayTypes({
563
+ force
564
+ }?: {
565
+ force?: boolean | undefined;
566
+ }): Promise<void>;
567
+ /**
568
+ * Re-syncs the array types from the database
569
+ * This is useful if you add a new type to the database and want to use it, otherwise pglite won't recognize it.
570
+ */
571
+ refreshArrayTypes(): Promise<void>;
572
+ /**
573
+ * Execute a single SQL statement
574
+ * This uses the "Extended Query" postgres wire protocol message.
575
+ * @param query The query to execute
576
+ * @param params Optional parameters for the query
577
+ * @returns The result of the query
578
+ */
579
+ query<T>(query: string, params?: any[], options?: QueryOptions): Promise<Results<T>>;
580
+ /**
581
+ * Execute a single SQL statement like with {@link PGlite.query}, but with a
582
+ * templated statement where template values will be treated as parameters.
583
+ *
584
+ * You can use helpers from `/template` to further format the query with
585
+ * identifiers, raw SQL, and nested statements.
586
+ *
587
+ * This uses the "Extended Query" postgres wire protocol message.
588
+ *
589
+ * @param query The query to execute with parameters as template values
590
+ * @returns The result of the query
591
+ *
592
+ * @example
593
+ * ```ts
594
+ * const results = await db.sql`SELECT * FROM ${identifier`foo`} WHERE id = ${id}`
595
+ * ```
596
+ */
597
+ sql<T>(sqlStrings: TemplateStringsArray, ...params: any[]): Promise<Results<T>>;
598
+ /**
599
+ * Execute a SQL query, this can have multiple statements.
600
+ * This uses the "Simple Query" postgres wire protocol message.
601
+ * @param query The query to execute
602
+ * @returns The result of the query
603
+ */
604
+ exec(query: string, options?: QueryOptions): Promise<Array<Results>>;
605
+ /**
606
+ * Describe a query
607
+ * @param query The query to describe
608
+ * @returns A description of the result types for the query
609
+ */
610
+ describeQuery(query: string, options?: QueryOptions): Promise<DescribeQueryResult>;
611
+ /**
612
+ * Execute a transaction
613
+ * @param callback A callback function that takes a transaction object
614
+ * @returns The result of the transaction
615
+ */
616
+ transaction<T>(callback: (tx: Transaction) => Promise<T>): Promise<T>;
617
+ /**
618
+ * Run a function exclusively, no other transactions or queries will be allowed
619
+ * while the function is running.
620
+ * This is useful when working with the execProtocol methods as they are not blocked,
621
+ * and do not block the locks used by transactions and queries.
622
+ * @param fn The function to run
623
+ * @returns The result of the function
624
+ */
625
+ runExclusive<T>(fn: () => Promise<T>): Promise<T>;
626
+ }
627
+ declare class PGlite extends BasePGlite implements PGliteInterface, AsyncDisposable {
628
+ #private;
629
+ fs?: Filesystem;
630
+ protected mod?: PostgresMod;
631
+ private readonly POSTGRES_MAIN_LONGJMP;
632
+ get ENV(): any;
633
+ readonly dataDir?: string;
634
+ readonly waitReady: Promise<void>;
635
+ readonly debug: DebugLevel;
636
+ static readonly DEFAULT_RECV_BUF_SIZE: number;
637
+ static readonly MAX_BUFFER_SIZE: number;
638
+ externalCommandStreamFd: number | null;
639
+ static readonly defaultStartParams: string[];
640
+ /**
641
+ * Create a new PGlite instance
642
+ * @param dataDir The directory to store the database files
643
+ * Prefix with idb:// to use indexeddb filesystem in the browser
644
+ * Use memory:// to use in-memory filesystem
645
+ * @param options PGlite options
646
+ */
647
+ constructor(dataDir?: string, options?: PGliteOptions);
648
+ /**
649
+ * Create a new PGlite instance
650
+ * @param options PGlite options including the data directory
651
+ */
652
+ constructor(options?: PGliteOptions);
653
+ /**
654
+ * Create a new PGlite instance with extensions on the Typescript interface
655
+ * (The main constructor does enable extensions, however due to the limitations
656
+ * of Typescript, the extensions are not available on the instance interface)
657
+ * @param options PGlite options including the data directory
658
+ * @returns A promise that resolves to the PGlite instance when it's ready.
659
+ */
660
+ static create<O extends PGliteOptions>(options?: O): Promise<PGlite & PGliteInterfaceExtensions<O['extensions']>>;
661
+ /**
662
+ * Create a new PGlite instance with extensions on the Typescript interface
663
+ * (The main constructor does enable extensions, however due to the limitations
664
+ * of Typescript, the extensions are not available on the instance interface)
665
+ * @param dataDir The directory to store the database files
666
+ * Prefix with idb:// to use indexeddb filesystem in the browser
667
+ * Use memory:// to use in-memory filesystem
668
+ * @param options PGlite options
669
+ * @returns A promise that resolves to the PGlite instance when it's ready.
670
+ */
671
+ static create<O extends PGliteOptions>(dataDir?: string, options?: O): Promise<PGlite & PGliteInterfaceExtensions<O['extensions']>>;
672
+ handleExternalCmd(cmd: string, mode: string): number;
673
+ /**
674
+ * The Postgres Emscripten Module
675
+ */
676
+ get Module(): PostgresMod;
677
+ /**
678
+ * The ready state of the database
679
+ */
680
+ get ready(): boolean;
681
+ /**
682
+ * The closed state of the database
683
+ */
684
+ get closed(): boolean;
685
+ /**
686
+ * Close the database
687
+ * @returns A promise that resolves when the database is closed
688
+ */
689
+ close(): Promise<void>;
690
+ /**
691
+ * Close the database when the object exits scope
692
+ * Stage 3 ECMAScript Explicit Resource Management
693
+ * https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management
694
+ */
695
+ [Symbol.asyncDispose](): Promise<void>;
696
+ /**
697
+ * Handle a file attached to the current query
698
+ * @param file The file to handle
699
+ */
700
+ _handleBlob(blob?: File | Blob): Promise<void>;
701
+ /**
702
+ * Cleanup the current file
703
+ */
704
+ _cleanupBlob(): Promise<void>;
705
+ /**
706
+ * Get the written blob from the current query
707
+ * @returns The written blob
708
+ */
709
+ _getWrittenBlob(): Promise<Blob | undefined>;
710
+ /**
711
+ * Wait for the database to be ready
712
+ */
713
+ _checkReady(): Promise<void>;
714
+ /**
715
+ * Execute a postgres wire protocol synchronously
716
+ * @param message The postgres wire protocol message to execute
717
+ * @returns The direct message data response produced by Postgres
718
+ */
719
+ execProtocolRawSync(message: Uint8Array): Uint8Array;
720
+ /**
721
+ * Execute a postgres wire protocol message directly without wrapping the response.
722
+ * Only use if `execProtocol()` doesn't suite your needs.
723
+ *
724
+ * **Warning:** This bypasses PGlite's protocol wrappers that manage error/notice messages,
725
+ * transactions, and notification listeners. Only use if you need to bypass these wrappers and
726
+ * don't intend to use the above features.
727
+ *
728
+ * @param message The postgres wire protocol message to execute
729
+ * @returns The direct message data response produced by Postgres
730
+ */
731
+ execProtocolRaw(message: Uint8Array, {
732
+ syncToFs
733
+ }?: ExecProtocolOptions): Promise<Uint8Array>;
734
+ /**
735
+ * Execute a postgres wire protocol message directly without wrapping the response.
736
+ * Only use if `execProtocol()` doesn't suite your needs.
737
+ *
738
+ * **Warning:** This bypasses PGlite's protocol wrappers that manage error/notice messages,
739
+ * transactions, and notification listeners. Only use if you need to bypass these wrappers and
740
+ * don't intend to use the above features.
741
+ *
742
+ * @param message The postgres wire protocol message to execute
743
+ * @param options.onRawData Callback to receive results as streaming data
744
+ */
745
+ execProtocolRawStream(message: Uint8Array, {
746
+ syncToFs,
747
+ onRawData
748
+ }: ExecProtocolOptionsStream): Promise<void>;
749
+ /**
750
+ * Execute a postgres wire protocol message
751
+ * @param message The postgres wire protocol message to execute
752
+ * @returns The result of the query
753
+ */
754
+ execProtocol(message: Uint8Array, {
755
+ syncToFs,
756
+ throwOnError,
757
+ onNotice
758
+ }?: ExecProtocolOptions): Promise<ExecProtocolResult>;
759
+ /**
760
+ * Execute a postgres wire protocol message
761
+ * @param message The postgres wire protocol message to execute
762
+ * @returns The parsed results of the query
763
+ */
764
+ execProtocolStream(message: Uint8Array, {
765
+ syncToFs,
766
+ throwOnError,
767
+ onNotice
768
+ }?: ExecProtocolOptions): Promise<BackendMessage[]>;
769
+ /**
770
+ * Check if the database is in a transaction
771
+ * @returns True if the database is in a transaction, false otherwise
772
+ */
773
+ isInTransaction(): boolean;
774
+ /**
775
+ * Perform any sync operations implemented by the filesystem, this is
776
+ * run after every query to ensure that the filesystem is synced.
777
+ */
778
+ syncToFs(): Promise<void>;
779
+ /**
780
+ * Listen for a notification
781
+ * @param channel The channel to listen on
782
+ * @param callback The callback to call when a notification is received
783
+ */
784
+ listen(channel: string, callback: (payload: string) => void, tx?: Transaction): Promise<(tx?: Transaction) => Promise<void>>;
785
+ /**
786
+ * Stop listening for a notification
787
+ * @param channel The channel to stop listening on
788
+ * @param callback The callback to remove
789
+ */
790
+ unlisten(channel: string, callback?: (payload: string) => void, tx?: Transaction): Promise<void>;
791
+ /**
792
+ * Listen to notifications
793
+ * @param callback The callback to call when a notification is received
794
+ */
795
+ onNotification(callback: (channel: string, payload: string) => void): () => void;
796
+ /**
797
+ * Stop listening to notifications
798
+ * @param callback The callback to remove
799
+ */
800
+ offNotification(callback: (channel: string, payload: string) => void): void;
801
+ /**
802
+ * Dump the PGDATA dir from the filesystem to a gzipped tarball.
803
+ * @param compression The compression options to use - 'gzip', 'auto', 'none'
804
+ * @returns The tarball as a File object where available, and fallback to a Blob
805
+ */
806
+ dumpDataDir(compression?: DumpTarCompressionOptions): Promise<File | Blob>;
807
+ /**
808
+ * Run a function in a mutex that's exclusive to queries
809
+ * @param fn The query to run
810
+ * @returns The result of the query
811
+ */
812
+ _runExclusiveQuery<T>(fn: () => Promise<T>): Promise<T>;
813
+ /**
814
+ * Run a function in a mutex that's exclusive to transactions
815
+ * @param fn The function to run
816
+ * @returns The result of the function
817
+ */
818
+ _runExclusiveTransaction<T>(fn: () => Promise<T>): Promise<T>;
819
+ clone(): Promise<PGliteInterface>;
820
+ _runExclusiveListen<T>(fn: () => Promise<T>): Promise<T>;
821
+ callMain(args: string[]): number;
822
+ }
823
+ //#endregion
217
824
  //#region ../../src/orm/postgres/providers/PglitePostgresProvider.d.ts
218
825
  interface PgLiteModule {
219
826
  PGlite: typeof PGlite;