@prismicio/mock 0.0.8 → 0.1.0

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.
Files changed (97) hide show
  1. package/dist/api/index.cjs +348 -236
  2. package/dist/api/index.cjs.map +1 -1
  3. package/dist/api/index.d.ts +52 -6
  4. package/dist/api/index.js +348 -236
  5. package/dist/api/index.js.map +1 -1
  6. package/dist/index.cjs +893 -543
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +247 -73
  9. package/dist/index.js +885 -542
  10. package/dist/index.js.map +1 -1
  11. package/dist/model/index.cjs +398 -134
  12. package/dist/model/index.cjs.map +1 -1
  13. package/dist/model/index.d.ts +114 -28
  14. package/dist/model/index.js +398 -134
  15. package/dist/model/index.js.map +1 -1
  16. package/dist/value/index.cjs +598 -468
  17. package/dist/value/index.cjs.map +1 -1
  18. package/dist/value/index.d.ts +96 -40
  19. package/dist/value/index.js +598 -468
  20. package/dist/value/index.js.map +1 -1
  21. package/package.json +22 -20
  22. package/src/api/createAPIMockFactory.ts +56 -0
  23. package/src/api/query.ts +4 -4
  24. package/src/api/ref.ts +6 -6
  25. package/src/api/repository.ts +12 -14
  26. package/src/api/tags.ts +5 -2
  27. package/src/createMockFactory.ts +52 -0
  28. package/src/index.ts +15 -0
  29. package/src/lib/buildEmbedField.ts +28 -30
  30. package/src/lib/buildImageFieldImage.ts +19 -7
  31. package/src/lib/createFaker.ts +99 -22
  32. package/src/lib/generateCustomTypeId.ts +13 -5
  33. package/src/lib/generateFieldId.ts +13 -7
  34. package/src/lib/generateTags.ts +17 -16
  35. package/src/lib/getMockEmbedData.ts +45 -16
  36. package/src/lib/getMockImageData.ts +13 -5
  37. package/src/lib/lorem.ts +112 -0
  38. package/src/lib/valueForModel.ts +47 -30
  39. package/src/lib/valueForModelMap.ts +24 -4
  40. package/src/model/boolean.ts +6 -6
  41. package/src/model/buildMockGroupFieldMap.ts +5 -5
  42. package/src/model/color.ts +4 -4
  43. package/src/model/contentRelationship.ts +4 -4
  44. package/src/model/createModelMockFactory.ts +213 -0
  45. package/src/model/customType.ts +6 -6
  46. package/src/model/date.ts +4 -4
  47. package/src/model/embed.ts +4 -4
  48. package/src/model/geoPoint.ts +3 -3
  49. package/src/model/group.ts +7 -7
  50. package/src/model/image.ts +8 -12
  51. package/src/model/index.ts +2 -0
  52. package/src/model/integrationFields.ts +4 -4
  53. package/src/model/keyText.ts +4 -4
  54. package/src/model/link.ts +6 -6
  55. package/src/model/linkToMedia.ts +5 -5
  56. package/src/model/number.ts +4 -4
  57. package/src/model/richText.ts +8 -8
  58. package/src/model/select.ts +5 -5
  59. package/src/model/sharedSlice.ts +5 -5
  60. package/src/model/sharedSliceVariation.ts +10 -10
  61. package/src/model/slice.ts +7 -7
  62. package/src/model/sliceZone.ts +7 -4
  63. package/src/model/timestamp.ts +4 -4
  64. package/src/model/title.ts +7 -7
  65. package/src/model/uid.ts +4 -4
  66. package/src/types.ts +70 -31
  67. package/src/value/boolean.ts +4 -6
  68. package/src/value/color.ts +3 -3
  69. package/src/value/contentRelationship.ts +21 -18
  70. package/src/value/createValueMockFactory.ts +236 -0
  71. package/src/value/customType.ts +12 -12
  72. package/src/value/date.ts +6 -2
  73. package/src/value/embed.ts +23 -7
  74. package/src/value/geoPoint.ts +4 -6
  75. package/src/value/group.ts +6 -11
  76. package/src/value/image.ts +26 -18
  77. package/src/value/integrationFields.ts +12 -26
  78. package/src/value/keyText.ts +3 -5
  79. package/src/value/link.ts +11 -9
  80. package/src/value/linkToMedia.ts +9 -8
  81. package/src/value/number.ts +3 -3
  82. package/src/value/richText/embed.ts +6 -3
  83. package/src/value/richText/heading.ts +32 -27
  84. package/src/value/richText/image.ts +9 -8
  85. package/src/value/richText/index.ts +71 -48
  86. package/src/value/richText/list.ts +6 -10
  87. package/src/value/richText/oList.ts +6 -10
  88. package/src/value/richText/paragraph.ts +10 -6
  89. package/src/value/richText/preformatted.ts +11 -7
  90. package/src/value/select.ts +11 -7
  91. package/src/value/sharedSlice.ts +5 -5
  92. package/src/value/sharedSliceVariation.ts +11 -16
  93. package/src/value/slice.ts +11 -15
  94. package/src/value/sliceZone.ts +14 -18
  95. package/src/value/timestamp.ts +31 -18
  96. package/src/value/title.ts +7 -3
  97. package/src/value/uid.ts +6 -4
@@ -4,8 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const prismicT = require('@prismicio/types');
6
6
  const changeCase = require('change-case');
7
- const fakerLocaleEN = require('faker/lib/locales/en/index.js');
8
- const Faker = require('faker/lib/index.js');
7
+ const Rand = require('rand-seed');
9
8
 
10
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
10
 
@@ -29,58 +28,146 @@ function _interopNamespace(e) {
29
28
 
30
29
  const prismicT__namespace = /*#__PURE__*/_interopNamespace(prismicT);
31
30
  const changeCase__namespace = /*#__PURE__*/_interopNamespace(changeCase);
32
- const fakerLocaleEN__namespace = /*#__PURE__*/_interopNamespace(fakerLocaleEN);
33
- const Faker__default = /*#__PURE__*/_interopDefaultLegacy(Faker);
34
-
35
- const FAKER_SEED = 1984;
36
-
37
- const createFaker = (seed = FAKER_SEED) => {
38
- let normalizedSeed;
39
- if (typeof seed === "string") {
40
- normalizedSeed = seed.split("").map((char) => char.charCodeAt(0));
41
- } else {
42
- normalizedSeed = seed;
43
- }
44
- const cacheKey = JSON.stringify(normalizedSeed);
45
- if (createFaker.cache[cacheKey]) {
46
- return createFaker.cache[cacheKey];
47
- }
48
- const fakerInstance = new Faker__default["default"]();
49
- fakerInstance.locales["en"] = fakerLocaleEN__namespace;
50
- fakerInstance.seed(normalizedSeed);
51
- createFaker.cache[cacheKey] = fakerInstance;
52
- return fakerInstance;
31
+ const Rand__default = /*#__PURE__*/_interopDefaultLegacy(Rand);
32
+
33
+ const wordsString = "lorem ipsum dolor sit amet, consectetur adipiscing elit ut aliquam, purus sit amet luctus venenatis, lectus magna fringilla urna, porttitor rhoncus dolor purus non enim praesent elementum facilisis leo, vel fringilla est ullamcorper eget nulla facilisi etiam dignissim diam quis enim lobortis scelerisque fermentum dui faucibus in ornare quam viverra orci sagittis eu volutpat odio facilisis mauris sit amet massa vitae tortor condimentum lacinia quis vel eros donec ac odio tempor orci dapibus ultrices in iaculis nunc sed augue lacus, viverra vitae congue eu, consequat ac felis donec et odio pellentesque diam volutpat commodo sed egestas egestas fringilla phasellus faucibus scelerisque eleifend donec pretium vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed velit dignissim sodales ut eu sem integer vitae justo eget magna fermentum iaculis eu non diam phasellus vestibulum lorem sed risus ultricies tristique nulla aliquet enim tortor, at auctor urna nunc id cursus metus aliquam eleifend mi in nulla posuere sollicitudin aliquam ultrices sagittis orci, a scelerisque purus semper eget duis at tellus at urna condimentum mattis pellentesque id nibh tortor, id aliquet lectus proin nibh nisl, condimentum id venenatis a, condimentum vitae sapien pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas sed tempus, urna et pharetra pharetra, massa massa ultricies mi, quis hendrerit dolor magna eget est lorem ipsum dolor sit amet, consectetur adipiscing elit pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas integer eget aliquet nibh praesent tristique magna sit amet purus gravida quis blandit turpis cursus in hac habitasse platea dictumst quisque sagittis, purus sit amet volutpat consequat, mauris nunc congue nisi, vitae suscipit tellus mauris a diam maecenas sed enim ut sem viverra aliquet eget sit amet tellus cras adipiscing enim eu turpis egestas pretium aenean pharetra, magna ac placerat vestibulum, lectus mauris ultrices eros, in cursus turpis massa tincidunt dui ut ornare lectus sit amet est placerat in egestas erat imperdiet sed euismod nisi porta lorem mollis aliquam ut porttitor leo a diam sollicitudin tempor id eu nisl nunc mi ipsum, faucibus vitae aliquet nec, ullamcorper sit amet risus nullam eget felis eget nunc lobortis mattis aliquam faucibus purus in massa tempor nec feugiat nisl pretium fusce id velit ut tortor pretium viverra suspendisse potenti nullam ac tortor vitae purus faucibus ornare suspendisse sed nisi lacus, sed viverra tellus in hac habitasse platea dictumst vestibulum rhoncus est pellentesque elit ullamcorper dignissim cras tincidunt lobortis feugiat vivamus at augue eget arcu dictum varius duis at consectetur lorem donec massa sapien, faucibus et molestie ac, feugiat sed lectus vestibulum mattis ullamcorper velit sed ullamcorper morbi tincidunt ornare massa, eget egestas purus viverra accumsan in nisl nisi, scelerisque eu ultrices vitae, auctor eu augue ut lectus arcu, bibendum at varius vel, pharetra vel turpis nunc eget lorem dolor, sed viverra ipsum nunc aliquet bibendum enim, facilisis gravida neque convallis a cras semper auctor neque, vitae tempus quam pellentesque nec nam aliquam sem et tortor consequat id porta nibh venenatis cras sed felis eget velit aliquet sagittis id consectetur purus ut faucibus pulvinar elementum integer enim neque, volutpat ac tincidunt vitae, semper quis lectus nulla at volutpat diam ut venenatis tellus in metus vulputate eu scelerisque felis imperdiet proin fermentum leo vel orci porta non pulvinar neque laoreet suspendisse interdum consectetur libero, id faucibus nisl tincidunt eget nullam non nisi est, sit amet facilisis magna etiam tempor, orci eu lobortis elementum, nibh tellus molestie nunc, non blandit massa enim nec dui nunc mattis enim ut tellus elementum sagittis vitae et leo duis ut diam quam nulla porttitor massa id neque aliquam vestibulum morbi blandit cursus risus, at ultrices mi tempus imperdiet nulla malesuada pellentesque elit eget gravida cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus mauris vitae ultricies leo integer malesuada nunc vel risus commodo viverra maecenas accumsan, lacus vel facilisis volutpat, est velit egestas dui, id ornare arcu odio ut sem nulla pharetra diam sit amet nisl suscipit adipiscing bibendum est ultricies integer quis auctor elit sed vulputate mi sit amet mauris commodo quis imperdiet massa tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc, consequat interdum varius sit amet, mattis vulputate enim nulla aliquet porttitor lacus, luctus accumsan tortor posuere ac ut consequat semper viverra nam libero justo, laoreet sit amet cursus sit amet, dictum sit amet justo donec enim diam, vulputate ut pharetra sit amet, aliquam id diam maecenas ultricies mi eget mauris pharetra et ultrices neque ornare aenean euismod elementum nisi, quis eleifend quam adipiscing vitae proin sagittis, nisl rhoncus mattis rhoncus, urna neque viverra justo, nec ultrices dui sapien eget mi proin sed libero enim, sed faucibus turpis in eu mi bibendum neque egestas congue quisque egestas diam in arcu cursus euismod quis viverra nibh cras pulvinar mattis nunc, sed blandit libero volutpat sed cras ornare arcu dui vivamus arcu felis, bibendum ut tristique et, egestas quis ipsum suspendisse ultrices gravida dictum fusce ut placerat orci nulla pellentesque dignissim enim, sit amet venenatis urna cursus eget nunc scelerisque viverra mauris, in aliquam sem fringilla ut morbi tincidunt augue interdum velit euismod in pellentesque massa placerat duis ultricies lacus sed turpis tincidunt id aliquet risus feugiat in ante metus, dictum at tempor commodo, ullamcorper a lacus vestibulum sed arcu non odio euismod lacinia at quis risus sed vulputate odio ut enim blandit volutpat maecenas volutpat blandit aliquam etiam erat velit, scelerisque in dictum non, consectetur a erat nam at lectus urna duis convallis convallis tellus, id interdum velit laoreet id donec ultrices tincidunt arcu, non sodales neque sodales ut etiam sit amet nisl purus, in mollis nunc sed id semper risus in hendrerit gravida rutrum quisque non tellus orci, ac auctor augue mauris augue neque, gravida in fermentum et, sollicitudin ac orci phasellus egestas tellus rutrum tellus pellentesque eu tincidunt tortor aliquam nulla facilisi cras fermentum, odio eu feugiat pretium, nibh ipsum consequat nisl, vel pretium lectus quam id leo in vitae turpis massa sed elementum tempus egestas sed sed risus pretium quam vulputate dignissim suspendisse in est ante in nibh mauris, cursus mattis molestie a, iaculis at erat pellentesque adipiscing commodo elit, at imperdiet dui accumsan sit amet nulla facilisi morbi tempus iaculis urna, id volutpat lacus laoreet non curabitur gravida arcu ac tortor dignissim convallis aenean et tortor at risus viverra adipiscing at in tellus integer feugiat scelerisque varius morbi enim nunc, faucibus a pellentesque sit amet, porttitor eget dolor morbi non arcu risus, quis varius quam quisque id diam vel quam elementum pulvinar etiam non quam lacus suspendisse faucibus interdum posuere lorem ipsum dolor sit amet, consectetur adipiscing elit duis tristique sollicitudin nibh sit amet commodo nulla facilisi nullam vehicula ipsum a arcu cursus vitae congue mauris rhoncus aenean vel elit scelerisque mauris pellentesque pulvinar pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas maecenas pharetra convallis posuere morbi leo urna, molestie at elementum eu, facilisis sed odio morbi quis commodo odio aenean sed adipiscing diam donec adipiscing tristique risus nec feugiat in fermentum posuere urna nec tincidunt praesent semper feugiat nibh sed pulvinar proin gravida hendrerit lectus a molestie";
34
+ const loremWords = wordsString.split(" ");
35
+ const lorem = (length, wordOffset = 0) => {
36
+ const count = parseInt(length.substring(0, length.length - 1));
37
+ const countType = length.charAt(length.length - 1);
38
+ if (!isNaN(count) && (countType === "w" || countType === "c")) {
39
+ if (!lorem.spaceIndices.length) {
40
+ let startIndex = -1;
41
+ do {
42
+ const index = wordsString.indexOf(" ", startIndex + 1);
43
+ lorem.spaceIndices.push(index);
44
+ startIndex = index;
45
+ } while (startIndex !== -1);
46
+ }
47
+ if (countType === "c") {
48
+ return wordsString.substring(0, count);
49
+ } else {
50
+ let sentence = "";
51
+ const startSpaceIndex = lorem.spaceIndices[wordOffset % lorem.spaceIndices.length - 1];
52
+ const endSpaceIndex = lorem.spaceIndices[(wordOffset % lorem.spaceIndices.length + count) % lorem.spaceIndices.length - 1];
53
+ if (count + wordOffset % lorem.spaceIndices.length > lorem.spaceIndices.length) {
54
+ sentence += wordsString.substring(startSpaceIndex + 1) + " ";
55
+ const wraparoundCounts = Math.floor(count / lorem.spaceIndices.length) - 1;
56
+ for (let i = 0; i < wraparoundCounts; i++) {
57
+ sentence += wordsString + " ";
58
+ }
59
+ sentence += wordsString.substring(0, endSpaceIndex);
60
+ } else {
61
+ sentence = wordsString.substring(startSpaceIndex + 1, endSpaceIndex);
62
+ }
63
+ if (sentence.charAt(sentence.length - 1) === ",") {
64
+ return sentence.substring(0, sentence.length - 1);
65
+ } else {
66
+ return sentence.substring(0, sentence.length);
67
+ }
68
+ }
69
+ }
70
+ throw new Error("Length must be of the form `${number}w` or `${number}c`");
53
71
  };
54
- createFaker.cache = {};
72
+ lorem.spaceIndices = [];
55
73
 
56
- const boolean = (config = {}) => {
57
- const faker = createFaker(config.seed);
74
+ const createFaker = (seed) => {
75
+ return new Faker(seed);
76
+ };
77
+ const DAY_MS = 1e3 * 60 * 60 * 24;
78
+ const YEAR_MS = DAY_MS * 365;
79
+ const YEAR_2022_MS = 52 * (YEAR_MS + DAY_MS / 4);
80
+ class Faker {
81
+ constructor(seed) {
82
+ this.seed = seed;
83
+ this.rand = new Rand__default["default"](seed.toString());
84
+ }
85
+ boolean() {
86
+ return this.random() >= 0.5;
87
+ }
88
+ random() {
89
+ return this.rand.next();
90
+ }
91
+ randomElement(elements) {
92
+ return elements[this.range(0, elements.length)];
93
+ }
94
+ randomElements(elements) {
95
+ const alwaysInclude = this.randomElement(elements);
96
+ return elements.filter((element) => element === alwaysInclude || this.boolean());
97
+ }
98
+ range(min, max) {
99
+ return Math.floor(this.rangeFloat(Math.ceil(min), Math.floor(max)));
100
+ }
101
+ rangeFloat(min, max) {
102
+ return this.random() * (max - min) + min;
103
+ }
104
+ words(length, wordOffset = this.range(0, loremWords.length)) {
105
+ return lorem(`${length}w`, wordOffset);
106
+ }
107
+ word() {
108
+ return this.randomElement(loremWords);
109
+ }
110
+ lorem(length, wordOffset = this.range(0, loremWords.length)) {
111
+ return lorem(length, wordOffset);
112
+ }
113
+ url() {
114
+ return `https://${this.word()}.example`;
115
+ }
116
+ hexColor() {
117
+ return `#${this.hash(6)}`;
118
+ }
119
+ hash(length) {
120
+ let hash = "";
121
+ for (let i = 0; i < length; i++) {
122
+ const chars = this.boolean() ? "abcdef" : "0123456789";
123
+ hash += chars[this.range(0, chars.length)];
124
+ }
125
+ return hash;
126
+ }
127
+ date() {
128
+ return new Date(YEAR_2022_MS + this.range(-YEAR_MS * 3, YEAR_MS * 3));
129
+ }
130
+ dateAfter(date) {
131
+ const timestamp = date.getTime();
132
+ return new Date(this.range(timestamp, timestamp + YEAR_MS * 3));
133
+ }
134
+ dateBefore(date) {
135
+ const timestamp = date.getTime();
136
+ return new Date(this.range(timestamp - YEAR_MS * 3, timestamp));
137
+ }
138
+ dateBetween(min, max) {
139
+ return new Date(this.range(min.getTime(), max.getTime()));
140
+ }
141
+ }
142
+
143
+ function boolean(config) {
144
+ const faker = config.faker || createFaker(config.seed);
58
145
  return {
59
146
  type: prismicT__namespace.CustomTypeModelFieldType.Boolean,
60
147
  config: {
61
- label: changeCase__namespace.capitalCase(faker.company.bsNoun())
148
+ label: changeCase__namespace.capitalCase(faker.word())
62
149
  }
63
150
  };
64
- };
151
+ }
65
152
 
66
- const color = (config = {}) => {
67
- const faker = createFaker(config.seed);
153
+ const color = (config) => {
154
+ const faker = config.faker || createFaker(config.seed);
68
155
  return {
69
156
  type: prismicT__namespace.CustomTypeModelFieldType.Color,
70
157
  config: {
71
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
72
- placeholder: changeCase__namespace.sentenceCase(faker.lorem.words(3))
158
+ label: changeCase__namespace.capitalCase(faker.word()),
159
+ placeholder: changeCase__namespace.sentenceCase(faker.words(3))
73
160
  }
74
161
  };
75
162
  };
76
163
 
77
- const contentRelationship = (config = {}) => {
78
- const faker = createFaker(config.seed);
164
+ const contentRelationship = (config) => {
165
+ const faker = config.faker || createFaker(config.seed);
79
166
  return {
80
167
  type: prismicT__namespace.CustomTypeModelFieldType.Link,
81
168
  config: {
82
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
83
- placeholder: changeCase__namespace.sentenceCase(faker.lorem.words(3)),
169
+ label: changeCase__namespace.capitalCase(faker.word()),
170
+ placeholder: changeCase__namespace.sentenceCase(faker.words(3)),
84
171
  select: prismicT__namespace.CustomTypeModelLinkSelectType.Document,
85
172
  customtypes: config.customTypeIDs,
86
173
  tags: config.tags
@@ -88,10 +175,10 @@ const contentRelationship = (config = {}) => {
88
175
  };
89
176
  };
90
177
 
91
- const customType = (config = {}) => {
178
+ const customType = (config) => {
92
179
  var _a, _b;
93
- const faker = createFaker(config.seed);
94
- let label = config.label || changeCase__namespace.capitalCase(faker.company.bsNoun());
180
+ const faker = config.faker || createFaker(config.seed);
181
+ let label = config.label || changeCase__namespace.capitalCase(faker.words(faker.range(1, 2)));
95
182
  let id = config.id || changeCase__namespace.snakeCase(label);
96
183
  if (config.id && !config.label) {
97
184
  label = changeCase__namespace.capitalCase(config.id);
@@ -107,139 +194,139 @@ const customType = (config = {}) => {
107
194
  return {
108
195
  id,
109
196
  label,
110
- status: (_a = config.status) != null ? _a : faker.datatype.boolean(),
111
- repeatable: (_b = config.repeatable) != null ? _b : faker.datatype.boolean(),
197
+ status: (_a = config.status) != null ? _a : faker.boolean(),
198
+ repeatable: (_b = config.repeatable) != null ? _b : faker.boolean(),
112
199
  json
113
200
  };
114
201
  };
115
202
 
116
- const date = (config = {}) => {
117
- const faker = createFaker(config.seed);
203
+ const date = (config) => {
204
+ const faker = config.faker || createFaker(config.seed);
118
205
  return {
119
206
  type: prismicT__namespace.CustomTypeModelFieldType.Date,
120
207
  config: {
121
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
122
- placeholder: changeCase__namespace.sentenceCase(faker.lorem.words(3))
208
+ label: changeCase__namespace.capitalCase(faker.word()),
209
+ placeholder: changeCase__namespace.sentenceCase(faker.words(3))
123
210
  }
124
211
  };
125
212
  };
126
213
 
127
- const embed = (config = {}) => {
128
- const faker = createFaker(config.seed);
214
+ const embed = (config) => {
215
+ const faker = config.faker || createFaker(config.seed);
129
216
  return {
130
217
  type: prismicT__namespace.CustomTypeModelFieldType.Embed,
131
218
  config: {
132
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
133
- placeholder: changeCase__namespace.sentenceCase(faker.lorem.words(3))
219
+ label: changeCase__namespace.capitalCase(faker.word()),
220
+ placeholder: changeCase__namespace.sentenceCase(faker.words(3))
134
221
  }
135
222
  };
136
223
  };
137
224
 
138
- const geoPoint = (config = {}) => {
139
- const faker = createFaker(config.seed);
225
+ const geoPoint = (config) => {
226
+ const faker = config.faker || createFaker(config.seed);
140
227
  return {
141
228
  type: prismicT__namespace.CustomTypeModelFieldType.GeoPoint,
142
229
  config: {
143
- label: changeCase__namespace.capitalCase(faker.company.bsNoun())
230
+ label: changeCase__namespace.capitalCase(faker.word())
144
231
  }
145
232
  };
146
233
  };
147
234
 
148
- const group = (config = {}) => {
149
- const faker = createFaker(config.seed);
235
+ function group(config) {
236
+ const faker = config.faker || createFaker(config.seed);
150
237
  return {
151
238
  type: prismicT__namespace.CustomTypeModelFieldType.Group,
152
239
  config: {
153
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
240
+ label: changeCase__namespace.capitalCase(faker.word()),
154
241
  fields: config.fields || {}
155
242
  }
156
243
  };
157
- };
244
+ }
158
245
 
159
- const image = (config = {}) => {
160
- const faker = createFaker(config.seed);
246
+ const image = (config) => {
247
+ const faker = config.faker || createFaker(config.seed);
161
248
  const thumbnails = (config.thumbnailNames || []).map((name) => {
162
249
  return {
163
250
  name,
164
- width: faker.datatype.number({ min: 500, max: 2e3 }),
165
- height: faker.datatype.number({ min: 500, max: 2e3 })
251
+ width: faker.range(500, 2e3),
252
+ height: faker.range(500, 2e3)
166
253
  };
167
254
  });
168
255
  return {
169
256
  type: prismicT__namespace.CustomTypeModelFieldType.Image,
170
257
  config: {
171
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
258
+ label: changeCase__namespace.capitalCase(faker.word()),
172
259
  constraint: {
173
- width: config.withConstraint ? faker.datatype.number({ min: 500, max: 2e3 }) : null,
174
- height: config.withConstraint ? faker.datatype.number({ min: 500, max: 2e3 }) : null
260
+ width: config.withConstraint ? faker.range(500, 2e3) : null,
261
+ height: config.withConstraint ? faker.range(500, 2e3) : null
175
262
  },
176
263
  thumbnails
177
264
  }
178
265
  };
179
266
  };
180
267
 
181
- const integrationFields = (config = {}) => {
182
- const faker = createFaker(config.seed);
268
+ const integrationFields = (config) => {
269
+ const faker = config.faker || createFaker(config.seed);
183
270
  return {
184
271
  type: prismicT__namespace.CustomTypeModelFieldType.IntegrationFields,
185
272
  config: {
186
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
187
- catalog: config.catalog || changeCase__namespace.snakeCase(faker.lorem.words(4))
273
+ label: changeCase__namespace.capitalCase(faker.word()),
274
+ catalog: config.catalog || changeCase__namespace.snakeCase(faker.words(2))
188
275
  }
189
276
  };
190
277
  };
191
278
 
192
- const keyText = (config = {}) => {
193
- const faker = createFaker(config.seed);
279
+ const keyText = (config) => {
280
+ const faker = config.faker || createFaker(config.seed);
194
281
  return {
195
282
  type: prismicT__namespace.CustomTypeModelFieldType.Text,
196
283
  config: {
197
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
198
- placeholder: changeCase__namespace.sentenceCase(faker.lorem.words(3))
284
+ label: changeCase__namespace.capitalCase(faker.word()),
285
+ placeholder: changeCase__namespace.sentenceCase(faker.words(3))
199
286
  }
200
287
  };
201
288
  };
202
289
 
203
- const link = (config = {}) => {
204
- const faker = createFaker(config.seed);
290
+ const link = (config) => {
291
+ const faker = config.faker || createFaker(config.seed);
205
292
  return {
206
293
  type: prismicT__namespace.CustomTypeModelFieldType.Link,
207
294
  config: {
208
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
209
- placeholder: changeCase__namespace.sentenceCase(faker.lorem.words(3)),
295
+ label: changeCase__namespace.capitalCase(faker.word()),
296
+ placeholder: changeCase__namespace.sentenceCase(faker.words(3)),
210
297
  select: null,
211
- allowTargetBlank: ("allowTargetBlank" in config ? config.allowTargetBlank : faker.datatype.boolean()) || void 0
298
+ allowTargetBlank: ("allowTargetBlank" in config ? config.allowTargetBlank : faker.boolean()) || void 0
212
299
  }
213
300
  };
214
301
  };
215
302
 
216
- const linkToMedia = (config = {}) => {
217
- const faker = createFaker(config.seed);
303
+ const linkToMedia = (config) => {
304
+ const faker = config.faker || createFaker(config.seed);
218
305
  return {
219
306
  type: prismicT__namespace.CustomTypeModelFieldType.Link,
220
307
  config: {
221
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
222
- placeholder: changeCase__namespace.sentenceCase(faker.lorem.words(3)),
308
+ label: changeCase__namespace.capitalCase(faker.word()),
309
+ placeholder: changeCase__namespace.sentenceCase(faker.words(3)),
223
310
  select: prismicT__namespace.CustomTypeModelLinkSelectType.Media
224
311
  }
225
312
  };
226
313
  };
227
314
 
228
- const number = (config = {}) => {
229
- const faker = createFaker(config.seed);
315
+ const number = (config) => {
316
+ const faker = config.faker || createFaker(config.seed);
230
317
  return {
231
318
  type: prismicT__namespace.CustomTypeModelFieldType.Number,
232
319
  config: {
233
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
234
- placeholder: changeCase__namespace.sentenceCase(faker.lorem.words(3))
320
+ label: changeCase__namespace.capitalCase(faker.word()),
321
+ placeholder: changeCase__namespace.sentenceCase(faker.words(3))
235
322
  }
236
323
  };
237
324
  };
238
325
 
239
- const richText = (config = {}) => {
326
+ const richText = (config) => {
240
327
  var _a;
241
- const faker = createFaker(config.seed);
242
- const blockTypes = faker.random.arrayElements([
328
+ const faker = config.faker || createFaker(config.seed);
329
+ const blockTypes = faker.randomElements([
243
330
  prismicT__namespace.RichTextNodeType.heading1,
244
331
  prismicT__namespace.RichTextNodeType.heading2,
245
332
  prismicT__namespace.RichTextNodeType.heading3,
@@ -256,34 +343,34 @@ const richText = (config = {}) => {
256
343
  prismicT__namespace.RichTextNodeType.embed,
257
344
  prismicT__namespace.RichTextNodeType.hyperlink
258
345
  ]).join(",");
259
- const blockTypeConfig = ((_a = config.withMultipleBlocks) != null ? _a : faker.datatype.boolean()) ? { multi: blockTypes } : { single: blockTypes };
346
+ const blockTypeConfig = ((_a = config.withMultipleBlocks) != null ? _a : faker.boolean()) ? { multi: blockTypes } : { single: blockTypes };
260
347
  return {
261
348
  type: prismicT__namespace.CustomTypeModelFieldType.StructuredText,
262
349
  config: {
263
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
264
- placeholder: changeCase__namespace.sentenceCase(faker.lorem.words(3)),
265
- allowTargetBlank: faker.datatype.boolean() ? true : void 0,
350
+ label: changeCase__namespace.capitalCase(faker.word()),
351
+ placeholder: changeCase__namespace.sentenceCase(faker.words(3)),
352
+ allowTargetBlank: faker.boolean() ? true : void 0,
266
353
  ...blockTypeConfig
267
354
  }
268
355
  };
269
356
  };
270
357
 
271
- const select = (config = {}) => {
272
- const faker = createFaker(config.seed);
358
+ const select = (config) => {
359
+ const faker = config.faker || createFaker(config.seed);
273
360
  return {
274
361
  type: prismicT__namespace.CustomTypeModelFieldType.Select,
275
362
  config: {
276
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
277
- placeholder: changeCase__namespace.sentenceCase(faker.lorem.words(3)),
363
+ label: changeCase__namespace.capitalCase(faker.word()),
364
+ placeholder: changeCase__namespace.sentenceCase(faker.words(3)),
278
365
  options: config.options || [],
279
366
  default_value: config.defaultValue || void 0
280
367
  }
281
368
  };
282
369
  };
283
370
 
284
- const sharedSlice = (config = {}) => {
285
- const faker = createFaker(config.seed);
286
- let name = config.name || changeCase__namespace.capitalCase(faker.company.bsNoun());
371
+ const sharedSlice = (config) => {
372
+ const faker = config.faker || createFaker(config.seed);
373
+ let name = config.name || changeCase__namespace.capitalCase(faker.words(faker.range(1, 2)));
287
374
  let id = config.id || changeCase__namespace.snakeCase(name);
288
375
  if (config.id && !config.name) {
289
376
  name = changeCase__namespace.pascalCase(config.id);
@@ -294,7 +381,7 @@ const sharedSlice = (config = {}) => {
294
381
  type: prismicT__namespace.CustomTypeModelSliceType.SharedSlice,
295
382
  id,
296
383
  name,
297
- description: faker.lorem.sentence(),
384
+ description: changeCase__namespace.sentenceCase(faker.words(faker.range(5, 10))),
298
385
  variations: config.variations || []
299
386
  };
300
387
  };
@@ -305,40 +392,129 @@ const sharedSliceChoice = () => {
305
392
  };
306
393
  };
307
394
 
308
- const sharedSliceVariation = (config = {}) => {
309
- const faker = createFaker(config.seed);
310
- let name = config.name || changeCase__namespace.capitalCase(faker.company.bsNoun());
395
+ const dataSet = [
396
+ {
397
+ url: "https://images.unsplash.com/photo-1604537529428-15bcbeecfe4d",
398
+ width: 4240,
399
+ height: 2832
400
+ },
401
+ {
402
+ url: "https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05",
403
+ width: 7372,
404
+ height: 4392
405
+ },
406
+ {
407
+ url: "https://images.unsplash.com/photo-1441974231531-c6227db76b6e",
408
+ width: 2560,
409
+ height: 1705
410
+ },
411
+ {
412
+ url: "https://images.unsplash.com/photo-1418065460487-3e41a6c84dc5",
413
+ width: 2200,
414
+ height: 1467
415
+ },
416
+ {
417
+ url: "https://images.unsplash.com/photo-1426604966848-d7adac402bff",
418
+ width: 5616,
419
+ height: 3744
420
+ },
421
+ {
422
+ url: "https://images.unsplash.com/photo-1604537466608-109fa2f16c3b",
423
+ width: 4240,
424
+ height: 2832
425
+ },
426
+ {
427
+ url: "https://images.unsplash.com/photo-1497436072909-60f360e1d4b1",
428
+ width: 2560,
429
+ height: 1440
430
+ },
431
+ {
432
+ url: "https://images.unsplash.com/reserve/HgZuGu3gSD6db21T3lxm_San%20Zenone.jpg",
433
+ width: 6373,
434
+ height: 4253
435
+ },
436
+ {
437
+ url: "https://images.unsplash.com/photo-1504198266287-1659872e6590",
438
+ width: 4272,
439
+ height: 2848
440
+ },
441
+ {
442
+ url: "https://images.unsplash.com/photo-1470770903676-69b98201ea1c",
443
+ width: 4554,
444
+ height: 3036
445
+ },
446
+ {
447
+ url: "https://images.unsplash.com/photo-1587502537745-84b86da1204f",
448
+ width: 6550,
449
+ height: 4367
450
+ },
451
+ {
452
+ url: "https://images.unsplash.com/photo-1431794062232-2a99a5431c6c",
453
+ width: 6e3,
454
+ height: 4e3
455
+ },
456
+ {
457
+ url: "https://images.unsplash.com/photo-1446329813274-7c9036bd9a1f",
458
+ width: 6e3,
459
+ height: 4e3
460
+ },
461
+ {
462
+ url: "https://images.unsplash.com/photo-1504567961542-e24d9439a724",
463
+ width: 4608,
464
+ height: 3456
465
+ },
466
+ {
467
+ url: "https://images.unsplash.com/photo-1444464666168-49d633b86797",
468
+ width: 4844,
469
+ height: 3234
470
+ },
471
+ {
472
+ url: "https://images.unsplash.com/photo-1553531384-397c80973a0b",
473
+ width: 4335,
474
+ height: 6502
475
+ }
476
+ ];
477
+ const getMockImageData = (config) => {
478
+ const faker = config.faker || createFaker(config.seed);
479
+ return faker.randomElement(dataSet);
480
+ };
481
+
482
+ const sharedSliceVariation = (config) => {
483
+ const faker = config.faker || createFaker(config.seed);
484
+ let name = config.name || changeCase__namespace.capitalCase(faker.words(faker.range(1, 2)));
311
485
  let id = config.id || changeCase__namespace.snakeCase(name);
312
486
  if (config.id && !config.name) {
313
487
  name = changeCase__namespace.pascalCase(config.id);
314
488
  } else if (config.name && !config.name) {
315
489
  id = changeCase__namespace.snakeCase(config.name);
316
490
  }
491
+ const imageData = getMockImageData({ faker });
317
492
  return {
318
493
  id,
319
494
  name,
320
- description: faker.lorem.sentence(),
321
- docURL: faker.internet.url(),
322
- version: faker.git.shortSha(),
495
+ description: changeCase__namespace.sentenceCase(faker.words(faker.range(5, 10))),
496
+ docURL: faker.url(),
497
+ version: faker.hash(7),
323
498
  primary: config.primaryFields || {},
324
- items: config.itemsFields || {}
499
+ items: config.itemsFields || {},
500
+ imageUrl: imageData.url
325
501
  };
326
502
  };
327
503
 
328
- const slice = (config = {}) => {
329
- const faker = createFaker(config.seed);
504
+ const slice = (config) => {
505
+ const faker = config.faker || createFaker(config.seed);
330
506
  return {
331
507
  type: prismicT__namespace.CustomTypeModelSliceType.Slice,
332
- icon: changeCase__namespace.snakeCase(faker.company.bsNoun()),
333
- display: faker.datatype.boolean() ? prismicT__namespace.CustomTypeModelSliceDisplay.Grid : prismicT__namespace.CustomTypeModelSliceDisplay.List,
334
- fieldset: changeCase__namespace.capitalCase(faker.lorem.words()),
335
- description: faker.lorem.sentence(),
508
+ icon: changeCase__namespace.snakeCase(faker.word()),
509
+ display: faker.boolean() ? prismicT__namespace.CustomTypeModelSliceDisplay.Grid : prismicT__namespace.CustomTypeModelSliceDisplay.List,
510
+ fieldset: changeCase__namespace.capitalCase(faker.words(2)),
511
+ description: changeCase__namespace.sentenceCase(faker.words(faker.range(5, 10))),
336
512
  repeat: config.repeatFields || {},
337
513
  "non-repeat": config.nonRepeatFields || {}
338
514
  };
339
515
  };
340
516
 
341
- const sliceZone = (config = {}) => {
517
+ const sliceZone = (config) => {
342
518
  const labels = {};
343
519
  for (const choiceId in config.choices) {
344
520
  const choice = config.choices[choiceId];
@@ -356,20 +532,20 @@ const sliceZone = (config = {}) => {
356
532
  };
357
533
  };
358
534
 
359
- const timestamp = (config = {}) => {
360
- const faker = createFaker(config.seed);
535
+ const timestamp = (config) => {
536
+ const faker = config.faker || createFaker(config.seed);
361
537
  return {
362
538
  type: prismicT__namespace.CustomTypeModelFieldType.Timestamp,
363
539
  config: {
364
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
365
- placeholder: changeCase__namespace.sentenceCase(faker.lorem.words(3))
540
+ label: changeCase__namespace.capitalCase(faker.word()),
541
+ placeholder: changeCase__namespace.sentenceCase(faker.words(3))
366
542
  }
367
543
  };
368
544
  };
369
545
 
370
- const title = (config = {}) => {
371
- const faker = createFaker(config.seed);
372
- const single = faker.random.arrayElements([
546
+ const title = (config) => {
547
+ const faker = config.faker || createFaker(config.seed);
548
+ const single = faker.randomElements([
373
549
  "heading1",
374
550
  "heading2",
375
551
  "heading3",
@@ -380,28 +556,28 @@ const title = (config = {}) => {
380
556
  return {
381
557
  type: prismicT__namespace.CustomTypeModelFieldType.StructuredText,
382
558
  config: {
383
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
384
- placeholder: changeCase__namespace.sentenceCase(faker.lorem.words(3)),
559
+ label: changeCase__namespace.capitalCase(faker.word()),
560
+ placeholder: changeCase__namespace.sentenceCase(faker.words(3)),
385
561
  single,
386
- allowTargetBlank: faker.datatype.boolean() ? true : void 0
562
+ allowTargetBlank: faker.boolean() || void 0
387
563
  }
388
564
  };
389
565
  };
390
566
 
391
- const uid = (config = {}) => {
392
- const faker = createFaker(config.seed);
567
+ const uid = (config) => {
568
+ const faker = config.faker || createFaker(config.seed);
393
569
  return {
394
570
  type: prismicT__namespace.CustomTypeModelFieldType.UID,
395
571
  config: {
396
- label: changeCase__namespace.capitalCase(faker.company.bsNoun()),
397
- placeholder: changeCase__namespace.sentenceCase(faker.lorem.words(3))
572
+ label: changeCase__namespace.capitalCase(faker.word()),
573
+ placeholder: changeCase__namespace.sentenceCase(faker.words(3))
398
574
  }
399
575
  };
400
576
  };
401
577
 
402
578
  const generateFieldId = (config) => {
403
- const faker = createFaker(config.seed);
404
- return changeCase__namespace.snakeCase(faker.lorem.words(faker.datatype.number({ min: 1, max: 3 })));
579
+ const faker = config.faker || createFaker(config.seed);
580
+ return changeCase__namespace.snakeCase(faker.words(faker.range(1, 3)));
405
581
  };
406
582
 
407
583
  const mockModelFns = {
@@ -422,22 +598,110 @@ const mockModelFns = {
422
598
  timestamp,
423
599
  title
424
600
  };
425
- const buildMockGroupFieldMap = (config = {}) => {
426
- const faker = createFaker(config.seed);
601
+ const buildMockGroupFieldMap = (config) => {
602
+ const faker = config.faker || createFaker(config.seed);
427
603
  const fields = {};
428
- const fieldTypes = faker.random.arrayElements(Object.keys(mockModelFns));
604
+ const fieldTypes = faker.randomElements(Object.keys(mockModelFns));
429
605
  for (const fieldType of fieldTypes) {
430
- const fieldId = generateFieldId({ seed: config.seed });
606
+ const fieldId = generateFieldId({ faker });
431
607
  const mockModelFn = mockModelFns[fieldType];
432
- fields[fieldId] = mockModelFn({ seed: config.seed });
608
+ fields[fieldId] = mockModelFn({ faker });
433
609
  }
434
610
  return fields;
435
611
  };
436
612
 
613
+ const createModelMockFactory = (...args) => {
614
+ return new ModelMockFactory(...args);
615
+ };
616
+ class ModelMockFactory {
617
+ constructor(config) {
618
+ this.faker = "faker" in config ? config.faker : createFaker(config.seed);
619
+ }
620
+ get seed() {
621
+ return this.faker.seed;
622
+ }
623
+ buildMockGroupFieldMap(config) {
624
+ return buildMockGroupFieldMap({ ...config, faker: this.faker });
625
+ }
626
+ boolean(config) {
627
+ return boolean({ ...config, faker: this.faker });
628
+ }
629
+ color(config) {
630
+ return color({ ...config, faker: this.faker });
631
+ }
632
+ contentRelationship(config) {
633
+ return contentRelationship({ ...config, faker: this.faker });
634
+ }
635
+ customType(config) {
636
+ return customType({ ...config, faker: this.faker });
637
+ }
638
+ date(config) {
639
+ return date({ ...config, faker: this.faker });
640
+ }
641
+ embed(config) {
642
+ return embed({ ...config, faker: this.faker });
643
+ }
644
+ geoPoint(config) {
645
+ return geoPoint({ ...config, faker: this.faker });
646
+ }
647
+ group(config) {
648
+ return group({ ...config, faker: this.faker });
649
+ }
650
+ image(config) {
651
+ return image({ ...config, faker: this.faker });
652
+ }
653
+ integrationFields(config) {
654
+ return integrationFields({ ...config, faker: this.faker });
655
+ }
656
+ keyText(config) {
657
+ return keyText({ ...config, faker: this.faker });
658
+ }
659
+ link(config) {
660
+ return link({ ...config, faker: this.faker });
661
+ }
662
+ linkToMedia(config) {
663
+ return linkToMedia({ ...config, faker: this.faker });
664
+ }
665
+ number(config) {
666
+ return number({ ...config, faker: this.faker });
667
+ }
668
+ richText(config) {
669
+ return richText({ ...config, faker: this.faker });
670
+ }
671
+ select(config) {
672
+ return select({ ...config, faker: this.faker });
673
+ }
674
+ sharedSlice(config) {
675
+ return sharedSlice({ ...config, faker: this.faker });
676
+ }
677
+ sharedSliceChoice() {
678
+ return sharedSliceChoice();
679
+ }
680
+ sharedSliceVariation(config) {
681
+ return sharedSliceVariation({ ...config, faker: this.faker });
682
+ }
683
+ slice(config) {
684
+ return slice({ ...config, faker: this.faker });
685
+ }
686
+ sliceZone(config) {
687
+ return sliceZone({ ...config, faker: this.faker });
688
+ }
689
+ timestamp(config) {
690
+ return timestamp({ ...config, faker: this.faker });
691
+ }
692
+ title(config) {
693
+ return title({ ...config, faker: this.faker });
694
+ }
695
+ uid(config) {
696
+ return uid({ ...config, faker: this.faker });
697
+ }
698
+ }
699
+
437
700
  exports.boolean = boolean;
438
701
  exports.buildMockGroupFieldMap = buildMockGroupFieldMap;
439
702
  exports.color = color;
440
703
  exports.contentRelationship = contentRelationship;
704
+ exports.createModelFactory = createModelMockFactory;
441
705
  exports.customType = customType;
442
706
  exports.date = date;
443
707
  exports.embed = embed;