@dbos-inc/kysely-datasource 4.28.4-preview → 4.28.6-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 +26 -0
- package/package.json +15 -2
- package/scripts/emit-esm-types.js +6 -0
- package/tests/esm-consumer.mts +13 -0
- package/tests/esmtypes.test.ts +27 -0
- package/tests/tsconfig.esmcheck.json +11 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FunctionName } from '@dbos-inc/dbos-sdk';
|
|
2
|
+
import { DBOSDataSource } from '@dbos-inc/dbos-sdk/datasource';
|
|
3
|
+
import { Kysely, IsolationLevel } from 'kysely';
|
|
4
|
+
import { PoolConfig } from 'pg';
|
|
5
|
+
export interface transaction_completion {
|
|
6
|
+
workflow_id: string;
|
|
7
|
+
function_num: number;
|
|
8
|
+
output: string | null;
|
|
9
|
+
error: string | null;
|
|
10
|
+
}
|
|
11
|
+
export interface TransactionConfig {
|
|
12
|
+
name?: string;
|
|
13
|
+
isolationLevel?: IsolationLevel;
|
|
14
|
+
readOnly?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare class KyselyDataSource<DB> implements DBOSDataSource<TransactionConfig> {
|
|
17
|
+
#private;
|
|
18
|
+
readonly name: string;
|
|
19
|
+
get client(): Kysely<DB>;
|
|
20
|
+
static initializeDBOSSchema(poolConfig: PoolConfig, schemaName?: string): Promise<void>;
|
|
21
|
+
static uninitializeDBOSSchema(poolConfig: PoolConfig, schemaName?: string): Promise<void>;
|
|
22
|
+
constructor(name: string, poolConfigOrKysely: PoolConfig | Kysely<any>, schemaName?: string);
|
|
23
|
+
runTransaction<R>(func: () => Promise<R>, config?: TransactionConfig): Promise<R>;
|
|
24
|
+
registerTransaction<This, Args extends unknown[], Return>(func: (this: This, ...args: Args) => Promise<Return>, config?: TransactionConfig & FunctionName): (this: This, ...args: Args) => Promise<Return>;
|
|
25
|
+
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>>;
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dbos-inc/kysely-datasource",
|
|
3
|
-
"version": "4.28.
|
|
3
|
+
"version": "4.28.6-preview",
|
|
4
4
|
"description": "DBOS DataSource library for Kysely Query Builder 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/kysely-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,13 @@
|
|
|
1
|
+
// Typechecked by esmtypes.test.ts, never executed: .mts makes it ESM regardless of the package type.
|
|
2
|
+
import { KyselyDataSource } from '@dbos-inc/kysely-datasource';
|
|
3
|
+
import type { Kysely } from 'kysely';
|
|
4
|
+
|
|
5
|
+
interface Database {
|
|
6
|
+
greetings: { greeting: string };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare const dataSource: KyselyDataSource<Database>;
|
|
10
|
+
declare const existingClient: Kysely<Database>;
|
|
11
|
+
|
|
12
|
+
export const client: Kysely<Database> = dataSource.client;
|
|
13
|
+
export const fromExistingClient = new KyselyDataSource<Database>('app', existingClient);
|
|
@@ -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/kysely-datasource/package.json')).not.toThrow();
|
|
26
|
+
});
|
|
27
|
+
});
|