@pikku/kysely 0.6.0 → 0.6.2
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/CHANGELOG.md +14 -0
- package/bin/pikku-kysely-pure.ts +49 -0
- package/dist/bin/pikku-kysely-pure.d.ts +2 -0
- package/dist/bin/pikku-kysely-pure.js +39 -0
- package/dist/{index.d.ts → src/index.d.ts} +1 -0
- package/dist/{index.js → src/index.js} +1 -0
- package/dist/src/pikku-kysely.d.ts +12 -0
- package/dist/src/pikku-kysely.js +39 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +17 -8
- package/src/index.ts +1 -0
- package/src/pikku-kysely.ts +46 -0
- package/tsconfig.json +2 -2
- package/tsconfig.tsbuildinfo +0 -1
- /package/dist/{kysely-channel-store.d.ts → src/kysely-channel-store.d.ts} +0 -0
- /package/dist/{kysely-channel-store.js → src/kysely-channel-store.js} +0 -0
- /package/dist/{kysely-eventhub-store.d.ts → src/kysely-eventhub-store.d.ts} +0 -0
- /package/dist/{kysely-eventhub-store.js → src/kysely-eventhub-store.js} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @pikku/pino
|
|
2
2
|
|
|
3
|
+
## 0.6.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 990c2c2: fix: not requiring kysely as a peerDependency
|
|
8
|
+
|
|
9
|
+
## 0.6.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 8fcaa7e: feat: adding kysely wrapper
|
|
14
|
+
- Updated dependencies [eb8a8b4]
|
|
15
|
+
- @pikku/core@0.6.13
|
|
16
|
+
|
|
3
17
|
## 0.6.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { mkdir, readFile, writeFile } from 'fs/promises'
|
|
4
|
+
import { dirname } from 'path'
|
|
5
|
+
import { fileURLToPath } from 'url'
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
8
|
+
const __dirname = dirname(__filename)
|
|
9
|
+
|
|
10
|
+
const main = async (output: string, input?: string) => {
|
|
11
|
+
let execDirectory = process.cwd()
|
|
12
|
+
let inputPath = `${__dirname}/../node_modules/kysely-codegen/dist/db.d.ts`
|
|
13
|
+
if (input) {
|
|
14
|
+
inputPath = `${execDirectory}/${input}`
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let kysely
|
|
18
|
+
try {
|
|
19
|
+
kysely = await readFile(inputPath, 'utf8')
|
|
20
|
+
} catch {
|
|
21
|
+
console.error(`Could not read file ${input}`)
|
|
22
|
+
process.exit(1)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
kysely = kysely
|
|
26
|
+
.replace(/import type { ColumnType } from "kysely";/, '')
|
|
27
|
+
.replace(
|
|
28
|
+
new RegExp('^export\\s+type\\s+Generated<[^>]+>.*?;\\s*$', 'ms'),
|
|
29
|
+
''
|
|
30
|
+
)
|
|
31
|
+
.replace(/Generated<(.*)>/g, '$1')
|
|
32
|
+
.replace(/export type Timestamp =.*;/, 'export type Timestamp = Date')
|
|
33
|
+
console.log('Writing kysely-pure.gen.ts')
|
|
34
|
+
|
|
35
|
+
const outputPath = `${execDirectory}/${output}`
|
|
36
|
+
const outputDirectory = dirname(outputPath)
|
|
37
|
+
await mkdir(outputDirectory, { recursive: true })
|
|
38
|
+
await writeFile(outputPath, kysely, 'utf-8')
|
|
39
|
+
console.log(outputPath)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (process.argv.length !== 4) {
|
|
43
|
+
console.error('Expected the following usage:')
|
|
44
|
+
console.error('node kysely-pure.js <output> <input>')
|
|
45
|
+
process.exit(1)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const [, , output, input] = process.argv
|
|
49
|
+
main(output!, input)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdir, readFile, writeFile } from 'fs/promises';
|
|
3
|
+
import { dirname } from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = dirname(__filename);
|
|
7
|
+
const main = async (output, input) => {
|
|
8
|
+
let execDirectory = process.cwd();
|
|
9
|
+
let inputPath = `${__dirname}/../node_modules/kysely-codegen/dist/db.d.ts`;
|
|
10
|
+
if (input) {
|
|
11
|
+
inputPath = `${execDirectory}/${input}`;
|
|
12
|
+
}
|
|
13
|
+
let kysely;
|
|
14
|
+
try {
|
|
15
|
+
kysely = await readFile(inputPath, 'utf8');
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
console.error(`Could not read file ${input}`);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
kysely = kysely
|
|
22
|
+
.replace(/import type { ColumnType } from "kysely";/, '')
|
|
23
|
+
.replace(new RegExp('^export\\s+type\\s+Generated<[^>]+>.*?;\\s*$', 'ms'), '')
|
|
24
|
+
.replace(/Generated<(.*)>/g, '$1')
|
|
25
|
+
.replace(/export type Timestamp =.*;/, 'export type Timestamp = Date');
|
|
26
|
+
console.log('Writing kysely-pure.gen.ts');
|
|
27
|
+
const outputPath = `${execDirectory}/${output}`;
|
|
28
|
+
const outputDirectory = dirname(outputPath);
|
|
29
|
+
await mkdir(outputDirectory, { recursive: true });
|
|
30
|
+
await writeFile(outputPath, kysely, 'utf-8');
|
|
31
|
+
console.log(outputPath);
|
|
32
|
+
};
|
|
33
|
+
if (process.argv.length !== 4) {
|
|
34
|
+
console.error('Expected the following usage:');
|
|
35
|
+
console.error('node kysely-pure.js <output> <input>');
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
const [, , output, input] = process.argv;
|
|
39
|
+
main(output, input);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Logger } from '@pikku/core/services';
|
|
2
|
+
import { Kysely } from 'kysely';
|
|
3
|
+
import postgres from 'postgres';
|
|
4
|
+
export declare class PikkuKysely<DB> {
|
|
5
|
+
private logger;
|
|
6
|
+
private poolConfig;
|
|
7
|
+
kysely: Kysely<DB>;
|
|
8
|
+
private postgres;
|
|
9
|
+
constructor(logger: Logger, poolConfig: postgres.Options<{}>, defaultSchemaName: string);
|
|
10
|
+
init(): Promise<void>;
|
|
11
|
+
close(): Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CamelCasePlugin, Kysely } from 'kysely';
|
|
2
|
+
import { PostgresJSDialect } from 'kysely-postgres-js';
|
|
3
|
+
import postgres from 'postgres';
|
|
4
|
+
export class PikkuKysely {
|
|
5
|
+
logger;
|
|
6
|
+
poolConfig;
|
|
7
|
+
kysely;
|
|
8
|
+
postgres;
|
|
9
|
+
constructor(logger, poolConfig, defaultSchemaName) {
|
|
10
|
+
this.logger = logger;
|
|
11
|
+
this.poolConfig = poolConfig;
|
|
12
|
+
delete poolConfig.ssl;
|
|
13
|
+
this.postgres = postgres(poolConfig);
|
|
14
|
+
this.kysely = new Kysely({
|
|
15
|
+
dialect: new PostgresJSDialect({
|
|
16
|
+
postgres: this.postgres,
|
|
17
|
+
}),
|
|
18
|
+
plugins: [new CamelCasePlugin()],
|
|
19
|
+
});
|
|
20
|
+
if (defaultSchemaName) {
|
|
21
|
+
this.kysely = this.kysely.withSchema(defaultSchemaName);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async init() {
|
|
25
|
+
this.logger.info(`Connecting to database: ${this.poolConfig.host}:${this.poolConfig.port} with name ${this.poolConfig.database}`);
|
|
26
|
+
try {
|
|
27
|
+
const response = await this.postgres `SELECT version();`;
|
|
28
|
+
const version = response[0]?.version;
|
|
29
|
+
this.logger.info(version);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
this.logger.error('Error connecting to database', error);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async close() {
|
|
37
|
+
await this.kysely.destroy();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/index.ts","../src/kysely-channel-store.ts","../src/kysely-eventhub-store.ts","../src/pikku-kysely.ts","../bin/pikku-kysely-pure.ts"],"version":"5.7.3"}
|
package/package.json
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/kysely",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"author": "yasser.fadl@gmail.com",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"module": "dist/index.js",
|
|
7
|
-
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/src/index.js",
|
|
7
|
+
"main": "dist/src/index.js",
|
|
8
|
+
"bin": {
|
|
9
|
+
"kysely-pure": "dist/bin/kysely-pure.js"
|
|
10
|
+
},
|
|
8
11
|
"type": "module",
|
|
9
12
|
"scripts": {
|
|
10
13
|
"tsc": "tsc",
|
|
14
|
+
"ncu": "npx npm-check-updates",
|
|
11
15
|
"build:esm": "tsc -b",
|
|
12
16
|
"build": "yarn build:esm",
|
|
13
|
-
"ncu": "ncu",
|
|
14
17
|
"release": "npm run build && npm test"
|
|
15
18
|
},
|
|
16
19
|
"peerDependencies": {
|
|
17
|
-
"@pikku/core": "^0.6.
|
|
18
|
-
|
|
20
|
+
"@pikku/core": "^0.6.13"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"kysely": "^0.27.6",
|
|
24
|
+
"kysely-postgres-js": "^2.0.0",
|
|
25
|
+
"postgres": "^3.4.5"
|
|
19
26
|
},
|
|
20
27
|
"devDependencies": {
|
|
21
|
-
"kysely": "
|
|
22
|
-
"kysely-codegen": "
|
|
28
|
+
"kysely": "^0.27.6",
|
|
29
|
+
"kysely-codegen": "^0.16.6",
|
|
30
|
+
"kysely-postgres-js": "^2.0.0",
|
|
31
|
+
"postgres": "^3.4.5",
|
|
23
32
|
"typescript": "^5.6"
|
|
24
33
|
}
|
|
25
34
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Logger } from '@pikku/core/services'
|
|
2
|
+
import { CamelCasePlugin, Kysely } from 'kysely'
|
|
3
|
+
import { PostgresJSDialect } from 'kysely-postgres-js'
|
|
4
|
+
import postgres from 'postgres'
|
|
5
|
+
|
|
6
|
+
export class PikkuKysely<DB> {
|
|
7
|
+
public kysely: Kysely<DB>
|
|
8
|
+
private postgres: postgres.Sql<{}>
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
private logger: Logger,
|
|
12
|
+
private poolConfig: postgres.Options<{}>,
|
|
13
|
+
defaultSchemaName: string
|
|
14
|
+
) {
|
|
15
|
+
delete poolConfig.ssl
|
|
16
|
+
this.postgres = postgres(poolConfig)
|
|
17
|
+
this.kysely = new Kysely<DB>({
|
|
18
|
+
dialect: new PostgresJSDialect({
|
|
19
|
+
postgres: this.postgres,
|
|
20
|
+
}),
|
|
21
|
+
plugins: [new CamelCasePlugin()],
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
if (defaultSchemaName) {
|
|
25
|
+
this.kysely = this.kysely.withSchema(defaultSchemaName)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public async init() {
|
|
30
|
+
this.logger.info(
|
|
31
|
+
`Connecting to database: ${this.poolConfig.host}:${this.poolConfig.port} with name ${this.poolConfig.database}`
|
|
32
|
+
)
|
|
33
|
+
try {
|
|
34
|
+
const response = await this.postgres`SELECT version();`
|
|
35
|
+
const version = response[0]?.version
|
|
36
|
+
this.logger.info(version)
|
|
37
|
+
} catch (error) {
|
|
38
|
+
this.logger.error('Error connecting to database', error)
|
|
39
|
+
process.exit(1)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public async close() {
|
|
44
|
+
await this.kysely.destroy()
|
|
45
|
+
}
|
|
46
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../../tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"rootDir": "
|
|
4
|
+
"rootDir": ".",
|
|
5
5
|
"module": "Node16",
|
|
6
6
|
"outDir": "dist",
|
|
7
7
|
"target": "esnext",
|
|
8
8
|
"declaration": true
|
|
9
9
|
},
|
|
10
|
-
"include": ["src/**/*.ts"],
|
|
10
|
+
"include": ["src/**/*.ts", "bin/**/*.ts", "bin/pikku-kysely-pure.ts"],
|
|
11
11
|
"exclude": ["**/*.test.ts", "node_modules", "bin/dist"],
|
|
12
12
|
"references": [
|
|
13
13
|
{
|
package/tsconfig.tsbuildinfo
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["./src/index.ts","./src/kysely-channel-store.ts","./src/kysely-eventhub-store.ts"],"version":"5.7.3"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|