Skip to content

Commit

Permalink
Merge pull request #341 from Quramy/fix/issue_307
Browse files Browse the repository at this point in the history
Sometimes `{}` is not assignable to  ModelFactoryInput
  • Loading branch information
Quramy committed Jun 24, 2024
2 parents 8057938 + de61ac5 commit 0464930
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 21 deletions.
14 changes: 7 additions & 7 deletions examples/example-prj/src/__generated__/fabbrica/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions packages/artifact-testing/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
fixtures/*/__generated__/client
dmmf.json
built/
built_node/
built_esnext/

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/artifact-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"name": "artifact-testing",
"version": "2.1.4",
"scripts": {
"clean": "rimraf -g \"fixtures/*/__generated__/client\" \"fixtures/*/dmmf.json\" built built_node built_esnext \"*.tsbuildinfo\"",
"clean": "rimraf -g \"fixtures/*/__generated__/client\" \"fixtures/*/dmmf.json\" built \"*.tsbuildinfo\"",
"pretest:compile": "node scripts/generateFixtures.mjs",
"pretest:compile:ci": "node scripts/generateFixtures.mjs",
"test": "npm run test:compile && npm run test:functions",
"test:ci": "npm run test:compile:ci && npm run test:functions",
"test:compile": "tsc -p tsconfig.json && tsc -p tsconfig.esnext.json && tsc -p tsconfig.node.json",
"test:compile:ci": "tsc -p tsconfig.json && tsc -p tsconfig.esnext.json && tsc -p tsconfig.node.json",
"test:compile": "tsc -p tsconfig.json && tsc -p tsconfig.esnext.json && tsc -p tsconfig.node.json && tsc -p tsconfig.noNullChecks.json",
"test:compile:ci": "tsc -p tsconfig.json && tsc -p tsconfig.esnext.json && tsc -p tsconfig.node.json && tsc -p tsconfig.noNullChecks.json",
"test:functions": "jest"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/artifact-testing/tsconfig.esnext.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"noEmit": false,
"outDir": "built_esnext"
"outDir": "built/esnext"
},
"include": ["**/__generated__/**/*"],
"exclude": ["built", "built_node", "built_esnext"]
"exclude": ["built"]
}
4 changes: 2 additions & 2 deletions packages/artifact-testing/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"module": "commonjs",
"noEmit": false,
"outDir": "built"
"outDir": "built/commonjs"
},
"exclude": ["built", "built_node", "built_esnext"]
"exclude": ["built"]
}
10 changes: 10 additions & 0 deletions packages/artifact-testing/tsconfig.noNullChecks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"noEmit": false,
"outDir": "built/noNullChecks",
"strictNullChecks": false
},
"exclude": ["built"]
}
4 changes: 2 additions & 2 deletions packages/artifact-testing/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"compilerOptions": {
"module": "nodenext",
"noEmit": false,
"outDir": "built_node"
"outDir": "built/nodenext"
},
"include": ["**/__generated__/**/*"],
"exclude": ["built", "built_node", "built_esnext"]
"exclude": ["built"]
}
5 changes: 4 additions & 1 deletion packages/prisma-fabbrica/src/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ export const defineModelFactoryInternal = (model: DMMF.Model, inputType: DMMF.In
) => {
const seq = getSeq();
const requiredScalarData = AUTO_GENERATE_MODEL_SCALARS_OR_ENUMS({ seq });
const resolveValue = normalizeResolver<MODEL_FACTORY_DEFINE_INPUT, BuildDataOptions>(defaultDataResolver ?? {});
const resolveValue = normalizeResolver<MODEL_FACTORY_DEFINE_INPUT, BuildDataOptions>(DEFALUT_DATA_RESOLVER);
const defaultData = await traitKeys.reduce(async (queue, traitKey) => {
const acc = await queue;
const resolveTraitValue = normalizeResolver<Partial<MODEL_FACTORY_DEFINE_INPUT>, BuildDataOptions>(traitsDefs[traitKey]?.data ?? {});
Expand Down Expand Up @@ -457,6 +457,9 @@ export const defineModelFactoryInternal = (model: DMMF.Model, inputType: DMMF.In
MODEL_FACTORY_DEFINE_OPTIONS: ast.identifier(`${model.name}FactoryDefineOptions`),
MODEL_CREATE_INPUT: ast.identifier(`${model.name}CreateInput`),
AUTO_GENERATE_MODEL_SCALARS_OR_ENUMS: ast.identifier(`autoGenerate${model.name}ScalarsOrEnums`),
DEFALUT_DATA_RESOLVER: filterRequiredInputObjectTypeField(inputType).length
? template.expression(`defaultDataResolver`)({})
: template.expression(`defaultDataResolver ?? {}`)({}),
});

export const defineModelFactory = (model: DMMF.Model, inputType: DMMF.InputType) => {
Expand Down

0 comments on commit 0464930

Please sign in to comment.