graphile-settings 4.1.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.d.ts +1 -2
- package/esm/index.js +2 -4
- package/esm/plugins/index.d.ts +4 -13
- package/esm/plugins/index.js +5 -21
- package/esm/presets/constructive-preset.d.ts +4 -0
- package/esm/presets/constructive-preset.js +17 -9
- package/esm/upload-resolver.d.ts +43 -0
- package/esm/upload-resolver.js +168 -0
- package/index.d.ts +1 -2
- package/index.js +4 -7
- package/package.json +26 -14
- package/plugins/index.d.ts +4 -13
- package/plugins/index.js +32 -44
- package/presets/constructive-preset.d.ts +4 -0
- package/presets/constructive-preset.js +26 -18
- package/upload-resolver.d.ts +43 -0
- package/upload-resolver.js +175 -0
- package/esm/plugins/conflict-detector.d.ts +0 -7
- package/esm/plugins/conflict-detector.js +0 -67
- package/esm/plugins/custom-inflector.d.ts +0 -9
- package/esm/plugins/custom-inflector.js +0 -382
- package/esm/plugins/enable-all-filter-columns.d.ts +0 -60
- package/esm/plugins/enable-all-filter-columns.js +0 -85
- package/esm/plugins/inflector-logger.d.ts +0 -7
- package/esm/plugins/inflector-logger.js +0 -215
- package/esm/plugins/many-to-many-preset.d.ts +0 -62
- package/esm/plugins/many-to-many-preset.js +0 -86
- package/esm/plugins/meta-schema/cache.d.ts +0 -4
- package/esm/plugins/meta-schema/cache.js +0 -7
- package/esm/plugins/meta-schema/constraint-meta-builders.d.ts +0 -13
- package/esm/plugins/meta-schema/constraint-meta-builders.js +0 -51
- package/esm/plugins/meta-schema/graphql-meta-field.d.ts +0 -4
- package/esm/plugins/meta-schema/graphql-meta-field.js +0 -201
- package/esm/plugins/meta-schema/inflection-utils.d.ts +0 -4
- package/esm/plugins/meta-schema/inflection-utils.js +0 -20
- package/esm/plugins/meta-schema/name-meta-builders.d.ts +0 -4
- package/esm/plugins/meta-schema/name-meta-builders.js +0 -38
- package/esm/plugins/meta-schema/plugin.d.ts +0 -2
- package/esm/plugins/meta-schema/plugin.js +0 -23
- package/esm/plugins/meta-schema/relation-meta-builders.d.ts +0 -8
- package/esm/plugins/meta-schema/relation-meta-builders.js +0 -115
- package/esm/plugins/meta-schema/table-meta-builder.d.ts +0 -2
- package/esm/plugins/meta-schema/table-meta-builder.js +0 -69
- package/esm/plugins/meta-schema/table-meta-context.d.ts +0 -13
- package/esm/plugins/meta-schema/table-meta-context.js +0 -11
- package/esm/plugins/meta-schema/table-resource-utils.d.ts +0 -12
- package/esm/plugins/meta-schema/table-resource-utils.js +0 -50
- package/esm/plugins/meta-schema/type-mappings.d.ts +0 -3
- package/esm/plugins/meta-schema/type-mappings.js +0 -75
- package/esm/plugins/meta-schema/types.d.ts +0 -206
- package/esm/plugins/meta-schema/types.js +0 -1
- package/esm/plugins/meta-schema.d.ts +0 -19
- package/esm/plugins/meta-schema.js +0 -20
- package/esm/plugins/minimal-preset.d.ts +0 -7
- package/esm/plugins/minimal-preset.js +0 -42
- package/esm/plugins/pg-type-mappings.d.ts +0 -41
- package/esm/plugins/pg-type-mappings.js +0 -122
- package/esm/plugins/primary-key-only.d.ts +0 -96
- package/esm/plugins/primary-key-only.js +0 -143
- package/plugins/conflict-detector.d.ts +0 -7
- package/plugins/conflict-detector.js +0 -70
- package/plugins/custom-inflector.d.ts +0 -9
- package/plugins/custom-inflector.js +0 -385
- package/plugins/enable-all-filter-columns.d.ts +0 -60
- package/plugins/enable-all-filter-columns.js +0 -88
- package/plugins/inflector-logger.d.ts +0 -7
- package/plugins/inflector-logger.js +0 -218
- package/plugins/many-to-many-preset.d.ts +0 -62
- package/plugins/many-to-many-preset.js +0 -89
- package/plugins/meta-schema/cache.d.ts +0 -4
- package/plugins/meta-schema/cache.js +0 -12
- package/plugins/meta-schema/constraint-meta-builders.d.ts +0 -13
- package/plugins/meta-schema/constraint-meta-builders.js +0 -58
- package/plugins/meta-schema/graphql-meta-field.d.ts +0 -4
- package/plugins/meta-schema/graphql-meta-field.js +0 -204
- package/plugins/meta-schema/inflection-utils.d.ts +0 -4
- package/plugins/meta-schema/inflection-utils.js +0 -25
- package/plugins/meta-schema/name-meta-builders.d.ts +0 -4
- package/plugins/meta-schema/name-meta-builders.js +0 -43
- package/plugins/meta-schema/plugin.d.ts +0 -2
- package/plugins/meta-schema/plugin.js +0 -26
- package/plugins/meta-schema/relation-meta-builders.d.ts +0 -8
- package/plugins/meta-schema/relation-meta-builders.js +0 -120
- package/plugins/meta-schema/table-meta-builder.d.ts +0 -2
- package/plugins/meta-schema/table-meta-builder.js +0 -72
- package/plugins/meta-schema/table-meta-context.d.ts +0 -13
- package/plugins/meta-schema/table-meta-context.js +0 -15
- package/plugins/meta-schema/table-resource-utils.d.ts +0 -12
- package/plugins/meta-schema/table-resource-utils.js +0 -60
- package/plugins/meta-schema/type-mappings.d.ts +0 -3
- package/plugins/meta-schema/type-mappings.js +0 -79
- package/plugins/meta-schema/types.d.ts +0 -206
- package/plugins/meta-schema/types.js +0 -2
- package/plugins/meta-schema.d.ts +0 -19
- package/plugins/meta-schema.js +0 -20
- package/plugins/minimal-preset.d.ts +0 -7
- package/plugins/minimal-preset.js +0 -45
- package/plugins/pg-type-mappings.d.ts +0 -41
- package/plugins/pg-type-mappings.js +0 -128
- package/plugins/primary-key-only.d.ts +0 -96
- package/plugins/primary-key-only.js +0 -147
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { MetaInflection, PgCodec } from './types';
|
|
2
|
-
export declare function safeInflection<T>(fn: () => T, fallback: T): T;
|
|
3
|
-
export declare function createAttributeInflector(inflection: MetaInflection): (attrName: string, codec: PgCodec) => string;
|
|
4
|
-
export declare function fallbackTableType(codecName: string): string;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.safeInflection = safeInflection;
|
|
4
|
-
exports.createAttributeInflector = createAttributeInflector;
|
|
5
|
-
exports.fallbackTableType = fallbackTableType;
|
|
6
|
-
function safeInflection(fn, fallback) {
|
|
7
|
-
try {
|
|
8
|
-
return fn() ?? fallback;
|
|
9
|
-
}
|
|
10
|
-
catch {
|
|
11
|
-
return fallback;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
function createAttributeInflector(inflection) {
|
|
15
|
-
return (attrName, codec) => {
|
|
16
|
-
const attributeName = safeInflection(() => inflection._attributeName?.({ attributeName: attrName, codec }), attrName);
|
|
17
|
-
return safeInflection(() => inflection.camelCase?.(attributeName), attributeName);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function fallbackTableType(codecName) {
|
|
21
|
-
return codecName
|
|
22
|
-
.replace(/_/g, ' ')
|
|
23
|
-
.replace(/\b\w/g, (char) => char.toUpperCase())
|
|
24
|
-
.replace(/ /g, '');
|
|
25
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { InflectionMeta, MetaBuild, PgCodec, PgTableResource, PgUnique, QueryMeta } from './types';
|
|
2
|
-
export declare function resolveTableType(build: MetaBuild, codec: PgCodec): string;
|
|
3
|
-
export declare function buildInflectionMeta(resource: PgTableResource, tableType: string, build: MetaBuild): InflectionMeta;
|
|
4
|
-
export declare function buildQueryMeta(resource: PgTableResource, uniques: PgUnique[], tableType: string, build: MetaBuild): QueryMeta;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveTableType = resolveTableType;
|
|
4
|
-
exports.buildInflectionMeta = buildInflectionMeta;
|
|
5
|
-
exports.buildQueryMeta = buildQueryMeta;
|
|
6
|
-
const inflection_utils_1 = require("./inflection-utils");
|
|
7
|
-
function resolveTableType(build, codec) {
|
|
8
|
-
return (0, inflection_utils_1.safeInflection)(() => build.inflection.tableType(codec), (0, inflection_utils_1.fallbackTableType)(codec.name));
|
|
9
|
-
}
|
|
10
|
-
function buildInflectionMeta(resource, tableType, build) {
|
|
11
|
-
const inflection = build.inflection;
|
|
12
|
-
return {
|
|
13
|
-
tableType,
|
|
14
|
-
allRows: (0, inflection_utils_1.safeInflection)(() => inflection.allRows?.(resource), `${tableType.toLowerCase()}s`),
|
|
15
|
-
connection: (0, inflection_utils_1.safeInflection)(() => inflection.connectionType?.(tableType), `${tableType}Connection`),
|
|
16
|
-
edge: (0, inflection_utils_1.safeInflection)(() => inflection.edgeType?.(tableType), `${tableType}Edge`),
|
|
17
|
-
filterType: (0, inflection_utils_1.safeInflection)(() => inflection.filterType?.(tableType), `${tableType}Filter`),
|
|
18
|
-
orderByType: (0, inflection_utils_1.safeInflection)(() => inflection.orderByType?.(tableType), `${tableType}OrderBy`),
|
|
19
|
-
conditionType: (0, inflection_utils_1.safeInflection)(() => inflection.conditionType?.(tableType), `${tableType}Condition`),
|
|
20
|
-
patchType: (0, inflection_utils_1.safeInflection)(() => inflection.patchType?.(tableType), `${tableType}Patch`),
|
|
21
|
-
createInputType: (0, inflection_utils_1.safeInflection)(() => inflection.createInputType?.(resource), `Create${tableType}Input`),
|
|
22
|
-
createPayloadType: (0, inflection_utils_1.safeInflection)(() => inflection.createPayloadType?.(resource), `Create${tableType}Payload`),
|
|
23
|
-
updatePayloadType: (0, inflection_utils_1.safeInflection)(() => inflection.updatePayloadType?.(resource), `Update${tableType}Payload`),
|
|
24
|
-
deletePayloadType: (0, inflection_utils_1.safeInflection)(() => inflection.deletePayloadType?.(resource), `Delete${tableType}Payload`),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function buildQueryMeta(resource, uniques, tableType, build) {
|
|
28
|
-
const inflection = build.inflection;
|
|
29
|
-
const hasPrimaryKey = uniques.some((unique) => unique.isPrimary);
|
|
30
|
-
return {
|
|
31
|
-
all: (0, inflection_utils_1.safeInflection)(() => inflection.allRows?.(resource), `${tableType.toLowerCase()}s`),
|
|
32
|
-
one: hasPrimaryKey
|
|
33
|
-
? (0, inflection_utils_1.safeInflection)(() => inflection.tableFieldName?.(resource), tableType.toLowerCase())
|
|
34
|
-
: null,
|
|
35
|
-
create: (0, inflection_utils_1.safeInflection)(() => inflection.createField?.(resource), `create${tableType}`),
|
|
36
|
-
update: hasPrimaryKey
|
|
37
|
-
? (0, inflection_utils_1.safeInflection)(() => inflection.updateByKeys?.(resource), `update${tableType}`)
|
|
38
|
-
: null,
|
|
39
|
-
delete: hasPrimaryKey
|
|
40
|
-
? (0, inflection_utils_1.safeInflection)(() => inflection.deleteByKeys?.(resource), `delete${tableType}`)
|
|
41
|
-
: null,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MetaSchemaPlugin = void 0;
|
|
4
|
-
const cache_1 = require("./cache");
|
|
5
|
-
const graphql_meta_field_1 = require("./graphql-meta-field");
|
|
6
|
-
const table_meta_builder_1 = require("./table-meta-builder");
|
|
7
|
-
exports.MetaSchemaPlugin = {
|
|
8
|
-
name: 'MetaSchemaPlugin',
|
|
9
|
-
version: '1.0.0',
|
|
10
|
-
description: 'Exposes _meta query for database schema introspection',
|
|
11
|
-
schema: {
|
|
12
|
-
hooks: {
|
|
13
|
-
init(input, rawBuild) {
|
|
14
|
-
const build = rawBuild;
|
|
15
|
-
(0, cache_1.setCachedTablesMeta)((0, table_meta_builder_1.collectTablesMeta)(build));
|
|
16
|
-
return input;
|
|
17
|
-
},
|
|
18
|
-
GraphQLObjectType_fields(rawFields, _rawBuild, rawContext) {
|
|
19
|
-
const context = rawContext;
|
|
20
|
-
if (context.Self?.name !== 'Query')
|
|
21
|
-
return rawFields;
|
|
22
|
-
return (0, graphql_meta_field_1.extendQueryWithMetaField)(rawFields, (0, cache_1.getCachedTablesMeta)());
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type BuildContext } from './table-meta-context';
|
|
2
|
-
import type { BelongsToRelation, HasRelation, ManyToManyRelation, PgAttribute, PgCodec, PgRelation, PgTableResource, PgUnique } from './types';
|
|
3
|
-
export declare function buildBelongsToRelations(codec: PgCodec, attributes: Record<string, PgAttribute>, uniques: PgUnique[], relations: Record<string, PgRelation>, context: BuildContext): BelongsToRelation[];
|
|
4
|
-
export declare function buildReverseRelations(codec: PgCodec, attributes: Record<string, PgAttribute>, relations: Record<string, PgRelation>, context: BuildContext): {
|
|
5
|
-
hasOne: HasRelation[];
|
|
6
|
-
hasMany: HasRelation[];
|
|
7
|
-
};
|
|
8
|
-
export declare function buildManyToManyRelations(resource: PgTableResource, codec: PgCodec, context: BuildContext): ManyToManyRelation[];
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildBelongsToRelations = buildBelongsToRelations;
|
|
4
|
-
exports.buildReverseRelations = buildReverseRelations;
|
|
5
|
-
exports.buildManyToManyRelations = buildManyToManyRelations;
|
|
6
|
-
const inflection_utils_1 = require("./inflection-utils");
|
|
7
|
-
const constraint_meta_builders_1 = require("./constraint-meta-builders");
|
|
8
|
-
const table_meta_context_1 = require("./table-meta-context");
|
|
9
|
-
const table_resource_utils_1 = require("./table-resource-utils");
|
|
10
|
-
function isRecord(value) {
|
|
11
|
-
return typeof value === 'object' && value !== null;
|
|
12
|
-
}
|
|
13
|
-
function buildBelongsToRelations(codec, attributes, uniques, relations, context) {
|
|
14
|
-
const belongsTo = [];
|
|
15
|
-
for (const [relationName, relation] of Object.entries(relations)) {
|
|
16
|
-
if (relation.isReferencee !== false)
|
|
17
|
-
continue;
|
|
18
|
-
const localAttributes = relation.localAttributes || [];
|
|
19
|
-
const isUnique = uniques.some((unique) => (0, table_resource_utils_1.sameAttributes)(unique.attributes, localAttributes));
|
|
20
|
-
belongsTo.push({
|
|
21
|
-
fieldName: relationName,
|
|
22
|
-
isUnique,
|
|
23
|
-
type: relation.remoteResource?.codec?.name || null,
|
|
24
|
-
keys: (0, table_meta_context_1.buildFieldList)(localAttributes, codec, attributes, context),
|
|
25
|
-
references: { name: relation.remoteResource?.codec?.name || 'unknown' },
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return belongsTo;
|
|
29
|
-
}
|
|
30
|
-
function buildReverseRelations(codec, attributes, relations, context) {
|
|
31
|
-
const hasOne = [];
|
|
32
|
-
const hasMany = [];
|
|
33
|
-
for (const [relationName, relation] of Object.entries(relations)) {
|
|
34
|
-
if (relation.isReferencee !== true)
|
|
35
|
-
continue;
|
|
36
|
-
const remoteUniques = (0, table_resource_utils_1.getUniques)(relation.remoteResource || {});
|
|
37
|
-
const remoteAttributes = relation.remoteAttributes || [];
|
|
38
|
-
const isUnique = remoteUniques.some((unique) => (0, table_resource_utils_1.sameAttributes)(unique.attributes, remoteAttributes));
|
|
39
|
-
const meta = {
|
|
40
|
-
fieldName: relationName,
|
|
41
|
-
isUnique,
|
|
42
|
-
type: relation.remoteResource?.codec?.name || null,
|
|
43
|
-
keys: (0, table_meta_context_1.buildFieldList)(relation.localAttributes || [], codec, attributes, context),
|
|
44
|
-
referencedBy: { name: relation.remoteResource?.codec?.name || 'unknown' },
|
|
45
|
-
};
|
|
46
|
-
if (isUnique) {
|
|
47
|
-
hasOne.push(meta);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
hasMany.push(meta);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return { hasOne, hasMany };
|
|
54
|
-
}
|
|
55
|
-
function isManyToManyDetails(value) {
|
|
56
|
-
if (!isRecord(value))
|
|
57
|
-
return false;
|
|
58
|
-
return (isRecord(value.leftTable) &&
|
|
59
|
-
isRecord(value.junctionTable) &&
|
|
60
|
-
isRecord(value.rightTable) &&
|
|
61
|
-
typeof value.leftRelationName === 'string' &&
|
|
62
|
-
typeof value.rightRelationName === 'string');
|
|
63
|
-
}
|
|
64
|
-
function parseManyToManyRelationships(value) {
|
|
65
|
-
if (!Array.isArray(value))
|
|
66
|
-
return [];
|
|
67
|
-
return value.filter(isManyToManyDetails);
|
|
68
|
-
}
|
|
69
|
-
function getManyToManyRelationships(build, tableResource, codec) {
|
|
70
|
-
const relationshipsByResource = build.pgManyToManyRealtionshipsByResource;
|
|
71
|
-
if (!(relationshipsByResource instanceof Map))
|
|
72
|
-
return [];
|
|
73
|
-
const direct = parseManyToManyRelationships(relationshipsByResource.get(tableResource));
|
|
74
|
-
if (direct.length > 0)
|
|
75
|
-
return direct;
|
|
76
|
-
for (const [leftTable, relationships] of relationshipsByResource.entries()) {
|
|
77
|
-
const details = parseManyToManyRelationships(relationships);
|
|
78
|
-
if (details.length === 0 || !isRecord(leftTable))
|
|
79
|
-
continue;
|
|
80
|
-
if (leftTable.codec === codec) {
|
|
81
|
-
return details;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return [];
|
|
85
|
-
}
|
|
86
|
-
function buildManyToManyRelation(details, context) {
|
|
87
|
-
const leftCodec = (0, table_resource_utils_1.getResourceCodec)(details.leftTable);
|
|
88
|
-
const junctionCodec = (0, table_resource_utils_1.getResourceCodec)(details.junctionTable);
|
|
89
|
-
const rightCodec = (0, table_resource_utils_1.getResourceCodec)(details.rightTable);
|
|
90
|
-
if (!leftCodec || !junctionCodec || !rightCodec)
|
|
91
|
-
return null;
|
|
92
|
-
const leftRelation = (0, table_resource_utils_1.getRelation)(details.leftTable, details.leftRelationName);
|
|
93
|
-
const junctionRightRelation = (0, table_resource_utils_1.getRelation)(details.junctionTable, details.rightRelationName);
|
|
94
|
-
if (!leftRelation || !junctionRightRelation)
|
|
95
|
-
return null;
|
|
96
|
-
const leftJunctionAttributes = leftRelation.remoteAttributes || [];
|
|
97
|
-
const leftTableAttributes = leftRelation.localAttributes || [];
|
|
98
|
-
const rightJunctionAttributes = junctionRightRelation.localAttributes || [];
|
|
99
|
-
const rightTableAttributes = junctionRightRelation.remoteAttributes || [];
|
|
100
|
-
const relationFieldName = (0, inflection_utils_1.safeInflection)(() => context.build.inflection._manyToManyRelation?.(details), details.rightRelationName || rightCodec.name || null);
|
|
101
|
-
const junctionLeftConstraint = (0, constraint_meta_builders_1.buildForeignKeyConstraint)(details.leftRelationName || `${junctionCodec.name}_${leftCodec.name}_fkey`, junctionCodec, junctionCodec.attributes, leftJunctionAttributes, leftCodec, leftCodec.attributes, leftTableAttributes, context);
|
|
102
|
-
const junctionRightConstraint = (0, constraint_meta_builders_1.buildForeignKeyConstraint)(details.rightRelationName || `${junctionCodec.name}_${rightCodec.name}_fkey`, junctionCodec, junctionCodec.attributes, rightJunctionAttributes, rightCodec, rightCodec.attributes, rightTableAttributes, context);
|
|
103
|
-
return {
|
|
104
|
-
fieldName: relationFieldName,
|
|
105
|
-
type: rightCodec.name || null,
|
|
106
|
-
junctionTable: { name: junctionCodec.name || 'unknown' },
|
|
107
|
-
junctionLeftConstraint,
|
|
108
|
-
junctionLeftKeyAttributes: (0, table_meta_context_1.buildFieldList)(leftJunctionAttributes, junctionCodec, junctionCodec.attributes, context),
|
|
109
|
-
junctionRightConstraint,
|
|
110
|
-
junctionRightKeyAttributes: (0, table_meta_context_1.buildFieldList)(rightJunctionAttributes, junctionCodec, junctionCodec.attributes, context),
|
|
111
|
-
leftKeyAttributes: (0, table_meta_context_1.buildFieldList)(leftTableAttributes, leftCodec, leftCodec.attributes, context),
|
|
112
|
-
rightKeyAttributes: (0, table_meta_context_1.buildFieldList)(rightTableAttributes, rightCodec, rightCodec.attributes, context),
|
|
113
|
-
rightTable: { name: rightCodec.name || 'unknown' },
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
function buildManyToManyRelations(resource, codec, context) {
|
|
117
|
-
return getManyToManyRelationships(context.build, resource, codec)
|
|
118
|
-
.map((details) => buildManyToManyRelation(details, context))
|
|
119
|
-
.filter((relation) => relation !== null);
|
|
120
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.collectTablesMeta = collectTablesMeta;
|
|
4
|
-
const constraint_meta_builders_1 = require("./constraint-meta-builders");
|
|
5
|
-
const name_meta_builders_1 = require("./name-meta-builders");
|
|
6
|
-
const relation_meta_builders_1 = require("./relation-meta-builders");
|
|
7
|
-
const type_mappings_1 = require("./type-mappings");
|
|
8
|
-
const table_meta_context_1 = require("./table-meta-context");
|
|
9
|
-
const table_resource_utils_1 = require("./table-resource-utils");
|
|
10
|
-
function buildTableMeta(resource, schemaName, context) {
|
|
11
|
-
const codec = resource.codec;
|
|
12
|
-
const attributes = codec.attributes;
|
|
13
|
-
const uniques = (0, table_resource_utils_1.getUniques)(resource);
|
|
14
|
-
const relations = (0, table_resource_utils_1.getRelations)(resource);
|
|
15
|
-
const fields = Object.entries(attributes).map(([attrName, attr]) => (0, type_mappings_1.buildFieldMeta)(context.inflectAttr(attrName, codec), attr, context.build));
|
|
16
|
-
const indexes = (0, constraint_meta_builders_1.buildIndexes)(codec, attributes, uniques, context);
|
|
17
|
-
const primaryKey = (0, constraint_meta_builders_1.buildPrimaryKey)(codec, attributes, uniques, context);
|
|
18
|
-
const uniqueConstraints = (0, constraint_meta_builders_1.buildUniqueConstraints)(codec, attributes, uniques, context);
|
|
19
|
-
const foreignKeyConstraints = (0, constraint_meta_builders_1.buildForeignKeyConstraints)(codec, attributes, relations, context);
|
|
20
|
-
const constraints = {
|
|
21
|
-
primaryKey,
|
|
22
|
-
unique: uniqueConstraints,
|
|
23
|
-
foreignKey: foreignKeyConstraints,
|
|
24
|
-
};
|
|
25
|
-
const belongsTo = (0, relation_meta_builders_1.buildBelongsToRelations)(codec, attributes, uniques, relations, context);
|
|
26
|
-
const { hasOne, hasMany } = (0, relation_meta_builders_1.buildReverseRelations)(codec, attributes, relations, context);
|
|
27
|
-
const manyToMany = (0, relation_meta_builders_1.buildManyToManyRelations)(resource, codec, context);
|
|
28
|
-
const relationsMeta = {
|
|
29
|
-
belongsTo,
|
|
30
|
-
has: [...hasOne, ...hasMany],
|
|
31
|
-
hasOne,
|
|
32
|
-
hasMany,
|
|
33
|
-
manyToMany,
|
|
34
|
-
};
|
|
35
|
-
const tableType = (0, name_meta_builders_1.resolveTableType)(context.build, codec);
|
|
36
|
-
return {
|
|
37
|
-
name: tableType,
|
|
38
|
-
schemaName,
|
|
39
|
-
fields,
|
|
40
|
-
indexes,
|
|
41
|
-
constraints,
|
|
42
|
-
foreignKeyConstraints,
|
|
43
|
-
primaryKeyConstraints: primaryKey ? [primaryKey] : [],
|
|
44
|
-
uniqueConstraints,
|
|
45
|
-
relations: relationsMeta,
|
|
46
|
-
inflection: (0, name_meta_builders_1.buildInflectionMeta)(resource, tableType, context.build),
|
|
47
|
-
query: (0, name_meta_builders_1.buildQueryMeta)(resource, uniques, tableType, context.build),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function collectTablesMeta(build) {
|
|
51
|
-
const configuredSchemas = (0, table_resource_utils_1.getConfiguredSchemas)(build);
|
|
52
|
-
const context = (0, table_meta_context_1.createBuildContext)(build);
|
|
53
|
-
const seenCodecs = new Set();
|
|
54
|
-
const tablesMeta = [];
|
|
55
|
-
for (const resource of Object.values(build.input.pgRegistry.pgResources || {})) {
|
|
56
|
-
if (!(0, table_resource_utils_1.isTableResource)(resource))
|
|
57
|
-
continue;
|
|
58
|
-
const codec = resource.codec;
|
|
59
|
-
if (seenCodecs.has(codec))
|
|
60
|
-
continue;
|
|
61
|
-
seenCodecs.add(codec);
|
|
62
|
-
const schemaName = (0, table_resource_utils_1.getSchemaName)(resource);
|
|
63
|
-
if (!schemaName)
|
|
64
|
-
continue;
|
|
65
|
-
if (configuredSchemas.length > 0 &&
|
|
66
|
-
!configuredSchemas.includes(schemaName)) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
tablesMeta.push(buildTableMeta(resource, schemaName, context));
|
|
70
|
-
}
|
|
71
|
-
return tablesMeta;
|
|
72
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { FieldMeta, MetaBuild, PgAttribute, PgCodec, PgTableResource } from './types';
|
|
2
|
-
export type AttributeInflector = (attrName: string, codec: PgCodec) => string;
|
|
3
|
-
export interface BuildContext {
|
|
4
|
-
build: MetaBuild;
|
|
5
|
-
inflectAttr: AttributeInflector;
|
|
6
|
-
}
|
|
7
|
-
export type TableResourceWithCodec = PgTableResource & {
|
|
8
|
-
codec: PgCodec & {
|
|
9
|
-
attributes: Record<string, PgAttribute>;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
export declare function createBuildContext(build: MetaBuild): BuildContext;
|
|
13
|
-
export declare function buildFieldList(attrNames: string[], codec: PgCodec, attributes: Record<string, PgAttribute>, context: BuildContext): FieldMeta[];
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createBuildContext = createBuildContext;
|
|
4
|
-
exports.buildFieldList = buildFieldList;
|
|
5
|
-
const inflection_utils_1 = require("./inflection-utils");
|
|
6
|
-
const type_mappings_1 = require("./type-mappings");
|
|
7
|
-
function createBuildContext(build) {
|
|
8
|
-
return {
|
|
9
|
-
build,
|
|
10
|
-
inflectAttr: (0, inflection_utils_1.createAttributeInflector)(build.inflection),
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function buildFieldList(attrNames, codec, attributes, context) {
|
|
14
|
-
return attrNames.map((attrName) => (0, type_mappings_1.buildFieldMeta)(context.inflectAttr(attrName, codec), attributes[attrName], context.build));
|
|
15
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { MetaBuild, PgAttribute, PgCodec, PgRelation, PgTableResource, PgUnique } from './types';
|
|
2
|
-
import type { TableResourceWithCodec } from './table-meta-context';
|
|
3
|
-
export declare function isTableResource(resource: PgTableResource): resource is TableResourceWithCodec;
|
|
4
|
-
export declare function getSchemaName(resource: PgTableResource): string | null;
|
|
5
|
-
export declare function getUniques(resource: PgTableResource): PgUnique[];
|
|
6
|
-
export declare function getRelations(resource: PgTableResource): Record<string, PgRelation>;
|
|
7
|
-
export declare function getRelation(resource: PgTableResource, relationName: string): PgRelation | null;
|
|
8
|
-
export declare function sameAttributes(uniqueAttributes: string[] | undefined, relationAttributes: string[] | undefined): boolean;
|
|
9
|
-
export declare function getConfiguredSchemas(build: MetaBuild): string[];
|
|
10
|
-
export declare function getResourceCodec(resource: PgTableResource): (PgCodec & {
|
|
11
|
-
attributes: Record<string, PgAttribute>;
|
|
12
|
-
}) | null;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isTableResource = isTableResource;
|
|
4
|
-
exports.getSchemaName = getSchemaName;
|
|
5
|
-
exports.getUniques = getUniques;
|
|
6
|
-
exports.getRelations = getRelations;
|
|
7
|
-
exports.getRelation = getRelation;
|
|
8
|
-
exports.sameAttributes = sameAttributes;
|
|
9
|
-
exports.getConfiguredSchemas = getConfiguredSchemas;
|
|
10
|
-
exports.getResourceCodec = getResourceCodec;
|
|
11
|
-
function isRecord(value) {
|
|
12
|
-
return typeof value === 'object' && value !== null;
|
|
13
|
-
}
|
|
14
|
-
function isTableResource(resource) {
|
|
15
|
-
return (!!resource.codec &&
|
|
16
|
-
!resource.codec.isAnonymous &&
|
|
17
|
-
isRecord(resource.codec.attributes) &&
|
|
18
|
-
!resource.parameters &&
|
|
19
|
-
!resource.isVirtual &&
|
|
20
|
-
!resource.isUnique);
|
|
21
|
-
}
|
|
22
|
-
function getSchemaName(resource) {
|
|
23
|
-
const schemaName = resource.codec?.extensions?.pg?.schemaName;
|
|
24
|
-
if (typeof schemaName !== 'string' || schemaName.length === 0)
|
|
25
|
-
return null;
|
|
26
|
-
return schemaName;
|
|
27
|
-
}
|
|
28
|
-
function getUniques(resource) {
|
|
29
|
-
return Array.isArray(resource.uniques) ? resource.uniques : [];
|
|
30
|
-
}
|
|
31
|
-
function getRelations(resource) {
|
|
32
|
-
return resource.relations || resource.getRelations?.() || {};
|
|
33
|
-
}
|
|
34
|
-
function getRelation(resource, relationName) {
|
|
35
|
-
if (!relationName)
|
|
36
|
-
return null;
|
|
37
|
-
if (typeof resource.getRelation === 'function') {
|
|
38
|
-
return resource.getRelation(relationName) || null;
|
|
39
|
-
}
|
|
40
|
-
const relations = getRelations(resource);
|
|
41
|
-
return relations[relationName] || null;
|
|
42
|
-
}
|
|
43
|
-
function sameAttributes(uniqueAttributes, relationAttributes) {
|
|
44
|
-
if (!uniqueAttributes || !relationAttributes)
|
|
45
|
-
return false;
|
|
46
|
-
return (uniqueAttributes.length === relationAttributes.length &&
|
|
47
|
-
uniqueAttributes.every((attrName) => relationAttributes.includes(attrName)));
|
|
48
|
-
}
|
|
49
|
-
function getConfiguredSchemas(build) {
|
|
50
|
-
const pgSchemas = build.options?.pgSchemas;
|
|
51
|
-
if (!Array.isArray(pgSchemas))
|
|
52
|
-
return [];
|
|
53
|
-
return pgSchemas.filter((schemaName) => typeof schemaName === 'string');
|
|
54
|
-
}
|
|
55
|
-
function getResourceCodec(resource) {
|
|
56
|
-
const codec = resource.codec;
|
|
57
|
-
if (!codec?.attributes)
|
|
58
|
-
return null;
|
|
59
|
-
return codec;
|
|
60
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { FieldMeta, GqlTypeResolverBuild, PgAttribute } from './types';
|
|
2
|
-
export declare function pgTypeToGqlType(pgTypeName: string): string;
|
|
3
|
-
export declare function buildFieldMeta(name: string, attr: PgAttribute | null | undefined, build?: GqlTypeResolverBuild): FieldMeta;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pgTypeToGqlType = pgTypeToGqlType;
|
|
4
|
-
exports.buildFieldMeta = buildFieldMeta;
|
|
5
|
-
const PG_TO_GQL_TYPE = {
|
|
6
|
-
text: 'String',
|
|
7
|
-
varchar: 'String',
|
|
8
|
-
char: 'String',
|
|
9
|
-
name: 'String',
|
|
10
|
-
bpchar: 'String',
|
|
11
|
-
uuid: 'UUID',
|
|
12
|
-
int2: 'Int',
|
|
13
|
-
int4: 'Int',
|
|
14
|
-
integer: 'Int',
|
|
15
|
-
int8: 'BigInt',
|
|
16
|
-
bigint: 'BigInt',
|
|
17
|
-
float4: 'Float',
|
|
18
|
-
float8: 'Float',
|
|
19
|
-
numeric: 'BigFloat',
|
|
20
|
-
bool: 'Boolean',
|
|
21
|
-
boolean: 'Boolean',
|
|
22
|
-
timestamptz: 'Datetime',
|
|
23
|
-
timestamp: 'Datetime',
|
|
24
|
-
date: 'Date',
|
|
25
|
-
time: 'Time',
|
|
26
|
-
timetz: 'Time',
|
|
27
|
-
json: 'JSON',
|
|
28
|
-
jsonb: 'JSON',
|
|
29
|
-
interval: 'Interval',
|
|
30
|
-
point: 'Point',
|
|
31
|
-
geometry: 'GeoJSON',
|
|
32
|
-
geography: 'GeoJSON',
|
|
33
|
-
inet: 'InternetAddress',
|
|
34
|
-
cidr: 'InternetAddress',
|
|
35
|
-
xml: 'String',
|
|
36
|
-
bytea: 'String',
|
|
37
|
-
macaddr: 'String',
|
|
38
|
-
};
|
|
39
|
-
function pgTypeToGqlType(pgTypeName) {
|
|
40
|
-
return PG_TO_GQL_TYPE[pgTypeName] || pgTypeName;
|
|
41
|
-
}
|
|
42
|
-
function resolveGqlTypeName(build, codec) {
|
|
43
|
-
if (!codec)
|
|
44
|
-
return 'unknown';
|
|
45
|
-
try {
|
|
46
|
-
const codecForLookup = codec.arrayOfCodec || codec;
|
|
47
|
-
if (build?.hasGraphQLTypeForPgCodec?.(codecForLookup, 'output')) {
|
|
48
|
-
const resolved = build.getGraphQLTypeNameByPgCodec?.(codecForLookup, 'output');
|
|
49
|
-
if (resolved)
|
|
50
|
-
return resolved;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
// Fall through to static fallback mapping.
|
|
55
|
-
}
|
|
56
|
-
const pgTypeName = codec.name || 'unknown';
|
|
57
|
-
const mapped = pgTypeToGqlType(pgTypeName);
|
|
58
|
-
if (mapped !== pgTypeName)
|
|
59
|
-
return mapped;
|
|
60
|
-
const nestedTypeName = codec.arrayOfCodec?.name;
|
|
61
|
-
return nestedTypeName ? pgTypeToGqlType(nestedTypeName) : pgTypeName;
|
|
62
|
-
}
|
|
63
|
-
function buildFieldMeta(name, attr, build) {
|
|
64
|
-
const pgType = attr?.codec?.name || 'unknown';
|
|
65
|
-
const isNotNull = attr?.notNull || false;
|
|
66
|
-
const hasDefault = attr?.hasDefault || false;
|
|
67
|
-
return {
|
|
68
|
-
name,
|
|
69
|
-
type: {
|
|
70
|
-
pgType,
|
|
71
|
-
gqlType: build ? resolveGqlTypeName(build, attr?.codec) : pgTypeToGqlType(pgType),
|
|
72
|
-
isArray: !!attr?.codec?.arrayOfCodec,
|
|
73
|
-
isNotNull,
|
|
74
|
-
hasDefault,
|
|
75
|
-
},
|
|
76
|
-
isNotNull,
|
|
77
|
-
hasDefault,
|
|
78
|
-
};
|
|
79
|
-
}
|