@drzl/validation-core 0.0.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/LICENSE +202 -0
- package/README.md +19 -0
- package/dist/acorn-INHVMR4C.js +3152 -0
- package/dist/angular-PLJ22ADZ.js +2806 -0
- package/dist/babel-CVYK62HY.js +7246 -0
- package/dist/chunk-MKBO26DX.js +12 -0
- package/dist/estree-MDGIBSVU.js +4395 -0
- package/dist/flow-JY4PURRI.js +27251 -0
- package/dist/glimmer-MBEW7BEA.js +2827 -0
- package/dist/graphql-MN6GABOM.js +1260 -0
- package/dist/html-IVOJHMRV.js +2796 -0
- package/dist/index.cjs +100227 -0
- package/dist/index.d.cts +41 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +49 -0
- package/dist/markdown-57GKYE4Z.js +3540 -0
- package/dist/meriyah-CFHRTLLB.js +2634 -0
- package/dist/postcss-Y427BJX7.js +5087 -0
- package/dist/prettier-Y62OQ7O7.js +19824 -0
- package/dist/typescript-EHLMTNRR.js +13208 -0
- package/dist/yaml-2W2UYV55.js +4226 -0
- package/package.json +37 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Column, Analysis } from '@drzl/analyzer';
|
|
2
|
+
|
|
3
|
+
interface Table {
|
|
4
|
+
name: string;
|
|
5
|
+
tsName: string;
|
|
6
|
+
columns: Column[];
|
|
7
|
+
primaryKey?: {
|
|
8
|
+
columns: string[];
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
type ValidationLibrary = 'zod' | 'valibot' | 'arktype';
|
|
12
|
+
interface FormatOptions {
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
engine?: 'auto' | 'prettier' | 'biome';
|
|
15
|
+
configPath?: string;
|
|
16
|
+
}
|
|
17
|
+
interface ValidationGenerateOptions {
|
|
18
|
+
outDir: string;
|
|
19
|
+
format?: FormatOptions;
|
|
20
|
+
fileSuffix?: string;
|
|
21
|
+
schemaSuffix?: string;
|
|
22
|
+
coerceDates?: 'input' | 'all' | 'none';
|
|
23
|
+
emit?: {
|
|
24
|
+
select?: boolean;
|
|
25
|
+
insert?: boolean;
|
|
26
|
+
update?: boolean;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
interface ValidationRenderer<TOptions extends ValidationGenerateOptions = ValidationGenerateOptions> {
|
|
30
|
+
readonly library: ValidationLibrary;
|
|
31
|
+
renderTable(table: Table, opts?: TOptions): string;
|
|
32
|
+
renderIndex?(analysis: Analysis, opts?: TOptions): string;
|
|
33
|
+
generate(opts: TOptions): Promise<string[]>;
|
|
34
|
+
}
|
|
35
|
+
declare function isGeneratedColumn(c: Column, primaryKeyColumns: string[]): boolean;
|
|
36
|
+
declare function insertColumns(table: Table): Column[];
|
|
37
|
+
declare function updateColumns(table: Table): Column[];
|
|
38
|
+
declare function selectColumns(table: Table): Column[];
|
|
39
|
+
declare function formatCode(code: string, filePath: string, fmt?: FormatOptions): Promise<any>;
|
|
40
|
+
|
|
41
|
+
export { type FormatOptions, type Table, type ValidationGenerateOptions, type ValidationLibrary, type ValidationRenderer, formatCode, insertColumns, isGeneratedColumn, selectColumns, updateColumns };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Column, Analysis } from '@drzl/analyzer';
|
|
2
|
+
|
|
3
|
+
interface Table {
|
|
4
|
+
name: string;
|
|
5
|
+
tsName: string;
|
|
6
|
+
columns: Column[];
|
|
7
|
+
primaryKey?: {
|
|
8
|
+
columns: string[];
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
type ValidationLibrary = 'zod' | 'valibot' | 'arktype';
|
|
12
|
+
interface FormatOptions {
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
engine?: 'auto' | 'prettier' | 'biome';
|
|
15
|
+
configPath?: string;
|
|
16
|
+
}
|
|
17
|
+
interface ValidationGenerateOptions {
|
|
18
|
+
outDir: string;
|
|
19
|
+
format?: FormatOptions;
|
|
20
|
+
fileSuffix?: string;
|
|
21
|
+
schemaSuffix?: string;
|
|
22
|
+
coerceDates?: 'input' | 'all' | 'none';
|
|
23
|
+
emit?: {
|
|
24
|
+
select?: boolean;
|
|
25
|
+
insert?: boolean;
|
|
26
|
+
update?: boolean;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
interface ValidationRenderer<TOptions extends ValidationGenerateOptions = ValidationGenerateOptions> {
|
|
30
|
+
readonly library: ValidationLibrary;
|
|
31
|
+
renderTable(table: Table, opts?: TOptions): string;
|
|
32
|
+
renderIndex?(analysis: Analysis, opts?: TOptions): string;
|
|
33
|
+
generate(opts: TOptions): Promise<string[]>;
|
|
34
|
+
}
|
|
35
|
+
declare function isGeneratedColumn(c: Column, primaryKeyColumns: string[]): boolean;
|
|
36
|
+
declare function insertColumns(table: Table): Column[];
|
|
37
|
+
declare function updateColumns(table: Table): Column[];
|
|
38
|
+
declare function selectColumns(table: Table): Column[];
|
|
39
|
+
declare function formatCode(code: string, filePath: string, fmt?: FormatOptions): Promise<any>;
|
|
40
|
+
|
|
41
|
+
export { type FormatOptions, type Table, type ValidationGenerateOptions, type ValidationLibrary, type ValidationRenderer, formatCode, insertColumns, isGeneratedColumn, selectColumns, updateColumns };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import "./chunk-MKBO26DX.js";
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
function isGeneratedColumn(c, primaryKeyColumns) {
|
|
5
|
+
return c.isGenerated || primaryKeyColumns.includes(c.name);
|
|
6
|
+
}
|
|
7
|
+
function insertColumns(table) {
|
|
8
|
+
const pkCols = table.primaryKey?.columns ?? [];
|
|
9
|
+
return table.columns.filter((c) => !isGeneratedColumn(c, pkCols));
|
|
10
|
+
}
|
|
11
|
+
function updateColumns(table) {
|
|
12
|
+
const pkCols = table.primaryKey?.columns ?? [];
|
|
13
|
+
return table.columns.filter((c) => !pkCols.includes(c.name));
|
|
14
|
+
}
|
|
15
|
+
function selectColumns(table) {
|
|
16
|
+
return table.columns;
|
|
17
|
+
}
|
|
18
|
+
async function formatCode(code, filePath, fmt) {
|
|
19
|
+
if (fmt && fmt.enabled === false) return code;
|
|
20
|
+
const engine = fmt?.engine ?? "auto";
|
|
21
|
+
try {
|
|
22
|
+
if (engine === "prettier" || engine === "auto") {
|
|
23
|
+
const prettier = await import("./prettier-Y62OQ7O7.js");
|
|
24
|
+
const cfgRef = fmt?.configPath ?? filePath;
|
|
25
|
+
const cfg = await prettier.resolveConfig(cfgRef).catch(() => null);
|
|
26
|
+
return prettier.format(code, { ...cfg ?? {}, parser: "typescript", filepath: filePath });
|
|
27
|
+
}
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
if (engine === "biome" || engine === "auto") {
|
|
32
|
+
const dynamicImport = Function("s", "return import(s)");
|
|
33
|
+
const biome = await dynamicImport("@biomejs/biome").catch(() => null);
|
|
34
|
+
if (biome?.formatContent) {
|
|
35
|
+
const res = await biome.formatContent(code, { filePath });
|
|
36
|
+
return (res && (res.content || res.formatted)) ?? code;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
return code;
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
formatCode,
|
|
45
|
+
insertColumns,
|
|
46
|
+
isGeneratedColumn,
|
|
47
|
+
selectColumns,
|
|
48
|
+
updateColumns
|
|
49
|
+
};
|