@prismicio/mock 0.3.5 → 0.3.6
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.
|
@@ -39,7 +39,9 @@ export declare class ModelMockFactory {
|
|
|
39
39
|
boolean(config?: WithoutFakerConfig<MockBooleanModelConfig>): prismic.CustomTypeModelBooleanField;
|
|
40
40
|
color(config?: WithoutFakerConfig<MockColorModelConfig>): prismic.CustomTypeModelColorField;
|
|
41
41
|
contentRelationship<CustomTypeIDs extends string, Tags extends string>(config?: WithoutFakerConfig<MockContentRelationshipModelConfig<CustomTypeIDs, Tags>>): prismic.CustomTypeModelContentRelationshipField<CustomTypeIDs, Tags>;
|
|
42
|
-
customType<Definition extends prismic.CustomTypeModelTab | prismic.CustomTypeModelDefinition>(config?: WithoutFakerConfig<MockCustomTypeModelConfig<Definition>>): Definition extends Record<string, prismic.CustomTypeModelField> ? prismic.CustomTypeModel<string, Record<"Main", Definition>> : Definition extends prismic.CustomTypeModelDefinition ? prismic.CustomTypeModel<string, Definition> : never
|
|
42
|
+
customType<Definition extends prismic.CustomTypeModelTab | prismic.CustomTypeModelDefinition>(config?: WithoutFakerConfig<MockCustomTypeModelConfig<Definition>>): (Definition extends Record<string, prismic.CustomTypeModelField> ? prismic.CustomTypeModel<string, Record<"Main", Definition>> : Definition extends prismic.CustomTypeModelDefinition ? prismic.CustomTypeModel<string, Definition> : never) & {
|
|
43
|
+
label: string;
|
|
44
|
+
};
|
|
43
45
|
date(config?: WithoutFakerConfig<MockDateModelConfig>): prismic.CustomTypeModelDateField;
|
|
44
46
|
embed(config?: WithoutFakerConfig<MockEmbedModelConfig>): prismic.CustomTypeModelEmbedField;
|
|
45
47
|
geoPoint(config?: WithoutFakerConfig<MockGeoPointModelConfig>): prismic.CustomTypeModelGeoPointField;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customType.cjs","sources":["../../../src/model/customType.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockModelConfig } from \"../types\";\n\nexport type MockCustomTypeModelConfig<\n\tDefinition extends\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition =\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition,\n> = {\n\tid?: string;\n\tlabel?: string;\n\tstatus?: boolean;\n\trepeatable?: boolean;\n\tformat?: prismic.CustomTypeModel[\"format\"];\n} & (\n\t| {\n\t\t\tfields?: Definition;\n\t\t\ttabs?: never;\n\t }\n\t| {\n\t\t\ttabs?: Definition;\n\t\t\tfields?: never;\n\t }\n) &\n\tMockModelConfig;\n\ntype MockCustomTypeModel<\n\tDefinition extends\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition,\n> = Definition extends prismic.CustomTypeModelTab\n\t? prismic.CustomTypeModel<string, Record<\"Main\", Definition>>\n\t: Definition extends prismic.CustomTypeModelDefinition\n\t\t? prismic.CustomTypeModel<string, Definition>\n\t\t: never;\n\nexport const customType = <\n\tDefinition extends\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition,\n>(\n\tconfig: MockCustomTypeModelConfig<Definition>,\n): MockCustomTypeModel<Definition> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\tlet label: string =\n\t\tconfig.label || changeCase.capitalCase(faker.words(faker.range(1, 2)));\n\tlet id: string = config.id || changeCase.snakeCase(label);\n\n\tif (config.id && !config.label) {\n\t\tlabel = changeCase.capitalCase(config.id);\n\t} else if (config.label && !config.label) {\n\t\tid = changeCase.snakeCase(config.label);\n\t}\n\n\tconst format = config.format ?? faker.randomElement([\"page\", \"custom\"]);\n\n\tlet json = {} as
|
|
1
|
+
{"version":3,"file":"customType.cjs","sources":["../../../src/model/customType.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockModelConfig } from \"../types\";\n\nexport type MockCustomTypeModelConfig<\n\tDefinition extends\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition =\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition,\n> = {\n\tid?: string;\n\tlabel?: string;\n\tstatus?: boolean;\n\trepeatable?: boolean;\n\tformat?: prismic.CustomTypeModel[\"format\"];\n} & (\n\t| {\n\t\t\tfields?: Definition;\n\t\t\ttabs?: never;\n\t }\n\t| {\n\t\t\ttabs?: Definition;\n\t\t\tfields?: never;\n\t }\n) &\n\tMockModelConfig;\n\ntype MockCustomTypeModel<\n\tDefinition extends\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition,\n> = (Definition extends prismic.CustomTypeModelTab\n\t? prismic.CustomTypeModel<string, Record<\"Main\", Definition>>\n\t: Definition extends prismic.CustomTypeModelDefinition\n\t\t? prismic.CustomTypeModel<string, Definition>\n\t\t: never) & {\n\tlabel: NonNullable<prismic.CustomTypeModel[\"label\"]>;\n};\n\nexport const customType = <\n\tDefinition extends\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition,\n>(\n\tconfig: MockCustomTypeModelConfig<Definition>,\n): MockCustomTypeModel<Definition> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\tlet label: string =\n\t\tconfig.label || changeCase.capitalCase(faker.words(faker.range(1, 2)));\n\tlet id: string = config.id || changeCase.snakeCase(label);\n\n\tif (config.id && !config.label) {\n\t\tlabel = changeCase.capitalCase(config.id);\n\t} else if (config.label && !config.label) {\n\t\tid = changeCase.snakeCase(config.label);\n\t}\n\n\tconst format = config.format ?? faker.randomElement([\"page\", \"custom\"]);\n\n\tlet json = {} as prismic.CustomTypeModelDefinition;\n\n\tif (\"fields\" in config && config.fields) {\n\t\tjson = { Main: config.fields } as typeof json;\n\t} else if (\"tabs\" in config && config.tabs) {\n\t\tjson = config.tabs as typeof json;\n\t}\n\n\treturn {\n\t\tid,\n\t\tlabel,\n\t\tstatus: config.status ?? faker.boolean(),\n\t\trepeatable: config.repeatable ?? faker.boolean(),\n\t\tformat,\n\t\tjson,\n\t} as MockCustomTypeModel<Definition>;\n};\n"],"names":["createFaker","changeCase.capitalCase","changeCase.snakeCase"],"mappings":";;;;AA2Ca,MAAA,aAAa,CAKzB,WACoC;AACpC,QAAM,QAAQ,OAAO,SAASA,YAAAA,YAAY,OAAO,IAAI;AAErD,MAAI,QACH,OAAO,SAASC,MAAuB,YAAA,MAAM,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC;AACtE,MAAI,KAAa,OAAO,MAAMC,gBAAqB,KAAK;AAExD,MAAI,OAAO,MAAM,CAAC,OAAO,OAAO;AACvB,YAAAD,MAAuB,YAAA,OAAO,EAAE;AAAA,EAC9B,WAAA,OAAO,SAAS,CAAC,OAAO,OAAO;AACpC,SAAAC,MAAqB,UAAA,OAAO,KAAK;AAAA,EACvC;AAEM,QAAA,SAAS,OAAO,UAAU,MAAM,cAAc,CAAC,QAAQ,QAAQ,CAAC;AAEtE,MAAI,OAAO,CAAA;AAEP,MAAA,YAAY,UAAU,OAAO,QAAQ;AACjC,WAAA,EAAE,MAAM,OAAO;EACZ,WAAA,UAAU,UAAU,OAAO,MAAM;AAC3C,WAAO,OAAO;AAAA,EACf;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,IACA,QAAQ,OAAO,UAAU,MAAM,QAAS;AAAA,IACxC,YAAY,OAAO,cAAc,MAAM,QAAS;AAAA,IAChD;AAAA,IACA;AAAA,EAAA;AAEF;;"}
|
|
@@ -13,6 +13,8 @@ export type MockCustomTypeModelConfig<Definition extends prismic.CustomTypeModel
|
|
|
13
13
|
tabs?: Definition;
|
|
14
14
|
fields?: never;
|
|
15
15
|
}) & MockModelConfig;
|
|
16
|
-
type MockCustomTypeModel<Definition extends prismic.CustomTypeModelTab | prismic.CustomTypeModelDefinition> = Definition extends prismic.CustomTypeModelTab ? prismic.CustomTypeModel<string, Record<"Main", Definition>> : Definition extends prismic.CustomTypeModelDefinition ? prismic.CustomTypeModel<string, Definition> : never
|
|
16
|
+
type MockCustomTypeModel<Definition extends prismic.CustomTypeModelTab | prismic.CustomTypeModelDefinition> = (Definition extends prismic.CustomTypeModelTab ? prismic.CustomTypeModel<string, Record<"Main", Definition>> : Definition extends prismic.CustomTypeModelDefinition ? prismic.CustomTypeModel<string, Definition> : never) & {
|
|
17
|
+
label: NonNullable<prismic.CustomTypeModel["label"]>;
|
|
18
|
+
};
|
|
17
19
|
export declare const customType: <Definition extends Record<string, prismic.CustomTypeModelField> | prismic.CustomTypeModelDefinition>(config: MockCustomTypeModelConfig<Definition>) => MockCustomTypeModel<Definition>;
|
|
18
20
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customType.js","sources":["../../../src/model/customType.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockModelConfig } from \"../types\";\n\nexport type MockCustomTypeModelConfig<\n\tDefinition extends\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition =\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition,\n> = {\n\tid?: string;\n\tlabel?: string;\n\tstatus?: boolean;\n\trepeatable?: boolean;\n\tformat?: prismic.CustomTypeModel[\"format\"];\n} & (\n\t| {\n\t\t\tfields?: Definition;\n\t\t\ttabs?: never;\n\t }\n\t| {\n\t\t\ttabs?: Definition;\n\t\t\tfields?: never;\n\t }\n) &\n\tMockModelConfig;\n\ntype MockCustomTypeModel<\n\tDefinition extends\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition,\n> = Definition extends prismic.CustomTypeModelTab\n\t? prismic.CustomTypeModel<string, Record<\"Main\", Definition>>\n\t: Definition extends prismic.CustomTypeModelDefinition\n\t\t? prismic.CustomTypeModel<string, Definition>\n\t\t: never;\n\nexport const customType = <\n\tDefinition extends\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition,\n>(\n\tconfig: MockCustomTypeModelConfig<Definition>,\n): MockCustomTypeModel<Definition> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\tlet label: string =\n\t\tconfig.label || changeCase.capitalCase(faker.words(faker.range(1, 2)));\n\tlet id: string = config.id || changeCase.snakeCase(label);\n\n\tif (config.id && !config.label) {\n\t\tlabel = changeCase.capitalCase(config.id);\n\t} else if (config.label && !config.label) {\n\t\tid = changeCase.snakeCase(config.label);\n\t}\n\n\tconst format = config.format ?? faker.randomElement([\"page\", \"custom\"]);\n\n\tlet json = {} as
|
|
1
|
+
{"version":3,"file":"customType.js","sources":["../../../src/model/customType.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\nimport * as changeCase from \"change-case\";\n\nimport { createFaker } from \"../lib/createFaker\";\n\nimport { MockModelConfig } from \"../types\";\n\nexport type MockCustomTypeModelConfig<\n\tDefinition extends\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition =\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition,\n> = {\n\tid?: string;\n\tlabel?: string;\n\tstatus?: boolean;\n\trepeatable?: boolean;\n\tformat?: prismic.CustomTypeModel[\"format\"];\n} & (\n\t| {\n\t\t\tfields?: Definition;\n\t\t\ttabs?: never;\n\t }\n\t| {\n\t\t\ttabs?: Definition;\n\t\t\tfields?: never;\n\t }\n) &\n\tMockModelConfig;\n\ntype MockCustomTypeModel<\n\tDefinition extends\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition,\n> = (Definition extends prismic.CustomTypeModelTab\n\t? prismic.CustomTypeModel<string, Record<\"Main\", Definition>>\n\t: Definition extends prismic.CustomTypeModelDefinition\n\t\t? prismic.CustomTypeModel<string, Definition>\n\t\t: never) & {\n\tlabel: NonNullable<prismic.CustomTypeModel[\"label\"]>;\n};\n\nexport const customType = <\n\tDefinition extends\n\t\t| prismic.CustomTypeModelTab\n\t\t| prismic.CustomTypeModelDefinition,\n>(\n\tconfig: MockCustomTypeModelConfig<Definition>,\n): MockCustomTypeModel<Definition> => {\n\tconst faker = config.faker || createFaker(config.seed);\n\n\tlet label: string =\n\t\tconfig.label || changeCase.capitalCase(faker.words(faker.range(1, 2)));\n\tlet id: string = config.id || changeCase.snakeCase(label);\n\n\tif (config.id && !config.label) {\n\t\tlabel = changeCase.capitalCase(config.id);\n\t} else if (config.label && !config.label) {\n\t\tid = changeCase.snakeCase(config.label);\n\t}\n\n\tconst format = config.format ?? faker.randomElement([\"page\", \"custom\"]);\n\n\tlet json = {} as prismic.CustomTypeModelDefinition;\n\n\tif (\"fields\" in config && config.fields) {\n\t\tjson = { Main: config.fields } as typeof json;\n\t} else if (\"tabs\" in config && config.tabs) {\n\t\tjson = config.tabs as typeof json;\n\t}\n\n\treturn {\n\t\tid,\n\t\tlabel,\n\t\tstatus: config.status ?? faker.boolean(),\n\t\trepeatable: config.repeatable ?? faker.boolean(),\n\t\tformat,\n\t\tjson,\n\t} as MockCustomTypeModel<Definition>;\n};\n"],"names":["changeCase.capitalCase","changeCase.snakeCase"],"mappings":";;AA2Ca,MAAA,aAAa,CAKzB,WACoC;AACpC,QAAM,QAAQ,OAAO,SAAS,YAAY,OAAO,IAAI;AAErD,MAAI,QACH,OAAO,SAASA,YAAuB,MAAM,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC;AACtE,MAAI,KAAa,OAAO,MAAMC,UAAqB,KAAK;AAExD,MAAI,OAAO,MAAM,CAAC,OAAO,OAAO;AACvB,YAAAD,YAAuB,OAAO,EAAE;AAAA,EAC9B,WAAA,OAAO,SAAS,CAAC,OAAO,OAAO;AACpC,SAAAC,UAAqB,OAAO,KAAK;AAAA,EACvC;AAEM,QAAA,SAAS,OAAO,UAAU,MAAM,cAAc,CAAC,QAAQ,QAAQ,CAAC;AAEtE,MAAI,OAAO,CAAA;AAEP,MAAA,YAAY,UAAU,OAAO,QAAQ;AACjC,WAAA,EAAE,MAAM,OAAO;EACZ,WAAA,UAAU,UAAU,OAAO,MAAM;AAC3C,WAAO,OAAO;AAAA,EACf;AAEO,SAAA;AAAA,IACN;AAAA,IACA;AAAA,IACA,QAAQ,OAAO,UAAU,MAAM,QAAS;AAAA,IACxC,YAAY,OAAO,cAAc,MAAM,QAAS;AAAA,IAChD;AAAA,IACA;AAAA,EAAA;AAEF;"}
|
package/package.json
CHANGED
package/src/model/customType.ts
CHANGED
|
@@ -33,11 +33,13 @@ type MockCustomTypeModel<
|
|
|
33
33
|
Definition extends
|
|
34
34
|
| prismic.CustomTypeModelTab
|
|
35
35
|
| prismic.CustomTypeModelDefinition,
|
|
36
|
-
> = Definition extends prismic.CustomTypeModelTab
|
|
36
|
+
> = (Definition extends prismic.CustomTypeModelTab
|
|
37
37
|
? prismic.CustomTypeModel<string, Record<"Main", Definition>>
|
|
38
38
|
: Definition extends prismic.CustomTypeModelDefinition
|
|
39
39
|
? prismic.CustomTypeModel<string, Definition>
|
|
40
|
-
: never
|
|
40
|
+
: never) & {
|
|
41
|
+
label: NonNullable<prismic.CustomTypeModel["label"]>;
|
|
42
|
+
};
|
|
41
43
|
|
|
42
44
|
export const customType = <
|
|
43
45
|
Definition extends
|
|
@@ -60,7 +62,7 @@ export const customType = <
|
|
|
60
62
|
|
|
61
63
|
const format = config.format ?? faker.randomElement(["page", "custom"]);
|
|
62
64
|
|
|
63
|
-
let json = {} as
|
|
65
|
+
let json = {} as prismic.CustomTypeModelDefinition;
|
|
64
66
|
|
|
65
67
|
if ("fields" in config && config.fields) {
|
|
66
68
|
json = { Main: config.fields } as typeof json;
|