/
regex.ts
44 lines (38 loc) · 1.76 KB
/
regex.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
/**
* A regex to match the JSON output of a field's comment type.
*
* @example `[TYPE] comment...`
*/
export const JSON_REGEX = /^\s*!?\[(.*?)\]/m;
export const LITERAL_REGEX = /^\s*!/m;
/**
* A list of regexes to match all types and subtypes generated by prisma for a specific
* model
*/
export function createRegexForType(name: string) {
return [
new RegExp(`^${name}CountAggregate$`, 'm'),
// new RegExp(`^${name}CountAggregateOutputType$`, 'm'), `number` fields
// new RegExp(`^${name}CountOrderByAggregateInput$`, 'm'), `SortOrder` fields
// new RegExp(`^${name}CountAggregateInputType$`, 'm'), `true` fields
new RegExp(`^${name}Group$`, 'm'),
new RegExp(`^${name}GroupByOutputType$`, 'm'),
// new RegExp(`^${name}OrderByWithRelationInput$`, 'm'), `SortOrder` fields
// new RegExp(`^${name}OrderByWithAggregationInput$`, 'm'), `SortOrder` fields
new RegExp(`^${name}(?:Scalar)?Where$`, 'm'),
new RegExp(`^${name}(?:Scalar)?WhereInput$`, 'm'),
new RegExp(`^${name}(?:Scalar)?WhereWithAggregatesInput$`, 'm'),
new RegExp(`^${name}(?:Unchecked)?CreateInput$`, 'm'),
new RegExp(`^${name}(?:Unchecked)?CreateManyInput$`, 'm'),
new RegExp(`^${name}(?:Unchecked)?CreateWithout(?:\\w+?)Input$`, 'm'),
new RegExp(`^${name}(?:Unchecked)?CreateMany(?:\\w+?)Input$`, 'm'),
new RegExp(`^${name}(?:Unchecked)?UpdateInput$`, 'm'),
new RegExp(`^${name}(?:Unchecked)?UpdateManyInput$`, 'm'),
new RegExp(`^${name}(?:Unchecked)?UpdateManyMutationInput$`, 'm'),
new RegExp(`^${name}(?:Unchecked)?UpdateWithout(?:\\w+?)Input$`, 'm')
];
}
/** If the provided type is a update one variant */
export function isUpdateOneType(type: string) {
return type.match(/UpdateInput$/m) || type.match(/UpdateWithout(?:\w+?)Input$/m);
}