@stonyx/orm 0.3.2-alpha.11 → 0.3.2-alpha.13
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 +1 -1
- package/dist/dynamodb/connection.d.ts +6 -4
- package/dist/dynamodb/connection.js +4 -4
- package/dist/postgres/connection.d.ts +1 -0
- package/dist/postgres/connection.js +8 -6
- package/package.json +3 -2
- package/src/dynamodb/connection.ts +8 -8
- package/src/postgres/connection.ts +10 -6
package/README.md
CHANGED
|
@@ -100,7 +100,7 @@ export default {
|
|
|
100
100
|
migrationsTable: '__migrations',
|
|
101
101
|
} : undefined,
|
|
102
102
|
dynamodb: DYNAMODB_REGION ? {
|
|
103
|
-
region: DYNAMODB_REGION
|
|
103
|
+
region: DYNAMODB_REGION,
|
|
104
104
|
endpoint: DYNAMODB_ENDPOINT, // optional, for DynamoDB Local
|
|
105
105
|
tablePrefix: DYNAMODB_TABLE_PREFIX, // optional table name prefix
|
|
106
106
|
} : undefined,
|
|
@@ -12,10 +12,12 @@ export interface DynamoDBConfig {
|
|
|
12
12
|
export type DocumentClient = {
|
|
13
13
|
send(command: unknown): Promise<unknown>;
|
|
14
14
|
};
|
|
15
|
-
export type
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
export type
|
|
15
|
+
export type DynamoDBClientConstructor = new (options: unknown) => {
|
|
16
|
+
config: unknown;
|
|
17
|
+
};
|
|
18
|
+
export type DocumentClientFromFn = {
|
|
19
|
+
from(client: unknown): DocumentClient;
|
|
20
|
+
};
|
|
19
21
|
/**
|
|
20
22
|
* Create a DynamoDBDocumentClient from the given config.
|
|
21
23
|
* Uses dynamic import so @aws-sdk/* are optional peer deps.
|
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
* Uses dynamic import so @aws-sdk/* are optional peer deps.
|
|
10
10
|
*/
|
|
11
11
|
export async function createDocumentClient(dbConfig) {
|
|
12
|
-
const {
|
|
13
|
-
const {
|
|
12
|
+
const { DynamoDBClient } = await import('@aws-sdk/client-dynamodb');
|
|
13
|
+
const { DynamoDBDocumentClient } = await import('@aws-sdk/lib-dynamodb');
|
|
14
14
|
const clientOptions = {};
|
|
15
15
|
if (dbConfig.region)
|
|
16
16
|
clientOptions.region = dbConfig.region;
|
|
17
17
|
if (dbConfig.endpoint)
|
|
18
18
|
clientOptions.endpoint = dbConfig.endpoint;
|
|
19
|
-
const rawClient = new
|
|
20
|
-
return
|
|
19
|
+
const rawClient = new DynamoDBClient(clientOptions);
|
|
20
|
+
return DynamoDBDocumentClient.from(rawClient);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Nullify the document client reference (DynamoDB connections are HTTP-based
|
|
@@ -7,15 +7,17 @@ export async function getPool(pgConfig, extensions = ['vector']) {
|
|
|
7
7
|
if (pool)
|
|
8
8
|
return pool;
|
|
9
9
|
const { default: pg } = await import('pg');
|
|
10
|
+
const { host, port, user, password, database, connectionLimit, migrationsDir, migrationsTable, ...poolOpts } = pgConfig;
|
|
10
11
|
pool = new pg.Pool({
|
|
11
|
-
host
|
|
12
|
-
port
|
|
13
|
-
user
|
|
14
|
-
password
|
|
15
|
-
database
|
|
16
|
-
max:
|
|
12
|
+
host,
|
|
13
|
+
port,
|
|
14
|
+
user,
|
|
15
|
+
password,
|
|
16
|
+
database,
|
|
17
|
+
max: connectionLimit,
|
|
17
18
|
idleTimeoutMillis: 30000,
|
|
18
19
|
connectionTimeoutMillis: 10000,
|
|
20
|
+
...poolOpts,
|
|
19
21
|
});
|
|
20
22
|
// Enable requested PostgreSQL extensions
|
|
21
23
|
for (const ext of extensions) {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"stonyx-async",
|
|
5
5
|
"stonyx-module"
|
|
6
6
|
],
|
|
7
|
-
"version": "0.3.2-alpha.
|
|
7
|
+
"version": "0.3.2-alpha.13",
|
|
8
8
|
"description": "",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"type": "module",
|
|
@@ -103,6 +103,7 @@
|
|
|
103
103
|
"scripts": {
|
|
104
104
|
"build": "tsc",
|
|
105
105
|
"build:test": "tsc -p tsconfig.test.json",
|
|
106
|
-
"test": "pnpm build && NODE_ENV=test node --import tsx/esm --import ./test/setup.ts node_modules/qunit/bin/qunit.js 'test/**/*-test.ts'"
|
|
106
|
+
"test": "pnpm build && NODE_ENV=test node --import tsx/esm --import ./test/setup.ts node_modules/qunit/bin/qunit.js 'test/**/*-test.ts'",
|
|
107
|
+
"test:dynamodb": "pnpm build && node --import tsx/esm --import ./test/integration/dynamodb/setup.ts node_modules/qunit/bin/qunit.js 'test/integration/dynamodb/**/*-test.ts'"
|
|
107
108
|
}
|
|
108
109
|
}
|
|
@@ -17,27 +17,27 @@ export type DocumentClient = {
|
|
|
17
17
|
send(command: unknown): Promise<unknown>;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export type
|
|
21
|
-
export type
|
|
20
|
+
export type DynamoDBClientConstructor = new (options: unknown) => { config: unknown };
|
|
21
|
+
export type DocumentClientFromFn = { from(client: unknown): DocumentClient };
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Create a DynamoDBDocumentClient from the given config.
|
|
25
25
|
* Uses dynamic import so @aws-sdk/* are optional peer deps.
|
|
26
26
|
*/
|
|
27
27
|
export async function createDocumentClient(dbConfig: DynamoDBConfig): Promise<DocumentClient> {
|
|
28
|
-
const {
|
|
29
|
-
|
|
28
|
+
const { DynamoDBClient } = await import('@aws-sdk/client-dynamodb' as string) as {
|
|
29
|
+
DynamoDBClient: DynamoDBClientConstructor;
|
|
30
30
|
};
|
|
31
|
-
const {
|
|
32
|
-
|
|
31
|
+
const { DynamoDBDocumentClient } = await import('@aws-sdk/lib-dynamodb' as string) as {
|
|
32
|
+
DynamoDBDocumentClient: DocumentClientFromFn;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
const clientOptions: Record<string, unknown> = {};
|
|
36
36
|
if (dbConfig.region) clientOptions.region = dbConfig.region;
|
|
37
37
|
if (dbConfig.endpoint) clientOptions.endpoint = dbConfig.endpoint;
|
|
38
38
|
|
|
39
|
-
const rawClient = new
|
|
40
|
-
return
|
|
39
|
+
const rawClient = new DynamoDBClient(clientOptions);
|
|
40
|
+
return DynamoDBDocumentClient.from(rawClient);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
/**
|
|
@@ -8,6 +8,7 @@ interface PgConfig {
|
|
|
8
8
|
password: string;
|
|
9
9
|
database: string;
|
|
10
10
|
connectionLimit: number;
|
|
11
|
+
[key: string]: unknown;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
let pool: PgPool | null = null;
|
|
@@ -20,15 +21,18 @@ export async function getPool(pgConfig: PgConfig, extensions: string[] = ['vecto
|
|
|
20
21
|
|
|
21
22
|
const { default: pg } = await import('pg');
|
|
22
23
|
|
|
24
|
+
const { host, port, user, password, database, connectionLimit, migrationsDir, migrationsTable, ...poolOpts } = pgConfig;
|
|
25
|
+
|
|
23
26
|
pool = new pg.Pool({
|
|
24
|
-
host
|
|
25
|
-
port
|
|
26
|
-
user
|
|
27
|
-
password
|
|
28
|
-
database
|
|
29
|
-
max:
|
|
27
|
+
host,
|
|
28
|
+
port,
|
|
29
|
+
user,
|
|
30
|
+
password,
|
|
31
|
+
database,
|
|
32
|
+
max: connectionLimit,
|
|
30
33
|
idleTimeoutMillis: 30000,
|
|
31
34
|
connectionTimeoutMillis: 10000,
|
|
35
|
+
...poolOpts,
|
|
32
36
|
});
|
|
33
37
|
|
|
34
38
|
// Enable requested PostgreSQL extensions
|