graphile-simple-inflector 0.1.1 → 0.1.3
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/LICENSE +3 -1
- package/README.md +28 -7
- package/index.js +333 -0
- package/package.json +26 -43
- package/main/index.js +0 -402
- package/module/index.js +0 -384
package/LICENSE
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
|
|
4
|
+
Copyright (c) 2025 Hyperweb <developers@hyperweb.io>
|
|
5
|
+
Copyright (c) 2020-present, Interweb, Inc.
|
|
4
6
|
|
|
5
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
8
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
|
-
# graphile-simple-inflector
|
|
1
|
+
# graphile-simple-inflector
|
|
2
|
+
|
|
3
|
+
Simplified naming inflector for Graphile/PostGraphile. It shortens common field names (e.g. `tableByNodeId` → `table`) and makes pluralization behave more predictably for numeric suffixes.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
2
6
|
|
|
3
7
|
```sh
|
|
4
|
-
|
|
8
|
+
pnpm add graphile-simple-inflector
|
|
5
9
|
```
|
|
6
10
|
|
|
7
|
-
|
|
11
|
+
When using PostGraphile:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import PgSimpleInflector from 'graphile-simple-inflector';
|
|
15
|
+
|
|
16
|
+
createPostGraphileSchema(pool, ['app_public'], {
|
|
17
|
+
appendPlugins: [PgSimpleInflector],
|
|
18
|
+
graphileBuildOptions: {
|
|
19
|
+
pgSimplifyPatch: true,
|
|
20
|
+
pgSimplifyAllRows: true
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Testing
|
|
26
|
+
|
|
27
|
+
Tests expect a running PostgreSQL instance (see `utils/env.ts` for defaults). Seed the test database with the provided fixtures or let the test harness create them automatically:
|
|
8
28
|
|
|
9
29
|
```sh
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
30
|
+
psql -U postgres -f sql/roles.sql postgres
|
|
31
|
+
pnpm test --filter graphile-simple-inflector
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The included SQL under `sql/` matches the original package’s fixtures.
|
package/index.js
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PgSimpleInflector = void 0;
|
|
4
|
+
const fixCapitalisedPlural = (fn) => function capitalisedPlural(str) {
|
|
5
|
+
const original = fn.call(this, str);
|
|
6
|
+
return original.replace(/[0-9]S(?=[A-Z]|$)/g, (match) => match.toLowerCase());
|
|
7
|
+
};
|
|
8
|
+
const fixChangePlural = (fn) => function changePlural(str) {
|
|
9
|
+
const matches = str.match(/([A-Z]|_[a-z0-9])[a-z0-9]*_*$/);
|
|
10
|
+
const index = matches ? (matches.index ?? 0) + matches[1].length - 1 : 0;
|
|
11
|
+
const suffixMatches = str.match(/_*$/);
|
|
12
|
+
const suffixIndex = suffixMatches && suffixMatches.index !== undefined ? suffixMatches.index : str.length;
|
|
13
|
+
const prefix = str.slice(0, index);
|
|
14
|
+
const word = str.slice(index, suffixIndex);
|
|
15
|
+
const suffix = str.slice(suffixIndex);
|
|
16
|
+
return `${prefix}${fn.call(this, word)}${suffix}`;
|
|
17
|
+
};
|
|
18
|
+
const DEFAULT_NODE_ID = 'nodeId';
|
|
19
|
+
const PgSimpleInflector = (builder, { pgSimpleCollections, pgOmitListSuffix, pgSimplifyPatch = true, pgSimplifyAllRows = true, pgShortPk = true, pgSimplifyMultikeyRelations = true, pgSimplifyOppositeBaseNames = true, nodeIdFieldName = DEFAULT_NODE_ID, } = {}) => {
|
|
20
|
+
const hasConnections = pgSimpleCollections !== 'only';
|
|
21
|
+
const hasSimpleCollections = pgSimpleCollections === 'only' || pgSimpleCollections === 'both';
|
|
22
|
+
if (hasSimpleCollections &&
|
|
23
|
+
!hasConnections &&
|
|
24
|
+
pgOmitListSuffix !== true &&
|
|
25
|
+
pgOmitListSuffix !== false) {
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
27
|
+
console.warn('You can simplify the inflector further by adding `{graphileBuildOptions: {pgOmitListSuffix: true}}` to the options passed to PostGraphile, however be aware that doing so will mean that later enabling relay connections will be a breaking change. To dismiss this message, set `pgOmitListSuffix` to false instead.');
|
|
28
|
+
}
|
|
29
|
+
const connectionSuffix = pgOmitListSuffix ? '-connection' : '';
|
|
30
|
+
const ConnectionSuffix = pgOmitListSuffix ? 'Connection' : '';
|
|
31
|
+
const listSuffix = pgOmitListSuffix ? '' : '-list';
|
|
32
|
+
const ListSuffix = pgOmitListSuffix ? '' : 'List';
|
|
33
|
+
builder.hook('inflection', (oldInflection) => {
|
|
34
|
+
const inflection = {
|
|
35
|
+
...oldInflection,
|
|
36
|
+
/*
|
|
37
|
+
* This solves the issue with `blah-table1s` becoming `blahTable1S`
|
|
38
|
+
* (i.e. the capital S at the end) or `table1-connection becoming `Table1SConnection`
|
|
39
|
+
*/
|
|
40
|
+
camelCase: fixCapitalisedPlural(oldInflection.camelCase),
|
|
41
|
+
upperCamelCase: fixCapitalisedPlural(oldInflection.upperCamelCase),
|
|
42
|
+
/*
|
|
43
|
+
* Pluralize/singularize only supports single words, so only run
|
|
44
|
+
* on the final segment of a name.
|
|
45
|
+
*/
|
|
46
|
+
pluralize: fixChangePlural(oldInflection.pluralize),
|
|
47
|
+
singularize: fixChangePlural(oldInflection.singularize),
|
|
48
|
+
distinctPluralize(str) {
|
|
49
|
+
const singular = this.singularize(str);
|
|
50
|
+
const plural = this.pluralize(singular);
|
|
51
|
+
if (singular !== plural) {
|
|
52
|
+
return plural;
|
|
53
|
+
}
|
|
54
|
+
if (plural.endsWith('ch') ||
|
|
55
|
+
plural.endsWith('s') ||
|
|
56
|
+
plural.endsWith('sh') ||
|
|
57
|
+
plural.endsWith('x') ||
|
|
58
|
+
plural.endsWith('z')) {
|
|
59
|
+
return `${plural}es`;
|
|
60
|
+
}
|
|
61
|
+
else if (plural.endsWith('y')) {
|
|
62
|
+
return `${plural.slice(0, -1)}ies`;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return `${plural}s`;
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
// Fix a naming bug
|
|
69
|
+
deletedNodeId(table) {
|
|
70
|
+
return this.camelCase(`deleted-${this.singularize(table.name)}-${nodeIdFieldName}`);
|
|
71
|
+
},
|
|
72
|
+
getBaseName(columnName) {
|
|
73
|
+
const matches = columnName.match(/^(.+?)(_row_id|_id|_uuid|_fk|_pk|RowId|Id|Uuid|UUID|Fk|Pk)$/);
|
|
74
|
+
if (matches) {
|
|
75
|
+
return matches[1];
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
},
|
|
79
|
+
baseNameMatches(baseName, otherName) {
|
|
80
|
+
const singularizedName = this.singularize(otherName);
|
|
81
|
+
return baseName === singularizedName;
|
|
82
|
+
},
|
|
83
|
+
baseNameMatchesAny(baseName, otherName) {
|
|
84
|
+
if (!baseName)
|
|
85
|
+
return false;
|
|
86
|
+
return this.singularize(baseName) === this.singularize(otherName);
|
|
87
|
+
},
|
|
88
|
+
/* This is a good method to override. */
|
|
89
|
+
getOppositeBaseName(baseName) {
|
|
90
|
+
return (pgSimplifyOppositeBaseNames &&
|
|
91
|
+
({
|
|
92
|
+
/*
|
|
93
|
+
* Changes to this list are breaking changes and will require a
|
|
94
|
+
* major version update, so we need to group as many together as
|
|
95
|
+
* possible! Rather than sending a PR, please look for an open
|
|
96
|
+
* issue called something like "Add more opposites" (if there isn't
|
|
97
|
+
* one then please open it) and add your suggestions to the GitHub
|
|
98
|
+
* comments.
|
|
99
|
+
*/
|
|
100
|
+
// NOTE: reason to be careful using this:
|
|
101
|
+
// field names to take into account this particular case (e.g. events with event.parent_id could not have parent OR child fields)
|
|
102
|
+
inviter: 'invitee',
|
|
103
|
+
parent: 'child',
|
|
104
|
+
child: 'parent',
|
|
105
|
+
owner: 'owned',
|
|
106
|
+
author: 'authored',
|
|
107
|
+
editor: 'edited',
|
|
108
|
+
reviewer: 'reviewed',
|
|
109
|
+
}[baseName ?? ''] || null));
|
|
110
|
+
},
|
|
111
|
+
getBaseNameFromKeys(detailedKeys) {
|
|
112
|
+
if (detailedKeys.length === 1) {
|
|
113
|
+
const key = detailedKeys[0];
|
|
114
|
+
const columnName = this._columnName(key);
|
|
115
|
+
return this.getBaseName?.(columnName) ?? null;
|
|
116
|
+
}
|
|
117
|
+
if (pgSimplifyMultikeyRelations) {
|
|
118
|
+
const columnNames = detailedKeys.map((key) => this._columnName(key));
|
|
119
|
+
const baseNames = columnNames.map((columnName) => this.getBaseName?.(columnName) ?? null);
|
|
120
|
+
// Check none are null
|
|
121
|
+
if (baseNames.every((n) => n)) {
|
|
122
|
+
return baseNames.join('-');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
},
|
|
127
|
+
...(pgSimplifyPatch
|
|
128
|
+
? {
|
|
129
|
+
patchField() {
|
|
130
|
+
return 'patch';
|
|
131
|
+
},
|
|
132
|
+
}
|
|
133
|
+
: {}),
|
|
134
|
+
...(pgSimplifyAllRows
|
|
135
|
+
? {
|
|
136
|
+
allRows(table) {
|
|
137
|
+
return this.camelCase(this.distinctPluralize(this._singularizedTableName(table)) + connectionSuffix);
|
|
138
|
+
},
|
|
139
|
+
allRowsSimple(table) {
|
|
140
|
+
return this.camelCase(this.distinctPluralize(this._singularizedTableName(table)) + listSuffix);
|
|
141
|
+
},
|
|
142
|
+
}
|
|
143
|
+
: {}),
|
|
144
|
+
computedColumn(pseudoColumnName, proc) {
|
|
145
|
+
return proc.tags.fieldName
|
|
146
|
+
? `${proc.tags.fieldName}${proc.returnsSet ? ConnectionSuffix : ''}`
|
|
147
|
+
: this.camelCase(pseudoColumnName + (proc.returnsSet ? connectionSuffix : ''));
|
|
148
|
+
},
|
|
149
|
+
computedColumnList(pseudoColumnName, proc) {
|
|
150
|
+
return proc.tags.fieldName
|
|
151
|
+
? `${proc.tags.fieldName}${ListSuffix}`
|
|
152
|
+
: this.camelCase(pseudoColumnName + listSuffix);
|
|
153
|
+
},
|
|
154
|
+
singleRelationByKeys(detailedKeys, table, _foreignTable, constraint) {
|
|
155
|
+
if (constraint.tags.fieldName) {
|
|
156
|
+
return constraint.tags.fieldName;
|
|
157
|
+
}
|
|
158
|
+
const baseName = this.getBaseNameFromKeys(detailedKeys);
|
|
159
|
+
if (constraint.classId === constraint.foreignClassId) {
|
|
160
|
+
if (baseName && this.baseNameMatchesAny?.(baseName, table.name)) {
|
|
161
|
+
return oldInflection.singleRelationByKeys(detailedKeys, table, _foreignTable, constraint);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (baseName) {
|
|
165
|
+
return this.camelCase(baseName);
|
|
166
|
+
}
|
|
167
|
+
if (this.baseNameMatches?.(baseName, table.name)) {
|
|
168
|
+
return this.camelCase(`${this._singularizedTableName(table)}`);
|
|
169
|
+
}
|
|
170
|
+
return oldInflection.singleRelationByKeys(detailedKeys, table, _foreignTable, constraint);
|
|
171
|
+
},
|
|
172
|
+
singleRelationByKeysBackwards(detailedKeys, table, foreignTable, constraint) {
|
|
173
|
+
if (constraint.tags.foreignSingleFieldName) {
|
|
174
|
+
return constraint.tags.foreignSingleFieldName;
|
|
175
|
+
}
|
|
176
|
+
if (constraint.tags.foreignFieldName) {
|
|
177
|
+
return constraint.tags.foreignFieldName;
|
|
178
|
+
}
|
|
179
|
+
const baseName = this.getBaseNameFromKeys(detailedKeys);
|
|
180
|
+
const oppositeBaseName = baseName && this.getOppositeBaseName?.(baseName);
|
|
181
|
+
if (oppositeBaseName) {
|
|
182
|
+
return this.camelCase(`${oppositeBaseName}-${this._singularizedTableName(table)}`);
|
|
183
|
+
}
|
|
184
|
+
if (baseName && this.baseNameMatches?.(baseName, foreignTable.name)) {
|
|
185
|
+
return this.camelCase(`${this._singularizedTableName(table)}`);
|
|
186
|
+
}
|
|
187
|
+
return oldInflection.singleRelationByKeysBackwards(detailedKeys, table, foreignTable, constraint);
|
|
188
|
+
},
|
|
189
|
+
_manyRelationByKeysBase(detailedKeys, table, foreignTable, constraint) {
|
|
190
|
+
const baseName = this.getBaseNameFromKeys(detailedKeys);
|
|
191
|
+
const oppositeBaseName = baseName && this.getOppositeBaseName?.(baseName);
|
|
192
|
+
if (constraint.classId === constraint.foreignClassId) {
|
|
193
|
+
if (baseName && this.baseNameMatches?.(baseName, table.name)) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (oppositeBaseName) {
|
|
198
|
+
return this.camelCase(`${oppositeBaseName}-${this.distinctPluralize(this._singularizedTableName(table))}`);
|
|
199
|
+
}
|
|
200
|
+
if (baseName && this.baseNameMatches?.(baseName, foreignTable.name)) {
|
|
201
|
+
return this.camelCase(`${this.distinctPluralize(this._singularizedTableName(table))}`);
|
|
202
|
+
}
|
|
203
|
+
return null;
|
|
204
|
+
},
|
|
205
|
+
manyRelationByKeys(detailedKeys, table, foreignTable, constraint) {
|
|
206
|
+
if (constraint.tags.foreignFieldName) {
|
|
207
|
+
if (constraint.tags.foreignSimpleFieldName) {
|
|
208
|
+
return constraint.tags.foreignFieldName;
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
return `${constraint.tags.foreignFieldName}${ConnectionSuffix}`;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const base = this._manyRelationByKeysBase?.(detailedKeys, table, foreignTable, constraint);
|
|
215
|
+
if (base) {
|
|
216
|
+
return base + ConnectionSuffix;
|
|
217
|
+
}
|
|
218
|
+
return (oldInflection.manyRelationByKeys(detailedKeys, table, foreignTable, constraint) + ConnectionSuffix);
|
|
219
|
+
},
|
|
220
|
+
manyRelationByKeysSimple(detailedKeys, table, foreignTable, constraint) {
|
|
221
|
+
if (constraint.tags.foreignSimpleFieldName) {
|
|
222
|
+
return constraint.tags.foreignSimpleFieldName;
|
|
223
|
+
}
|
|
224
|
+
if (constraint.tags.foreignFieldName) {
|
|
225
|
+
return `${constraint.tags.foreignFieldName}${ListSuffix}`;
|
|
226
|
+
}
|
|
227
|
+
const base = this._manyRelationByKeysBase?.(detailedKeys, table, foreignTable, constraint);
|
|
228
|
+
if (base) {
|
|
229
|
+
return base + ListSuffix;
|
|
230
|
+
}
|
|
231
|
+
return (oldInflection.manyRelationByKeys(detailedKeys, table, foreignTable, constraint) + ListSuffix);
|
|
232
|
+
},
|
|
233
|
+
functionQueryName(proc) {
|
|
234
|
+
return this.camelCase(this._functionName(proc) + (proc.returnsSet ? connectionSuffix : ''));
|
|
235
|
+
},
|
|
236
|
+
functionQueryNameList(proc) {
|
|
237
|
+
return this.camelCase(this._functionName(proc) + listSuffix);
|
|
238
|
+
},
|
|
239
|
+
...(pgShortPk
|
|
240
|
+
? {
|
|
241
|
+
tableNode(table) {
|
|
242
|
+
return this.camelCase(`${this._singularizedTableName(table)}-by-${nodeIdFieldName}`);
|
|
243
|
+
},
|
|
244
|
+
rowByUniqueKeys(detailedKeys, table, constraint) {
|
|
245
|
+
if (constraint.tags.fieldName) {
|
|
246
|
+
return constraint.tags.fieldName;
|
|
247
|
+
}
|
|
248
|
+
if (constraint.type === 'p') {
|
|
249
|
+
// Primary key, shorten!
|
|
250
|
+
return this.camelCase(this._singularizedTableName(table));
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
return this.camelCase(`${this._singularizedTableName(table)}-by-${detailedKeys
|
|
254
|
+
.map((key) => this.column(key))
|
|
255
|
+
.join('-and-')}`);
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
updateByKeys(detailedKeys, table, constraint) {
|
|
259
|
+
if (constraint.tags.updateFieldName) {
|
|
260
|
+
return constraint.tags.updateFieldName;
|
|
261
|
+
}
|
|
262
|
+
if (constraint.type === 'p') {
|
|
263
|
+
// Primary key, shorten!
|
|
264
|
+
return this.camelCase(`update-${this._singularizedTableName(table)}`);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
return this.camelCase(`update-${this._singularizedTableName(table)}-by-${detailedKeys
|
|
268
|
+
.map((key) => this.column(key))
|
|
269
|
+
.join('-and-')}`);
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
deleteByKeys(detailedKeys, table, constraint) {
|
|
273
|
+
if (constraint.tags.deleteFieldName) {
|
|
274
|
+
return constraint.tags.deleteFieldName;
|
|
275
|
+
}
|
|
276
|
+
if (constraint.type === 'p') {
|
|
277
|
+
// Primary key, shorten!
|
|
278
|
+
return this.camelCase(`delete-${this._singularizedTableName(table)}`);
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
return this.camelCase(`delete-${this._singularizedTableName(table)}-by-${detailedKeys
|
|
282
|
+
.map((key) => this.column(key))
|
|
283
|
+
.join('-and-')}`);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
updateByKeysInputType(detailedKeys, table, constraint) {
|
|
287
|
+
if (constraint.tags.updateFieldName) {
|
|
288
|
+
return this.upperCamelCase(`${constraint.tags.updateFieldName}-input`);
|
|
289
|
+
}
|
|
290
|
+
if (constraint.type === 'p') {
|
|
291
|
+
// Primary key, shorten!
|
|
292
|
+
return this.upperCamelCase(`update-${this._singularizedTableName(table)}-input`);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
return this.upperCamelCase(`update-${this._singularizedTableName(table)}-by-${detailedKeys
|
|
296
|
+
.map((key) => this.column(key))
|
|
297
|
+
.join('-and-')}-input`);
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
deleteByKeysInputType(detailedKeys, table, constraint) {
|
|
301
|
+
if (constraint.tags.deleteFieldName) {
|
|
302
|
+
return this.upperCamelCase(`${constraint.tags.deleteFieldName}-input`);
|
|
303
|
+
}
|
|
304
|
+
if (constraint.type === 'p') {
|
|
305
|
+
// Primary key, shorten!
|
|
306
|
+
return this.upperCamelCase(`delete-${this._singularizedTableName(table)}-input`);
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
return this.upperCamelCase(`delete-${this._singularizedTableName(table)}-by-${detailedKeys
|
|
310
|
+
.map((key) => this.column(key))
|
|
311
|
+
.join('-and-')}-input`);
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
updateNode(table) {
|
|
315
|
+
return this.camelCase(`update-${this._singularizedTableName(table)}-by-${nodeIdFieldName}`);
|
|
316
|
+
},
|
|
317
|
+
deleteNode(table) {
|
|
318
|
+
return this.camelCase(`delete-${this._singularizedTableName(table)}-by-${nodeIdFieldName}`);
|
|
319
|
+
},
|
|
320
|
+
updateNodeInputType(table) {
|
|
321
|
+
return this.upperCamelCase(`update-${this._singularizedTableName(table)}-by-${nodeIdFieldName}-input`);
|
|
322
|
+
},
|
|
323
|
+
deleteNodeInputType(table) {
|
|
324
|
+
return this.upperCamelCase(`delete-${this._singularizedTableName(table)}-by-${nodeIdFieldName}-input`);
|
|
325
|
+
},
|
|
326
|
+
}
|
|
327
|
+
: {}),
|
|
328
|
+
};
|
|
329
|
+
return inflection;
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
exports.PgSimpleInflector = PgSimpleInflector;
|
|
333
|
+
exports.default = exports.PgSimpleInflector;
|
package/package.json
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-simple-inflector",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Simple inflector plugin for Graphile/PostGraphile",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
|
-
"homepage": "https://github.com/
|
|
6
|
+
"homepage": "https://github.com/launchql/launchql",
|
|
7
7
|
"license": "SEE LICENSE IN LICENSE",
|
|
8
|
-
"main": "
|
|
9
|
-
"module": "
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"module": "esm/index.js",
|
|
10
|
+
"types": "index.d.ts",
|
|
10
11
|
"directories": {
|
|
11
12
|
"lib": "src",
|
|
12
13
|
"test": "__tests__"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
|
-
"
|
|
16
|
-
"module"
|
|
16
|
+
"dist"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
19
|
+
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
|
|
20
|
+
"clean": "rimraf dist/**",
|
|
21
|
+
"prepack": "npm run build",
|
|
22
|
+
"build": "npm run clean; tsc -p tsconfig.json; tsc -p tsconfig.esm.json; npm run copy",
|
|
23
|
+
"build:dev": "npm run clean; tsc -p tsconfig.json --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
|
|
24
|
+
"lint": "eslint . --fix",
|
|
24
25
|
"test": "jest",
|
|
25
|
-
"test:watch": "jest --watch"
|
|
26
|
-
"test:debug": "node --inspect node_modules/.bin/jest --runInBand"
|
|
26
|
+
"test:watch": "jest --watch"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
|
-
"access": "public"
|
|
29
|
+
"access": "public",
|
|
30
|
+
"directory": "dist"
|
|
30
31
|
},
|
|
31
32
|
"repository": {
|
|
32
33
|
"type": "git",
|
|
33
|
-
"url": "https://github.com/
|
|
34
|
+
"url": "https://github.com/launchql/launchql"
|
|
34
35
|
},
|
|
35
36
|
"keywords": [
|
|
36
37
|
"graphile",
|
|
@@ -38,37 +39,19 @@
|
|
|
38
39
|
"postgres",
|
|
39
40
|
"graphql",
|
|
40
41
|
"inflection",
|
|
41
|
-
"plugin"
|
|
42
|
+
"plugin",
|
|
43
|
+
"launchql"
|
|
42
44
|
],
|
|
43
45
|
"bugs": {
|
|
44
|
-
"url": "https://github.com/
|
|
46
|
+
"url": "https://github.com/launchql/launchql/issues"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"@babel/plugin-proposal-export-default-from": "7.8.3",
|
|
51
|
-
"@babel/plugin-proposal-object-rest-spread": "7.9.6",
|
|
52
|
-
"@babel/plugin-transform-runtime": "7.9.6",
|
|
53
|
-
"@babel/preset-env": "7.9.6",
|
|
54
|
-
"@babel/preset-react": "7.9.4",
|
|
55
|
-
"babel-core": "7.0.0-bridge.0",
|
|
56
|
-
"babel-eslint": "10.0.3",
|
|
57
|
-
"babel-jest": "25.1.0",
|
|
58
|
-
"babel-plugin-macros": "2.8.0",
|
|
59
|
-
"eslint": "6.8.0",
|
|
60
|
-
"eslint-config-prettier": "^6.10.0",
|
|
61
|
-
"eslint-config-react-app": "5.2.0",
|
|
62
|
-
"eslint-plugin-prettier": "^3.1.2",
|
|
63
|
-
"eslint-plugin-react": "^7.18.3",
|
|
64
|
-
"eslint-plugin-react-hooks": "4.0.0",
|
|
65
|
-
"graphile-test": "^0.1.0",
|
|
66
|
-
"jest": "^24.5.0",
|
|
67
|
-
"jest-in-case": "^1.0.2",
|
|
68
|
-
"prettier": "^1.19.1",
|
|
69
|
-
"regenerator-runtime": "^0.13.2"
|
|
49
|
+
"graphile-test": "^2.8.4",
|
|
50
|
+
"graphql-tag": "2.12.6",
|
|
51
|
+
"pgsql-test": "^2.14.7"
|
|
70
52
|
},
|
|
71
53
|
"dependencies": {
|
|
72
|
-
"
|
|
73
|
-
}
|
|
54
|
+
"graphile-build": "^4.14.1"
|
|
55
|
+
},
|
|
56
|
+
"gitHead": "4cd832ebee39d7be9375340e8e3283692d15b464"
|
|
74
57
|
}
|
package/main/index.js
DELETED
|
@@ -1,402 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.PgSimpleInflector = PgSimpleInflector;
|
|
9
|
-
exports["default"] = void 0;
|
|
10
|
-
|
|
11
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
-
|
|
13
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
14
|
-
|
|
15
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
16
|
-
|
|
17
|
-
// https://raw.githubusercontent.com/graphile/pg-simplify-inflector/master/index.js
|
|
18
|
-
function fixCapitalisedPlural(fn) {
|
|
19
|
-
return function (str) {
|
|
20
|
-
var original = fn.call(this, str);
|
|
21
|
-
return original.replace(/[0-9]S(?=[A-Z]|$)/g, function (match) {
|
|
22
|
-
return match.toLowerCase();
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function fixChangePlural(fn) {
|
|
28
|
-
return function (str) {
|
|
29
|
-
var matches = str.match(/([A-Z]|_[a-z0-9])[a-z0-9]*_*$/);
|
|
30
|
-
var index = matches ? matches.index + matches[1].length - 1 : 0;
|
|
31
|
-
var suffixMatches = str.match(/_*$/);
|
|
32
|
-
var suffixIndex = suffixMatches.index;
|
|
33
|
-
var prefix = str.substr(0, index);
|
|
34
|
-
var word = str.substr(index, suffixIndex - index);
|
|
35
|
-
var suffix = str.substr(suffixIndex);
|
|
36
|
-
return "".concat(prefix).concat(fn.call(this, word)).concat(suffix);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function PgSimpleInflector(builder, _ref) {
|
|
41
|
-
var pgSimpleCollections = _ref.pgSimpleCollections,
|
|
42
|
-
pgOmitListSuffix = _ref.pgOmitListSuffix,
|
|
43
|
-
_ref$pgSimplifyPatch = _ref.pgSimplifyPatch,
|
|
44
|
-
pgSimplifyPatch = _ref$pgSimplifyPatch === void 0 ? true : _ref$pgSimplifyPatch,
|
|
45
|
-
_ref$pgSimplifyAllRow = _ref.pgSimplifyAllRows,
|
|
46
|
-
pgSimplifyAllRows = _ref$pgSimplifyAllRow === void 0 ? true : _ref$pgSimplifyAllRow,
|
|
47
|
-
_ref$pgShortPk = _ref.pgShortPk,
|
|
48
|
-
pgShortPk = _ref$pgShortPk === void 0 ? true : _ref$pgShortPk,
|
|
49
|
-
_ref$pgSimplifyMultik = _ref.pgSimplifyMultikeyRelations,
|
|
50
|
-
pgSimplifyMultikeyRelations = _ref$pgSimplifyMultik === void 0 ? true : _ref$pgSimplifyMultik,
|
|
51
|
-
_ref$pgSimplifyOpposi = _ref.pgSimplifyOppositeBaseNames,
|
|
52
|
-
pgSimplifyOppositeBaseNames = _ref$pgSimplifyOpposi === void 0 ? true : _ref$pgSimplifyOpposi,
|
|
53
|
-
_ref$nodeIdFieldName = _ref.nodeIdFieldName,
|
|
54
|
-
nodeIdFieldName = _ref$nodeIdFieldName === void 0 ? 'nodeId' : _ref$nodeIdFieldName;
|
|
55
|
-
var hasConnections = pgSimpleCollections !== 'only';
|
|
56
|
-
var hasSimpleCollections = pgSimpleCollections === 'only' || pgSimpleCollections === 'both';
|
|
57
|
-
|
|
58
|
-
if (hasSimpleCollections && !hasConnections && pgOmitListSuffix !== true && pgOmitListSuffix !== false) {
|
|
59
|
-
// eslint-disable-next-line no-console
|
|
60
|
-
console.warn('You can simplify the inflector further by adding `{graphileBuildOptions: {pgOmitListSuffix: true}}` to the options passed to PostGraphile, however be aware that doing so will mean that later enabling relay connections will be a breaking change. To dismiss this message, set `pgOmitListSuffix` to false instead.');
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
var connectionSuffix = pgOmitListSuffix ? '-connection' : '';
|
|
64
|
-
var ConnectionSuffix = pgOmitListSuffix ? 'Connection' : '';
|
|
65
|
-
var listSuffix = pgOmitListSuffix ? '' : '-list';
|
|
66
|
-
var ListSuffix = pgOmitListSuffix ? '' : 'List';
|
|
67
|
-
builder.hook('inflection', function (oldInflection) {
|
|
68
|
-
return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, oldInflection), {}, {
|
|
69
|
-
/*
|
|
70
|
-
* This solves the issue with `blah-table1s` becoming `blahTable1S`
|
|
71
|
-
* (i.e. the capital S at the end) or `table1-connection becoming `Table1SConnection`
|
|
72
|
-
*/
|
|
73
|
-
camelCase: fixCapitalisedPlural(oldInflection.camelCase),
|
|
74
|
-
upperCamelCase: fixCapitalisedPlural(oldInflection.upperCamelCase),
|
|
75
|
-
|
|
76
|
-
/*
|
|
77
|
-
* Pluralize/singularize only supports single words, so only run
|
|
78
|
-
* on the final segment of a name.
|
|
79
|
-
*/
|
|
80
|
-
pluralize: fixChangePlural(oldInflection.pluralize),
|
|
81
|
-
singularize: fixChangePlural(oldInflection.singularize),
|
|
82
|
-
distinctPluralize: function distinctPluralize(str) {
|
|
83
|
-
var singular = this.singularize(str);
|
|
84
|
-
var plural = this.pluralize(singular);
|
|
85
|
-
|
|
86
|
-
if (singular !== plural) {
|
|
87
|
-
return plural;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (plural.endsWith('ch') || plural.endsWith('s') || plural.endsWith('sh') || plural.endsWith('x') || plural.endsWith('z')) {
|
|
91
|
-
return plural + 'es';
|
|
92
|
-
} else if (plural.endsWith('y')) {
|
|
93
|
-
return plural.slice(0, -1) + 'ies';
|
|
94
|
-
} else {
|
|
95
|
-
return plural + 's';
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
// Fix a naming bug
|
|
99
|
-
deletedNodeId: function deletedNodeId(table) {
|
|
100
|
-
return this.camelCase("deleted-".concat(this.singularize(table.name), "-").concat(nodeIdFieldName));
|
|
101
|
-
},
|
|
102
|
-
getBaseName: function getBaseName(columnName) {
|
|
103
|
-
var matches = columnName.match(/^(.+?)(_row_id|_id|_uuid|_fk|_pk|RowId|Id|Uuid|UUID|Fk|Pk)$/);
|
|
104
|
-
|
|
105
|
-
if (matches) {
|
|
106
|
-
return matches[1];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return null;
|
|
110
|
-
},
|
|
111
|
-
baseNameMatches: function baseNameMatches(baseName, otherName) {
|
|
112
|
-
var singularizedName = this.singularize(otherName);
|
|
113
|
-
return baseName === singularizedName;
|
|
114
|
-
},
|
|
115
|
-
baseNameMatchesAny: function baseNameMatchesAny(baseName, otherName) {
|
|
116
|
-
return this.singularize(baseName) === this.singularize(otherName);
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
/* This is a good method to override. */
|
|
120
|
-
getOppositeBaseName: function getOppositeBaseName(baseName) {
|
|
121
|
-
return pgSimplifyOppositeBaseNames && ({
|
|
122
|
-
/*
|
|
123
|
-
* Changes to this list are breaking changes and will require a
|
|
124
|
-
* major version update, so we need to group as many together as
|
|
125
|
-
* possible! Rather than sending a PR, please look for an open
|
|
126
|
-
* issue called something like "Add more opposites" (if there isn't
|
|
127
|
-
* one then please open it) and add your suggestions to the GitHub
|
|
128
|
-
* comments.
|
|
129
|
-
*/
|
|
130
|
-
// NOTE: reason to be careful using this:
|
|
131
|
-
// field names to take into account this particular case (e.g. events with event.parent_id could not have parent OR child fields)
|
|
132
|
-
inviter: 'invitee',
|
|
133
|
-
parent: 'child',
|
|
134
|
-
child: 'parent',
|
|
135
|
-
owner: 'owned',
|
|
136
|
-
author: 'authored',
|
|
137
|
-
editor: 'edited',
|
|
138
|
-
reviewer: 'reviewed'
|
|
139
|
-
}[baseName] || null);
|
|
140
|
-
},
|
|
141
|
-
getBaseNameFromKeys: function getBaseNameFromKeys(detailedKeys) {
|
|
142
|
-
var _this = this;
|
|
143
|
-
|
|
144
|
-
if (detailedKeys.length === 1) {
|
|
145
|
-
var key = detailedKeys[0];
|
|
146
|
-
|
|
147
|
-
var columnName = this._columnName(key);
|
|
148
|
-
|
|
149
|
-
return this.getBaseName(columnName);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (pgSimplifyMultikeyRelations) {
|
|
153
|
-
var columnNames = detailedKeys.map(function (key) {
|
|
154
|
-
return _this._columnName(key);
|
|
155
|
-
});
|
|
156
|
-
var baseNames = columnNames.map(function (columnName) {
|
|
157
|
-
return _this.getBaseName(columnName);
|
|
158
|
-
}); // Check none are null
|
|
159
|
-
|
|
160
|
-
if (baseNames.every(function (n) {
|
|
161
|
-
return n;
|
|
162
|
-
})) {
|
|
163
|
-
return baseNames.join('-');
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
}, pgSimplifyPatch ? {
|
|
170
|
-
patchField: function patchField() {
|
|
171
|
-
return 'patch';
|
|
172
|
-
}
|
|
173
|
-
} : null), pgSimplifyAllRows ? {
|
|
174
|
-
allRows: function allRows(table) {
|
|
175
|
-
return this.camelCase(this.distinctPluralize(this._singularizedTableName(table)) + connectionSuffix);
|
|
176
|
-
},
|
|
177
|
-
allRowsSimple: function allRowsSimple(table) {
|
|
178
|
-
return this.camelCase(this.distinctPluralize(this._singularizedTableName(table)) + listSuffix);
|
|
179
|
-
}
|
|
180
|
-
} : null), {}, {
|
|
181
|
-
computedColumn: function computedColumn(pseudoColumnName, proc, _table) {
|
|
182
|
-
return proc.tags.fieldName ? proc.tags.fieldName + (proc.returnsSet ? ConnectionSuffix : '') : this.camelCase(pseudoColumnName + (proc.returnsSet ? connectionSuffix : ''));
|
|
183
|
-
},
|
|
184
|
-
computedColumnList: function computedColumnList(pseudoColumnName, proc, _table) {
|
|
185
|
-
return proc.tags.fieldName ? proc.tags.fieldName + ListSuffix : this.camelCase(pseudoColumnName + listSuffix);
|
|
186
|
-
},
|
|
187
|
-
singleRelationByKeys: function singleRelationByKeys(detailedKeys, table, _foreignTable, constraint) {
|
|
188
|
-
if (constraint.tags.fieldName) {
|
|
189
|
-
return constraint.tags.fieldName;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
var baseName = this.getBaseNameFromKeys(detailedKeys);
|
|
193
|
-
|
|
194
|
-
if (constraint.classId === constraint.foreignClassId) {
|
|
195
|
-
if (this.baseNameMatchesAny(baseName, table.name)) {
|
|
196
|
-
return oldInflection.singleRelationByKeys(detailedKeys, table, _foreignTable, constraint);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
if (baseName) {
|
|
201
|
-
return this.camelCase(baseName);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (this.baseNameMatches(baseName, table.name)) {
|
|
205
|
-
return this.camelCase("".concat(this._singularizedTableName(table)));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return oldInflection.singleRelationByKeys(detailedKeys, table, _foreignTable, constraint);
|
|
209
|
-
},
|
|
210
|
-
singleRelationByKeysBackwards: function singleRelationByKeysBackwards(detailedKeys, table, foreignTable, constraint) {
|
|
211
|
-
if (constraint.tags.foreignSingleFieldName) {
|
|
212
|
-
return constraint.tags.foreignSingleFieldName;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if (constraint.tags.foreignFieldName) {
|
|
216
|
-
return constraint.tags.foreignFieldName;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
var baseName = this.getBaseNameFromKeys(detailedKeys);
|
|
220
|
-
var oppositeBaseName = baseName && this.getOppositeBaseName(baseName); // added
|
|
221
|
-
// if (constraint.classId === constraint.foreignClassId) {
|
|
222
|
-
// if (this.baseNameMatches(baseName, foreignTable.name)) {
|
|
223
|
-
// return oldInflection.singleRelationByKeysBackwards(
|
|
224
|
-
// detailedKeys,
|
|
225
|
-
// table,
|
|
226
|
-
// foreignTable,
|
|
227
|
-
// constraint
|
|
228
|
-
// );
|
|
229
|
-
// }
|
|
230
|
-
// }
|
|
231
|
-
|
|
232
|
-
if (oppositeBaseName) {
|
|
233
|
-
return this.camelCase("".concat(oppositeBaseName, "-").concat(this._singularizedTableName(table)));
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (this.baseNameMatches(baseName, foreignTable.name)) {
|
|
237
|
-
return this.camelCase("".concat(this._singularizedTableName(table)));
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return oldInflection.singleRelationByKeysBackwards(detailedKeys, table, foreignTable, constraint);
|
|
241
|
-
},
|
|
242
|
-
_manyRelationByKeysBase: function _manyRelationByKeysBase(detailedKeys, table, _foreignTable, _constraint) {
|
|
243
|
-
var baseName = this.getBaseNameFromKeys(detailedKeys);
|
|
244
|
-
var oppositeBaseName = baseName && this.getOppositeBaseName(baseName); // added
|
|
245
|
-
|
|
246
|
-
if (_constraint.classId === _constraint.foreignClassId) {
|
|
247
|
-
if (this.baseNameMatches(baseName, table.name)) {
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (oppositeBaseName) {
|
|
253
|
-
return this.camelCase("".concat(oppositeBaseName, "-").concat(this.distinctPluralize(this._singularizedTableName(table))));
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (this.baseNameMatches(baseName, _foreignTable.name)) {
|
|
257
|
-
return this.camelCase("".concat(this.distinctPluralize(this._singularizedTableName(table))));
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return null;
|
|
261
|
-
},
|
|
262
|
-
manyRelationByKeys: function manyRelationByKeys(detailedKeys, table, foreignTable, constraint) {
|
|
263
|
-
if (constraint.tags.foreignFieldName) {
|
|
264
|
-
if (constraint.tags.foreignSimpleFieldName) {
|
|
265
|
-
return constraint.tags.foreignFieldName;
|
|
266
|
-
} else {
|
|
267
|
-
return constraint.tags.foreignFieldName + ConnectionSuffix;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
var base = this._manyRelationByKeysBase(detailedKeys, table, foreignTable, constraint);
|
|
272
|
-
|
|
273
|
-
if (base) {
|
|
274
|
-
return base + ConnectionSuffix;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return oldInflection.manyRelationByKeys(detailedKeys, table, foreignTable, constraint) + ConnectionSuffix;
|
|
278
|
-
},
|
|
279
|
-
manyRelationByKeysSimple: function manyRelationByKeysSimple(detailedKeys, table, foreignTable, constraint) {
|
|
280
|
-
if (constraint.tags.foreignSimpleFieldName) {
|
|
281
|
-
return constraint.tags.foreignSimpleFieldName;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (constraint.tags.foreignFieldName) {
|
|
285
|
-
return constraint.tags.foreignFieldName + ListSuffix;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
var base = this._manyRelationByKeysBase(detailedKeys, table, foreignTable, constraint);
|
|
289
|
-
|
|
290
|
-
if (base) {
|
|
291
|
-
return base + ListSuffix;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return oldInflection.manyRelationByKeys(detailedKeys, table, foreignTable, constraint) + ListSuffix;
|
|
295
|
-
},
|
|
296
|
-
functionQueryName: function functionQueryName(proc) {
|
|
297
|
-
return this.camelCase(this._functionName(proc) + (proc.returnsSet ? connectionSuffix : ''));
|
|
298
|
-
},
|
|
299
|
-
functionQueryNameList: function functionQueryNameList(proc) {
|
|
300
|
-
return this.camelCase(this._functionName(proc) + listSuffix);
|
|
301
|
-
}
|
|
302
|
-
}, pgShortPk ? {
|
|
303
|
-
tableNode: function tableNode(table) {
|
|
304
|
-
return this.camelCase("".concat(this._singularizedTableName(table), "-by-").concat(nodeIdFieldName));
|
|
305
|
-
},
|
|
306
|
-
rowByUniqueKeys: function rowByUniqueKeys(detailedKeys, table, constraint) {
|
|
307
|
-
var _this2 = this;
|
|
308
|
-
|
|
309
|
-
if (constraint.tags.fieldName) {
|
|
310
|
-
return constraint.tags.fieldName;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
if (constraint.type === 'p') {
|
|
314
|
-
// Primary key, shorten!
|
|
315
|
-
return this.camelCase(this._singularizedTableName(table));
|
|
316
|
-
} else {
|
|
317
|
-
return this.camelCase("".concat(this._singularizedTableName(table), "-by-").concat(detailedKeys.map(function (key) {
|
|
318
|
-
return _this2.column(key);
|
|
319
|
-
}).join('-and-')));
|
|
320
|
-
}
|
|
321
|
-
},
|
|
322
|
-
updateByKeys: function updateByKeys(detailedKeys, table, constraint) {
|
|
323
|
-
var _this3 = this;
|
|
324
|
-
|
|
325
|
-
if (constraint.tags.updateFieldName) {
|
|
326
|
-
return constraint.tags.updateFieldName;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
if (constraint.type === 'p') {
|
|
330
|
-
return this.camelCase("update-".concat(this._singularizedTableName(table)));
|
|
331
|
-
} else {
|
|
332
|
-
return this.camelCase("update-".concat(this._singularizedTableName(table), "-by-").concat(detailedKeys.map(function (key) {
|
|
333
|
-
return _this3.column(key);
|
|
334
|
-
}).join('-and-')));
|
|
335
|
-
}
|
|
336
|
-
},
|
|
337
|
-
deleteByKeys: function deleteByKeys(detailedKeys, table, constraint) {
|
|
338
|
-
var _this4 = this;
|
|
339
|
-
|
|
340
|
-
if (constraint.tags.deleteFieldName) {
|
|
341
|
-
return constraint.tags.deleteFieldName;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
if (constraint.type === 'p') {
|
|
345
|
-
// Primary key, shorten!
|
|
346
|
-
return this.camelCase("delete-".concat(this._singularizedTableName(table)));
|
|
347
|
-
} else {
|
|
348
|
-
return this.camelCase("delete-".concat(this._singularizedTableName(table), "-by-").concat(detailedKeys.map(function (key) {
|
|
349
|
-
return _this4.column(key);
|
|
350
|
-
}).join('-and-')));
|
|
351
|
-
}
|
|
352
|
-
},
|
|
353
|
-
updateByKeysInputType: function updateByKeysInputType(detailedKeys, table, constraint) {
|
|
354
|
-
var _this5 = this;
|
|
355
|
-
|
|
356
|
-
if (constraint.tags.updateFieldName) {
|
|
357
|
-
return this.upperCamelCase("".concat(constraint.tags.updateFieldName, "-input"));
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (constraint.type === 'p') {
|
|
361
|
-
// Primary key, shorten!
|
|
362
|
-
return this.upperCamelCase("update-".concat(this._singularizedTableName(table), "-input"));
|
|
363
|
-
} else {
|
|
364
|
-
return this.upperCamelCase("update-".concat(this._singularizedTableName(table), "-by-").concat(detailedKeys.map(function (key) {
|
|
365
|
-
return _this5.column(key);
|
|
366
|
-
}).join('-and-'), "-input"));
|
|
367
|
-
}
|
|
368
|
-
},
|
|
369
|
-
deleteByKeysInputType: function deleteByKeysInputType(detailedKeys, table, constraint) {
|
|
370
|
-
var _this6 = this;
|
|
371
|
-
|
|
372
|
-
if (constraint.tags.deleteFieldName) {
|
|
373
|
-
return this.upperCamelCase("".concat(constraint.tags.deleteFieldName, "-input"));
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
if (constraint.type === 'p') {
|
|
377
|
-
// Primary key, shorten!
|
|
378
|
-
return this.upperCamelCase("delete-".concat(this._singularizedTableName(table), "-input"));
|
|
379
|
-
} else {
|
|
380
|
-
return this.upperCamelCase("delete-".concat(this._singularizedTableName(table), "-by-").concat(detailedKeys.map(function (key) {
|
|
381
|
-
return _this6.column(key);
|
|
382
|
-
}).join('-and-'), "-input"));
|
|
383
|
-
}
|
|
384
|
-
},
|
|
385
|
-
updateNode: function updateNode(table) {
|
|
386
|
-
return this.camelCase("update-".concat(this._singularizedTableName(table), "-by-").concat(nodeIdFieldName));
|
|
387
|
-
},
|
|
388
|
-
deleteNode: function deleteNode(table) {
|
|
389
|
-
return this.camelCase("delete-".concat(this._singularizedTableName(table), "-by-").concat(nodeIdFieldName));
|
|
390
|
-
},
|
|
391
|
-
updateNodeInputType: function updateNodeInputType(table) {
|
|
392
|
-
return this.upperCamelCase("update-".concat(this._singularizedTableName(table), "-by-").concat(nodeIdFieldName, "-input"));
|
|
393
|
-
},
|
|
394
|
-
deleteNodeInputType: function deleteNodeInputType(table) {
|
|
395
|
-
return this.upperCamelCase("delete-".concat(this._singularizedTableName(table), "-by-").concat(nodeIdFieldName, "-input"));
|
|
396
|
-
}
|
|
397
|
-
} : null);
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
var _default = PgSimpleInflector;
|
|
402
|
-
exports["default"] = _default;
|
package/module/index.js
DELETED
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
-
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
|
-
|
|
7
|
-
// https://raw.githubusercontent.com/graphile/pg-simplify-inflector/master/index.js
|
|
8
|
-
function fixCapitalisedPlural(fn) {
|
|
9
|
-
return function (str) {
|
|
10
|
-
const original = fn.call(this, str);
|
|
11
|
-
return original.replace(/[0-9]S(?=[A-Z]|$)/g, match => match.toLowerCase());
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function fixChangePlural(fn) {
|
|
16
|
-
return function (str) {
|
|
17
|
-
const matches = str.match(/([A-Z]|_[a-z0-9])[a-z0-9]*_*$/);
|
|
18
|
-
const index = matches ? matches.index + matches[1].length - 1 : 0;
|
|
19
|
-
const suffixMatches = str.match(/_*$/);
|
|
20
|
-
const suffixIndex = suffixMatches.index;
|
|
21
|
-
const prefix = str.substr(0, index);
|
|
22
|
-
const word = str.substr(index, suffixIndex - index);
|
|
23
|
-
const suffix = str.substr(suffixIndex);
|
|
24
|
-
return `${prefix}${fn.call(this, word)}${suffix}`;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function PgSimpleInflector(builder, {
|
|
29
|
-
pgSimpleCollections,
|
|
30
|
-
pgOmitListSuffix,
|
|
31
|
-
pgSimplifyPatch = true,
|
|
32
|
-
pgSimplifyAllRows = true,
|
|
33
|
-
pgShortPk = true,
|
|
34
|
-
pgSimplifyMultikeyRelations = true,
|
|
35
|
-
pgSimplifyOppositeBaseNames = true,
|
|
36
|
-
nodeIdFieldName = 'nodeId'
|
|
37
|
-
}) {
|
|
38
|
-
const hasConnections = pgSimpleCollections !== 'only';
|
|
39
|
-
const hasSimpleCollections = pgSimpleCollections === 'only' || pgSimpleCollections === 'both';
|
|
40
|
-
|
|
41
|
-
if (hasSimpleCollections && !hasConnections && pgOmitListSuffix !== true && pgOmitListSuffix !== false) {
|
|
42
|
-
// eslint-disable-next-line no-console
|
|
43
|
-
console.warn('You can simplify the inflector further by adding `{graphileBuildOptions: {pgOmitListSuffix: true}}` to the options passed to PostGraphile, however be aware that doing so will mean that later enabling relay connections will be a breaking change. To dismiss this message, set `pgOmitListSuffix` to false instead.');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const connectionSuffix = pgOmitListSuffix ? '-connection' : '';
|
|
47
|
-
const ConnectionSuffix = pgOmitListSuffix ? 'Connection' : '';
|
|
48
|
-
const listSuffix = pgOmitListSuffix ? '' : '-list';
|
|
49
|
-
const ListSuffix = pgOmitListSuffix ? '' : 'List';
|
|
50
|
-
builder.hook('inflection', oldInflection => {
|
|
51
|
-
return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, oldInflection), {}, {
|
|
52
|
-
/*
|
|
53
|
-
* This solves the issue with `blah-table1s` becoming `blahTable1S`
|
|
54
|
-
* (i.e. the capital S at the end) or `table1-connection becoming `Table1SConnection`
|
|
55
|
-
*/
|
|
56
|
-
camelCase: fixCapitalisedPlural(oldInflection.camelCase),
|
|
57
|
-
upperCamelCase: fixCapitalisedPlural(oldInflection.upperCamelCase),
|
|
58
|
-
|
|
59
|
-
/*
|
|
60
|
-
* Pluralize/singularize only supports single words, so only run
|
|
61
|
-
* on the final segment of a name.
|
|
62
|
-
*/
|
|
63
|
-
pluralize: fixChangePlural(oldInflection.pluralize),
|
|
64
|
-
singularize: fixChangePlural(oldInflection.singularize),
|
|
65
|
-
|
|
66
|
-
distinctPluralize(str) {
|
|
67
|
-
const singular = this.singularize(str);
|
|
68
|
-
const plural = this.pluralize(singular);
|
|
69
|
-
|
|
70
|
-
if (singular !== plural) {
|
|
71
|
-
return plural;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (plural.endsWith('ch') || plural.endsWith('s') || plural.endsWith('sh') || plural.endsWith('x') || plural.endsWith('z')) {
|
|
75
|
-
return plural + 'es';
|
|
76
|
-
} else if (plural.endsWith('y')) {
|
|
77
|
-
return plural.slice(0, -1) + 'ies';
|
|
78
|
-
} else {
|
|
79
|
-
return plural + 's';
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
// Fix a naming bug
|
|
84
|
-
deletedNodeId(table) {
|
|
85
|
-
return this.camelCase(`deleted-${this.singularize(table.name)}-${nodeIdFieldName}`);
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
getBaseName(columnName) {
|
|
89
|
-
const matches = columnName.match(/^(.+?)(_row_id|_id|_uuid|_fk|_pk|RowId|Id|Uuid|UUID|Fk|Pk)$/);
|
|
90
|
-
|
|
91
|
-
if (matches) {
|
|
92
|
-
return matches[1];
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return null;
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
baseNameMatches(baseName, otherName) {
|
|
99
|
-
const singularizedName = this.singularize(otherName);
|
|
100
|
-
return baseName === singularizedName;
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
baseNameMatchesAny(baseName, otherName) {
|
|
104
|
-
return this.singularize(baseName) === this.singularize(otherName);
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
/* This is a good method to override. */
|
|
108
|
-
getOppositeBaseName(baseName) {
|
|
109
|
-
return pgSimplifyOppositeBaseNames && ({
|
|
110
|
-
/*
|
|
111
|
-
* Changes to this list are breaking changes and will require a
|
|
112
|
-
* major version update, so we need to group as many together as
|
|
113
|
-
* possible! Rather than sending a PR, please look for an open
|
|
114
|
-
* issue called something like "Add more opposites" (if there isn't
|
|
115
|
-
* one then please open it) and add your suggestions to the GitHub
|
|
116
|
-
* comments.
|
|
117
|
-
*/
|
|
118
|
-
// NOTE: reason to be careful using this:
|
|
119
|
-
// field names to take into account this particular case (e.g. events with event.parent_id could not have parent OR child fields)
|
|
120
|
-
inviter: 'invitee',
|
|
121
|
-
parent: 'child',
|
|
122
|
-
child: 'parent',
|
|
123
|
-
owner: 'owned',
|
|
124
|
-
author: 'authored',
|
|
125
|
-
editor: 'edited',
|
|
126
|
-
reviewer: 'reviewed'
|
|
127
|
-
}[baseName] || null);
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
getBaseNameFromKeys(detailedKeys) {
|
|
131
|
-
if (detailedKeys.length === 1) {
|
|
132
|
-
const key = detailedKeys[0];
|
|
133
|
-
|
|
134
|
-
const columnName = this._columnName(key);
|
|
135
|
-
|
|
136
|
-
return this.getBaseName(columnName);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (pgSimplifyMultikeyRelations) {
|
|
140
|
-
const columnNames = detailedKeys.map(key => this._columnName(key));
|
|
141
|
-
const baseNames = columnNames.map(columnName => this.getBaseName(columnName)); // Check none are null
|
|
142
|
-
|
|
143
|
-
if (baseNames.every(n => n)) {
|
|
144
|
-
return baseNames.join('-');
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
}, pgSimplifyPatch ? {
|
|
152
|
-
patchField() {
|
|
153
|
-
return 'patch';
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
} : null), pgSimplifyAllRows ? {
|
|
157
|
-
allRows(table) {
|
|
158
|
-
return this.camelCase(this.distinctPluralize(this._singularizedTableName(table)) + connectionSuffix);
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
allRowsSimple(table) {
|
|
162
|
-
return this.camelCase(this.distinctPluralize(this._singularizedTableName(table)) + listSuffix);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
} : null), {}, {
|
|
166
|
-
computedColumn(pseudoColumnName, proc, _table) {
|
|
167
|
-
return proc.tags.fieldName ? proc.tags.fieldName + (proc.returnsSet ? ConnectionSuffix : '') : this.camelCase(pseudoColumnName + (proc.returnsSet ? connectionSuffix : ''));
|
|
168
|
-
},
|
|
169
|
-
|
|
170
|
-
computedColumnList(pseudoColumnName, proc, _table) {
|
|
171
|
-
return proc.tags.fieldName ? proc.tags.fieldName + ListSuffix : this.camelCase(pseudoColumnName + listSuffix);
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
singleRelationByKeys(detailedKeys, table, _foreignTable, constraint) {
|
|
175
|
-
if (constraint.tags.fieldName) {
|
|
176
|
-
return constraint.tags.fieldName;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const baseName = this.getBaseNameFromKeys(detailedKeys);
|
|
180
|
-
|
|
181
|
-
if (constraint.classId === constraint.foreignClassId) {
|
|
182
|
-
if (this.baseNameMatchesAny(baseName, table.name)) {
|
|
183
|
-
return oldInflection.singleRelationByKeys(detailedKeys, table, _foreignTable, constraint);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (baseName) {
|
|
188
|
-
return this.camelCase(baseName);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (this.baseNameMatches(baseName, table.name)) {
|
|
192
|
-
return this.camelCase(`${this._singularizedTableName(table)}`);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return oldInflection.singleRelationByKeys(detailedKeys, table, _foreignTable, constraint);
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
singleRelationByKeysBackwards(detailedKeys, table, foreignTable, constraint) {
|
|
199
|
-
if (constraint.tags.foreignSingleFieldName) {
|
|
200
|
-
return constraint.tags.foreignSingleFieldName;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (constraint.tags.foreignFieldName) {
|
|
204
|
-
return constraint.tags.foreignFieldName;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const baseName = this.getBaseNameFromKeys(detailedKeys);
|
|
208
|
-
const oppositeBaseName = baseName && this.getOppositeBaseName(baseName); // added
|
|
209
|
-
// if (constraint.classId === constraint.foreignClassId) {
|
|
210
|
-
// if (this.baseNameMatches(baseName, foreignTable.name)) {
|
|
211
|
-
// return oldInflection.singleRelationByKeysBackwards(
|
|
212
|
-
// detailedKeys,
|
|
213
|
-
// table,
|
|
214
|
-
// foreignTable,
|
|
215
|
-
// constraint
|
|
216
|
-
// );
|
|
217
|
-
// }
|
|
218
|
-
// }
|
|
219
|
-
|
|
220
|
-
if (oppositeBaseName) {
|
|
221
|
-
return this.camelCase(`${oppositeBaseName}-${this._singularizedTableName(table)}`);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (this.baseNameMatches(baseName, foreignTable.name)) {
|
|
225
|
-
return this.camelCase(`${this._singularizedTableName(table)}`);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return oldInflection.singleRelationByKeysBackwards(detailedKeys, table, foreignTable, constraint);
|
|
229
|
-
},
|
|
230
|
-
|
|
231
|
-
_manyRelationByKeysBase(detailedKeys, table, _foreignTable, _constraint) {
|
|
232
|
-
const baseName = this.getBaseNameFromKeys(detailedKeys);
|
|
233
|
-
const oppositeBaseName = baseName && this.getOppositeBaseName(baseName); // added
|
|
234
|
-
|
|
235
|
-
if (_constraint.classId === _constraint.foreignClassId) {
|
|
236
|
-
if (this.baseNameMatches(baseName, table.name)) {
|
|
237
|
-
return null;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
if (oppositeBaseName) {
|
|
242
|
-
return this.camelCase(`${oppositeBaseName}-${this.distinctPluralize(this._singularizedTableName(table))}`);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
if (this.baseNameMatches(baseName, _foreignTable.name)) {
|
|
246
|
-
return this.camelCase(`${this.distinctPluralize(this._singularizedTableName(table))}`);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return null;
|
|
250
|
-
},
|
|
251
|
-
|
|
252
|
-
manyRelationByKeys(detailedKeys, table, foreignTable, constraint) {
|
|
253
|
-
if (constraint.tags.foreignFieldName) {
|
|
254
|
-
if (constraint.tags.foreignSimpleFieldName) {
|
|
255
|
-
return constraint.tags.foreignFieldName;
|
|
256
|
-
} else {
|
|
257
|
-
return constraint.tags.foreignFieldName + ConnectionSuffix;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const base = this._manyRelationByKeysBase(detailedKeys, table, foreignTable, constraint);
|
|
262
|
-
|
|
263
|
-
if (base) {
|
|
264
|
-
return base + ConnectionSuffix;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return oldInflection.manyRelationByKeys(detailedKeys, table, foreignTable, constraint) + ConnectionSuffix;
|
|
268
|
-
},
|
|
269
|
-
|
|
270
|
-
manyRelationByKeysSimple(detailedKeys, table, foreignTable, constraint) {
|
|
271
|
-
if (constraint.tags.foreignSimpleFieldName) {
|
|
272
|
-
return constraint.tags.foreignSimpleFieldName;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (constraint.tags.foreignFieldName) {
|
|
276
|
-
return constraint.tags.foreignFieldName + ListSuffix;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
const base = this._manyRelationByKeysBase(detailedKeys, table, foreignTable, constraint);
|
|
280
|
-
|
|
281
|
-
if (base) {
|
|
282
|
-
return base + ListSuffix;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return oldInflection.manyRelationByKeys(detailedKeys, table, foreignTable, constraint) + ListSuffix;
|
|
286
|
-
},
|
|
287
|
-
|
|
288
|
-
functionQueryName(proc) {
|
|
289
|
-
return this.camelCase(this._functionName(proc) + (proc.returnsSet ? connectionSuffix : ''));
|
|
290
|
-
},
|
|
291
|
-
|
|
292
|
-
functionQueryNameList(proc) {
|
|
293
|
-
return this.camelCase(this._functionName(proc) + listSuffix);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
}, pgShortPk ? {
|
|
297
|
-
tableNode(table) {
|
|
298
|
-
return this.camelCase(`${this._singularizedTableName(table)}-by-${nodeIdFieldName}`);
|
|
299
|
-
},
|
|
300
|
-
|
|
301
|
-
rowByUniqueKeys(detailedKeys, table, constraint) {
|
|
302
|
-
if (constraint.tags.fieldName) {
|
|
303
|
-
return constraint.tags.fieldName;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
if (constraint.type === 'p') {
|
|
307
|
-
// Primary key, shorten!
|
|
308
|
-
return this.camelCase(this._singularizedTableName(table));
|
|
309
|
-
} else {
|
|
310
|
-
return this.camelCase(`${this._singularizedTableName(table)}-by-${detailedKeys.map(key => this.column(key)).join('-and-')}`);
|
|
311
|
-
}
|
|
312
|
-
},
|
|
313
|
-
|
|
314
|
-
updateByKeys(detailedKeys, table, constraint) {
|
|
315
|
-
if (constraint.tags.updateFieldName) {
|
|
316
|
-
return constraint.tags.updateFieldName;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if (constraint.type === 'p') {
|
|
320
|
-
return this.camelCase(`update-${this._singularizedTableName(table)}`);
|
|
321
|
-
} else {
|
|
322
|
-
return this.camelCase(`update-${this._singularizedTableName(table)}-by-${detailedKeys.map(key => this.column(key)).join('-and-')}`);
|
|
323
|
-
}
|
|
324
|
-
},
|
|
325
|
-
|
|
326
|
-
deleteByKeys(detailedKeys, table, constraint) {
|
|
327
|
-
if (constraint.tags.deleteFieldName) {
|
|
328
|
-
return constraint.tags.deleteFieldName;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (constraint.type === 'p') {
|
|
332
|
-
// Primary key, shorten!
|
|
333
|
-
return this.camelCase(`delete-${this._singularizedTableName(table)}`);
|
|
334
|
-
} else {
|
|
335
|
-
return this.camelCase(`delete-${this._singularizedTableName(table)}-by-${detailedKeys.map(key => this.column(key)).join('-and-')}`);
|
|
336
|
-
}
|
|
337
|
-
},
|
|
338
|
-
|
|
339
|
-
updateByKeysInputType(detailedKeys, table, constraint) {
|
|
340
|
-
if (constraint.tags.updateFieldName) {
|
|
341
|
-
return this.upperCamelCase(`${constraint.tags.updateFieldName}-input`);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
if (constraint.type === 'p') {
|
|
345
|
-
// Primary key, shorten!
|
|
346
|
-
return this.upperCamelCase(`update-${this._singularizedTableName(table)}-input`);
|
|
347
|
-
} else {
|
|
348
|
-
return this.upperCamelCase(`update-${this._singularizedTableName(table)}-by-${detailedKeys.map(key => this.column(key)).join('-and-')}-input`);
|
|
349
|
-
}
|
|
350
|
-
},
|
|
351
|
-
|
|
352
|
-
deleteByKeysInputType(detailedKeys, table, constraint) {
|
|
353
|
-
if (constraint.tags.deleteFieldName) {
|
|
354
|
-
return this.upperCamelCase(`${constraint.tags.deleteFieldName}-input`);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
if (constraint.type === 'p') {
|
|
358
|
-
// Primary key, shorten!
|
|
359
|
-
return this.upperCamelCase(`delete-${this._singularizedTableName(table)}-input`);
|
|
360
|
-
} else {
|
|
361
|
-
return this.upperCamelCase(`delete-${this._singularizedTableName(table)}-by-${detailedKeys.map(key => this.column(key)).join('-and-')}-input`);
|
|
362
|
-
}
|
|
363
|
-
},
|
|
364
|
-
|
|
365
|
-
updateNode(table) {
|
|
366
|
-
return this.camelCase(`update-${this._singularizedTableName(table)}-by-${nodeIdFieldName}`);
|
|
367
|
-
},
|
|
368
|
-
|
|
369
|
-
deleteNode(table) {
|
|
370
|
-
return this.camelCase(`delete-${this._singularizedTableName(table)}-by-${nodeIdFieldName}`);
|
|
371
|
-
},
|
|
372
|
-
|
|
373
|
-
updateNodeInputType(table) {
|
|
374
|
-
return this.upperCamelCase(`update-${this._singularizedTableName(table)}-by-${nodeIdFieldName}-input`);
|
|
375
|
-
},
|
|
376
|
-
|
|
377
|
-
deleteNodeInputType(table) {
|
|
378
|
-
return this.upperCamelCase(`delete-${this._singularizedTableName(table)}-by-${nodeIdFieldName}-input`);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
} : null);
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
export default PgSimpleInflector;
|