@framers/sql-storage-adapter 0.6.13 → 0.6.14
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/README.md +20 -3
- package/dist/adapters/capacitorSqliteAdapter.d.ts +42 -0
- package/dist/adapters/capacitorSqliteAdapter.d.ts.map +1 -1
- package/dist/adapters/capacitorSqliteAdapter.js +139 -21
- package/dist/adapters/capacitorSqliteAdapter.js.map +1 -1
- package/dist/adapters/indexedDbAdapter.d.ts +89 -10
- package/dist/adapters/indexedDbAdapter.d.ts.map +1 -1
- package/dist/adapters/indexedDbAdapter.js +265 -58
- package/dist/adapters/indexedDbAdapter.js.map +1 -1
- package/dist/core/database.d.ts +12 -4
- package/dist/core/database.d.ts.map +1 -1
- package/dist/core/database.js +17 -8
- package/dist/core/database.js.map +1 -1
- package/dist/core/resolver.d.ts +15 -5
- package/dist/core/resolver.d.ts.map +1 -1
- package/dist/core/resolver.js +43 -7
- package/dist/core/resolver.js.map +1 -1
- package/dist/shared/connectionGate.d.ts +32 -9
- package/dist/shared/connectionGate.d.ts.map +1 -1
- package/dist/shared/connectionGate.js +31 -12
- package/dist/shared/connectionGate.js.map +1 -1
- package/dist/shared/postgresTarget.d.ts +10 -0
- package/dist/shared/postgresTarget.d.ts.map +1 -0
- package/dist/shared/postgresTarget.js +13 -0
- package/dist/shared/postgresTarget.js.map +1 -0
- package/package.json +2 -1
package/dist/core/resolver.d.ts
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
import type { StorageAdapter, StorageOpenOptions } from './contracts/index.js';
|
|
2
2
|
import type { AdapterKind } from './contracts/context.js';
|
|
3
3
|
import { type CapacitorAdapterOptions } from '../adapters/capacitorSqliteAdapter.js';
|
|
4
|
+
import { type PostgresAdapterOptions } from '../adapters/postgresAdapter.js';
|
|
4
5
|
import { type IndexedDbAdapterOptions } from '../adapters/indexedDbAdapter.js';
|
|
5
6
|
export type { AdapterKind } from './contracts/context.js';
|
|
6
7
|
export interface StorageResolutionOptions {
|
|
7
8
|
/** Absolute path for sqlite file (used by better-sqlite3/sql.js when persistence is desired). */
|
|
8
9
|
filePath?: string;
|
|
9
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Explicit adapter priority override. The resolver builds `postgres`,
|
|
12
|
+
* `better-sqlite3`, `capacitor`, `indexeddb` and `sqljs`; `memory` builds
|
|
13
|
+
* sql.js, as `sqljs` does. Any other kind (`electron-main`,
|
|
14
|
+
* `electron-renderer`, `supabase`, or an unknown name) fails as a candidate
|
|
15
|
+
* with an error that names it, and the resolver goes on to the next one.
|
|
16
|
+
*/
|
|
10
17
|
priority?: AdapterKind[];
|
|
11
18
|
/** Options passed to the Capacitor adapter. */
|
|
12
19
|
capacitor?: CapacitorAdapterOptions;
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Options passed to the Postgres adapter, all of them: a connection string,
|
|
22
|
+
* or host, port, database, user and password, and the pool, SSL and timeout
|
|
23
|
+
* settings. Without a connection string or a host, database or user here,
|
|
24
|
+
* the connection string comes from DATABASE_URL.
|
|
25
|
+
*/
|
|
26
|
+
postgres?: PostgresAdapterOptions;
|
|
17
27
|
/** Options passed to the IndexedDB adapter (browser persistence). */
|
|
18
28
|
indexedDb?: IndexedDbAdapterOptions;
|
|
19
29
|
/** Options forwarded to adapter.open. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/core/resolver.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,EAAE,cAAc,EAAyB,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE7F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAAgC,KAAK,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/core/resolver.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,EAAE,cAAc,EAAyB,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE7F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAAgC,KAAK,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAChH,OAAO,EAAyB,KAAK,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACjG,OAAO,EAAoB,KAAK,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAI9F,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,WAAW,wBAAwB;IACvC,iGAAiG;IACjG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IACzB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,uBAAuB,CAAC;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,qEAAqE;IACrE,SAAS,CAAC,EAAE,uBAAuB,CAAC;IACpC,yCAAyC;IACzC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,iFAAiF;IACjF,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AA+DD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,aAAmB,wBAAwB,KAAQ,OAAO,CAAC,cAAc,CA6I1G,CAAC"}
|
package/dist/core/resolver.js
CHANGED
|
@@ -42,6 +42,7 @@ import { createSqlJsAdapter } from '../adapters/sqlJsAdapter.js';
|
|
|
42
42
|
import { createCapacitorSqliteAdapter } from '../adapters/capacitorSqliteAdapter.js';
|
|
43
43
|
import { createPostgresAdapter } from '../adapters/postgresAdapter.js';
|
|
44
44
|
import { IndexedDbAdapter } from '../adapters/indexedDbAdapter.js';
|
|
45
|
+
import { isNonEmpty, namesPostgresServer } from '../shared/postgresTarget.js';
|
|
45
46
|
const isCapacitorRuntime = () => {
|
|
46
47
|
if (typeof window === 'undefined') {
|
|
47
48
|
return false;
|
|
@@ -66,13 +67,35 @@ const isElectronRenderer = () => {
|
|
|
66
67
|
Boolean(process.versions?.electron) &&
|
|
67
68
|
process.type === 'renderer';
|
|
68
69
|
};
|
|
70
|
+
/** The error of a candidate the resolver cannot build. */
|
|
71
|
+
const unsupportedKind = (kind) => {
|
|
72
|
+
switch (kind) {
|
|
73
|
+
case 'electron-main':
|
|
74
|
+
return new Error(`The resolver cannot build adapter kind "${kind}". Create it with createElectronMainAdapter from '@framers/sql-storage-adapter/electron'.`);
|
|
75
|
+
case 'electron-renderer':
|
|
76
|
+
return new Error(`The resolver cannot build adapter kind "${kind}". Create it with createElectronRendererAdapter from '@framers/sql-storage-adapter/electron'.`);
|
|
77
|
+
case 'supabase':
|
|
78
|
+
return new Error(`The resolver cannot build adapter kind "${kind}". Use kind "postgres" with the Supabase connection string, or create a SupabaseAdapter.`);
|
|
79
|
+
default:
|
|
80
|
+
return new Error(`Unknown adapter kind "${kind}". The resolver builds postgres, better-sqlite3, capacitor, indexeddb, sqljs and memory.`);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
69
83
|
/**
|
|
70
84
|
* Resolves the most appropriate storage adapter for the current runtime.
|
|
71
85
|
* Tries candidates in the supplied priority order and falls back when one fails.
|
|
72
86
|
*/
|
|
73
87
|
export const resolveStorageAdapter = async (options = {}) => {
|
|
74
88
|
const envOverride = getEnv('STORAGE_ADAPTER');
|
|
75
|
-
const
|
|
89
|
+
const postgresOptions = options.postgres;
|
|
90
|
+
const explicitConnection = postgresOptions?.connectionString;
|
|
91
|
+
// Explicit options that name a server are the target; DATABASE_URL fills in
|
|
92
|
+
// only when they name none.
|
|
93
|
+
const postgresConnection = isNonEmpty(explicitConnection)
|
|
94
|
+
? explicitConnection
|
|
95
|
+
: namesPostgresServer(postgresOptions)
|
|
96
|
+
? undefined
|
|
97
|
+
: getEnv('DATABASE_URL') || undefined;
|
|
98
|
+
const postgresTarget = isNonEmpty(postgresConnection) || namesPostgresServer(postgresOptions);
|
|
76
99
|
const defaultFilePath = isBrowser ? 'db_data/app.sqlite3' : await joinPath([getCwd(), 'db_data', 'app.sqlite3']);
|
|
77
100
|
const filePath = options.filePath ?? defaultFilePath;
|
|
78
101
|
const defaultPriority = (() => {
|
|
@@ -100,7 +123,7 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
100
123
|
if (isCapacitorRuntime()) {
|
|
101
124
|
return ['capacitor', 'indexeddb', 'sqljs'];
|
|
102
125
|
}
|
|
103
|
-
if (
|
|
126
|
+
if (postgresTarget) {
|
|
104
127
|
return ['postgres', 'better-sqlite3', 'indexeddb', 'sqljs'];
|
|
105
128
|
}
|
|
106
129
|
// Browser detection (check for IndexedDB)
|
|
@@ -110,17 +133,21 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
110
133
|
return ['better-sqlite3', 'indexeddb', 'sqljs'];
|
|
111
134
|
})();
|
|
112
135
|
const candidates = defaultPriority.map((name) => {
|
|
136
|
+
// A kind from STORAGE_ADAPTER or a host's list is any string at run time.
|
|
113
137
|
switch (name) {
|
|
114
138
|
case 'postgres': {
|
|
115
139
|
return {
|
|
116
140
|
name,
|
|
117
141
|
factory: async () => {
|
|
118
|
-
if (!
|
|
119
|
-
throw new Error('DATABASE_URL
|
|
142
|
+
if (!postgresTarget) {
|
|
143
|
+
throw new Error('DATABASE_URL, a postgres connection string, or a postgres host, database or user is required.');
|
|
120
144
|
}
|
|
121
|
-
return createPostgresAdapter(
|
|
145
|
+
return createPostgresAdapter({
|
|
146
|
+
...postgresOptions,
|
|
147
|
+
...(postgresConnection ? { connectionString: postgresConnection } : {}),
|
|
148
|
+
});
|
|
122
149
|
},
|
|
123
|
-
openOptions: { connectionString: postgresConnection }
|
|
150
|
+
openOptions: postgresConnection ? { connectionString: postgresConnection } : undefined
|
|
124
151
|
};
|
|
125
152
|
}
|
|
126
153
|
case 'better-sqlite3':
|
|
@@ -150,12 +177,21 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
150
177
|
}
|
|
151
178
|
};
|
|
152
179
|
case 'sqljs':
|
|
153
|
-
|
|
180
|
+
// Not an AdapterKind, but the README lists it and hosts pass it; it builds
|
|
181
|
+
// what it has always built.
|
|
182
|
+
case 'memory':
|
|
154
183
|
return {
|
|
155
184
|
name: 'sqljs',
|
|
156
185
|
factory: async () => createSqlJsAdapter(),
|
|
157
186
|
openOptions: { filePath }
|
|
158
187
|
};
|
|
188
|
+
default:
|
|
189
|
+
return {
|
|
190
|
+
name,
|
|
191
|
+
factory: async () => {
|
|
192
|
+
throw unsupportedKind(name);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
159
195
|
}
|
|
160
196
|
});
|
|
161
197
|
const errors = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../src/core/resolver.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW,CAAC;AAC1F,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,WAAW,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC;AAE1E,6DAA6D;AAC7D,MAAM,QAAQ,GAAG,KAAK,EAAE,KAAe,EAAmB,EAAE;IAC1D,IAAI,SAAS,EAAE,CAAC;QACd,8EAA8E;QAC9E,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACD,wCAAwC;IACxC,IAAI,MAAM,EAAE,CAAC;QACX,IAAI,CAAC;YACH,4DAA4D;YAC5D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;YAClC,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,2BAA2B;YAC3B,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG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AAE,KAAK,IAAI,EAAE;wBAClB,MAAM,eAAe,CAAC,IAAI,CAAC,CAAC;oBAC9B,CAAC;iBACF,CAAC;QACN,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAc,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,KAAK,IAAI,CAAC;IAErC,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE,CAAC;YAC1C,MAAM,WAAW,GAAuB;gBACtC,GAAG,SAAS,CAAC,WAAW;gBACxB,GAAG,OAAO,CAAC,WAAW;aACvB,CAAC;YACF,MAAM,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAChC,IAAI,CAAC,KAAK;gBAAE,OAAO,CAAC,IAAI,CAAC,mCAAmC,SAAS,CAAC,IAAI,IAAI,CAAC,CAAC;YAChF,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,MAAM,GAAG,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACnE,OAAO,CAAC,IAAI,CAAC,oBAAoB,SAAS,CAAC,IAAI,gCAAgC,GAAG,EAAE,CAAC,CAAC;YACxF,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,SAAS;QACX,CAAC;IACH,CAAC;IAED,MAAM,IAAI,sBAAsB,CAAC,kEAAkE,EAAE,MAAM,CAAC,CAAC;AAC/G,CAAC,CAAC"}
|
|
@@ -12,9 +12,11 @@
|
|
|
12
12
|
* callback's handle it carries the transaction's token, so it is admitted
|
|
13
13
|
* whatever async context runs it. Through the adapter itself, from code the
|
|
14
14
|
* callback runs, the callback's async context tells it apart, so the gate needs
|
|
15
|
-
* a context store (Node's AsyncLocalStorage)
|
|
16
|
-
* statement that carries no token at once, which is how the
|
|
17
|
-
* before the gate
|
|
15
|
+
* a context store (Node's AsyncLocalStorage). Without one, the gate either
|
|
16
|
+
* admits every statement that carries no token at once, which is how the
|
|
17
|
+
* adapters behaved before the gate, or makes it wait like any outside caller,
|
|
18
|
+
* so that the handle is the only way into an open transaction: the adapters
|
|
19
|
+
* that run in a browser or a WebView, where there is no context store, wait.
|
|
18
20
|
*
|
|
19
21
|
* This module imports nothing from Node, so browser bundles can include it;
|
|
20
22
|
* the adapter that runs on Node passes the store in.
|
|
@@ -50,22 +52,43 @@ export interface ConnectionGate {
|
|
|
50
52
|
/** Releases the context store when the connection closes. */
|
|
51
53
|
dispose(): void;
|
|
52
54
|
}
|
|
55
|
+
/** How a gate treats a statement that carries no token. */
|
|
56
|
+
export interface ConnectionGateOptions {
|
|
57
|
+
/**
|
|
58
|
+
* When there is no context store: 'admit' runs such a statement at once (the
|
|
59
|
+
* default, how the adapters behaved before the gate); 'wait' holds it until
|
|
60
|
+
* the open transaction ends, so only the transaction's handle reaches it.
|
|
61
|
+
*/
|
|
62
|
+
withoutContext?: 'admit' | 'wait';
|
|
63
|
+
}
|
|
53
64
|
/**
|
|
54
65
|
* Creates the gate of one shared connection.
|
|
55
66
|
*
|
|
56
|
-
* @param context - Node's AsyncLocalStorage, or null where there is none
|
|
57
|
-
*
|
|
67
|
+
* @param context - Node's AsyncLocalStorage, or null where there is none.
|
|
68
|
+
* @param options - What the gate does with a token-less statement when there
|
|
69
|
+
* is no context store.
|
|
58
70
|
*/
|
|
59
|
-
export declare const createConnectionGate: (context: TransactionContextStore | null) => ConnectionGate;
|
|
71
|
+
export declare const createConnectionGate: (context: TransactionContextStore | null, options?: ConnectionGateOptions) => ConnectionGate;
|
|
72
|
+
/** Reports a statement that is still waiting for an open transaction after a while. */
|
|
73
|
+
export interface LongWaitWatch {
|
|
74
|
+
/** How long a statement may wait before `onLongWait` is called. */
|
|
75
|
+
afterMs: number;
|
|
76
|
+
/** Called once per waiting statement that passes `afterMs`. */
|
|
77
|
+
onLongWait: () => void;
|
|
78
|
+
}
|
|
60
79
|
/**
|
|
61
|
-
* Runs `work
|
|
62
|
-
*
|
|
80
|
+
* Runs `work` once the gate admits it. `work` starts the statement: it runs it
|
|
81
|
+
* (a synchronous adapter) or sends it (an asynchronous one), and the last check
|
|
82
|
+
* and that start happen in the same turn, so no transaction can open between
|
|
63
83
|
* them; a caller woken when a transaction ends checks again, since the next
|
|
64
84
|
* transaction may already be open.
|
|
65
85
|
*
|
|
66
86
|
* @param token - The transaction's token when the statement comes through a
|
|
67
87
|
* transaction handle; a handle whose transaction has ended waits like any
|
|
68
88
|
* outside caller.
|
|
89
|
+
* @param watch - Reports a statement that waits long, which is how a callback
|
|
90
|
+
* that issues a statement through the adapter instead of its handle shows
|
|
91
|
+
* on an adapter whose gate makes such statements wait.
|
|
69
92
|
*/
|
|
70
|
-
export declare const whenAdmitted: <T>(gate: ConnectionGate, work: () => T
|
|
93
|
+
export declare const whenAdmitted: <T>(gate: ConnectionGate, work: () => T | PromiseLike<T>, token?: symbol, watch?: LongWaitWatch) => Promise<T>;
|
|
71
94
|
//# sourceMappingURL=connectionGate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectionGate.d.ts","sourceRoot":"","sources":["../../src/shared/connectionGate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"connectionGate.d.ts","sourceRoot":"","sources":["../../src/shared/connectionGate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,4DAA4D;AAC5D,MAAM,WAAW,uBAAuB;IACtC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5C,QAAQ,IAAI,MAAM,GAAG,SAAS,CAAC;IAC/B,0EAA0E;IAC1E,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,qEAAqE;IACrE,MAAM,IAAI,OAAO,CAAC;IAClB,yFAAyF;IACzF,SAAS,IAAI,MAAM,GAAG,IAAI,CAAC;IAC3B,yEAAyE;IACzE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB;;;;;OAKG;IACH,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACzD,6DAA6D;IAC7D,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,2DAA2D;AAC3D,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CACnC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,YACtB,uBAAuB,GAAG,IAAI,YAC9B,qBAAqB,KAC7B,cAgCF,CAAC;AAEF,uFAAuF;AACvF,MAAM,WAAW,aAAa;IAC5B,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,GAAU,CAAC,QAC5B,cAAc,QACd,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,UACtB,MAAM,UACN,aAAa,KACpB,OAAO,CAAC,CAAC,CAYX,CAAC"}
|
|
@@ -12,9 +12,11 @@
|
|
|
12
12
|
* callback's handle it carries the transaction's token, so it is admitted
|
|
13
13
|
* whatever async context runs it. Through the adapter itself, from code the
|
|
14
14
|
* callback runs, the callback's async context tells it apart, so the gate needs
|
|
15
|
-
* a context store (Node's AsyncLocalStorage)
|
|
16
|
-
* statement that carries no token at once, which is how the
|
|
17
|
-
* before the gate
|
|
15
|
+
* a context store (Node's AsyncLocalStorage). Without one, the gate either
|
|
16
|
+
* admits every statement that carries no token at once, which is how the
|
|
17
|
+
* adapters behaved before the gate, or makes it wait like any outside caller,
|
|
18
|
+
* so that the handle is the only way into an open transaction: the adapters
|
|
19
|
+
* that run in a browser or a WebView, where there is no context store, wait.
|
|
18
20
|
*
|
|
19
21
|
* This module imports nothing from Node, so browser bundles can include it;
|
|
20
22
|
* the adapter that runs on Node passes the store in.
|
|
@@ -22,18 +24,22 @@
|
|
|
22
24
|
/**
|
|
23
25
|
* Creates the gate of one shared connection.
|
|
24
26
|
*
|
|
25
|
-
* @param context - Node's AsyncLocalStorage, or null where there is none
|
|
26
|
-
*
|
|
27
|
+
* @param context - Node's AsyncLocalStorage, or null where there is none.
|
|
28
|
+
* @param options - What the gate does with a token-less statement when there
|
|
29
|
+
* is no context store.
|
|
27
30
|
*/
|
|
28
|
-
export const createConnectionGate = (context) => {
|
|
31
|
+
export const createConnectionGate = (context, options = {}) => {
|
|
29
32
|
let open = null;
|
|
33
|
+
const waitWithoutContext = options.withoutContext === 'wait';
|
|
30
34
|
return {
|
|
31
35
|
blocks: (token) => {
|
|
32
36
|
if (open === null)
|
|
33
37
|
return false;
|
|
34
38
|
if (token !== undefined)
|
|
35
39
|
return token !== open.id;
|
|
36
|
-
|
|
40
|
+
if (context === null)
|
|
41
|
+
return waitWithoutContext;
|
|
42
|
+
return context.getStore() !== open.id;
|
|
37
43
|
},
|
|
38
44
|
inside: () => open !== null && context !== null && context.getStore() === open.id,
|
|
39
45
|
openToken: () => open?.id ?? null,
|
|
@@ -59,18 +65,31 @@ export const createConnectionGate = (context) => {
|
|
|
59
65
|
};
|
|
60
66
|
};
|
|
61
67
|
/**
|
|
62
|
-
* Runs `work
|
|
63
|
-
*
|
|
68
|
+
* Runs `work` once the gate admits it. `work` starts the statement: it runs it
|
|
69
|
+
* (a synchronous adapter) or sends it (an asynchronous one), and the last check
|
|
70
|
+
* and that start happen in the same turn, so no transaction can open between
|
|
64
71
|
* them; a caller woken when a transaction ends checks again, since the next
|
|
65
72
|
* transaction may already be open.
|
|
66
73
|
*
|
|
67
74
|
* @param token - The transaction's token when the statement comes through a
|
|
68
75
|
* transaction handle; a handle whose transaction has ended waits like any
|
|
69
76
|
* outside caller.
|
|
77
|
+
* @param watch - Reports a statement that waits long, which is how a callback
|
|
78
|
+
* that issues a statement through the adapter instead of its handle shows
|
|
79
|
+
* on an adapter whose gate makes such statements wait.
|
|
70
80
|
*/
|
|
71
|
-
export const whenAdmitted = async (gate, work, token) => {
|
|
72
|
-
|
|
73
|
-
|
|
81
|
+
export const whenAdmitted = async (gate, work, token, watch) => {
|
|
82
|
+
if (gate.blocks(token)) {
|
|
83
|
+
const timer = watch ? setTimeout(watch.onLongWait, watch.afterMs) : undefined;
|
|
84
|
+
try {
|
|
85
|
+
while (gate.blocks(token)) {
|
|
86
|
+
await gate.ended();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
if (timer !== undefined)
|
|
91
|
+
clearTimeout(timer);
|
|
92
|
+
}
|
|
74
93
|
}
|
|
75
94
|
return work();
|
|
76
95
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectionGate.js","sourceRoot":"","sources":["../../src/shared/connectionGate.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"connectionGate.js","sourceRoot":"","sources":["../../src/shared/connectionGate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AA6CH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,OAAuC,EACvC,UAAiC,EAAE,EACnB,EAAE;IAClB,IAAI,IAAI,GAA+C,IAAI,CAAC;IAC5D,MAAM,kBAAkB,GAAG,OAAO,CAAC,cAAc,KAAK,MAAM,CAAC;IAE7D,OAAO;QACL,MAAM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E,OAAO,EAAE,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAUF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAC/B,IAAoB,EACpB,IAA8B,EAC9B,KAAc,EACd,KAAqB,EACT,EAAE;IACd,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9E,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC1B,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;YACrB,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,IAAI,KAAK,KAAK,SAAS;gBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IACD,OAAO,IAAI,EAAE,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PostgresAdapterOptions } from '../adapters/postgresAdapter.js';
|
|
2
|
+
/** A string with something in it. */
|
|
3
|
+
export declare const isNonEmpty: (value: unknown) => value is string;
|
|
4
|
+
/**
|
|
5
|
+
* Whether Postgres options name a server: a connection string, or a host,
|
|
6
|
+
* database or user. `{ connectionString: process.env.DATABASE_URL }` with
|
|
7
|
+
* DATABASE_URL unset names none.
|
|
8
|
+
*/
|
|
9
|
+
export declare const namesPostgresServer: (options: PostgresAdapterOptions | undefined) => boolean;
|
|
10
|
+
//# sourceMappingURL=postgresTarget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgresTarget.d.ts","sourceRoot":"","sources":["../../src/shared/postgresTarget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE1E,qCAAqC;AACrC,eAAO,MAAM,UAAU,UAAW,OAAO,KAAG,KAAK,IAAI,MAAuD,CAAC;AAE7G;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,YAAa,sBAAsB,GAAG,SAAS,KAAG,OAO/E,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** A string with something in it. */
|
|
2
|
+
export const isNonEmpty = (value) => typeof value === 'string' && value.length > 0;
|
|
3
|
+
/**
|
|
4
|
+
* Whether Postgres options name a server: a connection string, or a host,
|
|
5
|
+
* database or user. `{ connectionString: process.env.DATABASE_URL }` with
|
|
6
|
+
* DATABASE_URL unset names none.
|
|
7
|
+
*/
|
|
8
|
+
export const namesPostgresServer = (options) => Boolean(options &&
|
|
9
|
+
(isNonEmpty(options.connectionString) ||
|
|
10
|
+
isNonEmpty(options.host) ||
|
|
11
|
+
isNonEmpty(options.database) ||
|
|
12
|
+
isNonEmpty(options.user)));
|
|
13
|
+
//# sourceMappingURL=postgresTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgresTarget.js","sourceRoot":"","sources":["../../src/shared/postgresTarget.ts"],"names":[],"mappings":"AAEA,qCAAqC;AACrC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AAE7G;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAA2C,EAAW,EAAE,CAC1F,OAAO,CACL,OAAO;IACL,CAAC,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC;QACnC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC;QACxB,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC5B,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAC9B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@framers/sql-storage-adapter",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.14",
|
|
4
4
|
"description": "Robust cross-platform SQL storage abstraction with automatic fallbacks and runtime detection",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -111,6 +111,7 @@
|
|
|
111
111
|
"@vitest/coverage-v8": "^3.2.7",
|
|
112
112
|
"eslint": "^9.13.0",
|
|
113
113
|
"eslint-config-prettier": "^9.1.0",
|
|
114
|
+
"fake-indexeddb": "^6.2.5",
|
|
114
115
|
"patch-package": "^8.0.0",
|
|
115
116
|
"rimraf": "^5.0.7",
|
|
116
117
|
"semantic-release": "^24.1.0",
|