@kronor/dtv 5.0.0 → 5.1.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/dist/assets/{index-BCuRRUo9.js → index-D2_2rYMS.js} +62 -62
- package/dist/cli/commands/init.js +106 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/typegen.js +26 -0
- package/dist/cli/commands/typegen.js.map +1 -0
- package/dist/cli/config/loadConfig.js +101 -0
- package/dist/cli/config/loadConfig.js.map +1 -0
- package/dist/cli/config/types.js +2 -0
- package/dist/cli/config/types.js.map +1 -0
- package/dist/cli/dtv.js +4 -504
- package/dist/cli/dtv.js.map +1 -1
- package/dist/cli/typegen/runTypegen.js +638 -0
- package/dist/cli/typegen/runTypegen.js.map +1 -0
- package/dist/cli/typegen/schemaToTs.js +5 -1
- package/dist/cli/typegen/schemaToTs.js.map +1 -1
- package/dist/index.es.js +903 -895
- package/dist/index.html +1 -1
- package/dist/types/cli/commands/init.d.ts +3 -0
- package/dist/types/cli/commands/init.d.ts.map +1 -0
- package/dist/types/cli/commands/typegen.d.ts +3 -0
- package/dist/types/cli/commands/typegen.d.ts.map +1 -0
- package/dist/types/cli/config/loadConfig.d.ts +3 -0
- package/dist/types/cli/config/loadConfig.d.ts.map +1 -0
- package/dist/types/cli/config/types.d.ts +34 -0
- package/dist/types/cli/config/types.d.ts.map +1 -0
- package/dist/types/cli/typegen/runTypegen.d.ts +9 -0
- package/dist/types/cli/typegen/runTypegen.d.ts.map +1 -0
- package/dist/types/cli/typegen/schemaToTs.d.ts.map +1 -1
- package/dist/types/dsl/filterExpr.d.ts +130 -46
- package/dist/types/dsl/filterExpr.d.ts.map +1 -1
- package/dist/types/dsl/filters.d.ts +72 -2
- package/dist/types/dsl/filters.d.ts.map +1 -1
- package/dist/types/framework/data.d.ts +1 -1
- package/dist/types/framework/data.d.ts.map +1 -1
- package/dist/types/framework/view-parser.d.ts +2 -0
- package/dist/types/framework/view-parser.d.ts.map +1 -1
- package/dist/types/framework/view.d.ts +5 -0
- package/dist/types/framework/view.d.ts.map +1 -1
- package/dist/types/lib/index.d.ts +1 -0
- package/dist/types/lib/index.d.ts.map +1 -1
- package/dist/types/lib/renderTableView.d.ts +4 -1
- package/dist/types/lib/renderTableView.d.ts.map +1 -1
- package/docs/typegen.md +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import * as fs from 'node:fs/promises';
|
|
3
|
+
async function writeFileEnsuringDir(filePath, content) {
|
|
4
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
5
|
+
await fs.writeFile(filePath, content, 'utf8');
|
|
6
|
+
}
|
|
7
|
+
async function fileExists(filePath) {
|
|
8
|
+
try {
|
|
9
|
+
await fs.stat(filePath);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function renderDefaultConfigTs(options) {
|
|
17
|
+
const stringifyArray = (items) => {
|
|
18
|
+
const outerIndent = ' ';
|
|
19
|
+
const innerIndent = ' ';
|
|
20
|
+
return `[
|
|
21
|
+
${items.map(v => `${innerIndent}${JSON.stringify(v)}`).join(',\n')}
|
|
22
|
+
${outerIndent}]`;
|
|
23
|
+
};
|
|
24
|
+
return [
|
|
25
|
+
"import type { DtvTypegenConfig } from '@kronor/dtv/typegen';",
|
|
26
|
+
'',
|
|
27
|
+
'const config: DtvTypegenConfig = {',
|
|
28
|
+
' schema: {',
|
|
29
|
+
` endpoint: ${JSON.stringify(options.endpoint)},`,
|
|
30
|
+
' headers: {',
|
|
31
|
+
' // Example header-based auth:',
|
|
32
|
+
' // Authorization: `Bearer ${process.env.HASURA_TOKEN}`,',
|
|
33
|
+
'',
|
|
34
|
+
' // Hasura admin secret:',
|
|
35
|
+
" // 'x-hasura-admin-secret': process.env.HASURA_ADMIN_SECRET ?? '',",
|
|
36
|
+
' }',
|
|
37
|
+
' },',
|
|
38
|
+
'',
|
|
39
|
+
' scan: {',
|
|
40
|
+
' // Scan TS/TSX files for `DSL.view({ ... })` calls (supports aliased/namespaced imports too)',
|
|
41
|
+
` include: ${stringifyArray(options.include)},`,
|
|
42
|
+
` exclude: ${stringifyArray(options.exclude)},`,
|
|
43
|
+
'',
|
|
44
|
+
' // Override if you re-export DTV under a different specifier.',
|
|
45
|
+
` dtvImport: ${JSON.stringify(options.dtvImport)}`,
|
|
46
|
+
' },',
|
|
47
|
+
'',
|
|
48
|
+
' output: {',
|
|
49
|
+
' // File name written next to each view module that calls DSL.view(...)',
|
|
50
|
+
` fileNamePattern: ${JSON.stringify(options.fileNamePattern)}`,
|
|
51
|
+
' },',
|
|
52
|
+
'',
|
|
53
|
+
' scalars: {',
|
|
54
|
+
" // DateTime: 'string'",
|
|
55
|
+
' },',
|
|
56
|
+
'',
|
|
57
|
+
' debug: {',
|
|
58
|
+
' // When true, include original GraphQL type refs as comments',
|
|
59
|
+
' includeGraphqlTypeComments: false',
|
|
60
|
+
' }',
|
|
61
|
+
'};',
|
|
62
|
+
'',
|
|
63
|
+
'export default config;',
|
|
64
|
+
''
|
|
65
|
+
].join('\n');
|
|
66
|
+
}
|
|
67
|
+
async function runInitConfig(outPath, force, overrides) {
|
|
68
|
+
const absOut = path.isAbsolute(outPath) ? outPath : path.resolve(process.cwd(), outPath);
|
|
69
|
+
if (!force && await fileExists(absOut)) {
|
|
70
|
+
throw new Error(`Refusing to overwrite existing file: ${absOut} (use --force to overwrite)`);
|
|
71
|
+
}
|
|
72
|
+
const content = renderDefaultConfigTs({
|
|
73
|
+
endpoint: overrides?.endpoint ?? 'https://my-hasura.example.com/v1/graphql',
|
|
74
|
+
fileNamePattern: overrides?.fileNamePattern ?? 'dtv.generated.{viewId}.ts',
|
|
75
|
+
include: ['src/**/*.{ts,tsx}'],
|
|
76
|
+
exclude: ['**/*.test.*', '**/node_modules/**'],
|
|
77
|
+
dtvImport: overrides?.dtvImport ?? '@kronor/dtv'
|
|
78
|
+
});
|
|
79
|
+
await writeFileEnsuringDir(absOut, content);
|
|
80
|
+
console.log(`Wrote ${absOut}`);
|
|
81
|
+
}
|
|
82
|
+
export function registerInitCommand(program) {
|
|
83
|
+
program
|
|
84
|
+
.command('init')
|
|
85
|
+
.description('Generate a dtv.config.ts template in the current project')
|
|
86
|
+
.option('-o, --out <path>', 'Output config file path', 'dtv.config.ts')
|
|
87
|
+
.option('--force', 'Overwrite if the file already exists', false)
|
|
88
|
+
.option('--endpoint <url>', 'Hasura GraphQL endpoint to prefill', 'https://my-hasura.example.com/v1/graphql')
|
|
89
|
+
.option('--file-pattern <pattern>', 'Output file name pattern written next to each view module', 'dtv.generated.{viewId}.ts')
|
|
90
|
+
.option('--dtv-import <specifier>', 'Module specifier used by views to import DSL', '@kronor/dtv')
|
|
91
|
+
.action(async (opts) => {
|
|
92
|
+
try {
|
|
93
|
+
await runInitConfig(opts.out, opts.force, {
|
|
94
|
+
endpoint: opts.endpoint,
|
|
95
|
+
fileNamePattern: opts.filePattern,
|
|
96
|
+
dtvImport: opts.dtvImport
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
101
|
+
console.error(msg);
|
|
102
|
+
process.exitCode = 1;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/cli/commands/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEvC,KAAK,UAAU,oBAAoB,CAAC,QAAgB,EAAE,OAAe;IACjE,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EA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C,kBAAkB,EAAE,yBAAyB,EAAE,eAAe,CAAC;SACtE,MAAM,CAAC,SAAS,EAAE,sCAAsC,EAAE,KAAK,CAAC;SAChE,MAAM,CAAC,kBAAkB,EAAE,oCAAoC,EAAE,0CAA0C,CAAC;SAC5G,MAAM,CAAC,0BAA0B,EAAE,2DAA2D,EAAE,2BAA2B,CAAC;SAC5H,MAAM,CAAC,0BAA0B,EAAE,8CAA8C,EAAE,aAAa,CAAC;SACjG,MAAM,CAAC,KAAK,EAAE,IAA+F,EAAE,EAAE;QAC9G,IAAI,CAAC;YACD,MAAM,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE;gBACtC,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,eAAe,EAAE,IAAI,CAAC,WAAW;gBACjC,SAAS,EAAE,IAAI,CAAC,SAAS;aAC5B,CAAC,CAAC;QACP,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACvD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACzB,CAAC;IACL,CAAC,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { runTypegen } from '../typegen/runTypegen.js';
|
|
2
|
+
export function registerTypegenCommand(program) {
|
|
3
|
+
program
|
|
4
|
+
.command('typegen')
|
|
5
|
+
.description('Generate TypeScript types from a Hasura GraphQL schema')
|
|
6
|
+
.argument('[viewId]', 'Optional view id to generate types for (only that view will be regenerated)')
|
|
7
|
+
.option('-c, --config <path>', 'Path to dtv.config.ts', 'dtv.config.ts')
|
|
8
|
+
.option('--debug-scan', 'Print view scanning debug information', false)
|
|
9
|
+
.option('--debug-scan-file <path>', 'Only scan a specific file and print debug output for it')
|
|
10
|
+
.action(async (viewId, opts) => {
|
|
11
|
+
try {
|
|
12
|
+
await runTypegen({
|
|
13
|
+
configPath: opts.config,
|
|
14
|
+
onlyViewId: viewId,
|
|
15
|
+
debugScan: Boolean(opts.debugScan || opts.debugScanFile),
|
|
16
|
+
debugScanFile: opts.debugScanFile
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
21
|
+
console.error(msg);
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=typegen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typegen.js","sourceRoot":"","sources":["../../../src/cli/commands/typegen.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,MAAM,UAAU,sBAAsB,CAAC,OAAgB;IACnD,OAAO;SACF,OAAO,CAAC,SAAS,CAAC;SAClB,WAAW,CAAC,wDAAwD,CAAC;SACrE,QAAQ,CAAC,UAAU,EAAE,6EAA6E,CAAC;SACnG,MAAM,CAAC,qBAAqB,EAAE,uBAAuB,EAAE,eAAe,CAAC;SACvE,MAAM,CAAC,cAAc,EAAE,uCAAuC,EAAE,KAAK,CAAC;SACtE,MAAM,CAAC,0BAA0B,EAAE,yDAAyD,CAAC;SAC7F,MAAM,CAAC,KAAK,EAAE,MAA0B,EAAE,IAAqE,EAAE,EAAE;QAChH,IAAI,CAAC;YACD,MAAM,UAAU,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,MAAM;gBACvB,UAAU,EAAE,MAAM;gBAClB,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,aAAa,CAAC;gBACxD,aAAa,EAAE,IAAI,CAAC,aAAa;aACpC,CAAC,CAAC;QACP,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,MAAM,GAAG,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACvD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACzB,CAAC;IACL,CAAC,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import * as fs from 'node:fs/promises';
|
|
4
|
+
import ts from 'typescript';
|
|
5
|
+
function isRecord(value) {
|
|
6
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
7
|
+
}
|
|
8
|
+
function assertString(value, context) {
|
|
9
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
10
|
+
throw new Error(`${context} must be a non-empty string`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export async function loadConfig(configPath) {
|
|
14
|
+
const abs = path.isAbsolute(configPath) ? configPath : path.resolve(process.cwd(), configPath);
|
|
15
|
+
const cfg = await (async () => {
|
|
16
|
+
const ext = path.extname(abs).toLowerCase();
|
|
17
|
+
const url = pathToFileURL(abs).href;
|
|
18
|
+
if (ext === '.ts' || ext === '.tsx') {
|
|
19
|
+
// Load TS config in a way that works in both CJS and ESM projects.
|
|
20
|
+
// We transpile the config file to ESM and import the emitted JS.
|
|
21
|
+
// This avoids requiring the consuming repo to be `type: module`.
|
|
22
|
+
const sourceText = await fs.readFile(abs, 'utf8');
|
|
23
|
+
// Under `module: NodeNext`, TS decides ESM vs CJS based on file extension
|
|
24
|
+
// and nearest package.json `type`. We want the config to always be treated
|
|
25
|
+
// as ESM so it can be imported reliably from any project.
|
|
26
|
+
const transpileFileName = abs.replace(/\.(tsx?)$/i, '.mts');
|
|
27
|
+
const transpiled = ts.transpileModule(sourceText, {
|
|
28
|
+
compilerOptions: {
|
|
29
|
+
target: ts.ScriptTarget.ES2022,
|
|
30
|
+
module: ts.ModuleKind.NodeNext,
|
|
31
|
+
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
|
32
|
+
jsx: ts.JsxEmit.Preserve,
|
|
33
|
+
esModuleInterop: true,
|
|
34
|
+
sourceMap: false
|
|
35
|
+
},
|
|
36
|
+
fileName: transpileFileName,
|
|
37
|
+
reportDiagnostics: true
|
|
38
|
+
});
|
|
39
|
+
if (transpiled.diagnostics?.length) {
|
|
40
|
+
const errors = transpiled.diagnostics.filter(d => d.category === ts.DiagnosticCategory.Error);
|
|
41
|
+
if (errors.length) {
|
|
42
|
+
const msg = errors
|
|
43
|
+
.map(d => ts.flattenDiagnosticMessageText(d.messageText, '\n'))
|
|
44
|
+
.join('\n');
|
|
45
|
+
throw new Error(`Failed to transpile ${abs}:\n${msg}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const tmpFile = path.join(path.dirname(abs), `.${path.basename(abs)}.dtv-tmp.${Date.now()}.mjs`);
|
|
49
|
+
await fs.writeFile(tmpFile, transpiled.outputText, 'utf8');
|
|
50
|
+
try {
|
|
51
|
+
const tmpUrl = pathToFileURL(tmpFile).href;
|
|
52
|
+
const mod = await import(`${tmpUrl}?t=${Date.now()}`);
|
|
53
|
+
return (mod.default ?? mod.config ?? mod);
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
await fs.unlink(tmpFile).catch(() => undefined);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// JS/MJS/CJS (or any Node-supported module) can be imported directly.
|
|
60
|
+
// Cache-bust import to allow repeated runs.
|
|
61
|
+
const mod = await import(`${url}?t=${Date.now()}`);
|
|
62
|
+
return (mod.default ?? mod.config ?? mod);
|
|
63
|
+
})();
|
|
64
|
+
if (!isRecord(cfg)) {
|
|
65
|
+
throw new Error('Config must export a plain object (default export recommended)');
|
|
66
|
+
}
|
|
67
|
+
if (!isRecord(cfg.schema))
|
|
68
|
+
throw new Error('Config.schema is required');
|
|
69
|
+
assertString(cfg.schema.endpoint, 'Config.schema.endpoint');
|
|
70
|
+
if (cfg.schema.headers !== undefined && !isRecord(cfg.schema.headers)) {
|
|
71
|
+
throw new Error('Config.schema.headers must be an object when provided');
|
|
72
|
+
}
|
|
73
|
+
if (!isRecord(cfg.scan))
|
|
74
|
+
throw new Error('Config.scan is required');
|
|
75
|
+
if (!Array.isArray(cfg.scan.include) || cfg.scan.include.length === 0) {
|
|
76
|
+
throw new Error('Config.scan.include must be a non-empty array of glob patterns');
|
|
77
|
+
}
|
|
78
|
+
if (cfg.scan.exclude !== undefined && !Array.isArray(cfg.scan.exclude)) {
|
|
79
|
+
throw new Error('Config.scan.exclude must be an array when provided');
|
|
80
|
+
}
|
|
81
|
+
if (cfg.scan.dtvImport !== undefined)
|
|
82
|
+
assertString(cfg.scan.dtvImport, 'Config.scan.dtvImport');
|
|
83
|
+
if (!isRecord(cfg.output))
|
|
84
|
+
throw new Error('Config.output is required');
|
|
85
|
+
assertString(cfg.output.fileNamePattern, 'Config.output.fileNamePattern');
|
|
86
|
+
if (cfg.output.fileNamePattern.includes('/') || cfg.output.fileNamePattern.includes('\\')) {
|
|
87
|
+
throw new Error('Config.output.fileNamePattern must be a file name (no path separators)');
|
|
88
|
+
}
|
|
89
|
+
if (cfg.scalars !== undefined && !isRecord(cfg.scalars)) {
|
|
90
|
+
throw new Error('Config.scalars must be an object when provided');
|
|
91
|
+
}
|
|
92
|
+
if (cfg.debug !== undefined) {
|
|
93
|
+
if (!isRecord(cfg.debug))
|
|
94
|
+
throw new Error('Config.debug must be an object when provided');
|
|
95
|
+
if (cfg.debug.includeGraphqlTypeComments !== undefined && typeof cfg.debug.includeGraphqlTypeComments !== 'boolean') {
|
|
96
|
+
throw new Error('Config.debug.includeGraphqlTypeComments must be a boolean when provided');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return cfg;
|
|
100
|
+
}
|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