@contractspec/lib.runtime-sandbox 0.11.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 (63) hide show
  1. package/dist/_virtual/rolldown_runtime.js +18 -0
  2. package/dist/adapters/pglite/adapter.js +97 -0
  3. package/dist/adapters/pglite/adapter.js.map +1 -0
  4. package/dist/adapters/pglite/index.js +3 -0
  5. package/dist/index.d.ts +23 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +24 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/ports/database.port.d.ts +70 -0
  10. package/dist/ports/database.port.d.ts.map +1 -0
  11. package/dist/types/database.types.d.ts +47 -0
  12. package/dist/types/database.types.d.ts.map +1 -0
  13. package/dist/web/database/migrations.d.ts +12 -0
  14. package/dist/web/database/migrations.d.ts.map +1 -0
  15. package/dist/web/database/migrations.js +746 -0
  16. package/dist/web/database/migrations.js.map +1 -0
  17. package/dist/web/database/schema.d.ts +7349 -0
  18. package/dist/web/database/schema.d.ts.map +1 -0
  19. package/dist/web/database/schema.js +528 -0
  20. package/dist/web/database/schema.js.map +1 -0
  21. package/dist/web/events/local-pubsub.d.ts +10 -0
  22. package/dist/web/events/local-pubsub.d.ts.map +1 -0
  23. package/dist/web/events/local-pubsub.js +24 -0
  24. package/dist/web/events/local-pubsub.js.map +1 -0
  25. package/dist/web/graphql/local-client.d.ts +20 -0
  26. package/dist/web/graphql/local-client.d.ts.map +1 -0
  27. package/dist/web/graphql/local-client.js +536 -0
  28. package/dist/web/graphql/local-client.js.map +1 -0
  29. package/dist/web/index.d.ts +15 -0
  30. package/dist/web/index.d.ts.map +1 -0
  31. package/dist/web/index.js +68 -0
  32. package/dist/web/index.js.map +1 -0
  33. package/dist/web/runtime/seeders/index.js +358 -0
  34. package/dist/web/runtime/seeders/index.js.map +1 -0
  35. package/dist/web/runtime/services.d.ts +60 -0
  36. package/dist/web/runtime/services.d.ts.map +1 -0
  37. package/dist/web/runtime/services.js +80 -0
  38. package/dist/web/runtime/services.js.map +1 -0
  39. package/dist/web/storage/indexeddb.d.ts +22 -0
  40. package/dist/web/storage/indexeddb.d.ts.map +1 -0
  41. package/dist/web/storage/indexeddb.js +85 -0
  42. package/dist/web/storage/indexeddb.js.map +1 -0
  43. package/dist/web/utils/id.d.ts +5 -0
  44. package/dist/web/utils/id.d.ts.map +1 -0
  45. package/dist/web/utils/id.js +9 -0
  46. package/dist/web/utils/id.js.map +1 -0
  47. package/package.json +70 -0
  48. package/src/adapters/pglite/adapter.ts +152 -0
  49. package/src/adapters/pglite/index.ts +1 -0
  50. package/src/index.ts +41 -0
  51. package/src/ports/database.port.ts +82 -0
  52. package/src/ports/index.ts +4 -0
  53. package/src/types/database.types.ts +55 -0
  54. package/src/types/index.ts +1 -0
  55. package/src/web/database/migrations.ts +760 -0
  56. package/src/web/database/schema.ts +596 -0
  57. package/src/web/events/local-pubsub.ts +28 -0
  58. package/src/web/graphql/local-client.ts +747 -0
  59. package/src/web/index.ts +21 -0
  60. package/src/web/runtime/seeders/index.ts +449 -0
  61. package/src/web/runtime/services.ts +132 -0
  62. package/src/web/storage/indexeddb.ts +116 -0
  63. package/src/web/utils/id.ts +7 -0
@@ -0,0 +1,18 @@
1
+ //#region rolldown:runtime
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, symbols) => {
4
+ let target = {};
5
+ for (var name in all) {
6
+ __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ }
11
+ if (symbols) {
12
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
13
+ }
14
+ return target;
15
+ };
16
+
17
+ //#endregion
18
+ export { __exportAll };
@@ -0,0 +1,97 @@
1
+ import { PGlite } from "@electric-sql/pglite";
2
+
3
+ //#region src/adapters/pglite/adapter.ts
4
+ /**
5
+ * PGLite database adapter for browser sandbox runtime.
6
+ *
7
+ * Uses PGLite (PostgreSQL WASM) for in-browser database operations.
8
+ * Supports in-memory or IndexedDB persistence.
9
+ */
10
+ var PGLiteDatabaseAdapter = class {
11
+ client = null;
12
+ initialized = false;
13
+ async init(options) {
14
+ if (this.initialized) return;
15
+ const dataDir = options?.dataDir;
16
+ this.client = dataDir ? new PGlite(`idb://${dataDir}`) : new PGlite();
17
+ await this.client.waitReady;
18
+ this.initialized = true;
19
+ }
20
+ async close() {
21
+ if (this.client) {
22
+ await this.client.close();
23
+ this.client = null;
24
+ this.initialized = false;
25
+ }
26
+ }
27
+ isInitialized() {
28
+ return this.initialized;
29
+ }
30
+ async query(sql, params) {
31
+ const client = this.getClient();
32
+ const normalizedParams = this.normalizeParams(params);
33
+ const result = await client.query(sql, normalizedParams);
34
+ return {
35
+ rows: result.rows,
36
+ rowCount: result.rows.length
37
+ };
38
+ }
39
+ async execute(sql, params) {
40
+ const client = this.getClient();
41
+ const normalizedParams = this.normalizeParams(params);
42
+ await client.query(sql, normalizedParams);
43
+ }
44
+ async transaction(callback) {
45
+ const client = this.getClient();
46
+ await client.query("BEGIN");
47
+ try {
48
+ const result = await callback({ execute: async (sql, params) => {
49
+ const normalizedParams = this.normalizeParams(params);
50
+ await client.query(sql, normalizedParams);
51
+ } });
52
+ await client.query("COMMIT");
53
+ return result;
54
+ } catch (error) {
55
+ await client.query("ROLLBACK");
56
+ throw error;
57
+ }
58
+ }
59
+ async migrate(migrations) {
60
+ const client = this.getClient();
61
+ await client.query(`
62
+ CREATE TABLE IF NOT EXISTS _sandbox_migrations (
63
+ id TEXT PRIMARY KEY,
64
+ applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
65
+ )
66
+ `);
67
+ for (const migration of migrations) if ((await client.query("SELECT id FROM _sandbox_migrations WHERE id = $1", [migration.id])).rows.length === 0) {
68
+ await client.query(migration.sql);
69
+ await client.query("INSERT INTO _sandbox_migrations (id) VALUES ($1)", [migration.id]);
70
+ }
71
+ }
72
+ async export() {
73
+ this.getClient();
74
+ return new Uint8Array();
75
+ }
76
+ /**
77
+ * Get the initialized PGLite client.
78
+ * Throws if not initialized.
79
+ */
80
+ getClient() {
81
+ if (!this.client || !this.initialized) throw new Error("PGLiteDatabaseAdapter not initialized. Call init() first.");
82
+ return this.client;
83
+ }
84
+ normalizeParams(params) {
85
+ if (!params) return [];
86
+ return params.map((value) => {
87
+ if (typeof value === "boolean") return value;
88
+ if (value instanceof Date) return value.toISOString();
89
+ if (value === void 0) return null;
90
+ return value;
91
+ });
92
+ }
93
+ };
94
+
95
+ //#endregion
96
+ export { PGLiteDatabaseAdapter };
97
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","names":[],"sources":["../../../src/adapters/pglite/adapter.ts"],"sourcesContent":["import { PGlite } from '@electric-sql/pglite';\n\nimport type { DatabasePort } from '../../ports/database.port';\nimport type {\n DatabaseInitOptions,\n DbRow,\n DbValue,\n Migration,\n QueryResult,\n TransactionContext,\n} from '../../types/database.types';\n\n/**\n * PGLite database adapter for browser sandbox runtime.\n *\n * Uses PGLite (PostgreSQL WASM) for in-browser database operations.\n * Supports in-memory or IndexedDB persistence.\n */\nexport class PGLiteDatabaseAdapter implements DatabasePort {\n private client: PGlite | null = null;\n private initialized = false;\n\n async init(options?: DatabaseInitOptions): Promise<void> {\n if (this.initialized) return;\n\n // Create PGLite instance\n // - undefined/empty = in-memory\n // - 'idb://dbname' = IndexedDB persistence\n const dataDir = options?.dataDir;\n this.client = dataDir ? new PGlite(`idb://${dataDir}`) : new PGlite();\n\n // Wait for PGLite to be ready\n await this.client.waitReady;\n this.initialized = true;\n }\n\n async close(): Promise<void> {\n if (this.client) {\n await this.client.close();\n this.client = null;\n this.initialized = false;\n }\n }\n\n isInitialized(): boolean {\n return this.initialized;\n }\n\n async query<T = DbRow>(\n sql: string,\n params?: DbValue[]\n ): Promise<QueryResult<T>> {\n const client = this.getClient();\n const normalizedParams = this.normalizeParams(params);\n const result = await client.query<T>(sql, normalizedParams);\n return {\n rows: result.rows,\n rowCount: result.rows.length,\n };\n }\n\n async execute(sql: string, params?: DbValue[]): Promise<void> {\n const client = this.getClient();\n const normalizedParams = this.normalizeParams(params);\n await client.query(sql, normalizedParams);\n }\n\n async transaction<T>(\n callback: (ctx: TransactionContext) => Promise<T>\n ): Promise<T> {\n const client = this.getClient();\n\n await client.query('BEGIN');\n try {\n const ctx: TransactionContext = {\n execute: async (sql: string, params?: DbValue[]) => {\n const normalizedParams = this.normalizeParams(params);\n await client.query(sql, normalizedParams);\n },\n };\n const result = await callback(ctx);\n await client.query('COMMIT');\n return result;\n } catch (error) {\n await client.query('ROLLBACK');\n throw error;\n }\n }\n\n async migrate(migrations: Migration[]): Promise<void> {\n const client = this.getClient();\n\n // Create migrations tracking table if not exists\n await client.query(`\n CREATE TABLE IF NOT EXISTS _sandbox_migrations (\n id TEXT PRIMARY KEY,\n applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP\n )\n `);\n\n // Apply each migration if not already applied\n for (const migration of migrations) {\n const existing = await client.query<{ id: string }>(\n 'SELECT id FROM _sandbox_migrations WHERE id = $1',\n [migration.id]\n );\n\n if (existing.rows.length === 0) {\n await client.query(migration.sql);\n await client.query('INSERT INTO _sandbox_migrations (id) VALUES ($1)', [\n migration.id,\n ]);\n }\n }\n }\n\n async export(): Promise<Uint8Array> {\n this.getClient(); // Ensure initialized\n // PGLite doesn't support export the same way sql.js does\n // For now, return empty array - can be implemented with pg_dump style later\n return new Uint8Array();\n }\n\n /**\n * Get the initialized PGLite client.\n * Throws if not initialized.\n */\n private getClient(): PGlite {\n if (!this.client || !this.initialized) {\n throw new Error(\n 'PGLiteDatabaseAdapter not initialized. Call init() first.'\n );\n }\n return this.client;\n }\n\n private normalizeParams(params?: DbValue[]): unknown[] {\n if (!params) return [];\n return params.map((value) => {\n if (typeof value === 'boolean') {\n return value;\n }\n if (value instanceof Date) {\n return value.toISOString();\n }\n if (value === undefined) {\n return null;\n }\n return value;\n });\n }\n}\n"],"mappings":";;;;;;;;;AAkBA,IAAa,wBAAb,MAA2D;CACzD,AAAQ,SAAwB;CAChC,AAAQ,cAAc;CAEtB,MAAM,KAAK,SAA8C;AACvD,MAAI,KAAK,YAAa;EAKtB,MAAM,UAAU,SAAS;AACzB,OAAK,SAAS,UAAU,IAAI,OAAO,SAAS,UAAU,GAAG,IAAI,QAAQ;AAGrE,QAAM,KAAK,OAAO;AAClB,OAAK,cAAc;;CAGrB,MAAM,QAAuB;AAC3B,MAAI,KAAK,QAAQ;AACf,SAAM,KAAK,OAAO,OAAO;AACzB,QAAK,SAAS;AACd,QAAK,cAAc;;;CAIvB,gBAAyB;AACvB,SAAO,KAAK;;CAGd,MAAM,MACJ,KACA,QACyB;EACzB,MAAM,SAAS,KAAK,WAAW;EAC/B,MAAM,mBAAmB,KAAK,gBAAgB,OAAO;EACrD,MAAM,SAAS,MAAM,OAAO,MAAS,KAAK,iBAAiB;AAC3D,SAAO;GACL,MAAM,OAAO;GACb,UAAU,OAAO,KAAK;GACvB;;CAGH,MAAM,QAAQ,KAAa,QAAmC;EAC5D,MAAM,SAAS,KAAK,WAAW;EAC/B,MAAM,mBAAmB,KAAK,gBAAgB,OAAO;AACrD,QAAM,OAAO,MAAM,KAAK,iBAAiB;;CAG3C,MAAM,YACJ,UACY;EACZ,MAAM,SAAS,KAAK,WAAW;AAE/B,QAAM,OAAO,MAAM,QAAQ;AAC3B,MAAI;GAOF,MAAM,SAAS,MAAM,SANW,EAC9B,SAAS,OAAO,KAAa,WAAuB;IAClD,MAAM,mBAAmB,KAAK,gBAAgB,OAAO;AACrD,UAAM,OAAO,MAAM,KAAK,iBAAiB;MAE5C,CACiC;AAClC,SAAM,OAAO,MAAM,SAAS;AAC5B,UAAO;WACA,OAAO;AACd,SAAM,OAAO,MAAM,WAAW;AAC9B,SAAM;;;CAIV,MAAM,QAAQ,YAAwC;EACpD,MAAM,SAAS,KAAK,WAAW;AAG/B,QAAM,OAAO,MAAM;;;;;MAKjB;AAGF,OAAK,MAAM,aAAa,WAMtB,MALiB,MAAM,OAAO,MAC5B,oDACA,CAAC,UAAU,GAAG,CACf,EAEY,KAAK,WAAW,GAAG;AAC9B,SAAM,OAAO,MAAM,UAAU,IAAI;AACjC,SAAM,OAAO,MAAM,oDAAoD,CACrE,UAAU,GACX,CAAC;;;CAKR,MAAM,SAA8B;AAClC,OAAK,WAAW;AAGhB,SAAO,IAAI,YAAY;;;;;;CAOzB,AAAQ,YAAoB;AAC1B,MAAI,CAAC,KAAK,UAAU,CAAC,KAAK,YACxB,OAAM,IAAI,MACR,4DACD;AAEH,SAAO,KAAK;;CAGd,AAAQ,gBAAgB,QAA+B;AACrD,MAAI,CAAC,OAAQ,QAAO,EAAE;AACtB,SAAO,OAAO,KAAK,UAAU;AAC3B,OAAI,OAAO,UAAU,UACnB,QAAO;AAET,OAAI,iBAAiB,KACnB,QAAO,MAAM,aAAa;AAE5B,OAAI,UAAU,OACZ,QAAO;AAET,UAAO;IACP"}
@@ -0,0 +1,3 @@
1
+ import { PGLiteDatabaseAdapter } from "./adapter.js";
2
+
3
+ export { PGLiteDatabaseAdapter };
@@ -0,0 +1,23 @@
1
+ import { DatabaseInitOptions, DbRow, DbValue, Migration, QueryResult, TransactionContext } from "./types/database.types.js";
2
+ import { DatabaseAdapterFactory, DatabasePort } from "./ports/database.port.js";
3
+ import { index_d_exports } from "./web/index.js";
4
+
5
+ //#region src/index.d.ts
6
+
7
+ /**
8
+ * Lazy-load the PGLite database adapter.
9
+ *
10
+ * This function dynamically imports PGLite and Drizzle only when called,
11
+ * avoiding bundle bloat for consumers not using the sandbox runtime.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const adapter = await createPGLiteAdapter();
16
+ * await adapter.init();
17
+ * const result = await adapter.query('SELECT * FROM users');
18
+ * ```
19
+ */
20
+ declare function createPGLiteAdapter(): Promise<DatabasePort>;
21
+ //#endregion
22
+ export { type DatabaseAdapterFactory, type DatabaseInitOptions, type DatabasePort, type DbRow, type DbValue, type Migration, type QueryResult, type TransactionContext, createPGLiteAdapter, index_d_exports as web };
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;iBAiCsB,mBAAA,CAAA,GAAuB,QAAJ,YAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ import { web_exports } from "./web/index.js";
2
+
3
+ //#region src/index.ts
4
+ /**
5
+ * Lazy-load the PGLite database adapter.
6
+ *
7
+ * This function dynamically imports PGLite and Drizzle only when called,
8
+ * avoiding bundle bloat for consumers not using the sandbox runtime.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const adapter = await createPGLiteAdapter();
13
+ * await adapter.init();
14
+ * const result = await adapter.query('SELECT * FROM users');
15
+ * ```
16
+ */
17
+ async function createPGLiteAdapter() {
18
+ const { PGLiteDatabaseAdapter } = await import("./adapters/pglite/index.js");
19
+ return new PGLiteDatabaseAdapter();
20
+ }
21
+
22
+ //#endregion
23
+ export { createPGLiteAdapter, web_exports as web };
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @contractspec/lib.runtime-sandbox\n *\n * Sandbox runtime library providing database abstraction for browser environments.\n * Supports lazy-loading of PGLite for bundle optimization.\n */\n\n// Core ports (interfaces)\nexport { type DatabaseAdapterFactory, type DatabasePort } from './ports';\n\n// Types\nexport {\n type DatabaseInitOptions,\n type DbRow,\n type DbValue,\n type Migration,\n type QueryResult,\n type TransactionContext,\n} from './types';\n\n/**\n * Lazy-load the PGLite database adapter.\n *\n * This function dynamically imports PGLite and Drizzle only when called,\n * avoiding bundle bloat for consumers not using the sandbox runtime.\n *\n * @example\n * ```ts\n * const adapter = await createPGLiteAdapter();\n * await adapter.init();\n * const result = await adapter.query('SELECT * FROM users');\n * ```\n */\nexport async function createPGLiteAdapter(): Promise<\n import('./ports').DatabasePort\n> {\n const { PGLiteDatabaseAdapter } = await import('./adapters/pglite');\n return new PGLiteDatabaseAdapter();\n}\n\nexport * as web from './web';\n"],"mappings":";;;;;;;;;;;;;;;;AAiCA,eAAsB,sBAEpB;CACA,MAAM,EAAE,0BAA0B,MAAM,OAAO;AAC/C,QAAO,IAAI,uBAAuB"}
@@ -0,0 +1,70 @@
1
+ import { DatabaseInitOptions, DbRow, DbValue, Migration, QueryResult, TransactionContext } from "../types/database.types.js";
2
+
3
+ //#region src/ports/database.port.d.ts
4
+
5
+ /**
6
+ * Database port interface for sandbox runtime.
7
+ *
8
+ * This interface abstracts the database layer, allowing:
9
+ * - PGLite adapter for browser sandbox
10
+ * - Prisma/Drizzle adapter for production
11
+ * - Mock adapter for testing
12
+ *
13
+ * All implementations must be lazy-loadable to avoid bundle bloat.
14
+ */
15
+ interface DatabasePort {
16
+ /**
17
+ * Initialize the database connection and run migrations.
18
+ */
19
+ init(options?: DatabaseInitOptions): Promise<void>;
20
+ /**
21
+ * Close the database connection and release resources.
22
+ */
23
+ close(): Promise<void>;
24
+ /**
25
+ * Check if the database is initialized.
26
+ */
27
+ isInitialized(): boolean;
28
+ /**
29
+ * Execute a SELECT query and return rows.
30
+ *
31
+ * @param sql - SQL query string with $1, $2, etc. placeholders
32
+ * @param params - Query parameters
33
+ * @returns Query result with typed rows
34
+ */
35
+ query<T = DbRow>(sql: string, params?: DbValue[]): Promise<QueryResult<T>>;
36
+ /**
37
+ * Execute an INSERT/UPDATE/DELETE statement.
38
+ *
39
+ * @param sql - SQL statement with $1, $2, etc. placeholders
40
+ * @param params - Statement parameters
41
+ */
42
+ execute(sql: string, params?: DbValue[]): Promise<void>;
43
+ /**
44
+ * Run a callback within a database transaction.
45
+ * Automatically commits on success, rolls back on error.
46
+ *
47
+ * @param callback - Function to execute within transaction
48
+ * @returns Result of the callback
49
+ */
50
+ transaction<T>(callback: (ctx: TransactionContext) => Promise<T>): Promise<T>;
51
+ /**
52
+ * Run schema migrations.
53
+ *
54
+ * @param migrations - Array of migrations to apply
55
+ */
56
+ migrate(migrations: Migration[]): Promise<void>;
57
+ /**
58
+ * Export the current database state as a binary blob.
59
+ * Useful for backup/restore in browser context.
60
+ */
61
+ export(): Promise<Uint8Array>;
62
+ }
63
+ /**
64
+ * Factory function type for creating database adapters.
65
+ * Used for lazy-loading adapters.
66
+ */
67
+ type DatabaseAdapterFactory = (options?: DatabaseInitOptions) => Promise<DatabasePort>;
68
+ //#endregion
69
+ export { DatabaseAdapterFactory, DatabasePort };
70
+ //# sourceMappingURL=database.port.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.port.d.ts","names":[],"sources":["../../src/ports/database.port.ts"],"sourcesContent":[],"mappings":";;;;;;AAmBA;;;;;;;;AAuBqD,UAvBpC,YAAA,CAuBoC;EAQrB;;;EASgC,IAAA,CAAA,OAAA,CAAA,EApC/C,mBAoC+C,CAAA,EApCzB,OAoCyB,CAAA,IAAA,CAAA;EAAR;;;EAOlC,KAAA,EAAA,EAtCX,OAsCW,CAAA,IAAA,CAAA;EAAc;;;EAMjB,aAAA,EAAA,EAAA,OAAA;EAOP;;;;;;;YArCA,6BAA6B,YAAY,QAAQ,YAAY;;;;;;;gCAQzC,YAAY;;;;;;;;iCASX,uBAAuB,QAAQ,KAAK,QAAQ;;;;;;sBAOvD,cAAc;;;;;YAMxB,QAAQ;;;;;;KAOR,sBAAA,cACA,wBACP,QAAQ"}
@@ -0,0 +1,47 @@
1
+ //#region src/types/database.types.d.ts
2
+ /**
3
+ * Database value types supported by the sandbox runtime
4
+ */
5
+ type DbValue = string | number | boolean | null | Uint8Array | Date | undefined;
6
+ /**
7
+ * Generic row type for database results
8
+ */
9
+ type DbRow = Record<string, DbValue>;
10
+ /**
11
+ * Options for initializing a database adapter
12
+ */
13
+ interface DatabaseInitOptions {
14
+ /**
15
+ * Data directory for persistence (optional).
16
+ * - Browser: uses IndexedDB when specified
17
+ * - Node/Bun: uses file system when specified
18
+ * - If omitted, uses in-memory storage
19
+ */
20
+ dataDir?: string;
21
+ }
22
+ /**
23
+ * Query builder result type
24
+ */
25
+ interface QueryResult<T = DbRow> {
26
+ rows: T[];
27
+ rowCount: number;
28
+ }
29
+ /**
30
+ * Transaction context for atomic operations
31
+ */
32
+ interface TransactionContext {
33
+ /**
34
+ * Execute raw SQL within the transaction
35
+ */
36
+ execute(sql: string, params?: DbValue[]): Promise<void>;
37
+ }
38
+ /**
39
+ * Migration definition
40
+ */
41
+ interface Migration {
42
+ id: string;
43
+ sql: string;
44
+ }
45
+ //#endregion
46
+ export { DatabaseInitOptions, DbRow, DbValue, Migration, QueryResult, TransactionContext };
47
+ //# sourceMappingURL=database.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.types.d.ts","names":[],"sources":["../../src/types/database.types.ts"],"sourcesContent":[],"mappings":";;AAGA;AAYA;AAKiB,KAjBL,OAAA,GAiBK,MAAmB,GAAA,MAAA,GAAA,OAAA,GAAA,IAAA,GAZhC,UAYgC,GAXhC,IAWgC,GAAA,SAAA;AAapC;AAQA;AAUA;KApCY,KAAA,GAAQ,eAAe;;;;UAKlB,mBAAA;;;;;;;;;;;;UAaA,gBAAgB;QACzB;;;;;;UAOS,kBAAA;;;;gCAIe,YAAY;;;;;UAM3B,SAAA"}
@@ -0,0 +1,12 @@
1
+ import { Migration } from "@contractspec/lib.runtime-sandbox";
2
+
3
+ //#region src/web/database/migrations.d.ts
4
+
5
+ /**
6
+ * All migrations for the sandbox runtime database.
7
+ * Each migration should be idempotent (CREATE TABLE IF NOT EXISTS).
8
+ */
9
+ declare const SANDBOX_MIGRATIONS: Migration[];
10
+ //#endregion
11
+ export { SANDBOX_MIGRATIONS };
12
+ //# sourceMappingURL=migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.d.ts","names":[],"sources":["../../../src/web/database/migrations.ts"],"sourcesContent":[],"mappings":";;;;;;;;cAYa,oBAAoB"}