@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.
- package/dist/adapters/pglite/adapter.d.ts +27 -0
- package/dist/adapters/pglite/adapter.d.ts.map +1 -0
- package/dist/adapters/pglite/index.d.ts +2 -0
- package/dist/adapters/pglite/index.d.ts.map +1 -0
- package/dist/browser/index.js +2443 -0
- package/dist/index.d.ts +10 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2436 -22
- package/dist/node/index.js +2438 -0
- package/dist/ports/database.port.d.ts +49 -53
- package/dist/ports/database.port.d.ts.map +1 -1
- package/dist/ports/index.d.ts +2 -0
- package/dist/ports/index.d.ts.map +1 -0
- package/dist/types/database.types.d.ts +21 -24
- package/dist/types/database.types.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/web/database/migrations.d.ts +8 -6
- package/dist/web/database/migrations.d.ts.map +1 -1
- package/dist/web/database/schema.d.ts +7297 -7302
- package/dist/web/database/schema.d.ts.map +1 -1
- package/dist/web/events/local-pubsub.d.ts +5 -7
- package/dist/web/events/local-pubsub.d.ts.map +1 -1
- package/dist/web/graphql/local-client.d.ts +13 -17
- package/dist/web/graphql/local-client.d.ts.map +1 -1
- package/dist/web/index.d.ts +7 -14
- package/dist/web/index.d.ts.map +1 -1
- package/dist/web/runtime/seeders/index.d.ts +19 -0
- package/dist/web/runtime/seeders/index.d.ts.map +1 -0
- package/dist/web/runtime/services.d.ts +51 -50
- package/dist/web/runtime/services.d.ts.map +1 -1
- package/dist/web/storage/indexeddb.d.ts +16 -19
- package/dist/web/storage/indexeddb.d.ts.map +1 -1
- package/dist/web/utils/id.d.ts +1 -4
- package/dist/web/utils/id.d.ts.map +1 -1
- package/package.json +18 -16
- package/dist/_virtual/_rolldown/runtime.js +0 -18
- package/dist/adapters/pglite/adapter.js +0 -97
- package/dist/adapters/pglite/adapter.js.map +0 -1
- package/dist/adapters/pglite/index.js +0 -3
- package/dist/index.js.map +0 -1
- package/dist/web/database/migrations.js +0 -746
- package/dist/web/database/migrations.js.map +0 -1
- package/dist/web/database/schema.js +0 -528
- package/dist/web/database/schema.js.map +0 -1
- package/dist/web/events/local-pubsub.js +0 -24
- package/dist/web/events/local-pubsub.js.map +0 -1
- package/dist/web/graphql/local-client.js +0 -536
- package/dist/web/graphql/local-client.js.map +0 -1
- package/dist/web/index.js +0 -68
- package/dist/web/index.js.map +0 -1
- package/dist/web/runtime/seeders/index.js +0 -358
- package/dist/web/runtime/seeders/index.js.map +0 -1
- package/dist/web/runtime/services.js +0 -80
- package/dist/web/runtime/services.js.map +0 -1
- package/dist/web/storage/indexeddb.js +0 -85
- package/dist/web/storage/indexeddb.js.map +0 -1
- package/dist/web/utils/id.js +0 -9
- package/dist/web/utils/id.js.map +0 -1
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { DatabaseInitOptions, DbRow, DbValue, Migration, QueryResult, TransactionContext } from
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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","
|
|
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 @@
|
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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","
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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","
|
|
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"}
|