@framers/sql-storage-adapter 0.6.13 → 0.6.15
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 +70 -38
- 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/adapters/postgresAdapter.d.ts +83 -5
- package/dist/adapters/postgresAdapter.d.ts.map +1 -1
- package/dist/adapters/postgresAdapter.js +285 -18
- package/dist/adapters/postgresAdapter.js.map +1 -1
- package/dist/core/database.d.ts +37 -8
- package/dist/core/database.d.ts.map +1 -1
- package/dist/core/database.js +48 -11
- package/dist/core/database.js.map +1 -1
- package/dist/core/resolver.d.ts +34 -5
- package/dist/core/resolver.d.ts.map +1 -1
- package/dist/core/resolver.js +59 -9
- 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/database.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - connectDatabase() - Explicit connection with clear options
|
|
7
7
|
* - openDatabase() - Simple file-based database
|
|
8
8
|
*/
|
|
9
|
-
import type
|
|
9
|
+
import { type StorageAdapter } from './contracts/index.js';
|
|
10
10
|
import { type AdapterKind } from './resolver.js';
|
|
11
11
|
import type { PostgresAdapterOptions } from '../adapters/postgresAdapter.js';
|
|
12
12
|
import type { CapacitorAdapterOptions } from '../adapters/capacitorSqliteAdapter.js';
|
|
@@ -17,7 +17,8 @@ import type { IndexedDbAdapterOptions } from '../adapters/indexedDbAdapter.js';
|
|
|
17
17
|
export interface DatabaseOptions {
|
|
18
18
|
/**
|
|
19
19
|
* Database URL (e.g., postgresql://user:pass@host/db).
|
|
20
|
-
* If provided, PostgreSQL
|
|
20
|
+
* If provided, PostgreSQL is used on Node, with no fallback to SQLite,
|
|
21
|
+
* unless `priority` or `type` says otherwise.
|
|
21
22
|
*/
|
|
22
23
|
url?: string;
|
|
23
24
|
/**
|
|
@@ -26,8 +27,11 @@ export interface DatabaseOptions {
|
|
|
26
27
|
*/
|
|
27
28
|
file?: string;
|
|
28
29
|
/**
|
|
29
|
-
* PostgreSQL-specific configuration.
|
|
30
|
-
*
|
|
30
|
+
* PostgreSQL-specific configuration, passed on to the Postgres adapter whole.
|
|
31
|
+
* When it names a server (a connection string, or a host, database or user),
|
|
32
|
+
* PostgreSQL is used on Node, with no fallback to SQLite, unless `priority`
|
|
33
|
+
* or `type` says otherwise. `{ connectionString: process.env.DATABASE_URL }`
|
|
34
|
+
* with DATABASE_URL unset names none, and the local default is used.
|
|
31
35
|
*/
|
|
32
36
|
postgres?: PostgresAdapterOptions;
|
|
33
37
|
/**
|
|
@@ -63,6 +67,20 @@ export interface DatabaseOptions {
|
|
|
63
67
|
* Advanced: Only use if you need fine-grained control.
|
|
64
68
|
*/
|
|
65
69
|
priority?: AdapterKind[];
|
|
70
|
+
/**
|
|
71
|
+
* Strict resolution, for servers: no local database stands in for a
|
|
72
|
+
* Postgres the options configure. Default: false.
|
|
73
|
+
*
|
|
74
|
+
* - A `url` or `postgres` option that names no server (an empty or unset
|
|
75
|
+
* connection string and no host, database or user) fails on Node instead
|
|
76
|
+
* of opening the local default, unless `file` is given.
|
|
77
|
+
* - A postgres candidate that fails ends resolution with an error, whatever
|
|
78
|
+
* `priority` lists after it.
|
|
79
|
+
*
|
|
80
|
+
* `DATABASE_URL` in the environment does not count here, strict or not.
|
|
81
|
+
* See `StorageResolutionOptions.strict` for the resolver's side.
|
|
82
|
+
*/
|
|
83
|
+
strict?: boolean;
|
|
66
84
|
}
|
|
67
85
|
/**
|
|
68
86
|
* Create a database connection.
|
|
@@ -70,12 +88,15 @@ export interface DatabaseOptions {
|
|
|
70
88
|
*
|
|
71
89
|
* @example
|
|
72
90
|
* ```typescript
|
|
73
|
-
* //
|
|
91
|
+
* // The local default: better-sqlite3 (sql.js without it) on Node, sql.js in a
|
|
92
|
+
* // browser. DATABASE_URL in the environment does not change it.
|
|
74
93
|
* const db = await createDatabase();
|
|
75
94
|
*
|
|
76
|
-
* //
|
|
95
|
+
* // PostgreSQL from DATABASE_URL on a server; strict fails when it is unset
|
|
96
|
+
* // instead of opening a local file
|
|
77
97
|
* const db = await createDatabase({
|
|
78
|
-
* url: process.env.DATABASE_URL
|
|
98
|
+
* url: process.env.DATABASE_URL,
|
|
99
|
+
* strict: true
|
|
79
100
|
* });
|
|
80
101
|
*
|
|
81
102
|
* // Specify file path
|
|
@@ -103,7 +124,15 @@ export interface DatabaseOptions {
|
|
|
103
124
|
* 2. Explicit `options.type` is mapped to a single adapter priority.
|
|
104
125
|
* 3. Otherwise we auto-detect environment:
|
|
105
126
|
* - Browser / Deno: ['sqljs']
|
|
106
|
-
* - Node.js
|
|
127
|
+
* - Node.js with a Postgres URL, or Postgres options that name a server:
|
|
128
|
+
* ['postgres']. There is no fallback to SQLite: data meant for Postgres
|
|
129
|
+
* would land in a local file. DATABASE_URL in the environment does not
|
|
130
|
+
* count here.
|
|
131
|
+
* - Node.js otherwise: ['better-sqlite3', 'sqljs'] (native first, wasm fallback)
|
|
132
|
+
*
|
|
133
|
+
* With `strict` on Node, a `url` or `postgres` option that names no server
|
|
134
|
+
* throws instead of choosing the local default (unless `file` is given), and a
|
|
135
|
+
* postgres candidate that fails ends resolution.
|
|
107
136
|
*
|
|
108
137
|
* The function never throws solely due to a native adapter absence; it falls
|
|
109
138
|
* back to next candidates. Only when no candidate can open will it bubble an error.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/core/database.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/core/database.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAA0B,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAwD,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAEpG,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAa5E;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAElC;;;OAGG;IACH,MAAM,CAAC,EAAE,uBAAuB,CAAC;IAEjC;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,EAAE,uBAAuB,CAAC;IAEpC;;;OAGG;IACH,IAAI,CAAC,EAAE,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAE/D;;;OAGG;IACH,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAC;IAEzB;;;;;;;;;;;;OAYG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,cAAc,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,cAAc,CAAC,CAkF3F;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,GAAG,sBAAsB,GACtC,OAAO,CAAC,cAAc,CAAC,CAKzB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAE5E;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,cAAc,CAAC,CAEpE;AAGD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/core/database.js
CHANGED
|
@@ -6,19 +6,36 @@
|
|
|
6
6
|
* - connectDatabase() - Explicit connection with clear options
|
|
7
7
|
* - openDatabase() - Simple file-based database
|
|
8
8
|
*/
|
|
9
|
+
import { StorageResolutionError } from './contracts/index.js';
|
|
9
10
|
import { resolveStorageAdapter } from './resolver.js';
|
|
11
|
+
import { namesPostgresServer } from '../shared/postgresTarget.js';
|
|
12
|
+
/**
|
|
13
|
+
* The options that configure Postgres: `url` when the caller set the key, even
|
|
14
|
+
* to undefined (`{ url: process.env.DATABASE_URL }`), and `postgres`.
|
|
15
|
+
*/
|
|
16
|
+
const configuredPostgresOptions = (options) => {
|
|
17
|
+
const named = [];
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(options, 'url'))
|
|
19
|
+
named.push('url');
|
|
20
|
+
if (options.postgres !== undefined)
|
|
21
|
+
named.push('postgres');
|
|
22
|
+
return named;
|
|
23
|
+
};
|
|
10
24
|
/**
|
|
11
25
|
* Create a database connection.
|
|
12
26
|
* Automatically picks the best database for your environment.
|
|
13
27
|
*
|
|
14
28
|
* @example
|
|
15
29
|
* ```typescript
|
|
16
|
-
* //
|
|
30
|
+
* // The local default: better-sqlite3 (sql.js without it) on Node, sql.js in a
|
|
31
|
+
* // browser. DATABASE_URL in the environment does not change it.
|
|
17
32
|
* const db = await createDatabase();
|
|
18
33
|
*
|
|
19
|
-
* //
|
|
34
|
+
* // PostgreSQL from DATABASE_URL on a server; strict fails when it is unset
|
|
35
|
+
* // instead of opening a local file
|
|
20
36
|
* const db = await createDatabase({
|
|
21
|
-
* url: process.env.DATABASE_URL
|
|
37
|
+
* url: process.env.DATABASE_URL,
|
|
38
|
+
* strict: true
|
|
22
39
|
* });
|
|
23
40
|
*
|
|
24
41
|
* // Specify file path
|
|
@@ -46,7 +63,15 @@ import { resolveStorageAdapter } from './resolver.js';
|
|
|
46
63
|
* 2. Explicit `options.type` is mapped to a single adapter priority.
|
|
47
64
|
* 3. Otherwise we auto-detect environment:
|
|
48
65
|
* - Browser / Deno: ['sqljs']
|
|
49
|
-
* - Node.js
|
|
66
|
+
* - Node.js with a Postgres URL, or Postgres options that name a server:
|
|
67
|
+
* ['postgres']. There is no fallback to SQLite: data meant for Postgres
|
|
68
|
+
* would land in a local file. DATABASE_URL in the environment does not
|
|
69
|
+
* count here.
|
|
70
|
+
* - Node.js otherwise: ['better-sqlite3', 'sqljs'] (native first, wasm fallback)
|
|
71
|
+
*
|
|
72
|
+
* With `strict` on Node, a `url` or `postgres` option that names no server
|
|
73
|
+
* throws instead of choosing the local default (unless `file` is given), and a
|
|
74
|
+
* postgres candidate that fails ends resolution.
|
|
50
75
|
*
|
|
51
76
|
* The function never throws solely due to a native adapter absence; it falls
|
|
52
77
|
* back to next candidates. Only when no candidate can open will it bubble an error.
|
|
@@ -59,13 +84,13 @@ export async function createDatabase(options = {}) {
|
|
|
59
84
|
// (declare loosely to prevent dependency on @types/deno)
|
|
60
85
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
86
|
const isDeno = typeof globalThis.Deno !== 'undefined';
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
87
|
+
// PostgreSQL: the options pass on whole; the URL fills in a connection
|
|
88
|
+
// string they do not give.
|
|
89
|
+
if (options.url || options.postgres) {
|
|
90
|
+
resolverOptions.postgres = {
|
|
91
|
+
...options.postgres,
|
|
92
|
+
connectionString: options.postgres?.connectionString || options.url || undefined,
|
|
93
|
+
};
|
|
69
94
|
}
|
|
70
95
|
// Handle file path
|
|
71
96
|
if (options.file) {
|
|
@@ -97,11 +122,23 @@ export async function createDatabase(options = {}) {
|
|
|
97
122
|
if (options.priority) {
|
|
98
123
|
resolverOptions.priority = options.priority;
|
|
99
124
|
}
|
|
125
|
+
if (options.strict) {
|
|
126
|
+
resolverOptions.strict = true;
|
|
127
|
+
}
|
|
100
128
|
// Auto-detect environment ONLY if no priority already set
|
|
101
129
|
if (!resolverOptions.priority || resolverOptions.priority.length === 0) {
|
|
102
130
|
if (isBrowser || isDeno) {
|
|
131
|
+
// A browser cannot reach PostgreSQL, so a URL here changes nothing.
|
|
103
132
|
resolverOptions.priority = ['sqljs'];
|
|
104
133
|
}
|
|
134
|
+
else if (isNode && namesPostgresServer(resolverOptions.postgres)) {
|
|
135
|
+
resolverOptions.priority = ['postgres'];
|
|
136
|
+
}
|
|
137
|
+
else if (isNode && options.strict && !options.file && configuredPostgresOptions(options).length > 0) {
|
|
138
|
+
const named = configuredPostgresOptions(options);
|
|
139
|
+
throw new StorageResolutionError(`[StorageAdapter] Strict resolution: the ${named.join(' and ')} option${named.length > 1 ? 's name' : ' names'} no server. ` +
|
|
140
|
+
'Give a connection string, or a host, database or user, or pass file to open a local database.');
|
|
141
|
+
}
|
|
105
142
|
else if (isNode) {
|
|
106
143
|
resolverOptions.priority = ['better-sqlite3', 'sqljs'];
|
|
107
144
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/core/database.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/core/database.ts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AAM,EAAE,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,cAAc,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,QAAgB;IACjD,OAAO,cAAc,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,OAAO,YAAY,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC;AAED,wCAAwC;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/core/resolver.d.ts
CHANGED
|
@@ -1,25 +1,54 @@
|
|
|
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. */
|
|
20
30
|
openOptions?: StorageOpenOptions;
|
|
21
31
|
/** Suppress fallback chain logs (adapter not-found warnings). Default: false. */
|
|
22
32
|
quiet?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Strict resolution, for servers: only the database the options name opens.
|
|
35
|
+
* Default: false.
|
|
36
|
+
*
|
|
37
|
+
* - The postgres candidate is the last one tried. When it fails to open,
|
|
38
|
+
* resolution throws a `StorageResolutionError` instead of trying a local
|
|
39
|
+
* SQLite database, whatever `priority` lists after it.
|
|
40
|
+
* - A Postgres server named by `postgres` or `DATABASE_URL`, with no
|
|
41
|
+
* `priority`, makes `['postgres']` the whole list.
|
|
42
|
+
* - An explicit `filePath` outranks `DATABASE_URL`: with a `filePath` and no
|
|
43
|
+
* `postgres` options that name a server, `DATABASE_URL` is not read.
|
|
44
|
+
* - `postgres` options that name no server, with no `DATABASE_URL` to fill
|
|
45
|
+
* in and no `filePath`, fail instead of opening the local default.
|
|
46
|
+
*
|
|
47
|
+
* Without `strict`, a postgres candidate that fails falls through to the
|
|
48
|
+
* next candidate, and `DATABASE_URL` puts Postgres first even when a
|
|
49
|
+
* `filePath` is given.
|
|
50
|
+
*/
|
|
51
|
+
strict?: boolean;
|
|
23
52
|
}
|
|
24
53
|
/**
|
|
25
54
|
* Resolves the most appropriate storage adapter for the current runtime.
|
|
@@ -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;IAChB;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AA+DD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,aAAmB,wBAAwB,KAAQ,OAAO,CAAC,cAAc,CAgK1G,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,38 @@ 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 strict = options.strict === true;
|
|
90
|
+
const postgresOptions = options.postgres;
|
|
91
|
+
const explicitConnection = postgresOptions?.connectionString;
|
|
92
|
+
// In strict resolution an explicit file path outranks DATABASE_URL.
|
|
93
|
+
const fileOutranksEnv = strict && isNonEmpty(options.filePath);
|
|
94
|
+
// Explicit options that name a server are the target; DATABASE_URL fills in
|
|
95
|
+
// only when they name none.
|
|
96
|
+
const postgresConnection = isNonEmpty(explicitConnection)
|
|
97
|
+
? explicitConnection
|
|
98
|
+
: namesPostgresServer(postgresOptions) || fileOutranksEnv
|
|
99
|
+
? undefined
|
|
100
|
+
: getEnv('DATABASE_URL') || undefined;
|
|
101
|
+
const postgresTarget = isNonEmpty(postgresConnection) || namesPostgresServer(postgresOptions);
|
|
76
102
|
const defaultFilePath = isBrowser ? 'db_data/app.sqlite3' : await joinPath([getCwd(), 'db_data', 'app.sqlite3']);
|
|
77
103
|
const filePath = options.filePath ?? defaultFilePath;
|
|
78
104
|
const defaultPriority = (() => {
|
|
@@ -100,8 +126,13 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
100
126
|
if (isCapacitorRuntime()) {
|
|
101
127
|
return ['capacitor', 'indexeddb', 'sqljs'];
|
|
102
128
|
}
|
|
103
|
-
if (
|
|
104
|
-
return ['postgres', 'better-sqlite3', 'indexeddb', 'sqljs'];
|
|
129
|
+
if (postgresTarget) {
|
|
130
|
+
return strict ? ['postgres'] : ['postgres', 'better-sqlite3', 'indexeddb', 'sqljs'];
|
|
131
|
+
}
|
|
132
|
+
if (strict && postgresOptions !== undefined && !isNonEmpty(options.filePath)) {
|
|
133
|
+
// Postgres is configured but names no server: the postgres candidate
|
|
134
|
+
// fails with the reason, where the local default would hide it.
|
|
135
|
+
return ['postgres'];
|
|
105
136
|
}
|
|
106
137
|
// Browser detection (check for IndexedDB)
|
|
107
138
|
if (typeof window !== 'undefined' && window.indexedDB) {
|
|
@@ -110,17 +141,23 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
110
141
|
return ['better-sqlite3', 'indexeddb', 'sqljs'];
|
|
111
142
|
})();
|
|
112
143
|
const candidates = defaultPriority.map((name) => {
|
|
144
|
+
// A kind from STORAGE_ADAPTER or a host's list is any string at run time.
|
|
113
145
|
switch (name) {
|
|
114
146
|
case 'postgres': {
|
|
115
147
|
return {
|
|
116
148
|
name,
|
|
117
149
|
factory: async () => {
|
|
118
|
-
if (!
|
|
119
|
-
throw new Error(
|
|
150
|
+
if (!postgresTarget) {
|
|
151
|
+
throw new Error(fileOutranksEnv
|
|
152
|
+
? 'A postgres connection string, or a postgres host, database or user is required. Strict resolution does not read DATABASE_URL when a filePath is given.'
|
|
153
|
+
: 'DATABASE_URL, a postgres connection string, or a postgres host, database or user is required.');
|
|
120
154
|
}
|
|
121
|
-
return createPostgresAdapter(
|
|
155
|
+
return createPostgresAdapter({
|
|
156
|
+
...postgresOptions,
|
|
157
|
+
...(postgresConnection ? { connectionString: postgresConnection } : {}),
|
|
158
|
+
});
|
|
122
159
|
},
|
|
123
|
-
openOptions: { connectionString: postgresConnection }
|
|
160
|
+
openOptions: postgresConnection ? { connectionString: postgresConnection } : undefined
|
|
124
161
|
};
|
|
125
162
|
}
|
|
126
163
|
case 'better-sqlite3':
|
|
@@ -150,12 +187,21 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
150
187
|
}
|
|
151
188
|
};
|
|
152
189
|
case 'sqljs':
|
|
153
|
-
|
|
190
|
+
// Not an AdapterKind, but the README lists it and hosts pass it; it builds
|
|
191
|
+
// what it has always built.
|
|
192
|
+
case 'memory':
|
|
154
193
|
return {
|
|
155
194
|
name: 'sqljs',
|
|
156
195
|
factory: async () => createSqlJsAdapter(),
|
|
157
196
|
openOptions: { filePath }
|
|
158
197
|
};
|
|
198
|
+
default:
|
|
199
|
+
return {
|
|
200
|
+
name,
|
|
201
|
+
factory: async () => {
|
|
202
|
+
throw unsupportedKind(name);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
159
205
|
}
|
|
160
206
|
});
|
|
161
207
|
const errors = [];
|
|
@@ -173,11 +219,15 @@ export const resolveStorageAdapter = async (options = {}) => {
|
|
|
173
219
|
return adapter;
|
|
174
220
|
}
|
|
175
221
|
catch (error) {
|
|
222
|
+
errors.push(error);
|
|
223
|
+
if (strict && candidate.name === 'postgres') {
|
|
224
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
225
|
+
throw new StorageResolutionError(`PostgreSQL could not be opened, and strict resolution does not fall back to a local database. ${msg}`, errors);
|
|
226
|
+
}
|
|
176
227
|
if (!quiet) {
|
|
177
228
|
const msg = error instanceof Error ? error.message : String(error);
|
|
178
229
|
console.warn(`[StorageAdapter] ${candidate.name} not available, trying next. ${msg}`);
|
|
179
230
|
}
|
|
180
|
-
errors.push(error);
|
|
181
231
|
continue;
|
|
182
232
|
}
|
|
183
233
|
}
|
|
@@ -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;YAC5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AS,CAAC,IAAI,IAAI,CAAC,CAAC;YAChF,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,IAAI,MAAM,IAAI,SAAS,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBAC5C,MAAM,GAAG,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACnE,MAAM,IAAI,sBAAsB,CAC9B,iGAAiG,GAAG,EAAE,EACtG,MAAM,CACP,CAAC;YACJ,CAAC;YACD,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,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,EAAE,CAAC,KAAK,EAAE,EAAE;YAChB,IAAI,IAAI,KAAK,IAAI;gBAAE,OAAO,KAAK,CAAC;YAChC,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO,KAAK,KAAK,IAAI,CAAC,EAAE,CAAC;YAClD,IAAI,OAAO,KAAK,IAAI;gBAAE,OAAO,kBAAkB,CAAC;YAChD,OAAO,OAAO,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,EAAE,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C,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"}
|