@onreza/sqlx-js 0.5.0 → 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/README.md +59 -19
- package/ROADMAP.md +1 -1
- package/dist/bin/sqlx-js-diagnostics.d.ts +2 -0
- package/dist/bin/sqlx-js-diagnostics.js +96 -0
- package/dist/bin/sqlx-js.js +258 -81
- package/dist/src/commands/init.js +87 -3
- package/dist/src/commands/migrate.d.ts +2 -101
- package/dist/src/commands/migrate.js +6 -546
- package/dist/src/commands/prepare.d.ts +2 -1
- package/dist/src/commands/prepare.js +104 -5
- package/dist/src/commands/schema.js +1 -1
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.js +8 -0
- package/dist/src/migration-core.d.ts +157 -0
- package/dist/src/migration-core.js +578 -0
- package/dist/src/runtime.js +1 -1
- package/dist/src/scan/scanner.d.ts +1 -1
- package/dist/src/scan/scanner.js +4 -4
- package/dist/src/type-inspection.d.ts +1 -0
- package/dist/src/type-inspection.js +20 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -46,6 +46,8 @@ const rows = await sql(
|
|
|
46
46
|
- **Watch mode**: debounced re-prepare with a warm `PgClient` + `SchemaCache` on source/SQL changes and scanner/config graph updates.
|
|
47
47
|
- **Cache pruning** removes orphaned entries automatically (toggleable with `--no-prune`).
|
|
48
48
|
- **Environment doctor** checks runtime versions, config loading, `.env`, database connectivity/permissions, cache metadata, tsconfig inclusion, and pgschema availability.
|
|
49
|
+
- **Strict inference gate** promotes degraded nullability analysis and generated `unknown` query types to CI errors.
|
|
50
|
+
- **GitHub/editor diagnostics adapter** converts versioned prepare JSON into workflow annotations or Unix problem-matcher output.
|
|
49
51
|
|
|
50
52
|
## Install
|
|
51
53
|
|
|
@@ -57,7 +59,7 @@ bun add @onreza/sqlx-js
|
|
|
57
59
|
|
|
58
60
|
Node.js 24 or newer is required. Bun users need Bun 1.3 or newer.
|
|
59
61
|
|
|
60
|
-
The package installs
|
|
62
|
+
The package installs `sqlx-js` and `sqlx-js-diagnostics` binaries. The CLI examples below use `npx @onreza/sqlx-js`; `bunx @onreza/sqlx-js ...` works the same if your project uses Bun.
|
|
61
63
|
|
|
62
64
|
## Setup
|
|
63
65
|
|
|
@@ -67,7 +69,7 @@ The package installs a `sqlx-js` binary. The CLI examples below use `npx @onreza
|
|
|
67
69
|
npx @onreza/sqlx-js init
|
|
68
70
|
```
|
|
69
71
|
|
|
70
|
-
Creates `sqlx-js.config.ts`, a `migrations/` directory, and `.env.example` if they don't already exist
|
|
72
|
+
Creates `sqlx-js.config.ts`, `sqlx-js-env.d.ts`, a `migrations/` directory, and `.env.example` if they don't already exist. For strict-JSON files it adds missing `sqlx:*` scripts to `package.json` and appends the declaration to an existing `files` or `include` array in `tsconfig.json`, without replacing existing values; JSONC files are left unchanged with a manual-update hint. Skip it if you prefer to wire things up manually.
|
|
71
73
|
|
|
72
74
|
For declarative PostgreSQL schema management, scaffold the pgschema workflow instead:
|
|
73
75
|
|
|
@@ -144,7 +146,7 @@ const users = await sql(
|
|
|
144
146
|
npx @onreza/sqlx-js prepare
|
|
145
147
|
```
|
|
146
148
|
|
|
147
|
-
This generates `sqlx-js-env.d.ts` next to your code. Add it to your `tsconfig.json` `include` if it isn't picked up automatically. Use `--dts <path>` to override the destination
|
|
149
|
+
This generates `sqlx-js-env.d.ts` next to your code. Add it to your `tsconfig.json` `include` if it isn't picked up automatically. Use `--dts <path>` to override the destination relative to `--root`.
|
|
148
150
|
|
|
149
151
|
### 5. Dev loop with watch
|
|
150
152
|
|
|
@@ -385,11 +387,13 @@ In addition to `import { sql } from "@onreza/sqlx-js"`, the scanner recognises `
|
|
|
385
387
|
|
|
386
388
|
```
|
|
387
389
|
sqlx-js init [--root <dir>] [--schema-provider builtin|pgschema]
|
|
388
|
-
sqlx-js doctor [--root <dir>] [--json]
|
|
389
|
-
sqlx-js db install | check
|
|
390
|
-
sqlx-js
|
|
391
|
-
sqlx-js
|
|
392
|
-
sqlx-js
|
|
390
|
+
sqlx-js doctor [--root <dir>] [--dts <path>] [--json]
|
|
391
|
+
sqlx-js db install | check [--root <dir>]
|
|
392
|
+
sqlx-js db plan | apply [--root <dir>] [-- <pgschema args>]
|
|
393
|
+
sqlx-js prepare [--check | --verify | --watch] [--json] [--strict-inference] [--root <dir>] [--dts <path>] [--no-prune] [--shadow-url <url>]
|
|
394
|
+
sqlx-js migrate dev [--shadow-admin-url <url> | --shadow-url <url>] [--lock-timeout <ms>] [--strict-inference] | verify [--shadow-admin-url <url> | --shadow-url <url>] [--lock-timeout <ms>] [--strict-inference] | run [--dry-run] [--json] [--lock-timeout <ms>] | info [--json] | check [--json] | revert [--dry-run] [--json] [--shadow-admin-url <url> | --shadow-url <url>] [--lock-timeout <ms>] | add <name> | squash <name> [--shadow-admin-url <url> | --shadow-url <url>] [--replace] [--pg-dump <path>] [--lock-timeout <ms>] | archive list | archive restore <name> [--force]
|
|
395
|
+
sqlx-js schema dump [--schema <path>] [--manifest <path>] [--no-manifest] [--shadow-url <url>]
|
|
396
|
+
sqlx-js schema check [--schema <path>] [--shadow-url <url>]
|
|
393
397
|
sqlx-js --version | --help
|
|
394
398
|
```
|
|
395
399
|
|
|
@@ -401,25 +405,26 @@ Regular `prepare` describes queries across a small connection pool (default 8, o
|
|
|
401
405
|
| `--verify` | Prepare against the live/shadow schema and compare generated artifacts without writing. |
|
|
402
406
|
| `--watch` | Persistent connection, re-prepare on file change. |
|
|
403
407
|
| `--root <dir>` | Source/cache/migrations root (default: cwd). |
|
|
404
|
-
| `--dts <path>` |
|
|
408
|
+
| `--dts <path>` | Root-relative declarations output (default: `<root>/sqlx-js-env.d.ts`). |
|
|
405
409
|
| `--no-prune` | Keep orphaned cache entries instead of removing them. |
|
|
406
|
-
| `--migrations <dir>` |
|
|
410
|
+
| `--migrations <dir>` | Root-relative migrations directory (default: `<root>/migrations`). |
|
|
407
411
|
| `--dry-run` | For `migrate run` / `migrate revert`: validate without applying to the target DB. |
|
|
408
412
|
| `--json` | Machine-readable prepare diagnostics, doctor output, migration inspection and dry-runs. |
|
|
413
|
+
| `--strict-inference` | Fail prepare/dev/verify when nullability degrades or a generated query type contains `unknown`. |
|
|
409
414
|
| `--force` | For `migrate archive restore`: allow overwriting existing migration files. |
|
|
410
415
|
| `--lock-timeout <ms>` | Advisory-lock acquisition timeout for `migrate run` / `revert` / `dev` / `verify` / `squash`. |
|
|
411
416
|
| `--shadow-url <url>` | Use an existing disposable shadow DB instead of auto-creating one. |
|
|
412
417
|
| `--shadow-admin-url <url>` | Admin/maintenance DB URL used to auto-create shadow DBs. |
|
|
413
418
|
| `--replace` | For `migrate squash`: archive replaced migration files after writing the baseline. |
|
|
414
419
|
| `--pg-dump <path>` | For `migrate squash`: `pg_dump` executable path (default: `pg_dump`). |
|
|
415
|
-
| `--schema <path>` |
|
|
416
|
-
| `--manifest <path>` | LLM schema manifest path (default: `<root>/.sqlx-js/schema/schema.md`).
|
|
420
|
+
| `--schema <path>` | Root-relative schema snapshot path (default: `<root>/.sqlx-js/schema/schema.json`). |
|
|
421
|
+
| `--manifest <path>` | Root-relative LLM schema manifest path (default: `<root>/.sqlx-js/schema/schema.md`). |
|
|
417
422
|
| `--no-manifest` | Skip writing the LLM schema manifest during `schema dump`. |
|
|
418
423
|
| `--schema-provider <name>` | For `init`: `builtin` (default) or `pgschema`. |
|
|
419
424
|
|
|
420
425
|
Flags that take a value accept both `--flag value` and `--flag=value` forms.
|
|
421
426
|
|
|
422
|
-
Prepare and doctor JSON use `formatVersion: 1`. Prepare diagnostics include a stable phase plus root-relative file, 1-based line/column, PostgreSQL code/position/hint when available, and the query text. This is intended for CI annotations and editor integrations; stdout contains one JSON document and human progress is suppressed.
|
|
427
|
+
Prepare and doctor JSON use `formatVersion: 1`. Prepare diagnostics include a stable phase plus root-relative file, 1-based line/column, PostgreSQL code/position/hint when available, and the query text. Degraded inference and generated `unknown` types appear as warnings by default; `--strict-inference` promotes them to errors. This is intended for CI annotations and editor integrations; stdout contains one JSON document and human progress is suppressed.
|
|
423
428
|
|
|
424
429
|
`DATABASE_URL` must be set for any command that touches the application database or auto-creates a shadow database. `SHADOW_ADMIN_DATABASE_URL` can point at a maintenance/admin database when the application user cannot `CREATE DATABASE`; `SHADOW_DATABASE_URL` can point at a pre-created disposable shadow database. The internal wire client understands `sslmode`, `sslrootcert`, `sslcert`, `sslkey`, `application_name`, `connect_timeout` (seconds), and `statement_timeout` (milliseconds).
|
|
425
430
|
|
|
@@ -454,7 +459,7 @@ The built-in `migrate` workflow is kept for simple projects and embedded applica
|
|
|
454
459
|
Use `migrate verify` in PR/CI before merge:
|
|
455
460
|
|
|
456
461
|
```bash
|
|
457
|
-
sqlx-js migrate verify
|
|
462
|
+
sqlx-js migrate verify --strict-inference
|
|
458
463
|
sqlx-js prepare --check
|
|
459
464
|
sqlx-js doctor --json
|
|
460
465
|
tsc --noEmit
|
|
@@ -514,6 +519,39 @@ When `prepare` fails, every diagnostic points back to the originating call site:
|
|
|
514
519
|
|
|
515
520
|
Phases reported separately: `describe failed`, `analyze failed`, `paramMap failed`. PostgreSQL `position`, `code`, and `hint` are surfaced when present.
|
|
516
521
|
|
|
522
|
+
### GitHub and editor diagnostics
|
|
523
|
+
|
|
524
|
+
`sqlx-js-diagnostics` converts the versioned prepare JSON document into GitHub workflow commands or a standard Unix problem-matcher stream:
|
|
525
|
+
|
|
526
|
+
```bash
|
|
527
|
+
set -o pipefail
|
|
528
|
+
sqlx-js prepare --verify --json | sqlx-js-diagnostics github
|
|
529
|
+
sqlx-js prepare --check --json | sqlx-js-diagnostics unix
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
The `github` format creates inline workflow annotations. The `unix` format emits `file:line:column: severity: [phase] message`, which can be consumed by VS Code tasks and other editors without a dedicated extension. A minimal VS Code task uses a custom problem matcher:
|
|
533
|
+
|
|
534
|
+
```json
|
|
535
|
+
{
|
|
536
|
+
"label": "sqlx-js: check",
|
|
537
|
+
"type": "shell",
|
|
538
|
+
"command": "sqlx-js prepare --check --json | sqlx-js-diagnostics unix",
|
|
539
|
+
"problemMatcher": {
|
|
540
|
+
"owner": "sqlx-js",
|
|
541
|
+
"fileLocation": ["relative", "${workspaceFolder}"],
|
|
542
|
+
"pattern": {
|
|
543
|
+
"regexp": "^(.+):(\\d+):(\\d+): (error|warning): \\[([^\\]]+)\\] (.*)$",
|
|
544
|
+
"file": 1,
|
|
545
|
+
"line": 2,
|
|
546
|
+
"column": 3,
|
|
547
|
+
"severity": 4,
|
|
548
|
+
"code": 5,
|
|
549
|
+
"message": 6
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
```
|
|
554
|
+
|
|
517
555
|
## Configuration
|
|
518
556
|
|
|
519
557
|
`sqlx-js.config.ts` at the project root is optional.
|
|
@@ -527,6 +565,7 @@ export default defineConfig({
|
|
|
527
565
|
scan: {
|
|
528
566
|
include: ["apps/*/src/**/*", "packages/*/src/**/*"],
|
|
529
567
|
exclude: ["**/*.generated.ts"],
|
|
568
|
+
modules: ["@onreza/sqlx-js", "@app/database"],
|
|
530
569
|
},
|
|
531
570
|
schema: {
|
|
532
571
|
provider: "pgschema",
|
|
@@ -541,7 +580,7 @@ export default defineConfig({
|
|
|
541
580
|
});
|
|
542
581
|
```
|
|
543
582
|
|
|
544
|
-
By default the scanner uses the root `tsconfig.json` file list and follows TypeScript project references, so a referenced monorepo is scanned without walking unrelated folders. `scan.include` replaces that source-file universe with TypeScript glob patterns; `scan.exclude` is added to the built-in dependency/build exclusions. If there is no root `tsconfig.json`, the fallback is a recursive TypeScript scan.
|
|
583
|
+
By default the scanner uses the root `tsconfig.json` file list and follows TypeScript project references, so a referenced monorepo is scanned without walking unrelated folders. `scan.include` replaces that source-file universe with TypeScript glob patterns; `scan.exclude` is added to the built-in dependency/build exclusions. `scan.modules` replaces the default `@onreza/sqlx-js` import source list, which lets an application re-export `sql` through a shared database module without requiring arbitrary re-export graph analysis. Include `@onreza/sqlx-js` explicitly when direct imports and application-module imports are both used. If there is no root `tsconfig.json`, the fallback is a recursive TypeScript scan.
|
|
545
584
|
|
|
546
585
|
The `schema` block is optional. Use `provider: "pgschema"` when sqlx-js should delegate schema planning/apply commands to pgschema. `command` can override the managed binary lookup and point at another executable. With the pinned pgschema 1.12.0 CLI, `schemas` must contain exactly one schema name.
|
|
547
586
|
|
|
@@ -620,11 +659,11 @@ Commit the generated `sqlx-js-env.d.ts` and the `.sqlx-js/` cache directory to y
|
|
|
620
659
|
|
|
621
660
|
```yaml
|
|
622
661
|
- run: bun install
|
|
623
|
-
- run: sqlx-js migrate verify
|
|
662
|
+
- run: sqlx-js migrate verify --strict-inference # built-in migration workflow
|
|
624
663
|
# or, when schema.provider is "pgschema":
|
|
625
664
|
- run: sqlx-js db install
|
|
626
665
|
- run: sqlx-js db plan -- --output-json plan.json
|
|
627
|
-
- run: sqlx-js prepare --verify
|
|
666
|
+
- run: sqlx-js prepare --verify --strict-inference # live/shadow comparison with complete inference
|
|
628
667
|
- run: sqlx-js prepare --check # offline cache/version/config consistency
|
|
629
668
|
- run: sqlx-js doctor --json # runtime/config/DB/cache/tsconfig preflight
|
|
630
669
|
- run: sqlx-js schema check # fails if the committed schema snapshot is stale
|
|
@@ -646,18 +685,19 @@ bun install # installs lefthook + wires git hooks
|
|
|
646
685
|
cargo install cocogitto # or: brew install cocogitto
|
|
647
686
|
```
|
|
648
687
|
|
|
649
|
-
Releases are automated via `release-please`: pushes to `main` accumulate into a release PR that bumps `package.json
|
|
688
|
+
Releases are automated via `release-please`: pushes to `main` accumulate into a release PR that bumps `package.json` and writes `CHANGELOG.md`. Merging that PR creates the tag and release, then the same workflow builds `dist/`, smoke-tests the package entrypoints, checks the tarball contents, and publishes to npm through Trusted Publishing.
|
|
650
689
|
|
|
651
690
|
## Limitations
|
|
652
691
|
|
|
653
692
|
`sqlx-js` is a young library. Known gaps:
|
|
654
693
|
|
|
655
694
|
- PostgreSQL only (no MySQL or SQLite).
|
|
656
|
-
- The scanner only follows direct named imports and namespace imports from `@onreza/sqlx-js
|
|
695
|
+
- The scanner only follows direct named imports and namespace imports from configured `scan.modules` (default: `@onreza/sqlx-js`); it does not discover re-export graphs, dynamic aliases, or tagged-template calls automatically.
|
|
657
696
|
- `SELECT *` falls back to conservative nullability.
|
|
658
697
|
- Plain `sql(...)` keeps returning rows, so statements without `RETURNING` produce an empty typed array. Use `sql.execute(...)` when affected-row count and command metadata matter.
|
|
659
698
|
- Nested CTE references (CTE-`b` referencing CTE-`a` in the same `WITH`) and `WITH RECURSIVE` are not analysed transitively — at worst this produces extra `T | null`. Use `AS "id!"` overrides if needed.
|
|
660
699
|
- Column names whose **real** name (not an alias) ends with `!` or `?` are not supported — the runtime strips those suffixes assuming an override. Use `AS "alias"` if you have such a column.
|
|
700
|
+
- Result columns must have unique names because Postgres.js returns object rows. Alias join projections such as `users.id AS user_id, posts.id AS post_id`; `prepare` rejects duplicate output names before generating declarations.
|
|
661
701
|
- Migrations run inside `BEGIN/COMMIT`. DDL that disallows transactions (`CREATE INDEX CONCURRENTLY`, `VACUUM`, `REINDEX CONCURRENTLY`, …) will fail; split such operations into separate migrations executed outside the runner.
|
|
662
702
|
- The **internal** wire client (used by `migrate run`, `prepare`, and the runtime `migrate()` helper) reads `sslmode`, `sslrootcert`/`sslcert`/`sslkey`, `application_name`, `connect_timeout`, and `statement_timeout` from `DATABASE_URL`. The default runtime `sql()` path delegates connection handling to Postgres.js; configure TLS, pooling, and timeouts through the `DATABASE_URL` and `createClient(...)` options it understands (`statementTimeoutMs` is a convenience that maps to a per-connection `statement_timeout`).
|
|
663
703
|
- `connect_timeout` bounds the entire internal-client connect, including the TLS handshake and SCRAM authentication.
|
package/ROADMAP.md
CHANGED
|
@@ -11,7 +11,7 @@ Items already shipped live in the [README](./README.md) feature list; this file
|
|
|
11
11
|
| Prisma migration assistant | 7 | Import Prisma Migrate SQL history and Prisma TypedSQL/raw SQL into `sqlx-js`; classify Prisma Client CRUD/nested-write sites as assisted/manual instead of promising a fully automatic ORM rewrite. |
|
|
12
12
|
| Self-join precision (unqualified ColumnRef) | 4 | `SELECT name FROM users u1 JOIN users u2 ON ...` with unqualified `name` can't be attributed to a specific alias. PG would reject ambiguous unqualified refs anyway, but explicit aliasing currently has no narrowing benefit in self-joins. |
|
|
13
13
|
| Tagged-template literal API (`` sql`SELECT ${x}` ``) | 8 | Restoring sqlx's inline-SQL aesthetic requires either a TS compiler plugin (`ts-patch`) or a Bun preload-time AST rewriter. TS itself hardcodes the first tag argument as `TemplateStringsArray` and refuses to narrow to literal tuples. Significant effort, large UX win. |
|
|
14
|
-
| LSP server | 6 | Realtime diagnostics, hover with column types, autocomplete on schema names. Versioned `prepare --json` diagnostics
|
|
14
|
+
| LSP server | 6 | Realtime diagnostics, hover with column types, autocomplete on schema names. Versioned `prepare --json` plus `sqlx-js-diagnostics` already cover GitHub annotations and editor problem matchers; a full server still needs separate VS Code / Neovim clients. |
|
|
15
15
|
| Schema-aware `jsonb` runtime validation | 5 | Optional opt-in: pass a Zod / Valibot / ArkType schema, validate rows on read. Currently we are compile-time-only by design. |
|
|
16
16
|
| MySQL backend | 5 | Some runtime clients support it, but MySQL has no `Describe Statement` equivalent. Would need a real SQL parser pass + `INFORMATION_SCHEMA` introspection. |
|
|
17
17
|
| SQLite backend | 4 | SQLite's column types are dynamic. Would require running `EXPLAIN` and a heuristic mapper, or schema-driven inference per-statement. |
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function optionalString(value, name) {
|
|
6
|
+
if (value !== undefined && typeof value !== "string")
|
|
7
|
+
throw new Error(`${name} must be a string`);
|
|
8
|
+
}
|
|
9
|
+
function optionalPosition(value, name) {
|
|
10
|
+
if (value !== undefined && (!Number.isInteger(value) || value < 1)) {
|
|
11
|
+
throw new Error(`${name} must be a positive integer`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function parsePayload(value) {
|
|
15
|
+
if (!isRecord(value) || value.formatVersion !== 1 || typeof value.ok !== "boolean" || !Array.isArray(value.diagnostics)) {
|
|
16
|
+
throw new Error("expected sqlx-js diagnostic formatVersion 1");
|
|
17
|
+
}
|
|
18
|
+
const diagnostics = value.diagnostics.map((item, index) => {
|
|
19
|
+
if (!isRecord(item))
|
|
20
|
+
throw new Error(`diagnostics[${index}] must be an object`);
|
|
21
|
+
if (item.severity !== "error" && item.severity !== "warning") {
|
|
22
|
+
throw new Error(`diagnostics[${index}].severity must be error or warning`);
|
|
23
|
+
}
|
|
24
|
+
if (typeof item.phase !== "string")
|
|
25
|
+
throw new Error(`diagnostics[${index}].phase must be a string`);
|
|
26
|
+
if (typeof item.message !== "string")
|
|
27
|
+
throw new Error(`diagnostics[${index}].message must be a string`);
|
|
28
|
+
optionalString(item.file, `diagnostics[${index}].file`);
|
|
29
|
+
optionalString(item.code, `diagnostics[${index}].code`);
|
|
30
|
+
optionalPosition(item.line, `diagnostics[${index}].line`);
|
|
31
|
+
optionalPosition(item.column, `diagnostics[${index}].column`);
|
|
32
|
+
return {
|
|
33
|
+
severity: item.severity,
|
|
34
|
+
phase: item.phase,
|
|
35
|
+
message: item.message,
|
|
36
|
+
...(item.file !== undefined ? { file: item.file } : {}),
|
|
37
|
+
...(item.line !== undefined ? { line: item.line } : {}),
|
|
38
|
+
...(item.column !== undefined ? { column: item.column } : {}),
|
|
39
|
+
...(item.code !== undefined ? { code: item.code } : {}),
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
return { formatVersion: 1, ok: value.ok, diagnostics };
|
|
43
|
+
}
|
|
44
|
+
function githubData(value) {
|
|
45
|
+
return value.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A");
|
|
46
|
+
}
|
|
47
|
+
function githubProperty(value) {
|
|
48
|
+
return githubData(value).replaceAll(":", "%3A").replaceAll(",", "%2C");
|
|
49
|
+
}
|
|
50
|
+
function renderGithub(diagnostic) {
|
|
51
|
+
const properties = [];
|
|
52
|
+
if (diagnostic.file)
|
|
53
|
+
properties.push(`file=${githubProperty(diagnostic.file)}`);
|
|
54
|
+
if (diagnostic.line !== undefined)
|
|
55
|
+
properties.push(`line=${diagnostic.line}`);
|
|
56
|
+
if (diagnostic.column !== undefined)
|
|
57
|
+
properties.push(`col=${diagnostic.column}`);
|
|
58
|
+
const propertyText = properties.length > 0 ? ` ${properties.join(",")}` : "";
|
|
59
|
+
const code = diagnostic.code ? ` ${diagnostic.code}` : "";
|
|
60
|
+
return `::${diagnostic.severity}${propertyText}::${githubData(`[${diagnostic.phase}${code}] ${diagnostic.message}`)}`;
|
|
61
|
+
}
|
|
62
|
+
function renderUnix(diagnostic) {
|
|
63
|
+
const clean = (value) => value.replace(/[\r\n]+/g, " ");
|
|
64
|
+
const file = clean(diagnostic.file ?? "<project>");
|
|
65
|
+
const line = diagnostic.line ?? 1;
|
|
66
|
+
const column = diagnostic.column ?? 1;
|
|
67
|
+
const code = diagnostic.code ? ` ${clean(diagnostic.code)}` : "";
|
|
68
|
+
return `${file}:${line}:${column}: ${diagnostic.severity}: [${clean(diagnostic.phase)}${code}] ${clean(diagnostic.message)}`;
|
|
69
|
+
}
|
|
70
|
+
function usage() {
|
|
71
|
+
console.log("usage: sqlx-js-diagnostics github|unix < prepare-diagnostics.json");
|
|
72
|
+
process.exit(0);
|
|
73
|
+
}
|
|
74
|
+
const format = process.argv[2];
|
|
75
|
+
if (format === "--help" || format === "-h")
|
|
76
|
+
usage();
|
|
77
|
+
if (format !== "github" && format !== "unix") {
|
|
78
|
+
console.error("sqlx-js-diagnostics: expected output format github or unix");
|
|
79
|
+
process.exit(2);
|
|
80
|
+
}
|
|
81
|
+
let input = "";
|
|
82
|
+
for await (const chunk of process.stdin)
|
|
83
|
+
input += chunk;
|
|
84
|
+
let payload;
|
|
85
|
+
try {
|
|
86
|
+
payload = parsePayload(JSON.parse(input));
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
console.error(`sqlx-js-diagnostics: ${error.message}`);
|
|
90
|
+
process.exit(2);
|
|
91
|
+
}
|
|
92
|
+
for (const diagnostic of payload.diagnostics) {
|
|
93
|
+
console.log(format === "github" ? renderGithub(diagnostic) : renderUnix(diagnostic));
|
|
94
|
+
}
|
|
95
|
+
process.exit(payload.ok ? 0 : 1);
|
|
96
|
+
export {};
|