Skip to content

Commit 258fb18

Browse files
committed
chore: add workflows and linter
1 parent 0ee5242 commit 258fb18

10 files changed

Lines changed: 265 additions & 13 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Publish npm package function-kysely-tailordb-codegen
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
9+
defaults:
10+
run:
11+
shell: bash
12+
13+
jobs:
14+
publish:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
19+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
20+
with:
21+
node-version-file: packages/kysely-tailordb-codegen/package.json
22+
registry-url: https://registry.npmjs.org
23+
24+
- name: Update corepack
25+
run: |
26+
npm i -g corepack@latest
27+
28+
- name: Publish
29+
working-directory: packages/kysely-tailordb-codegen
30+
run: |
31+
corepack enable
32+
pnpm install
33+
pnpm run build
34+
pnpm publish --no-git-checks --access public
35+
env:
36+
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test packages/kysely-tailordb-codegen
2+
3+
on: workflow_call
4+
5+
jobs:
6+
test:
7+
timeout-minutes: 10
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
13+
steps:
14+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
15+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
16+
with:
17+
node-version-file: packages/kysely-tailordb/package.json
18+
registry-url: https://registry.npmjs.org
19+
20+
- name: Setup pnpm
21+
run: |
22+
npm i -g corepack@latest
23+
corepack enable
24+
25+
- name: Install deps
26+
working-directory: packages/kysely-tailordb-codegen
27+
run: |
28+
pnpm install
29+
30+
- name: Lint
31+
working-directory: packages/kysely-tailordb-codegen
32+
run: |
33+
pnpm run check
34+
35+
- name: Run type-check
36+
working-directory: packages/kysely-tailordb-codegen
37+
run: |
38+
pnpm run type-check
39+
40+
- name: Build
41+
working-directory: packages/kysely-tailordb-codegen
42+
run: |
43+
pnpm run build

.github/workflows/test.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
action: ${{ steps.changes.outputs.action }}
1212
renovate: ${{ steps.changes.outputs.renovate }}
1313
kysely-tailordb: ${{ steps.changes.outputs.kysely-tailordb }}
14+
kysely-tailordb-codegen: ${{ steps.changes.outputs.kysely-tailordb-codegen }}
1415
types: ${{ steps.changes.outputs.types }}
1516
runs-on: ubuntu-latest
1617
permissions:
@@ -28,6 +29,8 @@ jobs:
2829
- renovate.json
2930
kysely-tailordb:
3031
- packages/kysely-tailordb/**
32+
kysely-tailordb-codegen:
33+
- packages/kysely-tailordb-codegen/**
3134
types:
3235
- packages/types/**
3336
@@ -38,6 +41,7 @@ jobs:
3841
- action
3942
- renovate
4043
- kysely-tailordb
44+
- kysely-tailordb-codegen
4145
permissions: {}
4246
if: failure()
4347
steps:
@@ -64,3 +68,11 @@ jobs:
6468
permissions:
6569
contents: read
6670
pull-requests: write
71+
72+
kysely-tailordb-codegen:
73+
uses: ./.github/workflows/test-function-kysely-tailordb-codegen.yaml
74+
needs: path-filter
75+
if: needs.path-filter.outputs.kysely-tailordb-codegen == 'true'
76+
permissions:
77+
contents: read
78+
pull-requests: write
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
11
# @tailor-platform/function-kysely-tailordb-codegen
22

33
Generate [Kysely](https://github.com/kysely-org/kysely) code for TailorDB
4+
5+
## Usage
6+
7+
```sh
8+
npm install -D @tailor-platform/function-kysely-tailordb-codegen
9+
npx kysely-tailordb-codegen -h
10+
```
11+
12+
```
13+
Usage: kysely-tailordb-codegen [options]
14+
15+
Generate Kysely code for TailorDB
16+
17+
Options:
18+
-a, --app <string> App name
19+
-n, --namespace <string> TailorDB namespace
20+
-m, --machineuser <string> Machine user name
21+
-o, --output <string> Output file name
22+
-h, --help display help for command
23+
```
24+
25+
## Requirements
26+
27+
This command uses `tailorctl` internally to run the code generation script on the Tailor Platform.
28+
Therefore, please make sure `tailorctl` is installed and the correct workspace is selected before running the command.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3+
"formatter": {
4+
"enabled": true,
5+
"indentStyle": "space",
6+
"indentWidth": 2,
7+
"formatWithErrors": false
8+
},
9+
"javascript": {
10+
"formatter": {
11+
"quoteStyle": "double",
12+
"semicolons": "always",
13+
"trailingCommas": "all"
14+
}
15+
},
16+
"linter": {
17+
"enabled": true,
18+
"ignore": ["**/node_modules/**", "**/dist/**"],
19+
"rules": {
20+
"recommended": true
21+
}
22+
},
23+
"organizeImports": {
24+
"enabled": true
25+
},
26+
"vcs": {
27+
"enabled": true,
28+
"clientKind": "git",
29+
"useIgnoreFile": true
30+
}
31+
}

packages/kysely-tailordb-codegen/build.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { build } from "esbuild";
21
import { createRequire } from "node:module";
32
import path from "node:path";
3+
import { build } from "esbuild";
44
import { nodeless } from "unenv";
55

66
const require = createRequire(import.meta.url);

packages/kysely-tailordb-codegen/package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
"bin": {
1212
"kysely-tailordb-codegen": "./dist/cli.js"
1313
},
14-
"files": [
15-
"dist"
16-
],
14+
"files": ["dist"],
1715
"scripts": {
1816
"build": "node ./build.mjs",
17+
"check": "biome check .",
18+
"check-write": "biome check --write .",
1919
"type-check": "tsc"
2020
},
2121
"dependencies": {
2222
"commander": "^14.0.0",
2323
"zx": "^8.5.4"
2424
},
2525
"devDependencies": {
26+
"@biomejs/biome": "^1.9.4",
2627
"@tailor-platform/function-kysely-tailordb": "^0.1.2",
2728
"@tailor-platform/function-types": "^0.2.0",
2829
"@tsconfig/recommended": "^1.0.8",
@@ -34,5 +35,11 @@
3435
"typescript": "^5.8.3",
3536
"unenv": "^1.10.0"
3637
},
37-
"packageManager": "pnpm@10.11.0"
38+
"engines": {
39+
"node": "22.x"
40+
},
41+
"packageManager": "pnpm@10.11.0",
42+
"pnpm": {
43+
"onlyBuiltDependencies": ["@biomejs/biome"]
44+
}
3845
}

packages/kysely-tailordb-codegen/pnpm-lock.yaml

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/kysely-tailordb-codegen/src/cli.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const script = path.join(import.meta.dirname, "function.js");
1818
const out = path.resolve(process.cwd(), output);
1919

2020
console.log(
21-
`Generating code for TailorDB namespace "${namespace}" in app "${app}"...`
21+
`Generating code for TailorDB namespace "${namespace}" in app "${app}"...`,
2222
);
2323

2424
const result =
@@ -29,17 +29,20 @@ if (!result.ok) {
2929
program.error(
3030
`${chalk.red.bold("ERROR")} tailorctl failed with exit code ${
3131
result.exitCode
32-
}.\n${result.stderr}`
32+
}.\n${result.stderr}`,
3333
);
3434
}
3535

36-
let json;
36+
let json: { data: string };
3737
try {
3838
const match = result.stdout.match(/\{"data":.*\}/);
39-
json = JSON.parse(match![0]);
39+
if (!match) {
40+
throw new Error("No JSON data found in output.");
41+
}
42+
json = JSON.parse(match[0]);
4043
} catch {
4144
program.error(
42-
`${chalk.red.bold("ERROR")} Failed to parse output from tailorctl.`
45+
`${chalk.red.bold("ERROR")} Failed to parse output from tailorctl.`,
4346
);
4447
}
4548

packages/kysely-tailordb-codegen/src/function.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import { Kysely } from "kysely";
2-
import { PostgresDialect, TypeScriptSerializer } from "kysely-codegen";
31
import { TailordbDialect } from "@tailor-platform/function-kysely-tailordb";
2+
import { Kysely } from "kysely";
3+
import {
4+
type PostgresDB,
5+
PostgresDialect,
6+
TypeScriptSerializer,
7+
} from "kysely-codegen";
48

59
export default async (args: { namespace: string }) => {
610
const client = new tailordb.Client({
711
namespace: args.namespace,
812
});
9-
const db = new Kysely<any>({
13+
const db = new Kysely<PostgresDB>({
1014
dialect: new TailordbDialect(client),
1115
});
1216
const dialect = new PostgresDialect({ domains: false });

0 commit comments

Comments
 (0)