-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrepository.ts
56 lines (49 loc) · 1.25 KB
/
repository.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import * as prismic from "@prismicio/client";
import { capitalCase } from "../lib/changeCase";
import { createFaker } from "../lib/createFaker";
import { generateTags } from "../lib/generateTags";
import { MockRestApiConfig } from "../types";
import { ref } from "./ref";
export type MockRestApiRepositoryConfig = {
customTypeModels?: prismic.CustomTypeModel[];
withReleases?: boolean;
} & MockRestApiConfig;
export const repository = (
config: MockRestApiRepositoryConfig,
): prismic.Repository => {
const faker = config.faker || createFaker(config.seed);
const types = (config.customTypeModels || []).reduce(
(acc, model) => {
acc[model.id] = model.label || model.id;
return acc;
},
{} as prismic.Repository["types"],
);
return {
refs: [
ref({ faker, isMasterRef: true }),
...(config.withReleases ? [ref({ faker }), ref({ faker })] : []),
],
integrationFieldsRef: ref({ faker }).ref,
types,
languages: [
{
id: faker.word(),
name: capitalCase(faker.word()),
is_master: true,
},
],
tags: generateTags({
faker,
min: 1,
max: 10,
}),
forms: {},
license: "All Rights Reserved",
version: faker.hash(7),
bookmarks: {},
experiments: {},
oauth_token: faker.url(),
oauth_initiate: faker.url(),
};
};