@typed-sql/compiler 2.0.0-rc.1 → 2.1.0-rc.1
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 +89 -0
- package/README.md +14 -0
- package/dist/packages/compiler/src/analysis.d.ts +93 -0
- package/dist/packages/compiler/src/analysis.d.ts.map +1 -0
- package/dist/packages/compiler/src/analysis.js +149 -0
- package/dist/packages/compiler/src/analysis.js.map +1 -0
- package/dist/packages/compiler/src/check.d.ts +5 -0
- package/dist/packages/compiler/src/check.d.ts.map +1 -1
- package/dist/packages/compiler/src/check.js +40 -14
- package/dist/packages/compiler/src/check.js.map +1 -1
- package/dist/packages/compiler/src/compatibility.d.ts +7 -5
- package/dist/packages/compiler/src/compatibility.d.ts.map +1 -1
- package/dist/packages/compiler/src/compatibility.js +312 -11
- package/dist/packages/compiler/src/compatibility.js.map +1 -1
- package/dist/packages/compiler/src/compiler.d.ts +30 -1
- package/dist/packages/compiler/src/compiler.d.ts.map +1 -1
- package/dist/packages/compiler/src/compiler.js +162 -17
- package/dist/packages/compiler/src/compiler.js.map +1 -1
- package/dist/packages/compiler/src/index.d.ts +7 -3
- package/dist/packages/compiler/src/index.d.ts.map +1 -1
- package/dist/packages/compiler/src/index.js +3 -1
- package/dist/packages/compiler/src/index.js.map +1 -1
- package/dist/packages/compiler/src/manifest.d.ts +162 -1
- package/dist/packages/compiler/src/manifest.d.ts.map +1 -1
- package/dist/packages/compiler/src/manifest.js +233 -22
- package/dist/packages/compiler/src/manifest.js.map +1 -1
- package/dist/packages/compiler/src/plans.d.ts +1 -0
- package/dist/packages/compiler/src/plans.d.ts.map +1 -1
- package/dist/packages/compiler/src/plans.js +6 -1
- package/dist/packages/compiler/src/plans.js.map +1 -1
- package/dist/packages/compiler/src/repeated-fragments.d.ts +20 -0
- package/dist/packages/compiler/src/repeated-fragments.d.ts.map +1 -0
- package/dist/packages/compiler/src/repeated-fragments.js +108 -0
- package/dist/packages/compiler/src/repeated-fragments.js.map +1 -0
- package/dist/packages/compiler/src/scanner.d.ts +17 -0
- package/dist/packages/compiler/src/scanner.d.ts.map +1 -1
- package/dist/packages/compiler/src/scanner.js +213 -1
- package/dist/packages/compiler/src/scanner.js.map +1 -1
- package/dist/packages/compiler/src/typescript.d.ts +16 -0
- package/dist/packages/compiler/src/typescript.d.ts.map +1 -0
- package/dist/packages/compiler/src/typescript.js +35 -0
- package/dist/packages/compiler/src/typescript.js.map +1 -0
- package/dist/packages/compiler/src/verification.d.ts +3 -0
- package/dist/packages/compiler/src/verification.d.ts.map +1 -1
- package/dist/packages/compiler/src/verification.js +15 -0
- package/dist/packages/compiler/src/verification.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,94 @@
|
|
|
1
1
|
# @typed-sql/compiler
|
|
2
2
|
|
|
3
|
+
## 2.1.0-rc.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Publish the coherent 2.1.0-rc.1 release-candidate train.
|
|
8
|
+
|
|
9
|
+
## 2.1.0-rc.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 58bd4d1: Add the versioned, serializable source-analysis service shared by batch checks and editor tooling.
|
|
14
|
+
Results carry deterministic source, project, schema, type-policy, grammar, and capability identities;
|
|
15
|
+
cancellation and source, query-count, structural-variant, and generated-declaration limits fail closed.
|
|
16
|
+
- e433feb: Allow non-empty arrays of typed SQL fragments to be interpolated directly as homogeneous,
|
|
17
|
+
comma-separated structure. Add fail-closed compiler analysis for direct map callbacks and fragment
|
|
18
|
+
literals, cardinality-independent artifacts, bounded prepared-cardinality caches, shared grammar
|
|
19
|
+
conformance, and runtime limits while preserving ordinary arrays as single bound values.
|
|
20
|
+
- 1c64475: Add canonical schema snapshot format 2 with isolated v1/v2 codecs, conservative v1 upgrades,
|
|
21
|
+
neutral relation/constraint/index/type/routine evidence, and complete provider introspection.
|
|
22
|
+
Resolvers now consume structural write and routine evidence, while drift, compatibility, manifests,
|
|
23
|
+
verification proofs, and plan artifacts bind to the schema format and canonical hash.
|
|
24
|
+
- 4a12de5: Reject unsupported TypeScript compiler and preview patches before project work begins. Add
|
|
25
|
+
`typed-sql doctor` with human and JSON reports for Node.js, TypeScript, grammar, schema, redacted
|
|
26
|
+
server evidence, language-server/bridge metadata, and editor protocol compatibility.
|
|
27
|
+
- 1c64475: Add deterministic versioned dialect capability states backed by normalized server versions,
|
|
28
|
+
settings, extensions, and compile options. Query manifests now invalidate on capability changes and
|
|
29
|
+
record evidence for capabilities each query uses, while the CLI exposes a human-readable capability
|
|
30
|
+
report. The boolean capability map remains available as an additive migration bridge.
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- 58aa9ef: Add a grammar-neutral serialized artifact compatibility identity and deterministic compatibility outcomes, and use the shared identity contract for query-manifest cache reuse.
|
|
35
|
+
- Updated dependencies [58bd4d1]
|
|
36
|
+
- Updated dependencies [58aa9ef]
|
|
37
|
+
- Updated dependencies [65b662f]
|
|
38
|
+
- Updated dependencies [e433feb]
|
|
39
|
+
- Updated dependencies [0efc90c]
|
|
40
|
+
- Updated dependencies [ff0e3bb]
|
|
41
|
+
- Updated dependencies [6f5b977]
|
|
42
|
+
- Updated dependencies [1c64475]
|
|
43
|
+
- Updated dependencies [1c64475]
|
|
44
|
+
- Updated dependencies [1c64475]
|
|
45
|
+
- Updated dependencies [1c64475]
|
|
46
|
+
- @typed-sql/core@2.1.0-rc.0
|
|
47
|
+
- @typed-sql/schema@2.1.0-rc.0
|
|
48
|
+
|
|
49
|
+
## 2.0.0
|
|
50
|
+
|
|
51
|
+
### Major Changes
|
|
52
|
+
|
|
53
|
+
- 3f063f6: Add deterministic, secret-free query manifests with bounded structural variants, inferred result
|
|
54
|
+
and parameter descriptions, semantic evidence, runtime-correlatable fingerprints, unresolved
|
|
55
|
+
entries, compatible parsing, canonical serialization, incremental per-file reuse, tsconfig project
|
|
56
|
+
discovery, and a dedicated CLI command.
|
|
57
|
+
- 6a7ae58: Add opt-in live query verification through grammar-owned PostgreSQL PREPARE and MySQL
|
|
58
|
+
COM_STMT_PREPARE adapters, bounded neutral comparison, deterministic secret-free proof artifacts,
|
|
59
|
+
offline cache validation, explicit unsupported classifications, CLI workflows, real database E2E,
|
|
60
|
+
and performance budgets.
|
|
61
|
+
- 3050209: Add the dialect contract v4 semantic query evidence foundation. PostgreSQL and MySQL now report operation, dependencies, cardinality, volatility, locking, connection affinity, and required capabilities; compiler results add deterministic query and structural-variant fingerprints and conservatively merged source-mapped semantics. Schema snapshots can record function volatility, and the AST package exposes a neutral statement walker for grammar implementations.
|
|
62
|
+
- b4f1b6e: Add deterministic migration compatibility analysis across before/after schema snapshots and query
|
|
63
|
+
manifests. Reports classify both rolling-deployment directions, retain exact source and dependency
|
|
64
|
+
evidence, fail closed for unknown semantics, redact defaults and paths, and support configurable CI
|
|
65
|
+
severity through `typed-sql compat`.
|
|
66
|
+
- b2ec119: Add opt-in, grammar-neutral query-plan governance with PostgreSQL and MySQL structured EXPLAIN
|
|
67
|
+
adapters, transient application-owned samples, redacted fingerprint-keyed artifacts, absolute and
|
|
68
|
+
comparable regression budgets, explicit uncertainty, CLI capture and review, documentation, and
|
|
69
|
+
performance coverage.
|
|
70
|
+
|
|
71
|
+
### Minor Changes
|
|
72
|
+
|
|
73
|
+
- 9c72dab: Use live MySQL catalog origins to preserve enum result evidence, and compare parameter metadata in
|
|
74
|
+
the safe input direction so compiler-enforced literal subsets do not become false mismatches.
|
|
75
|
+
|
|
76
|
+
### Patch Changes
|
|
77
|
+
|
|
78
|
+
- Updated dependencies [7ea5d2f]
|
|
79
|
+
- Updated dependencies [29afc3d]
|
|
80
|
+
- Updated dependencies [3f063f6]
|
|
81
|
+
- Updated dependencies [6a7ae58]
|
|
82
|
+
- Updated dependencies [b06fd0a]
|
|
83
|
+
- Updated dependencies [3050209]
|
|
84
|
+
- Updated dependencies [1b054b6]
|
|
85
|
+
- Updated dependencies [b4f1b6e]
|
|
86
|
+
- Updated dependencies [87189c3]
|
|
87
|
+
- Updated dependencies [e654fae]
|
|
88
|
+
- Updated dependencies [b2ec119]
|
|
89
|
+
- @typed-sql/core@2.0.0
|
|
90
|
+
- @typed-sql/schema@2.0.0
|
|
91
|
+
|
|
3
92
|
## 2.0.0-rc.1
|
|
4
93
|
|
|
5
94
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -23,6 +23,12 @@ const result = compileSource({
|
|
|
23
23
|
});
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
For batch/editor parity and incremental consumers, `createSourceAnalysisService()` accepts a
|
|
27
|
+
serializable `SourceAnalysisRequest` and returns a versioned `SourceAnalysisResult`. The result
|
|
28
|
+
contains the same transform and diagnostics as `compileSource`, plus source/project, grammar and
|
|
29
|
+
capability, schema, type-policy, compiler-option, and revision identities. `checkFile()` uses this
|
|
30
|
+
service and exposes its result as `analysis`.
|
|
31
|
+
|
|
26
32
|
`compileSource` consumes only `DialectPlugin`; it does not branch on a database, grammar package,
|
|
27
33
|
or driver. Compiled queries expose path-independent SHA-256 fingerprints, variant fingerprints,
|
|
28
34
|
variant descriptions, and source-mapped semantics merged conservatively across conditional
|
|
@@ -31,6 +37,14 @@ generating an application API. Its public options include the structural-variant
|
|
|
31
37
|
conditional fragments. Application projects normally use the compiler through `typed-sql check`
|
|
32
38
|
or the language server.
|
|
33
39
|
|
|
40
|
+
Source bytes, static query count, structural variants, and generated declaration bytes have finite
|
|
41
|
+
defaults and explicit overrides. Exceeding a limit returns `TSQ006`, the unchanged source overlay,
|
|
42
|
+
and no inferred query contract. Cancellation raises `AbortError` before a partial result is returned.
|
|
43
|
+
|
|
44
|
+
Native `checkFile()` verification executes only TypeScript 7.0.2. It reads `tsc --version` before
|
|
45
|
+
writing a temporary overlay and throws `TypeScriptCompilerCompatibilityError` with remediation for
|
|
46
|
+
an untested patch or another line.
|
|
47
|
+
|
|
34
48
|
Live verification APIs collect transient SQL only after sources still match the manifest, schedule
|
|
35
49
|
grammar-owned adapters with bounded concurrency, compare native field evidence, and emit canonical
|
|
36
50
|
proofs that contain no SQL, values, URLs, absolute paths, or driver errors.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type DialectPlugin, type SchemaSnapshot } from "@typed-sql/core";
|
|
2
|
+
import { compileSource } from "./compiler.js";
|
|
3
|
+
export declare const SOURCE_ANALYSIS_FORMAT_VERSION: 1;
|
|
4
|
+
export interface SourceAnalysisRange {
|
|
5
|
+
readonly start: number;
|
|
6
|
+
readonly end: number;
|
|
7
|
+
}
|
|
8
|
+
export interface SourceAnalysisBinding {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly range: SourceAnalysisRange;
|
|
11
|
+
}
|
|
12
|
+
export interface SourceAnalysisQuery {
|
|
13
|
+
readonly index: number;
|
|
14
|
+
readonly rowType: string;
|
|
15
|
+
readonly parameterType: string;
|
|
16
|
+
readonly queryType: string;
|
|
17
|
+
readonly sourceRange: SourceAnalysisRange;
|
|
18
|
+
readonly transformedRange: SourceAnalysisRange;
|
|
19
|
+
readonly interpolationRanges: readonly SourceAnalysisRange[];
|
|
20
|
+
readonly binding?: SourceAnalysisBinding;
|
|
21
|
+
}
|
|
22
|
+
export interface SourceAnalysisInsertion {
|
|
23
|
+
readonly position: number;
|
|
24
|
+
readonly length: number;
|
|
25
|
+
}
|
|
26
|
+
export interface SourceAnalysisProjectIdentity {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly generation: number;
|
|
29
|
+
readonly configHash: string;
|
|
30
|
+
}
|
|
31
|
+
export interface SourceAnalysisRequest {
|
|
32
|
+
readonly formatVersion: typeof SOURCE_ANALYSIS_FORMAT_VERSION;
|
|
33
|
+
readonly source: {
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly text: string;
|
|
36
|
+
readonly version?: number | string;
|
|
37
|
+
};
|
|
38
|
+
readonly project?: SourceAnalysisProjectIdentity;
|
|
39
|
+
readonly compiler?: {
|
|
40
|
+
readonly maxStructuralVariants?: number;
|
|
41
|
+
readonly maxSourceBytes?: number;
|
|
42
|
+
readonly maxQueries?: number;
|
|
43
|
+
readonly maxGeneratedDeclarationBytes?: number;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface SourceAnalysisContext<Snapshot extends SchemaSnapshot, Policy> {
|
|
47
|
+
readonly dialect: DialectPlugin<Snapshot, Policy>;
|
|
48
|
+
readonly schema: Snapshot;
|
|
49
|
+
readonly typePolicy?: Policy;
|
|
50
|
+
}
|
|
51
|
+
export interface SourceAnalysisControl {
|
|
52
|
+
readonly isCancellationRequested: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface SourceAnalysisIdentity {
|
|
55
|
+
readonly source: {
|
|
56
|
+
readonly id: string;
|
|
57
|
+
readonly hash: string;
|
|
58
|
+
readonly version?: number | string;
|
|
59
|
+
};
|
|
60
|
+
readonly project?: SourceAnalysisProjectIdentity;
|
|
61
|
+
readonly grammar: {
|
|
62
|
+
readonly id: string;
|
|
63
|
+
readonly version: string;
|
|
64
|
+
readonly capabilityFingerprint: string;
|
|
65
|
+
};
|
|
66
|
+
readonly schema: {
|
|
67
|
+
readonly formatVersion: 1 | 2;
|
|
68
|
+
readonly hash: string;
|
|
69
|
+
};
|
|
70
|
+
readonly typePolicyHash: string;
|
|
71
|
+
readonly compiler: {
|
|
72
|
+
readonly maxStructuralVariants: number;
|
|
73
|
+
readonly maxSourceBytes: number;
|
|
74
|
+
readonly maxQueries: number;
|
|
75
|
+
readonly maxGeneratedDeclarationBytes: number;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export interface SourceAnalysisResult {
|
|
79
|
+
readonly formatVersion: typeof SOURCE_ANALYSIS_FORMAT_VERSION;
|
|
80
|
+
readonly revision: string;
|
|
81
|
+
readonly identity: SourceAnalysisIdentity;
|
|
82
|
+
readonly source: string;
|
|
83
|
+
readonly transformedSource: string;
|
|
84
|
+
readonly insertions: readonly SourceAnalysisInsertion[];
|
|
85
|
+
readonly queries: readonly SourceAnalysisQuery[];
|
|
86
|
+
readonly diagnostics: ReturnType<typeof compileSource>["diagnostics"];
|
|
87
|
+
}
|
|
88
|
+
export interface SourceAnalysisService {
|
|
89
|
+
analyze(request: SourceAnalysisRequest, control?: SourceAnalysisControl): SourceAnalysisResult;
|
|
90
|
+
}
|
|
91
|
+
export declare function analyzeSource<Snapshot extends SchemaSnapshot, Policy>(request: SourceAnalysisRequest, context: SourceAnalysisContext<Snapshot, Policy>, control?: SourceAnalysisControl): SourceAnalysisResult;
|
|
92
|
+
export declare function createSourceAnalysisService<Snapshot extends SchemaSnapshot, Policy>(context: SourceAnalysisContext<Snapshot, Policy>): SourceAnalysisService;
|
|
93
|
+
//# sourceMappingURL=analysis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analysis.d.ts","sourceRoot":"","sources":["../../../../src/analysis.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAkC,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAE1G,OAAO,EAEL,aAAa,EAKd,MAAM,eAAe,CAAC;AAEvB,eAAO,MAAM,8BAA8B,EAAG,CAAU,CAAC;AAEzD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;CACrC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAA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iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,SAAS,uBAAuB,EAAE,CAAC;IACxD,QAAQ,CAAC,OAAO,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACjD,QAAQ,CAAC,WAAW,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,aAAa,CAAC,CAAC;CACvE;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,OAAO,EAAE,qBAAqB,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,oBAAoB,CAAC;CAChG;AA4ED,wBAAgB,aAAa,CAAC,QAAQ,SAAS,cAAc,EAAE,MAAM,EACnE,OAAO,EAAE,qBAAqB,EAC9B,OAAO,EAAE,qBAAqB,CAAC,QAAQ,EAAE,MAAM,CAAC,EAChD,OAAO,CAAC,EAAE,qBAAqB,GAC9B,oBAAoB,CAuFtB;AAED,wBAAgB,2BAA2B,CAAC,QAAQ,SAAS,cAAc,EAAE,MAAM,EACjF,OAAO,EAAE,qBAAqB,CAAC,QAAQ,EAAE,MAAM,CAAC,GAC/C,qBAAqB,CAKvB"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { resolveDialectCapabilityStates } from "@typed-sql/core";
|
|
3
|
+
import { calculateSchemaHash, calculateTypePolicyHash } from "@typed-sql/schema";
|
|
4
|
+
import { compileSource, DEFAULT_MAX_GENERATED_DECLARATION_BYTES, DEFAULT_MAX_QUERIES, DEFAULT_MAX_SOURCE_BYTES, DEFAULT_MAX_STRUCTURAL_VARIANTS, } from "./compiler.js";
|
|
5
|
+
export const SOURCE_ANALYSIS_FORMAT_VERSION = 1;
|
|
6
|
+
const sha256 = (value) => `sha256:${createHash("sha256").update(value).digest("hex")}`;
|
|
7
|
+
function cancelled(control) {
|
|
8
|
+
if (control?.isCancellationRequested !== true)
|
|
9
|
+
return;
|
|
10
|
+
const error = new Error("typed-sql source analysis cancelled");
|
|
11
|
+
error.name = "AbortError";
|
|
12
|
+
throw error;
|
|
13
|
+
}
|
|
14
|
+
function bindingBefore(source, tagStart) {
|
|
15
|
+
const prefix = source.slice(0, tagStart);
|
|
16
|
+
const match = /(?:^|[;{}]\s*|\n\s*)(?:export\s+)?(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*$/u.exec(prefix);
|
|
17
|
+
if (match === null)
|
|
18
|
+
return undefined;
|
|
19
|
+
const name = match[1];
|
|
20
|
+
if (name === undefined)
|
|
21
|
+
return undefined;
|
|
22
|
+
const relativeStart = match[0].lastIndexOf(name);
|
|
23
|
+
const start = match.index + relativeStart;
|
|
24
|
+
return { name, range: { start, end: start + name.length } };
|
|
25
|
+
}
|
|
26
|
+
function positiveLimit(value, fallback, name) {
|
|
27
|
+
const result = value ?? fallback;
|
|
28
|
+
if (!Number.isSafeInteger(result) || result < 1)
|
|
29
|
+
throw new TypeError(`${name} must be a positive safe integer`);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
function validateRequest(request) {
|
|
33
|
+
if (request.formatVersion !== SOURCE_ANALYSIS_FORMAT_VERSION) {
|
|
34
|
+
throw new TypeError(`Unsupported source analysis request format ${String(request.formatVersion)}`);
|
|
35
|
+
}
|
|
36
|
+
if (request.source.id.length === 0 || request.source.id.includes("\0")) {
|
|
37
|
+
throw new TypeError("Source analysis id must be a non-empty string without null bytes");
|
|
38
|
+
}
|
|
39
|
+
const version = request.source.version;
|
|
40
|
+
if (version !== undefined &&
|
|
41
|
+
!((typeof version === "number" && Number.isSafeInteger(version) && version >= 0) ||
|
|
42
|
+
(typeof version === "string" && version.length > 0 && !version.includes("\0")))) {
|
|
43
|
+
throw new TypeError("Source analysis version must be a non-negative integer or non-empty string");
|
|
44
|
+
}
|
|
45
|
+
const project = request.project;
|
|
46
|
+
if (project !== undefined &&
|
|
47
|
+
(project.id.length === 0 ||
|
|
48
|
+
project.id.includes("\0") ||
|
|
49
|
+
!Number.isSafeInteger(project.generation) ||
|
|
50
|
+
project.generation < 0 ||
|
|
51
|
+
project.configHash.length === 0 ||
|
|
52
|
+
project.configHash.includes("\0"))) {
|
|
53
|
+
throw new TypeError("Source analysis project identity is invalid");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function resolvedCompilerOptions(request) {
|
|
57
|
+
return Object.freeze({
|
|
58
|
+
maxStructuralVariants: positiveLimit(request.compiler?.maxStructuralVariants, DEFAULT_MAX_STRUCTURAL_VARIANTS, "maxStructuralVariants"),
|
|
59
|
+
maxSourceBytes: positiveLimit(request.compiler?.maxSourceBytes, DEFAULT_MAX_SOURCE_BYTES, "maxSourceBytes"),
|
|
60
|
+
maxQueries: positiveLimit(request.compiler?.maxQueries, DEFAULT_MAX_QUERIES, "maxQueries"),
|
|
61
|
+
maxGeneratedDeclarationBytes: positiveLimit(request.compiler?.maxGeneratedDeclarationBytes, DEFAULT_MAX_GENERATED_DECLARATION_BYTES, "maxGeneratedDeclarationBytes"),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export function analyzeSource(request, context, control) {
|
|
65
|
+
validateRequest(request);
|
|
66
|
+
cancelled(control);
|
|
67
|
+
const compiler = resolvedCompilerOptions(request);
|
|
68
|
+
const effectiveTypePolicy = context.typePolicy ?? context.dialect.defaultTypePolicy;
|
|
69
|
+
const capabilityStates = resolveDialectCapabilityStates(context.dialect, context.schema, effectiveTypePolicy);
|
|
70
|
+
const identity = Object.freeze({
|
|
71
|
+
source: Object.freeze({
|
|
72
|
+
id: request.source.id,
|
|
73
|
+
hash: sha256(request.source.text),
|
|
74
|
+
...(request.source.version === undefined ? {} : { version: request.source.version }),
|
|
75
|
+
}),
|
|
76
|
+
...(request.project === undefined ? {} : { project: Object.freeze({ ...request.project }) }),
|
|
77
|
+
grammar: Object.freeze({
|
|
78
|
+
id: context.dialect.id,
|
|
79
|
+
version: context.dialect.grammarVersion,
|
|
80
|
+
capabilityFingerprint: sha256(JSON.stringify(capabilityStates)),
|
|
81
|
+
}),
|
|
82
|
+
schema: Object.freeze({
|
|
83
|
+
formatVersion: context.schema.formatVersion,
|
|
84
|
+
hash: calculateSchemaHash(context.schema),
|
|
85
|
+
}),
|
|
86
|
+
typePolicyHash: calculateTypePolicyHash(effectiveTypePolicy),
|
|
87
|
+
compiler,
|
|
88
|
+
});
|
|
89
|
+
const revision = sha256(JSON.stringify(identity));
|
|
90
|
+
const compilationOptions = {
|
|
91
|
+
source: request.source.text,
|
|
92
|
+
dialect: context.dialect,
|
|
93
|
+
schema: context.schema,
|
|
94
|
+
typePolicy: effectiveTypePolicy,
|
|
95
|
+
...compiler,
|
|
96
|
+
};
|
|
97
|
+
const compilation = compileSource(compilationOptions);
|
|
98
|
+
cancelled(control);
|
|
99
|
+
const insertions = Object.freeze([
|
|
100
|
+
...compilation.queries.map(({ query, rowType, parameterType, structural, fragmentList }) => ({
|
|
101
|
+
position: query.insertionPosition,
|
|
102
|
+
length: fragmentList === true
|
|
103
|
+
? `.__typedRow<${rowType}>()`.length
|
|
104
|
+
: structural
|
|
105
|
+
? rowType.length + parameterType.length + 14
|
|
106
|
+
: rowType.length + parameterType.length + 4,
|
|
107
|
+
})),
|
|
108
|
+
...compilation.fragments.map(({ fragment, parameterType }) => ({
|
|
109
|
+
position: fragment.insertionPosition,
|
|
110
|
+
length: parameterType.length + 2,
|
|
111
|
+
})),
|
|
112
|
+
].sort((left, right) => left.position - right.position));
|
|
113
|
+
const shiftBefore = (position) => insertions.reduce((total, insertion) => total + (insertion.position < position ? insertion.length : 0), 0);
|
|
114
|
+
const queries = Object.freeze(compilation.queries.map(({ query, rowType, parameterType }, index) => ({
|
|
115
|
+
index,
|
|
116
|
+
rowType,
|
|
117
|
+
parameterType,
|
|
118
|
+
queryType: `Query<${rowType}, ${parameterType}>`,
|
|
119
|
+
sourceRange: { start: query.range.start, end: query.range.end },
|
|
120
|
+
transformedRange: {
|
|
121
|
+
start: query.range.start + shiftBefore(query.range.start),
|
|
122
|
+
end: query.range.end + shiftBefore(query.range.end),
|
|
123
|
+
},
|
|
124
|
+
interpolationRanges: query.interpolations.map(({ sourceStart, sourceEnd }) => ({
|
|
125
|
+
start: sourceStart,
|
|
126
|
+
end: sourceEnd,
|
|
127
|
+
})),
|
|
128
|
+
...(() => {
|
|
129
|
+
const binding = bindingBefore(request.source.text, query.range.start);
|
|
130
|
+
return binding === undefined ? {} : { binding };
|
|
131
|
+
})(),
|
|
132
|
+
})));
|
|
133
|
+
return Object.freeze({
|
|
134
|
+
formatVersion: SOURCE_ANALYSIS_FORMAT_VERSION,
|
|
135
|
+
revision,
|
|
136
|
+
identity,
|
|
137
|
+
source: request.source.text,
|
|
138
|
+
transformedSource: compilation.transformedSource,
|
|
139
|
+
insertions,
|
|
140
|
+
queries,
|
|
141
|
+
diagnostics: compilation.diagnostics,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
export function createSourceAnalysisService(context) {
|
|
145
|
+
return Object.freeze({
|
|
146
|
+
analyze: (request, control) => analyzeSource(request, context, control),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=analysis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analysis.js","sourceRoot":"","sources":["../../../../src/analysis.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAsB,8BAA8B,EAAuB,MAAM,iBAAiB,CAAC;AAC1G,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAEL,aAAa,EACb,uCAAuC,EACvC,mBAAmB,EACnB,wBAAwB,EACxB,+BAA+B,GAChC,MAAM,eAAe,CAAC;AAEvB,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAU,CAAC;AAoGzD,MAAM,MAAM,GAAG,CAAC,KAAa,EAAU,EAAE,CAAC,UAAU,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAA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C,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;KAC3C,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DialectPlugin, SchemaSnapshot, SqlDiagnostic } from "@typed-sql/core";
|
|
2
|
+
import { type SourceAnalysisResult } from "./analysis.js";
|
|
2
3
|
export interface CheckFileOptions<Snapshot extends SchemaSnapshot = SchemaSnapshot, Policy = unknown> {
|
|
3
4
|
readonly file: string;
|
|
4
5
|
readonly schema: string | SchemaSnapshot;
|
|
@@ -7,6 +8,9 @@ export interface CheckFileOptions<Snapshot extends SchemaSnapshot = SchemaSnapsh
|
|
|
7
8
|
readonly project?: string;
|
|
8
9
|
readonly runTypeScript?: boolean;
|
|
9
10
|
readonly maxStructuralVariants?: number;
|
|
11
|
+
readonly maxSourceBytes?: number;
|
|
12
|
+
readonly maxQueries?: number;
|
|
13
|
+
readonly maxGeneratedDeclarationBytes?: number;
|
|
10
14
|
readonly typeScriptTimeoutMs?: number;
|
|
11
15
|
}
|
|
12
16
|
export interface TypeScriptCheckResult {
|
|
@@ -15,6 +19,7 @@ export interface TypeScriptCheckResult {
|
|
|
15
19
|
readonly command: string;
|
|
16
20
|
}
|
|
17
21
|
export interface CheckFileResult {
|
|
22
|
+
readonly analysis: SourceAnalysisResult;
|
|
18
23
|
readonly transformedSource: string;
|
|
19
24
|
readonly sqlDiagnostics: readonly SqlDiagnostic[];
|
|
20
25
|
readonly typeScript?: TypeScriptCheckResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../../../src/check.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../../../src/check.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa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,SAAS,cAAc,EAAE,MAAM,EACrE,OAAO,EAAE,gBAAgB,CAAC,QAAQ,EAAE,MAAM,CAAC,GAC1C,OAAO,CAAC,eAAe,CAAC,CA6F1B"}
|
|
@@ -3,7 +3,8 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { constants } from "node:fs";
|
|
4
4
|
import { access, readFile, unlink, writeFile } from "node:fs/promises";
|
|
5
5
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
6
|
-
import {
|
|
6
|
+
import { analyzeSource, SOURCE_ANALYSIS_FORMAT_VERSION } from "./analysis.js";
|
|
7
|
+
import { assertTypeScriptCompilerVersion } from "./typescript.js";
|
|
7
8
|
async function exists(path) {
|
|
8
9
|
try {
|
|
9
10
|
await access(path, constants.F_OK);
|
|
@@ -48,18 +49,30 @@ export async function checkFile(options) {
|
|
|
48
49
|
const schema = typeof options.schema === "string"
|
|
49
50
|
? options.dialect.validateSnapshot(JSON.parse(await readFile(resolve(options.schema), "utf8")))
|
|
50
51
|
: options.dialect.validateSnapshot(options.schema);
|
|
51
|
-
const
|
|
52
|
-
|
|
52
|
+
const analysis = analyzeSource({
|
|
53
|
+
formatVersion: SOURCE_ANALYSIS_FORMAT_VERSION,
|
|
54
|
+
source: { id: file, text: source },
|
|
55
|
+
compiler: {
|
|
56
|
+
...(options.maxStructuralVariants === undefined
|
|
57
|
+
? {}
|
|
58
|
+
: { maxStructuralVariants: options.maxStructuralVariants }),
|
|
59
|
+
...(options.maxSourceBytes === undefined ? {} : { maxSourceBytes: options.maxSourceBytes }),
|
|
60
|
+
...(options.maxQueries === undefined ? {} : { maxQueries: options.maxQueries }),
|
|
61
|
+
...(options.maxGeneratedDeclarationBytes === undefined
|
|
62
|
+
? {}
|
|
63
|
+
: { maxGeneratedDeclarationBytes: options.maxGeneratedDeclarationBytes }),
|
|
64
|
+
},
|
|
65
|
+
}, {
|
|
53
66
|
dialect: options.dialect,
|
|
54
67
|
schema,
|
|
55
|
-
...(options.maxStructuralVariants === undefined ? {} : { maxStructuralVariants: options.maxStructuralVariants }),
|
|
56
68
|
...(options.typePolicy === undefined ? {} : { typePolicy: options.typePolicy }),
|
|
57
69
|
});
|
|
58
|
-
const hasSqlErrors =
|
|
70
|
+
const hasSqlErrors = analysis.diagnostics.some((diagnostic) => diagnostic.severity === "error");
|
|
59
71
|
if (hasSqlErrors || options.runTypeScript === false) {
|
|
60
72
|
return {
|
|
61
|
-
|
|
62
|
-
|
|
73
|
+
analysis,
|
|
74
|
+
transformedSource: analysis.transformedSource,
|
|
75
|
+
sqlDiagnostics: analysis.diagnostics,
|
|
63
76
|
ok: !hasSqlErrors,
|
|
64
77
|
};
|
|
65
78
|
}
|
|
@@ -80,13 +93,25 @@ export async function checkFile(options) {
|
|
|
80
93
|
files: [`./${overlay.slice(directory.length + 1)}`],
|
|
81
94
|
include: [],
|
|
82
95
|
};
|
|
83
|
-
|
|
96
|
+
const timeout = options.typeScriptTimeoutMs ?? 60_000;
|
|
97
|
+
if (!Number.isSafeInteger(timeout) || timeout < 1)
|
|
98
|
+
throw new TypeError("typeScriptTimeoutMs must be a positive safe integer");
|
|
99
|
+
const binary = await tscBinary(directory);
|
|
100
|
+
const versionResult = spawnSync(binary, ["--version"], {
|
|
101
|
+
cwd: directory,
|
|
102
|
+
encoding: "utf8",
|
|
103
|
+
maxBuffer: 1024 * 1024,
|
|
104
|
+
timeout,
|
|
105
|
+
});
|
|
106
|
+
const versionMatch = /^Version\s+([^\s]+)\s*$/u.exec(String(versionResult.stdout ?? "").trim());
|
|
107
|
+
if (versionResult.status !== 0 || versionMatch?.[1] === undefined) {
|
|
108
|
+
const detail = `${versionResult.stderr ?? ""}${versionResult.error?.message ?? ""}`.trim();
|
|
109
|
+
throw new Error(`typed-sql could not determine the TypeScript compiler version${detail ? `: ${detail}` : ""}`);
|
|
110
|
+
}
|
|
111
|
+
assertTypeScriptCompilerVersion(versionMatch[1]);
|
|
112
|
+
await writeFile(overlay, analysis.transformedSource, "utf8");
|
|
84
113
|
await writeFile(tempConfig, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
85
114
|
try {
|
|
86
|
-
const binary = await tscBinary(directory);
|
|
87
|
-
const timeout = options.typeScriptTimeoutMs ?? 60_000;
|
|
88
|
-
if (!Number.isSafeInteger(timeout) || timeout < 1)
|
|
89
|
-
throw new TypeError("typeScriptTimeoutMs must be a positive safe integer");
|
|
90
115
|
const result = spawnSync(binary, ["--project", tempConfig, "--pretty", "false"], {
|
|
91
116
|
cwd: directory,
|
|
92
117
|
encoding: "utf8",
|
|
@@ -98,8 +123,9 @@ export async function checkFile(options) {
|
|
|
98
123
|
.replaceAll(tempConfig.slice(directory.length + 1), configPath(directory, project));
|
|
99
124
|
const typeScript = { exitCode: result.status ?? 1, output, command: `${binary} --project ${tempConfig}` };
|
|
100
125
|
return {
|
|
101
|
-
|
|
102
|
-
|
|
126
|
+
analysis,
|
|
127
|
+
transformedSource: analysis.transformedSource,
|
|
128
|
+
sqlDiagnostics: analysis.diagnostics,
|
|
103
129
|
typeScript,
|
|
104
130
|
ok: typeScript.exitCode === 0,
|
|
105
131
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../../../src/check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAElE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../../../src/check.ts"],"names":[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,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC;AACH,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { SchemaSnapshot, SourceRange } from "@typed-sql/core";
|
|
1
|
+
import type { SchemaSnapshot as CoreSchemaSnapshot, SourceRange } from "@typed-sql/core";
|
|
2
2
|
import type { QueryManifest, QueryManifestLocation } from "./manifest.js";
|
|
3
3
|
export declare const SCHEMA_COMPATIBILITY_FORMAT_VERSION: 1;
|
|
4
4
|
export declare const SCHEMA_COMPATIBILITY_ANALYZER_VERSION: "typed-sql-v1";
|
|
5
5
|
export type DeploymentDirection = "before-app-after-database" | "after-app-before-database";
|
|
6
6
|
export type CompatibilityClassification = "compatible" | "deployment-order-sensitive" | "source-breaking" | "runtime-breaking" | "unknown";
|
|
7
7
|
export type CompatibilitySeverity = "info" | "warning" | "error";
|
|
8
|
-
export type SchemaCompatibilityChangeKind = "relation-added" | "relation-removed" | "column-added" | "column-removed" | "column-database-type" | "column-typescript-type" | "column-nullability" | "column-array" | "column-default" | "enum-added" | "enum-removed" | "enum-values" | "domain-added" | "domain-removed" | "domain-database-type" | "domain-typescript-type" | "domain-nullability" | "function-added" | "function-removed" | "function-return-type" | "function-nullability" | "function-set-returning" | "function-volatility" | "dialect-version" | "server-version" | "query-contract";
|
|
8
|
+
export type SchemaCompatibilityChangeKind = "relation-added" | "relation-removed" | "column-added" | "column-removed" | "column-database-type" | "column-typescript-type" | "column-nullability" | "column-array" | "column-default" | "enum-added" | "enum-removed" | "enum-values" | "domain-added" | "domain-removed" | "domain-database-type" | "domain-typescript-type" | "domain-nullability" | "function-added" | "function-removed" | "function-return-type" | "function-nullability" | "function-set-returning" | "function-volatility" | "namespace-added" | "namespace-removed" | "namespace-definition" | "relation-definition" | "column-structure" | "constraint-added" | "constraint-removed" | "constraint-definition" | "index-added" | "index-removed" | "index-definition" | "type-added" | "type-removed" | "type-definition" | "routine-added" | "routine-removed" | "routine-definition" | "server-evidence" | "extension-definition" | "dialect-version" | "server-version" | "query-contract";
|
|
9
9
|
export interface SchemaCompatibilityTarget {
|
|
10
|
-
readonly kind: "schema" | "relation" | "column" | "enum" | "domain" | "function" | "query";
|
|
10
|
+
readonly kind: "schema" | "namespace" | "relation" | "column" | "constraint" | "index" | "type" | "enum" | "domain" | "routine" | "function" | "extension" | "query";
|
|
11
11
|
readonly key: string;
|
|
12
12
|
readonly name: string;
|
|
13
13
|
readonly schema?: string;
|
|
@@ -43,11 +43,13 @@ export interface SchemaCompatibilityReport {
|
|
|
43
43
|
readonly before: {
|
|
44
44
|
readonly schemaHash: string;
|
|
45
45
|
readonly manifestHash: string;
|
|
46
|
+
readonly schemaFormat?: 1 | 2;
|
|
46
47
|
readonly version?: string;
|
|
47
48
|
};
|
|
48
49
|
readonly after: {
|
|
49
50
|
readonly schemaHash: string;
|
|
50
51
|
readonly manifestHash: string;
|
|
52
|
+
readonly schemaFormat?: 1 | 2;
|
|
51
53
|
readonly version?: string;
|
|
52
54
|
};
|
|
53
55
|
readonly changes: readonly SchemaCompatibilityChange[];
|
|
@@ -55,8 +57,8 @@ export interface SchemaCompatibilityReport {
|
|
|
55
57
|
readonly summary: Readonly<Record<CompatibilitySeverity, number>>;
|
|
56
58
|
}
|
|
57
59
|
export interface AnalyzeSchemaCompatibilityOptions {
|
|
58
|
-
readonly before:
|
|
59
|
-
readonly after:
|
|
60
|
+
readonly before: CoreSchemaSnapshot;
|
|
61
|
+
readonly after: CoreSchemaSnapshot;
|
|
60
62
|
readonly beforeManifest: QueryManifest;
|
|
61
63
|
readonly afterManifest: QueryManifest;
|
|
62
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compatibility.d.ts","sourceRoot":"","sources":["../../../../src/compatibility.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"compatibility.d.ts","sourceRoot":"","sources":["../../../../src/compatibility.ts"],"names":[],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