@vantreeseba/drizzle-graphql 12.0.1 → 13.0.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.
- package/README.md +13 -8
- package/dist/index.cjs +8 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +375 -52
- package/dist/index.d.ts +375 -52
- package/dist/index.js +8 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,291 @@ import { GraphQLDate, GraphQLDateTime, GraphQLJSON, GraphQLUUID } from "graphql-
|
|
|
7
7
|
import "drizzle-orm/mysql-core/query-builders/query";
|
|
8
8
|
import "drizzle-orm/pg-core/query-builders/query";
|
|
9
9
|
import "drizzle-orm/sqlite-core/query-builders/query";
|
|
10
|
+
//#region src/util/type-naming.d.ts
|
|
11
|
+
/** A word the rules decline to decide. Widens the keys derived from it rather than guessing. */
|
|
12
|
+
type Unresolved = string;
|
|
13
|
+
type Letter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
|
|
14
|
+
type Vowel = 'a' | 'e' | 'i' | 'o' | 'u';
|
|
15
|
+
/** `pluralize`'s `[^aou]` class, from the `[^aou]us` stem both directions share. */
|
|
16
|
+
type NotAOU = Exclude<Letter, 'a' | 'o' | 'u'>;
|
|
17
|
+
/** True when `S` ends with any member of the union `Suffix`. */
|
|
18
|
+
type EndsWith<S extends string, Suffix extends string> = Lowercase<S> extends `${string}${Suffix}` ? true : false;
|
|
19
|
+
/**
|
|
20
|
+
* `pluralize`'s uncountable list: these are their own singular *and* plural. Trimmed to the
|
|
21
|
+
* entries that could plausibly name a table; the corpus test pins the ones that are here.
|
|
22
|
+
*/
|
|
23
|
+
type Uncountable = 'advice' | 'agenda' | 'aid' | 'aircraft' | 'alcohol' | 'ammo' | 'analytics' | 'anime' | 'athletics' | 'audio' | 'blood' | 'cash' | 'chassis' | 'chess' | 'clothing' | 'commerce' | 'cooperation' | 'corps' | 'debris' | 'digestion' | 'energy' | 'equipment' | 'expertise' | 'firmware' | 'fun' | 'garbage' | 'graffiti' | 'hardware' | 'headquarters' | 'health' | 'homework' | 'housework' | 'information' | 'jeans' | 'justice' | 'kudos' | 'labour' | 'literature' | 'machinery' | 'mail' | 'manga' | 'media' | 'mews' | 'music' | 'mud' | 'news' | 'personnel' | 'plankton' | 'pliers' | 'police' | 'pollution' | 'premises' | 'rain' | 'research' | 'rice' | 'scissors' | 'series' | 'sewage' | 'shambles' | 'software' | 'species' | 'staff' | 'tennis' | 'traffic' | 'transportation' | 'wealth' | 'welfare' | 'wildlife';
|
|
24
|
+
/** The same list's regex members, as the endings they stand for. */
|
|
25
|
+
type UncountableEnding = 'fish' | 'deer' | 'sheep' | 'pox' | 'measles' | 'pokemon' | 'pokémon' | `${Exclude<Letter, Vowel>}ese` | `o${'i' | 'u'}s`;
|
|
26
|
+
/**
|
|
27
|
+
* `pluralize`'s irregular pairs, minus the pronouns, plus the handful of words whose rule is
|
|
28
|
+
* `\b`-anchored and so behaves as a whole word: `mice`/`lice` from `\b((?:tit)?m|l)ice$`,
|
|
29
|
+
* `people` and `children` from their own rules, and `lives` from the guarded `li` in the
|
|
30
|
+
* `-ves` rule that leaves `olives` alone.
|
|
31
|
+
*/
|
|
32
|
+
type IrregularPlurals = {
|
|
33
|
+
anathema: 'anathemata';
|
|
34
|
+
axe: 'axes';
|
|
35
|
+
carve: 'carves';
|
|
36
|
+
child: 'children';
|
|
37
|
+
die: 'dice';
|
|
38
|
+
dingo: 'dingoes';
|
|
39
|
+
dogma: 'dogmata';
|
|
40
|
+
eave: 'eaves';
|
|
41
|
+
echo: 'echoes';
|
|
42
|
+
foot: 'feet';
|
|
43
|
+
genus: 'genera';
|
|
44
|
+
goose: 'geese';
|
|
45
|
+
groove: 'grooves';
|
|
46
|
+
human: 'humans';
|
|
47
|
+
lemma: 'lemmata';
|
|
48
|
+
life: 'lives';
|
|
49
|
+
louse: 'lice';
|
|
50
|
+
man: 'men';
|
|
51
|
+
mouse: 'mice';
|
|
52
|
+
ox: 'oxen';
|
|
53
|
+
passerby: 'passersby';
|
|
54
|
+
person: 'people';
|
|
55
|
+
pickaxe: 'pickaxes';
|
|
56
|
+
proof: 'proofs';
|
|
57
|
+
quiz: 'quizzes';
|
|
58
|
+
schema: 'schemata';
|
|
59
|
+
stigma: 'stigmata';
|
|
60
|
+
stoma: 'stomata';
|
|
61
|
+
thief: 'thieves';
|
|
62
|
+
titmouse: 'titmice';
|
|
63
|
+
tooth: 'teeth';
|
|
64
|
+
tornado: 'tornadoes';
|
|
65
|
+
torpedo: 'torpedoes';
|
|
66
|
+
valve: 'valves';
|
|
67
|
+
viscus: 'viscera';
|
|
68
|
+
volcano: 'volcanoes';
|
|
69
|
+
yes: 'yeses';
|
|
70
|
+
};
|
|
71
|
+
type IrregularSingulars = {
|
|
72
|
+
anathemata: 'anathema';
|
|
73
|
+
axes: 'axe';
|
|
74
|
+
carves: 'carve';
|
|
75
|
+
children: 'child';
|
|
76
|
+
dice: 'die';
|
|
77
|
+
dingoes: 'dingo';
|
|
78
|
+
dogmata: 'dogma';
|
|
79
|
+
eaves: 'eave';
|
|
80
|
+
echoes: 'echo';
|
|
81
|
+
feet: 'foot';
|
|
82
|
+
geese: 'goose';
|
|
83
|
+
genera: 'genus';
|
|
84
|
+
grooves: 'groove';
|
|
85
|
+
humans: 'human';
|
|
86
|
+
lemmata: 'lemma';
|
|
87
|
+
lice: 'louse';
|
|
88
|
+
lives: 'life';
|
|
89
|
+
men: 'man';
|
|
90
|
+
mice: 'mouse';
|
|
91
|
+
oxen: 'ox';
|
|
92
|
+
passersby: 'passerby';
|
|
93
|
+
people: 'person';
|
|
94
|
+
pickaxes: 'pickaxe';
|
|
95
|
+
proofs: 'proof';
|
|
96
|
+
quizzes: 'quiz';
|
|
97
|
+
schemata: 'schema';
|
|
98
|
+
stigmata: 'stigma';
|
|
99
|
+
stomata: 'stoma';
|
|
100
|
+
teeth: 'tooth';
|
|
101
|
+
thieves: 'thief';
|
|
102
|
+
titmice: 'titmouse';
|
|
103
|
+
tornadoes: 'tornado';
|
|
104
|
+
torpedoes: 'torpedo';
|
|
105
|
+
valves: 'valve';
|
|
106
|
+
viscera: 'viscus';
|
|
107
|
+
volcanoes: 'volcano';
|
|
108
|
+
yeses: 'yes';
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* The stems that keep their `ie` instead of collapsing to `y`. `pluralize` anchors this rule
|
|
112
|
+
* at a word boundary, so these are whole stems and not endings: `ties` gives `tie` and
|
|
113
|
+
* `cuties` gives `cutie`, but `oldies` gives `oldy` and `cookies` gives `cooky`. Guessing
|
|
114
|
+
* from the ending is precisely what does not work here, hence the list.
|
|
115
|
+
*/
|
|
116
|
+
type IeWholeStem = 'l' | 't' | 'neckt' | 'crosst' | 'coll' | 'faer' | 'food' | 'gen' | 'goon' | 'group' | 'lass' | 'talk' | 'goal' | 'p' | 'cut' | 'zomb';
|
|
117
|
+
/** `\b(mon|smil)ies$` — the two stems that take `ey` rather than `y` or `ie`. */
|
|
118
|
+
type EyWholeStem = 'mon' | 'smil';
|
|
119
|
+
/** `(movie|twelve|abuse|e[mn]u)s$` — words that just drop the `s`, ahead of the `ies` rule. */
|
|
120
|
+
type PlainSStem = 'movie' | 'twelve' | 'abuse' | `e${'m' | 'n'}u`;
|
|
121
|
+
/**
|
|
122
|
+
* Stems the big `(x|ch|ss|sh|zz|…)(?:es)?$` rule strips `es` from — the ones expressible as a
|
|
123
|
+
* plain ending. Its character-class members are {@link EsClassStem}, since a union of endings
|
|
124
|
+
* cannot say "any letter but these".
|
|
125
|
+
*/
|
|
126
|
+
type EsStem = 'x' | 'ch' | 'ss' | 'sh' | 'zz' | 'tto' | 'go' | 'cho' | 'alias' | 'gas' | 'hero' | 'ato' | 'gro';
|
|
127
|
+
/** The same rule's character classes, expanded into the unions they stand for. */
|
|
128
|
+
type EsClassStem = `${NotAOU}us` | `t${'l' | 'm'}as` | `${Vowel}ris`;
|
|
129
|
+
/**
|
|
130
|
+
* `(agend|addend|…|quor)(?:a|um)$` and `(apheli|…|automat)(?:a|on)$`. Both directions read
|
|
131
|
+
* these as endings rather than whole words, so `metadata` gives `metadatum`.
|
|
132
|
+
*/
|
|
133
|
+
type AToUmStem = 'agend' | 'addend' | 'millenni' | 'dat' | 'extrem' | 'bacteri' | 'desiderat' | 'strat' | 'candelabr' | 'errat' | 'ov' | 'symposi' | 'curricul' | 'quor';
|
|
134
|
+
type AToOnStem = 'apheli' | 'hyperbat' | 'periheli' | 'asyndet' | 'noumen' | 'phenomen' | 'criteri' | 'organ' | 'prolegomen' | 'hedr' | 'automat';
|
|
135
|
+
/** `(ax|test)is$` -> `es`. */
|
|
136
|
+
type AxisStem = 'ax' | 'test';
|
|
137
|
+
/** `(analy|diagno|…)(?:sis|ses)$` — the `-sis` family, which keeps its `sis`. */
|
|
138
|
+
type SisStem = 'analy' | 'diagno' | 'parenthe' | 'progno' | 'synop' | 'the' | 'empha' | 'cri' | 'ne';
|
|
139
|
+
/**
|
|
140
|
+
* `-ves` plurals that restore an `f` or `fe`. These are endings, not whole words, so
|
|
141
|
+
* `bookshelves` gives `bookshelf` and `housewives` gives `housewife` — but `archives`,
|
|
142
|
+
* `olives` and `sieves` match none of them and fall through to the plain `s` drop, which is
|
|
143
|
+
* the whole point of listing the stems rather than keying off `ves`.
|
|
144
|
+
*/
|
|
145
|
+
type VesToFStem = 'ar' | 'wol' | 'al' | 'el' | 'ea' | 'eo' | 'oa' | 'oo';
|
|
146
|
+
type VesToFeStem = 'wi' | 'kni';
|
|
147
|
+
/** The same rule's `\b`-anchored `li`, which is why `lives` is `life` but `olives` is `olive`. */
|
|
148
|
+
type LiWholeStem = 'li' | `${'after' | 'half' | 'high' | 'low' | 'mid' | 'night' | 'non'}li`;
|
|
149
|
+
/** `(cod|mur|sil|vert|ind)ices$` -> `ex` and `(matr|append)ices$` -> `ix`. */
|
|
150
|
+
type IcesToExStem = 'cod' | 'mur' | 'sil' | 'vert' | 'ind';
|
|
151
|
+
type IcesToIxStem = 'matr' | 'append';
|
|
152
|
+
/** Latin plurals whose singular no ending-based rule recovers. */
|
|
153
|
+
type LatinSingulars = {
|
|
154
|
+
addenda: 'addendum';
|
|
155
|
+
algae: 'alga';
|
|
156
|
+
alumnae: 'alumna';
|
|
157
|
+
alumni: 'alumnus';
|
|
158
|
+
bacteria: 'bacterium';
|
|
159
|
+
cacti: 'cactus';
|
|
160
|
+
candelabra: 'candelabrum';
|
|
161
|
+
cherubim: 'cherub';
|
|
162
|
+
criteria: 'criterion';
|
|
163
|
+
curricula: 'curriculum';
|
|
164
|
+
data: 'datum';
|
|
165
|
+
errata: 'erratum';
|
|
166
|
+
foci: 'focus';
|
|
167
|
+
fungi: 'fungus';
|
|
168
|
+
millennia: 'millennium';
|
|
169
|
+
nuclei: 'nucleus';
|
|
170
|
+
ova: 'ovum';
|
|
171
|
+
phenomena: 'phenomenon';
|
|
172
|
+
radii: 'radius';
|
|
173
|
+
seraphim: 'seraph';
|
|
174
|
+
strata: 'stratum';
|
|
175
|
+
syllabi: 'syllabus';
|
|
176
|
+
symposia: 'symposium';
|
|
177
|
+
termini: 'terminus';
|
|
178
|
+
testes: 'testis';
|
|
179
|
+
vertebrae: 'vertebra';
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Endings the rules above leave undecided and the plain `s` drop would get wrong — Latin
|
|
183
|
+
* stems and the `-is` family, mostly. A word ending in one of these that matched nothing
|
|
184
|
+
* earlier is left unresolved rather than guessed at.
|
|
185
|
+
*/
|
|
186
|
+
type UndecidedSingularEnding = 'a' | 'i' | 'ae' | 'im' | 'ice' | 'ren' | 'eaux' | 'is';
|
|
187
|
+
/**
|
|
188
|
+
* The singular of a table key, as `pluralize.singular` would return it — or `string` where
|
|
189
|
+
* these rules decline to decide. Matching is case-insensitive, and the word's interior case
|
|
190
|
+
* survives (`auditLogs` -> `auditLog`); a whole-word match comes back lower case, which is
|
|
191
|
+
* immaterial since every caller re-cases the first letter anyway.
|
|
192
|
+
*/
|
|
193
|
+
type Singularize<S extends string> = Lowercase<S> extends Uncountable ? Lowercase<S> : EndsWith<S, UncountableEnding> extends true ? S : Lowercase<S> extends keyof IrregularPlurals ? Lowercase<S> : Lowercase<S> extends keyof IrregularSingulars ? IrregularSingulars[Lowercase<S>] : Lowercase<S> extends keyof LatinSingulars ? LatinSingulars[Lowercase<S>] : S extends `${infer A}men` ? `${A}man` : S extends `${infer A}s` ? SingularizeS<S, A> : S extends `${infer A}a` ? SingularizeA<A> : EndsWith<S, EsStem | EsClassStem> extends true ? S : EndsWith<S, UndecidedSingularEnding> extends true ? Unresolved : S;
|
|
194
|
+
/** The `…s` forks, in `pluralize`'s priority order, each testing a stem it has already split. */
|
|
195
|
+
type SingularizeS<S extends string, A extends string> = EndsWith<A, PlainSStem> extends true ? A : S extends `${infer B}ies` ? SingularizeIes<S, B> : EndsWith<S, 'ss'> extends true ? S : S extends `${infer B}ses` ? SingularizeSes<S, B> : S extends `${infer B}ves` ? SingularizeVes<B> : S extends `${infer B}ices` ? SingularizeIces<B> : S extends `${infer B}es` ? SingularizeEs<S, B> : S extends `${infer B}sis` ? SingularizeSis<S, B> : EndsWith<S, EsStem | EsClassStem> extends true ? S : EndsWith<S, UndecidedSingularEnding> extends true ? Unresolved : A;
|
|
196
|
+
/** `(analy|…)sis$` is already singular; any other `-sis` word the rules leave alone. */
|
|
197
|
+
type SingularizeSis<S extends string, A extends string> = EndsWith<A, SisStem> extends true ? S : Unresolved;
|
|
198
|
+
/** `(agend|…)a$` -> `um` and `(apheli|…)a$` -> `on`, both read as endings. */
|
|
199
|
+
type SingularizeA<A extends string> = EndsWith<A, AToOnStem> extends true ? `${A}on` : EndsWith<A, AToUmStem> extends true ? `${A}um` : Unresolved;
|
|
200
|
+
/** `…ies` -> `y`, `ie` or `ey`, following `pluralize`'s three competing `ies` rules. */
|
|
201
|
+
type SingularizeIes<S extends string, A extends string> = Lowercase<A> extends EyWholeStem ? `${A}ey` : Lowercase<A> extends IeWholeStem ? `${A}ie` : EndsWith<S, 'ss'> extends true ? S : `${A}y`;
|
|
202
|
+
/**
|
|
203
|
+
* The `…ses` fork. `(analy|…)(?:sis|ses)$` restores that family's `sis`; anything else ending
|
|
204
|
+
* in `ses` is an ordinary `es` plural (`houses`, `roses`, `statuses`) and is handed on.
|
|
205
|
+
*/
|
|
206
|
+
type SingularizeSes<S extends string, A extends string> = EndsWith<A, SisStem> extends true ? `${A}sis` : S extends `${infer B}es` ? SingularizeEs<S, B> : Unresolved;
|
|
207
|
+
/** The `…ves` fork: `f`/`fe` for the listed stems, an ordinary `e` for everything else. */
|
|
208
|
+
type SingularizeVes<A extends string> = Lowercase<A> extends LiWholeStem ? `${A}fe` : EndsWith<A, VesToFeStem> extends true ? `${A}fe` : EndsWith<A, VesToFStem> extends true ? `${A}f` : `${A}ve`;
|
|
209
|
+
/** The `…ices` fork: `ex`, `ix`, or — for `invoices` and its like — an ordinary `e`. */
|
|
210
|
+
type SingularizeIces<A extends string> = EndsWith<A, IcesToExStem> extends true ? `${A}ex` : EndsWith<A, IcesToIxStem> extends true ? `${A}ix` : `${A}ice`;
|
|
211
|
+
/** The `…es` fork: strip `es` for the stems that call for it, else drop the trailing `s`. */
|
|
212
|
+
type SingularizeEs<S extends string, A extends string> = EndsWith<A, EsStem | EsClassStem> extends true ? A : EndsWith<S, UndecidedSingularEnding> extends true ? Unresolved : `${A}e`;
|
|
213
|
+
/** `([^aeiouy]|qu)y$` -> `ies`. A vowel before the `y` keeps it: `days`, not `daies`. */
|
|
214
|
+
type ConsonantBeforeY = Exclude<Letter, Vowel | 'y'>;
|
|
215
|
+
/** `(x|ch|ss|sh|zz)$` and `(alias|t[lm]as|gas|ris)$`, both -> `es`. */
|
|
216
|
+
type PluralEsStem = 'x' | 'ch' | 'ss' | 'sh' | 'zz' | 'alias' | 'gas' | 'ris' | `t${'l' | 'm'}as`;
|
|
217
|
+
/** `(her|at|gr)o$` -> `oes`. */
|
|
218
|
+
type OesStem = 'hero' | 'ato' | 'gro';
|
|
219
|
+
/** `(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$` -> `ices`. */
|
|
220
|
+
type IcesStem = 'matr' | 'cod' | 'mur' | 'sil' | 'vert' | 'ind' | 'append';
|
|
221
|
+
/** `(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$` -> `ves`. */
|
|
222
|
+
type FToVesStem = 'ar' | 'l' | 'ea' | 'eo' | 'oa' | 'hoo';
|
|
223
|
+
type FeToVesStem = 'kni' | 'wi' | 'li';
|
|
224
|
+
/** `(apheli|…|criteri|organ|…|automat)(?:a|on)$` -> `a`. */
|
|
225
|
+
type OnToAStem = 'apheli' | 'hyperbat' | 'periheli' | 'asyndet' | 'noumen' | 'phenomen' | 'criteri' | 'organ' | 'prolegomen' | 'hedr' | 'automat';
|
|
226
|
+
/** `(alumn|syllab|vir|…|strat)(?:us|i)$` -> `i`, which outranks the `[^aou]us` -> `es` rule. */
|
|
227
|
+
type UsToIStem = 'alumn' | 'syllab' | 'vir' | 'radi' | 'nucle' | 'fung' | 'cact' | 'stimul' | 'termin' | 'bacill' | 'foc' | 'uter' | 'loc' | 'strat';
|
|
228
|
+
/** `(seraph|cherub)(?:im)?$` -> `im`. */
|
|
229
|
+
type ImStem = 'seraph' | 'cherub';
|
|
230
|
+
/**
|
|
231
|
+
* Endings `pluralize` handles with rules these types do not reproduce: the Latin `-a`/`-um`
|
|
232
|
+
* and `-ae` stems, the `([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$` rule that leaves `atlas`
|
|
233
|
+
* alone, `(ax|test)is$`, and `eaux$`. Left unresolved, not guessed.
|
|
234
|
+
*/
|
|
235
|
+
type UndecidedPluralEnding = 'ae' | 'i' | 'ias' | 'las' | `${'i' | 'u'}am` | 'eaux';
|
|
236
|
+
/**
|
|
237
|
+
* The plural of a table key, as `pluralize.plural` would return it — or `string` where these
|
|
238
|
+
* rules decline to decide. A key that is already plural comes back unchanged, because
|
|
239
|
+
* `pluralize`'s base rule is `s?$` -> `s` rather than a bare append.
|
|
240
|
+
*/
|
|
241
|
+
type Pluralize<S extends string> = Lowercase<S> extends Uncountable ? Lowercase<S> : EndsWith<S, UncountableEnding> extends true ? S : Lowercase<S> extends keyof IrregularPlurals ? IrregularPlurals[Lowercase<S>] : Lowercase<S> extends keyof IrregularSingulars ? Lowercase<S> : Lowercase<S> extends keyof LatinSingulars ? Lowercase<S> : S extends `${infer A}m${'a' | 'e'}n` ? `${A}men` : S extends `${infer A}${'ix' | 'ex'}` ? PluralizeIxEx<S, A> : S extends `${infer A}${'i' | 'e' | 'o'}${'l' | 'n'}ey` ? PluralizeEy<S, A> : S extends `${infer A}${ConsonantBeforeY}y` ? PluralizeY<S, A> : S extends `${infer A}fe` ? PluralizeFe<S, A> : S extends `${infer A}f` ? PluralizeF<S, A> : S extends `${infer A}sis` ? `${A}ses` : S extends `${infer A}on` ? PluralizeOn<S, A> : S extends `${infer A}um` ? PluralizeUm<A> : S extends `${infer A}a` ? PluralizeA<A> : S extends `${infer A}is` ? PluralizeIs<A> : S extends `${infer A}us` ? PluralizeUs<S, A> : EndsWith<S, ImStem> extends true ? `${S}im` : EndsWith<S, UndecidedPluralEnding> extends true ? Unresolved : EndsWith<S, OesStem> extends true ? `${S}es` : EndsWith<S, PluralEsStem> extends true ? `${S}es` : S extends `${infer A}s` ? `${A}s` : `${S}s`;
|
|
242
|
+
/** Re-attaches the consonant the ending split off, so `category` -> `categories`. */
|
|
243
|
+
type PluralizeY<S extends string, A extends string> = S extends `${A}${infer C}y` ? `${A}${C}ies` : Unresolved;
|
|
244
|
+
/** `([^ch][ieo][ln])ey$` -> `ies`; any other `-ey` word falls through to the `y` rules. */
|
|
245
|
+
type PluralizeEy<S extends string, A extends string> = EndsWith<A, Exclude<Letter, 'c' | 'h'>> extends true ? S extends `${A}${infer Mid}ey` ? `${A}${Mid}ies` : Unresolved : `${S}s`;
|
|
246
|
+
/** `(kni|wi|li)fe$` -> `ves`; any other `-fe` word just takes an `s`. */
|
|
247
|
+
type PluralizeFe<S extends string, A extends string> = EndsWith<A, FeToVesStem> extends true ? `${A}ves` : `${S}s`;
|
|
248
|
+
/** `(ar|l|ea|eo|oa|hoo)f$` -> `ves`; `belief`, `roof` and `chef` take an `s`. */
|
|
249
|
+
type PluralizeF<S extends string, A extends string> = EndsWith<A, FToVesStem> extends true ? `${A}ves` : `${S}s`;
|
|
250
|
+
/** `(matr|cod|…|append)(?:ix|ex)$` -> `ices`; `prefix` and `apex` fall to the `x` -> `es` rule. */
|
|
251
|
+
type PluralizeIxEx<S extends string, A extends string> = EndsWith<A, IcesStem> extends true ? `${A}ices` : `${S}es`;
|
|
252
|
+
/** `(agend|…)um$` -> `a`; `album` and `aquarium` take an `s`. */
|
|
253
|
+
type PluralizeUm<A extends string> = EndsWith<A, AToUmStem> extends true ? `${A}a` : `${A}ums`;
|
|
254
|
+
/** A word already in its Latin `-a` plural stays put; `area` and `villa` take an `s`. */
|
|
255
|
+
type PluralizeA<A extends string> = EndsWith<A, AToUmStem | AToOnStem> extends true ? `${A}a` : `${A}as`;
|
|
256
|
+
/** `(ax|test)is$` -> `es`; every other `-is` word is left undecided. */
|
|
257
|
+
type PluralizeIs<A extends string> = EndsWith<A, AxisStem> extends true ? `${A}es` : Unresolved;
|
|
258
|
+
/** `(criteri|phenomen|…)on$` -> `a`; `session` and `icon` take an `s`. */
|
|
259
|
+
type PluralizeOn<S extends string, A extends string> = EndsWith<A, OnToAStem> extends true ? `${A}a` : `${S}s`;
|
|
260
|
+
/**
|
|
261
|
+
* The two `-us` rules, in priority order: the Latin stems take `i` (`focus` -> `foci`), and
|
|
262
|
+
* `[^aou]us` takes `es` (`bus` -> `buses`, `status` -> `statuses`). A `-us` word that is
|
|
263
|
+
* neither — one with `a`, `o` or `u` before the `us` — just takes an `s`.
|
|
264
|
+
*/
|
|
265
|
+
type PluralizeUs<S extends string, A extends string> = EndsWith<A, UsToIStem> extends true ? `${A}i` : EndsWith<S, `${NotAOU}us`> extends true ? `${S}es` : `${S}s`;
|
|
266
|
+
/**
|
|
267
|
+
* How a build's `typeNameMapper` decides the keys of the generated entity maps.
|
|
268
|
+
*
|
|
269
|
+
* - `false` — no mapper. Every noun is the table key itself and the one-row operations keep
|
|
270
|
+
* their `Single` suffix, which is exactly what these types described before singularization
|
|
271
|
+
* existed.
|
|
272
|
+
* - `'singularize'` — the built-in preset, whose two nouns {@link Singularize} and
|
|
273
|
+
* {@link Pluralize} replicate. The one-row operations take the singular noun and no suffix.
|
|
274
|
+
* - `'loose'` — a mapper function, whose output no type can know. Every noun widens to
|
|
275
|
+
* `string`, so the entity maps fall back to an index signature rather than naming fields the
|
|
276
|
+
* build does not publish.
|
|
277
|
+
*/
|
|
278
|
+
type TypeNaming = 'singularize' | 'loose' | false;
|
|
279
|
+
/** The naming modes whose nouns a type can actually name. */
|
|
280
|
+
type KnownNaming = Exclude<TypeNaming, 'loose'>;
|
|
281
|
+
/** The noun the plural (set-of-rows) operations are named from. */
|
|
282
|
+
type PluralNoun<TNaming extends KnownNaming, TName extends string> = TNaming extends 'singularize' ? Pluralize<TName> : TName;
|
|
283
|
+
/** The noun the singular (one-row) operations and the object type are named from. */
|
|
284
|
+
type SingularNoun<TNaming extends KnownNaming, TName extends string> = TNaming extends 'singularize' ? Singularize<TName> : TName;
|
|
285
|
+
/** The plural noun as a root field name starts — `users` in `usersAggregate`. */
|
|
286
|
+
type LowerPlural<TNaming extends TypeNaming, TName extends string> = TNaming extends 'loose' ? string : Uncapitalize<PluralNoun<Extract<TNaming, KnownNaming>, TName>>;
|
|
287
|
+
/** The plural noun as a field name continues — `Users` in `createUsers`. */
|
|
288
|
+
type UpperPlural<TNaming extends TypeNaming, TName extends string> = TNaming extends 'loose' ? string : Capitalize<PluralNoun<Extract<TNaming, KnownNaming>, TName>>;
|
|
289
|
+
/** The singular noun as a root field name starts — `user` in `user(where:)`. */
|
|
290
|
+
type LowerSingular<TNaming extends TypeNaming, TName extends string> = TNaming extends 'loose' ? string : Uncapitalize<SingularNoun<Extract<TNaming, KnownNaming>, TName>>;
|
|
291
|
+
/** The singular noun as a type or field name continues — `User` in `UserFilters`. */
|
|
292
|
+
type UpperSingular<TNaming extends TypeNaming, TName extends string> = TNaming extends 'loose' ? string : Capitalize<SingularNoun<Extract<TNaming, KnownNaming>, TName>>;
|
|
293
|
+
type SingleSuffix<TNaming extends TypeNaming> = TNaming extends 'singularize' ? '' : TNaming extends 'loose' ? string : 'Single';
|
|
294
|
+
//#endregion
|
|
10
295
|
//#region src/util/extensions.d.ts
|
|
11
296
|
/**
|
|
12
297
|
* The identity a generated field publishes about itself, under `extensions.drizzle`.
|
|
@@ -765,6 +1050,8 @@ type AnyDrizzleDB<TSchema extends Record<string, any>> = PgAsyncDatabase<any, TS
|
|
|
765
1050
|
* The two branches differ in one detail: a module's members are `readonly`, a
|
|
766
1051
|
* relations config's are not, so the derived entity types are `readonly` only on that path.
|
|
767
1052
|
*/
|
|
1053
|
+
/** The Drizzle schema a database handle carries. */
|
|
1054
|
+
type SchemaOf<TDatabase> = TDatabase extends AnyDrizzleDB<infer ISchema> ? ISchema : never;
|
|
768
1055
|
type ExtractTables<TSchema extends Record<string, Table | unknown>> = TSchema extends TablesRelationalConfig ? { [K in keyof TSchema]: TSchema[K]['table'] extends (infer TTable extends Table) ? TTable : never; } : { [K in keyof TSchema as TSchema[K] extends Table ? K : never]: TSchema[K] extends Table ? TSchema[K] : never; };
|
|
769
1056
|
type ExtractRelations<TSchema extends Record<string, Table | unknown>> = { [K in keyof TSchema as TSchema[K] extends Relations ? K : never]: TSchema[K] extends Relations ? TSchema[K] : never; };
|
|
770
1057
|
type ExtractTableRelations<TTable extends Table, TSchemaRelations extends Record<string, Relations>> = { [K in keyof TSchemaRelations as TSchemaRelations[K]['table']['_']['name'] extends TTable['_']['name'] ? K : never]: TSchemaRelations[K]['table']['_']['name'] extends TTable['_']['name'] ? TSchemaRelations[K] extends Relations<any, infer RelationConfig> ? RelationConfig : never : never; };
|
|
@@ -866,8 +1153,8 @@ type DeleteResolver<TTable extends Table, IsReturnless extends boolean> = (sourc
|
|
|
866
1153
|
* out. Throws before writing anything when `where` matches more than one row.
|
|
867
1154
|
*/
|
|
868
1155
|
type DeleteSingleResolver<TTable extends Table, IsReturnless extends boolean> = (source: any, args: DeleteSingleArgs<TTable>, context: any, info: GraphQLResolveInfo) => Promise<IsReturnless extends false ? GetRemappedTableDataType<TTable> | undefined : MutationReturnlessResult>;
|
|
869
|
-
type QueriesCore<TSchemaTables extends Record<string, Table>, TSchemaRelations extends Record<string, Relations>, TInputs extends Record<string, GraphQLInputObjectType>, TOutputs extends Record<string, GraphQLObjectType
|
|
870
|
-
type: GraphQLNonNull<GraphQLList<GraphQLNonNull<TOutputs[
|
|
1156
|
+
type QueriesCore<TSchemaTables extends Record<string, Table>, TSchemaRelations extends Record<string, Relations>, TInputs extends Record<string, GraphQLInputObjectType>, TOutputs extends Record<string, GraphQLObjectType>, TNaming extends TypeNaming = false> = { [TName in keyof TSchemaTables as TName extends string ? `${LowerPlural<TNaming, TName>}` : never]: TName extends string ? {
|
|
1157
|
+
type: GraphQLNonNull<GraphQLList<GraphQLNonNull<TOutputs[UpperSingular<TNaming, TName>]>>>;
|
|
871
1158
|
args: {
|
|
872
1159
|
offset: {
|
|
873
1160
|
type: GraphQLScalarType<number, number>;
|
|
@@ -876,120 +1163,120 @@ type QueriesCore<TSchemaTables extends Record<string, Table>, TSchemaRelations e
|
|
|
876
1163
|
type: GraphQLScalarType<number, number>;
|
|
877
1164
|
};
|
|
878
1165
|
orderBy: {
|
|
879
|
-
type: TInputs[`${
|
|
1166
|
+
type: TInputs[`${UpperSingular<TNaming, TName>}OrderBy`] extends GraphQLInputObjectType ? TInputs[`${UpperSingular<TNaming, TName>}OrderBy`] : never;
|
|
880
1167
|
};
|
|
881
1168
|
where: {
|
|
882
|
-
type: TInputs[`${
|
|
1169
|
+
type: TInputs[`${UpperSingular<TNaming, TName>}Filters`] extends GraphQLInputObjectType ? TInputs[`${UpperSingular<TNaming, TName>}Filters`] : never;
|
|
883
1170
|
};
|
|
884
1171
|
distinct: {
|
|
885
1172
|
type: GraphQLList<GraphQLNonNull<GraphQLEnumType>>;
|
|
886
1173
|
};
|
|
887
1174
|
};
|
|
888
1175
|
resolve: SelectResolver<TSchemaTables[TName], TSchemaTables, ExtractTableRelations<TSchemaTables[TName], TSchemaRelations> extends (infer R) ? R[keyof R] : never>;
|
|
889
|
-
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `${
|
|
890
|
-
type: TOutputs[
|
|
1176
|
+
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `${LowerSingular<TNaming, TName>}${SingleSuffix<TNaming>}` : never]: TName extends string ? {
|
|
1177
|
+
type: TOutputs[UpperSingular<TNaming, TName>];
|
|
891
1178
|
args: {
|
|
892
1179
|
offset: {
|
|
893
1180
|
type: GraphQLScalarType<number, number>;
|
|
894
1181
|
};
|
|
895
1182
|
orderBy: {
|
|
896
|
-
type: TInputs[`${
|
|
1183
|
+
type: TInputs[`${UpperSingular<TNaming, TName>}OrderBy`] extends GraphQLInputObjectType ? TInputs[`${UpperSingular<TNaming, TName>}OrderBy`] : never;
|
|
897
1184
|
};
|
|
898
1185
|
where: {
|
|
899
|
-
type: TInputs[`${
|
|
1186
|
+
type: TInputs[`${UpperSingular<TNaming, TName>}Filters`] extends GraphQLInputObjectType ? TInputs[`${UpperSingular<TNaming, TName>}Filters`] : never;
|
|
900
1187
|
};
|
|
901
1188
|
};
|
|
902
1189
|
resolve: SelectSingleResolver<TSchemaTables[TName], TSchemaTables, ExtractTableRelations<TSchemaTables[TName], TSchemaRelations> extends (infer R) ? R[keyof R] : never>;
|
|
903
|
-
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `${
|
|
904
|
-
type: GraphQLNonNull<TOutputs[`${
|
|
1190
|
+
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `${LowerPlural<TNaming, TName>}Aggregate` : never]: TName extends string ? {
|
|
1191
|
+
type: GraphQLNonNull<TOutputs[`${UpperSingular<TNaming, TName>}Aggregate`] extends GraphQLObjectType ? TOutputs[`${UpperSingular<TNaming, TName>}Aggregate`] : GraphQLObjectType>;
|
|
905
1192
|
args: {
|
|
906
1193
|
where: {
|
|
907
|
-
type: TInputs[`${
|
|
1194
|
+
type: TInputs[`${UpperSingular<TNaming, TName>}Filters`] extends GraphQLInputObjectType ? TInputs[`${UpperSingular<TNaming, TName>}Filters`] : never;
|
|
908
1195
|
};
|
|
909
1196
|
};
|
|
910
1197
|
resolve: AggregateResolver<TSchemaTables[TName]>;
|
|
911
1198
|
} : never; };
|
|
912
|
-
type MutationsCore<TSchemaTables extends Record<string, Table>, TInputs extends Record<string, GraphQLInputObjectType>, TOutputs extends Record<string, GraphQLObjectType>, IsReturnless extends boolean> = { [TName in keyof TSchemaTables as TName extends string ? `create${
|
|
913
|
-
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : GraphQLNonNull<GraphQLList<GraphQLNonNull<TOutputs[
|
|
1199
|
+
type MutationsCore<TSchemaTables extends Record<string, Table>, TInputs extends Record<string, GraphQLInputObjectType>, TOutputs extends Record<string, GraphQLObjectType>, IsReturnless extends boolean, TNaming extends TypeNaming = false> = { [TName in keyof TSchemaTables as TName extends string ? `create${UpperPlural<TNaming, TName>}` : never]: TName extends string ? {
|
|
1200
|
+
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : GraphQLNonNull<GraphQLList<GraphQLNonNull<TOutputs[UpperSingular<TNaming, TName>]>>>;
|
|
914
1201
|
args: {
|
|
915
1202
|
values: {
|
|
916
|
-
type: GraphQLNonNull<GraphQLList<GraphQLNonNull<TInputs[`Create${
|
|
1203
|
+
type: GraphQLNonNull<GraphQLList<GraphQLNonNull<TInputs[`Create${UpperSingular<TNaming, TName>}Input`]>>>;
|
|
917
1204
|
};
|
|
918
1205
|
};
|
|
919
1206
|
resolve: InsertArrResolver<TSchemaTables[TName], IsReturnless>;
|
|
920
|
-
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `create${
|
|
921
|
-
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : TOutputs[
|
|
1207
|
+
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `create${UpperSingular<TNaming, TName>}${SingleSuffix<TNaming>}` : never]: TName extends string ? {
|
|
1208
|
+
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : TOutputs[UpperSingular<TNaming, TName>];
|
|
922
1209
|
args: {
|
|
923
1210
|
values: {
|
|
924
|
-
type: GraphQLNonNull<TInputs[`Create${
|
|
1211
|
+
type: GraphQLNonNull<TInputs[`Create${UpperSingular<TNaming, TName>}Input`]>;
|
|
925
1212
|
};
|
|
926
1213
|
};
|
|
927
1214
|
resolve: InsertResolver<TSchemaTables[TName], IsReturnless>;
|
|
928
|
-
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `upsert${
|
|
929
|
-
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : GraphQLNonNull<GraphQLList<GraphQLNonNull<TOutputs[
|
|
1215
|
+
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `upsert${UpperPlural<TNaming, TName>}` : never]?: TName extends string ? {
|
|
1216
|
+
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : GraphQLNonNull<GraphQLList<GraphQLNonNull<TOutputs[UpperSingular<TNaming, TName>]>>>;
|
|
930
1217
|
args: {
|
|
931
1218
|
values: {
|
|
932
|
-
type: GraphQLNonNull<GraphQLList<GraphQLNonNull<TInputs[`Create${
|
|
1219
|
+
type: GraphQLNonNull<GraphQLList<GraphQLNonNull<TInputs[`Create${UpperSingular<TNaming, TName>}Input`]>>>;
|
|
933
1220
|
};
|
|
934
1221
|
onConflict: {
|
|
935
1222
|
type: GraphQLInputObjectType;
|
|
936
1223
|
};
|
|
937
1224
|
};
|
|
938
1225
|
resolve: UpsertArrResolver<TSchemaTables[TName], IsReturnless>;
|
|
939
|
-
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `upsert${
|
|
940
|
-
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : TOutputs[
|
|
1226
|
+
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `upsert${UpperSingular<TNaming, TName>}${SingleSuffix<TNaming>}` : never]?: TName extends string ? {
|
|
1227
|
+
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : TOutputs[UpperSingular<TNaming, TName>];
|
|
941
1228
|
args: {
|
|
942
1229
|
values: {
|
|
943
|
-
type: GraphQLNonNull<TInputs[`Create${
|
|
1230
|
+
type: GraphQLNonNull<TInputs[`Create${UpperSingular<TNaming, TName>}Input`]>;
|
|
944
1231
|
};
|
|
945
1232
|
onConflict: {
|
|
946
1233
|
type: GraphQLInputObjectType;
|
|
947
1234
|
};
|
|
948
1235
|
};
|
|
949
1236
|
resolve: UpsertResolver<TSchemaTables[TName], IsReturnless>;
|
|
950
|
-
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `update${
|
|
951
|
-
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : GraphQLNonNull<GraphQLList<GraphQLNonNull<TOutputs[
|
|
1237
|
+
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `update${UpperPlural<TNaming, TName>}` : never]: TName extends string ? {
|
|
1238
|
+
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : GraphQLNonNull<GraphQLList<GraphQLNonNull<TOutputs[UpperSingular<TNaming, TName>]>>>;
|
|
952
1239
|
args: {
|
|
953
1240
|
set: {
|
|
954
|
-
type: GraphQLNonNull<TInputs[`Update${
|
|
1241
|
+
type: GraphQLNonNull<TInputs[`Update${UpperSingular<TNaming, TName>}Input`]>;
|
|
955
1242
|
};
|
|
956
1243
|
where: {
|
|
957
|
-
type: TInputs[`${
|
|
1244
|
+
type: TInputs[`${UpperSingular<TNaming, TName>}Filters`] extends GraphQLInputObjectType ? TInputs[`${UpperSingular<TNaming, TName>}Filters`] : never;
|
|
958
1245
|
};
|
|
959
1246
|
};
|
|
960
1247
|
resolve: UpdateResolver<TSchemaTables[TName], IsReturnless>;
|
|
961
|
-
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `update${
|
|
962
|
-
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : GraphQLNonNull<GraphQLList<TOutputs[
|
|
1248
|
+
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `update${UpperPlural<TNaming, TName>}Many` : never]: TName extends string ? {
|
|
1249
|
+
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : GraphQLNonNull<GraphQLList<TOutputs[UpperSingular<TNaming, TName>]>>;
|
|
963
1250
|
args: {
|
|
964
1251
|
updates: {
|
|
965
|
-
type: GraphQLNonNull<GraphQLList<GraphQLNonNull<TInputs[`Update${
|
|
1252
|
+
type: GraphQLNonNull<GraphQLList<GraphQLNonNull<TInputs[`Update${UpperSingular<TNaming, TName>}ManyInput`]>>>;
|
|
966
1253
|
};
|
|
967
1254
|
};
|
|
968
1255
|
resolve: UpdateManyResolver<TSchemaTables[TName], IsReturnless>;
|
|
969
|
-
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `update${
|
|
970
|
-
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : TOutputs[
|
|
1256
|
+
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `update${UpperSingular<TNaming, TName>}${SingleSuffix<TNaming>}` : never]: TName extends string ? {
|
|
1257
|
+
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : TOutputs[UpperSingular<TNaming, TName>];
|
|
971
1258
|
args: {
|
|
972
1259
|
set: {
|
|
973
|
-
type: GraphQLNonNull<TInputs[`Update${
|
|
1260
|
+
type: GraphQLNonNull<TInputs[`Update${UpperSingular<TNaming, TName>}Input`]>;
|
|
974
1261
|
};
|
|
975
1262
|
where: {
|
|
976
|
-
type: GraphQLNonNull<TInputs[`${
|
|
1263
|
+
type: GraphQLNonNull<TInputs[`${UpperSingular<TNaming, TName>}Filters`] extends GraphQLInputObjectType ? TInputs[`${UpperSingular<TNaming, TName>}Filters`] : never>;
|
|
977
1264
|
};
|
|
978
1265
|
};
|
|
979
1266
|
resolve: UpdateSingleResolver<TSchemaTables[TName], IsReturnless>;
|
|
980
|
-
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `delete${
|
|
981
|
-
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : GraphQLNonNull<GraphQLList<GraphQLNonNull<TOutputs[
|
|
1267
|
+
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `delete${UpperPlural<TNaming, TName>}` : never]: TName extends string ? {
|
|
1268
|
+
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : GraphQLNonNull<GraphQLList<GraphQLNonNull<TOutputs[UpperSingular<TNaming, TName>]>>>;
|
|
982
1269
|
args: {
|
|
983
1270
|
where: {
|
|
984
|
-
type: TInputs[`${
|
|
1271
|
+
type: TInputs[`${UpperSingular<TNaming, TName>}Filters`] extends GraphQLInputObjectType ? TInputs[`${UpperSingular<TNaming, TName>}Filters`] : never;
|
|
985
1272
|
};
|
|
986
1273
|
};
|
|
987
1274
|
resolve: DeleteResolver<TSchemaTables[TName], IsReturnless>;
|
|
988
|
-
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `delete${
|
|
989
|
-
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : TOutputs[
|
|
1275
|
+
} : never; } & { [TName in keyof TSchemaTables as TName extends string ? `delete${UpperSingular<TNaming, TName>}${SingleSuffix<TNaming>}` : never]: TName extends string ? {
|
|
1276
|
+
type: IsReturnless extends true ? TOutputs['MutationReturn'] extends GraphQLObjectType ? TOutputs['MutationReturn'] : never : TOutputs[UpperSingular<TNaming, TName>];
|
|
990
1277
|
args: {
|
|
991
1278
|
where: {
|
|
992
|
-
type: GraphQLNonNull<TInputs[`${
|
|
1279
|
+
type: GraphQLNonNull<TInputs[`${UpperSingular<TNaming, TName>}Filters`] extends GraphQLInputObjectType ? TInputs[`${UpperSingular<TNaming, TName>}Filters`] : never>;
|
|
993
1280
|
};
|
|
994
1281
|
};
|
|
995
1282
|
resolve: DeleteSingleResolver<TSchemaTables[TName], IsReturnless>;
|
|
@@ -1003,7 +1290,7 @@ type MutationsCore<TSchemaTables extends Record<string, Table>, TInputs extends
|
|
|
1003
1290
|
* enabled — `${Table}OnConflict` for upsert, `${Table}Having` for group-by — are not listed,
|
|
1004
1291
|
* since whether they were generated is a runtime decision.
|
|
1005
1292
|
*/
|
|
1006
|
-
type GeneratedInputs<TSchema extends Record<string, Table
|
|
1293
|
+
type GeneratedInputs<TSchema extends Record<string, Table>, TNaming extends TypeNaming = false> = { [TName in keyof TSchema as TName extends string ? `Create${UpperSingular<TNaming, TName>}Input` : never]: GraphQLInputObjectType; } & { [TName in keyof TSchema as TName extends string ? `Update${UpperSingular<TNaming, TName>}Input` : never]: GraphQLInputObjectType; } & { [TName in keyof TSchema as TName extends string ? `Update${UpperSingular<TNaming, TName>}ManyInput` : never]: GraphQLInputObjectType; } & { [TName in keyof TSchema as TName extends string ? `${UpperSingular<TNaming, TName>}OrderBy` : never]: GraphQLInputObjectType; } & { [TName in keyof TSchema as TName extends string ? `${UpperSingular<TNaming, TName>}Filters` : never]: GraphQLInputObjectType; };
|
|
1007
1294
|
/**
|
|
1008
1295
|
* Keys of `entities.types`, which is keyed by generated GraphQL type name.
|
|
1009
1296
|
*
|
|
@@ -1012,12 +1299,12 @@ type GeneratedInputs<TSchema extends Record<string, Table>> = { [TName in keyof
|
|
|
1012
1299
|
* type kept those names long after the generator stopped producing them. MySQL still has a
|
|
1013
1300
|
* shared `MutationReturn` instead of per-table return types, because its writes return no rows.
|
|
1014
1301
|
*/
|
|
1015
|
-
type GeneratedOutputs<TSchema extends Record<string, Table>, IsReturnless extends boolean> = { [TName in keyof TSchema as TName extends string ?
|
|
1302
|
+
type GeneratedOutputs<TSchema extends Record<string, Table>, IsReturnless extends boolean, TNaming extends TypeNaming = false> = { [TName in keyof TSchema as TName extends string ? UpperSingular<TNaming, TName> : never]: GraphQLObjectType; } & { [TName in keyof TSchema as TName extends string ? `${UpperSingular<TNaming, TName>}Aggregate` : never]: GraphQLObjectType; } & (IsReturnless extends true ? {
|
|
1016
1303
|
MutationReturn: GraphQLObjectType;
|
|
1017
|
-
} : { [TName in keyof TSchema as TName extends string ?
|
|
1018
|
-
type GeneratedEntities<TDatabase extends AnyDrizzleDB<TSchema>, TSchema extends Record<string, unknown> = TDatabase
|
|
1019
|
-
queries: QueriesCore<TSchemaTables, TSchemaRelations, TInputs, TOutputs>;
|
|
1020
|
-
mutations: MutationsCore<TSchemaTables, TInputs, TOutputs, TDatabase extends MySqlAsyncDatabase<any, any> ? true : false>;
|
|
1304
|
+
} : { [TName in keyof TSchema as TName extends string ? UpperSingular<TNaming, TName> : never]: GraphQLObjectType; });
|
|
1305
|
+
type GeneratedEntities<TDatabase extends AnyDrizzleDB<TSchema>, TSchema extends Record<string, unknown> = SchemaOf<TDatabase>, TSchemaTables extends ExtractTables<TSchema> = ExtractTables<TSchema>, TSchemaRelations extends ExtractRelations<TSchema> = ExtractRelations<TSchema>, TNaming extends TypeNaming = false, TInputs extends GeneratedInputs<TSchemaTables, TNaming> = GeneratedInputs<TSchemaTables, TNaming>, TOutputs extends GeneratedOutputs<TSchemaTables, TDatabase extends MySqlAsyncDatabase<any, any> ? true : false, TNaming> = GeneratedOutputs<TSchemaTables, TDatabase extends MySqlAsyncDatabase<any, any> ? true : false, TNaming>> = {
|
|
1306
|
+
queries: QueriesCore<TSchemaTables, TSchemaRelations, TInputs, TOutputs, TNaming>;
|
|
1307
|
+
mutations: MutationsCore<TSchemaTables, TInputs, TOutputs, TDatabase extends MySqlAsyncDatabase<any, any> ? true : false, TNaming>;
|
|
1021
1308
|
inputs: TInputs;
|
|
1022
1309
|
types: TOutputs;
|
|
1023
1310
|
/**
|
|
@@ -1028,10 +1315,24 @@ type GeneratedEntities<TDatabase extends AnyDrizzleDB<TSchema>, TSchema extends
|
|
|
1028
1315
|
*/
|
|
1029
1316
|
fieldResolvers: { [TName in keyof TSchemaTables as TName extends string ? TName : never]?: Record<string, (source: any, args: any, context: any, info: GraphQLResolveInfo) => Promise<any>>; };
|
|
1030
1317
|
};
|
|
1031
|
-
type GeneratedData<TDatabase extends AnyDrizzleDB<any
|
|
1318
|
+
type GeneratedData<TDatabase extends AnyDrizzleDB<any>, TNaming extends TypeNaming = false> = {
|
|
1032
1319
|
schema: GraphQLSchema;
|
|
1033
|
-
entities: GeneratedEntities<TDatabase>;
|
|
1320
|
+
entities: GeneratedEntities<TDatabase, SchemaOf<TDatabase>, ExtractTables<SchemaOf<TDatabase>>, ExtractRelations<SchemaOf<TDatabase>>, TNaming>;
|
|
1034
1321
|
};
|
|
1322
|
+
/**
|
|
1323
|
+
* The naming mode a `buildSchema` config selects, which decides how {@link GeneratedEntities}
|
|
1324
|
+
* keys its maps.
|
|
1325
|
+
*
|
|
1326
|
+
* Read off the config's *static* type, so it answers only for a config written inline (or
|
|
1327
|
+
* `as const`): a `typeNameMapper` assigned through a variable of type
|
|
1328
|
+
* {@link BuildSchemaConfig} is invisible here and keys as if there were no mapper, the same
|
|
1329
|
+
* way these types behaved before singularization existed.
|
|
1330
|
+
*/
|
|
1331
|
+
type NamingOf<TConfig> = TConfig extends {
|
|
1332
|
+
typeNameMapper: 'singularize';
|
|
1333
|
+
} ? 'singularize' : TConfig extends {
|
|
1334
|
+
typeNameMapper: (...args: any[]) => any;
|
|
1335
|
+
} ? 'loose' : false;
|
|
1035
1336
|
/**
|
|
1036
1337
|
* A feature switch. `true` / `false` decides for the whole build; a predicate decides per
|
|
1037
1338
|
* table, receiving the table's key in the Drizzle schema.
|
|
@@ -1418,6 +1719,15 @@ type BuildSchemaConfig = {
|
|
|
1418
1719
|
/**
|
|
1419
1720
|
* Customizes query name suffixes for generated GraphQL operations.
|
|
1420
1721
|
*
|
|
1722
|
+
* Both reach every operation that comes in a list/single pair, mutations included. The
|
|
1723
|
+
* variants that carry their own disambiguator — `<plural>Aggregate`, `<plural>GroupBy`,
|
|
1724
|
+
* `update<Table>Many`, `update<Table>Count`, `delete<Table>Count` — take neither.
|
|
1725
|
+
*
|
|
1726
|
+
* The two cannot be the same string unless a {@link BuildSchemaConfig.typeNameMapper} is
|
|
1727
|
+
* also configured: without one both nouns are the table key, so the pair would collapse
|
|
1728
|
+
* onto a single field name. With one, the mapper's singular/plural forms separate every
|
|
1729
|
+
* pair on their own and the single side takes no suffix at all — see `typeNameMapper`.
|
|
1730
|
+
*
|
|
1421
1731
|
* @default { list: '', single: 'Single' }
|
|
1422
1732
|
*/
|
|
1423
1733
|
suffixes?: {
|
|
@@ -1790,8 +2100,15 @@ type BuildSchemaConfig = {
|
|
|
1790
2100
|
* Return `undefined` for tables that should use the default naming.
|
|
1791
2101
|
*
|
|
1792
2102
|
* Example: `(name) => name === 'users' ? { singular: 'user', plural: 'users' } : undefined`
|
|
1793
|
-
* produces type `User`, queries `users` / `user`, mutations `createUsers` / `createUser
|
|
1794
|
-
*
|
|
2103
|
+
* produces type `User`, queries `users` / `user`, mutations `createUsers` / `createUser`,
|
|
2104
|
+
* `updateUsers` / `updateUser` and `deleteUsers` / `deleteUser` for the `users` table, and
|
|
2105
|
+
* leaves other tables with their default names.
|
|
2106
|
+
*
|
|
2107
|
+
* The noun is what separates a mapped table's pairs — plural on the form that operates on
|
|
2108
|
+
* a set of rows, singular on the one that operates on exactly one — so a mapped table's
|
|
2109
|
+
* operations carry no `Single` suffix, whatever {@link BuildSchemaConfig.suffixes} says.
|
|
2110
|
+
* A table the mapper returns `undefined` for is back on the default naming, where
|
|
2111
|
+
* `suffixes.single` is the only thing separating its pairs.
|
|
1795
2112
|
*
|
|
1796
2113
|
* Pass the string `'singularize'` for the built-in preset, which derives both forms of every
|
|
1797
2114
|
* table key with the library's own `pluralize` — the mapper most schemas with plural table
|
|
@@ -1808,6 +2125,12 @@ type BuildSchemaConfig = {
|
|
|
1808
2125
|
* The function half is the exported {@link TypeNameMapper}, so a mapper can be declared once
|
|
1809
2126
|
* and handed both to `buildSchema` and to `selectionToWith` / `resolveSelection`, which need
|
|
1810
2127
|
* the same naming rule to read a selection back out of a schema built with it.
|
|
2128
|
+
*
|
|
2129
|
+
* `entities` is keyed to match, when the config is written inline so its type is visible:
|
|
2130
|
+
* the preset's two nouns are replicated at the type level, so `entities.queries.task`
|
|
2131
|
+
* autocompletes. A mapper *function* renames types in a way no type can predict, so those
|
|
2132
|
+
* maps fall back to an index signature rather than naming fields the build does not
|
|
2133
|
+
* publish — see {@link NamingOf}.
|
|
1811
2134
|
*/
|
|
1812
2135
|
typeNameMapper?: 'singularize' | TypeNameMapper;
|
|
1813
2136
|
/**
|
|
@@ -2174,7 +2497,7 @@ type ResolveSelectionOptions = SelectionOptions & {
|
|
|
2174
2497
|
declare const resolveSelection: (info: GraphQLResolveInfo | ResolveTree, options: ResolveSelectionOptions) => Promise<any>;
|
|
2175
2498
|
//#endregion
|
|
2176
2499
|
//#region src/index.d.ts
|
|
2177
|
-
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any
|
|
2500
|
+
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>, TConfig extends BuildSchemaConfig = BuildSchemaConfig>(db: TDbClient, config?: TConfig) => GeneratedData<TDbClient, NamingOf<TConfig>>;
|
|
2178
2501
|
//#endregion
|
|
2179
|
-
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type ContextValuesConfig, type DefaultOrderByEntry, type DefaultsConfig, type DeleteResolver, type DeleteSingleResolver, type DerivedTypeNameMapper, type DrizzleErrorCode, type DrizzleErrorContext, type DrizzleExtension, type DrizzleFieldExtension, type DrizzleFieldKind, type DrizzleFieldOperation, type DrizzleTargetArg, type DrizzleTypeExtension, type EnumNameInfo, type EnumNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type FeatureSwitch, type FieldsByTypeName, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, type GeneratedTypeInfo, type GeneratedTypeKind, GraphQLBigIntString, GraphQLDate, GraphQLDateTime, GraphQLDecimalString, GraphQLJSON, GraphQLUUID, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type OnWriteConfig, type ParseResolveInfoOptions, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type ResolveTree, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type SoftDeleteColumn, type SoftDeleteConfig, type TableDefaults, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type TypeNameMapper, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, type WriteHook, type WriteHookPayload, type WriteHookPositions, type WriteHooks, type WriteOperation, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleError, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, parseResolveInfo, resolveSelection, selectionToWith, singularizeMapper };
|
|
2502
|
+
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type ContextValuesConfig, type DefaultOrderByEntry, type DefaultsConfig, type DeleteResolver, type DeleteSingleResolver, type DerivedTypeNameMapper, type DrizzleErrorCode, type DrizzleErrorContext, type DrizzleExtension, type DrizzleFieldExtension, type DrizzleFieldKind, type DrizzleFieldOperation, type DrizzleTargetArg, type DrizzleTypeExtension, type EnumNameInfo, type EnumNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type FeatureSwitch, type FieldsByTypeName, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, type GeneratedTypeInfo, type GeneratedTypeKind, GraphQLBigIntString, GraphQLDate, GraphQLDateTime, GraphQLDecimalString, GraphQLJSON, GraphQLUUID, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type NamingOf, type OnWriteConfig, type ParseResolveInfoOptions, type Pluralize, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type ResolveTree, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type Singularize, type SoftDeleteColumn, type SoftDeleteConfig, type TableDefaults, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type TypeNameMapper, type TypeNaming, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, type WriteHook, type WriteHookPayload, type WriteHookPositions, type WriteHooks, type WriteOperation, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleError, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, parseResolveInfo, resolveSelection, selectionToWith, singularizeMapper };
|
|
2180
2503
|
//# sourceMappingURL=index.d.ts.map
|