@typed-sql/cli 1.0.0-beta.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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/packages/cli/src/cli.d.ts +3 -0
- package/dist/packages/cli/src/cli.d.ts.map +1 -0
- package/dist/packages/cli/src/cli.js +98 -0
- package/dist/packages/cli/src/cli.js.map +1 -0
- package/dist/packages/cli/src/config.d.ts +9 -0
- package/dist/packages/cli/src/config.d.ts.map +1 -0
- package/dist/packages/cli/src/config.js +50 -0
- package/dist/packages/cli/src/config.js.map +1 -0
- package/package.json +40 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @typed-sql/cli
|
|
2
|
+
|
|
3
|
+
## 1.0.0-beta.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Release the first public typed-sql beta: exact TypeScript 7 row inference from static PostgreSQL and
|
|
8
|
+
MySQL, versioned schema introspection, application-owned drivers, config-driven grammar plugins,
|
|
9
|
+
CLI verification, editor language-server integration, versioned diagnostics, bounded parsing, and
|
|
10
|
+
real-database plus packed-tarball verification.
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @typed-sql/compiler@1.0.0-beta.0
|
|
16
|
+
- @typed-sql/config@1.0.0-beta.0
|
|
17
|
+
- @typed-sql/core@1.0.0-beta.0
|
|
18
|
+
- @typed-sql/schema@1.0.0-beta.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 typed-sql contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @typed-sql/cli
|
|
2
|
+
|
|
3
|
+
The config-driven command line interface for [typed-sql](https://github.com/Lojhan/typed-sql).
|
|
4
|
+
It generates deterministic database snapshots, verifies inferred queries through TypeScript 7, and
|
|
5
|
+
detects live schema drift.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add -D @typed-sql/cli@next typescript@7.0.2
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Install one dialect and its application-owned driver, then create `typed-sql.config.ts` as shown in
|
|
12
|
+
the [root guide](https://github.com/Lojhan/typed-sql#configure-the-database-contract).
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
# Introspect the configured database and write schema metadata.
|
|
16
|
+
pnpm exec typed-sql generate
|
|
17
|
+
|
|
18
|
+
# Compile SQL inference into an isolated overlay and ask TypeScript 7 to check it.
|
|
19
|
+
pnpm exec typed-sql check --file src/query.ts --project tsconfig.json
|
|
20
|
+
|
|
21
|
+
# Compare the committed snapshot with the current live catalog and type policy.
|
|
22
|
+
pnpm exec typed-sql drift
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Use `--config path/to/typed-sql.config.ts` when discovery is not appropriate. `generate` also accepts
|
|
26
|
+
`--out`; `check` accepts `--file` and `--project`.
|
|
27
|
+
|
|
28
|
+
The CLI contains no PostgreSQL, MySQL, `pg`, or `mysql2` dependency. It loads the installed dialect
|
|
29
|
+
and schema provider through the project config. Diagnostics use the versioned
|
|
30
|
+
[`TSQ` registry](https://github.com/Lojhan/typed-sql/blob/main/docs/DIAGNOSTICS.md).
|
|
31
|
+
|
|
32
|
+
MIT © typed-sql contributors
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../../src/cli.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { checkFile } from "@typed-sql/compiler";
|
|
5
|
+
import { fromConfig, loadConfig } from "@typed-sql/config";
|
|
6
|
+
import { checkSchemaDrift, generateSchemaPackage, loadGeneratedSchemaSnapshot, } from "@typed-sql/schema";
|
|
7
|
+
function parseArguments(args) {
|
|
8
|
+
const command = args[0];
|
|
9
|
+
const options = {};
|
|
10
|
+
for (let index = 1; index < args.length; index += 1) {
|
|
11
|
+
const argument = args[index];
|
|
12
|
+
if (!argument.startsWith("--"))
|
|
13
|
+
throw new Error(`Unexpected argument ${argument}`);
|
|
14
|
+
const equals = argument.indexOf("=");
|
|
15
|
+
if (equals !== -1)
|
|
16
|
+
options[argument.slice(2, equals)] = argument.slice(equals + 1);
|
|
17
|
+
else {
|
|
18
|
+
const value = args[index + 1];
|
|
19
|
+
if (value === undefined || value.startsWith("--"))
|
|
20
|
+
throw new Error(`Missing value for ${argument}`);
|
|
21
|
+
options[argument.slice(2)] = value;
|
|
22
|
+
index += 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { ...(command === undefined ? {} : { command }), options };
|
|
26
|
+
}
|
|
27
|
+
function required(options, name) {
|
|
28
|
+
const value = options[name];
|
|
29
|
+
if (value === undefined)
|
|
30
|
+
throw new Error(`Missing required --${name}`);
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
async function readSnapshot(path, validate) {
|
|
34
|
+
return validate(JSON.parse(await readFile(path, "utf8")));
|
|
35
|
+
}
|
|
36
|
+
async function main() {
|
|
37
|
+
const parsed = parseArguments(process.argv.slice(2));
|
|
38
|
+
const loaded = await loadConfig({ ...(parsed.options.config === undefined ? {} : { file: parsed.options.config }) });
|
|
39
|
+
const config = loaded.config;
|
|
40
|
+
const dialect = config.dialect;
|
|
41
|
+
const policy = config.typePolicy ?? dialect.defaultTypePolicy;
|
|
42
|
+
const schemaFile = fromConfig(loaded.directory, parsed.options.schema ?? config.schema.file);
|
|
43
|
+
if (parsed.command === "check") {
|
|
44
|
+
const file = resolve(required(parsed.options, "file"));
|
|
45
|
+
const result = await checkFile({
|
|
46
|
+
file,
|
|
47
|
+
schema: schemaFile,
|
|
48
|
+
dialect,
|
|
49
|
+
typePolicy: policy,
|
|
50
|
+
...(parsed.options.project === undefined ? {} : { project: resolve(parsed.options.project) }),
|
|
51
|
+
});
|
|
52
|
+
for (const diagnostic of result.sqlDiagnostics) {
|
|
53
|
+
const suggestion = diagnostic.suggestion === undefined ? "" : ` ${diagnostic.suggestion}`;
|
|
54
|
+
process.stderr.write(`${file}:${diagnostic.range.line}:${diagnostic.range.column} - ${diagnostic.severity} ${diagnostic.code}: ${diagnostic.message}${suggestion}\n`);
|
|
55
|
+
}
|
|
56
|
+
if (result.typeScript?.output)
|
|
57
|
+
process.stderr.write(result.typeScript.output);
|
|
58
|
+
if (!result.ok)
|
|
59
|
+
process.exitCode = 1;
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (parsed.command === "generate") {
|
|
63
|
+
const current = parsed.options.snapshot !== undefined
|
|
64
|
+
? await readSnapshot(resolve(parsed.options.snapshot), (value) => dialect.validateSnapshot(value))
|
|
65
|
+
: config.schema.provider === undefined
|
|
66
|
+
? await readSnapshot(schemaFile, (value) => dialect.validateSnapshot(value))
|
|
67
|
+
: await config.schema.provider.introspect();
|
|
68
|
+
const metadata = await generateSchemaPackage(current, {
|
|
69
|
+
outDir: fromConfig(loaded.directory, parsed.options.out ?? config.outDir),
|
|
70
|
+
typePolicy: policy,
|
|
71
|
+
dialectVersion: dialect.grammarVersion,
|
|
72
|
+
});
|
|
73
|
+
process.stdout.write(`Generated schema ${metadata.schemaHash}\n`);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (parsed.command === "drift") {
|
|
77
|
+
if (config.schema.provider === undefined)
|
|
78
|
+
throw new Error("typed-sql drift requires schema.provider in typed-sql.config.ts");
|
|
79
|
+
const generated = await loadGeneratedSchemaSnapshot(schemaFile);
|
|
80
|
+
const current = await config.schema.provider.introspect();
|
|
81
|
+
const drift = checkSchemaDrift(generated, current, policy);
|
|
82
|
+
if (drift.drifted) {
|
|
83
|
+
process.stderr.write(`error TSQ301: Schema drift detected (schemaChanged=${drift.schemaChanged}, typePolicyChanged=${drift.typePolicyChanged})\n`);
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
}
|
|
86
|
+
else
|
|
87
|
+
process.stdout.write("No schema drift detected\n");
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
process.stdout.write("typed-sql check --config typed-sql.config.ts --file <query.ts> [--project tsconfig.json]\n");
|
|
91
|
+
process.stdout.write("typed-sql generate --config typed-sql.config.ts [--out <directory>]\n");
|
|
92
|
+
process.stdout.write("typed-sql drift --config typed-sql.config.ts\n");
|
|
93
|
+
}
|
|
94
|
+
main().catch((error) => {
|
|
95
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
96
|
+
process.exitCode = 1;
|
|
97
|
+
});
|
|
98
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAO3B,SAAS,cAAc,CAAC,IAAuB;IAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACxB,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAE,CAAC;QAC9B,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,EAAE,CAAC,CAAC;QACnF,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,MAAM,KAAK,CAAC,CAAC;YAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;aAC9E,CAAC;YACJ,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;YAC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AG,MAAM,2BAA2B,CAAC,UAAU,CAAC,CAAC;QAChE,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QAC1D,MAAM,KAAK,GAAG,gBAAgB,CAAC,SAAS,EAAE,OAAgB,EAAE,MAAM,CAAC,CAAC;QACpE,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sDAAsD,KAAK,CAAC,aAAa,uBAAuB,KAAK,CAAC,iBAAiB,KAAK,CAAC,CAAC;YACnJ,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,CAAC;;YAAM,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAC1D,OAAO;IACT,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,4FAA4F,CAAC,CAAC;IACnH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,uEAAuE,CAAC,CAAC;IAC9F,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;AACzE,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;IAC9B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpF,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SchemaSnapshot, TypedSqlConfig } from "@typed-sql/core";
|
|
2
|
+
export interface LoadedConfig {
|
|
3
|
+
readonly file: string;
|
|
4
|
+
readonly directory: string;
|
|
5
|
+
readonly config: TypedSqlConfig<SchemaSnapshot, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export declare function loadConfig(input?: string): Promise<LoadedConfig>;
|
|
8
|
+
export declare function fromConfig(directory: string, path: string): string;
|
|
9
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGtE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;CAC1D;AA8BD,wBAAsB,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAKtE;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAElE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { access } from "node:fs/promises";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { tsImport } from "tsx/esm/api";
|
|
6
|
+
async function exists(path) {
|
|
7
|
+
try {
|
|
8
|
+
await access(path, constants.F_OK);
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
async function discover(start) {
|
|
16
|
+
let directory = resolve(start);
|
|
17
|
+
while (true) {
|
|
18
|
+
for (const name of ["typed-sql.config.ts", "typed-sql.config.mts", "typed-sql.config.mjs", "typed-sql.config.js"]) {
|
|
19
|
+
const candidate = join(directory, name);
|
|
20
|
+
if (await exists(candidate))
|
|
21
|
+
return candidate;
|
|
22
|
+
}
|
|
23
|
+
const parent = dirname(directory);
|
|
24
|
+
if (parent === directory)
|
|
25
|
+
throw new Error(`Could not find typed-sql.config.ts from ${start}`);
|
|
26
|
+
directory = parent;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function isConfig(value) {
|
|
30
|
+
if (typeof value !== "object" || value === null)
|
|
31
|
+
return false;
|
|
32
|
+
const candidate = value;
|
|
33
|
+
return typeof candidate.dialect === "object"
|
|
34
|
+
&& candidate.dialect !== null
|
|
35
|
+
&& typeof candidate.dialect.id === "string"
|
|
36
|
+
&& typeof candidate.dialect.analyze === "function"
|
|
37
|
+
&& typeof candidate.schema?.file === "string"
|
|
38
|
+
&& typeof candidate.outDir === "string";
|
|
39
|
+
}
|
|
40
|
+
export async function loadConfig(input) {
|
|
41
|
+
const file = input === undefined ? await discover(process.cwd()) : resolve(input);
|
|
42
|
+
const module = await tsImport(pathToFileURL(file).href, import.meta.url);
|
|
43
|
+
if (!isConfig(module.default))
|
|
44
|
+
throw new TypeError(`${file} must default-export defineConfig({...})`);
|
|
45
|
+
return { file, directory: dirname(file), config: module.default };
|
|
46
|
+
}
|
|
47
|
+
export function fromConfig(directory, path) {
|
|
48
|
+
return resolve(directory, path);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQvC,KAAK,UAAU,MAAM,CAAC,IAAY;IAChC,IAAI,CAAC;QAAC,MA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U,UAAU,CAAC,KAAc;IAC7C,MAAM,IAAI,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAClF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,OAAO,IAAI,CAAC,GAAG,CAAmC,CAAC;IAC3G,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,0CAA0C,CAAC,CAAC;IACtG,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,SAAiB,EAAE,IAAY;IACxD,OAAO,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typed-sql/cli",
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
|
+
"description": "Config-driven typed-sql generation, checking, and schema drift CLI.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Lojhan",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Lojhan/typed-sql.git",
|
|
10
|
+
"directory": "packages/cli"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/Lojhan/typed-sql#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/Lojhan/typed-sql/issues"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22.11"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist/**/*.js",
|
|
21
|
+
"dist/**/*.d.ts",
|
|
22
|
+
"dist/**/*.map",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"CHANGELOG.md"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"type": "module",
|
|
31
|
+
"bin": {
|
|
32
|
+
"typed-sql": "./dist/packages/cli/src/cli.js"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@typed-sql/core": "1.0.0-beta.0",
|
|
36
|
+
"@typed-sql/compiler": "1.0.0-beta.0",
|
|
37
|
+
"@typed-sql/config": "1.0.0-beta.0",
|
|
38
|
+
"@typed-sql/schema": "1.0.0-beta.0"
|
|
39
|
+
}
|
|
40
|
+
}
|