@onreza/sqlx-js 0.9.1 → 0.9.2

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 CHANGED
@@ -512,7 +512,7 @@ Regular `prepare` describes queries across a small connection pool (default 8, o
512
512
  | `--json` | Machine-readable prepare diagnostics, doctor output, migration inspection and dry-runs. |
513
513
  | `--embed <path>` | For `queries`: write a deterministic TypeScript map of referenced external SQL files. |
514
514
  | `--jsonl` | Versioned streaming events for `prepare --watch`. |
515
- | `--strict-inference` | Fail prepare/dev/verify when nullability degrades or a generated query type contains `unknown`. |
515
+ | `--strict-inference` | Fail prepare/dev/verify when nullability degrades or a generated query type contains unresolved `unknown`. Intentional `JsonParameter<unknown>` wrappers remain accepted. |
516
516
  | `--force` | For `migrate archive restore`: allow overwriting existing migration files. |
517
517
  | `--lock-timeout <ms>` | Advisory-lock acquisition timeout for `migrate run` / `revert` / `dev` / `verify` / `squash`. |
518
518
  | `--shadow-url <url>` | Use an existing disposable shadow DB instead of auto-creating one. |
@@ -714,7 +714,7 @@ declare global {
714
714
  export {};
715
715
  ```
716
716
 
717
- After re-running `prepare`, every `jsonb` column or parameter declared in `jsonbTypes` is checked against the corresponding TypeScript type. Columns without a custom mapping use `JsonValue` for result rows and `JsonParameter<unknown>` for parameters: the existential parameter type accepts any wrapper already proven JSON-safe by `sql.json(value)` without requiring domain interfaces to declare a string index signature. Non-JSON inputs such as `Date`, functions, and `bigint` are rejected by TypeScript while plain JSON objects, arrays, strings, numbers, booleans, and nested JSON `null` values are accepted. A bare top-level `null` remains SQL `NULL` and is allowed only when the mapped database parameter is nullable; use `sql.json(null)` for JSON `null`.
717
+ After re-running `prepare`, every `jsonb` column or parameter declared in `jsonbTypes` is checked against the corresponding TypeScript type. Columns without a custom mapping use `JsonValue` for result rows and `JsonParameter<unknown>` for parameters: the existential parameter type accepts any wrapper already proven JSON-safe by `sql.json(value)` without requiring domain interfaces to declare a string index signature. `--strict-inference` accepts this intentional wrapper while continuing to reject unresolved `unknown` elsewhere in generated query contracts. Non-JSON inputs such as `Date`, functions, and `bigint` are rejected by TypeScript while plain JSON objects, arrays, strings, numbers, booleans, and nested JSON `null` values are accepted. A bare top-level `null` remains SQL `NULL` and is allowed only when the mapped database parameter is nullable; use `sql.json(null)` for JSON `null`.
718
718
 
719
719
  ### Direct scalar `columnTypes`
720
720
 
@@ -1,5 +1,16 @@
1
1
  import ts from "typescript";
2
2
  const unknownTypeCache = new Map();
3
+ function isExistentialJsonParameter(node) {
4
+ if (!ts.isImportTypeNode(node))
5
+ return false;
6
+ if (!ts.isLiteralTypeNode(node.argument) || !ts.isStringLiteral(node.argument.literal))
7
+ return false;
8
+ if (node.argument.literal.text !== "@onreza/sqlx-js")
9
+ return false;
10
+ if (!node.qualifier || !ts.isIdentifier(node.qualifier) || node.qualifier.text !== "JsonParameter")
11
+ return false;
12
+ return node.typeArguments?.length === 1 && node.typeArguments[0]?.kind === ts.SyntaxKind.UnknownKeyword;
13
+ }
3
14
  export function containsUnknownType(type) {
4
15
  const cached = unknownTypeCache.get(type);
5
16
  if (cached !== undefined)
@@ -7,6 +18,8 @@ export function containsUnknownType(type) {
7
18
  const source = ts.createSourceFile("sqlx-js-type.ts", `type SqlxJsType = ${type};`, ts.ScriptTarget.Latest, true);
8
19
  let found = false;
9
20
  const visit = (node) => {
21
+ if (isExistentialJsonParameter(node))
22
+ return;
10
23
  if (node.kind === ts.SyntaxKind.UnknownKeyword) {
11
24
  found = true;
12
25
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onreza/sqlx-js",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "Compile-time-checked raw SQL for TypeScript + PostgreSQL. Inspired by sqlx.",
5
5
  "license": "MIT",
6
6
  "type": "module",