@vibeorm/generator 1.3.1 → 2.0.0-alpha.10
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/README.md +43 -39
- package/dist/emit-dts.d.ts +32 -0
- package/dist/emit-dts.d.ts.map +1 -0
- package/dist/emit-js.d.ts +34 -0
- package/dist/emit-js.d.ts.map +1 -0
- package/dist/extension-bake.d.ts +42 -0
- package/dist/extension-bake.d.ts.map +1 -0
- package/dist/generate.d.ts +29 -0
- package/dist/generate.d.ts.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2154 -0
- package/dist/index.js.map +16 -0
- package/dist/schema-view.d.ts +103 -0
- package/dist/schema-view.d.ts.map +1 -0
- package/dist/type-names.d.ts +30 -0
- package/dist/type-names.d.ts.map +1 -0
- package/dist/util.d.ts +39 -0
- package/dist/util.d.ts.map +1 -0
- package/package.json +31 -23
- package/src/generate.ts +0 -70
- package/src/generators/generate-args.ts +0 -322
- package/src/generators/generate-client.ts +0 -252
- package/src/generators/generate-delegates.ts +0 -590
- package/src/generators/generate-enums.ts +0 -28
- package/src/generators/generate-inputs.ts +0 -655
- package/src/generators/generate-models.ts +0 -130
- package/src/generators/generate-result.ts +0 -182
- package/src/generators/generate-schemas.ts +0 -474
- package/src/generators/generate-view-types.ts +0 -446
- package/src/index.ts +0 -2
- package/src/utils.ts +0 -51
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scalar → TypeScript type mapping and the shared filter/update-operation type
|
|
3
|
+
* names referenced by the emitted d.ts. Payload types mirror the runtime codec
|
|
4
|
+
* table exactly (BigInt → bigint, Decimal → string, DateTime → Date, Json →
|
|
5
|
+
* JsonValue, Bytes → Uint8Array); input types are wider where every dialect
|
|
6
|
+
* coerces (`Date | string`, `bigint | number`, `string | number` for Decimal).
|
|
7
|
+
*/
|
|
8
|
+
import type { ScalarType } from "@vibeorm/schema";
|
|
9
|
+
import type { FieldView } from "./schema-view.ts";
|
|
10
|
+
/** Scalars that take atomic update operations (increment/decrement/multiply/divide). */
|
|
11
|
+
export declare const NUMERIC_SCALARS: ReadonlySet<ScalarType>;
|
|
12
|
+
/** Scalars aggregable with `_min`/`_max` (orderable on every dialect). */
|
|
13
|
+
export declare const MINMAX_SCALARS: ReadonlySet<ScalarType>;
|
|
14
|
+
/** The payload type of a field WITHOUT list/null decoration (`string`, `Role`, …). */
|
|
15
|
+
export declare function payloadBaseType(params: {
|
|
16
|
+
field: FieldView;
|
|
17
|
+
}): string;
|
|
18
|
+
/** The accepted input value type of a field WITHOUT list/null decoration. */
|
|
19
|
+
export declare function inputBaseType(params: {
|
|
20
|
+
field: FieldView;
|
|
21
|
+
}): string;
|
|
22
|
+
/** The filter type name for a field (`StringFilter`, `RoleNullableFilter`, `IntListFilter`, …). */
|
|
23
|
+
export declare function filterName(params: {
|
|
24
|
+
field: FieldView;
|
|
25
|
+
}): string;
|
|
26
|
+
/** The atomic update-operations type name for a numeric field, else `null`. */
|
|
27
|
+
export declare function updateOpsName(params: {
|
|
28
|
+
field: FieldView;
|
|
29
|
+
}): string | null;
|
|
30
|
+
//# sourceMappingURL=type-names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-names.d.ts","sourceRoot":"","sources":["../src/type-names.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AA+ClD,wFAAwF;AACxF,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,UAAU,CAAkD,CAAC;AAEvG,0EAA0E;AAC1E,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,UAAU,CAOjD,CAAC;AAIH,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,SAAS,CAAA;CAAE,GAAG,MAAM,CAKpE;AAED,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,SAAS,CAAA;CAAE,GAAG,MAAM,CAKlE;AAED,mGAAmG;AACnG,wBAAgB,UAAU,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,SAAS,CAAA;CAAE,GAAG,MAAM,CAK/D;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,SAAS,CAAA;CAAE,GAAG,MAAM,GAAG,IAAI,CAKzE"}
|
package/dist/util.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for the generator: naming, TS property keys, and the stable
|
|
3
|
+
* JSON serializer that keeps emitted output byte-identical for structurally
|
|
4
|
+
* identical IR (object-key insertion order never leaks into the output).
|
|
5
|
+
*/
|
|
6
|
+
/** First character uppercased, rest untouched (`posts` → `Posts`). */
|
|
7
|
+
export declare function pascal(params: {
|
|
8
|
+
name: string;
|
|
9
|
+
}): string;
|
|
10
|
+
/**
|
|
11
|
+
* Delegate key for a model name: first character lowercased, rest untouched
|
|
12
|
+
* (the Prisma convention — mirrors @vibeorm/runtime's `toClientName`, which the
|
|
13
|
+
* generator must never drift from: the emitted d.ts declares exactly the
|
|
14
|
+
* properties the runtime attaches).
|
|
15
|
+
*/
|
|
16
|
+
export declare function clientNameOf(params: {
|
|
17
|
+
name: string;
|
|
18
|
+
}): string;
|
|
19
|
+
/** A field name as a TS property key — bare when it is a valid identifier, quoted otherwise. */
|
|
20
|
+
export declare function propKey(params: {
|
|
21
|
+
name: string;
|
|
22
|
+
}): string;
|
|
23
|
+
/** A TS/JS double-quoted string literal, escaped. */
|
|
24
|
+
export declare function tsString(params: {
|
|
25
|
+
value: string;
|
|
26
|
+
}): string;
|
|
27
|
+
/** Wrap a type expression in parens when it is a union (for `[]` suffixing). */
|
|
28
|
+
export declare function maybeParens(params: {
|
|
29
|
+
type: string;
|
|
30
|
+
}): string;
|
|
31
|
+
/**
|
|
32
|
+
* JSON.stringify with recursively sorted object keys and 2-space indentation.
|
|
33
|
+
* Arrays keep their order (array order is semantic in the IR); `undefined`
|
|
34
|
+
* object values are omitted exactly like JSON.stringify does.
|
|
35
|
+
*/
|
|
36
|
+
export declare function stableStringify(params: {
|
|
37
|
+
value: unknown;
|
|
38
|
+
}): string;
|
|
39
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,sEAAsE;AACtE,wBAAgB,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAIvD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAI7D;AAID,gGAAgG;AAChG,wBAAgB,OAAO,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAGxD;AAED,qDAAqD;AACrD,wBAAgB,QAAQ,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAE1D;AAED,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAG5D;AAID;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,CAElE"}
|
package/package.json
CHANGED
|
@@ -1,42 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibeorm/generator",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"license": "MIT",
|
|
3
|
+
"version": "2.0.0-alpha.10",
|
|
4
|
+
"description": "Client generator for VibeORM v2 — emits .js + directly-written .d.ts from the Schema IR",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"orm",
|
|
8
|
-
"codegen",
|
|
9
|
-
"prisma",
|
|
10
|
-
"bun",
|
|
11
7
|
"typescript",
|
|
12
|
-
"
|
|
8
|
+
"sql",
|
|
9
|
+
"database",
|
|
10
|
+
"bun",
|
|
11
|
+
"type-safe",
|
|
12
|
+
"codegen",
|
|
13
|
+
"client",
|
|
14
|
+
"typescript-codegen",
|
|
15
|
+
"declaration-files"
|
|
13
16
|
],
|
|
17
|
+
"homepage": "https://github.com/vibeorm/vibeorm/tree/master/packages/generator#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/vibeorm/vibeorm/issues"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/vibeorm/vibeorm.git",
|
|
24
|
+
"directory": "packages/generator"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"author": "VibeORM contributors",
|
|
14
28
|
"type": "module",
|
|
15
29
|
"exports": {
|
|
16
30
|
".": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
19
33
|
}
|
|
20
34
|
},
|
|
21
35
|
"files": [
|
|
22
|
-
"
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md"
|
|
23
38
|
],
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"directory": "packages/generator"
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18",
|
|
41
|
+
"bun": ">=1.2.0"
|
|
28
42
|
},
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
"
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@vibeorm/schema": "2.0.0-alpha.8",
|
|
45
|
+
"@vibeorm/sql": "2.0.0-alpha.8"
|
|
32
46
|
},
|
|
33
47
|
"publishConfig": {
|
|
34
48
|
"access": "public"
|
|
35
|
-
},
|
|
36
|
-
"engines": {
|
|
37
|
-
"bun": ">=1.1.0"
|
|
38
|
-
},
|
|
39
|
-
"dependencies": {
|
|
40
|
-
"@vibeorm/parser": "1.3.1"
|
|
41
49
|
}
|
|
42
50
|
}
|
package/src/generate.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { Schema } from "@vibeorm/parser";
|
|
2
|
-
import { generateEnums } from "./generators/generate-enums.ts";
|
|
3
|
-
import { generateModels } from "./generators/generate-models.ts";
|
|
4
|
-
import {
|
|
5
|
-
generateInputs,
|
|
6
|
-
generateFilterTypes,
|
|
7
|
-
generateRelationFilterTypes,
|
|
8
|
-
} from "./generators/generate-inputs.ts";
|
|
9
|
-
import { generateArgs } from "./generators/generate-args.ts";
|
|
10
|
-
import { generateResult } from "./generators/generate-result.ts";
|
|
11
|
-
import { generateDelegates } from "./generators/generate-delegates.ts";
|
|
12
|
-
import { generateClient } from "./generators/generate-client.ts";
|
|
13
|
-
import { generateSchemas } from "./generators/generate-schemas.ts";
|
|
14
|
-
import { generateViewTypes } from "./generators/generate-view-types.ts";
|
|
15
|
-
|
|
16
|
-
export type GeneratedFile = {
|
|
17
|
-
filename: string;
|
|
18
|
-
content: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Takes a parsed schema IR and produces all the generated TypeScript files.
|
|
23
|
-
*/
|
|
24
|
-
export function generate(params: { schema: Schema }): GeneratedFile[] {
|
|
25
|
-
const { schema } = params;
|
|
26
|
-
|
|
27
|
-
const files: GeneratedFile[] = [
|
|
28
|
-
{
|
|
29
|
-
filename: "enums.ts",
|
|
30
|
-
content: generateEnums({ enums: schema.enums }),
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
filename: "models.ts",
|
|
34
|
-
content: generateModels({ schema }),
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
filename: "inputs.ts",
|
|
38
|
-
content:
|
|
39
|
-
generateInputs({ schema }) +
|
|
40
|
-
generateFilterTypes() +
|
|
41
|
-
generateRelationFilterTypes({ schema }),
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
filename: "args.ts",
|
|
45
|
-
content: generateArgs({ schema }),
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
filename: "result.ts",
|
|
49
|
-
content: generateResult({ schema }),
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
filename: "delegates.ts",
|
|
53
|
-
content: generateDelegates({ schema }),
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
filename: "index.ts",
|
|
57
|
-
content: generateClient({ schema }),
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
filename: "schemas.ts",
|
|
61
|
-
content: generateSchemas({ schema }),
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
filename: "view-types.ts",
|
|
65
|
-
content: generateViewTypes({ schema }),
|
|
66
|
-
},
|
|
67
|
-
];
|
|
68
|
-
|
|
69
|
-
return files;
|
|
70
|
-
}
|
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import type { Model, Schema, RelationField, ScalarField } from "@vibeorm/parser";
|
|
2
|
-
import { fileHeader } from "../utils.ts";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Generates Select, Include, and Args types for each model,
|
|
6
|
-
* plus the FindManyArgs, FindFirstArgs, FindUniqueArgs, etc.
|
|
7
|
-
*/
|
|
8
|
-
export function generateArgs(params: { schema: Schema }): string {
|
|
9
|
-
const { schema } = params;
|
|
10
|
-
const parts: string[] = [fileHeader()];
|
|
11
|
-
|
|
12
|
-
// Imports
|
|
13
|
-
const modelImports = schema.models.map((m) => `${m.name}WhereInput, ${m.name}WhereUniqueInput, ${m.name}OrderByInput, ${m.name}CreateInput, ${m.name}UpdateInput`).join(", ");
|
|
14
|
-
parts.push(`import type { ${modelImports}, SortOrder, SortOrderWithNulls } from "./inputs.ts";`);
|
|
15
|
-
|
|
16
|
-
const payloadImports = schema.models.map((m) => `$${m.name}Payload`).join(", ");
|
|
17
|
-
parts.push(`import type { ${payloadImports}, OperationPayload } from "./models.ts";\n`);
|
|
18
|
-
|
|
19
|
-
// Shared types
|
|
20
|
-
parts.push(`export type RelationStrategy = "query" | "join";
|
|
21
|
-
|
|
22
|
-
export type NumberWithAggregatesFilter = {
|
|
23
|
-
equals?: number;
|
|
24
|
-
not?: number;
|
|
25
|
-
lt?: number;
|
|
26
|
-
lte?: number;
|
|
27
|
-
gt?: number;
|
|
28
|
-
gte?: number;
|
|
29
|
-
};
|
|
30
|
-
`);
|
|
31
|
-
|
|
32
|
-
// Generate Select + Include + Args for each model
|
|
33
|
-
for (const model of schema.models) {
|
|
34
|
-
parts.push(generateSelectType({ model, schema }));
|
|
35
|
-
parts.push(generateIncludeType({ model, schema }));
|
|
36
|
-
parts.push(generateOperationArgs({ model }));
|
|
37
|
-
parts.push(generateAggregateInputTypes({ model }));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return parts.join("\n");
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// ─── Select Type ──────────────────────────────────────────────────
|
|
44
|
-
|
|
45
|
-
function generateSelectType(params: {
|
|
46
|
-
model: Model;
|
|
47
|
-
schema: Schema;
|
|
48
|
-
}): string {
|
|
49
|
-
const { model, schema } = params;
|
|
50
|
-
|
|
51
|
-
const entries: string[] = [];
|
|
52
|
-
|
|
53
|
-
for (const field of model.fields) {
|
|
54
|
-
if (field.kind === "scalar" || field.kind === "enum") {
|
|
55
|
-
entries.push(` ${field.name}?: boolean;`);
|
|
56
|
-
} else if (field.kind === "relation") {
|
|
57
|
-
if (field.isList) {
|
|
58
|
-
entries.push(` ${field.name}?: boolean | ${field.relatedModel}FindManyArgs;`);
|
|
59
|
-
} else {
|
|
60
|
-
entries.push(` ${field.name}?: boolean | ${field.relatedModel}FindFirstArgs;`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Add _count support for relation counting
|
|
66
|
-
const countableRelations = model.fields.filter(
|
|
67
|
-
(f): f is RelationField => f.kind === "relation" && f.isList
|
|
68
|
-
);
|
|
69
|
-
if (countableRelations.length > 0) {
|
|
70
|
-
const countFields = countableRelations.map((f) => ` ${f.name}?: boolean;`);
|
|
71
|
-
entries.push(` _count?: boolean | {\n select?: {\n${countFields.join("\n")}\n };\n };`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return `export type ${model.name}Select = {
|
|
75
|
-
${entries.join("\n")}
|
|
76
|
-
};
|
|
77
|
-
`;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// ─── Include Type ─────────────────────────────────────────────────
|
|
81
|
-
|
|
82
|
-
function generateIncludeType(params: {
|
|
83
|
-
model: Model;
|
|
84
|
-
schema: Schema;
|
|
85
|
-
}): string {
|
|
86
|
-
const { model } = params;
|
|
87
|
-
|
|
88
|
-
const relationFields = model.fields.filter(
|
|
89
|
-
(f): f is RelationField => f.kind === "relation"
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
if (relationFields.length === 0) {
|
|
93
|
-
return `export type ${model.name}Include = Record<string, never>;\n`;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const entries = relationFields.map((f) => {
|
|
97
|
-
if (f.isList) {
|
|
98
|
-
return ` ${f.name}?: boolean | ${f.relatedModel}FindManyArgs;`;
|
|
99
|
-
}
|
|
100
|
-
return ` ${f.name}?: boolean | ${f.relatedModel}FindFirstArgs;`;
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// Add _count support for relation counting
|
|
104
|
-
const countableRelations = relationFields.filter((f) => f.isList);
|
|
105
|
-
if (countableRelations.length > 0) {
|
|
106
|
-
const countFields = countableRelations.map((f) => ` ${f.name}?: boolean;`);
|
|
107
|
-
entries.push(` _count?: boolean | {\n select?: {\n${countFields.join("\n")}\n };\n };`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return `export type ${model.name}Include = {
|
|
111
|
-
${entries.join("\n")}
|
|
112
|
-
};
|
|
113
|
-
`;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// ─── Operation Args ───────────────────────────────────────────────
|
|
117
|
-
|
|
118
|
-
function generateOperationArgs(params: { model: Model }): string {
|
|
119
|
-
const { model } = params;
|
|
120
|
-
|
|
121
|
-
// Omit type — inverse of select (exclude specific fields)
|
|
122
|
-
const scalarFieldNames = model.fields
|
|
123
|
-
.filter((f) => f.kind === "scalar" || f.kind === "enum")
|
|
124
|
-
.map((f) => ` ${f.name}?: boolean;`);
|
|
125
|
-
|
|
126
|
-
const omitTypeDef = `export type ${model.name}Omit = {
|
|
127
|
-
${scalarFieldNames.join("\n")}
|
|
128
|
-
};
|
|
129
|
-
`;
|
|
130
|
-
|
|
131
|
-
return `${omitTypeDef}
|
|
132
|
-
export type ${model.name}FindManyArgs = {
|
|
133
|
-
select?: ${model.name}Select | null;
|
|
134
|
-
include?: ${model.name}Include | null;
|
|
135
|
-
omit?: ${model.name}Omit;
|
|
136
|
-
where?: ${model.name}WhereInput;
|
|
137
|
-
orderBy?: ${model.name}OrderByInput | ${model.name}OrderByInput[];
|
|
138
|
-
take?: number;
|
|
139
|
-
skip?: number;
|
|
140
|
-
cursor?: ${model.name}WhereUniqueInput;
|
|
141
|
-
distinct?: (keyof ${model.name}Select)[];
|
|
142
|
-
relationStrategy?: RelationStrategy;
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export type ${model.name}FindFirstArgs = {
|
|
146
|
-
select?: ${model.name}Select | null;
|
|
147
|
-
include?: ${model.name}Include | null;
|
|
148
|
-
omit?: ${model.name}Omit;
|
|
149
|
-
where?: ${model.name}WhereInput;
|
|
150
|
-
orderBy?: ${model.name}OrderByInput | ${model.name}OrderByInput[];
|
|
151
|
-
take?: number;
|
|
152
|
-
skip?: number;
|
|
153
|
-
cursor?: ${model.name}WhereUniqueInput;
|
|
154
|
-
relationStrategy?: RelationStrategy;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export type ${model.name}FindUniqueArgs = {
|
|
158
|
-
select?: ${model.name}Select | null;
|
|
159
|
-
include?: ${model.name}Include | null;
|
|
160
|
-
omit?: ${model.name}Omit;
|
|
161
|
-
where: ${model.name}WhereUniqueInput;
|
|
162
|
-
relationStrategy?: RelationStrategy;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
export type ${model.name}CreateArgs = {
|
|
166
|
-
select?: ${model.name}Select | null;
|
|
167
|
-
include?: ${model.name}Include | null;
|
|
168
|
-
omit?: ${model.name}Omit;
|
|
169
|
-
data: ${model.name}CreateInput;
|
|
170
|
-
relationStrategy?: RelationStrategy;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
export type ${model.name}UpdateArgs = {
|
|
174
|
-
select?: ${model.name}Select | null;
|
|
175
|
-
include?: ${model.name}Include | null;
|
|
176
|
-
omit?: ${model.name}Omit;
|
|
177
|
-
where: ${model.name}WhereUniqueInput;
|
|
178
|
-
data: ${model.name}UpdateInput;
|
|
179
|
-
relationStrategy?: RelationStrategy;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
export type ${model.name}UpsertArgs = {
|
|
183
|
-
select?: ${model.name}Select | null;
|
|
184
|
-
include?: ${model.name}Include | null;
|
|
185
|
-
where: ${model.name}WhereUniqueInput;
|
|
186
|
-
create: ${model.name}CreateInput;
|
|
187
|
-
update: ${model.name}UpdateInput;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
export type ${model.name}DeleteArgs = {
|
|
191
|
-
select?: ${model.name}Select | null;
|
|
192
|
-
include?: ${model.name}Include | null;
|
|
193
|
-
where: ${model.name}WhereUniqueInput;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
export type ${model.name}DeleteManyArgs = {
|
|
197
|
-
where?: ${model.name}WhereInput;
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
export type ${model.name}CountArgs = {
|
|
201
|
-
where?: ${model.name}WhereInput;
|
|
202
|
-
orderBy?: ${model.name}OrderByInput | ${model.name}OrderByInput[];
|
|
203
|
-
take?: number;
|
|
204
|
-
skip?: number;
|
|
205
|
-
cursor?: ${model.name}WhereUniqueInput;
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
export type ${model.name}CreateManyArgs = {
|
|
209
|
-
data: ${model.name}CreateInput | ${model.name}CreateInput[];
|
|
210
|
-
skipDuplicates?: boolean;
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
export type ${model.name}CreateManyAndReturnArgs = {
|
|
214
|
-
select?: ${model.name}Select | null;
|
|
215
|
-
include?: ${model.name}Include | null;
|
|
216
|
-
data: ${model.name}CreateInput | ${model.name}CreateInput[];
|
|
217
|
-
skipDuplicates?: boolean;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
export type ${model.name}UpdateManyArgs = {
|
|
221
|
-
where?: ${model.name}WhereInput;
|
|
222
|
-
data: ${model.name}UpdateInput;
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
export type ${model.name}AggregateArgs = {
|
|
226
|
-
where?: ${model.name}WhereInput;
|
|
227
|
-
orderBy?: ${model.name}OrderByInput | ${model.name}OrderByInput[];
|
|
228
|
-
take?: number;
|
|
229
|
-
skip?: number;
|
|
230
|
-
cursor?: ${model.name}WhereUniqueInput;
|
|
231
|
-
_count?: true | ${model.name}CountAggregateInputType;
|
|
232
|
-
_avg?: ${model.name}AvgAggregateInputType;
|
|
233
|
-
_sum?: ${model.name}SumAggregateInputType;
|
|
234
|
-
_min?: ${model.name}MinAggregateInputType;
|
|
235
|
-
_max?: ${model.name}MaxAggregateInputType;
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
export type ${model.name}GroupByArgs = {
|
|
239
|
-
by: (keyof ${model.name}Select)[];
|
|
240
|
-
where?: ${model.name}WhereInput;
|
|
241
|
-
orderBy?: ${model.name}OrderByInput | ${model.name}OrderByInput[];
|
|
242
|
-
having?: ${model.name}ScalarWhereWithAggregatesInput;
|
|
243
|
-
take?: number;
|
|
244
|
-
skip?: number;
|
|
245
|
-
_count?: true | ${model.name}CountAggregateInputType;
|
|
246
|
-
_avg?: ${model.name}AvgAggregateInputType;
|
|
247
|
-
_sum?: ${model.name}SumAggregateInputType;
|
|
248
|
-
_min?: ${model.name}MinAggregateInputType;
|
|
249
|
-
_max?: ${model.name}MaxAggregateInputType;
|
|
250
|
-
};
|
|
251
|
-
`;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// ─── Aggregate Input Types ────────────────────────────────────────
|
|
255
|
-
|
|
256
|
-
const NUMERIC_PRISMA_TYPES = new Set(["Int", "Float", "Decimal", "BigInt"]);
|
|
257
|
-
|
|
258
|
-
function generateAggregateInputTypes(params: { model: Model }): string {
|
|
259
|
-
const { model } = params;
|
|
260
|
-
|
|
261
|
-
const scalarFields = model.fields.filter(
|
|
262
|
-
(f): f is ScalarField => f.kind === "scalar"
|
|
263
|
-
);
|
|
264
|
-
|
|
265
|
-
const numericFields = scalarFields.filter(
|
|
266
|
-
(f) => NUMERIC_PRISMA_TYPES.has(f.prismaType)
|
|
267
|
-
);
|
|
268
|
-
|
|
269
|
-
// CountAggregateInputType — all scalar fields + _all
|
|
270
|
-
const countEntries = [
|
|
271
|
-
` _all?: boolean;`,
|
|
272
|
-
...scalarFields.map((f) => ` ${f.name}?: boolean;`),
|
|
273
|
-
];
|
|
274
|
-
|
|
275
|
-
// AvgAggregateInputType — only numeric fields
|
|
276
|
-
const avgEntries = numericFields.map((f) => ` ${f.name}?: boolean;`);
|
|
277
|
-
|
|
278
|
-
// SumAggregateInputType — only numeric fields
|
|
279
|
-
const sumEntries = numericFields.map((f) => ` ${f.name}?: boolean;`);
|
|
280
|
-
|
|
281
|
-
// MinAggregateInputType — all scalar fields
|
|
282
|
-
const minEntries = scalarFields.map((f) => ` ${f.name}?: boolean;`);
|
|
283
|
-
|
|
284
|
-
// MaxAggregateInputType — all scalar fields
|
|
285
|
-
const maxEntries = scalarFields.map((f) => ` ${f.name}?: boolean;`);
|
|
286
|
-
|
|
287
|
-
// ScalarWhereWithAggregatesInput — for HAVING clause in groupBy
|
|
288
|
-
const havingEntries = scalarFields.map((f) => {
|
|
289
|
-
return ` ${f.name}?: {
|
|
290
|
-
_count?: NumberWithAggregatesFilter;
|
|
291
|
-
_avg?: NumberWithAggregatesFilter;
|
|
292
|
-
_sum?: NumberWithAggregatesFilter;
|
|
293
|
-
_min?: NumberWithAggregatesFilter;
|
|
294
|
-
_max?: NumberWithAggregatesFilter;
|
|
295
|
-
};`;
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
return `export type ${model.name}CountAggregateInputType = {
|
|
299
|
-
${countEntries.join("\n")}
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
export type ${model.name}AvgAggregateInputType = {
|
|
303
|
-
${avgEntries.length > 0 ? avgEntries.join("\n") : " [key: string]: never;"}
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
export type ${model.name}SumAggregateInputType = {
|
|
307
|
-
${sumEntries.length > 0 ? sumEntries.join("\n") : " [key: string]: never;"}
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
export type ${model.name}MinAggregateInputType = {
|
|
311
|
-
${minEntries.join("\n")}
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
export type ${model.name}MaxAggregateInputType = {
|
|
315
|
-
${maxEntries.join("\n")}
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
export type ${model.name}ScalarWhereWithAggregatesInput = {
|
|
319
|
-
${havingEntries.join("\n")}
|
|
320
|
-
};
|
|
321
|
-
`;
|
|
322
|
-
}
|