UNPKG

@prismicio/mock

Version:

Generate mock Prismic documents, fields, Slices, and models for development and testing environments

1 lines 13.3 kB
{"version":3,"file":"createValueMockFactory.cjs","names":["createFaker","boolean","color","contentRelationship","customType","date","document","embed","geoPoint","group","image","integration","keyText","link","linkToMedia","number","richText","select","sharedSlice","sharedSliceVariation","slice","sliceZone","table","timestamp","title","uid"],"sources":["../../src/value/createValueMockFactory.ts"],"sourcesContent":["import type * as prismic from \"@prismicio/client\"\n\nimport { createFaker, type Faker } from \"../lib/createFaker\"\nimport type { ModelValue, Seed, WithoutFakerConfig } from \"../types\"\nimport { boolean, type MockBooleanValueConfig } from \"./boolean\"\nimport { color, type MockColorValue, type MockColorValueConfig } from \"./color\"\nimport {\n\tcontentRelationship,\n\ttype MockContentRelationshipValue,\n\ttype MockContentRelationshipValueConfig,\n} from \"./contentRelationship\"\nimport { customType, type MockCustomTypeValueConfig } from \"./customType\"\nimport { date, type MockDateValue, type MockDateValueConfig } from \"./date\"\nimport { document, type MockDocumentValueConfig } from \"./document\"\nimport { embed, type MockEmbedValue, type MockEmbedValueConfig } from \"./embed\"\nimport { geoPoint, type MockGeoPointValue, type MockGeoPointValueConfig } from \"./geoPoint\"\nimport { group, type MockGroupValueConfig } from \"./group\"\nimport { image, type MockImageValue, type MockImageValueConfig } from \"./image\"\nimport {\n\tintegration,\n\ttype MockIntegrationFieldValue,\n\ttype MockIntegrationFieldValueConfig,\n} from \"./integration\"\nimport { keyText, type MockKeyTextValue, type MockKeyTextValueConfig } from \"./keyText\"\nimport { link, type MockLinkValue, type MockLinkValueConfig } from \"./link\"\nimport {\n\tlinkToMedia,\n\ttype MockLinkToMediaValue,\n\ttype MockLinkToMediaValueConfig,\n} from \"./linkToMedia\"\nimport { number, type MockNumberValue, type MockNumberValueConfig } from \"./number\"\nimport { richText, type MockRichTextValue, type MockRichTextValueConfig } from \"./richText\"\nimport { select, type MockSelectValue, type MockSelectValueConfig } from \"./select\"\nimport { sharedSlice, type MockSharedSliceValueConfig } from \"./sharedSlice\"\nimport {\n\tsharedSliceVariation,\n\ttype MockSharedSliceVariationValueConfig,\n} from \"./sharedSliceVariation\"\nimport { slice, type MockSliceValueConfig } from \"./slice\"\nimport { sliceZone, type MockSliceZoneValueConfig } from \"./sliceZone\"\nimport { table, type MockTableValue, type MockTableValueConfig } from \"./table\"\nimport { timestamp, type MockTimestampValue, type MockTimestampValueConfig } from \"./timestamp\"\nimport { title, type MockTitleValue, type MockTitleValueConfig } from \"./title\"\nimport { uid, type MockUIDValueConfig } from \"./uid\"\n\nexport const createValueMockFactory = (\n\t...args: ConstructorParameters<typeof ValueMockFactory>\n): ValueMockFactory => {\n\treturn new ValueMockFactory(...args)\n}\n\ntype ValueMockFactoryConfig =\n\t| {\n\t\t\tseed: Seed\n\t }\n\t| {\n\t\t\tfaker: Faker\n\t }\n\nexport class ValueMockFactory {\n\tprivate faker: Faker\n\n\tconstructor(config: ValueMockFactoryConfig) {\n\t\tthis.faker = \"faker\" in config ? config.faker : createFaker(config.seed)\n\t}\n\n\tget seed(): Seed {\n\t\treturn this.faker.seed\n\t}\n\n\tboolean<Model extends prismic.CustomTypeModelBooleanField>(\n\t\tconfig?: WithoutFakerConfig<MockBooleanValueConfig<Model>>,\n\t): prismic.BooleanField {\n\t\treturn boolean({ ...config, faker: this.faker })\n\t}\n\n\tcolor<\n\t\tModel extends prismic.CustomTypeModelColorField = prismic.CustomTypeModelColorField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(config?: WithoutFakerConfig<MockColorValueConfig<Model, State>>): MockColorValue<State> {\n\t\treturn color({ ...config, faker: this.faker })\n\t}\n\n\tcontentRelationship<\n\t\tModel extends prismic.CustomTypeModelContentRelationshipField =\n\t\t\tprismic.CustomTypeModelContentRelationshipField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(\n\t\tconfig?: WithoutFakerConfig<MockContentRelationshipValueConfig<Model, State>>,\n\t): MockContentRelationshipValue<Model, State> {\n\t\treturn contentRelationship({ ...config, faker: this.faker })\n\t}\n\n\tcustomType<Model extends prismic.CustomTypeModel = prismic.CustomTypeModel>(\n\t\tconfig?: WithoutFakerConfig<MockCustomTypeValueConfig<Model>>,\n\t): ModelValue<Model> {\n\t\treturn customType({ ...config, faker: this.faker })\n\t}\n\n\tdate<\n\t\tModel extends prismic.CustomTypeModelDateField = prismic.CustomTypeModelDateField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(config?: WithoutFakerConfig<MockDateValueConfig<Model, State>>): MockDateValue<State> {\n\t\treturn date({ ...config, faker: this.faker })\n\t}\n\n\tdocument<Model extends prismic.CustomTypeModel = prismic.CustomTypeModel>(\n\t\tconfig?: WithoutFakerConfig<MockDocumentValueConfig<Model>>,\n\t): ModelValue<Model> {\n\t\treturn document({ ...config, faker: this.faker })\n\t}\n\n\tembed<\n\t\tModel extends prismic.CustomTypeModelEmbedField = prismic.CustomTypeModelEmbedField,\n\t\tData extends prismic.AnyOEmbed = prismic.AnyOEmbed,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(\n\t\tconfig?: WithoutFakerConfig<MockEmbedValueConfig<Model, Data, State>>,\n\t): MockEmbedValue<Data, State> {\n\t\treturn embed({ ...config, faker: this.faker })\n\t}\n\n\tgeoPoint<\n\t\tModel extends prismic.CustomTypeModelGeoPointField = prismic.CustomTypeModelGeoPointField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(config?: WithoutFakerConfig<MockGeoPointValueConfig<Model, State>>): MockGeoPointValue<State> {\n\t\treturn geoPoint({ ...config, faker: this.faker })\n\t}\n\n\tgroup<\n\t\tModel extends prismic.CustomTypeModelGroupField = prismic.CustomTypeModelGroupField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(config?: WithoutFakerConfig<MockGroupValueConfig<Model, State>>): ModelValue<Model, State> {\n\t\treturn group({ ...config, faker: this.faker })\n\t}\n\n\timage<\n\t\tModel extends prismic.CustomTypeModelImageField = prismic.CustomTypeModelImageField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(config?: WithoutFakerConfig<MockImageValueConfig<Model, State>>): MockImageValue<Model, State> {\n\t\treturn image({ ...config, faker: this.faker })\n\t}\n\n\tintegration<\n\t\tModel extends prismic.CustomTypeModelIntegrationField = prismic.CustomTypeModelIntegrationField,\n\t\tData extends Record<string, unknown> = Record<string, unknown>,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(\n\t\tconfig?: WithoutFakerConfig<MockIntegrationFieldValueConfig<Model, Data, State>>,\n\t): MockIntegrationFieldValue<Data, State> {\n\t\treturn integration({ ...config, faker: this.faker })\n\t}\n\n\tkeyText<\n\t\tModel extends prismic.CustomTypeModelKeyTextField = prismic.CustomTypeModelKeyTextField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(config?: WithoutFakerConfig<MockKeyTextValueConfig<Model, State>>): MockKeyTextValue<State> {\n\t\treturn keyText({ ...config, faker: this.faker })\n\t}\n\n\tlink<\n\t\tLinkType extends (typeof prismic.LinkType)[keyof typeof prismic.LinkType] =\n\t\t\t(typeof prismic.LinkType)[keyof typeof prismic.LinkType],\n\t\tModel extends prismic.CustomTypeModelLinkField = prismic.CustomTypeModelLinkField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(\n\t\tconfig?: WithoutFakerConfig<MockLinkValueConfig<LinkType, Model, State>>,\n\t): MockLinkValue<LinkType, State> {\n\t\treturn link({ ...config, faker: this.faker })\n\t}\n\n\tlinkToMedia<\n\t\tModel extends prismic.CustomTypeModelLinkToMediaField = prismic.CustomTypeModelLinkToMediaField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(\n\t\tconfig?: WithoutFakerConfig<MockLinkToMediaValueConfig<Model, State>>,\n\t): MockLinkToMediaValue<State> {\n\t\treturn linkToMedia({ ...config, faker: this.faker })\n\t}\n\n\tnumber<\n\t\tModel extends prismic.CustomTypeModelNumberField = prismic.CustomTypeModelNumberField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(config?: WithoutFakerConfig<MockNumberValueConfig<Model, State>>): MockNumberValue<State> {\n\t\treturn number({ ...config, faker: this.faker })\n\t}\n\n\trichText<\n\t\tModel extends prismic.CustomTypeModelRichTextField = prismic.CustomTypeModelRichTextField,\n\t>(config?: WithoutFakerConfig<MockRichTextValueConfig<Model>>): MockRichTextValue {\n\t\treturn richText({ ...config, faker: this.faker })\n\t}\n\n\tselect<\n\t\tModel extends prismic.CustomTypeModelSelectField = prismic.CustomTypeModelSelectField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(\n\t\tconfig?: WithoutFakerConfig<MockSelectValueConfig<Model, State>>,\n\t): MockSelectValue<Model, State> {\n\t\treturn select({ ...config, faker: this.faker })\n\t}\n\n\tsharedSlice<Model extends prismic.SharedSliceModel = prismic.SharedSliceModel>(\n\t\tconfig?: WithoutFakerConfig<MockSharedSliceValueConfig<Model>>,\n\t): ModelValue<Model> {\n\t\treturn sharedSlice({ ...config, faker: this.faker })\n\t}\n\n\tsharedSliceVariation<\n\t\tModel extends prismic.SharedSliceModelVariation = prismic.SharedSliceModelVariation,\n\t>(config?: WithoutFakerConfig<MockSharedSliceVariationValueConfig<Model>>): ModelValue<Model> {\n\t\treturn sharedSliceVariation({ ...config, faker: this.faker })\n\t}\n\n\tslice<Model extends prismic.CustomTypeModelSlice = prismic.CustomTypeModelSlice>(\n\t\tconfig?: WithoutFakerConfig<MockSliceValueConfig<Model>>,\n\t): ModelValue<Model> {\n\t\treturn slice({ ...config, faker: this.faker })\n\t}\n\n\tsliceZone<\n\t\tModel extends prismic.CustomTypeModelSliceZoneField = prismic.CustomTypeModelSliceZoneField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(config?: WithoutFakerConfig<MockSliceZoneValueConfig<Model, State>>): ModelValue<Model, State> {\n\t\treturn sliceZone({ ...config, faker: this.faker })\n\t}\n\n\ttable<Model extends prismic.CustomTypeModelTableField = prismic.CustomTypeModelTableField>(\n\t\tconfig?: WithoutFakerConfig<MockTableValueConfig<Model>>,\n\t): MockTableValue {\n\t\treturn table({ ...config, faker: this.faker })\n\t}\n\n\ttimestamp<\n\t\tModel extends prismic.CustomTypeModelTimestampField = prismic.CustomTypeModelTimestampField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(\n\t\tconfig?: WithoutFakerConfig<MockTimestampValueConfig<Model, State>>,\n\t): MockTimestampValue<State> {\n\t\treturn timestamp({ ...config, faker: this.faker })\n\t}\n\n\ttitle<\n\t\tModel extends prismic.CustomTypeModelTitleField = prismic.CustomTypeModelTitleField,\n\t\tState extends prismic.FieldState = \"filled\",\n\t>(config?: WithoutFakerConfig<MockTitleValueConfig<Model, State>>): MockTitleValue<State> {\n\t\treturn title({ ...config, faker: this.faker })\n\t}\n\n\tuid<Model extends prismic.CustomTypeModelUIDField = prismic.CustomTypeModelUIDField>(\n\t\tconfig?: WithoutFakerConfig<MockUIDValueConfig<Model>>,\n\t): NonNullable<prismic.PrismicDocument[\"uid\"]> {\n\t\treturn uid({ ...config, faker: this.faker })\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAa,0BACZ,GAAG,SACmB;AACtB,QAAO,IAAI,iBAAiB,GAAG,KAAK;;AAWrC,IAAa,mBAAb,MAA8B;CAC7B;CAEA,YAAY,QAAgC;AAC3C,OAAK,QAAQ,WAAW,SAAS,OAAO,QAAQA,oBAAAA,YAAY,OAAO,KAAK;;CAGzE,IAAI,OAAa;AAChB,SAAO,KAAK,MAAM;;CAGnB,QACC,QACuB;AACvB,SAAOC,gBAAAA,QAAQ;GAAE,GAAG;GAAQ,OAAO,KAAK;GAAO,CAAC;;CAGjD,MAGE,QAAwF;AACzF,SAAOC,cAAAA,MAAM;GAAE,GAAG;GAAQ,OAAO,KAAK;GAAO,CAAC;;CAG/C,oBAKC,QAC6C;AAC7C,SAAOC,4BAAAA,oBAAoB;GAAE,GAAG;GAAQ,OAAO,KAAK;GAAO,CAAC;;CAG7D,WACC,QACoB;AACpB,SAAOC,mBAAAA,WAAW;GAAE,GAAG;GAAQ,OAA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