@constructive-io/graphql-codegen 4.29.0 → 4.29.2
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/core/codegen/cli/index.d.ts +0 -2
- package/core/codegen/cli/index.js +0 -4
- package/core/codegen/cli/table-command-generator.d.ts +0 -2
- package/core/codegen/cli/table-command-generator.js +14 -25
- package/core/codegen/index.js +0 -3
- package/core/codegen/orm/index.js +2 -3
- package/core/codegen/orm/input-types-generator.d.ts +1 -3
- package/core/codegen/orm/input-types-generator.js +3 -113
- package/core/codegen/orm/model-generator.d.ts +2 -6
- package/core/codegen/orm/model-generator.js +2 -27
- package/core/codegen/orm/select-types.d.ts +2 -4
- package/core/codegen/queries.d.ts +0 -1
- package/core/codegen/queries.js +1 -7
- package/core/codegen/templates/cli-utils.ts +1 -5
- package/core/codegen/templates/query-builder.ts +3 -26
- package/core/codegen/templates/select-types.ts +2 -4
- package/core/generate.js +0 -2
- package/esm/core/codegen/cli/index.d.ts +0 -2
- package/esm/core/codegen/cli/index.js +0 -4
- package/esm/core/codegen/cli/table-command-generator.d.ts +0 -2
- package/esm/core/codegen/cli/table-command-generator.js +15 -26
- package/esm/core/codegen/index.js +0 -3
- package/esm/core/codegen/orm/index.js +2 -3
- package/esm/core/codegen/orm/input-types-generator.d.ts +1 -3
- package/esm/core/codegen/orm/input-types-generator.js +4 -114
- package/esm/core/codegen/orm/model-generator.d.ts +2 -6
- package/esm/core/codegen/orm/model-generator.js +2 -27
- package/esm/core/codegen/orm/select-types.d.ts +2 -4
- package/esm/core/codegen/queries.d.ts +0 -1
- package/esm/core/codegen/queries.js +2 -8
- package/esm/core/generate.js +0 -2
- package/package.json +7 -7
|
@@ -43,8 +43,6 @@ export interface GenerateMultiTargetCliOptions {
|
|
|
43
43
|
nodeHttpAdapter?: boolean;
|
|
44
44
|
/** Generate a runnable index.ts entry point */
|
|
45
45
|
entryPoint?: boolean;
|
|
46
|
-
/** Whether PostGraphile condition types are enabled (default: true) */
|
|
47
|
-
condition?: boolean;
|
|
48
46
|
}
|
|
49
47
|
export declare function resolveBuiltinNames(targetNames: string[], userOverrides?: BuiltinNames): {
|
|
50
48
|
auth: string;
|
|
@@ -40,11 +40,9 @@ function generateCli(options) {
|
|
|
40
40
|
files.push(contextFile);
|
|
41
41
|
const authFile = (0, infra_generator_1.generateAuthCommand)(toolName);
|
|
42
42
|
files.push(authFile);
|
|
43
|
-
const conditionEnabled = config.codegen?.condition === true;
|
|
44
43
|
for (const table of tables) {
|
|
45
44
|
const tableFile = (0, table_command_generator_1.generateTableCommand)(table, {
|
|
46
45
|
typeRegistry: options.typeRegistry,
|
|
47
|
-
condition: conditionEnabled,
|
|
48
46
|
});
|
|
49
47
|
files.push(tableFile);
|
|
50
48
|
}
|
|
@@ -91,7 +89,6 @@ function resolveBuiltinNames(targetNames, userOverrides) {
|
|
|
91
89
|
}
|
|
92
90
|
function generateMultiTargetCli(options) {
|
|
93
91
|
const { toolName, targets } = options;
|
|
94
|
-
const conditionEnabled = options.condition === true;
|
|
95
92
|
const files = [];
|
|
96
93
|
const targetNames = targets.map((t) => t.name);
|
|
97
94
|
const builtinNames = resolveBuiltinNames(targetNames, options.builtinNames);
|
|
@@ -141,7 +138,6 @@ function generateMultiTargetCli(options) {
|
|
|
141
138
|
targetName: target.name,
|
|
142
139
|
executorImportPath: '../../executor',
|
|
143
140
|
typeRegistry: target.typeRegistry,
|
|
144
|
-
condition: conditionEnabled,
|
|
145
141
|
});
|
|
146
142
|
files.push(tableFile);
|
|
147
143
|
}
|
|
@@ -6,7 +6,5 @@ export interface TableCommandOptions {
|
|
|
6
6
|
executorImportPath?: string;
|
|
7
7
|
/** TypeRegistry from introspection, used to check field defaults */
|
|
8
8
|
typeRegistry?: TypeRegistry;
|
|
9
|
-
/** Whether PostGraphile condition types are enabled (default: true) */
|
|
10
|
-
condition?: boolean;
|
|
11
9
|
}
|
|
12
10
|
export declare function generateTableCommand(table: Table, options?: TableCommandOptions): GeneratedFile;
|
|
@@ -286,24 +286,20 @@ function buildAutoEmbedInputBlock(vectorFieldNames) {
|
|
|
286
286
|
}
|
|
287
287
|
/**
|
|
288
288
|
* Build the FindManyArgs type instantiation for a table:
|
|
289
|
-
* FindManyArgs<SelectType, FilterType,
|
|
289
|
+
* FindManyArgs<SelectType, FilterType, OrderByType> & { select: SelectType }
|
|
290
290
|
*
|
|
291
291
|
* The intersection with { select: SelectType } makes select required,
|
|
292
292
|
* matching what the ORM's findMany method expects. parseFindManyArgs
|
|
293
293
|
* always sets select at runtime (from defaultSelect or --select flag).
|
|
294
294
|
*/
|
|
295
|
-
function buildFindManyArgsType(table
|
|
295
|
+
function buildFindManyArgsType(table) {
|
|
296
296
|
const { typeName } = (0, utils_1.getTableNames)(table);
|
|
297
297
|
const selectTypeName = `${typeName}Select`;
|
|
298
298
|
const whereTypeName = (0, utils_1.getFilterTypeName)(table);
|
|
299
|
-
const conditionTypeName = conditionEnabled ? (0, utils_1.getConditionTypeName)(table) : undefined;
|
|
300
299
|
const orderByTypeName = (0, utils_1.getOrderByTypeName)(table);
|
|
301
300
|
const findManyType = t.tsTypeReference(t.identifier('FindManyArgs'), t.tsTypeParameterInstantiation([
|
|
302
301
|
t.tsTypeReference(t.identifier(selectTypeName)),
|
|
303
302
|
t.tsTypeReference(t.identifier(whereTypeName)),
|
|
304
|
-
conditionTypeName
|
|
305
|
-
? t.tsTypeReference(t.identifier(conditionTypeName))
|
|
306
|
-
: t.tsNeverKeyword(),
|
|
307
303
|
t.tsTypeReference(t.identifier(orderByTypeName)),
|
|
308
304
|
]));
|
|
309
305
|
// Intersect with { select: SelectType } to make select required
|
|
@@ -316,22 +312,18 @@ function buildFindManyArgsType(table, conditionEnabled) {
|
|
|
316
312
|
}
|
|
317
313
|
/**
|
|
318
314
|
* Build the FindFirstArgs type instantiation for a table:
|
|
319
|
-
* FindFirstArgs<SelectType, FilterType
|
|
315
|
+
* FindFirstArgs<SelectType, FilterType> & { select: SelectType }
|
|
320
316
|
*
|
|
321
317
|
* The intersection with { select: SelectType } makes select required,
|
|
322
318
|
* matching what the ORM's findFirst method expects.
|
|
323
319
|
*/
|
|
324
|
-
function buildFindFirstArgsType(table
|
|
320
|
+
function buildFindFirstArgsType(table) {
|
|
325
321
|
const { typeName } = (0, utils_1.getTableNames)(table);
|
|
326
322
|
const selectTypeName = `${typeName}Select`;
|
|
327
323
|
const whereTypeName = (0, utils_1.getFilterTypeName)(table);
|
|
328
|
-
const conditionTypeName = conditionEnabled ? (0, utils_1.getConditionTypeName)(table) : undefined;
|
|
329
324
|
const findFirstType = t.tsTypeReference(t.identifier('FindFirstArgs'), t.tsTypeParameterInstantiation([
|
|
330
325
|
t.tsTypeReference(t.identifier(selectTypeName)),
|
|
331
326
|
t.tsTypeReference(t.identifier(whereTypeName)),
|
|
332
|
-
conditionTypeName
|
|
333
|
-
? t.tsTypeReference(t.identifier(conditionTypeName))
|
|
334
|
-
: t.tsNeverKeyword(),
|
|
335
327
|
]));
|
|
336
328
|
// Intersect with { select: SelectType } to make select required
|
|
337
329
|
return t.tsIntersectionType([
|
|
@@ -341,7 +333,7 @@ function buildFindFirstArgsType(table, conditionEnabled) {
|
|
|
341
333
|
]),
|
|
342
334
|
]);
|
|
343
335
|
}
|
|
344
|
-
function buildListHandler(table, vectorFieldNames, targetName, typeRegistry
|
|
336
|
+
function buildListHandler(table, vectorFieldNames, targetName, typeRegistry) {
|
|
345
337
|
const { singularName } = (0, utils_1.getTableNames)(table);
|
|
346
338
|
const defaultSelectObj = buildSelectObject(table, typeRegistry);
|
|
347
339
|
// --- Build the try body ---
|
|
@@ -357,7 +349,7 @@ function buildListHandler(table, vectorFieldNames, targetName, typeRegistry, con
|
|
|
357
349
|
t.identifier('defaultSelect'),
|
|
358
350
|
]);
|
|
359
351
|
callExpr.typeParameters = t.tsTypeParameterInstantiation([
|
|
360
|
-
buildFindManyArgsType(table
|
|
352
|
+
buildFindManyArgsType(table),
|
|
361
353
|
]);
|
|
362
354
|
tryBody.push(t.variableDeclaration('const', [
|
|
363
355
|
t.variableDeclarator(t.identifier('findManyArgs'), callExpr),
|
|
@@ -383,10 +375,10 @@ function buildListHandler(table, vectorFieldNames, targetName, typeRegistry, con
|
|
|
383
375
|
}
|
|
384
376
|
/**
|
|
385
377
|
* Build a `handleFindFirst` function — CLI equivalent of the TS SDK's findFirst().
|
|
386
|
-
* Accepts --select, --where.<field>.<op
|
|
378
|
+
* Accepts --select, --where.<field>.<op> flags.
|
|
387
379
|
* Internally calls findMany with first:1 and returns a single record (or null).
|
|
388
380
|
*/
|
|
389
|
-
function buildFindFirstHandler(table, targetName, typeRegistry
|
|
381
|
+
function buildFindFirstHandler(table, targetName, typeRegistry) {
|
|
390
382
|
const { singularName } = (0, utils_1.getTableNames)(table);
|
|
391
383
|
const defaultSelectObj = buildSelectObject(table, typeRegistry);
|
|
392
384
|
const tryBody = [];
|
|
@@ -401,7 +393,7 @@ function buildFindFirstHandler(table, targetName, typeRegistry, conditionEnabled
|
|
|
401
393
|
t.identifier('defaultSelect'),
|
|
402
394
|
]);
|
|
403
395
|
callExpr.typeParameters = t.tsTypeParameterInstantiation([
|
|
404
|
-
buildFindFirstArgsType(table
|
|
396
|
+
buildFindFirstArgsType(table),
|
|
405
397
|
]);
|
|
406
398
|
tryBody.push(t.variableDeclaration('const', [
|
|
407
399
|
t.variableDeclarator(t.identifier('findFirstArgs'), callExpr),
|
|
@@ -427,7 +419,7 @@ function buildFindFirstHandler(table, targetName, typeRegistry, conditionEnabled
|
|
|
427
419
|
* `where` clause that targets all detected search fields (tsvector, BM25,
|
|
428
420
|
* trigram, vector embedding). Supports --limit, --offset, --select, --orderBy.
|
|
429
421
|
*/
|
|
430
|
-
function buildSearchHandler(table, specialGroups, vectorFieldNames, targetName, typeRegistry
|
|
422
|
+
function buildSearchHandler(table, specialGroups, vectorFieldNames, targetName, typeRegistry) {
|
|
431
423
|
const { singularName } = (0, utils_1.getTableNames)(table);
|
|
432
424
|
const defaultSelectObj = buildSelectObject(table, typeRegistry);
|
|
433
425
|
const tryBody = [];
|
|
@@ -501,7 +493,7 @@ function buildSearchHandler(table, specialGroups, vectorFieldNames, targetName,
|
|
|
501
493
|
t.identifier('searchWhere'),
|
|
502
494
|
]);
|
|
503
495
|
callExpr.typeParameters = t.tsTypeParameterInstantiation([
|
|
504
|
-
buildFindManyArgsType(table
|
|
496
|
+
buildFindManyArgsType(table),
|
|
505
497
|
]);
|
|
506
498
|
tryBody.push(t.variableDeclaration('const', [
|
|
507
499
|
t.variableDeclarator(t.identifier('findManyArgs'), callExpr),
|
|
@@ -754,14 +746,11 @@ function generateTableCommand(table, options) {
|
|
|
754
746
|
const selectTypeName = `${typeName}Select`;
|
|
755
747
|
const whereTypeName = (0, utils_1.getFilterTypeName)(table);
|
|
756
748
|
const orderByTypeName = (0, utils_1.getOrderByTypeName)(table);
|
|
757
|
-
const conditionEnabled = options?.condition === true;
|
|
758
|
-
const conditionTypeName = conditionEnabled ? (0, utils_1.getConditionTypeName)(table) : undefined;
|
|
759
749
|
statements.push(createImportDeclaration(inputTypesPath, [
|
|
760
750
|
createInputTypeName,
|
|
761
751
|
patchTypeName,
|
|
762
752
|
selectTypeName,
|
|
763
753
|
whereTypeName,
|
|
764
|
-
...(conditionTypeName ? [conditionTypeName] : []),
|
|
765
754
|
orderByTypeName,
|
|
766
755
|
], true));
|
|
767
756
|
// Import FindManyArgs/FindFirstArgs from select-types for proper generic typing
|
|
@@ -906,10 +895,10 @@ function generateTableCommand(table, options) {
|
|
|
906
895
|
]), false, true));
|
|
907
896
|
const tn = options?.targetName;
|
|
908
897
|
const ormTypes = { createInputTypeName, patchTypeName, innerFieldName };
|
|
909
|
-
statements.push(buildListHandler(table, vectorFieldNames, tn, options?.typeRegistry
|
|
910
|
-
statements.push(buildFindFirstHandler(table, tn, options?.typeRegistry
|
|
898
|
+
statements.push(buildListHandler(table, vectorFieldNames, tn, options?.typeRegistry));
|
|
899
|
+
statements.push(buildFindFirstHandler(table, tn, options?.typeRegistry));
|
|
911
900
|
if (hasSearchFields)
|
|
912
|
-
statements.push(buildSearchHandler(table, specialGroups, vectorFieldNames, tn, options?.typeRegistry
|
|
901
|
+
statements.push(buildSearchHandler(table, specialGroups, vectorFieldNames, tn, options?.typeRegistry));
|
|
913
902
|
if (hasGet)
|
|
914
903
|
statements.push(buildGetHandler(table, tn, options?.typeRegistry));
|
|
915
904
|
statements.push(buildMutationHandler(table, 'create', vectorFieldNames, tn, options?.typeRegistry, ormTypes));
|
package/core/codegen/index.js
CHANGED
|
@@ -96,14 +96,11 @@ function generate(options) {
|
|
|
96
96
|
});
|
|
97
97
|
hasInvalidation = true;
|
|
98
98
|
}
|
|
99
|
-
// Condition types (PostGraphile simple equality filters)
|
|
100
|
-
const conditionEnabled = config.codegen?.condition === true;
|
|
101
99
|
// 4. Generate table-based query hooks (queries/*.ts)
|
|
102
100
|
const queryHooks = (0, queries_1.generateAllQueryHooks)(tables, {
|
|
103
101
|
reactQueryEnabled,
|
|
104
102
|
useCentralizedKeys,
|
|
105
103
|
hasRelationships,
|
|
106
|
-
condition: conditionEnabled,
|
|
107
104
|
});
|
|
108
105
|
for (const hook of queryHooks) {
|
|
109
106
|
files.push({
|
|
@@ -13,7 +13,6 @@ const model_generator_1 = require("./model-generator");
|
|
|
13
13
|
function generateOrm(options) {
|
|
14
14
|
const { tables, customOperations, sharedTypesPath } = options;
|
|
15
15
|
const commentsEnabled = options.config.codegen?.comments !== false;
|
|
16
|
-
const conditionEnabled = options.config.codegen?.condition === true;
|
|
17
16
|
const files = [];
|
|
18
17
|
// Use shared types when a sharedTypesPath is provided (unified output mode)
|
|
19
18
|
const useSharedTypes = !!sharedTypesPath;
|
|
@@ -34,7 +33,7 @@ function generateOrm(options) {
|
|
|
34
33
|
content: selectTypesFile.content,
|
|
35
34
|
});
|
|
36
35
|
// 2. Generate model files
|
|
37
|
-
const modelFiles = (0, model_generator_1.generateAllModelFiles)(tables, useSharedTypes
|
|
36
|
+
const modelFiles = (0, model_generator_1.generateAllModelFiles)(tables, useSharedTypes);
|
|
38
37
|
for (const modelFile of modelFiles) {
|
|
39
38
|
files.push({
|
|
40
39
|
path: `models/${modelFile.fileName}`,
|
|
@@ -71,7 +70,7 @@ function generateOrm(options) {
|
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
|
-
const inputTypesFile = (0, input_types_generator_1.generateInputTypesFile)(typeRegistry ?? new Map(), usedInputTypes, tables, usedPayloadTypes, commentsEnabled
|
|
73
|
+
const inputTypesFile = (0, input_types_generator_1.generateInputTypesFile)(typeRegistry ?? new Map(), usedInputTypes, tables, usedPayloadTypes, commentsEnabled);
|
|
75
74
|
files.push({
|
|
76
75
|
path: inputTypesFile.fileName,
|
|
77
76
|
content: inputTypesFile.content,
|
|
@@ -18,6 +18,4 @@ export declare function collectPayloadTypeNames(operations: Array<{
|
|
|
18
18
|
/**
|
|
19
19
|
* Generate comprehensive input-types.ts file using Babel AST
|
|
20
20
|
*/
|
|
21
|
-
export declare function generateInputTypesFile(typeRegistry: TypeRegistry, usedInputTypes: Set<string>, tables?: Table[], usedPayloadTypes?: Set<string>, comments?: boolean
|
|
22
|
-
condition?: boolean;
|
|
23
|
-
}): GeneratedInputTypesFile;
|
|
21
|
+
export declare function generateInputTypesFile(typeRegistry: TypeRegistry, usedInputTypes: Set<string>, tables?: Table[], usedPayloadTypes?: Set<string>, comments?: boolean): GeneratedInputTypesFile;
|
|
@@ -253,8 +253,7 @@ const SCALAR_FILTER_CONFIGS = [
|
|
|
253
253
|
},
|
|
254
254
|
{ name: 'FullTextFilter', tsType: 'string', operators: ['fulltext'] },
|
|
255
255
|
// VectorFilter: equality/distinct operators for vector columns on Filter types.
|
|
256
|
-
//
|
|
257
|
-
// connection-filter may still generate a filter for vector columns. This ensures
|
|
256
|
+
// connection-filter may generate a filter for vector columns. This ensures
|
|
258
257
|
// the generated type uses number[] rather than being silently omitted.
|
|
259
258
|
{ name: 'VectorFilter', tsType: 'number[]', operators: ['equality', 'distinct'] },
|
|
260
259
|
// List filters (for array fields like string[], int[], uuid[])
|
|
@@ -775,69 +774,6 @@ function generateTableFilterTypes(tables, typeRegistry) {
|
|
|
775
774
|
return statements;
|
|
776
775
|
}
|
|
777
776
|
// ============================================================================
|
|
778
|
-
// Condition Types Generator (AST-based)
|
|
779
|
-
// ============================================================================
|
|
780
|
-
/**
|
|
781
|
-
* Build properties for a table condition interface
|
|
782
|
-
* Condition types are simpler than Filter types - they use direct value equality.
|
|
783
|
-
*
|
|
784
|
-
* Also merges any extra fields from the GraphQL schema's condition type
|
|
785
|
-
* (e.g., plugin-injected fields like vectorEmbedding from VectorSearchPlugin)
|
|
786
|
-
* that are not derived from the table's own columns.
|
|
787
|
-
*/
|
|
788
|
-
function buildTableConditionProperties(table, typeRegistry) {
|
|
789
|
-
const properties = [];
|
|
790
|
-
const generatedFieldNames = new Set();
|
|
791
|
-
for (const field of table.fields) {
|
|
792
|
-
const fieldType = typeof field.type === 'string' ? field.type : field.type.gqlType;
|
|
793
|
-
if ((0, utils_1.isRelationField)(field.name, table))
|
|
794
|
-
continue;
|
|
795
|
-
// Condition types use the raw scalar type (nullable)
|
|
796
|
-
const tsType = (0, scalars_1.scalarToTsType)(fieldType, { unknownScalar: 'unknown' });
|
|
797
|
-
properties.push({
|
|
798
|
-
name: field.name,
|
|
799
|
-
type: `${tsType} | null`,
|
|
800
|
-
optional: true,
|
|
801
|
-
});
|
|
802
|
-
generatedFieldNames.add(field.name);
|
|
803
|
-
}
|
|
804
|
-
// Merge any additional fields from the schema's condition type
|
|
805
|
-
// (e.g., plugin-added fields like vectorEmbedding from VectorSearchPlugin)
|
|
806
|
-
if (typeRegistry) {
|
|
807
|
-
const conditionTypeName = (0, utils_1.getConditionTypeName)(table);
|
|
808
|
-
const conditionType = typeRegistry.get(conditionTypeName);
|
|
809
|
-
if (conditionType?.kind === 'INPUT_OBJECT' &&
|
|
810
|
-
conditionType.inputFields) {
|
|
811
|
-
for (const field of conditionType.inputFields) {
|
|
812
|
-
if (generatedFieldNames.has(field.name))
|
|
813
|
-
continue;
|
|
814
|
-
const tsType = typeRefToTs(field.type);
|
|
815
|
-
properties.push({
|
|
816
|
-
name: field.name,
|
|
817
|
-
type: tsType,
|
|
818
|
-
optional: true,
|
|
819
|
-
description: (0, utils_1.stripSmartComments)(field.description, true),
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
return properties;
|
|
825
|
-
}
|
|
826
|
-
/**
|
|
827
|
-
* Generate table condition type statements
|
|
828
|
-
*/
|
|
829
|
-
function generateTableConditionTypes(tables, typeRegistry) {
|
|
830
|
-
const statements = [];
|
|
831
|
-
for (const table of tables) {
|
|
832
|
-
const conditionName = (0, utils_1.getConditionTypeName)(table);
|
|
833
|
-
statements.push(createExportedInterface(conditionName, buildTableConditionProperties(table, typeRegistry)));
|
|
834
|
-
}
|
|
835
|
-
if (statements.length > 0) {
|
|
836
|
-
addSectionComment(statements, 'Table Condition Types');
|
|
837
|
-
}
|
|
838
|
-
return statements;
|
|
839
|
-
}
|
|
840
|
-
// ============================================================================
|
|
841
777
|
// OrderBy Types Generator (AST-based)
|
|
842
778
|
// ============================================================================
|
|
843
779
|
/**
|
|
@@ -1380,47 +1316,13 @@ function collectFilterExtraInputTypes(tables, typeRegistry) {
|
|
|
1380
1316
|
}
|
|
1381
1317
|
return extraTypes;
|
|
1382
1318
|
}
|
|
1383
|
-
/**
|
|
1384
|
-
* Collect extra input type names referenced by plugin-injected condition fields.
|
|
1385
|
-
*
|
|
1386
|
-
* When plugins (like VectorSearchPlugin) inject fields into condition types,
|
|
1387
|
-
* they reference types (like VectorNearbyInput, VectorMetric) that also need
|
|
1388
|
-
* to be generated. This function discovers those types by comparing the
|
|
1389
|
-
* schema's condition type fields against the table's own columns.
|
|
1390
|
-
*/
|
|
1391
|
-
function collectConditionExtraInputTypes(tables, typeRegistry) {
|
|
1392
|
-
const extraTypes = new Set();
|
|
1393
|
-
for (const table of tables) {
|
|
1394
|
-
const conditionTypeName = (0, utils_1.getConditionTypeName)(table);
|
|
1395
|
-
const conditionType = typeRegistry.get(conditionTypeName);
|
|
1396
|
-
if (!conditionType ||
|
|
1397
|
-
conditionType.kind !== 'INPUT_OBJECT' ||
|
|
1398
|
-
!conditionType.inputFields) {
|
|
1399
|
-
continue;
|
|
1400
|
-
}
|
|
1401
|
-
const tableFieldNames = new Set(table.fields
|
|
1402
|
-
.filter((f) => !(0, utils_1.isRelationField)(f.name, table))
|
|
1403
|
-
.map((f) => f.name));
|
|
1404
|
-
for (const field of conditionType.inputFields) {
|
|
1405
|
-
if (tableFieldNames.has(field.name))
|
|
1406
|
-
continue;
|
|
1407
|
-
// Collect the base type name of this extra field
|
|
1408
|
-
const baseName = (0, type_resolver_1.getTypeBaseName)(field.type);
|
|
1409
|
-
if (baseName && !scalars_1.SCALAR_NAMES.has(baseName)) {
|
|
1410
|
-
extraTypes.add(baseName);
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
return extraTypes;
|
|
1415
|
-
}
|
|
1416
1319
|
// ============================================================================
|
|
1417
1320
|
// Main Generator (AST-based)
|
|
1418
1321
|
// ============================================================================
|
|
1419
1322
|
/**
|
|
1420
1323
|
* Generate comprehensive input-types.ts file using Babel AST
|
|
1421
1324
|
*/
|
|
1422
|
-
function generateInputTypesFile(typeRegistry, usedInputTypes, tables, usedPayloadTypes, comments = true
|
|
1423
|
-
const conditionEnabled = options?.condition === true;
|
|
1325
|
+
function generateInputTypesFile(typeRegistry, usedInputTypes, tables, usedPayloadTypes, comments = true) {
|
|
1424
1326
|
const statements = [];
|
|
1425
1327
|
const tablesList = tables ?? [];
|
|
1426
1328
|
const hasTables = tablesList.length > 0;
|
|
@@ -1446,12 +1348,6 @@ function generateInputTypesFile(typeRegistry, usedInputTypes, tables, usedPayloa
|
|
|
1446
1348
|
// Pass typeRegistry to use schema's filter type as source of truth,
|
|
1447
1349
|
// capturing plugin-injected filter fields (e.g., bm25, tsvector, trgm, vector, geom)
|
|
1448
1350
|
statements.push(...generateTableFilterTypes(tablesList, typeRegistry));
|
|
1449
|
-
// 4b. Table condition types (simple equality filter)
|
|
1450
|
-
// Pass typeRegistry to merge plugin-injected condition fields
|
|
1451
|
-
// (e.g., vectorEmbedding from VectorSearchPlugin)
|
|
1452
|
-
if (conditionEnabled) {
|
|
1453
|
-
statements.push(...generateTableConditionTypes(tablesList, typeRegistry));
|
|
1454
|
-
}
|
|
1455
1351
|
// 5. OrderBy types
|
|
1456
1352
|
// Pass typeRegistry to merge plugin-injected orderBy values
|
|
1457
1353
|
// (e.g., EMBEDDING_DISTANCE_ASC/DESC from VectorSearchPlugin)
|
|
@@ -1463,7 +1359,7 @@ function generateInputTypesFile(typeRegistry, usedInputTypes, tables, usedPayloa
|
|
|
1463
1359
|
// Always emit this export so generated model/custom-op imports stay valid.
|
|
1464
1360
|
statements.push(...generateConnectionFieldsMap(tablesList, tableByName));
|
|
1465
1361
|
// 7. Custom input types from TypeRegistry
|
|
1466
|
-
// Also include any extra types referenced by plugin-injected filter
|
|
1362
|
+
// Also include any extra types referenced by plugin-injected filter fields
|
|
1467
1363
|
const mergedUsedInputTypes = new Set(usedInputTypes);
|
|
1468
1364
|
if (hasTables) {
|
|
1469
1365
|
const filterExtraTypes = collectFilterExtraInputTypes(tablesList, typeRegistry);
|
|
@@ -1471,12 +1367,6 @@ function generateInputTypesFile(typeRegistry, usedInputTypes, tables, usedPayloa
|
|
|
1471
1367
|
mergedUsedInputTypes.add(typeName);
|
|
1472
1368
|
}
|
|
1473
1369
|
}
|
|
1474
|
-
if (hasTables && conditionEnabled) {
|
|
1475
|
-
const conditionExtraTypes = collectConditionExtraInputTypes(tablesList, typeRegistry);
|
|
1476
|
-
for (const typeName of conditionExtraTypes) {
|
|
1477
|
-
mergedUsedInputTypes.add(typeName);
|
|
1478
|
-
}
|
|
1479
|
-
}
|
|
1480
1370
|
const tableCrudTypes = tables ? buildTableCrudTypeNames(tables) : undefined;
|
|
1481
1371
|
// Pass customScalarTypes + enumTypes as already-generated to avoid duplicate declarations
|
|
1482
1372
|
const alreadyGenerated = new Set([
|
|
@@ -5,9 +5,5 @@ export interface GeneratedModelFile {
|
|
|
5
5
|
modelName: string;
|
|
6
6
|
tableName: string;
|
|
7
7
|
}
|
|
8
|
-
export declare function generateModelFile(table: Table, _useSharedTypes: boolean, options?:
|
|
9
|
-
|
|
10
|
-
}, allTables?: Table[]): GeneratedModelFile;
|
|
11
|
-
export declare function generateAllModelFiles(tables: Table[], useSharedTypes: boolean, options?: {
|
|
12
|
-
condition?: boolean;
|
|
13
|
-
}): GeneratedModelFile[];
|
|
8
|
+
export declare function generateModelFile(table: Table, _useSharedTypes: boolean, options?: Record<string, never>, allTables?: Table[]): GeneratedModelFile;
|
|
9
|
+
export declare function generateAllModelFiles(tables: Table[], useSharedTypes: boolean): GeneratedModelFile[];
|
|
@@ -104,7 +104,6 @@ function strictSelectGuard(selectTypeName) {
|
|
|
104
104
|
]));
|
|
105
105
|
}
|
|
106
106
|
function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
107
|
-
const conditionEnabled = options?.condition === true;
|
|
108
107
|
const { typeName, singularName, pluralName } = (0, utils_1.getTableNames)(table);
|
|
109
108
|
const modelName = `${typeName}Model`;
|
|
110
109
|
const baseFileName = (0, utils_1.lcFirst)(typeName);
|
|
@@ -113,7 +112,6 @@ function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
113
112
|
const selectTypeName = `${typeName}Select`;
|
|
114
113
|
const relationTypeName = `${typeName}WithRelations`;
|
|
115
114
|
const whereTypeName = (0, utils_1.getFilterTypeName)(table);
|
|
116
|
-
const conditionTypeName = conditionEnabled ? `${typeName}Condition` : undefined;
|
|
117
115
|
const orderByTypeName = (0, utils_1.getOrderByTypeName)(table);
|
|
118
116
|
const createInputTypeName = `Create${typeName}Input`;
|
|
119
117
|
const updateInputTypeName = `Update${typeName}Input`;
|
|
@@ -161,7 +159,6 @@ function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
161
159
|
relationTypeName,
|
|
162
160
|
selectTypeName,
|
|
163
161
|
whereTypeName,
|
|
164
|
-
...(conditionTypeName ? [conditionTypeName] : []),
|
|
165
162
|
orderByTypeName,
|
|
166
163
|
createInputTypeName,
|
|
167
164
|
updateInputTypeName,
|
|
@@ -184,9 +181,6 @@ function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
184
181
|
const findManyTypeArgs = [
|
|
185
182
|
(sel) => sel,
|
|
186
183
|
() => t.tsTypeReference(t.identifier(whereTypeName)),
|
|
187
|
-
conditionTypeName
|
|
188
|
-
? () => t.tsTypeReference(t.identifier(conditionTypeName))
|
|
189
|
-
: () => t.tsNeverKeyword(),
|
|
190
184
|
() => t.tsTypeReference(t.identifier(orderByTypeName)),
|
|
191
185
|
];
|
|
192
186
|
const argsType = (sel) => t.tsTypeReference(t.identifier('FindManyArgs'), t.tsTypeParameterInstantiation(findManyTypeArgs.map(fn => fn(sel))));
|
|
@@ -209,11 +203,6 @@ function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
209
203
|
const selectExpr = t.memberExpression(t.identifier('args'), t.identifier('select'));
|
|
210
204
|
const findManyObjProps = [
|
|
211
205
|
t.objectProperty(t.identifier('where'), t.optionalMemberExpression(t.identifier('args'), t.identifier('where'), false, true)),
|
|
212
|
-
...(conditionTypeName
|
|
213
|
-
? [
|
|
214
|
-
t.objectProperty(t.identifier('condition'), t.optionalMemberExpression(t.identifier('args'), t.identifier('condition'), false, true)),
|
|
215
|
-
]
|
|
216
|
-
: []),
|
|
217
206
|
t.objectProperty(t.identifier('orderBy'), t.tsAsExpression(t.optionalMemberExpression(t.identifier('args'), t.identifier('orderBy'), false, true), t.tsUnionType([
|
|
218
207
|
t.tsArrayType(t.tsStringKeyword()),
|
|
219
208
|
t.tsUndefinedKeyword(),
|
|
@@ -232,9 +221,6 @@ function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
232
221
|
t.stringLiteral(whereTypeName),
|
|
233
222
|
t.stringLiteral(orderByTypeName),
|
|
234
223
|
t.identifier('connectionFieldsMap'),
|
|
235
|
-
...(conditionTypeName
|
|
236
|
-
? [t.stringLiteral(conditionTypeName)]
|
|
237
|
-
: []),
|
|
238
224
|
];
|
|
239
225
|
classBody.push(createClassMethod('findMany', createTypeParam(selectTypeName), [implParam], retType(sRef()), buildMethodBody('buildFindManyDocument', bodyArgs, 'query', typeName, pluralQueryName)));
|
|
240
226
|
}
|
|
@@ -243,9 +229,6 @@ function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
243
229
|
const findFirstTypeArgs = [
|
|
244
230
|
(sel) => sel,
|
|
245
231
|
() => t.tsTypeReference(t.identifier(whereTypeName)),
|
|
246
|
-
...(conditionTypeName
|
|
247
|
-
? [() => t.tsTypeReference(t.identifier(conditionTypeName))]
|
|
248
|
-
: []),
|
|
249
232
|
];
|
|
250
233
|
const argsType = (sel) => t.tsTypeReference(t.identifier('FindFirstArgs'), t.tsTypeParameterInstantiation(findFirstTypeArgs.map(fn => fn(sel))));
|
|
251
234
|
const retType = (sel) => t.tsTypeAnnotation(t.tsTypeReference(t.identifier('QueryBuilder'), t.tsTypeParameterInstantiation([
|
|
@@ -267,11 +250,6 @@ function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
267
250
|
const selectExpr = t.memberExpression(t.identifier('args'), t.identifier('select'));
|
|
268
251
|
const findFirstObjProps = [
|
|
269
252
|
t.objectProperty(t.identifier('where'), t.optionalMemberExpression(t.identifier('args'), t.identifier('where'), false, true)),
|
|
270
|
-
...(conditionTypeName
|
|
271
|
-
? [
|
|
272
|
-
t.objectProperty(t.identifier('condition'), t.optionalMemberExpression(t.identifier('args'), t.identifier('condition'), false, true)),
|
|
273
|
-
]
|
|
274
|
-
: []),
|
|
275
253
|
];
|
|
276
254
|
const bodyArgs = [
|
|
277
255
|
t.stringLiteral(typeName),
|
|
@@ -280,9 +258,6 @@ function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
280
258
|
t.objectExpression(findFirstObjProps),
|
|
281
259
|
t.stringLiteral(whereTypeName),
|
|
282
260
|
t.identifier('connectionFieldsMap'),
|
|
283
|
-
...(conditionTypeName
|
|
284
|
-
? [t.stringLiteral(conditionTypeName)]
|
|
285
|
-
: []),
|
|
286
261
|
];
|
|
287
262
|
classBody.push(createClassMethod('findFirst', createTypeParam(selectTypeName), [implParam], retType(sRef()), buildMethodBody('buildFindFirstDocument', bodyArgs, 'query', typeName, pluralQueryName)));
|
|
288
263
|
}
|
|
@@ -611,6 +586,6 @@ function generateModelFile(table, _useSharedTypes, options, allTables) {
|
|
|
611
586
|
tableName: table.name,
|
|
612
587
|
};
|
|
613
588
|
}
|
|
614
|
-
function generateAllModelFiles(tables, useSharedTypes
|
|
615
|
-
return tables.map((table) => generateModelFile(table, useSharedTypes,
|
|
589
|
+
function generateAllModelFiles(tables, useSharedTypes) {
|
|
590
|
+
return tables.map((table) => generateModelFile(table, useSharedTypes, undefined, tables));
|
|
616
591
|
}
|
|
@@ -150,10 +150,9 @@ export interface PageInfo {
|
|
|
150
150
|
/**
|
|
151
151
|
* Arguments for findMany operations
|
|
152
152
|
*/
|
|
153
|
-
export interface FindManyArgs<TSelect, TWhere,
|
|
153
|
+
export interface FindManyArgs<TSelect, TWhere, TOrderBy> {
|
|
154
154
|
select?: TSelect;
|
|
155
155
|
where?: TWhere;
|
|
156
|
-
condition?: TCondition;
|
|
157
156
|
orderBy?: TOrderBy[];
|
|
158
157
|
first?: number;
|
|
159
158
|
last?: number;
|
|
@@ -164,10 +163,9 @@ export interface FindManyArgs<TSelect, TWhere, TCondition, TOrderBy> {
|
|
|
164
163
|
/**
|
|
165
164
|
* Arguments for findFirst/findUnique operations
|
|
166
165
|
*/
|
|
167
|
-
export interface FindFirstArgs<TSelect, TWhere
|
|
166
|
+
export interface FindFirstArgs<TSelect, TWhere> {
|
|
168
167
|
select?: TSelect;
|
|
169
168
|
where?: TWhere;
|
|
170
|
-
condition?: TCondition;
|
|
171
169
|
}
|
|
172
170
|
/**
|
|
173
171
|
* Arguments for create operations
|
|
@@ -7,7 +7,6 @@ export interface QueryGeneratorOptions {
|
|
|
7
7
|
reactQueryEnabled?: boolean;
|
|
8
8
|
useCentralizedKeys?: boolean;
|
|
9
9
|
hasRelationships?: boolean;
|
|
10
|
-
condition?: boolean;
|
|
11
10
|
}
|
|
12
11
|
export declare function generateListQueryHook(table: Table, options?: QueryGeneratorOptions): GeneratedQueryFile;
|
|
13
12
|
export declare function generateSingleQueryHook(table: Table, options?: QueryGeneratorOptions): GeneratedQueryFile | null;
|
package/core/codegen/queries.js
CHANGED
|
@@ -49,13 +49,12 @@ const babel_ast_1 = require("./babel-ast");
|
|
|
49
49
|
const hooks_ast_1 = require("./hooks-ast");
|
|
50
50
|
const utils_1 = require("./utils");
|
|
51
51
|
function generateListQueryHook(table, options = {}) {
|
|
52
|
-
const { reactQueryEnabled = true, useCentralizedKeys = true, hasRelationships = false,
|
|
52
|
+
const { reactQueryEnabled = true, useCentralizedKeys = true, hasRelationships = false, } = options;
|
|
53
53
|
const { typeName, pluralName, singularName } = (0, utils_1.getTableNames)(table);
|
|
54
54
|
const hookName = (0, utils_1.getListQueryHookName)(table);
|
|
55
55
|
const queryName = (0, utils_1.getAllRowsQueryName)(table);
|
|
56
56
|
const filterTypeName = (0, utils_1.getFilterTypeName)(table);
|
|
57
57
|
const orderByTypeName = (0, utils_1.getOrderByTypeName)(table);
|
|
58
|
-
const conditionTypeName = conditionEnabled ? (0, utils_1.getConditionTypeName)(table) : undefined;
|
|
59
58
|
const keysName = `${(0, utils_1.lcFirst)(typeName)}Keys`;
|
|
60
59
|
const scopeTypeName = `${typeName}Scope`;
|
|
61
60
|
const selectTypeName = `${typeName}Select`;
|
|
@@ -77,8 +76,6 @@ function generateListQueryHook(table, options = {}) {
|
|
|
77
76
|
}
|
|
78
77
|
}
|
|
79
78
|
const inputTypeImports = [selectTypeName, relationTypeName, filterTypeName, orderByTypeName];
|
|
80
|
-
if (conditionTypeName)
|
|
81
|
-
inputTypeImports.push(conditionTypeName);
|
|
82
79
|
statements.push((0, hooks_ast_1.createImportDeclaration)('../../orm/input-types', inputTypeImports, true));
|
|
83
80
|
statements.push((0, hooks_ast_1.createImportDeclaration)('../../orm/select-types', [
|
|
84
81
|
'FindManyArgs',
|
|
@@ -88,8 +85,6 @@ function generateListQueryHook(table, options = {}) {
|
|
|
88
85
|
], true));
|
|
89
86
|
// Re-exports
|
|
90
87
|
const reExportTypes = [selectTypeName, relationTypeName, filterTypeName, orderByTypeName];
|
|
91
|
-
if (conditionTypeName)
|
|
92
|
-
reExportTypes.push(conditionTypeName);
|
|
93
88
|
statements.push((0, hooks_ast_1.createTypeReExport)(reExportTypes, '../../orm/input-types'));
|
|
94
89
|
// Query key
|
|
95
90
|
if (useCentralizedKeys) {
|
|
@@ -105,7 +100,6 @@ function generateListQueryHook(table, options = {}) {
|
|
|
105
100
|
const findManyKeyTypeArgs = [
|
|
106
101
|
t.tsUnknownKeyword(),
|
|
107
102
|
(0, hooks_ast_1.typeRef)(filterTypeName),
|
|
108
|
-
conditionTypeName ? (0, hooks_ast_1.typeRef)(conditionTypeName) : t.tsNeverKeyword(),
|
|
109
103
|
(0, hooks_ast_1.typeRef)(orderByTypeName),
|
|
110
104
|
];
|
|
111
105
|
const keyFn = t.arrowFunctionExpression([
|
|
@@ -267,7 +267,6 @@ export function parseFindManyArgs<T = Record<string, unknown>>(
|
|
|
267
267
|
const where = parsed.where ?? extraWhere
|
|
268
268
|
? { ...(extraWhere ?? {}), ...((parsed.where as Record<string, unknown>) ?? {}) }
|
|
269
269
|
: undefined;
|
|
270
|
-
const condition = parsed.condition;
|
|
271
270
|
const orderBy = parseOrderByFlag(argv);
|
|
272
271
|
|
|
273
272
|
return {
|
|
@@ -278,14 +277,13 @@ export function parseFindManyArgs<T = Record<string, unknown>>(
|
|
|
278
277
|
...(before !== undefined ? { before } : {}),
|
|
279
278
|
...(offset !== undefined ? { offset } : {}),
|
|
280
279
|
...(where !== undefined ? { where } : {}),
|
|
281
|
-
...(condition !== undefined ? { condition } : {}),
|
|
282
280
|
...(orderBy !== undefined ? { orderBy } : {}),
|
|
283
281
|
} as unknown as T;
|
|
284
282
|
}
|
|
285
283
|
|
|
286
284
|
/**
|
|
287
285
|
* Build findFirst args from CLI argv.
|
|
288
|
-
* Like parseFindManyArgs but only includes select
|
|
286
|
+
* Like parseFindManyArgs but only includes select and where
|
|
289
287
|
* (no pagination flags — findFirst returns the first matching record).
|
|
290
288
|
*/
|
|
291
289
|
export function parseFindFirstArgs<T = Record<string, unknown>>(
|
|
@@ -295,12 +293,10 @@ export function parseFindFirstArgs<T = Record<string, unknown>>(
|
|
|
295
293
|
const select = parseSelectFlag(argv, defaultSelect);
|
|
296
294
|
const parsed = unflattenDotNotation(argv);
|
|
297
295
|
const where = parsed.where;
|
|
298
|
-
const condition = parsed.condition;
|
|
299
296
|
|
|
300
297
|
return {
|
|
301
298
|
select,
|
|
302
299
|
...(where !== undefined ? { where } : {}),
|
|
303
|
-
...(condition !== undefined ? { condition } : {}),
|
|
304
300
|
} as unknown as T;
|
|
305
301
|
}
|
|
306
302
|
|