@onreza/sqlx-js 0.4.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 +139 -48
- package/ROADMAP.md +1 -3
- 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 +337 -89
- package/dist/src/artifacts.d.ts +9 -0
- package/dist/src/artifacts.js +26 -0
- package/dist/src/cache.d.ts +17 -0
- package/dist/src/cache.js +83 -1
- package/dist/src/codegen.js +14 -2
- package/dist/src/commands/doctor.d.ts +16 -0
- package/dist/src/commands/doctor.js +196 -0
- package/dist/src/commands/init.js +93 -13
- package/dist/src/commands/migrate.d.ts +2 -101
- package/dist/src/commands/migrate.js +11 -566
- package/dist/src/commands/pgschema.d.ts +6 -0
- package/dist/src/commands/pgschema.js +30 -0
- package/dist/src/commands/prepare.d.ts +41 -6
- package/dist/src/commands/prepare.js +440 -63
- package/dist/src/commands/schema.js +1 -1
- package/dist/src/commands/watch.d.ts +1 -0
- package/dist/src/commands/watch.js +23 -9
- package/dist/src/config.d.ts +22 -0
- package/dist/src/config.js +149 -11
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.js +2 -1
- package/dist/src/migration-core.d.ts +157 -0
- package/dist/src/migration-core.js +578 -0
- package/dist/src/postgres-runtime.d.ts +3 -0
- package/dist/src/postgres-runtime.js +66 -29
- package/dist/src/runtime.d.ts +36 -3
- package/dist/src/runtime.js +92 -23
- package/dist/src/scan/scanner.d.ts +10 -3
- package/dist/src/scan/scanner.js +83 -32
- package/dist/src/type-inspection.d.ts +1 -0
- package/dist/src/type-inspection.js +20 -0
- package/dist/src/typed.d.ts +10 -0
- package/package.json +11 -6
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
const unknownTypeCache = new Map();
|
|
3
|
+
export function containsUnknownType(type) {
|
|
4
|
+
const cached = unknownTypeCache.get(type);
|
|
5
|
+
if (cached !== undefined)
|
|
6
|
+
return cached;
|
|
7
|
+
const source = ts.createSourceFile("sqlx-js-type.ts", `type SqlxJsType = ${type};`, ts.ScriptTarget.Latest, true);
|
|
8
|
+
let found = false;
|
|
9
|
+
const visit = (node) => {
|
|
10
|
+
if (node.kind === ts.SyntaxKind.UnknownKeyword) {
|
|
11
|
+
found = true;
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (!found)
|
|
15
|
+
ts.forEachChild(node, visit);
|
|
16
|
+
};
|
|
17
|
+
visit(source);
|
|
18
|
+
unknownTypeCache.set(type, found);
|
|
19
|
+
return found;
|
|
20
|
+
}
|
package/dist/src/typed.d.ts
CHANGED
|
@@ -4,17 +4,27 @@ type ParamsOf<T> = T extends {
|
|
|
4
4
|
type RowOf<T> = T extends {
|
|
5
5
|
row: infer R;
|
|
6
6
|
} ? R : never;
|
|
7
|
+
type ExecuteResult = import("./runtime.js").ExecuteResult;
|
|
8
|
+
type JsonInputValue = import("./runtime.js").JsonInputValue;
|
|
9
|
+
type JsonParameter<T> = import("./runtime.js").JsonParameter<T>;
|
|
10
|
+
type PgArrayParameter<T> = import("./runtime.js").PgArrayParameter<T>;
|
|
11
|
+
type JsonFn = <T extends JsonInputValue>(value: T) => JsonParameter<T>;
|
|
12
|
+
type ArrayFn = <T>(value: readonly (T | null)[]) => PgArrayParameter<T>;
|
|
7
13
|
export type TypedFile<TFileQueries> = {
|
|
8
14
|
<P extends keyof TFileQueries>(path: P, ...params: ParamsOf<TFileQueries[P]>): Promise<RowOf<TFileQueries[P]>[]>;
|
|
9
15
|
one: <P extends keyof TFileQueries>(path: P, ...params: ParamsOf<TFileQueries[P]>) => Promise<RowOf<TFileQueries[P]>>;
|
|
10
16
|
optional: <P extends keyof TFileQueries>(path: P, ...params: ParamsOf<TFileQueries[P]>) => Promise<RowOf<TFileQueries[P]> | null>;
|
|
17
|
+
execute: <P extends keyof TFileQueries>(path: P, ...params: ParamsOf<TFileQueries[P]>) => Promise<ExecuteResult>;
|
|
11
18
|
};
|
|
12
19
|
export type TypedSql<TQueries, TFileQueries> = {
|
|
13
20
|
<Q extends keyof TQueries>(query: Q, ...params: ParamsOf<TQueries[Q]>): Promise<RowOf<TQueries[Q]>[]>;
|
|
14
21
|
one: <Q extends keyof TQueries>(query: Q, ...params: ParamsOf<TQueries[Q]>) => Promise<RowOf<TQueries[Q]>>;
|
|
15
22
|
optional: <Q extends keyof TQueries>(query: Q, ...params: ParamsOf<TQueries[Q]>) => Promise<RowOf<TQueries[Q]> | null>;
|
|
23
|
+
execute: <Q extends keyof TQueries>(query: Q, ...params: ParamsOf<TQueries[Q]>) => Promise<ExecuteResult>;
|
|
16
24
|
file: TypedFile<TFileQueries>;
|
|
17
25
|
id: (...parts: string[]) => string;
|
|
26
|
+
json: JsonFn;
|
|
27
|
+
array: ArrayFn;
|
|
18
28
|
};
|
|
19
29
|
export type Typed<TQueries, TFileQueries, TTransactionOptions> = TypedSql<TQueries, TFileQueries> & {
|
|
20
30
|
transaction: {
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onreza/sqlx-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Compile-time-checked raw SQL for TypeScript + PostgreSQL. Inspired by sqlx.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=24",
|
|
9
|
+
"bun": ">=1.3"
|
|
9
10
|
},
|
|
10
11
|
"sideEffects": false,
|
|
11
12
|
"main": "./dist/src/index.js",
|
|
@@ -18,7 +19,8 @@
|
|
|
18
19
|
}
|
|
19
20
|
},
|
|
20
21
|
"bin": {
|
|
21
|
-
"sqlx-js": "dist/bin/sqlx-js.js"
|
|
22
|
+
"sqlx-js": "dist/bin/sqlx-js.js",
|
|
23
|
+
"sqlx-js-diagnostics": "dist/bin/sqlx-js-diagnostics.js"
|
|
22
24
|
},
|
|
23
25
|
"files": [
|
|
24
26
|
"dist",
|
|
@@ -49,13 +51,16 @@
|
|
|
49
51
|
"migrations"
|
|
50
52
|
],
|
|
51
53
|
"scripts": {
|
|
52
|
-
"prepare": "
|
|
53
|
-
"test": "bun test tests",
|
|
54
|
+
"prepare": "node scripts/prepare-package.mjs",
|
|
55
|
+
"test": "bun test tests --timeout 120000",
|
|
54
56
|
"test:typecheck": "tsc --noEmit",
|
|
55
57
|
"test:example": "bunx tsc -p example --noEmit",
|
|
58
|
+
"test:runtime-boundary": "bun run build && node scripts/check-runtime-boundary.mjs",
|
|
59
|
+
"test:node-package": "node scripts/node-package-smoke.mjs",
|
|
60
|
+
"test:corpus": "bun scripts/check-production-corpus.ts",
|
|
56
61
|
"sqlx:prepare": "bun bin/sqlx-js.ts prepare",
|
|
57
62
|
"sqlx:migrate": "bun bin/sqlx-js.ts migrate",
|
|
58
|
-
"build": "
|
|
63
|
+
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json && bun scripts/fix-dist-imports.ts",
|
|
59
64
|
"prepack": "bun run build"
|
|
60
65
|
},
|
|
61
66
|
"peerDependencies": {
|