@contractspec/lib.runtime-sandbox 0.12.0 → 0.14.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 (59) hide show
  1. package/dist/adapters/pglite/adapter.d.ts +27 -0
  2. package/dist/adapters/pglite/adapter.d.ts.map +1 -0
  3. package/dist/adapters/pglite/index.d.ts +2 -0
  4. package/dist/adapters/pglite/index.d.ts.map +1 -0
  5. package/dist/browser/index.js +2443 -0
  6. package/dist/index.d.ts +10 -8
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +2436 -22
  9. package/dist/node/index.js +2438 -0
  10. package/dist/ports/database.port.d.ts +49 -53
  11. package/dist/ports/database.port.d.ts.map +1 -1
  12. package/dist/ports/index.d.ts +2 -0
  13. package/dist/ports/index.d.ts.map +1 -0
  14. package/dist/types/database.types.d.ts +21 -24
  15. package/dist/types/database.types.d.ts.map +1 -1
  16. package/dist/types/index.d.ts +2 -0
  17. package/dist/types/index.d.ts.map +1 -0
  18. package/dist/web/database/migrations.d.ts +8 -6
  19. package/dist/web/database/migrations.d.ts.map +1 -1
  20. package/dist/web/database/schema.d.ts +7297 -7302
  21. package/dist/web/database/schema.d.ts.map +1 -1
  22. package/dist/web/events/local-pubsub.d.ts +5 -7
  23. package/dist/web/events/local-pubsub.d.ts.map +1 -1
  24. package/dist/web/graphql/local-client.d.ts +13 -17
  25. package/dist/web/graphql/local-client.d.ts.map +1 -1
  26. package/dist/web/index.d.ts +7 -14
  27. package/dist/web/index.d.ts.map +1 -1
  28. package/dist/web/runtime/seeders/index.d.ts +19 -0
  29. package/dist/web/runtime/seeders/index.d.ts.map +1 -0
  30. package/dist/web/runtime/services.d.ts +51 -50
  31. package/dist/web/runtime/services.d.ts.map +1 -1
  32. package/dist/web/storage/indexeddb.d.ts +16 -19
  33. package/dist/web/storage/indexeddb.d.ts.map +1 -1
  34. package/dist/web/utils/id.d.ts +1 -4
  35. package/dist/web/utils/id.d.ts.map +1 -1
  36. package/package.json +18 -16
  37. package/dist/_virtual/_rolldown/runtime.js +0 -18
  38. package/dist/adapters/pglite/adapter.js +0 -97
  39. package/dist/adapters/pglite/adapter.js.map +0 -1
  40. package/dist/adapters/pglite/index.js +0 -3
  41. package/dist/index.js.map +0 -1
  42. package/dist/web/database/migrations.js +0 -746
  43. package/dist/web/database/migrations.js.map +0 -1
  44. package/dist/web/database/schema.js +0 -528
  45. package/dist/web/database/schema.js.map +0 -1
  46. package/dist/web/events/local-pubsub.js +0 -24
  47. package/dist/web/events/local-pubsub.js.map +0 -1
  48. package/dist/web/graphql/local-client.js +0 -536
  49. package/dist/web/graphql/local-client.js.map +0 -1
  50. package/dist/web/index.js +0 -68
  51. package/dist/web/index.js.map +0 -1
  52. package/dist/web/runtime/seeders/index.js +0 -358
  53. package/dist/web/runtime/seeders/index.js.map +0 -1
  54. package/dist/web/runtime/services.js +0 -80
  55. package/dist/web/runtime/services.js.map +0 -1
  56. package/dist/web/storage/indexeddb.js +0 -85
  57. package/dist/web/storage/indexeddb.js.map +0 -1
  58. package/dist/web/utils/id.js +0 -9
  59. package/dist/web/utils/id.js.map +0 -1
@@ -1,6 +1,4 @@
1
- import { DatabaseInitOptions, DbRow, DbValue, Migration, QueryResult, TransactionContext } from "../types/database.types.js";
2
-
3
- //#region src/ports/database.port.d.ts
1
+ import type { DatabaseInitOptions, DbRow, DbValue, Migration, QueryResult, TransactionContext } from '../types/database.types';
4
2
  /**
5
3
  * Database port interface for sandbox runtime.
6
4
  *
@@ -11,59 +9,57 @@ import { DatabaseInitOptions, DbRow, DbValue, Migration, QueryResult, Transactio
11
9
  *
12
10
  * All implementations must be lazy-loadable to avoid bundle bloat.
13
11
  */
14
- interface DatabasePort {
15
- /**
16
- * Initialize the database connection and run migrations.
17
- */
18
- init(options?: DatabaseInitOptions): Promise<void>;
19
- /**
20
- * Close the database connection and release resources.
21
- */
22
- close(): Promise<void>;
23
- /**
24
- * Check if the database is initialized.
25
- */
26
- isInitialized(): boolean;
27
- /**
28
- * Execute a SELECT query and return rows.
29
- *
30
- * @param sql - SQL query string with $1, $2, etc. placeholders
31
- * @param params - Query parameters
32
- * @returns Query result with typed rows
33
- */
34
- query<T = DbRow>(sql: string, params?: DbValue[]): Promise<QueryResult<T>>;
35
- /**
36
- * Execute an INSERT/UPDATE/DELETE statement.
37
- *
38
- * @param sql - SQL statement with $1, $2, etc. placeholders
39
- * @param params - Statement parameters
40
- */
41
- execute(sql: string, params?: DbValue[]): Promise<void>;
42
- /**
43
- * Run a callback within a database transaction.
44
- * Automatically commits on success, rolls back on error.
45
- *
46
- * @param callback - Function to execute within transaction
47
- * @returns Result of the callback
48
- */
49
- transaction<T>(callback: (ctx: TransactionContext) => Promise<T>): Promise<T>;
50
- /**
51
- * Run schema migrations.
52
- *
53
- * @param migrations - Array of migrations to apply
54
- */
55
- migrate(migrations: Migration[]): Promise<void>;
56
- /**
57
- * Export the current database state as a binary blob.
58
- * Useful for backup/restore in browser context.
59
- */
60
- export(): Promise<Uint8Array>;
12
+ export interface DatabasePort {
13
+ /**
14
+ * Initialize the database connection and run migrations.
15
+ */
16
+ init(options?: DatabaseInitOptions): Promise<void>;
17
+ /**
18
+ * Close the database connection and release resources.
19
+ */
20
+ close(): Promise<void>;
21
+ /**
22
+ * Check if the database is initialized.
23
+ */
24
+ isInitialized(): boolean;
25
+ /**
26
+ * Execute a SELECT query and return rows.
27
+ *
28
+ * @param sql - SQL query string with $1, $2, etc. placeholders
29
+ * @param params - Query parameters
30
+ * @returns Query result with typed rows
31
+ */
32
+ query<T = DbRow>(sql: string, params?: DbValue[]): Promise<QueryResult<T>>;
33
+ /**
34
+ * Execute an INSERT/UPDATE/DELETE statement.
35
+ *
36
+ * @param sql - SQL statement with $1, $2, etc. placeholders
37
+ * @param params - Statement parameters
38
+ */
39
+ execute(sql: string, params?: DbValue[]): Promise<void>;
40
+ /**
41
+ * Run a callback within a database transaction.
42
+ * Automatically commits on success, rolls back on error.
43
+ *
44
+ * @param callback - Function to execute within transaction
45
+ * @returns Result of the callback
46
+ */
47
+ transaction<T>(callback: (ctx: TransactionContext) => Promise<T>): Promise<T>;
48
+ /**
49
+ * Run schema migrations.
50
+ *
51
+ * @param migrations - Array of migrations to apply
52
+ */
53
+ migrate(migrations: Migration[]): Promise<void>;
54
+ /**
55
+ * Export the current database state as a binary blob.
56
+ * Useful for backup/restore in browser context.
57
+ */
58
+ export(): Promise<Uint8Array>;
61
59
  }
62
60
  /**
63
61
  * Factory function type for creating database adapters.
64
62
  * Used for lazy-loading adapters.
65
63
  */
66
- type DatabaseAdapterFactory = (options?: DatabaseInitOptions) => Promise<DatabasePort>;
67
- //#endregion
68
- export { DatabaseAdapterFactory, DatabasePort };
64
+ export type DatabaseAdapterFactory = (options?: DatabaseInitOptions) => Promise<DatabasePort>;
69
65
  //# sourceMappingURL=database.port.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"database.port.d.ts","names":[],"sources":["../../src/ports/database.port.ts"],"mappings":";;;;;AAmBA;;;;;;;;UAAiB,YAAA;EAuB4C;;;EAnB3D,IAAA,CAAK,OAAA,GAAU,mBAAA,GAAsB,OAAA;EAoCN;;;EA/B/B,KAAA,IAAS,OAAA;EA+B0D;;;EA1BnE,aAAA;EAuCU;;;;;;;EA9BV,KAAA,KAAU,KAAA,EAAO,GAAA,UAAa,MAAA,GAAS,OAAA,KAAY,OAAA,CAAQ,WAAA,CAAY,CAAA;EAd9D;;;;;;EAsBT,OAAA,CAAQ,GAAA,UAAa,MAAA,GAAS,OAAA,KAAY,OAAA;EARZ;;;;;;;EAiB9B,WAAA,IAAe,QAAA,GAAW,GAAA,EAAK,kBAAA,KAAuB,OAAA,CAAQ,CAAA,IAAK,OAAA,CAAQ,CAAA;EATjC;;;;;EAgB1C,OAAA,CAAQ,UAAA,EAAY,SAAA,KAAc,OAAA;EAP4B;;;;EAa9D,MAAA,IAAU,OAAA,CAAQ,UAAA;AAAA;;;;;KAOR,sBAAA,IACV,OAAA,GAAU,mBAAA,KACP,OAAA,CAAQ,YAAA"}
1
+ {"version":3,"file":"database.port.d.ts","sourceRoot":"","sources":["../../src/ports/database.port.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,KAAK,EACL,OAAO,EACP,SAAS,EACT,WAAW,EACX,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AAEjC;;;;;;;;;GASG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnD;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;OAEG;IACH,aAAa,IAAI,OAAO,CAAC;IAEzB;;;;;;OAMG;IACH,KAAK,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3E;;;;;OAKG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD;;;;;;OAMG;IACH,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAE9E;;;;OAIG;IACH,OAAO,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhD;;;OAGG;IACH,MAAM,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,CACnC,OAAO,CAAC,EAAE,mBAAmB,KAC1B,OAAO,CAAC,YAAY,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { type DatabaseAdapterFactory, type DatabasePort, } from './database.port';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ports/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,YAAY,GAClB,MAAM,iBAAiB,CAAC"}
@@ -1,47 +1,44 @@
1
- //#region src/types/database.types.d.ts
2
1
  /**
3
2
  * Database value types supported by the sandbox runtime
4
3
  */
5
- type DbValue = string | number | boolean | null | Uint8Array | Date | undefined;
4
+ export type DbValue = string | number | boolean | null | Uint8Array | Date | undefined;
6
5
  /**
7
6
  * Generic row type for database results
8
7
  */
9
- type DbRow = Record<string, DbValue>;
8
+ export type DbRow = Record<string, DbValue>;
10
9
  /**
11
10
  * Options for initializing a database adapter
12
11
  */
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;
12
+ export interface DatabaseInitOptions {
13
+ /**
14
+ * Data directory for persistence (optional).
15
+ * - Browser: uses IndexedDB when specified
16
+ * - Node/Bun: uses file system when specified
17
+ * - If omitted, uses in-memory storage
18
+ */
19
+ dataDir?: string;
21
20
  }
22
21
  /**
23
22
  * Query builder result type
24
23
  */
25
- interface QueryResult<T = DbRow> {
26
- rows: T[];
27
- rowCount: number;
24
+ export interface QueryResult<T = DbRow> {
25
+ rows: T[];
26
+ rowCount: number;
28
27
  }
29
28
  /**
30
29
  * Transaction context for atomic operations
31
30
  */
32
- interface TransactionContext {
33
- /**
34
- * Execute raw SQL within the transaction
35
- */
36
- execute(sql: string, params?: DbValue[]): Promise<void>;
31
+ export interface TransactionContext {
32
+ /**
33
+ * Execute raw SQL within the transaction
34
+ */
35
+ execute(sql: string, params?: DbValue[]): Promise<void>;
37
36
  }
38
37
  /**
39
38
  * Migration definition
40
39
  */
41
- interface Migration {
42
- id: string;
43
- sql: string;
40
+ export interface Migration {
41
+ id: string;
42
+ sql: string;
44
43
  }
45
- //#endregion
46
- export { DatabaseInitOptions, DbRow, DbValue, Migration, QueryResult, TransactionContext };
47
44
  //# sourceMappingURL=database.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"database.types.d.ts","names":[],"sources":["../../src/types/database.types.ts"],"mappings":";;AAGA;;KAAY,OAAA,sCAKR,UAAA,GACA,IAAA;;;AAMJ;KAAY,KAAA,GAAQ,MAAA,SAAe,OAAA;;;;UAKlB,mBAAA;EAAmB;;;;AAapC;;EANE,OAAA;AAAA;;;;UAMe,WAAA,KAAgB,KAAA;EAC/B,IAAA,EAAM,CAAA;EACN,QAAA;AAAA;AAMF;;;AAAA,UAAiB,kBAAA;EAIf;;;EAAA,OAAA,CAAQ,GAAA,UAAa,MAAA,GAAS,OAAA,KAAY,OAAA;AAAA;;;AAM5C;UAAiB,SAAA;EACf,EAAA;EACA,GAAA;AAAA"}
1
+ {"version":3,"file":"database.types.d.ts","sourceRoot":"","sources":["../../src/types/database.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,OAAO,GACf,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,UAAU,GACV,IAAI,GACJ,SAAS,CAAC;AAEd;;GAEG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,KAAK;IACpC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACb"}
@@ -0,0 +1,2 @@
1
+ export * from './database.types';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
@@ -1,11 +1,13 @@
1
- import { Migration } from "@contractspec/lib.runtime-sandbox";
2
-
3
- //#region src/web/database/migrations.d.ts
1
+ /**
2
+ * Schema migrations for PGLite sandbox runtime.
3
+ *
4
+ * These migrations create all tables defined in schema.ts.
5
+ * Using raw SQL for migrations to work with DatabasePort interface.
6
+ */
7
+ import type { Migration } from '@contractspec/lib.runtime-sandbox';
4
8
  /**
5
9
  * All migrations for the sandbox runtime database.
6
10
  * Each migration should be idempotent (CREATE TABLE IF NOT EXISTS).
7
11
  */
8
- declare const SANDBOX_MIGRATIONS: Migration[];
9
- //#endregion
10
- export { SANDBOX_MIGRATIONS };
12
+ export declare const SANDBOX_MIGRATIONS: Migration[];
11
13
  //# sourceMappingURL=migrations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.d.ts","names":[],"sources":["../../../src/web/database/migrations.ts"],"mappings":";;;;;;;cAYa,kBAAA,EAAoB,SAAA"}
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../src/web/database/migrations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAEnE;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAAS,EA2uBzC,CAAC"}