Repository: Quramy/prisma-fabbrica (ts)

Issue:
Override scalar field generate functions
Allow to customize rules defined https://github.com/Quramy/prisma-fabbrica/blob/main/packages/prisma-fabbrica/src/scalar/gen.ts . 

```ts
registerScalarFieldValueGenerator({
  String: ({ fieldName }) => {
    if (fieldName.endsWith('email')) {
      return randomeEmail()
    }
    return fieldName;
  },
})
```

Pull request description:
feat: Allow to custom scalar generation rule
It closes #35 

Patch:
diff --git a/README.md b/README.md
index fea9bf1..29f702d 100644
--- a/README.md
+++ b/README.md
@@ -19,6 +19,7 @@ Prisma generator for model factories.
   - [Connection helper](#connection-helper)
   - [Build input data only](#build-input-data-only)
   - [has-many / has-one relation](#has-many--has-one-relation)
+  - [Custom scalar field generation](#custom-scalar-field-generation)
   - [More examples](#more-examples)
 - [Generator configuration](#generator-configuration)
 - [Tips](#tips)
@@ -316,6 +317,26 @@ Note: In the above example, `PostFactory.build()` resolves JSON data such as:
 
 The `author` field is not allowed in `prisma.user.create` context. So `UserFactory` automatically filters the `author` field out in `.create` method.
 
+### Custom scalar field generation
+
+prisma-fabbrica provides function to complete scalar fields( https://github.com/Quramy/prisma-fabbrica/blob/main/packages/prisma-fabbrica/src/scalar/gen.ts ).
+
+`registerScalarFieldValueGenerator` allows to custom this rule. For example:
+
+```ts
+import { registerScalarFieldValueGenerator } from "./__generated__/fabbrica";
+
+registerScalarFieldValueGenerator({
+  String: ({ modelName, fieldName, seq }) => `${modelName}_{fieldName}_${seq}`,
+});
+```
+
+`registerScalarFieldValueGenerator` accepts an object `Record<FiledType, FieldGenerateFunction>`.
+Field type is one of `Boolean`, `String`, `Int`, `Float`, `BigInt`, `Decimal`, `DateTime`, `Bytes`, and `Json`
+`FieldGenerateFunction` is a function to return corresponding filed type.
+
+See also https://github.com/Quramy/prisma-fabbrica/blob/main/packages/prisma-fabbrica/src/scalar/types.ts .
+
 ### More examples
 
 There are more example codes in https://github.com/Quramy/prisma-fabbrica/tree/main/examples/example-prj/src .
diff --git a/examples/example-prj/src/__generated__/fabbrica/index.d.ts b/examples/example-prj/src/__generated__/fabbrica/index.d.ts
index 94b78b1..a741263 100644
--- a/examples/example-prj/src/__generated__/fabbrica/index.d.ts
+++ b/examples/example-prj/src/__generated__/fabbrica/index.d.ts
@@ -4,7 +4,7 @@ import type { Comment } from "@prisma/client";
 import type { Category } from "@prisma/client";
 import { Prisma } from "@prisma/client";
 import { Resolver } from "@quramy/prisma-fabbrica/lib/internal";
-export { initialize, resetSequence } from "@quramy/prisma-fabbrica/lib/internal";
+export { initialize, resetSequence, registerScalarFieldValueGenerator, resetScalarFieldValueGenerator } from "@quramy/prisma-fabbrica/lib/internal";
 type BuildDataOptions = {
     readonly seq: number;
 };
diff --git a/examples/example-prj/src/__generated__/fabbrica/index.js b/examples/example-prj/src/__generated__/fabbrica/index.js
index 7966a44..38a0ac2 100644
--- a/examples/example-prj/src/__generated__/fabbrica/index.js
+++ b/examples/example-prj/src/__generated__/fabbrica/index.js
@@ -1,10 +1,12 @@
 "use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.defineCategoryFactory = exports.defineCommentFactory = exports.definePostFactory = exports.defineUserFactory = exports.resetSequence = exports.initialize = void 0;
+exports.defineCategoryFactory = exports.defineCommentFactory = exports.definePostFactory = exports.defineUserFactory = exports.resetScalarFieldValueGenerator = exports.registerScalarFieldValueGenerator = exports.resetSequence = exports.initialize = void 0;
 const internal_1 = require("@quramy/prisma-fabbrica/lib/internal");
 var internal_2 = require("@quramy/prisma-fabbrica/lib/internal");
 Object.defineProperty(exports, "initialize", { enumerable: true, get: function () { return internal_2.initialize; } });
 Object.defineProperty(exports, "resetSequence", { enumerable: true, get: function () { return internal_2.resetSequence; } });
+Object.defineProperty(exports, "registerScalarFieldValueGenerator", { enumerable: true, get: function () { return internal_2.registerScalarFieldValueGenerator; } });
+Object.defineProperty(exports, "resetScalarFieldValueGenerator", { enumerable: true, get: function () { return internal_2.resetScalarFieldValueGenerator; } });
 const modelFieldDefinitions = [{
         name: "User",
         fields: [{
@@ -52,9 +54,9 @@ const modelFieldDefinitions = [{
     }];
 function autoGenerateUserScalarsOrEnums({ seq }) {
     return {
-        id: internal_1.scalarFieldValueGenerator.String({ modelName: "User", fieldName: "id", isId: true, isUnique: false, seq }),
-        email: internal_1.scalarFieldValueGenerator.String({ modelName: "User", fieldName: "email", isId: false, isUnique: true, seq }),
-        name: internal_1.scalarFieldValueGenerator.String({ modelName: "User", fieldName: "name", isId: false, isUnique: false, seq })
+        id: (0, internal_1.getScalarFieldValueGenerator)().String({ modelName: "User", fieldName: "id", isId: true, isUnique: false, seq }),
+        email: (0, internal_1.getScalarFieldValueGenerator)().String({ modelName: "User", fieldName: "email", isId: false, isUnique: true, seq }),
+        name: (0, internal_1.getScalarFieldValueGenerator)().String({ modelName: "User", fieldName: "name", isId: false, isUnique: false, seq })
     };
 }
 function defineUserFactoryInternal({ defaultData: defaultDataResolver }) {
@@ -106,8 +108,8 @@ function isPostauthorFactory(x) {
 }
 function autoGeneratePostScalarsOrEnums({ seq }) {
     return {
-        id: internal_1.scalarFieldValueGenerator.String({ modelName: "Post", fieldName: "id", isId: true, isUnique: false, seq }),
-        title: internal_1.scalarFieldValueGenerator.String({ modelName: "Post", fieldName: "title", isId: false, isUnique: false, seq })
+        id: (0, internal_1.getScalarFieldValueGenerator)().String({ modelName: "Post", fieldName: "id", isId: true, isUnique: false, seq }),
+        title: (0, internal_1.getScalarFieldValueGenerator)().String({ modelName: "Post", fieldName: "title", isId: false, isUnique: false, seq })
     };
 }
 function definePostFactoryInternal({ defaultData: defaultDataResolver }) {
@@ -166,8 +168,8 @@ function isCommentauthorFactory(x) {
 }
 function autoGenerateCommentScalarsOrEnums({ seq }) {
     return {
-        id: internal_1.scalarFieldValueGenerator.String({ modelName: "Comment", fieldName: "id", isId: true, isUnique: false, seq }),
-        body: internal_1.scalarFieldValueGenerator.String({ modelName: "Comment", fieldName: "body", isId: false, isUnique: false, seq })
+        id: (0, internal_1.getScalarFieldValueGenerator)().String({ modelName: "Comment", fieldName: "id", isId: true, isUnique: false, seq }),
+        body: (0, internal_1.getScalarFieldValueGenerator)().String({ modelName: "Comment", fieldName: "body", isId: false, isUnique: false, seq })
     };
 }
 function defineCommentFactoryInternal({ defaultData: defaultDataResolver }) {
@@ -223,8 +225,8 @@ function defineCommentFactory(options) {
 exports.defineCommentFactory = defineCommentFactory;
 function autoGenerateCategoryScalarsOrEnums({ seq }) {
     return {
-        id: internal_1.scalarFieldValueGenerator.String({ modelName: "Category", fieldName: "id", isId: true, isUnique: false, seq }),
-        name: internal_1.scalarFieldValueGenerator.String({ modelName: "Category", fieldName: "name", isId: false, isUnique: true, seq })
+        id: (0, internal_1.getScalarFieldValueGenerator)().String({ modelName: "Category", fieldName: "id", isId: true, isUnique: false, seq }),
+        name: (0, internal_1.getScalarFieldValueGenerator)().String({ modelName: "Category", fieldName: "name", isId: false, isUnique: true, seq })
     };
 }
 function defineCategoryFactoryInternal({ defaultData: defaultDataResolver }) {
diff --git a/packages/prisma-fabbrica/src/initialize.ts b/packages/prisma-fabbrica/src/initialize.ts
index 84da06d..c48a7fc 100644
--- a/packages/prisma-fabbrica/src/initialize.ts
+++ b/packages/prisma-fabbrica/src/initialize.ts
@@ -1,6 +1,8 @@
 import { resetClient, setClient, PrismaClientLike } from "./clientHolder";
 import { resetSequence } from "./helpers";
+import { resetScalarFieldValueGenerator } from "./internal";
 export { resetSequence } from "./helpers";
+export { registerScalarFieldValueGenerator, resetScalarFieldValueGenerator } from "./scalar/customize";
 
 export type InitializeOptions = {
   readonly prisma: PrismaClientLike | (() => PrismaClientLike);
@@ -9,6 +11,7 @@ export type InitializeOptions = {
 export function reset() {
   resetClient();
   resetSequence();
+  resetScalarFieldValueGenerator();
 }
 
 export function initialize(options: InitializeOptions) {
diff --git a/packages/prisma-fabbrica/src/internal.ts b/packages/prisma-fabbrica/src/internal.ts
index ca0208a..97c00f3 100644
--- a/packages/prisma-fabbrica/src/internal.ts
+++ b/packages/prisma-fabbrica/src/internal.ts
@@ -1,5 +1,9 @@
 export { getClient } from "./clientHolder";
 export { ModelWithFields, createScreener } from "./relations/screen";
-export { scalarFieldValueGenerator } from "./scalar/gen";
 export { Resolver, normalizeResolver, normalizeList, getSequenceCounter } from "./helpers";
 export { initialize, resetSequence } from "./initialize";
+export {
+  getScalarFieldValueGenerator,
+  registerScalarFieldValueGenerator,
+  resetScalarFieldValueGenerator,
+} from "./scalar/customize";
diff --git a/packages/prisma-fabbrica/src/scalar/customize.ts b/packages/prisma-fabbrica/src/scalar/customize.ts
new file mode 100644
index 0000000..3463b74
--- /dev/null
+++ b/packages/prisma-fabbrica/src/scalar/customize.ts
@@ -0,0 +1,19 @@
+import { scalarFieldValueGenerator } from "./gen";
+import { ScalarFieldValueGenerator, StrictScalarFieldValueGenerator } from "./types";
+
+let _customGeneratorDefinition: ScalarFieldValueGenerator | undefined;
+
+export function registerScalarFieldValueGenerator(generatorDefinition: ScalarFieldValueGenerator) {
+  _customGeneratorDefinition = generatorDefinition;
+}
+
+export function resetScalarFieldValueGenerator() {
+  _customGeneratorDefinition = undefined;
+}
+
+export function getScalarFieldValueGenerator(): StrictScalarFieldValueGenerator {
+  return {
+    ...scalarFieldValueGenerator,
+    ..._customGeneratorDefinition,
+  };
+}
diff --git a/packages/prisma-fabbrica/src/scalar/gen.ts b/packages/prisma-fabbrica/src/scalar/gen.ts
index 2a97a71..ee4c880 100644
--- a/packages/prisma-fabbrica/src/scalar/gen.ts
+++ b/packages/prisma-fabbrica/src/scalar/gen.ts
@@ -1,7 +1,7 @@
 import short from "short-uuid";
-import { ScalarFieldValueGenerator } from "./types";
+import { StrictScalarFieldValueGenerator } from "./types";
 
-export const scalarFieldValueGenerator: ScalarFieldValueGenerator = {
+export const scalarFieldValueGenerator: StrictScalarFieldValueGenerator = {
   Boolean: () => true,
   String: ({ fieldName, isId, isUnique }) => {
     if (isId || isUnique) {
diff --git a/packages/prisma-fabbrica/src/scalar/types.ts b/packages/prisma-fabbrica/src/scalar/types.ts
index ce8b1e3..416d828 100644
--- a/packages/prisma-fabbrica/src/scalar/types.ts
+++ b/packages/prisma-fabbrica/src/scalar/types.ts
@@ -6,14 +6,20 @@ export type ScalarFieldGenerateOptions = {
   readonly seq: number;
 };
 
+type Stricten<T extends {}> = {
+  [K in keyof T]-?: T[K];
+};
+
 export interface ScalarFieldValueGenerator {
-  Boolean: (options: ScalarFieldGenerateOptions) => boolean;
-  String: (options: ScalarFieldGenerateOptions) => string;
-  Int: (options: ScalarFieldGenerateOptions) => number;
-  Float: (options: ScalarFieldGenerateOptions) => number;
-  BigInt: (options: ScalarFieldGenerateOptions) => bigint;
-  Decimal: (options: ScalarFieldGenerateOptions) => any;
-  DateTime: (options: ScalarFieldGenerateOptions) => Date;
-  Bytes: (options: ScalarFieldGenerateOptions) => Buffer;
-  Json: (options: ScalarFieldGenerateOptions) => any;
+  Boolean?: (options: ScalarFieldGenerateOptions) => boolean;
+  String?: (options: ScalarFieldGenerateOptions) => string;
+  Int?: (options: ScalarFieldGenerateOptions) => number;
+  Float?: (options: ScalarFieldGenerateOptions) => number;
+  BigInt?: (options: ScalarFieldGenerateOptions) => bigint;
+  Decimal?: (options: ScalarFieldGenerateOptions) => any;
+  DateTime?: (options: ScalarFieldGenerateOptions) => Date;
+  Bytes?: (options: ScalarFieldGenerateOptions) => Buffer;
+  Json?: (options: ScalarFieldGenerateOptions) => any;
 }
+
+export type StrictScalarFieldValueGenerator = Stricten<ScalarFieldValueGenerator>;
diff --git a/packages/prisma-fabbrica/src/templates/index.ts b/packages/prisma-fabbrica/src/templates/index.ts
index 8ecab9f..a71087f 100644
--- a/packages/prisma-fabbrica/src/templates/index.ts
+++ b/packages/prisma-fabbrica/src/templates/index.ts
@@ -81,13 +81,13 @@ export const header = (prismaClientModuleSpecifier: string) =>
       getClient,
       ModelWithFields,
       createScreener,
-      scalarFieldValueGenerator,
+      getScalarFieldValueGenerator,
       Resolver,
       normalizeResolver,
       normalizeList,
       getSequenceCounter,
     } from "@quramy/prisma-fabbrica/lib/internal";
-    export { initialize, resetSequence } from "@quramy/prisma-fabbrica/lib/internal";
+    export { initialize, resetSequence, registerScalarFieldValueGenerator, resetScalarFieldValueGenerator } from "@quramy/prisma-fabbrica/lib/internal";
   `();
 
 export const buildDataOptions = () =>
@@ -273,7 +273,7 @@ export const autoGenerateModelScalarsOrEnumsFieldArgs = (
   // Note: In Json sclar filed, inputTypes[0].location is not scalar but enumType
   field.inputTypes[field.inputTypes.length - 1].location === "scalar"
     ? template.expression`
-        scalarFieldValueGenerator.SCALAR_TYPE({ modelName: MODEL_NAME, fieldName: FIELD_NAME, isId: IS_ID, isUnique: IS_UNIQUE, seq })
+        getScalarFieldValueGenerator().SCALAR_TYPE({ modelName: MODEL_NAME, fieldName: FIELD_NAME, isId: IS_ID, isUnique: IS_UNIQUE, seq })
       `({
         SCALAR_TYPE: ast.identifier(field.inputTypes[field.inputTypes.length - 1].type as string),
         MODEL_NAME: ast.stringLiteral(model.name),


Test patch:
diff --git a/examples/example-prj/src/customScalarField.test.ts b/examples/example-prj/src/customScalarField.test.ts
new file mode 100644
index 0000000..abfde44
--- /dev/null
+++ b/examples/example-prj/src/customScalarField.test.ts
@@ -0,0 +1,22 @@
+import { defineUserFactory, registerScalarFieldValueGenerator, resetSequence } from "./__generated__/fabbrica";
+
+const prisma = jestPrisma.client;
+
+const UserFactory = defineUserFactory();
+
+registerScalarFieldValueGenerator({
+  String: ({ modelName, fieldName, seq }) => (fieldName === "id" ? `${modelName}_id_${seq}` : seq + ""),
+});
+
+describe("factories", () => {
+  describe("UserFactory", () => {
+    beforeEach(async () => {
+      resetSequence();
+      await UserFactory.create();
+    });
+
+    it("creates record with customized scalar field", async () => {
+      await expect(prisma.user.findUnique({ where: { id: "User_id_0" } })).resolves.not.toBeNull();
+    });
+  });
+});
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 410a568..addab28 100644
--- a/packages/prisma-fabbrica/src/templates/__snapshots__/getSourceFile.test.ts.snap
+++ b/packages/prisma-fabbrica/src/templates/__snapshots__/getSourceFile.test.ts.snap
@@ -4,8 +4,8 @@ exports[`getSourceFile generates TypeScript AST 1`] = `
 "import type { User } from "@prisma/client";
 import { Prisma } from "@prisma/client";
 import type { PrismaClient } from "@prisma/client";
-import { getClient, ModelWithFields, createScreener, scalarFieldValueGenerator, Resolver, normalizeResolver, normalizeList, getSequenceCounter, } from "@quramy/prisma-fabbrica/lib/internal";
-export { initialize, resetSequence } from "@quramy/prisma-fabbrica/lib/internal";
+import { getClient, ModelWithFields, createScreener, getScalarFieldValueGenerator, Resolver, normalizeResolver, normalizeList, getSequenceCounter, } from "@quramy/prisma-fabbrica/lib/internal";
+export { initialize, resetSequence, registerScalarFieldValueGenerator, resetScalarFieldValueGenerator } from "@quramy/prisma-fabbrica/lib/internal";
 
 type BuildDataOptions = {
     readonly seq: number;
@@ -45,8 +45,8 @@ function autoGenerateUserScalarsOrEnums({ seq }: {
     readonly seq: number;
 }): UserScalarOrEnumFields {
     return {
-        id: scalarFieldValueGenerator.Int({ modelName: "User", fieldName: "id", isId: true, isUnique: false, seq }),
-        name: scalarFieldValueGenerator.String({ modelName: "User", fieldName: "name", isId: false, isUnique: false, seq })
+        id: getScalarFieldValueGenerator().Int({ modelName: "User", fieldName: "id", isId: true, isUnique: false, seq }),
+        name: getScalarFieldValueGenerator().String({ modelName: "User", fieldName: "name", isId: false, isUnique: false, seq })
     };
 }
 
diff --git a/packages/prisma-fabbrica/src/templates/autoGenerateModelScalarsOrEnumsFieldArgs.test.ts b/packages/prisma-fabbrica/src/templates/autoGenerateModelScalarsOrEnumsFieldArgs.test.ts
index 9ea331e..be4886f 100644
--- a/packages/prisma-fabbrica/src/templates/autoGenerateModelScalarsOrEnumsFieldArgs.test.ts
+++ b/packages/prisma-fabbrica/src/templates/autoGenerateModelScalarsOrEnumsFieldArgs.test.ts
@@ -13,7 +13,7 @@ describe(autoGenerateModelScalarsOrEnumsFieldArgs, () => {
       `,
       targetField: "id",
       expected: `
-        scalarFieldValueGenerator.Int({ modelName: "TestModel", fieldName: "id", isId: true, isUnique: false, seq })
+        getScalarFieldValueGenerator().Int({ modelName: "TestModel", fieldName: "id", isId: true, isUnique: false, seq })
       `,
     },
     {
@@ -26,7 +26,7 @@ describe(autoGenerateModelScalarsOrEnumsFieldArgs, () => {
       `,
       targetField: "complexIdField",
       expected: `
-        scalarFieldValueGenerator.Int({ modelName: "TestModel", fieldName: "complexIdField", isId: true, isUnique: false, seq })
+        getScalarFieldValueGenerator().Int({ modelName: "TestModel", fieldName: "complexIdField", isId: true, isUnique: false, seq })
       `,
     },
     {
@@ -38,7 +38,7 @@ describe(autoGenerateModelScalarsOrEnumsFieldArgs, () => {
       `,
       targetField: "uniqueField",
       expected: `
-        scalarFieldValueGenerator.String({ modelName: "TestModel", fieldName: "uniqueField", isId: false, isUnique: true, seq })
+        getScalarFieldValueGenerator().String({ modelName: "TestModel", fieldName: "uniqueField", isId: false, isUnique: true, seq })
       `,
     },
     {
@@ -52,7 +52,7 @@ describe(autoGenerateModelScalarsOrEnumsFieldArgs, () => {
       `,
       targetField: "uniqueField1",
       expected: `
-        scalarFieldValueGenerator.String({ modelName: "TestModel", fieldName: "uniqueField1", isId: false, isUnique: true, seq })
+        getScalarFieldValueGenerator().String({ modelName: "TestModel", fieldName: "uniqueField1", isId: false, isUnique: true, seq })
       `,
     },
     {
@@ -64,7 +64,7 @@ describe(autoGenerateModelScalarsOrEnumsFieldArgs, () => {
       `,
       targetField: "booleanField",
       expected: `
-        scalarFieldValueGenerator.Boolean({ modelName: "TestModel", fieldName: "booleanField", isId: false, isUnique: false, seq })
+        getScalarFieldValueGenerator().Boolean({ modelName: "TestModel", fieldName: "booleanField", isId: false, isUnique: false, seq })
       `,
     },
     {
@@ -76,7 +76,7 @@ describe(autoGenerateModelScalarsOrEnumsFieldArgs, () => {
       `,
       targetField: "stringField",
       expected: `
-        scalarFieldValueGenerator.String({ modelName: "TestModel", fieldName: "stringField", isId: false, isUnique: false, seq })
+        getScalarFieldValueGenerator().String({ modelName: "TestModel", fieldName: "stringField", isId: false, isUnique: false, seq })
       `,
     },
     {
@@ -88,7 +88,7 @@ describe(autoGenerateModelScalarsOrEnumsFieldArgs, () => {
       `,
       targetField: "intField",
       expected: `
-        scalarFieldValueGenerator.Int({ modelName: "TestModel", fieldName: "intField", isId: false, isUnique: false, seq })
+        getScalarFieldValueGenerator().Int({ modelName: "TestModel", fieldName: "intField", isId: false, isUnique: false, seq })
       `,
     },
     {
@@ -100,7 +100,7 @@ describe(autoGenerateModelScalarsOrEnumsFieldArgs, () => {
       `,
       targetField: "floatField",
       expected: `
-        scalarFieldValueGenerator.Float({ modelName: "TestModel", fieldName: "floatField", isId: false, isUnique: false, seq })
+        getScalarFieldValueGenerator().Float({ modelName: "TestModel", fieldName: "floatField", isId: false, isUnique: false, seq })
       `,
     },
     {
@@ -112,7 +112,7 @@ describe(autoGenerateModelScalarsOrEnumsFieldArgs, () => {
       `,
       targetField: "bigIntField",
       expected: `
-        scalarFieldValueGenerator.BigInt({ modelName: "TestModel", fieldName: "bigIntField", isId: false, isUnique: false, seq })
+        getScalarFieldValueGenerator().BigInt({ modelName: "TestModel", fieldName: "bigIntField", isId: false, isUnique: false, seq })
       `,
     },
     {
@@ -124,7 +124,7 @@ describe(autoGenerateModelScalarsOrEnumsFieldArgs, () => {
       `,
       targetField: "dateTimeField",
       expected: `
-        scalarFieldValueGenerator.DateTime({ modelName: "TestModel", fieldName: "dateTimeField", isId: false, isUnique: false, seq })
+        getScalarFieldValueGenerator().DateTime({ modelName: "TestModel", fieldName: "dateTimeField", isId: false, isUnique: false, seq })
       `,
     },
     {
@@ -136,7 +136,7 @@ describe(autoGenerateModelScalarsOrEnumsFieldArgs, () => {
       `,
       targetField: "bytesField",
       expected: `
-        scalarFieldValueGenerator.Bytes({ modelName: "TestModel", fieldName: "bytesField", isId: false, isUnique: false, seq })
+        getScalarFieldValueGenerator().Bytes({ modelName: "TestModel", fieldName: "bytesField", isId: false, isUnique: false, seq })
       `,
     },
     {
@@ -148,7 +148,7 @@ describe(autoGenerateModelScalarsOrEnumsFieldArgs, () => {
       `,
       targetField: "jsonField",
       expected: `
-        scalarFieldValueGenerator.Json({ modelName: "TestModel", fieldName: "jsonField", isId: false, isUnique: false, seq })
+        getScalarFieldValueGenerator().Json({ modelName: "TestModel", fieldName: "jsonField", isId: false, isUnique: false, seq })
       `,
     },
     {
diff --git a/packages/ts-compile-testing/fixtures/field-variation/__generated__/fabbrica/index.ts b/packages/ts-compile-testing/fixtures/field-variation/__generated__/fabbrica/index.ts
index 0760652..8dda5e3 100644
--- a/packages/ts-compile-testing/fixtures/field-variation/__generated__/fabbrica/index.ts
+++ b/packages/ts-compile-testing/fixtures/field-variation/__generated__/fabbrica/index.ts
@@ -5,8 +5,8 @@ import type { NoPkModel } from "./../client";
 import type { Role } from "./../client";
 import { Prisma } from "./../client";
 import type { PrismaClient } from "./../client";
-import { getClient, ModelWithFields, createScreener, scalarFieldValueGenerator, Resolver, normalizeResolver, normalizeList, getSequenceCounter, } from "@quramy/prisma-fabbrica/lib/internal";
-export { initialize, resetSequence } from "@quramy/prisma-fabbrica/lib/internal";
+import { getClient, ModelWithFields, createScreener, getScalarFieldValueGenerator, Resolver, normalizeResolver, normalizeList, getSequenceCounter, } from "@quramy/prisma-fabbrica/lib/internal";
+export { initialize, resetSequence, registerScalarFieldValueGenerator, resetScalarFieldValueGenerator } from "@quramy/prisma-fabbrica/lib/internal";
 
 type BuildDataOptions = {
     readonly seq: number;
@@ -57,7 +57,7 @@ function autoGenerateUserScalarsOrEnums({ seq }: {
     readonly seq: number;
 }): UserScalarOrEnumFields {
     return {
-        id: scalarFieldValueGenerator.String({ modelName: "User", fieldName: "id", isId: true, isUnique: false, seq }),
+        id: getScalarFieldValueGenerator().String({ modelName: "User", fieldName: "id", isId: true, isUnique: false, seq }),
         role: "USER"
     };
 }
@@ -136,8 +136,8 @@ function autoGenerateComplexIdModelScalarsOrEnums({ seq }: {
     readonly seq: number;
 }): ComplexIdModelScalarOrEnumFields {
     return {
-        firstName: scalarFieldValueGenerator.String({ modelName: "ComplexIdModel", fieldName: "firstName", isId: true, isUnique: false, seq }),
-        lastName: scalarFieldValueGenerator.String({ modelName: "ComplexIdModel", fieldName: "lastName", isId: true, isUnique: false, seq })
+        firstName: getScalarFieldValueGenerator().String({ modelName: "ComplexIdModel", fieldName: "firstName", isId: true, isUnique: false, seq }),
+        lastName: getScalarFieldValueGenerator().String({ modelName: "ComplexIdModel", fieldName: "lastName", isId: true, isUnique: false, seq })
     };
 }
 
@@ -240,15 +240,15 @@ function autoGenerateFieldTypePatternModelScalarsOrEnums({ seq }: {
     readonly seq: number;
 }): FieldTypePatternModelScalarOrEnumFields {
     return {
-        id: scalarFieldValueGenerator.Int({ modelName: "FieldTypePatternModel", fieldName: "id", isId: true, isUnique: false, seq }),
-        requiredInt: scalarFieldValueGenerator.Int({ modelName: "FieldTypePatternModel", fieldName: "requiredInt", isId: false, isUnique: false, seq }),
-        requiredStr: scalarFieldValueGenerator.String({ modelName: "FieldTypePatternModel", fieldName: "requiredStr", isId: false, isUnique: false, seq }),
-        requiredBool: scalarFieldValueGenerator.Boolean({ modelName: "FieldTypePatternModel", fieldName: "requiredBool", isId: false, isUnique: false, seq }),
-        requiredFlaot: scalarFieldValueGenerator.Float({ modelName: "FieldTypePatternModel", fieldName: "requiredFlaot", isId: false, isUnique: false, seq }),
-        requiredDecimal: scalarFieldValueGenerator.Decimal({ modelName: "FieldTypePatternModel", fieldName: "requiredDecimal", isId: false, isUnique: false, seq }),
-        requiredJson: scalarFieldValueGenerator.Json({ modelName: "FieldTypePatternModel", fieldName: "requiredJson", isId: false, isUnique: false, seq }),
-        requriedBytes: scalarFieldValueGenerator.Bytes({ modelName: "FieldTypePatternModel", fieldName: "requriedBytes", isId: false, isUnique: false, seq }),
-        requiredBigInt: scalarFieldValueGenerator.BigInt({ modelName: "FieldTypePatternModel", fieldName: "requiredBigInt", isId: false, isUnique: false, seq })
+        id: getScalarFieldValueGenerator().Int({ modelName: "FieldTypePatternModel", fieldName: "id", isId: true, isUnique: false, seq }),
+        requiredInt: getScalarFieldValueGenerator().Int({ modelName: "FieldTypePatternModel", fieldName: "requiredInt", isId: false, isUnique: false, seq }),
+        requiredStr: getScalarFieldValueGenerator().String({ modelName: "FieldTypePatternModel", fieldName: "requiredStr", isId: false, isUnique: false, seq }),
+        requiredBool: getScalarFieldValueGenerator().Boolean({ modelName: "FieldTypePatternModel", fieldName: "requiredBool", isId: false, isUnique: false, seq }),
+        requiredFlaot: getScalarFieldValueGenerator().Float({ modelName: "FieldTypePatternModel", fieldName: "requiredFlaot", isId: false, isUnique: false, seq }),
+        requiredDecimal: getScalarFieldValueGenerator().Decimal({ modelName: "FieldTypePatternModel", fieldName: "requiredDecimal", isId: false, isUnique: false, seq }),
+        requiredJson: getScalarFieldValueGenerator().Json({ modelName: "FieldTypePatternModel", fieldName: "requiredJson", isId: false, isUnique: false, seq }),
+        requriedBytes: getScalarFieldValueGenerator().Bytes({ modelName: "FieldTypePatternModel", fieldName: "requriedBytes", isId: false, isUnique: false, seq }),
+        requiredBigInt: getScalarFieldValueGenerator().BigInt({ modelName: "FieldTypePatternModel", fieldName: "requiredBigInt", isId: false, isUnique: false, seq })
     };
 }
 
@@ -324,7 +324,7 @@ function autoGenerateNoPkModelScalarsOrEnums({ seq }: {
     readonly seq: number;
 }): NoPkModelScalarOrEnumFields {
     return {
-        id: scalarFieldValueGenerator.Int({ modelName: "NoPkModel", fieldName: "id", isId: false, isUnique: true, seq })
+        id: getScalarFieldValueGenerator().Int({ modelName: "NoPkModel", fieldName: "id", isId: false, isUnique: true, seq })
     };
 }
 
diff --git a/packages/ts-compile-testing/fixtures/relations-many-to-many/__generated__/fabbrica/index.ts b/packages/ts-compile-testing/fixtures/relations-many-to-many/__generated__/fabbrica/index.ts
index a745bfe..7bff810 100644
--- a/packages/ts-compile-testing/fixtures/relations-many-to-many/__generated__/fabbrica/index.ts
+++ b/packages/ts-compile-testing/fixtures/relations-many-to-many/__generated__/fabbrica/index.ts
@@ -2,8 +2,8 @@ import type { Post } from "./../client";
 import type { Category } from "./../client";
 import { Prisma } from "./../client";
 import type { PrismaClient } from "./../client";
-import { getClient, ModelWithFields, createScreener, scalarFieldValueGenerator, Resolver, normalizeResolver, normalizeList, getSequenceCounter, } from "@quramy/prisma-fabbrica/lib/internal";
-export { initialize, resetSequence } from "@quramy/prisma-fabbrica/lib/internal";
+import { getClient, ModelWithFields, createScreener, getScalarFieldValueGenerator, Resolver, normalizeResolver, normalizeList, getSequenceCounter, } from "@quramy/prisma-fabbrica/lib/internal";
+export { initialize, resetSequence, registerScalarFieldValueGenerator, resetScalarFieldValueGenerator } from "@quramy/prisma-fabbrica/lib/internal";
 
 type BuildDataOptions = {
     readonly seq: number;
@@ -55,8 +55,8 @@ function autoGeneratePostScalarsOrEnums({ seq }: {
     readonly seq: number;
 }): PostScalarOrEnumFields {
     return {
-        id: scalarFieldValueGenerator.String({ modelName: "Post", fieldName: "id", isId: true, isUnique: false, seq }),
-        title: scalarFieldValueGenerator.String({ modelName: "Post", fieldName: "title", isId: false, isUnique: false, seq })
+        id: getScalarFieldValueGenerator().String({ modelName: "Post", fieldName: "id", isId: true, isUnique: false, seq }),
+        title: getScalarFieldValueGenerator().String({ modelName: "Post", fieldName: "title", isId: false, isUnique: false, seq })
     };
 }
 
@@ -135,8 +135,8 @@ function autoGenerateCategoryScalarsOrEnums({ seq }: {
     readonly seq: number;
 }): CategoryScalarOrEnumFields {
     return {
-        id: scalarFieldValueGenerator.String({ modelName: "Category", fieldName: "id", isId: true, isUnique: false, seq }),
-        name: scalarFieldValueGenerator.String({ modelName: "Category", fieldName: "name", isId: false, isUnique: false, seq })
+        id: getScalarFieldValueGenerator().String({ modelName: "Category", fieldName: "id", isId: true, isUnique: false, seq }),
+        name: getScalarFieldValueGenerator().String({ modelName: "Category", fieldName: "name", isId: false, isUnique: false, seq })
     };
 }
 
diff --git a/packages/ts-compile-testing/fixtures/relations-one-to-many/__generated__/fabbrica/index.ts b/packages/ts-compile-testing/fixtures/relations-one-to-many/__generated__/fabbrica/index.ts
index 20bfd2e..645785b 100644
--- a/packages/ts-compile-testing/fixtures/relations-one-to-many/__generated__/fabbrica/index.ts
+++ b/packages/ts-compile-testing/fixtures/relations-one-to-many/__generated__/fabbrica/index.ts
@@ -3,8 +3,8 @@ import type { Post } from "./../client";
 import type { Review } from "./../client";
 import { Prisma } from "./../client";
 import type { PrismaClient } from "./../client";
-import { getClient, ModelWithFields, createScreener, scalarFieldValueGenerator, Resolver, normalizeResolver, normalizeList, getSequenceCounter, } from "@quramy/prisma-fabbrica/lib/internal";
-export { initialize, resetSequence } from "@quramy/prisma-fabbrica/lib/internal";
+import { getClient, ModelWithFields, createScreener, getScalarFieldValueGenerator, Resolver, normalizeResolver, normalizeList, getSequenceCounter, } from "@quramy/prisma-fabbrica/lib/internal";
+export { initialize, resetSequence, registerScalarFieldValueGenerator, resetScalarFieldValueGenerator } from "@quramy/prisma-fabbrica/lib/internal";
 
 type BuildDataOptions = {
     readonly seq: number;
@@ -76,8 +76,8 @@ function autoGenerateUserScalarsOrEnums({ seq }: {
     readonly seq: number;
 }): UserScalarOrEnumFields {
     return {
-        id: scalarFieldValueGenerator.String({ modelName: "User", fieldName: "id", isId: true, isUnique: false, seq }),
-        name: scalarFieldValueGenerator.String({ modelName: "User", fieldName: "name", isId: false, isUnique: false, seq })
+        id: getScalarFieldValueGenerator().String({ modelName: "User", fieldName: "id", isId: true, isUnique: false, seq }),
+        name: getScalarFieldValueGenerator().String({ modelName: "User", fieldName: "name", isId: false, isUnique: false, seq })
     };
 }
 
@@ -166,8 +166,8 @@ function autoGeneratePostScalarsOrEnums({ seq }: {
     readonly seq: number;
 }): PostScalarOrEnumFields {
     return {
-        id: scalarFieldValueGenerator.String({ modelName: "Post", fieldName: "id", isId: true, isUnique: false, seq }),
-        title: scalarFieldValueGenerator.String({ modelName: "Post", fieldName: "title", isId: false, isUnique: false, seq })
+        id: getScalarFieldValueGenerator().String({ modelName: "Post", fieldName: "id", isId: true, isUnique: false, seq }),
+        title: getScalarFieldValueGenerator().String({ modelName: "Post", fieldName: "title", isId: false, isUnique: false, seq })
     };
 }
 
@@ -269,8 +269,8 @@ function autoGenerateReviewScalarsOrEnums({ seq }: {
     readonly seq: number;
 }): ReviewScalarOrEnumFields {
     return {
-        id: scalarFieldValueGenerator.String({ modelName: "Review", fieldName: "id", isId: true, isUnique: false, seq }),
-        body: scalarFieldValueGenerator.String({ modelName: "Review", fieldName: "body", isId: false, isUnique: false, seq })
+        id: getScalarFieldValueGenerator().String({ modelName: "Review", fieldName: "id", isId: true, isUnique: false, seq }),
+        body: getScalarFieldValueGenerator().String({ modelName: "Review", fieldName: "body", isId: false, isUnique: false, seq })
     };
 }
 
diff --git a/packages/ts-compile-testing/fixtures/relations-one-to-one/__generated__/fabbrica/index.ts b/packages/ts-compile-testing/fixtures/relations-one-to-one/__generated__/fabbrica/index.ts
index 55d8a4b..ade7e44 100644
--- a/packages/ts-compile-testing/fixtures/relations-one-to-one/__generated__/fabbrica/index.ts
+++ b/packages/ts-compile-testing/fixtures/relations-one-to-one/__generated__/fabbrica/index.ts
@@ -2,8 +2,8 @@ import type { User } from "./../client";
 import type { Profile } from "./../client";
 import { Prisma } from "./../client";
 import type { PrismaClient } from "./../client";
-import { getClient, ModelWithFields, createScreener, scalarFieldValueGenerator, Resolver, normalizeResolver, normalizeList, getSequenceCounter, } from "@quramy/prisma-fabbrica/lib/internal";
-export { initialize, resetSequence } from "@quramy/prisma-fabbrica/lib/internal";
+import { getClient, ModelWithFields, createScreener, getScalarFieldValueGenerator, Resolver, normalizeResolver, normalizeList, getSequenceCounter, } from "@quramy/prisma-fabbrica/lib/internal";
+export { initialize, resetSequence, registerScalarFieldValueGenerator, resetScalarFieldValueGenerator } from "@quramy/prisma-fabbrica/lib/internal";
 
 type BuildDataOptions = {
     readonly seq: number;
@@ -64,8 +64,8 @@ function autoGenerateUserScalarsOrEnums({ seq }: {
     readonly seq: number;
 }): UserScalarOrEnumFields {
     return {
-        id: scalarFieldValueGenerator.String({ modelName: "User", fieldName: "id", isId: true, isUnique: false, seq }),
-        name: scalarFieldValueGenerator.String({ modelName: "User", fieldName: "name", isId: false, isUnique: false, seq })
+        id: getScalarFieldValueGenerator().String({ modelName: "User", fieldName: "id", isId: true, isUnique: false, seq }),
+        name: getScalarFieldValueGenerator().String({ modelName: "User", fieldName: "name", isId: false, isUnique: false, seq })
     };
 }
 
@@ -155,7 +155,7 @@ function autoGenerateProfileScalarsOrEnums({ seq }: {
     readonly seq: number;
 }): ProfileScalarOrEnumFields {
     return {
-        id: scalarFieldValueGenerator.String({ modelName: "Profile", fieldName: "id", isId: true, isUnique: false, seq })
+        id: getScalarFieldValueGenerator().String({ modelName: "Profile", fieldName: "id", isId: true, isUnique: false, seq })
     };
 }
 
diff --git a/packages/ts-compile-testing/fixtures/simple-model/__generated__/fabbrica/index.ts b/packages/ts-compile-testing/fixtures/simple-model/__generated__/fabbrica/index.ts
index 6bb2ef1..7d0b3ca 100644
--- a/packages/ts-compile-testing/fixtures/simple-model/__generated__/fabbrica/index.ts
+++ b/packages/ts-compile-testing/fixtures/simple-model/__generated__/fabbrica/index.ts
@@ -1,8 +1,8 @@
 import type { User } from "./../client";
 import { Prisma } from "./../client";
 import type { PrismaClient } from "./../client";
-import { getClient, ModelWithFields, createScreener, scalarFieldValueGenerator, Resolver, normalizeResolver, normalizeList, getSequenceCounter, } from "@quramy/prisma-fabbrica/lib/internal";
-export { initialize, resetSequence } from "@quramy/prisma-fabbrica/lib/internal";
+import { getClient, ModelWithFields, createScreener, getScalarFieldValueGenerator, Resolver, normalizeResolver, normalizeList, getSequenceCounter, } from "@quramy/prisma-fabbrica/lib/internal";
+export { initialize, resetSequence, registerScalarFieldValueGenerator, resetScalarFieldValueGenerator } from "@quramy/prisma-fabbrica/lib/internal";
 
 type BuildDataOptions = {
     readonly seq: number;
@@ -42,8 +42,8 @@ function autoGenerateUserScalarsOrEnums({ seq }: {
     readonly seq: number;
 }): UserScalarOrEnumFields {
     return {
-        id: scalarFieldValueGenerator.String({ modelName: "User", fieldName: "id", isId: true, isUnique: false, seq }),
-        name: scalarFieldValueGenerator.String({ modelName: "User", fieldName: "name", isId: false, isUnique: false, seq })
+        id: getScalarFieldValueGenerator().String({ modelName: "User", fieldName: "id", isId: true, isUnique: false, seq }),
+        name: getScalarFieldValueGenerator().String({ modelName: "User", fieldName: "name", isId: false, isUnique: false, seq })
     };
 }