graphile-settings 4.14.0 → 4.15.1
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { singularize, singularizeLast, pluralizeLast, distinctPluralize, fixCapitalisedPlural,
|
|
1
|
+
import { singularize, singularizeLast, pluralizeLast, distinctPluralize, fixCapitalisedPlural, toCamelCase, } from 'inflekt';
|
|
2
2
|
/**
|
|
3
3
|
* Custom inflector plugin for Constructive using the inflekt library.
|
|
4
4
|
*
|
|
@@ -43,7 +43,7 @@ function getBaseName(attributeName) {
|
|
|
43
43
|
*/
|
|
44
44
|
function baseNameMatches(baseName, otherName) {
|
|
45
45
|
const singularizedName = singularize(otherName);
|
|
46
|
-
return
|
|
46
|
+
return toCamelCase(baseName) === toCamelCase(singularizedName);
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Get the opposite name for a relation base name
|
|
@@ -173,14 +173,14 @@ export const InflektPlugin = {
|
|
|
173
173
|
*/
|
|
174
174
|
allRowsConnection(_previous, _options, resource) {
|
|
175
175
|
const resourceName = this._singularizedResourceName(resource);
|
|
176
|
-
return
|
|
176
|
+
return toCamelCase(distinctPluralize(resourceName));
|
|
177
177
|
},
|
|
178
178
|
/**
|
|
179
179
|
* Simplify root query list fields
|
|
180
180
|
*/
|
|
181
181
|
allRowsList(_previous, _options, resource) {
|
|
182
182
|
const resourceName = this._singularizedResourceName(resource);
|
|
183
|
-
return
|
|
183
|
+
return toCamelCase(distinctPluralize(resourceName)) + 'List';
|
|
184
184
|
},
|
|
185
185
|
/**
|
|
186
186
|
* Simplify single relation field names (userByAuthorId -> author)
|
|
@@ -199,14 +199,14 @@ export const InflektPlugin = {
|
|
|
199
199
|
const attributeName = relation.localAttributes[0];
|
|
200
200
|
const baseName = getBaseName(attributeName);
|
|
201
201
|
if (baseName) {
|
|
202
|
-
return
|
|
202
|
+
return toCamelCase(baseName);
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
// Fall back to the remote resource name
|
|
206
206
|
const foreignPk = relation.remoteResource.uniques.find((u) => u.isPrimary);
|
|
207
207
|
if (foreignPk &&
|
|
208
208
|
arraysMatch(foreignPk.attributes, relation.remoteAttributes)) {
|
|
209
|
-
return
|
|
209
|
+
return toCamelCase(this._singularizedCodecName(relation.remoteResource.codec));
|
|
210
210
|
}
|
|
211
211
|
return previous(details);
|
|
212
212
|
},
|
|
@@ -232,10 +232,10 @@ export const InflektPlugin = {
|
|
|
232
232
|
if (baseName) {
|
|
233
233
|
const oppositeBaseName = getOppositeBaseName(baseName);
|
|
234
234
|
if (oppositeBaseName) {
|
|
235
|
-
return
|
|
235
|
+
return toCamelCase(`${oppositeBaseName}_${this._singularizedCodecName(relation.remoteResource.codec)}`);
|
|
236
236
|
}
|
|
237
237
|
if (baseNameMatches(baseName, codec.name)) {
|
|
238
|
-
return
|
|
238
|
+
return toCamelCase(this._singularizedCodecName(relation.remoteResource.codec));
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
}
|
|
@@ -261,17 +261,17 @@ export const InflektPlugin = {
|
|
|
261
261
|
if (baseName) {
|
|
262
262
|
const oppositeBaseName = getOppositeBaseName(baseName);
|
|
263
263
|
if (oppositeBaseName) {
|
|
264
|
-
return
|
|
264
|
+
return toCamelCase(`${oppositeBaseName}_${distinctPluralize(this._singularizedCodecName(relation.remoteResource.codec))}`);
|
|
265
265
|
}
|
|
266
266
|
if (baseNameMatches(baseName, codec.name)) {
|
|
267
|
-
return
|
|
267
|
+
return toCamelCase(distinctPluralize(this._singularizedCodecName(relation.remoteResource.codec)));
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
// Fall back to pluralized remote resource name
|
|
272
272
|
const pk = relation.remoteResource.uniques.find((u) => u.isPrimary);
|
|
273
273
|
if (pk && arraysMatch(pk.attributes, relation.remoteAttributes)) {
|
|
274
|
-
return
|
|
274
|
+
return toCamelCase(distinctPluralize(this._singularizedCodecName(relation.remoteResource.codec)));
|
|
275
275
|
}
|
|
276
276
|
return previous(details);
|
|
277
277
|
},
|
|
@@ -296,7 +296,7 @@ export const InflektPlugin = {
|
|
|
296
296
|
if (typeof baseOverride === 'string') {
|
|
297
297
|
return baseOverride;
|
|
298
298
|
}
|
|
299
|
-
const simpleName =
|
|
299
|
+
const simpleName = toCamelCase(distinctPluralize(this._singularizedCodecName(rightTable.codec)));
|
|
300
300
|
const leftRelations = leftTable.getRelations();
|
|
301
301
|
let hasDirectRelation = false;
|
|
302
302
|
let manyToManyCount = 0;
|
|
@@ -331,7 +331,7 @@ export const InflektPlugin = {
|
|
|
331
331
|
return unique.extensions?.tags?.fieldName;
|
|
332
332
|
}
|
|
333
333
|
if (unique.isPrimary) {
|
|
334
|
-
return
|
|
334
|
+
return toCamelCase(this._singularizedCodecName(resource.codec));
|
|
335
335
|
}
|
|
336
336
|
return previous(details);
|
|
337
337
|
},
|
|
@@ -344,7 +344,7 @@ export const InflektPlugin = {
|
|
|
344
344
|
return unique.extensions.tags.updateFieldName;
|
|
345
345
|
}
|
|
346
346
|
if (unique.isPrimary) {
|
|
347
|
-
return
|
|
347
|
+
return toCamelCase(`update_${this._singularizedCodecName(resource.codec)}`);
|
|
348
348
|
}
|
|
349
349
|
return previous(details);
|
|
350
350
|
},
|
|
@@ -357,7 +357,7 @@ export const InflektPlugin = {
|
|
|
357
357
|
return unique.extensions.tags.deleteFieldName;
|
|
358
358
|
}
|
|
359
359
|
if (unique.isPrimary) {
|
|
360
|
-
return
|
|
360
|
+
return toCamelCase(`delete_${this._singularizedCodecName(resource.codec)}`);
|
|
361
361
|
}
|
|
362
362
|
return previous(details);
|
|
363
363
|
},
|
|
@@ -12,12 +12,13 @@ export function buildBelongsToRelations(codec, attributes, uniques, relations, c
|
|
|
12
12
|
continue;
|
|
13
13
|
const localAttributes = relation.localAttributes || [];
|
|
14
14
|
const isUnique = uniques.some((unique) => sameAttributes(unique.attributes, localAttributes));
|
|
15
|
+
const remoteCodec = relation.remoteResource?.codec;
|
|
15
16
|
belongsTo.push({
|
|
16
17
|
fieldName: relationName,
|
|
17
18
|
isUnique,
|
|
18
|
-
type:
|
|
19
|
+
type: remoteCodec?.name || null,
|
|
19
20
|
keys: buildFieldList(localAttributes, codec, attributes, context),
|
|
20
|
-
references: { name:
|
|
21
|
+
references: { name: remoteCodec?.name || 'unknown' },
|
|
21
22
|
});
|
|
22
23
|
}
|
|
23
24
|
return belongsTo;
|
|
@@ -31,12 +32,13 @@ export function buildReverseRelations(codec, attributes, relations, context) {
|
|
|
31
32
|
const remoteUniques = getUniques(relation.remoteResource || {});
|
|
32
33
|
const remoteAttributes = relation.remoteAttributes || [];
|
|
33
34
|
const isUnique = remoteUniques.some((unique) => sameAttributes(unique.attributes, remoteAttributes));
|
|
35
|
+
const remoteCodec = relation.remoteResource?.codec;
|
|
34
36
|
const meta = {
|
|
35
37
|
fieldName: relationName,
|
|
36
38
|
isUnique,
|
|
37
|
-
type:
|
|
39
|
+
type: remoteCodec?.name || null,
|
|
38
40
|
keys: buildFieldList(relation.localAttributes || [], codec, attributes, context),
|
|
39
|
-
referencedBy: { name:
|
|
41
|
+
referencedBy: { name: remoteCodec?.name || 'unknown' },
|
|
40
42
|
};
|
|
41
43
|
if (isUnique) {
|
|
42
44
|
hasOne.push(meta);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-settings",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.15.1",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "graphile settings",
|
|
6
6
|
"main": "index.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"graphile-upload-plugin": "^2.4.4",
|
|
54
54
|
"graphile-utils": "5.0.0-rc.8",
|
|
55
55
|
"graphql": "16.13.0",
|
|
56
|
-
"inflekt": "^0.
|
|
56
|
+
"inflekt": "^0.5.1",
|
|
57
57
|
"lru-cache": "^11.2.7",
|
|
58
58
|
"pg": "^8.20.0",
|
|
59
59
|
"pg-query-context": "^2.8.3",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"constructive",
|
|
81
81
|
"graphql"
|
|
82
82
|
],
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "8366738765a5615ad279eec5b462a291020fef94"
|
|
84
84
|
}
|
|
@@ -46,7 +46,7 @@ function getBaseName(attributeName) {
|
|
|
46
46
|
*/
|
|
47
47
|
function baseNameMatches(baseName, otherName) {
|
|
48
48
|
const singularizedName = (0, inflekt_1.singularize)(otherName);
|
|
49
|
-
return (0, inflekt_1.
|
|
49
|
+
return (0, inflekt_1.toCamelCase)(baseName) === (0, inflekt_1.toCamelCase)(singularizedName);
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Get the opposite name for a relation base name
|
|
@@ -176,14 +176,14 @@ exports.InflektPlugin = {
|
|
|
176
176
|
*/
|
|
177
177
|
allRowsConnection(_previous, _options, resource) {
|
|
178
178
|
const resourceName = this._singularizedResourceName(resource);
|
|
179
|
-
return (0, inflekt_1.
|
|
179
|
+
return (0, inflekt_1.toCamelCase)((0, inflekt_1.distinctPluralize)(resourceName));
|
|
180
180
|
},
|
|
181
181
|
/**
|
|
182
182
|
* Simplify root query list fields
|
|
183
183
|
*/
|
|
184
184
|
allRowsList(_previous, _options, resource) {
|
|
185
185
|
const resourceName = this._singularizedResourceName(resource);
|
|
186
|
-
return (0, inflekt_1.
|
|
186
|
+
return (0, inflekt_1.toCamelCase)((0, inflekt_1.distinctPluralize)(resourceName)) + 'List';
|
|
187
187
|
},
|
|
188
188
|
/**
|
|
189
189
|
* Simplify single relation field names (userByAuthorId -> author)
|
|
@@ -202,14 +202,14 @@ exports.InflektPlugin = {
|
|
|
202
202
|
const attributeName = relation.localAttributes[0];
|
|
203
203
|
const baseName = getBaseName(attributeName);
|
|
204
204
|
if (baseName) {
|
|
205
|
-
return (0, inflekt_1.
|
|
205
|
+
return (0, inflekt_1.toCamelCase)(baseName);
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
// Fall back to the remote resource name
|
|
209
209
|
const foreignPk = relation.remoteResource.uniques.find((u) => u.isPrimary);
|
|
210
210
|
if (foreignPk &&
|
|
211
211
|
arraysMatch(foreignPk.attributes, relation.remoteAttributes)) {
|
|
212
|
-
return (0, inflekt_1.
|
|
212
|
+
return (0, inflekt_1.toCamelCase)(this._singularizedCodecName(relation.remoteResource.codec));
|
|
213
213
|
}
|
|
214
214
|
return previous(details);
|
|
215
215
|
},
|
|
@@ -235,10 +235,10 @@ exports.InflektPlugin = {
|
|
|
235
235
|
if (baseName) {
|
|
236
236
|
const oppositeBaseName = getOppositeBaseName(baseName);
|
|
237
237
|
if (oppositeBaseName) {
|
|
238
|
-
return (0, inflekt_1.
|
|
238
|
+
return (0, inflekt_1.toCamelCase)(`${oppositeBaseName}_${this._singularizedCodecName(relation.remoteResource.codec)}`);
|
|
239
239
|
}
|
|
240
240
|
if (baseNameMatches(baseName, codec.name)) {
|
|
241
|
-
return (0, inflekt_1.
|
|
241
|
+
return (0, inflekt_1.toCamelCase)(this._singularizedCodecName(relation.remoteResource.codec));
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
}
|
|
@@ -264,17 +264,17 @@ exports.InflektPlugin = {
|
|
|
264
264
|
if (baseName) {
|
|
265
265
|
const oppositeBaseName = getOppositeBaseName(baseName);
|
|
266
266
|
if (oppositeBaseName) {
|
|
267
|
-
return (0, inflekt_1.
|
|
267
|
+
return (0, inflekt_1.toCamelCase)(`${oppositeBaseName}_${(0, inflekt_1.distinctPluralize)(this._singularizedCodecName(relation.remoteResource.codec))}`);
|
|
268
268
|
}
|
|
269
269
|
if (baseNameMatches(baseName, codec.name)) {
|
|
270
|
-
return (0, inflekt_1.
|
|
270
|
+
return (0, inflekt_1.toCamelCase)((0, inflekt_1.distinctPluralize)(this._singularizedCodecName(relation.remoteResource.codec)));
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
274
|
// Fall back to pluralized remote resource name
|
|
275
275
|
const pk = relation.remoteResource.uniques.find((u) => u.isPrimary);
|
|
276
276
|
if (pk && arraysMatch(pk.attributes, relation.remoteAttributes)) {
|
|
277
|
-
return (0, inflekt_1.
|
|
277
|
+
return (0, inflekt_1.toCamelCase)((0, inflekt_1.distinctPluralize)(this._singularizedCodecName(relation.remoteResource.codec)));
|
|
278
278
|
}
|
|
279
279
|
return previous(details);
|
|
280
280
|
},
|
|
@@ -299,7 +299,7 @@ exports.InflektPlugin = {
|
|
|
299
299
|
if (typeof baseOverride === 'string') {
|
|
300
300
|
return baseOverride;
|
|
301
301
|
}
|
|
302
|
-
const simpleName = (0, inflekt_1.
|
|
302
|
+
const simpleName = (0, inflekt_1.toCamelCase)((0, inflekt_1.distinctPluralize)(this._singularizedCodecName(rightTable.codec)));
|
|
303
303
|
const leftRelations = leftTable.getRelations();
|
|
304
304
|
let hasDirectRelation = false;
|
|
305
305
|
let manyToManyCount = 0;
|
|
@@ -334,7 +334,7 @@ exports.InflektPlugin = {
|
|
|
334
334
|
return unique.extensions?.tags?.fieldName;
|
|
335
335
|
}
|
|
336
336
|
if (unique.isPrimary) {
|
|
337
|
-
return (0, inflekt_1.
|
|
337
|
+
return (0, inflekt_1.toCamelCase)(this._singularizedCodecName(resource.codec));
|
|
338
338
|
}
|
|
339
339
|
return previous(details);
|
|
340
340
|
},
|
|
@@ -347,7 +347,7 @@ exports.InflektPlugin = {
|
|
|
347
347
|
return unique.extensions.tags.updateFieldName;
|
|
348
348
|
}
|
|
349
349
|
if (unique.isPrimary) {
|
|
350
|
-
return (0, inflekt_1.
|
|
350
|
+
return (0, inflekt_1.toCamelCase)(`update_${this._singularizedCodecName(resource.codec)}`);
|
|
351
351
|
}
|
|
352
352
|
return previous(details);
|
|
353
353
|
},
|
|
@@ -360,7 +360,7 @@ exports.InflektPlugin = {
|
|
|
360
360
|
return unique.extensions.tags.deleteFieldName;
|
|
361
361
|
}
|
|
362
362
|
if (unique.isPrimary) {
|
|
363
|
-
return (0, inflekt_1.
|
|
363
|
+
return (0, inflekt_1.toCamelCase)(`delete_${this._singularizedCodecName(resource.codec)}`);
|
|
364
364
|
}
|
|
365
365
|
return previous(details);
|
|
366
366
|
},
|
|
@@ -17,12 +17,13 @@ function buildBelongsToRelations(codec, attributes, uniques, relations, context)
|
|
|
17
17
|
continue;
|
|
18
18
|
const localAttributes = relation.localAttributes || [];
|
|
19
19
|
const isUnique = uniques.some((unique) => (0, table_resource_utils_1.sameAttributes)(unique.attributes, localAttributes));
|
|
20
|
+
const remoteCodec = relation.remoteResource?.codec;
|
|
20
21
|
belongsTo.push({
|
|
21
22
|
fieldName: relationName,
|
|
22
23
|
isUnique,
|
|
23
|
-
type:
|
|
24
|
+
type: remoteCodec?.name || null,
|
|
24
25
|
keys: (0, table_meta_context_1.buildFieldList)(localAttributes, codec, attributes, context),
|
|
25
|
-
references: { name:
|
|
26
|
+
references: { name: remoteCodec?.name || 'unknown' },
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
return belongsTo;
|
|
@@ -36,12 +37,13 @@ function buildReverseRelations(codec, attributes, relations, context) {
|
|
|
36
37
|
const remoteUniques = (0, table_resource_utils_1.getUniques)(relation.remoteResource || {});
|
|
37
38
|
const remoteAttributes = relation.remoteAttributes || [];
|
|
38
39
|
const isUnique = remoteUniques.some((unique) => (0, table_resource_utils_1.sameAttributes)(unique.attributes, remoteAttributes));
|
|
40
|
+
const remoteCodec = relation.remoteResource?.codec;
|
|
39
41
|
const meta = {
|
|
40
42
|
fieldName: relationName,
|
|
41
43
|
isUnique,
|
|
42
|
-
type:
|
|
44
|
+
type: remoteCodec?.name || null,
|
|
43
45
|
keys: (0, table_meta_context_1.buildFieldList)(relation.localAttributes || [], codec, attributes, context),
|
|
44
|
-
referencedBy: { name:
|
|
46
|
+
referencedBy: { name: remoteCodec?.name || 'unknown' },
|
|
45
47
|
};
|
|
46
48
|
if (isUnique) {
|
|
47
49
|
hasOne.push(meta);
|