@dbos-inc/drizzle-datasource 4.28.4-preview → 4.28.7-preview
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/index.d.mts +31 -0
- package/package.json +15 -2
- package/scripts/emit-esm-types.js +6 -0
- package/tests/esm-consumer.mts +8 -0
- package/tests/esmtypes.test.ts +27 -0
- package/tests/tsconfig.esmcheck.json +11 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Client, ClientConfig, Pool, PoolClient, PoolConfig } from 'pg';
|
|
2
|
+
import { FunctionName } from '@dbos-inc/dbos-sdk';
|
|
3
|
+
import { DBOSDataSource } from '@dbos-inc/dbos-sdk/datasource';
|
|
4
|
+
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
5
|
+
import { PgTransactionConfig } from 'drizzle-orm/pg-core';
|
|
6
|
+
export type TransactionConfig = Pick<PgTransactionConfig, 'isolationLevel' | 'accessMode'> & {
|
|
7
|
+
name?: string;
|
|
8
|
+
};
|
|
9
|
+
export interface transaction_completion {
|
|
10
|
+
workflow_id: string;
|
|
11
|
+
function_num: number;
|
|
12
|
+
output: string | null;
|
|
13
|
+
error: string | null;
|
|
14
|
+
}
|
|
15
|
+
export declare class DrizzleDataSource<CT = NodePgDatabase<{
|
|
16
|
+
[key: string]: object;
|
|
17
|
+
}>> implements DBOSDataSource<TransactionConfig> {
|
|
18
|
+
#private;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
static get client(): NodePgDatabase<{
|
|
21
|
+
[key: string]: object;
|
|
22
|
+
}>;
|
|
23
|
+
get client(): CT;
|
|
24
|
+
static initializeDBOSSchema(configOrClient: ClientConfig | Client | PoolClient, schemaName?: string): Promise<void>;
|
|
25
|
+
constructor(name: string, configOrPool: PoolConfig | Pool, entities?: {
|
|
26
|
+
[key: string]: object;
|
|
27
|
+
}, schemaName?: string);
|
|
28
|
+
runTransaction<T>(func: () => Promise<T>, config?: TransactionConfig): Promise<T>;
|
|
29
|
+
registerTransaction<This, Args extends unknown[], Return>(func: (this: This, ...args: Args) => Promise<Return>, config?: TransactionConfig & FunctionName): (this: This, ...args: Args) => Promise<Return>;
|
|
30
|
+
transaction(config?: TransactionConfig): <This, Args extends unknown[], Return>(target: object, propertyKey: PropertyKey, descriptor: TypedPropertyDescriptor<(this: This, ...args: Args) => Promise<Return>>) => TypedPropertyDescriptor<(this: This, ...args: Args) => Promise<Return>>;
|
|
31
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbos-inc/drizzle-datasource",
|
|
3
|
-
"version": "4.28.
|
|
3
|
+
"version": "4.28.7-preview",
|
|
4
4
|
"description": "DBOS DataSource library for Drizzle ORM with PostgreSQL support",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.mts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
8
21
|
"homepage": "https://docs.dbos.dev/",
|
|
9
22
|
"repository": {
|
|
10
23
|
"type": "git",
|
|
@@ -12,7 +25,7 @@
|
|
|
12
25
|
"directory": "packages/drizzle-datasource"
|
|
13
26
|
},
|
|
14
27
|
"scripts": {
|
|
15
|
-
"build": "tsc --project tsconfig.json",
|
|
28
|
+
"build": "tsc --project tsconfig.json && node scripts/emit-esm-types.js",
|
|
16
29
|
"test": "jest --detectOpenHandles"
|
|
17
30
|
},
|
|
18
31
|
"dependencies": {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
|
|
3
|
+
// ESM consumers need a .d.mts so the declarations' own imports resolve through the "import" condition.
|
|
4
|
+
const declarations = fs.readFileSync('dist/index.d.ts', 'utf8');
|
|
5
|
+
// The copied sourceMappingURL would point at a map that names index.d.ts as its file.
|
|
6
|
+
fs.writeFileSync('dist/index.d.mts', declarations.replace(/^\/\/# sourceMappingURL=.*\n?/m, ''));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Typechecked by esmtypes.test.ts, never executed: .mts makes it ESM regardless of the package type.
|
|
2
|
+
import { DrizzleDataSource } from '@dbos-inc/drizzle-datasource';
|
|
3
|
+
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
4
|
+
|
|
5
|
+
declare const dataSource: DrizzleDataSource;
|
|
6
|
+
|
|
7
|
+
export const instanceClient: NodePgDatabase<{ [key: string]: object }> = dataSource.client;
|
|
8
|
+
export const staticClient: NodePgDatabase<{ [key: string]: object }> = DrizzleDataSource.client;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { execFileSync } from 'child_process';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
const packageRoot = path.join(__dirname, '..');
|
|
6
|
+
|
|
7
|
+
describe('ESM type declarations', () => {
|
|
8
|
+
test('an ESM consumer under NodeNext typechecks against the built declarations', () => {
|
|
9
|
+
const tsc = require.resolve('typescript/bin/tsc');
|
|
10
|
+
const project = path.join(__dirname, 'tsconfig.esmcheck.json');
|
|
11
|
+
try {
|
|
12
|
+
execFileSync(process.execPath, [tsc, '--project', project], { cwd: packageRoot, stdio: 'pipe' });
|
|
13
|
+
} catch (error) {
|
|
14
|
+
const { stdout } = error as { stdout?: Buffer };
|
|
15
|
+
throw new Error(`ESM consumer failed to typecheck. Run 'npm run build' first.\n${stdout?.toString() ?? ''}`);
|
|
16
|
+
}
|
|
17
|
+
}, 120000);
|
|
18
|
+
|
|
19
|
+
test('the ESM declarations carry no reference to the CommonJS declaration map', () => {
|
|
20
|
+
const declarations = readFileSync(path.join(packageRoot, 'dist', 'index.d.mts'), 'utf8');
|
|
21
|
+
expect(declarations).not.toContain('sourceMappingURL');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('the exports map still resolves the package manifest', () => {
|
|
25
|
+
expect(() => require.resolve('@dbos-inc/drizzle-datasource/package.json')).not.toThrow();
|
|
26
|
+
});
|
|
27
|
+
});
|