graphile-build-pg 5.0.0-beta.2 → 5.0.0-beta.21
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/CHANGELOG.md +535 -0
- package/README.md +6 -7
- package/dist/behavior.d.ts +0 -1
- package/dist/behavior.d.ts.map +1 -1
- package/dist/behavior.js +0 -1
- package/dist/behavior.js.map +1 -1
- package/dist/index.d.ts +84 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/plugins/PgAttributesPlugin.d.ts +0 -1
- package/dist/plugins/PgAttributesPlugin.d.ts.map +1 -1
- package/dist/plugins/PgAttributesPlugin.js +9 -11
- package/dist/plugins/PgAttributesPlugin.js.map +1 -1
- package/dist/plugins/PgBasicsPlugin.d.ts +20 -10
- package/dist/plugins/PgBasicsPlugin.d.ts.map +1 -1
- package/dist/plugins/PgBasicsPlugin.js +50 -2
- package/dist/plugins/PgBasicsPlugin.js.map +1 -1
- package/dist/plugins/PgCodecsPlugin.d.ts +6 -0
- package/dist/plugins/PgCodecsPlugin.d.ts.map +1 -1
- package/dist/plugins/PgCodecsPlugin.js +240 -211
- package/dist/plugins/PgCodecsPlugin.js.map +1 -1
- package/dist/plugins/PgConnectionArgOrderByPlugin.d.ts.map +1 -1
- package/dist/plugins/PgConnectionArgOrderByPlugin.js +3 -0
- package/dist/plugins/PgConnectionArgOrderByPlugin.js.map +1 -1
- package/dist/plugins/PgCustomTypeFieldPlugin.d.ts.map +1 -1
- package/dist/plugins/PgCustomTypeFieldPlugin.js +105 -40
- package/dist/plugins/PgCustomTypeFieldPlugin.js.map +1 -1
- package/dist/plugins/PgEnumTablesPlugin.d.ts +3 -0
- package/dist/plugins/PgEnumTablesPlugin.d.ts.map +1 -1
- package/dist/plugins/PgEnumTablesPlugin.js +49 -31
- package/dist/plugins/PgEnumTablesPlugin.js.map +1 -1
- package/dist/plugins/PgFakeConstraintsPlugin.js +3 -1
- package/dist/plugins/PgFakeConstraintsPlugin.js.map +1 -1
- package/dist/plugins/PgInterfaceModeUnionAllRowsPlugin.d.ts.map +1 -1
- package/dist/plugins/PgInterfaceModeUnionAllRowsPlugin.js +5 -76
- package/dist/plugins/PgInterfaceModeUnionAllRowsPlugin.js.map +1 -1
- package/dist/plugins/PgIntrospectionPlugin.d.ts.map +1 -1
- package/dist/plugins/PgIntrospectionPlugin.js +119 -104
- package/dist/plugins/PgIntrospectionPlugin.js.map +1 -1
- package/dist/plugins/PgLtreePlugin.d.ts +2 -0
- package/dist/plugins/PgLtreePlugin.d.ts.map +1 -0
- package/dist/plugins/PgLtreePlugin.js +66 -0
- package/dist/plugins/PgLtreePlugin.js.map +1 -0
- package/dist/plugins/PgMutationPayloadEdgePlugin.d.ts.map +1 -1
- package/dist/plugins/PgMutationPayloadEdgePlugin.js +2 -9
- package/dist/plugins/PgMutationPayloadEdgePlugin.js.map +1 -1
- package/dist/plugins/PgMutationUpdateDeletePlugin.d.ts.map +1 -1
- package/dist/plugins/PgMutationUpdateDeletePlugin.js +41 -39
- package/dist/plugins/PgMutationUpdateDeletePlugin.js.map +1 -1
- package/dist/plugins/PgNodeIdAttributesPlugin.d.ts +0 -1
- package/dist/plugins/PgNodeIdAttributesPlugin.d.ts.map +1 -1
- package/dist/plugins/PgNodeIdAttributesPlugin.js +32 -32
- package/dist/plugins/PgNodeIdAttributesPlugin.js.map +1 -1
- package/dist/plugins/PgOrderAllAttributesPlugin.d.ts.map +1 -1
- package/dist/plugins/PgOrderAllAttributesPlugin.js +2 -2
- package/dist/plugins/PgOrderAllAttributesPlugin.js.map +1 -1
- package/dist/plugins/PgOrderByPrimaryKeyPlugin.d.ts.map +1 -1
- package/dist/plugins/PgOrderByPrimaryKeyPlugin.js +5 -5
- package/dist/plugins/PgOrderByPrimaryKeyPlugin.js.map +1 -1
- package/dist/plugins/PgPolymorphismOnlyArgumentPlugin.d.ts +18 -0
- package/dist/plugins/PgPolymorphismOnlyArgumentPlugin.d.ts.map +1 -0
- package/dist/plugins/PgPolymorphismOnlyArgumentPlugin.js +136 -0
- package/dist/plugins/PgPolymorphismOnlyArgumentPlugin.js.map +1 -0
- package/dist/plugins/PgPolymorphismPlugin.d.ts +25 -1
- package/dist/plugins/PgPolymorphismPlugin.d.ts.map +1 -1
- package/dist/plugins/PgPolymorphismPlugin.js +335 -8
- package/dist/plugins/PgPolymorphismPlugin.js.map +1 -1
- package/dist/plugins/PgProceduresPlugin.d.ts.map +1 -1
- package/dist/plugins/PgProceduresPlugin.js +4 -2
- package/dist/plugins/PgProceduresPlugin.js.map +1 -1
- package/dist/plugins/PgRBACPlugin.d.ts.map +1 -1
- package/dist/plugins/PgRBACPlugin.js +7 -12
- package/dist/plugins/PgRBACPlugin.js.map +1 -1
- package/dist/plugins/PgRefsPlugin.d.ts.map +1 -1
- package/dist/plugins/PgRefsPlugin.js +9 -3
- package/dist/plugins/PgRefsPlugin.js.map +1 -1
- package/dist/plugins/PgRelationsPlugin.d.ts +8 -1
- package/dist/plugins/PgRelationsPlugin.d.ts.map +1 -1
- package/dist/plugins/PgRelationsPlugin.js +27 -14
- package/dist/plugins/PgRelationsPlugin.js.map +1 -1
- package/dist/plugins/PgRowByUniquePlugin.d.ts.map +1 -1
- package/dist/plugins/PgRowByUniquePlugin.js +1 -0
- package/dist/plugins/PgRowByUniquePlugin.js.map +1 -1
- package/dist/plugins/PgTableNodePlugin.d.ts.map +1 -1
- package/dist/plugins/PgTableNodePlugin.js +51 -33
- package/dist/plugins/PgTableNodePlugin.js.map +1 -1
- package/dist/plugins/PgTablesPlugin.d.ts.map +1 -1
- package/dist/plugins/PgTablesPlugin.js +28 -22
- package/dist/plugins/PgTablesPlugin.js.map +1 -1
- package/dist/plugins/PgTypesPlugin.d.ts +0 -1
- package/dist/plugins/PgTypesPlugin.d.ts.map +1 -1
- package/dist/plugins/PgTypesPlugin.js +6 -7
- package/dist/plugins/PgTypesPlugin.js.map +1 -1
- package/dist/preset.d.ts.map +1 -1
- package/dist/preset.js +6 -2
- package/dist/preset.js.map +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +63 -2
- package/dist/utils.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/watchFixtures.js +1 -1
- package/package.json +34 -33
- package/dist/interfaces.d.ts +0 -89
- package/dist/interfaces.d.ts.map +0 -1
- package/dist/interfaces.js +0 -3
- package/dist/interfaces.js.map +0 -1
- package/dist/pgServices.d.ts +0 -18
- package/dist/pgServices.d.ts.map +0 -1
- package/dist/pgServices.js +0 -133
- package/dist/pgServices.js.map +0 -1
- package/dist/plugins/PgContextPlugin.d.ts +0 -2
- package/dist/plugins/PgContextPlugin.d.ts.map +0 -1
- package/dist/plugins/PgContextPlugin.js +0 -52
- package/dist/plugins/PgContextPlugin.js.map +0 -1
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PgCodecsPlugin = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const pg_1 = require("@dataplan/pg");
|
|
6
5
|
const graphile_build_1 = require("graphile-build");
|
|
7
|
-
const pg_sql2_1 = tslib_1.__importDefault(require("pg-sql2"));
|
|
8
6
|
const utils_js_1 = require("../utils.js");
|
|
9
7
|
const version_js_1 = require("../version.js");
|
|
10
8
|
exports.PgCodecsPlugin = {
|
|
@@ -30,7 +28,10 @@ exports.PgCodecsPlugin = {
|
|
|
30
28
|
typeCodecName(options, { pgType, serviceName }) {
|
|
31
29
|
const pgNamespace = pgType.getNamespace();
|
|
32
30
|
const schemaPrefix = this._schemaPrefix({ pgNamespace, serviceName });
|
|
33
|
-
|
|
31
|
+
const name = pgType.typcategory === "A" && pgType.typname.startsWith("_")
|
|
32
|
+
? pgType.typname.substring(1) + "_array"
|
|
33
|
+
: pgType.typname;
|
|
34
|
+
return this.camelCase(`${schemaPrefix}${name}`);
|
|
34
35
|
},
|
|
35
36
|
scalarCodecTypeName(options, codec) {
|
|
36
37
|
return this.upperCamelCase(this.coerceToGraphQLName(codec.extensions?.tags?.name ?? codec.name));
|
|
@@ -204,6 +205,8 @@ exports.PgCodecsPlugin = {
|
|
|
204
205
|
const tags = Object.assign(Object.create(null), classTagsAndDescription.tags, typeTagsAndDescription.tags);
|
|
205
206
|
const description = typeTagsAndDescription.description ??
|
|
206
207
|
classTagsAndDescription.description;
|
|
208
|
+
// Do NOT mark `extensions` as `EXPORTABLE` otherwise changes
|
|
209
|
+
// implemented through hooks will not be represented in the export.
|
|
207
210
|
const extensions = {
|
|
208
211
|
oid: pgClass.reltype,
|
|
209
212
|
isTableLike: ["r", "v", "m", "f", "p"].includes(pgClass.relkind),
|
|
@@ -215,29 +218,25 @@ exports.PgCodecsPlugin = {
|
|
|
215
218
|
tags,
|
|
216
219
|
};
|
|
217
220
|
const executor = info.helpers.pgIntrospection.getExecutorForService(serviceName);
|
|
218
|
-
const
|
|
221
|
+
const sqlIdent = info.helpers.pgBasics.identifier(nspName, className);
|
|
222
|
+
(0, utils_js_1.exportNameHint)(sqlIdent, `${codecName}Identifier`);
|
|
223
|
+
(0, utils_js_1.exportNameHint)(attributes, `${codecName}Attributes`);
|
|
224
|
+
// Do NOT mark `spec` as `EXPORTABLE` otherwise the changes from
|
|
225
|
+
// `pgCodecs_recordType_spec` won't be represented in the export.
|
|
226
|
+
const spec = {
|
|
219
227
|
name: codecName,
|
|
220
|
-
identifier:
|
|
228
|
+
identifier: sqlIdent,
|
|
221
229
|
attributes,
|
|
222
230
|
description,
|
|
223
231
|
extensions,
|
|
224
232
|
executor,
|
|
225
|
-
}
|
|
226
|
-
attributes,
|
|
227
|
-
className,
|
|
228
|
-
codecName,
|
|
229
|
-
description,
|
|
230
|
-
executor,
|
|
231
|
-
extensions,
|
|
232
|
-
nspName,
|
|
233
|
-
pg_sql2_1.default,
|
|
234
|
-
]);
|
|
233
|
+
};
|
|
235
234
|
await info.process("pgCodecs_recordType_spec", {
|
|
236
235
|
serviceName,
|
|
237
236
|
pgClass,
|
|
238
237
|
spec,
|
|
239
238
|
});
|
|
240
|
-
const codec = (0, graphile_build_1.EXPORTABLE)((recordCodec, spec) => recordCodec(spec), [pg_1.recordCodec, spec]);
|
|
239
|
+
const codec = (0, graphile_build_1.EXPORTABLE)((recordCodec, spec) => recordCodec(spec), [pg_1.recordCodec, spec], `${spec.name}Codec`);
|
|
241
240
|
await info.process("pgCodecs_PgCodec", {
|
|
242
241
|
pgCodec: codec,
|
|
243
242
|
pgType: pgClass.getType(),
|
|
@@ -263,47 +262,217 @@ exports.PgCodecsPlugin = {
|
|
|
263
262
|
if (!type) {
|
|
264
263
|
return null;
|
|
265
264
|
}
|
|
266
|
-
const citextExt = await info.helpers.pgIntrospection.getExtensionByName(serviceName, "citext");
|
|
267
|
-
const hstoreExt = await info.helpers.pgIntrospection.getExtensionByName(serviceName, "hstore");
|
|
268
|
-
const pgCatalog = await info.helpers.pgIntrospection.getNamespaceByName(serviceName, "pg_catalog");
|
|
269
|
-
if (!pgCatalog) {
|
|
270
|
-
return null;
|
|
271
|
-
}
|
|
272
265
|
// Class types are handled via getCodecFromClass (they have to add attributes)
|
|
273
266
|
if (type.typtype === "c") {
|
|
274
267
|
return info.helpers.pgCodecs.getCodecFromClass(serviceName, type.typrelid);
|
|
275
268
|
}
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
269
|
+
const event = {
|
|
270
|
+
pgCodec: null,
|
|
271
|
+
pgType: type,
|
|
272
|
+
typeModifier,
|
|
273
|
+
serviceName,
|
|
274
|
+
};
|
|
275
|
+
await info.process("pgCodecs_findPgCodec", event);
|
|
276
|
+
if (event.pgCodec) {
|
|
277
|
+
const codec = event.pgCodec;
|
|
278
|
+
// Be careful not to call this for class codecs!
|
|
279
|
+
await info.process("pgCodecs_PgCodec", {
|
|
280
|
+
pgCodec: codec,
|
|
281
|
+
pgType: type,
|
|
282
|
+
serviceName,
|
|
283
|
+
});
|
|
284
|
+
return codec;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
console.dir(event);
|
|
288
|
+
console.warn(`Could not build PgCodec for '${type.getNamespace()?.nspname ?? "??"}.${type.typname}'; maybe you need a plugin implementing gather.hooks.pgCodecs_findPgCodec to add support.`);
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
})();
|
|
292
|
+
map.set(typeId, promise);
|
|
293
|
+
return promise;
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
hooks: {
|
|
297
|
+
async pgCodecs_findPgCodec(info, event) {
|
|
298
|
+
if (event.pgCodec) {
|
|
299
|
+
// Another plugin has already supplied a codec; skip
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const { serviceName, pgType: type, typeModifier } = event;
|
|
303
|
+
const namespace = type.getNamespace();
|
|
304
|
+
if (!namespace) {
|
|
305
|
+
throw new Error(`Could not get namespace '${type.typnamespace}'`);
|
|
306
|
+
}
|
|
307
|
+
const namespaceName = namespace.nspname;
|
|
308
|
+
const pgCatalog = await info.helpers.pgIntrospection.getNamespaceByName(serviceName, "pg_catalog");
|
|
309
|
+
if (!pgCatalog) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
// For the standard pg_catalog types, we have standard handling.
|
|
313
|
+
// (In v4 we used OIDs for this, but using the name is safer for PostgreSQL-likes.)
|
|
314
|
+
if (type.typnamespace == pgCatalog._id) {
|
|
315
|
+
const knownType = (0, pg_1.getCodecByPgCatalogTypeName)(type.typname);
|
|
316
|
+
if (knownType) {
|
|
317
|
+
event.pgCodec = knownType;
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const citextExt = await info.helpers.pgIntrospection.getExtensionByName(serviceName, "citext");
|
|
322
|
+
const hstoreExt = await info.helpers.pgIntrospection.getExtensionByName(serviceName, "hstore");
|
|
323
|
+
if (type.typname === "citext" &&
|
|
324
|
+
type.typnamespace === citextExt?.extnamespace) {
|
|
325
|
+
event.pgCodec = pg_1.TYPES.citext;
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
else if (type.typname === "hstore" &&
|
|
329
|
+
type.typnamespace === hstoreExt?.extnamespace) {
|
|
330
|
+
event.pgCodec = pg_1.TYPES.hstore;
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
// Enum type
|
|
334
|
+
if (type.typtype === "e") {
|
|
335
|
+
const enumValues = await info.helpers.pgIntrospection.getEnumsForType(serviceName, type._id);
|
|
336
|
+
const typeName = type.typname;
|
|
337
|
+
const codecName = info.inflection.typeCodecName({
|
|
338
|
+
pgType: type,
|
|
339
|
+
serviceName,
|
|
340
|
+
});
|
|
341
|
+
const enumLabels = enumValues.map((e) => e.enumlabel);
|
|
342
|
+
const { tags, description } = type.getTagsAndDescription();
|
|
343
|
+
const extensions = {
|
|
344
|
+
oid: type._id,
|
|
345
|
+
pg: {
|
|
346
|
+
serviceName,
|
|
347
|
+
schemaName: type.getNamespace().nspname,
|
|
348
|
+
name: type.typname,
|
|
349
|
+
},
|
|
350
|
+
tags,
|
|
351
|
+
};
|
|
352
|
+
await info.process("pgCodecs_enumType_extensions", {
|
|
353
|
+
serviceName,
|
|
354
|
+
pgType: type,
|
|
355
|
+
extensions,
|
|
356
|
+
});
|
|
357
|
+
const sqlIdent = info.helpers.pgBasics.identifier(namespaceName, typeName);
|
|
358
|
+
event.pgCodec = (0, graphile_build_1.EXPORTABLE)((codecName, description, enumCodec, enumLabels, extensions, sqlIdent) => enumCodec({
|
|
359
|
+
name: codecName,
|
|
360
|
+
identifier: sqlIdent,
|
|
361
|
+
values: enumLabels,
|
|
362
|
+
description,
|
|
363
|
+
extensions,
|
|
364
|
+
}), [
|
|
365
|
+
codecName,
|
|
366
|
+
description,
|
|
367
|
+
pg_1.enumCodec,
|
|
368
|
+
enumLabels,
|
|
369
|
+
extensions,
|
|
370
|
+
sqlIdent,
|
|
371
|
+
], `${codecName}Codec`);
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
// Range type
|
|
375
|
+
if (type.typtype === "r") {
|
|
376
|
+
const range = await info.helpers.pgIntrospection.getRangeByType(serviceName, type._id);
|
|
377
|
+
if (!range) {
|
|
378
|
+
throw new Error(`Failed to get range entry related to '${type._id}'`);
|
|
379
|
+
}
|
|
380
|
+
const innerCodec = (await info.helpers.pgCodecs.getCodecFromType(serviceName, range.rngsubtype));
|
|
381
|
+
const namespaceName = namespace.nspname;
|
|
382
|
+
const typeName = type.typname;
|
|
383
|
+
if (!innerCodec) {
|
|
384
|
+
console.warn(`PgCodec could not build codec for '${namespaceName}.${typeName}', we don't know how to process the subtype`);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const codecName = info.inflection.typeCodecName({
|
|
388
|
+
pgType: type,
|
|
389
|
+
serviceName,
|
|
390
|
+
});
|
|
391
|
+
const { tags, description } = type.getTagsAndDescription();
|
|
392
|
+
const extensions = {
|
|
393
|
+
oid: type._id,
|
|
394
|
+
pg: {
|
|
395
|
+
serviceName,
|
|
396
|
+
schemaName: type.getNamespace().nspname,
|
|
397
|
+
name: type.typname,
|
|
398
|
+
},
|
|
399
|
+
tags,
|
|
400
|
+
};
|
|
401
|
+
await info.process("pgCodecs_rangeOfCodec_extensions", {
|
|
402
|
+
serviceName,
|
|
403
|
+
pgType: type,
|
|
404
|
+
innerCodec,
|
|
405
|
+
extensions,
|
|
406
|
+
});
|
|
407
|
+
const sqlIdent = info.helpers.pgBasics.identifier(namespaceName, typeName);
|
|
408
|
+
event.pgCodec = (0, graphile_build_1.EXPORTABLE)((codecName, description, extensions, innerCodec, rangeOfCodec, sqlIdent) => rangeOfCodec(innerCodec, codecName, sqlIdent, {
|
|
409
|
+
description,
|
|
410
|
+
extensions,
|
|
411
|
+
}), [
|
|
412
|
+
codecName,
|
|
413
|
+
description,
|
|
414
|
+
extensions,
|
|
415
|
+
innerCodec,
|
|
416
|
+
pg_1.rangeOfCodec,
|
|
417
|
+
sqlIdent,
|
|
418
|
+
], `${codecName}Codec`);
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
// Domains are wrappers under an underlying type
|
|
422
|
+
if (type.typtype === "d") {
|
|
423
|
+
const { typnotnull: notNull, typbasetype: baseTypeOid, typtypmod: baseTypeModifier, typndims: _numberOfArrayDimensions, typcollation: _domainCollation, typdefaultbin: _defaultValueNodeTree, } = type;
|
|
424
|
+
const innerCodec = baseTypeOid
|
|
425
|
+
? await info.helpers.pgCodecs.getCodecFromType(serviceName, baseTypeOid, baseTypeModifier)
|
|
426
|
+
: null;
|
|
427
|
+
const namespaceName = namespace.nspname;
|
|
428
|
+
const typeName = type.typname;
|
|
429
|
+
if (innerCodec) {
|
|
430
|
+
const { tags, description } = type.getTagsAndDescription();
|
|
431
|
+
const extensions = {
|
|
432
|
+
oid: type._id,
|
|
433
|
+
pg: {
|
|
304
434
|
serviceName,
|
|
305
|
-
|
|
306
|
-
|
|
435
|
+
schemaName: type.getNamespace().nspname,
|
|
436
|
+
name: type.typname,
|
|
437
|
+
},
|
|
438
|
+
tags,
|
|
439
|
+
};
|
|
440
|
+
await info.process("pgCodecs_domainOfCodec_extensions", {
|
|
441
|
+
serviceName,
|
|
442
|
+
pgType: type,
|
|
443
|
+
innerCodec,
|
|
444
|
+
extensions,
|
|
445
|
+
});
|
|
446
|
+
const codecName = info.inflection.typeCodecName({
|
|
447
|
+
pgType: type,
|
|
448
|
+
serviceName,
|
|
449
|
+
});
|
|
450
|
+
const sqlIdent = info.helpers.pgBasics.identifier(namespaceName, typeName);
|
|
451
|
+
(0, utils_js_1.exportNameHint)(sqlIdent, `${codecName}Identifier`);
|
|
452
|
+
event.pgCodec = (0, graphile_build_1.EXPORTABLE)((codecName, description, domainOfCodec, extensions, innerCodec, notNull, sqlIdent) => domainOfCodec(innerCodec, codecName, sqlIdent, {
|
|
453
|
+
description,
|
|
454
|
+
extensions,
|
|
455
|
+
notNull,
|
|
456
|
+
}), [
|
|
457
|
+
codecName,
|
|
458
|
+
description,
|
|
459
|
+
pg_1.domainOfCodec,
|
|
460
|
+
extensions,
|
|
461
|
+
innerCodec,
|
|
462
|
+
notNull,
|
|
463
|
+
sqlIdent,
|
|
464
|
+
], `${codecName}Codec`);
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
// Array types are just listOfCodec() of their inner type
|
|
469
|
+
if (type.typcategory === "A") {
|
|
470
|
+
const innerType = await info.helpers.pgIntrospection.getTypeByArray(serviceName, type._id);
|
|
471
|
+
if (innerType) {
|
|
472
|
+
const innerCodec = (await info.helpers.pgCodecs.getCodecFromType(serviceName, innerType._id, typeModifier));
|
|
473
|
+
if (innerCodec) {
|
|
474
|
+
const typeDelim = innerType.typdelim;
|
|
475
|
+
const { tags, description } = type.getTagsAndDescription();
|
|
307
476
|
const extensions = {
|
|
308
477
|
oid: type._id,
|
|
309
478
|
pg: {
|
|
@@ -311,179 +480,38 @@ exports.PgCodecsPlugin = {
|
|
|
311
480
|
schemaName: type.getNamespace().nspname,
|
|
312
481
|
name: type.typname,
|
|
313
482
|
},
|
|
314
|
-
tags
|
|
483
|
+
tags,
|
|
315
484
|
};
|
|
316
|
-
await info.process("
|
|
485
|
+
await info.process("pgCodecs_listOfCodec_extensions", {
|
|
317
486
|
serviceName,
|
|
318
487
|
pgType: type,
|
|
488
|
+
innerCodec,
|
|
319
489
|
extensions,
|
|
320
490
|
});
|
|
321
|
-
|
|
322
|
-
name: codecName,
|
|
323
|
-
identifier: sql.identifier(namespaceName, typeName),
|
|
324
|
-
values: enumLabels,
|
|
325
|
-
extensions,
|
|
326
|
-
}), [
|
|
327
|
-
codecName,
|
|
328
|
-
pg_1.enumCodec,
|
|
329
|
-
enumLabels,
|
|
330
|
-
extensions,
|
|
331
|
-
namespaceName,
|
|
332
|
-
pg_sql2_1.default,
|
|
333
|
-
typeName,
|
|
334
|
-
]);
|
|
335
|
-
}
|
|
336
|
-
// Range type
|
|
337
|
-
if (type.typtype === "r") {
|
|
338
|
-
const range = await info.helpers.pgIntrospection.getRangeByType(serviceName, type._id);
|
|
339
|
-
if (!range) {
|
|
340
|
-
throw new Error(`Failed to get range entry related to '${type._id}'`);
|
|
341
|
-
}
|
|
342
|
-
const innerCodec = (await info.helpers.pgCodecs.getCodecFromType(serviceName, range.rngsubtype));
|
|
343
|
-
const namespaceName = namespace.nspname;
|
|
344
|
-
const typeName = type.typname;
|
|
345
|
-
if (!innerCodec) {
|
|
346
|
-
console.warn(`PgCodec could not build codec for '${namespaceName}.${typeName}', we don't know how to process the subtype`);
|
|
347
|
-
return null;
|
|
348
|
-
}
|
|
349
|
-
const codecName = info.inflection.typeCodecName({
|
|
491
|
+
const name = info.inflection.typeCodecName({
|
|
350
492
|
pgType: type,
|
|
351
493
|
serviceName,
|
|
352
494
|
});
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
oid: type._id,
|
|
356
|
-
pg: {
|
|
357
|
-
serviceName,
|
|
358
|
-
schemaName: type.getNamespace().nspname,
|
|
359
|
-
name: type.typname,
|
|
360
|
-
},
|
|
361
|
-
tags,
|
|
362
|
-
};
|
|
363
|
-
await info.process("pgCodecs_rangeOfCodec_extensions", {
|
|
364
|
-
serviceName,
|
|
365
|
-
pgType: type,
|
|
366
|
-
innerCodec,
|
|
495
|
+
(0, utils_js_1.exportNameHint)(extensions, `${name}CodecExtensions`);
|
|
496
|
+
event.pgCodec = (0, graphile_build_1.EXPORTABLE)((description, extensions, innerCodec, listOfCodec, name, typeDelim) => listOfCodec(innerCodec, {
|
|
367
497
|
extensions,
|
|
368
|
-
|
|
369
|
-
return (0, graphile_build_1.EXPORTABLE)((codecName, description, extensions, innerCodec, namespaceName, rangeOfCodec, sql, typeName) => rangeOfCodec(innerCodec, codecName, sql.identifier(namespaceName, typeName), {
|
|
498
|
+
typeDelim,
|
|
370
499
|
description,
|
|
371
|
-
|
|
500
|
+
name,
|
|
372
501
|
}), [
|
|
373
|
-
codecName,
|
|
374
502
|
description,
|
|
375
503
|
extensions,
|
|
376
504
|
innerCodec,
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
// Domains are wrappers under an underlying type
|
|
384
|
-
if (type.typtype === "d") {
|
|
385
|
-
const { typnotnull: notNull, typbasetype: baseTypeOid, typtypmod: baseTypeModifier, typndims: _numberOfArrayDimensions, typcollation: _domainCollation, typdefaultbin: _defaultValueNodeTree, } = type;
|
|
386
|
-
const innerCodec = baseTypeOid
|
|
387
|
-
? await info.helpers.pgCodecs.getCodecFromType(serviceName, baseTypeOid, baseTypeModifier)
|
|
388
|
-
: null;
|
|
389
|
-
const namespaceName = namespace.nspname;
|
|
390
|
-
const typeName = type.typname;
|
|
391
|
-
if (innerCodec) {
|
|
392
|
-
const { tags, description } = type.getTagsAndDescription();
|
|
393
|
-
const extensions = {
|
|
394
|
-
oid: type._id,
|
|
395
|
-
pg: {
|
|
396
|
-
serviceName,
|
|
397
|
-
schemaName: type.getNamespace().nspname,
|
|
398
|
-
name: type.typname,
|
|
399
|
-
},
|
|
400
|
-
tags,
|
|
401
|
-
};
|
|
402
|
-
await info.process("pgCodecs_domainOfCodec_extensions", {
|
|
403
|
-
serviceName,
|
|
404
|
-
pgType: type,
|
|
405
|
-
innerCodec,
|
|
406
|
-
extensions,
|
|
407
|
-
});
|
|
408
|
-
const codecName = info.inflection.typeCodecName({
|
|
409
|
-
pgType: type,
|
|
410
|
-
serviceName,
|
|
411
|
-
});
|
|
412
|
-
return (0, graphile_build_1.EXPORTABLE)((codecName, description, domainOfCodec, extensions, innerCodec, namespaceName, notNull, sql, typeName) => domainOfCodec(innerCodec, codecName, sql.identifier(namespaceName, typeName), {
|
|
413
|
-
description,
|
|
414
|
-
extensions,
|
|
415
|
-
notNull,
|
|
416
|
-
}), [
|
|
417
|
-
codecName,
|
|
418
|
-
description,
|
|
419
|
-
pg_1.domainOfCodec,
|
|
420
|
-
extensions,
|
|
421
|
-
innerCodec,
|
|
422
|
-
namespaceName,
|
|
423
|
-
notNull,
|
|
424
|
-
pg_sql2_1.default,
|
|
425
|
-
typeName,
|
|
426
|
-
]);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
// Array types are just listOfCodec() of their inner type
|
|
430
|
-
if (type.typcategory === "A") {
|
|
431
|
-
const innerType = await info.helpers.pgIntrospection.getTypeByArray(serviceName, type._id);
|
|
432
|
-
if (innerType) {
|
|
433
|
-
const innerCodec = (await info.helpers.pgCodecs.getCodecFromType(serviceName, innerType._id, typeModifier));
|
|
434
|
-
if (innerCodec) {
|
|
435
|
-
const typeDelim = innerType.typdelim;
|
|
436
|
-
const { tags, description } = type.getTagsAndDescription();
|
|
437
|
-
const extensions = {
|
|
438
|
-
oid: type._id,
|
|
439
|
-
pg: {
|
|
440
|
-
serviceName,
|
|
441
|
-
schemaName: type.getNamespace().nspname,
|
|
442
|
-
name: type.typname,
|
|
443
|
-
},
|
|
444
|
-
tags,
|
|
445
|
-
};
|
|
446
|
-
await info.process("pgCodecs_listOfCodec_extensions", {
|
|
447
|
-
serviceName,
|
|
448
|
-
pgType: type,
|
|
449
|
-
innerCodec,
|
|
450
|
-
extensions,
|
|
451
|
-
});
|
|
452
|
-
return (0, graphile_build_1.EXPORTABLE)((description, extensions, innerCodec, listOfCodec, typeDelim) => listOfCodec(innerCodec, {
|
|
453
|
-
extensions,
|
|
454
|
-
typeDelim,
|
|
455
|
-
description,
|
|
456
|
-
}), [
|
|
457
|
-
description,
|
|
458
|
-
extensions,
|
|
459
|
-
innerCodec,
|
|
460
|
-
pg_1.listOfCodec,
|
|
461
|
-
typeDelim,
|
|
462
|
-
]);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
console.warn(`Could not build PgCodec for '${namespaceName}.${type.typname}' due to issue with getting codec for underlying type`);
|
|
466
|
-
return null;
|
|
505
|
+
pg_1.listOfCodec,
|
|
506
|
+
name,
|
|
507
|
+
typeDelim,
|
|
508
|
+
], `${name}Codec`);
|
|
509
|
+
return;
|
|
467
510
|
}
|
|
468
|
-
// TODO: basic type support
|
|
469
|
-
console.warn(`Don't understand how to build type for ${type.typname}`);
|
|
470
|
-
return null;
|
|
471
|
-
})();
|
|
472
|
-
if (codec) {
|
|
473
|
-
// Be careful not to call this for class codecs!
|
|
474
|
-
await info.process("pgCodecs_PgCodec", {
|
|
475
|
-
pgCodec: codec,
|
|
476
|
-
pgType: type,
|
|
477
|
-
serviceName,
|
|
478
|
-
});
|
|
479
511
|
}
|
|
480
|
-
return
|
|
481
|
-
}
|
|
482
|
-
map.set(typeId, promise);
|
|
483
|
-
return promise;
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
484
514
|
},
|
|
485
|
-
},
|
|
486
|
-
hooks: {
|
|
487
515
|
async pgRegistry_PgRegistryBuilder_pgCodecs(info, event) {
|
|
488
516
|
const { registryBuilder } = event;
|
|
489
517
|
const codecs = new Set();
|
|
@@ -849,8 +877,9 @@ exports.PgCodecsPlugin = {
|
|
|
849
877
|
else if (codec.domainOfCodec) {
|
|
850
878
|
// We just want to be a copy of the underlying type spec, but with a different name/description
|
|
851
879
|
const copy = (underlyingTypeName) => () => {
|
|
852
|
-
const
|
|
853
|
-
const
|
|
880
|
+
const details = build.getTypeMetaByName(underlyingTypeName);
|
|
881
|
+
const baseConfig = details?.specGenerator();
|
|
882
|
+
const config = { ...baseConfig };
|
|
854
883
|
delete config.name;
|
|
855
884
|
delete config.description;
|
|
856
885
|
return config;
|
|
@@ -916,7 +945,7 @@ exports.PgCodecsPlugin = {
|
|
|
916
945
|
else {
|
|
917
946
|
// We have no idea what this is or how to handle it.
|
|
918
947
|
// TODO: add some default handling, like "behavesLike = TYPES.text"?
|
|
919
|
-
console.warn(`PgCodec '${codec.name}'
|
|
948
|
+
console.warn(`Do not know how to convert PgCodec '${codec.name}' into a GraphQL type; please use \`build.setGraphQLTypeForPgCodec(codec, mode, typeName)\` inside \`plugin.schema.hooks.init\` for each mode/typeName combo you want to support.`);
|
|
920
949
|
}
|
|
921
950
|
}
|
|
922
951
|
const visited = new Set();
|