@pikku/kysely 0.6.5 → 0.7.0
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 +4 -0
- package/dist/bin/pikku-kysely-pure.js +0 -0
- package/package.json +2 -2
- package/bin/pikku-kysely-pure.ts +0 -49
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/index.ts +0 -3
- package/src/kysely-channel-store.ts +0 -53
- package/src/kysely-eventhub-store.ts +0 -32
- package/src/pikku-kysely.ts +0 -45
- package/tsconfig.json +0 -17
package/CHANGELOG.md
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/kysely",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"author": "yasser.fadl@gmail.com",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"module": "dist/src/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"release": "npm run build && npm test"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@pikku/core": "^0.
|
|
20
|
+
"@pikku/core": "^0.7.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"kysely": "^0.27.6",
|
package/bin/pikku-kysely-pure.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
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)
|
|
@@ -1 +0,0 @@
|
|
|
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/src/index.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { CoreUserSession } from '@pikku/core'
|
|
2
|
-
import { Channel, ChannelStore } from '@pikku/core/channel'
|
|
3
|
-
import { Kysely } from 'kysely'
|
|
4
|
-
|
|
5
|
-
export class KyselyChannelStore extends ChannelStore {
|
|
6
|
-
constructor(private database: Kysely<any>) {
|
|
7
|
-
super()
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public async addChannel({
|
|
11
|
-
channelId,
|
|
12
|
-
channelName,
|
|
13
|
-
openingData,
|
|
14
|
-
}: Channel): Promise<void> {
|
|
15
|
-
await this.database
|
|
16
|
-
.insertInto('serverless.lambdaChannels')
|
|
17
|
-
.values({
|
|
18
|
-
channelId,
|
|
19
|
-
channelName,
|
|
20
|
-
openingData: openingData as any,
|
|
21
|
-
})
|
|
22
|
-
.execute()
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public async removeChannels(channelIds: string[]): Promise<void> {
|
|
26
|
-
await this.database
|
|
27
|
-
.deleteFrom('serverless.lambdaChannels')
|
|
28
|
-
.where('channelId', 'in', channelIds)
|
|
29
|
-
.execute()
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public async setUserSession(channelId: string, session: any): Promise<void> {
|
|
33
|
-
await this.database
|
|
34
|
-
.updateTable('serverless.lambdaChannels')
|
|
35
|
-
.where('channelId', '=', channelId)
|
|
36
|
-
.set('userSession', session)
|
|
37
|
-
.executeTakeFirstOrThrow()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public async getChannelAndSession(channelId: string) {
|
|
41
|
-
const result = await this.database
|
|
42
|
-
.selectFrom('serverless.lambdaChannels')
|
|
43
|
-
.selectAll()
|
|
44
|
-
.where('channelId', '=', channelId)
|
|
45
|
-
.executeTakeFirstOrThrow()
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
openingData: result.openingData as any,
|
|
49
|
-
session: result.userSession as CoreUserSession,
|
|
50
|
-
channelName: result.channelName,
|
|
51
|
-
} as Channel & { session: CoreUserSession }
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { EventHubStore } from '@pikku/core/channel'
|
|
2
|
-
import { Kysely } from 'kysely'
|
|
3
|
-
|
|
4
|
-
export class KyselyEventHubStore implements EventHubStore {
|
|
5
|
-
constructor(private database: Kysely<any>) {}
|
|
6
|
-
|
|
7
|
-
public async getChannelIdsForTopic(topic: string): Promise<string[]> {
|
|
8
|
-
const result = await this.database
|
|
9
|
-
.selectFrom('serverless.lambdaChannelSubscriptions')
|
|
10
|
-
.select('channelId')
|
|
11
|
-
.where('topic', '=', topic)
|
|
12
|
-
.execute()
|
|
13
|
-
return result.map((row) => row.channelId)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public async subscribe(topic: string, channelId: string): Promise<boolean> {
|
|
17
|
-
await this.database
|
|
18
|
-
.insertInto('serverless.lambdaChannelSubscriptions')
|
|
19
|
-
.values({ channelId, topic })
|
|
20
|
-
.execute()
|
|
21
|
-
return true
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public async unsubscribe(topic: string, channelId: string): Promise<boolean> {
|
|
25
|
-
await this.database
|
|
26
|
-
.deleteFrom('serverless.lambdaChannelSubscriptions')
|
|
27
|
-
.where('channelId', '=', channelId)
|
|
28
|
-
.where('topic', '=', topic)
|
|
29
|
-
.execute()
|
|
30
|
-
return true
|
|
31
|
-
}
|
|
32
|
-
}
|
package/src/pikku-kysely.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
this.postgres = postgres(poolConfig)
|
|
16
|
-
this.kysely = new Kysely<DB>({
|
|
17
|
-
dialect: new PostgresJSDialect({
|
|
18
|
-
postgres: this.postgres,
|
|
19
|
-
}),
|
|
20
|
-
plugins: [new CamelCasePlugin()],
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
if (defaultSchemaName) {
|
|
24
|
-
this.kysely = this.kysely.withSchema(defaultSchemaName)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public async init() {
|
|
29
|
-
this.logger.info(
|
|
30
|
-
`Connecting to database: ${this.poolConfig.host}:${this.poolConfig.port} with name ${this.poolConfig.database}`
|
|
31
|
-
)
|
|
32
|
-
try {
|
|
33
|
-
const response = await this.postgres`SELECT version();`
|
|
34
|
-
const version = response[0]?.version
|
|
35
|
-
this.logger.info(version)
|
|
36
|
-
} catch (error) {
|
|
37
|
-
this.logger.error('Error connecting to database', error)
|
|
38
|
-
process.exit(1)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public async close() {
|
|
43
|
-
await this.kysely.destroy()
|
|
44
|
-
}
|
|
45
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": ".",
|
|
5
|
-
"module": "Node16",
|
|
6
|
-
"outDir": "dist",
|
|
7
|
-
"target": "esnext",
|
|
8
|
-
"declaration": true
|
|
9
|
-
},
|
|
10
|
-
"include": ["src/**/*.ts", "bin/**/*.ts", "bin/pikku-kysely-pure.ts"],
|
|
11
|
-
"exclude": ["**/*.test.ts", "node_modules", "bin/dist"],
|
|
12
|
-
"references": [
|
|
13
|
-
{
|
|
14
|
-
"path": "../../core/tsconfig.json"
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
}
|