-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrc.ts
98 lines (90 loc) · 2.93 KB
/
rc.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { ServerScope } from "nano";
/** Kivik RC file configuration. */
export interface Rc {
/**
* Object containing deployment configurations. Adding at least one is
* required to be able to deploy Kivik configuration elsewhere.
*/
deployments?: Record<string, Deployment>;
/** Subdirectories of the root directory which do not contain database configuration. Default: `["node_modules"]` */
excludeDirectories?: string[];
/** JavaScript files to ignore when processing design documents. Default: `["*.spec.*", "*.test.*"]` */
excludeDesign?: string[];
/** Configuration for Kivik instances. */
local?: InstanceConfig;
/** Subdirectory of the directory containing the RC file where the database configuration can be found. */
subdirectory?: string;
}
/**
* Configuration for deploying design documents to a CouchDB endpoint.
*/
export interface Deployment {
/** CouchDB endpoint URL. Required. */
url: string;
/**
* Authentication credentials. If left unset, Kivik will attempt to deploy
* anonymously.
*/
auth?: {
/** CouchDB username */
user: string;
/** `user`'s password */
password: string;
};
/** Suffix to append to the end of each database name. Default: `undefined` */
suffix?: string;
/** Whether or not to deploy fixtures along with the design documents Default: `false`. */
fixtures?: boolean;
/** List of databases to deploy. By default, all databases are deployed. */
dbs?: string[];
}
export type NanoDeployment = {
nano: ServerScope;
suffix?: string;
fixtures: boolean;
dbs: string[] | null;
};
/** Configuration for Kivik instances. */
export interface InstanceConfig {
/** Deploy fixtures when running `kivik dev`. Default: `true` */
fixtures?: boolean;
/** CouchDB docker image tag. Default: `couchdb:3.1` */
image?: string;
/** Port that Kivik will attempt to run a `kivik dev` instance on. Default: `5984` */
port?: number;
/** CouchDB admin user. Default: `kivik` */
user?: string;
/** CouchDB admin user's password. Default: `kivik` */
password?: string;
}
export type NormalizedInstanceConfig = Required<InstanceConfig>;
/**
* Normalize a InstanceConfig object with defaults.
*/
export const normalizeInstanceConfig = (
c: InstanceConfig
): NormalizedInstanceConfig => {
return {
fixtures: typeof c.fixtures === "boolean" ? c.fixtures : true,
image: c.image || "couchdb:3.1",
port: c.port || 5984,
user: c.user || "kivik",
password: c.password || "kivik",
};
};
export type NormalizedRc = Required<Omit<Rc, "local">> & {
/** Configuration for local, ephemeral Kivik containers */
local: NormalizedInstanceConfig;
};
/**
* Normalize an Rc object with defaults.
*/
export const normalizeRc = (rc: Rc): NormalizedRc => {
return {
deployments: rc.deployments || {},
excludeDirectories: rc.excludeDirectories || ["node_modules"],
excludeDesign: rc.excludeDesign || ["*.spec.*", "*.test.*"],
local: normalizeInstanceConfig(rc.local || {}),
subdirectory: rc.subdirectory || ".",
};
};