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