graphile-settings 6.5.1 → 6.5.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/esm/plugins/index.d.ts +1 -1
- package/esm/plugins/meta-schema.d.ts +3 -18
- package/esm/plugins/meta-schema.js +3 -19
- package/package.json +12 -11
- package/plugins/index.d.ts +1 -1
- package/plugins/meta-schema.d.ts +3 -18
- package/plugins/meta-schema.js +11 -16
- 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/encoding-meta-builders.d.ts +0 -2
- package/esm/plugins/meta-schema/encoding-meta-builders.js +0 -84
- package/esm/plugins/meta-schema/graphql-meta-field.d.ts +0 -4
- package/esm/plugins/meta-schema/graphql-meta-field.js +0 -314
- 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 -119
- package/esm/plugins/meta-schema/scope-meta-builders.d.ts +0 -15
- package/esm/plugins/meta-schema/scope-meta-builders.js +0 -40
- package/esm/plugins/meta-schema/storage-search-meta-builders.d.ts +0 -29
- package/esm/plugins/meta-schema/storage-search-meta-builders.js +0 -180
- package/esm/plugins/meta-schema/table-meta-builder.d.ts +0 -2
- package/esm/plugins/meta-schema/table-meta-builder.js +0 -99
- 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 -7
- package/esm/plugins/meta-schema/type-mappings.js +0 -100
- package/esm/plugins/meta-schema/types.d.ts +0 -325
- package/esm/plugins/meta-schema/types.js +0 -1
- 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/encoding-meta-builders.d.ts +0 -2
- package/plugins/meta-schema/encoding-meta-builders.js +0 -87
- package/plugins/meta-schema/graphql-meta-field.d.ts +0 -4
- package/plugins/meta-schema/graphql-meta-field.js +0 -317
- 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 -124
- package/plugins/meta-schema/scope-meta-builders.d.ts +0 -15
- package/plugins/meta-schema/scope-meta-builders.js +0 -43
- package/plugins/meta-schema/storage-search-meta-builders.d.ts +0 -29
- package/plugins/meta-schema/storage-search-meta-builders.js +0 -186
- package/plugins/meta-schema/table-meta-builder.d.ts +0 -2
- package/plugins/meta-schema/table-meta-builder.js +0 -102
- 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 -7
- package/plugins/meta-schema/type-mappings.js +0 -104
- package/plugins/meta-schema/types.d.ts +0 -325
- package/plugins/meta-schema/types.js +0 -2
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Detect storage metadata from a codec's smart tags.
|
|
3
|
-
* Storage tables are identified by @storageFiles and @storageBuckets smart tags.
|
|
4
|
-
*/
|
|
5
|
-
export function buildStorageMeta(codec) {
|
|
6
|
-
const tags = codec.extensions?.tags;
|
|
7
|
-
if (!tags)
|
|
8
|
-
return null;
|
|
9
|
-
const isFilesTable = !!tags.storageFiles;
|
|
10
|
-
const isBucketsTable = !!tags.storageBuckets;
|
|
11
|
-
if (!isFilesTable && !isBucketsTable)
|
|
12
|
-
return null;
|
|
13
|
-
return {
|
|
14
|
-
isFilesTable,
|
|
15
|
-
isBucketsTable,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Detect search metadata from a codec's columns and smart tags.
|
|
20
|
-
*
|
|
21
|
-
* Looks for:
|
|
22
|
-
* - tsvector columns (full-text search)
|
|
23
|
-
* - vector columns (pgvector semantic search)
|
|
24
|
-
* - @searchConfig smart tag (per-table search configuration)
|
|
25
|
-
* - @bm25Index smart tag on columns (BM25 search)
|
|
26
|
-
* - @trgmSearch smart tag (trigram search)
|
|
27
|
-
*/
|
|
28
|
-
export function buildSearchMeta(codec, _build, inflectAttr) {
|
|
29
|
-
const attributes = codec.attributes;
|
|
30
|
-
if (!attributes)
|
|
31
|
-
return null;
|
|
32
|
-
const tags = codec.extensions?.tags || {};
|
|
33
|
-
const columns = [];
|
|
34
|
-
const algorithmSet = new Set();
|
|
35
|
-
// Detect columns by type
|
|
36
|
-
for (const [attrName, attr] of Object.entries(attributes)) {
|
|
37
|
-
const pgType = attr?.codec?.name;
|
|
38
|
-
if (!pgType)
|
|
39
|
-
continue;
|
|
40
|
-
const inflectedName = inflectAttr(attrName, codec);
|
|
41
|
-
if (pgType === 'tsvector') {
|
|
42
|
-
columns.push({ name: inflectedName, algorithm: 'tsvector' });
|
|
43
|
-
algorithmSet.add('tsvector');
|
|
44
|
-
}
|
|
45
|
-
else if (pgType === 'vector') {
|
|
46
|
-
columns.push({ name: inflectedName, algorithm: 'vector' });
|
|
47
|
-
algorithmSet.add('vector');
|
|
48
|
-
}
|
|
49
|
-
// Check per-column @bm25Index tag
|
|
50
|
-
const attrTags = attr?.extensions?.tags;
|
|
51
|
-
if (attrTags?.bm25Index) {
|
|
52
|
-
columns.push({ name: inflectedName, algorithm: 'bm25' });
|
|
53
|
-
algorithmSet.add('bm25');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// Check for table-level @trgmSearch tag
|
|
57
|
-
if (tags.trgmSearch) {
|
|
58
|
-
algorithmSet.add('trgm');
|
|
59
|
-
// trgm operates on text columns — detect which ones
|
|
60
|
-
for (const [attrName, attr] of Object.entries(attributes)) {
|
|
61
|
-
const pgType = attr?.codec?.name;
|
|
62
|
-
if (pgType === 'text' || pgType === 'varchar' || pgType === 'citext') {
|
|
63
|
-
const attrTags = attr?.extensions?.tags;
|
|
64
|
-
if (attrTags?.trgmSearch) {
|
|
65
|
-
columns.push({ name: inflectAttr(attrName, codec), algorithm: 'trgm' });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
// Parse @searchConfig smart tag
|
|
71
|
-
const config = parseSearchConfig(tags);
|
|
72
|
-
// If nothing search-related was found, return null
|
|
73
|
-
if (columns.length === 0 && !config)
|
|
74
|
-
return null;
|
|
75
|
-
// Determine if unified search is available
|
|
76
|
-
// unifiedSearch requires at least one text-compatible adapter (tsvector or bm25)
|
|
77
|
-
const hasUnifiedSearch = algorithmSet.has('tsvector') || algorithmSet.has('bm25');
|
|
78
|
-
return {
|
|
79
|
-
algorithms: Array.from(algorithmSet).sort(),
|
|
80
|
-
columns,
|
|
81
|
-
hasUnifiedSearch,
|
|
82
|
-
config,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Detect i18n metadata from a codec's @i18n smart tag.
|
|
87
|
-
* The @i18n tag value is the name of the translation table.
|
|
88
|
-
* Translatable fields are discovered by matching text/citext columns
|
|
89
|
-
* between the base table and the translation table codec.
|
|
90
|
-
*/
|
|
91
|
-
export function buildI18nMeta(codec, build, inflectAttr) {
|
|
92
|
-
const tags = codec.extensions?.tags;
|
|
93
|
-
if (!tags)
|
|
94
|
-
return null;
|
|
95
|
-
const i18nTag = tags.i18n;
|
|
96
|
-
if (typeof i18nTag !== 'string' || i18nTag.length === 0)
|
|
97
|
-
return null;
|
|
98
|
-
const attributes = codec.attributes;
|
|
99
|
-
if (!attributes)
|
|
100
|
-
return { translationTable: i18nTag, translatableFields: [] };
|
|
101
|
-
// Discover translatable fields: text/citext columns on the base table
|
|
102
|
-
const allowedTypes = ['text', 'citext'];
|
|
103
|
-
const translatableFields = [];
|
|
104
|
-
// Try to find the translation codec to get the intersection of fields
|
|
105
|
-
const pgRegistry = build?.input?.pgRegistry;
|
|
106
|
-
let translationAttrs = null;
|
|
107
|
-
if (pgRegistry?.pgResources) {
|
|
108
|
-
for (const r of Object.values(pgRegistry.pgResources)) {
|
|
109
|
-
const sqlName = r?.codec?.extensions?.pg?.name ?? r?.codec?.name;
|
|
110
|
-
if (sqlName === i18nTag) {
|
|
111
|
-
const tAttrs = r?.codec?.attributes;
|
|
112
|
-
if (tAttrs) {
|
|
113
|
-
translationAttrs = new Set(Object.keys(tAttrs));
|
|
114
|
-
}
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
for (const [attrName, attr] of Object.entries(attributes)) {
|
|
120
|
-
const pgType = attr?.codec?.name;
|
|
121
|
-
if (!pgType || !allowedTypes.includes(pgType))
|
|
122
|
-
continue;
|
|
123
|
-
// If we found the translation table, only include columns that exist there too
|
|
124
|
-
if (translationAttrs && !translationAttrs.has(attrName))
|
|
125
|
-
continue;
|
|
126
|
-
translatableFields.push({
|
|
127
|
-
name: inflectAttr(attrName, codec),
|
|
128
|
-
type: pgType,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
translationTable: i18nTag,
|
|
133
|
-
translatableFields,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Detect realtime metadata from a codec's @realtime smart tag.
|
|
138
|
-
* Tables tagged with @realtime get subscription fields generated.
|
|
139
|
-
*/
|
|
140
|
-
export function buildRealtimeMeta(codec, build) {
|
|
141
|
-
const tags = codec.extensions?.tags;
|
|
142
|
-
if (!tags?.realtime)
|
|
143
|
-
return null;
|
|
144
|
-
const typeName = build.inflection?.tableType?.(codec);
|
|
145
|
-
if (!typeName)
|
|
146
|
-
return null;
|
|
147
|
-
return {
|
|
148
|
-
subscriptionFieldName: `on${typeName}Changed`,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
function parseSearchConfig(tags) {
|
|
152
|
-
const raw = tags.searchConfig;
|
|
153
|
-
if (!raw)
|
|
154
|
-
return null;
|
|
155
|
-
let parsed;
|
|
156
|
-
if (typeof raw === 'string') {
|
|
157
|
-
try {
|
|
158
|
-
parsed = JSON.parse(raw);
|
|
159
|
-
}
|
|
160
|
-
catch {
|
|
161
|
-
return null;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
else if (typeof raw === 'object') {
|
|
165
|
-
parsed = raw;
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
return {
|
|
171
|
-
weights: parsed.weights && typeof parsed.weights === 'object'
|
|
172
|
-
? parsed.weights
|
|
173
|
-
: null,
|
|
174
|
-
boostRecent: !!parsed.boost_recent,
|
|
175
|
-
boostRecencyField: parsed.boost_recency_field || null,
|
|
176
|
-
boostRecencyDecay: typeof parsed.boost_recency_decay === 'number'
|
|
177
|
-
? parsed.boost_recency_decay
|
|
178
|
-
: null,
|
|
179
|
-
};
|
|
180
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { buildForeignKeyConstraints, buildIndexes, buildPrimaryKey, buildUniqueConstraints } from './constraint-meta-builders';
|
|
2
|
-
import { buildInflectionMeta, buildQueryMeta, resolveTableType } from './name-meta-builders';
|
|
3
|
-
import { buildBelongsToRelations, buildManyToManyRelations, buildReverseRelations } from './relation-meta-builders';
|
|
4
|
-
import { buildScopeMeta } from './scope-meta-builders';
|
|
5
|
-
import { buildI18nMeta, buildRealtimeMeta, buildSearchMeta, buildStorageMeta } from './storage-search-meta-builders';
|
|
6
|
-
import { createBuildContext } from './table-meta-context';
|
|
7
|
-
import { getConfiguredSchemas, getRelations, getSchemaName, getUniques, isTableResource } from './table-resource-utils';
|
|
8
|
-
import { buildFieldMeta } from './type-mappings';
|
|
9
|
-
function buildTableMeta(resource, schemaName, context) {
|
|
10
|
-
const codec = resource.codec;
|
|
11
|
-
const attributes = codec.attributes;
|
|
12
|
-
const uniques = getUniques(resource);
|
|
13
|
-
const relations = getRelations(resource);
|
|
14
|
-
// Compute PK and FK attribute name sets for field metadata
|
|
15
|
-
const pkAttrNames = new Set();
|
|
16
|
-
const fkAttrNames = new Set();
|
|
17
|
-
for (const unique of uniques) {
|
|
18
|
-
if (unique.isPrimary) {
|
|
19
|
-
for (const attrName of unique.attributes)
|
|
20
|
-
pkAttrNames.add(attrName);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
for (const relation of Object.values(relations)) {
|
|
24
|
-
if (relation.isReferencee)
|
|
25
|
-
continue;
|
|
26
|
-
for (const attrName of relation.localAttributes || [])
|
|
27
|
-
fkAttrNames.add(attrName);
|
|
28
|
-
}
|
|
29
|
-
const fields = Object.entries(attributes).map(([attrName, attr]) => buildFieldMeta(context.inflectAttr(attrName, codec), attr, context.build, {
|
|
30
|
-
isPrimaryKey: pkAttrNames.has(attrName),
|
|
31
|
-
isForeignKey: fkAttrNames.has(attrName)
|
|
32
|
-
}));
|
|
33
|
-
const indexes = buildIndexes(codec, attributes, uniques, context);
|
|
34
|
-
const primaryKey = buildPrimaryKey(codec, attributes, uniques, context);
|
|
35
|
-
const uniqueConstraints = buildUniqueConstraints(codec, attributes, uniques, context);
|
|
36
|
-
const foreignKeyConstraints = buildForeignKeyConstraints(codec, attributes, relations, context);
|
|
37
|
-
const constraints = {
|
|
38
|
-
primaryKey,
|
|
39
|
-
unique: uniqueConstraints,
|
|
40
|
-
foreignKey: foreignKeyConstraints
|
|
41
|
-
};
|
|
42
|
-
const belongsTo = buildBelongsToRelations(codec, attributes, uniques, relations, context);
|
|
43
|
-
const { hasOne, hasMany } = buildReverseRelations(codec, attributes, relations, context);
|
|
44
|
-
const manyToMany = buildManyToManyRelations(resource, codec, context);
|
|
45
|
-
const relationsMeta = {
|
|
46
|
-
belongsTo,
|
|
47
|
-
has: [...hasOne, ...hasMany],
|
|
48
|
-
hasOne,
|
|
49
|
-
hasMany,
|
|
50
|
-
manyToMany
|
|
51
|
-
};
|
|
52
|
-
const tableType = resolveTableType(context.build, codec);
|
|
53
|
-
const storage = buildStorageMeta(codec);
|
|
54
|
-
const search = buildSearchMeta(codec, context.build, context.inflectAttr);
|
|
55
|
-
const i18n = buildI18nMeta(codec, context.build, context.inflectAttr);
|
|
56
|
-
const realtime = buildRealtimeMeta(codec, context.build);
|
|
57
|
-
const scope = buildScopeMeta(codec, context.inflectAttr);
|
|
58
|
-
return {
|
|
59
|
-
name: tableType,
|
|
60
|
-
schemaName,
|
|
61
|
-
fields,
|
|
62
|
-
indexes,
|
|
63
|
-
constraints,
|
|
64
|
-
foreignKeyConstraints,
|
|
65
|
-
primaryKeyConstraints: primaryKey ? [primaryKey] : [],
|
|
66
|
-
uniqueConstraints,
|
|
67
|
-
relations: relationsMeta,
|
|
68
|
-
inflection: buildInflectionMeta(resource, tableType, context.build),
|
|
69
|
-
query: buildQueryMeta(resource, uniques, tableType, context.build),
|
|
70
|
-
storage,
|
|
71
|
-
search,
|
|
72
|
-
i18n,
|
|
73
|
-
realtime,
|
|
74
|
-
scope
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
export function collectTablesMeta(build) {
|
|
78
|
-
const configuredSchemas = getConfiguredSchemas(build);
|
|
79
|
-
const context = createBuildContext(build);
|
|
80
|
-
const seenCodecs = new Set();
|
|
81
|
-
const tablesMeta = [];
|
|
82
|
-
for (const resource of Object.values(build.input.pgRegistry.pgResources || {})) {
|
|
83
|
-
if (!isTableResource(resource))
|
|
84
|
-
continue;
|
|
85
|
-
const codec = resource.codec;
|
|
86
|
-
if (seenCodecs.has(codec))
|
|
87
|
-
continue;
|
|
88
|
-
seenCodecs.add(codec);
|
|
89
|
-
const schemaName = getSchemaName(resource);
|
|
90
|
-
if (!schemaName)
|
|
91
|
-
continue;
|
|
92
|
-
if (configuredSchemas.length > 0 &&
|
|
93
|
-
!configuredSchemas.includes(schemaName)) {
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
tablesMeta.push(buildTableMeta(resource, schemaName, context));
|
|
97
|
-
}
|
|
98
|
-
return tablesMeta;
|
|
99
|
-
}
|
|
@@ -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,11 +0,0 @@
|
|
|
1
|
-
import { createAttributeInflector } from './inflection-utils';
|
|
2
|
-
import { buildFieldMeta } from './type-mappings';
|
|
3
|
-
export function createBuildContext(build) {
|
|
4
|
-
return {
|
|
5
|
-
build,
|
|
6
|
-
inflectAttr: createAttributeInflector(build.inflection),
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
export function buildFieldList(attrNames, codec, attributes, context) {
|
|
10
|
-
return attrNames.map((attrName) => buildFieldMeta(context.inflectAttr(attrName, codec), attributes[attrName], context.build));
|
|
11
|
-
}
|
|
@@ -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,50 +0,0 @@
|
|
|
1
|
-
function isRecord(value) {
|
|
2
|
-
return typeof value === 'object' && value !== null;
|
|
3
|
-
}
|
|
4
|
-
export function isTableResource(resource) {
|
|
5
|
-
return (!!resource.codec &&
|
|
6
|
-
!resource.codec.isAnonymous &&
|
|
7
|
-
isRecord(resource.codec.attributes) &&
|
|
8
|
-
!resource.parameters &&
|
|
9
|
-
!resource.isVirtual &&
|
|
10
|
-
!resource.isUnique);
|
|
11
|
-
}
|
|
12
|
-
export function getSchemaName(resource) {
|
|
13
|
-
const schemaName = resource.codec?.extensions?.pg?.schemaName;
|
|
14
|
-
if (typeof schemaName !== 'string' || schemaName.length === 0)
|
|
15
|
-
return null;
|
|
16
|
-
return schemaName;
|
|
17
|
-
}
|
|
18
|
-
export function getUniques(resource) {
|
|
19
|
-
return Array.isArray(resource.uniques) ? resource.uniques : [];
|
|
20
|
-
}
|
|
21
|
-
export function getRelations(resource) {
|
|
22
|
-
return resource.relations || resource.getRelations?.() || {};
|
|
23
|
-
}
|
|
24
|
-
export function getRelation(resource, relationName) {
|
|
25
|
-
if (!relationName)
|
|
26
|
-
return null;
|
|
27
|
-
if (typeof resource.getRelation === 'function') {
|
|
28
|
-
return resource.getRelation(relationName) || null;
|
|
29
|
-
}
|
|
30
|
-
const relations = getRelations(resource);
|
|
31
|
-
return relations[relationName] || null;
|
|
32
|
-
}
|
|
33
|
-
export function sameAttributes(uniqueAttributes, relationAttributes) {
|
|
34
|
-
if (!uniqueAttributes || !relationAttributes)
|
|
35
|
-
return false;
|
|
36
|
-
return (uniqueAttributes.length === relationAttributes.length &&
|
|
37
|
-
uniqueAttributes.every((attrName) => relationAttributes.includes(attrName)));
|
|
38
|
-
}
|
|
39
|
-
export function getConfiguredSchemas(build) {
|
|
40
|
-
const pgSchemas = build.options?.pgSchemas;
|
|
41
|
-
if (!Array.isArray(pgSchemas))
|
|
42
|
-
return [];
|
|
43
|
-
return pgSchemas.filter((schemaName) => typeof schemaName === 'string');
|
|
44
|
-
}
|
|
45
|
-
export function getResourceCodec(resource) {
|
|
46
|
-
const codec = resource.codec;
|
|
47
|
-
if (!codec?.attributes)
|
|
48
|
-
return null;
|
|
49
|
-
return codec;
|
|
50
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { FieldMeta, GqlTypeResolverBuild, PgAttribute } from './types';
|
|
2
|
-
export declare function pgTypeToGqlType(pgTypeName: string): string;
|
|
3
|
-
export interface BuildFieldMetaOptions {
|
|
4
|
-
isPrimaryKey?: boolean;
|
|
5
|
-
isForeignKey?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare function buildFieldMeta(name: string, attr: PgAttribute | null | undefined, build?: GqlTypeResolverBuild, options?: BuildFieldMetaOptions): FieldMeta;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { buildScalarEncoding } from './encoding-meta-builders';
|
|
2
|
-
const PG_TO_GQL_TYPE = {
|
|
3
|
-
text: 'String',
|
|
4
|
-
varchar: 'String',
|
|
5
|
-
char: 'String',
|
|
6
|
-
name: 'String',
|
|
7
|
-
bpchar: 'String',
|
|
8
|
-
uuid: 'UUID',
|
|
9
|
-
int2: 'Int',
|
|
10
|
-
int4: 'Int',
|
|
11
|
-
integer: 'Int',
|
|
12
|
-
int8: 'BigInt',
|
|
13
|
-
bigint: 'BigInt',
|
|
14
|
-
float4: 'Float',
|
|
15
|
-
float8: 'Float',
|
|
16
|
-
numeric: 'BigFloat',
|
|
17
|
-
bool: 'Boolean',
|
|
18
|
-
boolean: 'Boolean',
|
|
19
|
-
timestamptz: 'Datetime',
|
|
20
|
-
timestamp: 'Datetime',
|
|
21
|
-
date: 'Date',
|
|
22
|
-
time: 'Time',
|
|
23
|
-
timetz: 'Time',
|
|
24
|
-
json: 'JSON',
|
|
25
|
-
jsonb: 'JSON',
|
|
26
|
-
interval: 'Interval',
|
|
27
|
-
point: 'Point',
|
|
28
|
-
geometry: 'GeoJSON',
|
|
29
|
-
geography: 'GeoJSON',
|
|
30
|
-
inet: 'InternetAddress',
|
|
31
|
-
cidr: 'InternetAddress',
|
|
32
|
-
xml: 'String',
|
|
33
|
-
bytea: 'String',
|
|
34
|
-
macaddr: 'String',
|
|
35
|
-
};
|
|
36
|
-
export function pgTypeToGqlType(pgTypeName) {
|
|
37
|
-
return PG_TO_GQL_TYPE[pgTypeName] || pgTypeName;
|
|
38
|
-
}
|
|
39
|
-
function getGeometrySubtype(attr) {
|
|
40
|
-
const subtype = attr?.extensions?.geometrySubtype;
|
|
41
|
-
return typeof subtype === 'string' ? subtype : null;
|
|
42
|
-
}
|
|
43
|
-
function resolveGqlTypeName(build, codec) {
|
|
44
|
-
if (!codec)
|
|
45
|
-
return 'unknown';
|
|
46
|
-
try {
|
|
47
|
-
const codecForLookup = codec.arrayOfCodec || codec;
|
|
48
|
-
if (build?.hasGraphQLTypeForPgCodec?.(codecForLookup, 'output')) {
|
|
49
|
-
const resolved = build.getGraphQLTypeNameByPgCodec?.(codecForLookup, 'output');
|
|
50
|
-
if (resolved)
|
|
51
|
-
return resolved;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
// Fall through to static fallback mapping.
|
|
56
|
-
}
|
|
57
|
-
const pgTypeName = codec.name || 'unknown';
|
|
58
|
-
const mapped = pgTypeToGqlType(pgTypeName);
|
|
59
|
-
if (mapped !== pgTypeName)
|
|
60
|
-
return mapped;
|
|
61
|
-
const nestedTypeName = codec.arrayOfCodec?.name;
|
|
62
|
-
return nestedTypeName ? pgTypeToGqlType(nestedTypeName) : pgTypeName;
|
|
63
|
-
}
|
|
64
|
-
function extractEnumMeta(codec) {
|
|
65
|
-
if (!codec)
|
|
66
|
-
return null;
|
|
67
|
-
// Check the codec itself, or unwrap domain/array wrappers
|
|
68
|
-
const inner = codec.domainOfCodec ?? codec.arrayOfCodec ?? codec;
|
|
69
|
-
const values = inner.values;
|
|
70
|
-
if (!Array.isArray(values) || values.length === 0)
|
|
71
|
-
return null;
|
|
72
|
-
return {
|
|
73
|
-
name: inner.name || codec.name || 'unknown',
|
|
74
|
-
values: values.map((v) => (typeof v === 'string' ? v : v.value)),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
export function buildFieldMeta(name, attr, build, options) {
|
|
78
|
-
const pgType = attr?.codec?.name || 'unknown';
|
|
79
|
-
const isNotNull = attr?.notNull || false;
|
|
80
|
-
const hasDefault = attr?.hasDefault || false;
|
|
81
|
-
const subtype = getGeometrySubtype(attr);
|
|
82
|
-
return {
|
|
83
|
-
name,
|
|
84
|
-
type: {
|
|
85
|
-
pgType,
|
|
86
|
-
gqlType: build ? resolveGqlTypeName(build, attr?.codec) : pgTypeToGqlType(pgType),
|
|
87
|
-
isArray: !!attr?.codec?.arrayOfCodec,
|
|
88
|
-
isNotNull,
|
|
89
|
-
hasDefault,
|
|
90
|
-
subtype,
|
|
91
|
-
encoding: buildScalarEncoding(attr),
|
|
92
|
-
},
|
|
93
|
-
isNotNull,
|
|
94
|
-
hasDefault,
|
|
95
|
-
isPrimaryKey: options?.isPrimaryKey ?? false,
|
|
96
|
-
isForeignKey: options?.isForeignKey ?? false,
|
|
97
|
-
description: attr?.description ?? null,
|
|
98
|
-
enumValues: extractEnumMeta(attr?.codec),
|
|
99
|
-
};
|
|
100
|
-
}
|