@stonyx/orm 0.3.2-beta.67 → 0.3.2-beta.69

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.
@@ -12,10 +12,12 @@ export interface DynamoDBConfig {
12
12
  export type DocumentClient = {
13
13
  send(command: unknown): Promise<unknown>;
14
14
  };
15
- export type DocumentClientConstructor = new (options: {
16
- client: unknown;
17
- }) => DocumentClient;
18
- export type DynamoDBClientConstructor = new (options: unknown) => unknown;
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 { DynamoDB } = await import('@aws-sdk/client-dynamodb');
13
- const { DynamoDBDocument } = await import('@aws-sdk/lib-dynamodb');
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 DynamoDB(clientOptions);
20
- return new DynamoDBDocument({ client: rawClient });
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
@@ -6,6 +6,7 @@ interface PgConfig {
6
6
  password: string;
7
7
  database: string;
8
8
  connectionLimit: number;
9
+ [key: string]: unknown;
9
10
  }
10
11
  /**
11
12
  * Create or return the singleton pg Pool.
@@ -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: pgConfig.host,
12
- port: pgConfig.port,
13
- user: pgConfig.user,
14
- password: pgConfig.password,
15
- database: pgConfig.database,
16
- max: pgConfig.connectionLimit,
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-beta.67",
7
+ "version": "0.3.2-beta.69",
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 DocumentClientConstructor = new (options: { client: unknown }) => DocumentClient;
21
- export type DynamoDBClientConstructor = new (options: unknown) => unknown;
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 { DynamoDB } = await import('@aws-sdk/client-dynamodb' as string) as {
29
- DynamoDB: DynamoDBClientConstructor;
28
+ const { DynamoDBClient } = await import('@aws-sdk/client-dynamodb' as string) as {
29
+ DynamoDBClient: DynamoDBClientConstructor;
30
30
  };
31
- const { DynamoDBDocument } = await import('@aws-sdk/lib-dynamodb' as string) as {
32
- DynamoDBDocument: DocumentClientConstructor;
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 DynamoDB(clientOptions);
40
- return new DynamoDBDocument({ client: rawClient });
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: pgConfig.host,
25
- port: pgConfig.port,
26
- user: pgConfig.user,
27
- password: pgConfig.password,
28
- database: pgConfig.database,
29
- max: pgConfig.connectionLimit,
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