@drzl/validation-core 2.0.0 → 2.1.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/dist/index.cjs +36 -0
- package/dist/index.d.cts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +35 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -100187,6 +100187,7 @@ __export(index_exports2, {
|
|
|
100187
100187
|
moduleSpecifier: () => moduleSpecifier,
|
|
100188
100188
|
pascalCase: () => pascalCase,
|
|
100189
100189
|
resolveAffix: () => resolveAffix,
|
|
100190
|
+
resolveConfiguredImport: () => resolveConfiguredImport,
|
|
100190
100191
|
schemaName: () => schemaName,
|
|
100191
100192
|
selectColumns: () => selectColumns,
|
|
100192
100193
|
typeName: () => typeName,
|
|
@@ -100196,6 +100197,8 @@ __export(index_exports2, {
|
|
|
100196
100197
|
module.exports = __toCommonJS(index_exports2);
|
|
100197
100198
|
|
|
100198
100199
|
// src/files.ts
|
|
100200
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
100201
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
100199
100202
|
var IMPORT_EXTENSIONS = ["js", "none", "ts"];
|
|
100200
100203
|
var DEFAULT_IMPORT_EXTENSION = "js";
|
|
100201
100204
|
var TS_EXTENSIONS = [
|
|
@@ -100219,6 +100222,38 @@ function importSpecifier(relativePath, importExtension = DEFAULT_IMPORT_EXTENSIO
|
|
|
100219
100222
|
function moduleSpecifier(tsName, fileSuffix, importExtension = DEFAULT_IMPORT_EXTENSION) {
|
|
100220
100223
|
return importSpecifier(`./${moduleFileName(tsName, fileSuffix)}`, importExtension);
|
|
100221
100224
|
}
|
|
100225
|
+
function resolveConfiguredImport(configured, outDirAbs, cwd, importExtension = DEFAULT_IMPORT_EXTENSION) {
|
|
100226
|
+
if (isPackageSpecifier(configured)) return configured;
|
|
100227
|
+
const targetAbs = import_node_path.default.isAbsolute(configured) ? configured : import_node_path.default.resolve(configured.startsWith(".") ? outDirAbs : cwd, configured);
|
|
100228
|
+
const withIndex = pointsAtDirectory(targetAbs) ? `${configured}/index` : configured;
|
|
100229
|
+
if (configured.startsWith(".")) {
|
|
100230
|
+
return importSpecifier(withTsExtension(withIndex), importExtension);
|
|
100231
|
+
}
|
|
100232
|
+
const resolved = pointsAtDirectory(targetAbs) ? import_node_path.default.join(targetAbs, "index") : targetAbs;
|
|
100233
|
+
const rel = import_node_path.default.relative(outDirAbs, resolved).split(import_node_path.default.sep).join("/");
|
|
100234
|
+
const prefixed = !rel ? "." : rel.startsWith(".") ? rel : `./${rel}`;
|
|
100235
|
+
return importSpecifier(withTsExtension(prefixed), importExtension);
|
|
100236
|
+
}
|
|
100237
|
+
function isPackageSpecifier(p5) {
|
|
100238
|
+
if (p5.startsWith(".") || import_node_path.default.isAbsolute(p5)) return false;
|
|
100239
|
+
if (p5.startsWith("@") || p5.includes(":")) return true;
|
|
100240
|
+
return !p5.includes("/");
|
|
100241
|
+
}
|
|
100242
|
+
function pointsAtDirectory(absPath) {
|
|
100243
|
+
try {
|
|
100244
|
+
return import_node_fs.default.statSync(absPath).isDirectory();
|
|
100245
|
+
} catch {
|
|
100246
|
+
for (const ext of [".ts", ".tsx", ".mts", ".cts", ".js", ".mjs", ".cjs"]) {
|
|
100247
|
+
if (import_node_fs.default.existsSync(`${absPath}${ext}`)) return false;
|
|
100248
|
+
}
|
|
100249
|
+
return !/\.[a-z]+$/i.test(import_node_path.default.basename(absPath));
|
|
100250
|
+
}
|
|
100251
|
+
}
|
|
100252
|
+
function withTsExtension(p5) {
|
|
100253
|
+
if (/\.(ts|tsx|mts|cts)$/.test(p5)) return p5;
|
|
100254
|
+
if (/\.(js|mjs|cjs)$/.test(p5)) return p5.replace(/\.(js|mjs|cjs)$/, ".ts");
|
|
100255
|
+
return `${p5}.ts`;
|
|
100256
|
+
}
|
|
100222
100257
|
|
|
100223
100258
|
// src/naming.ts
|
|
100224
100259
|
var NAME_MODES = ["insert", "update", "select"];
|
|
@@ -100384,6 +100419,7 @@ async function formatCode(code, filePath, fmt) {
|
|
|
100384
100419
|
moduleSpecifier,
|
|
100385
100420
|
pascalCase,
|
|
100386
100421
|
resolveAffix,
|
|
100422
|
+
resolveConfiguredImport,
|
|
100387
100423
|
schemaName,
|
|
100388
100424
|
selectColumns,
|
|
100389
100425
|
typeName,
|
package/dist/index.d.cts
CHANGED
|
@@ -52,6 +52,34 @@ declare function importSpecifier(relativePath: string, importExtension?: ImportE
|
|
|
52
52
|
* `./users.zod.js`.
|
|
53
53
|
*/
|
|
54
54
|
declare function moduleSpecifier(tsName: string, fileSuffix: string, importExtension?: ImportExtension): string;
|
|
55
|
+
/**
|
|
56
|
+
* Turn a configured module path into a specifier the generated file can actually import.
|
|
57
|
+
*
|
|
58
|
+
* Options like `validation.importPath`, `dbImportPath` and `schemaImportPath` get written as
|
|
59
|
+
* project-relative paths, `src/validators/zod`, because that is how the rest of the config
|
|
60
|
+
* names directories. Emitted verbatim that is a *bare* specifier: Node and tsc look for a
|
|
61
|
+
* package of that name in node_modules and never consider the local file. The config in the
|
|
62
|
+
* getting-started guide produced three such imports, none of which resolved.
|
|
63
|
+
*
|
|
64
|
+
* Two questions have to be answered, and neither can be guessed from the string alone.
|
|
65
|
+
*
|
|
66
|
+
* **Package or path?** `zod` and `@acme/schemas` are package names and pass through untouched.
|
|
67
|
+
* A path containing a separator, or starting with `.`, is a path.
|
|
68
|
+
*
|
|
69
|
+
* **File or directory?** `src/db/connection` is usually a file and `src/validators/zod` a
|
|
70
|
+
* directory holding a barrel, and they look identical. So the filesystem is asked. Where the
|
|
71
|
+
* target does not exist yet, which happens when this generator runs before the one that writes
|
|
72
|
+
* it, an extensionless path is taken to be a directory, since these options name directories by
|
|
73
|
+
* convention and the one path that can be missing is a generated barrel.
|
|
74
|
+
*
|
|
75
|
+
* A path already relative keeps its own spelling and only has its extension corrected, so
|
|
76
|
+
* anyone who followed the older guidance and wrote `../validators/zod/index.js` is unaffected.
|
|
77
|
+
*
|
|
78
|
+
* @param configured what the user put in the config
|
|
79
|
+
* @param outDirAbs absolute directory the importing file is written to
|
|
80
|
+
* @param cwd project root a non-relative path is resolved against
|
|
81
|
+
*/
|
|
82
|
+
declare function resolveConfiguredImport(configured: string, outDirAbs: string, cwd: string, importExtension?: ImportExtension): string;
|
|
55
83
|
|
|
56
84
|
/**
|
|
57
85
|
* One place that decides what a generated identifier is called.
|
|
@@ -201,4 +229,4 @@ declare function updateColumns(table: Table): Column[];
|
|
|
201
229
|
declare function selectColumns(table: Table): Column[];
|
|
202
230
|
declare function formatCode(code: string, filePath: string, fmt?: FormatOptions): Promise<any>;
|
|
203
231
|
|
|
204
|
-
export { AFFIX_PROBE_TABLE, type AffixIssue, type AffixOptions, type AffixValue, DEFAULT_IMPORT_EXTENSION, DEFAULT_MODE_PREFIX, DEFAULT_SCHEMA_SUFFIX, DEFAULT_TYPE_SUFFIX, type FormatOptions, IMPORT_EXTENSIONS, type ImportExtension, NAME_MODES, type NameMode, type ResolvedAffix, type Table, type TableCase, type ValidationGenerateOptions, type ValidationLibrary, type ValidationRenderer, applyTableCase, formatCode, importSpecifier, insertColumns, isGeneratedColumn, moduleFileName, moduleSpecifier, pascalCase, resolveAffix, schemaName, selectColumns, typeName, updateColumns, validateAffix };
|
|
232
|
+
export { AFFIX_PROBE_TABLE, type AffixIssue, type AffixOptions, type AffixValue, DEFAULT_IMPORT_EXTENSION, DEFAULT_MODE_PREFIX, DEFAULT_SCHEMA_SUFFIX, DEFAULT_TYPE_SUFFIX, type FormatOptions, IMPORT_EXTENSIONS, type ImportExtension, NAME_MODES, type NameMode, type ResolvedAffix, type Table, type TableCase, type ValidationGenerateOptions, type ValidationLibrary, type ValidationRenderer, applyTableCase, formatCode, importSpecifier, insertColumns, isGeneratedColumn, moduleFileName, moduleSpecifier, pascalCase, resolveAffix, resolveConfiguredImport, schemaName, selectColumns, typeName, updateColumns, validateAffix };
|
package/dist/index.d.ts
CHANGED
|
@@ -52,6 +52,34 @@ declare function importSpecifier(relativePath: string, importExtension?: ImportE
|
|
|
52
52
|
* `./users.zod.js`.
|
|
53
53
|
*/
|
|
54
54
|
declare function moduleSpecifier(tsName: string, fileSuffix: string, importExtension?: ImportExtension): string;
|
|
55
|
+
/**
|
|
56
|
+
* Turn a configured module path into a specifier the generated file can actually import.
|
|
57
|
+
*
|
|
58
|
+
* Options like `validation.importPath`, `dbImportPath` and `schemaImportPath` get written as
|
|
59
|
+
* project-relative paths, `src/validators/zod`, because that is how the rest of the config
|
|
60
|
+
* names directories. Emitted verbatim that is a *bare* specifier: Node and tsc look for a
|
|
61
|
+
* package of that name in node_modules and never consider the local file. The config in the
|
|
62
|
+
* getting-started guide produced three such imports, none of which resolved.
|
|
63
|
+
*
|
|
64
|
+
* Two questions have to be answered, and neither can be guessed from the string alone.
|
|
65
|
+
*
|
|
66
|
+
* **Package or path?** `zod` and `@acme/schemas` are package names and pass through untouched.
|
|
67
|
+
* A path containing a separator, or starting with `.`, is a path.
|
|
68
|
+
*
|
|
69
|
+
* **File or directory?** `src/db/connection` is usually a file and `src/validators/zod` a
|
|
70
|
+
* directory holding a barrel, and they look identical. So the filesystem is asked. Where the
|
|
71
|
+
* target does not exist yet, which happens when this generator runs before the one that writes
|
|
72
|
+
* it, an extensionless path is taken to be a directory, since these options name directories by
|
|
73
|
+
* convention and the one path that can be missing is a generated barrel.
|
|
74
|
+
*
|
|
75
|
+
* A path already relative keeps its own spelling and only has its extension corrected, so
|
|
76
|
+
* anyone who followed the older guidance and wrote `../validators/zod/index.js` is unaffected.
|
|
77
|
+
*
|
|
78
|
+
* @param configured what the user put in the config
|
|
79
|
+
* @param outDirAbs absolute directory the importing file is written to
|
|
80
|
+
* @param cwd project root a non-relative path is resolved against
|
|
81
|
+
*/
|
|
82
|
+
declare function resolveConfiguredImport(configured: string, outDirAbs: string, cwd: string, importExtension?: ImportExtension): string;
|
|
55
83
|
|
|
56
84
|
/**
|
|
57
85
|
* One place that decides what a generated identifier is called.
|
|
@@ -201,4 +229,4 @@ declare function updateColumns(table: Table): Column[];
|
|
|
201
229
|
declare function selectColumns(table: Table): Column[];
|
|
202
230
|
declare function formatCode(code: string, filePath: string, fmt?: FormatOptions): Promise<any>;
|
|
203
231
|
|
|
204
|
-
export { AFFIX_PROBE_TABLE, type AffixIssue, type AffixOptions, type AffixValue, DEFAULT_IMPORT_EXTENSION, DEFAULT_MODE_PREFIX, DEFAULT_SCHEMA_SUFFIX, DEFAULT_TYPE_SUFFIX, type FormatOptions, IMPORT_EXTENSIONS, type ImportExtension, NAME_MODES, type NameMode, type ResolvedAffix, type Table, type TableCase, type ValidationGenerateOptions, type ValidationLibrary, type ValidationRenderer, applyTableCase, formatCode, importSpecifier, insertColumns, isGeneratedColumn, moduleFileName, moduleSpecifier, pascalCase, resolveAffix, schemaName, selectColumns, typeName, updateColumns, validateAffix };
|
|
232
|
+
export { AFFIX_PROBE_TABLE, type AffixIssue, type AffixOptions, type AffixValue, DEFAULT_IMPORT_EXTENSION, DEFAULT_MODE_PREFIX, DEFAULT_SCHEMA_SUFFIX, DEFAULT_TYPE_SUFFIX, type FormatOptions, IMPORT_EXTENSIONS, type ImportExtension, NAME_MODES, type NameMode, type ResolvedAffix, type Table, type TableCase, type ValidationGenerateOptions, type ValidationLibrary, type ValidationRenderer, applyTableCase, formatCode, importSpecifier, insertColumns, isGeneratedColumn, moduleFileName, moduleSpecifier, pascalCase, resolveAffix, resolveConfiguredImport, schemaName, selectColumns, typeName, updateColumns, validateAffix };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import "./chunk-MKBO26DX.js";
|
|
2
2
|
|
|
3
3
|
// src/files.ts
|
|
4
|
+
import nodeFs from "fs";
|
|
5
|
+
import nodePath from "path";
|
|
4
6
|
var IMPORT_EXTENSIONS = ["js", "none", "ts"];
|
|
5
7
|
var DEFAULT_IMPORT_EXTENSION = "js";
|
|
6
8
|
var TS_EXTENSIONS = [
|
|
@@ -24,6 +26,38 @@ function importSpecifier(relativePath, importExtension = DEFAULT_IMPORT_EXTENSIO
|
|
|
24
26
|
function moduleSpecifier(tsName, fileSuffix, importExtension = DEFAULT_IMPORT_EXTENSION) {
|
|
25
27
|
return importSpecifier(`./${moduleFileName(tsName, fileSuffix)}`, importExtension);
|
|
26
28
|
}
|
|
29
|
+
function resolveConfiguredImport(configured, outDirAbs, cwd, importExtension = DEFAULT_IMPORT_EXTENSION) {
|
|
30
|
+
if (isPackageSpecifier(configured)) return configured;
|
|
31
|
+
const targetAbs = nodePath.isAbsolute(configured) ? configured : nodePath.resolve(configured.startsWith(".") ? outDirAbs : cwd, configured);
|
|
32
|
+
const withIndex = pointsAtDirectory(targetAbs) ? `${configured}/index` : configured;
|
|
33
|
+
if (configured.startsWith(".")) {
|
|
34
|
+
return importSpecifier(withTsExtension(withIndex), importExtension);
|
|
35
|
+
}
|
|
36
|
+
const resolved = pointsAtDirectory(targetAbs) ? nodePath.join(targetAbs, "index") : targetAbs;
|
|
37
|
+
const rel = nodePath.relative(outDirAbs, resolved).split(nodePath.sep).join("/");
|
|
38
|
+
const prefixed = !rel ? "." : rel.startsWith(".") ? rel : `./${rel}`;
|
|
39
|
+
return importSpecifier(withTsExtension(prefixed), importExtension);
|
|
40
|
+
}
|
|
41
|
+
function isPackageSpecifier(p) {
|
|
42
|
+
if (p.startsWith(".") || nodePath.isAbsolute(p)) return false;
|
|
43
|
+
if (p.startsWith("@") || p.includes(":")) return true;
|
|
44
|
+
return !p.includes("/");
|
|
45
|
+
}
|
|
46
|
+
function pointsAtDirectory(absPath) {
|
|
47
|
+
try {
|
|
48
|
+
return nodeFs.statSync(absPath).isDirectory();
|
|
49
|
+
} catch {
|
|
50
|
+
for (const ext of [".ts", ".tsx", ".mts", ".cts", ".js", ".mjs", ".cjs"]) {
|
|
51
|
+
if (nodeFs.existsSync(`${absPath}${ext}`)) return false;
|
|
52
|
+
}
|
|
53
|
+
return !/\.[a-z]+$/i.test(nodePath.basename(absPath));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function withTsExtension(p) {
|
|
57
|
+
if (/\.(ts|tsx|mts|cts)$/.test(p)) return p;
|
|
58
|
+
if (/\.(js|mjs|cjs)$/.test(p)) return p.replace(/\.(js|mjs|cjs)$/, ".ts");
|
|
59
|
+
return `${p}.ts`;
|
|
60
|
+
}
|
|
27
61
|
|
|
28
62
|
// src/naming.ts
|
|
29
63
|
var NAME_MODES = ["insert", "update", "select"];
|
|
@@ -188,6 +222,7 @@ export {
|
|
|
188
222
|
moduleSpecifier,
|
|
189
223
|
pascalCase,
|
|
190
224
|
resolveAffix,
|
|
225
|
+
resolveConfiguredImport,
|
|
191
226
|
schemaName,
|
|
192
227
|
selectColumns,
|
|
193
228
|
typeName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drzl/validation-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@drzl/analyzer": "^1.
|
|
14
|
+
"@drzl/analyzer": "^1.4.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"tsup": "^8.5.0",
|