diff --git a/examples/example-prj/src/__generated__/fabbrica/index.d.ts b/examples/example-prj/src/__generated__/fabbrica/index.d.ts index 7d39807..545d8d0 100644 --- a/examples/example-prj/src/__generated__/fabbrica/index.d.ts +++ b/examples/example-prj/src/__generated__/fabbrica/index.d.ts @@ -9,7 +9,6 @@ type BuildDataOptions = { readonly seq: number; }; export declare const initialize: (options: import("@quramy/prisma-fabbrica/lib/initialize").InitializeOptions) => void; -declare const factoryFor: unique symbol; type UserFactoryDefineInput = { id?: string; email?: string; @@ -29,7 +28,7 @@ type UserFactoryDefineOptions = { }; type UserTraitKeys = keyof TOptions["traits"]; export interface UserFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "User"; + readonly _factoryFor: "User"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -49,7 +48,7 @@ export interface UserFactoryInterface(options?: TOptions): UserFactoryInterface; type PostauthorFactory = { - [factoryFor]: "User"; + _factoryFor: "User"; build: () => PromiseLike; }; type PostFactoryDefineInput = { @@ -71,7 +70,7 @@ type PostFactoryDefineOptions = { }; type PostTraitKeys = keyof TOptions["traits"]; export interface PostFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "Post"; + readonly _factoryFor: "Post"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -91,11 +90,11 @@ export interface PostFactoryInterface(options: TOptions): PostFactoryInterface; type CommentpostFactory = { - [factoryFor]: "Post"; + _factoryFor: "Post"; build: () => PromiseLike; }; type CommentauthorFactory = { - [factoryFor]: "User"; + _factoryFor: "User"; build: () => PromiseLike; }; type CommentFactoryDefineInput = { @@ -116,7 +115,7 @@ type CommentFactoryDefineOptions = { }; type CommentTraitKeys = keyof TOptions["traits"]; export interface CommentFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "Comment"; + readonly _factoryFor: "Comment"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -150,7 +149,7 @@ type CategoryFactoryDefineOptions = { }; type CategoryTraitKeys = keyof TOptions["traits"]; export interface CategoryFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "Category"; + readonly _factoryFor: "Category"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; diff --git a/examples/example-prj/src/__generated__/fabbrica/index.js b/examples/example-prj/src/__generated__/fabbrica/index.js index 85551f6..4a84950 100644 --- a/examples/example-prj/src/__generated__/fabbrica/index.js +++ b/examples/example-prj/src/__generated__/fabbrica/index.js @@ -9,7 +9,6 @@ Object.defineProperty(exports, "resetScalarFieldValueGenerator", { enumerable: t const initializer = (0, internal_1.createInitializer)(); const { getClient } = initializer; exports.initialize = initializer.initialize; -const factoryFor = Symbol("factoryFor"); const modelFieldDefinitions = [{ name: "User", fields: [{ @@ -95,7 +94,7 @@ function defineUserFactoryInternal({ defaultData: defaultDataResolver, traits: t const createList = (inputData) => Promise.all((0, internal_1.normalizeList)(inputData).map(data => create(data))); const createForConnect = (inputData = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "User", + _factoryFor: "User", build, buildList, buildCreateInput: build, @@ -125,7 +124,7 @@ function defineUserFactory(options) { } exports.defineUserFactory = defineUserFactory; function isPostauthorFactory(x) { - return x?.[factoryFor] === "User"; + return x?._factoryFor === "User"; } function autoGeneratePostScalarsOrEnums({ seq }) { return { @@ -170,7 +169,7 @@ function definePostFactoryInternal({ defaultData: defaultDataResolver, traits: t const createList = (inputData) => Promise.all((0, internal_1.normalizeList)(inputData).map(data => create(data))); const createForConnect = (inputData = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "Post", + _factoryFor: "Post", build, buildList, buildCreateInput: build, @@ -200,10 +199,10 @@ function definePostFactory(options) { } exports.definePostFactory = definePostFactory; function isCommentpostFactory(x) { - return x?.[factoryFor] === "Post"; + return x?._factoryFor === "Post"; } function isCommentauthorFactory(x) { - return x?.[factoryFor] === "User"; + return x?._factoryFor === "User"; } function autoGenerateCommentScalarsOrEnums({ seq }) { return { @@ -251,7 +250,7 @@ function defineCommentFactoryInternal({ defaultData: defaultDataResolver, traits const createList = (inputData) => Promise.all((0, internal_1.normalizeList)(inputData).map(data => create(data))); const createForConnect = (inputData = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "Comment", + _factoryFor: "Comment", build, buildList, buildCreateInput: build, @@ -319,7 +318,7 @@ function defineCategoryFactoryInternal({ defaultData: defaultDataResolver, trait const createList = (inputData) => Promise.all((0, internal_1.normalizeList)(inputData).map(data => create(data))); const createForConnect = (inputData = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "Category", + _factoryFor: "Category", build, buildList, buildCreateInput: build, diff --git a/packages/artifact-testing/.gitignore b/packages/artifact-testing/.gitignore index 4fe8d26..303ec13 100644 --- a/packages/artifact-testing/.gitignore +++ b/packages/artifact-testing/.gitignore @@ -1,2 +1,3 @@ fixtures/*/__generated__/client dmmf.json +built/ diff --git a/packages/artifact-testing/fixtures/field-variation/__generated__/fabbrica/index.ts b/packages/artifact-testing/fixtures/field-variation/__generated__/fabbrica/index.ts index 95e6d48..74fa05d 100644 --- a/packages/artifact-testing/fixtures/field-variation/__generated__/fabbrica/index.ts +++ b/packages/artifact-testing/fixtures/field-variation/__generated__/fabbrica/index.ts @@ -19,8 +19,6 @@ const { getClient } = initializer; export const { initialize } = initializer; -const factoryFor = Symbol("factoryFor"); - const modelFieldDefinitions: ModelWithFields[] = [{ name: "User", fields: [] @@ -63,7 +61,7 @@ type UserFactoryDefineOptions = { type UserTraitKeys = keyof TOptions["traits"]; export interface UserFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "User"; + readonly _factoryFor: "User"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -119,7 +117,7 @@ function defineUserFactoryInternal({ const createList = (inputData: number | readonly Partial[]) => Promise.all(normalizeList(inputData).map(data => create(data))); const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "User" as const, + _factoryFor: "User" as const, build, buildList, buildCreateInput: build, @@ -171,7 +169,7 @@ type ComplexIdModelFactoryDefineOptions = { type ComplexIdModelTraitKeys = keyof TOptions["traits"]; export interface ComplexIdModelFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "ComplexIdModel"; + readonly _factoryFor: "ComplexIdModel"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -228,7 +226,7 @@ function defineComplexIdModelFactoryInternal[]) => Promise.all(normalizeList(inputData).map(data => create(data))); const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "ComplexIdModel" as const, + _factoryFor: "ComplexIdModel" as const, build, buildList, buildCreateInput: build, @@ -304,7 +302,7 @@ type FieldTypePatternModelFactoryDefineOptions = { type FieldTypePatternModelTraitKeys = keyof TOptions["traits"]; export interface FieldTypePatternModelFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "FieldTypePatternModel"; + readonly _factoryFor: "FieldTypePatternModel"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -367,7 +365,7 @@ function defineFieldTypePatternModelFactoryInternal[]) => Promise.all(normalizeList(inputData).map(data => create(data))); const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "FieldTypePatternModel" as const, + _factoryFor: "FieldTypePatternModel" as const, build, buildList, buildCreateInput: build, @@ -417,7 +415,7 @@ type NoPkModelFactoryDefineOptions = { type NoPkModelTraitKeys = keyof TOptions["traits"]; export interface NoPkModelFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "NoPkModel"; + readonly _factoryFor: "NoPkModel"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -472,7 +470,7 @@ function defineNoPkModelFactoryInternal[]) => Promise.all(normalizeList(inputData).map(data => create(data))); const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "NoPkModel" as const, + _factoryFor: "NoPkModel" as const, build, buildList, buildCreateInput: build, diff --git a/packages/artifact-testing/fixtures/relations-many-to-many/__generated__/fabbrica/index.ts b/packages/artifact-testing/fixtures/relations-many-to-many/__generated__/fabbrica/index.ts index b1a45aa..2042882 100644 --- a/packages/artifact-testing/fixtures/relations-many-to-many/__generated__/fabbrica/index.ts +++ b/packages/artifact-testing/fixtures/relations-many-to-many/__generated__/fabbrica/index.ts @@ -15,8 +15,6 @@ const { getClient } = initializer; export const { initialize } = initializer; -const factoryFor = Symbol("factoryFor"); - const modelFieldDefinitions: ModelWithFields[] = [{ name: "Post", fields: [{ @@ -56,7 +54,7 @@ type PostFactoryDefineOptions = { type PostTraitKeys = keyof TOptions["traits"]; export interface PostFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "Post"; + readonly _factoryFor: "Post"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -112,7 +110,7 @@ function definePostFactoryInternal({ const createList = (inputData: number | readonly Partial[]) => Promise.all(normalizeList(inputData).map(data => create(data))); const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "Post" as const, + _factoryFor: "Post" as const, build, buildList, buildCreateInput: build, @@ -165,7 +163,7 @@ type CategoryFactoryDefineOptions = { type CategoryTraitKeys = keyof TOptions["traits"]; export interface CategoryFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "Category"; + readonly _factoryFor: "Category"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -221,7 +219,7 @@ function defineCategoryFactoryInternal[]) => Promise.all(normalizeList(inputData).map(data => create(data))); const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "Category" as const, + _factoryFor: "Category" as const, build, buildList, buildCreateInput: build, diff --git a/packages/artifact-testing/fixtures/relations-one-to-many/__generated__/fabbrica/index.ts b/packages/artifact-testing/fixtures/relations-one-to-many/__generated__/fabbrica/index.ts index e6e1f52..ae26243 100644 --- a/packages/artifact-testing/fixtures/relations-one-to-many/__generated__/fabbrica/index.ts +++ b/packages/artifact-testing/fixtures/relations-one-to-many/__generated__/fabbrica/index.ts @@ -16,8 +16,6 @@ const { getClient } = initializer; export const { initialize } = initializer; -const factoryFor = Symbol("factoryFor"); - const modelFieldDefinitions: ModelWithFields[] = [{ name: "User", fields: [{ @@ -77,7 +75,7 @@ type UserFactoryDefineOptions = { type UserTraitKeys = keyof TOptions["traits"]; export interface UserFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "User"; + readonly _factoryFor: "User"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -133,7 +131,7 @@ function defineUserFactoryInternal({ const createList = (inputData: number | readonly Partial[]) => Promise.all(normalizeList(inputData).map(data => create(data))); const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "User" as const, + _factoryFor: "User" as const, build, buildList, buildCreateInput: build, @@ -169,7 +167,7 @@ type PostScalarOrEnumFields = { }; type PostauthorFactory = { - [factoryFor]: "User"; + _factoryFor: "User"; build: () => PromiseLike; }; @@ -190,13 +188,13 @@ type PostFactoryDefineOptions = { }; function isPostauthorFactory(x: PostauthorFactory | Prisma.UserCreateNestedOneWithoutPostsInput | undefined): x is PostauthorFactory { - return (x as any)?.[factoryFor] === "User"; + return (x as any)?._factoryFor === "User"; } type PostTraitKeys = keyof TOptions["traits"]; export interface PostFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "Post"; + readonly _factoryFor: "Post"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -256,7 +254,7 @@ function definePostFactoryInternal({ const createList = (inputData: number | readonly Partial[]) => Promise.all(normalizeList(inputData).map(data => create(data))); const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "Post" as const, + _factoryFor: "Post" as const, build, buildList, buildCreateInput: build, @@ -292,12 +290,12 @@ type ReviewScalarOrEnumFields = { }; type ReviewpostFactory = { - [factoryFor]: "Post"; + _factoryFor: "Post"; build: () => PromiseLike; }; type ReviewreviewerFactory = { - [factoryFor]: "User"; + _factoryFor: "User"; build: () => PromiseLike; }; @@ -318,17 +316,17 @@ type ReviewFactoryDefineOptions = { }; function isReviewpostFactory(x: ReviewpostFactory | Prisma.PostCreateNestedOneWithoutReviewsInput | undefined): x is ReviewpostFactory { - return (x as any)?.[factoryFor] === "Post"; + return (x as any)?._factoryFor === "Post"; } function isReviewreviewerFactory(x: ReviewreviewerFactory | Prisma.UserCreateNestedOneWithoutReviewsInput | undefined): x is ReviewreviewerFactory { - return (x as any)?.[factoryFor] === "User"; + return (x as any)?._factoryFor === "User"; } type ReviewTraitKeys = keyof TOptions["traits"]; export interface ReviewFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "Review"; + readonly _factoryFor: "Review"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -391,7 +389,7 @@ function defineReviewFactoryInternal[]) => Promise.all(normalizeList(inputData).map(data => create(data))); const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "Review" as const, + _factoryFor: "Review" as const, build, buildList, buildCreateInput: build, diff --git a/packages/artifact-testing/fixtures/relations-one-to-one/__generated__/fabbrica/index.ts b/packages/artifact-testing/fixtures/relations-one-to-one/__generated__/fabbrica/index.ts index f9f589b..044ca80 100644 --- a/packages/artifact-testing/fixtures/relations-one-to-one/__generated__/fabbrica/index.ts +++ b/packages/artifact-testing/fixtures/relations-one-to-one/__generated__/fabbrica/index.ts @@ -15,8 +15,6 @@ const { getClient } = initializer; export const { initialize } = initializer; -const factoryFor = Symbol("factoryFor"); - const modelFieldDefinitions: ModelWithFields[] = [{ name: "User", fields: [{ @@ -39,7 +37,7 @@ type UserScalarOrEnumFields = { }; type UserprofileFactory = { - [factoryFor]: "Profile"; + _factoryFor: "Profile"; build: () => PromiseLike; }; @@ -59,13 +57,13 @@ type UserFactoryDefineOptions = { }; function isUserprofileFactory(x: UserprofileFactory | Prisma.ProfileCreateNestedOneWithoutUserInput | undefined): x is UserprofileFactory { - return (x as any)?.[factoryFor] === "Profile"; + return (x as any)?._factoryFor === "Profile"; } type UserTraitKeys = keyof TOptions["traits"]; export interface UserFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "User"; + readonly _factoryFor: "User"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -125,7 +123,7 @@ function defineUserFactoryInternal({ const createList = (inputData: number | readonly Partial[]) => Promise.all(normalizeList(inputData).map(data => create(data))); const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "User" as const, + _factoryFor: "User" as const, build, buildList, buildCreateInput: build, @@ -160,7 +158,7 @@ type ProfileScalarOrEnumFields = { }; type ProfileuserFactory = { - [factoryFor]: "User"; + _factoryFor: "User"; build: () => PromiseLike; }; @@ -179,13 +177,13 @@ type ProfileFactoryDefineOptions = { }; function isProfileuserFactory(x: ProfileuserFactory | Prisma.UserCreateNestedOneWithoutProfileInput | undefined): x is ProfileuserFactory { - return (x as any)?.[factoryFor] === "User"; + return (x as any)?._factoryFor === "User"; } type ProfileTraitKeys = keyof TOptions["traits"]; export interface ProfileFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "Profile"; + readonly _factoryFor: "Profile"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -244,7 +242,7 @@ function defineProfileFactoryInternal[]) => Promise.all(normalizeList(inputData).map(data => create(data))); const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "Profile" as const, + _factoryFor: "Profile" as const, build, buildList, buildCreateInput: build, diff --git a/packages/artifact-testing/fixtures/simple-model/__generated__/fabbrica/index.ts b/packages/artifact-testing/fixtures/simple-model/__generated__/fabbrica/index.ts index 8962e01..9e08528 100644 --- a/packages/artifact-testing/fixtures/simple-model/__generated__/fabbrica/index.ts +++ b/packages/artifact-testing/fixtures/simple-model/__generated__/fabbrica/index.ts @@ -14,8 +14,6 @@ const { getClient } = initializer; export const { initialize } = initializer; -const factoryFor = Symbol("factoryFor"); - const modelFieldDefinitions: ModelWithFields[] = [{ name: "User", fields: [] @@ -43,7 +41,7 @@ type UserFactoryDefineOptions = { type UserTraitKeys = keyof TOptions["traits"]; export interface UserFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "User"; + readonly _factoryFor: "User"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -99,7 +97,7 @@ function defineUserFactoryInternal({ const createList = (inputData: number | readonly Partial[]) => Promise.all(normalizeList(inputData).map(data => create(data))); const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "User" as const, + _factoryFor: "User" as const, build, buildList, buildCreateInput: build, diff --git a/packages/artifact-testing/package.json b/packages/artifact-testing/package.json index 12ced81..641a52c 100644 --- a/packages/artifact-testing/package.json +++ b/packages/artifact-testing/package.json @@ -3,7 +3,7 @@ "name": "artifact-testing", "version": "2.1.0", "scripts": { - "clean": "rimraf \"fixtures/*/__generated__/client\" \"fixtures/*/dmmf.json\"", + "clean": "rimraf -g \"fixtures/*/__generated__/client\" \"fixtures/*/dmmf.json\" built \"*.tsbuildinfo\"", "pretest:compile": "ts-node scripts/generateFixtures.ts", "pretest:compile:ci": "ts-node scripts/generateFixtures.ts", "test": "npm run test:compile && npm run test:functions", diff --git a/packages/artifact-testing/tsconfig.json b/packages/artifact-testing/tsconfig.json index 7e62704..b7e04e4 100644 --- a/packages/artifact-testing/tsconfig.json +++ b/packages/artifact-testing/tsconfig.json @@ -1,6 +1,8 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "noEmit": true - } + "noEmit": false, + "outDir": "built" + }, + "exclude": ["built"] } diff --git a/packages/prisma-fabbrica/package.json b/packages/prisma-fabbrica/package.json index 7b2270f..38d62c1 100644 --- a/packages/prisma-fabbrica/package.json +++ b/packages/prisma-fabbrica/package.json @@ -31,7 +31,7 @@ } }, "scripts": { - "clean": "rimraf \"*.tsbuildinfo\" \"lib/**/*.{js,ts}\" coverage", + "clean": "rimraf -g \"*.tsbuildinfo\" \"lib/**/*.{js,ts}\" coverage", "test": "NODE_ENV=development jest", "test:ci": "NODE_ENV=development jest --coverage", "prepublishOnly": "cp ../../README.md ." diff --git a/packages/prisma-fabbrica/src/templates/__snapshots__/getSourceFile.test.ts.snap b/packages/prisma-fabbrica/src/templates/__snapshots__/getSourceFile.test.ts.snap index 0c5d744..295f8b8 100644 --- a/packages/prisma-fabbrica/src/templates/__snapshots__/getSourceFile.test.ts.snap +++ b/packages/prisma-fabbrica/src/templates/__snapshots__/getSourceFile.test.ts.snap @@ -17,8 +17,6 @@ const { getClient } = initializer; export const { initialize } = initializer; -const factoryFor = Symbol("factoryFor"); - const modelFieldDefinitions: ModelWithFields[] = [{ name: "User", fields: [] @@ -46,7 +44,7 @@ type UserFactoryDefineOptions = { type UserTraitKeys = keyof TOptions["traits"]; export interface UserFactoryInterfaceWithoutTraits { - readonly [factoryFor]: "User"; + readonly _factoryFor: "User"; build(inputData?: Partial): PromiseLike; buildCreateInput(inputData?: Partial): PromiseLike; buildList(inputData: number | readonly Partial[]): PromiseLike; @@ -102,7 +100,7 @@ function defineUserFactoryInternal({ const createList = (inputData: number | readonly Partial[]) => Promise.all(normalizeList(inputData).map(data => create(data))); const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: "User" as const, + _factoryFor: "User" as const, build, buildList, buildCreateInput: build, diff --git a/packages/prisma-fabbrica/src/templates/index.ts b/packages/prisma-fabbrica/src/templates/index.ts index d99da7f..d29fc9a 100644 --- a/packages/prisma-fabbrica/src/templates/index.ts +++ b/packages/prisma-fabbrica/src/templates/index.ts @@ -112,11 +112,6 @@ export const initializer = () => export const { initialize } = initializer; `(); -export const symbols = () => - template.sourceFile` - const factoryFor = Symbol("factoryFor"); - `(); - export const modelFieldDefinitions = (models: readonly DMMF.Model[]) => template.statement` const modelFieldDefinitions: ModelWithFields[] = ${() => createJSONLiteral(createFieldDefinitions(models))}; @@ -202,7 +197,7 @@ export const modelBelongsToRelationFactory = (fieldType: DMMF.SchemaArg, model: const targetModel = model.fields.find(byName(fieldType))!; return template.statement` type ${() => ast.identifier(`${model.name}${fieldType.name}Factory`)} = { - [factoryFor]: ${() => ast.literalTypeNode(ast.stringLiteral(targetModel.type))}; + _factoryFor: ${() => ast.literalTypeNode(ast.stringLiteral(targetModel.type))}; build: () => PromiseLike ast.identifier(fieldType.inputTypes[0].type as string)}["create"]>; }; `(); @@ -270,7 +265,7 @@ export const modelTraitKeys = (model: DMMF.Model) => export const modelFactoryInterfaceWithoutTraits = (model: DMMF.Model) => template.statement` export interface MODEL_FACTORY_INTERFACE_WITHOUT_TRAITS { - readonly [factoryFor]: ${() => ast.literalTypeNode(ast.stringLiteral(model.name))} + readonly _factoryFor: ${() => ast.literalTypeNode(ast.stringLiteral(model.name))} build(inputData?: Partial): PromiseLike buildCreateInput(inputData?: Partial): PromiseLike buildList(inputData: number | readonly Partial[]): PromiseLike @@ -307,7 +302,7 @@ export const isModelAssociationFactory = (fieldType: DMMF.SchemaArg, model: DMMF x: MODEL_BELONGS_TO_RELATION_FACTORY | ${() => argInputType(model, fieldType.name, fieldType.inputTypes[0])} | undefined ): x is MODEL_BELONGS_TO_RELATION_FACTORY { - return (x as any)?.[factoryFor] === ${() => ast.stringLiteral(targetModel.type)}; + return (x as any)?._factoryFor === ${() => ast.stringLiteral(targetModel.type)}; } `({ MODEL_BELONGS_TO_RELATION_FACTORY: ast.typeReferenceNode(`${model.name}${fieldType.name}Factory`), @@ -433,7 +428,7 @@ export const defineModelFactoryInternal = (model: DMMF.Model, inputType: DMMF.In const createForConnect = (inputData: Partial = {}) => create(inputData).then(pickForConnect); return { - [factoryFor]: ${() => ast.stringLiteral(model.name)} as const, + _factoryFor: ${() => ast.stringLiteral(model.name)} as const, build, buildList, buildCreateInput: build, @@ -521,7 +516,6 @@ export function getSourceFile({ ...header(prismaClientModuleSpecifier).statements, insertLeadingBreakMarker(buildDataOptions()), ...insertLeadingBreakMarker(initializer().statements), - ...insertLeadingBreakMarker(symbols().statements), insertLeadingBreakMarker(modelFieldDefinitions(document.datamodel.models)), ...document.datamodel.models .reduce((acc, model) => {