@pikku/kysely 0.6.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 ADDED
@@ -0,0 +1,44 @@
1
+ # @pikku/pino
2
+
3
+ ## 0.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 0a92fa7: refactor: pulling schema into seperate package since ajv doesnt work on cloudflare (also keeps bundle size small!)
8
+ - Updated dependencies [0a92fa7]
9
+ - @pikku/core@0.6.7
10
+
11
+ ## 0.6
12
+
13
+ Marking a major release to include channels and scheduled tasks
14
+
15
+ ## 0.5.3
16
+
17
+ ### Patch Changes
18
+
19
+ - 886a2fb: refactor: moving singletons (like routes and channels) to global to avoid nodemodule overrides
20
+ - Updated dependencies [a768bad]
21
+ - Updated dependencies [886a2fb]
22
+ - Updated dependencies [886a2fb]
23
+ - @pikku/core@0.5.28
24
+
25
+ ## 0.5.2
26
+
27
+ ### Patch Changes
28
+
29
+ - 0f96787: refactor: dropping cjs support
30
+ - c23524a: refactor: bump to versions to ensure correct package usage
31
+ - Updated dependencies [0f96787]
32
+ - Updated dependencies [64e4a1e]
33
+ - Updated dependencies [c23524a]
34
+ - @pikku/core@0.5.25
35
+
36
+ ## 0.5.1
37
+
38
+ ### Patch Changes
39
+
40
+ - bba25cc: chore: updating all packages to reflect major changes
41
+ - Updated dependencies [bba25cc]
42
+ - Updated dependencies [9deb482]
43
+ - Updated dependencies [ee0c6ea]
44
+ - @pikku/core@0.5.24
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @pikku/pino
2
+
3
+ This package is part of @pikku/mono and is responsible for providing the Pino Logger
@@ -0,0 +1,2 @@
1
+ export { KyselyChannelStore } from './kysely-channel-store.js';
2
+ export { KyselyEventHubStore } from './kysely-eventhub-store.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { KyselyChannelStore } from './kysely-channel-store.js';
2
+ export { KyselyEventHubStore } from './kysely-eventhub-store.js';
@@ -0,0 +1,10 @@
1
+ import { Channel, ChannelStore } from '@pikku/core/channel';
2
+ import { Kysely } from 'kysely';
3
+ export declare class KyselyChannelStore extends ChannelStore {
4
+ private database;
5
+ constructor(database: Kysely<any>);
6
+ addChannel({ channelId, channelName, openingData, }: Channel): Promise<void>;
7
+ removeChannels(channelIds: string[]): Promise<void>;
8
+ setUserSession(channelId: string, session: any): Promise<void>;
9
+ getChannel(channelId: string): Promise<Channel>;
10
+ }
@@ -0,0 +1,43 @@
1
+ import { ChannelStore } from '@pikku/core/channel';
2
+ export class KyselyChannelStore extends ChannelStore {
3
+ database;
4
+ constructor(database) {
5
+ super();
6
+ this.database = database;
7
+ }
8
+ async addChannel({ channelId, channelName, openingData, }) {
9
+ await this.database
10
+ .insertInto('serverless.lambdaChannels')
11
+ .values({
12
+ channelId,
13
+ channelName,
14
+ openingData: openingData,
15
+ })
16
+ .execute();
17
+ }
18
+ async removeChannels(channelIds) {
19
+ await this.database
20
+ .deleteFrom('serverless.lambdaChannels')
21
+ .where('channelId', 'in', channelIds)
22
+ .execute();
23
+ }
24
+ async setUserSession(channelId, session) {
25
+ await this.database
26
+ .updateTable('serverless.lambdaChannels')
27
+ .where('channelId', '=', channelId)
28
+ .set('userSession', session)
29
+ .executeTakeFirstOrThrow();
30
+ }
31
+ async getChannel(channelId) {
32
+ const result = await this.database
33
+ .selectFrom('serverless.lambdaChannels')
34
+ .selectAll()
35
+ .where('channelId', '=', channelId)
36
+ .executeTakeFirstOrThrow();
37
+ return {
38
+ openingData: result.openingData,
39
+ userSession: result.userSession,
40
+ channelName: result.channelName,
41
+ };
42
+ }
43
+ }
@@ -0,0 +1,9 @@
1
+ import { EventHubStore } from '@pikku/core/channel';
2
+ import { Kysely } from 'kysely';
3
+ export declare class KyselyEventHubStore implements EventHubStore {
4
+ private database;
5
+ constructor(database: Kysely<any>);
6
+ getChannelIdsForTopic(topic: string): Promise<string[]>;
7
+ subscribe(topic: string, channelId: string): Promise<boolean>;
8
+ unsubscribe(topic: string, channelId: string): Promise<boolean>;
9
+ }
@@ -0,0 +1,29 @@
1
+ export class KyselyEventHubStore {
2
+ database;
3
+ constructor(database) {
4
+ this.database = database;
5
+ }
6
+ async getChannelIdsForTopic(topic) {
7
+ const result = await this.database
8
+ .selectFrom('serverless.lambdaChannelSubscriptions')
9
+ .select('channelId')
10
+ .where('topic', '=', topic)
11
+ .execute();
12
+ return result.map((row) => row.channelId);
13
+ }
14
+ async subscribe(topic, channelId) {
15
+ await this.database
16
+ .insertInto('serverless.lambdaChannelSubscriptions')
17
+ .values({ channelId, topic })
18
+ .execute();
19
+ return true;
20
+ }
21
+ async unsubscribe(topic, channelId) {
22
+ await this.database
23
+ .deleteFrom('serverless.lambdaChannelSubscriptions')
24
+ .where('channelId', '=', channelId)
25
+ .where('topic', '=', topic)
26
+ .execute();
27
+ return true;
28
+ }
29
+ }
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@pikku/kysely",
3
+ "version": "0.6.0",
4
+ "author": "yasser.fadl@gmail.com",
5
+ "license": "MIT",
6
+ "module": "dist/index.js",
7
+ "main": "dist/index.js",
8
+ "type": "module",
9
+ "scripts": {
10
+ "tsc": "tsc",
11
+ "build:esm": "tsc -b",
12
+ "build": "yarn build:esm",
13
+ "ncu": "ncu",
14
+ "release": "npm run build && npm test"
15
+ },
16
+ "peerDependencies": {
17
+ "@pikku/core": "^0.6.7",
18
+ "kysely": "*"
19
+ },
20
+ "devDependencies": {
21
+ "kysely": "latest",
22
+ "kysely-codegen": "latest",
23
+ "typescript": "^5.6"
24
+ }
25
+ }
package/run-tests.sh ADDED
@@ -0,0 +1,53 @@
1
+ #!/bin/bash
2
+
3
+ # Enable nullglob to handle cases where no files match the pattern
4
+ shopt -s nullglob
5
+
6
+ # Initialize variables for options
7
+ watch_mode=false
8
+ coverage_mode=false
9
+
10
+ # Parse command-line options
11
+ while [[ $# -gt 0 ]]; do
12
+ case $1 in
13
+ --watch)
14
+ watch_mode=true
15
+ shift
16
+ ;;
17
+ --coverage)
18
+ coverage_mode=true
19
+ shift
20
+ ;;
21
+ *)
22
+ echo "Unknown option: $1"
23
+ exit 1
24
+ ;;
25
+ esac
26
+ done
27
+
28
+ # Define the pattern to match your test files
29
+ pattern="src/*.test.ts"
30
+
31
+ # Expand the pattern into an array of files
32
+ files=($(find src -type f -name "*.test.ts"))
33
+
34
+ # Check if any files matched the pattern
35
+ if [ ${#files[@]} -eq 0 ]; then
36
+ echo "No test files found matching pattern: $pattern"
37
+ exit 0
38
+ fi
39
+
40
+ # Construct the node command
41
+ node_cmd="node --import tsx --test"
42
+
43
+ # Append options based on flags
44
+ if [ "$watch_mode" = true ]; then
45
+ node_cmd="$node_cmd --watch"
46
+ fi
47
+
48
+ if [ "$coverage_mode" = true ]; then
49
+ node_cmd="$node_cmd --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info"
50
+ fi
51
+
52
+ # Execute the node command with the expanded list of files
53
+ $node_cmd "${files[@]}"
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { KyselyChannelStore } from './kysely-channel-store.js'
2
+ export { KyselyEventHubStore } from './kysely-eventhub-store.js'
@@ -0,0 +1,52 @@
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 getChannel(channelId: string) {
41
+ const result = await this.database
42
+ .selectFrom('serverless.lambdaChannels')
43
+ .selectAll()
44
+ .where('channelId', '=', channelId)
45
+ .executeTakeFirstOrThrow()
46
+ return {
47
+ openingData: result.openingData as any,
48
+ userSession: result.userSession as CoreUserSession,
49
+ channelName: result.channelName,
50
+ } as Channel
51
+ }
52
+ }
@@ -0,0 +1,32 @@
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/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "module": "Node16",
6
+ "outDir": "dist",
7
+ "target": "esnext",
8
+ "declaration": true
9
+ },
10
+ "include": ["src/**/*.ts"],
11
+ "exclude": ["**/*.test.ts", "node_modules", "bin/dist"],
12
+ "references": [
13
+ {
14
+ "path": "../../core/tsconfig.json"
15
+ }
16
+ ]
17
+ }
@@ -0,0 +1 @@
1
+ {"root":["./src/index.ts","./src/kysely-channel-store.ts","./src/kysely-eventhub-store.ts"],"version":"5.7.3"}