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.
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 +12 -11
  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,314 +0,0 @@
1
- import { GraphQLBoolean, GraphQLFloat, GraphQLInt, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLString } from 'graphql';
2
- function nn(type) {
3
- return new GraphQLNonNull(type);
4
- }
5
- function nnList(type) {
6
- return nn(new GraphQLList(nn(type)));
7
- }
8
- function createMetaSchemaType() {
9
- const MetaScalarEncodingType = new GraphQLObjectType({
10
- name: 'MetaScalarEncoding',
11
- description: 'How a client must serialize/parse a scalar — the one field-type detail standard GraphQL introspection cannot describe. Null for plain scalars whose wire format is obvious from gqlType.',
12
- fields: () => ({
13
- kind: {
14
- type: nn(GraphQLString),
15
- description: "Machine kind: bigint, datetime, date, time, interval, uuid, geojson, point, inet, ltree, vector, bytea, or composite."
16
- },
17
- elementType: { type: GraphQLString, description: "For 'vector': element scalar (e.g. 'float')." },
18
- dimensions: { type: GraphQLInt, description: "For 'vector': declared length, else null." },
19
- geometrySubtype: { type: GraphQLString, description: "For 'geojson': Point/LineString/Polygon/…, else null." },
20
- srid: { type: GraphQLInt, description: "For 'geojson': spatial reference id, else null." },
21
- dotPath: { type: GraphQLBoolean, description: "For 'ltree': values are dot-separated path strings." }
22
- })
23
- });
24
- const MetaTypeType = new GraphQLObjectType({
25
- name: 'MetaType',
26
- description: 'Information about a PostgreSQL type',
27
- fields: () => ({
28
- pgType: { type: nn(GraphQLString) },
29
- gqlType: { type: nn(GraphQLString) },
30
- isArray: { type: nn(GraphQLBoolean) },
31
- isNotNull: { type: GraphQLBoolean },
32
- hasDefault: { type: GraphQLBoolean },
33
- subtype: { type: GraphQLString },
34
- encoding: {
35
- type: MetaScalarEncodingType,
36
- description: 'Scalar serialization contract (null for plain scalars)'
37
- }
38
- })
39
- });
40
- const MetaEnumType = new GraphQLObjectType({
41
- name: 'MetaEnum',
42
- description: 'Information about a PostgreSQL enum type',
43
- fields: () => ({
44
- name: { type: nn(GraphQLString), description: 'The PostgreSQL enum type name' },
45
- values: { type: nnList(GraphQLString), description: 'Allowed values for this enum' }
46
- })
47
- });
48
- const MetaFieldType = new GraphQLObjectType({
49
- name: 'MetaField',
50
- description: 'Information about a table field/column',
51
- fields: () => ({
52
- name: { type: nn(GraphQLString) },
53
- type: { type: nn(MetaTypeType) },
54
- isNotNull: { type: nn(GraphQLBoolean) },
55
- hasDefault: { type: nn(GraphQLBoolean) },
56
- isPrimaryKey: { type: nn(GraphQLBoolean) },
57
- isForeignKey: { type: nn(GraphQLBoolean) },
58
- description: { type: GraphQLString },
59
- enumValues: { type: MetaEnumType, description: 'Enum metadata if this field has an enum type' }
60
- })
61
- });
62
- const MetaIndexType = new GraphQLObjectType({
63
- name: 'MetaIndex',
64
- description: 'Information about a database index',
65
- fields: () => ({
66
- name: { type: nn(GraphQLString) },
67
- isUnique: { type: nn(GraphQLBoolean) },
68
- isPrimary: { type: nn(GraphQLBoolean) },
69
- columns: { type: nnList(GraphQLString) },
70
- fields: { type: new GraphQLList(nn(MetaFieldType)) }
71
- })
72
- });
73
- const MetaPrimaryKeyConstraintType = new GraphQLObjectType({
74
- name: 'MetaPrimaryKeyConstraint',
75
- description: 'Information about a primary key constraint',
76
- fields: () => ({
77
- name: { type: nn(GraphQLString) },
78
- fields: { type: nnList(MetaFieldType) }
79
- })
80
- });
81
- const MetaUniqueConstraintType = new GraphQLObjectType({
82
- name: 'MetaUniqueConstraint',
83
- description: 'Information about a unique constraint',
84
- fields: () => ({
85
- name: { type: nn(GraphQLString) },
86
- fields: { type: nnList(MetaFieldType) }
87
- })
88
- });
89
- const MetaRefTableType = new GraphQLObjectType({
90
- name: 'MetaRefTable',
91
- description: 'Reference to a related table',
92
- fields: () => ({
93
- name: { type: nn(GraphQLString) }
94
- })
95
- });
96
- const MetaForeignKeyConstraintType = new GraphQLObjectType({
97
- name: 'MetaForeignKeyConstraint',
98
- description: 'Information about a foreign key constraint',
99
- fields: () => ({
100
- name: { type: nn(GraphQLString) },
101
- fields: { type: nnList(MetaFieldType) },
102
- referencedTable: { type: nn(GraphQLString) },
103
- referencedFields: { type: nnList(GraphQLString) },
104
- refFields: { type: new GraphQLList(nn(MetaFieldType)) },
105
- refTable: { type: MetaRefTableType }
106
- })
107
- });
108
- const MetaConstraintsType = new GraphQLObjectType({
109
- name: 'MetaConstraints',
110
- description: 'Table constraints',
111
- fields: () => ({
112
- primaryKey: { type: MetaPrimaryKeyConstraintType },
113
- unique: { type: nnList(MetaUniqueConstraintType) },
114
- foreignKey: { type: nnList(MetaForeignKeyConstraintType) }
115
- })
116
- });
117
- const MetaInflectionType = new GraphQLObjectType({
118
- name: 'MetaInflection',
119
- description: 'Table inflection names',
120
- fields: () => ({
121
- tableType: { type: nn(GraphQLString) },
122
- allRows: { type: nn(GraphQLString) },
123
- connection: { type: nn(GraphQLString) },
124
- edge: { type: nn(GraphQLString) },
125
- filterType: { type: GraphQLString },
126
- orderByType: { type: nn(GraphQLString) },
127
- conditionType: { type: nn(GraphQLString) },
128
- patchType: { type: GraphQLString },
129
- createInputType: { type: nn(GraphQLString) },
130
- createPayloadType: { type: nn(GraphQLString) },
131
- updatePayloadType: { type: GraphQLString },
132
- deletePayloadType: { type: nn(GraphQLString) }
133
- })
134
- });
135
- const MetaQueryType = new GraphQLObjectType({
136
- name: 'MetaQuery',
137
- description: 'Table query/mutation names',
138
- fields: () => ({
139
- all: { type: nn(GraphQLString) },
140
- one: { type: GraphQLString },
141
- create: { type: GraphQLString },
142
- update: { type: GraphQLString },
143
- delete: { type: GraphQLString }
144
- })
145
- });
146
- const MetaBelongsToRelationType = new GraphQLObjectType({
147
- name: 'MetaBelongsToRelation',
148
- description: 'A belongs-to (forward FK) relation',
149
- fields: () => ({
150
- fieldName: { type: GraphQLString },
151
- isUnique: { type: nn(GraphQLBoolean) },
152
- type: { type: GraphQLString },
153
- keys: { type: nnList(MetaFieldType) },
154
- references: { type: nn(MetaRefTableType) }
155
- })
156
- });
157
- const MetaHasRelationType = new GraphQLObjectType({
158
- name: 'MetaHasRelation',
159
- description: 'A has-one or has-many (reverse FK) relation',
160
- fields: () => ({
161
- fieldName: { type: GraphQLString },
162
- isUnique: { type: nn(GraphQLBoolean) },
163
- type: { type: GraphQLString },
164
- keys: { type: nnList(MetaFieldType) },
165
- referencedBy: { type: nn(MetaRefTableType) }
166
- })
167
- });
168
- const MetaManyToManyRelationType = new GraphQLObjectType({
169
- name: 'MetaManyToManyRelation',
170
- description: 'A many-to-many relation via junction table',
171
- fields: () => ({
172
- fieldName: { type: GraphQLString },
173
- type: { type: GraphQLString },
174
- junctionTable: { type: nn(MetaRefTableType) },
175
- junctionLeftConstraint: { type: nn(MetaForeignKeyConstraintType) },
176
- junctionLeftKeyAttributes: { type: nnList(MetaFieldType) },
177
- junctionRightConstraint: { type: nn(MetaForeignKeyConstraintType) },
178
- junctionRightKeyAttributes: { type: nnList(MetaFieldType) },
179
- leftKeyAttributes: { type: nnList(MetaFieldType) },
180
- rightKeyAttributes: { type: nnList(MetaFieldType) },
181
- rightTable: { type: nn(MetaRefTableType) }
182
- })
183
- });
184
- const MetaRelationsType = new GraphQLObjectType({
185
- name: 'MetaRelations',
186
- description: 'Table relations',
187
- fields: () => ({
188
- belongsTo: { type: nnList(MetaBelongsToRelationType) },
189
- has: { type: nnList(MetaHasRelationType) },
190
- hasOne: { type: nnList(MetaHasRelationType) },
191
- hasMany: { type: nnList(MetaHasRelationType) },
192
- manyToMany: { type: nnList(MetaManyToManyRelationType) }
193
- })
194
- });
195
- const MetaStorageType = new GraphQLObjectType({
196
- name: 'MetaStorage',
197
- description: 'Storage metadata for a table',
198
- fields: () => ({
199
- isFilesTable: { type: nn(GraphQLBoolean), description: 'Whether this table is a storage files table' },
200
- isBucketsTable: { type: nn(GraphQLBoolean), description: 'Whether this table is a storage buckets table' }
201
- })
202
- });
203
- const MetaSearchConfigType = new GraphQLObjectType({
204
- name: 'MetaSearchConfig',
205
- description: 'Per-table search configuration from @searchConfig smart tag',
206
- fields: () => ({
207
- weights: {
208
- type: GraphQLString,
209
- description: 'JSON-encoded per-adapter score weights',
210
- resolve(source) {
211
- return source.weights ? JSON.stringify(source.weights) : null;
212
- }
213
- },
214
- boostRecent: { type: nn(GraphQLBoolean), description: 'Whether recency boosting is enabled' },
215
- boostRecencyField: { type: GraphQLString, description: 'Field used for recency decay' },
216
- boostRecencyDecay: { type: GraphQLFloat, description: 'Exponential decay factor per day' }
217
- })
218
- });
219
- const MetaSearchColumnType = new GraphQLObjectType({
220
- name: 'MetaSearchColumn',
221
- description: 'A searchable column with its algorithm',
222
- fields: () => ({
223
- name: { type: nn(GraphQLString), description: 'Column name (camelCase)' },
224
- algorithm: { type: nn(GraphQLString), description: 'Search algorithm: tsvector, bm25, trgm, or vector' }
225
- })
226
- });
227
- const MetaSearchType = new GraphQLObjectType({
228
- name: 'MetaSearch',
229
- description: 'Search metadata for a table',
230
- fields: () => ({
231
- algorithms: { type: nnList(GraphQLString), description: 'Active search algorithms on this table' },
232
- columns: { type: nnList(MetaSearchColumnType), description: 'Searchable columns with their algorithm' },
233
- hasUnifiedSearch: { type: nn(GraphQLBoolean), description: 'Whether unifiedSearch composite filter is available' },
234
- config: { type: MetaSearchConfigType, description: 'Per-table search configuration' }
235
- })
236
- });
237
- const MetaI18nFieldType = new GraphQLObjectType({
238
- name: 'MetaI18nField',
239
- description: 'A translatable field',
240
- fields: () => ({
241
- name: { type: nn(GraphQLString), description: 'GraphQL field name' },
242
- type: { type: nn(GraphQLString), description: 'PostgreSQL column type (text, citext)' }
243
- })
244
- });
245
- const MetaI18nType = new GraphQLObjectType({
246
- name: 'MetaI18n',
247
- description: 'i18n metadata for a table with @i18n tag',
248
- fields: () => ({
249
- translationTable: { type: nn(GraphQLString), description: 'Name of the translation table' },
250
- translatableFields: { type: nnList(MetaI18nFieldType), description: 'Fields that are translatable' }
251
- })
252
- });
253
- const MetaRealtimeType = new GraphQLObjectType({
254
- name: 'MetaRealtime',
255
- description: 'Realtime metadata for a table with @realtime tag',
256
- fields: () => ({
257
- subscriptionFieldName: { type: nn(GraphQLString), description: 'The generated subscription field name (e.g. onPostChanged)' }
258
- })
259
- });
260
- const MetaScopeType = new GraphQLObjectType({
261
- name: 'MetaScope',
262
- description: 'Provisioning scope metadata for a table',
263
- fields: () => ({
264
- scope: { type: nn(GraphQLString), description: "Provisioning scope: 'platform', 'app', 'database', or an entity scope (e.g. 'org')" },
265
- tier: { type: nn(GraphQLString), description: "Coarse bucket: 'global', 'database', or 'entity'" },
266
- keyColumn: { type: GraphQLString, description: 'Inflected scope key column (e.g. databaseId, orgId), null for global tiers' },
267
- entityTable: { type: GraphQLString, description: 'SQL name of the entity table for entity scopes, else null' },
268
- source: { type: nn(GraphQLString), description: "Provenance of the scope metadata (always 'smartTag')" }
269
- })
270
- });
271
- const MetaTableType = new GraphQLObjectType({
272
- name: 'MetaTable',
273
- description: 'Information about a database table',
274
- fields: () => ({
275
- name: { type: nn(GraphQLString) },
276
- schemaName: { type: nn(GraphQLString) },
277
- fields: { type: nnList(MetaFieldType) },
278
- indexes: { type: nnList(MetaIndexType) },
279
- constraints: { type: nn(MetaConstraintsType) },
280
- foreignKeyConstraints: { type: nnList(MetaForeignKeyConstraintType) },
281
- primaryKeyConstraints: { type: nnList(MetaPrimaryKeyConstraintType) },
282
- uniqueConstraints: { type: nnList(MetaUniqueConstraintType) },
283
- relations: { type: nn(MetaRelationsType) },
284
- inflection: { type: nn(MetaInflectionType) },
285
- query: { type: nn(MetaQueryType) },
286
- storage: { type: MetaStorageType, description: 'Storage metadata (null if not a storage table)' },
287
- search: { type: MetaSearchType, description: 'Search metadata (null if no search configured)' },
288
- i18n: { type: MetaI18nType, description: 'i18n metadata (null if no @i18n tag)' },
289
- realtime: { type: MetaRealtimeType, description: 'Realtime metadata (null if no @realtime tag)' },
290
- scope: { type: MetaScopeType, description: 'Provisioning scope metadata (null if no @scope tag)' }
291
- })
292
- });
293
- return new GraphQLObjectType({
294
- name: 'MetaSchema',
295
- description: 'Root meta schema type',
296
- fields: () => ({
297
- tables: { type: nnList(MetaTableType) }
298
- })
299
- });
300
- }
301
- export function extendQueryWithMetaField(fields, tablesMeta) {
302
- const metaSchemaType = createMetaSchemaType();
303
- const metaField = {
304
- type: metaSchemaType,
305
- description: 'Metadata about the database schema, including tables, fields, indexes, and constraints. Useful for code generation tools.',
306
- resolve() {
307
- return { tables: tablesMeta };
308
- }
309
- };
310
- return {
311
- ...fields,
312
- _meta: metaField
313
- };
314
- }
@@ -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,20 +0,0 @@
1
- export function safeInflection(fn, fallback) {
2
- try {
3
- return fn() ?? fallback;
4
- }
5
- catch {
6
- return fallback;
7
- }
8
- }
9
- export function createAttributeInflector(inflection) {
10
- return (attrName, codec) => {
11
- const attributeName = safeInflection(() => inflection._attributeName?.({ attributeName: attrName, codec }), attrName);
12
- return safeInflection(() => inflection.camelCase?.(attributeName), attributeName);
13
- };
14
- }
15
- export function fallbackTableType(codecName) {
16
- return codecName
17
- .replace(/_/g, ' ')
18
- .replace(/\b\w/g, (char) => char.toUpperCase())
19
- .replace(/ /g, '');
20
- }
@@ -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,38 +0,0 @@
1
- import { fallbackTableType, safeInflection } from './inflection-utils';
2
- export function resolveTableType(build, codec) {
3
- return safeInflection(() => build.inflection.tableType(codec), fallbackTableType(codec.name));
4
- }
5
- export function buildInflectionMeta(resource, tableType, build) {
6
- const inflection = build.inflection;
7
- return {
8
- tableType,
9
- allRows: safeInflection(() => inflection.allRows?.(resource), `${tableType.toLowerCase()}s`),
10
- connection: safeInflection(() => inflection.connectionType?.(tableType), `${tableType}Connection`),
11
- edge: safeInflection(() => inflection.edgeType?.(tableType), `${tableType}Edge`),
12
- filterType: safeInflection(() => inflection.filterType?.(tableType), `${tableType}Filter`),
13
- orderByType: safeInflection(() => inflection.orderByType?.(tableType), `${tableType}OrderBy`),
14
- conditionType: safeInflection(() => inflection.conditionType?.(tableType), `${tableType}Condition`),
15
- patchType: safeInflection(() => inflection.patchType?.(tableType), `${tableType}Patch`),
16
- createInputType: safeInflection(() => inflection.createInputType?.(resource), `Create${tableType}Input`),
17
- createPayloadType: safeInflection(() => inflection.createPayloadType?.(resource), `Create${tableType}Payload`),
18
- updatePayloadType: safeInflection(() => inflection.updatePayloadType?.(resource), `Update${tableType}Payload`),
19
- deletePayloadType: safeInflection(() => inflection.deletePayloadType?.(resource), `Delete${tableType}Payload`),
20
- };
21
- }
22
- export function buildQueryMeta(resource, uniques, tableType, build) {
23
- const inflection = build.inflection;
24
- const hasPrimaryKey = uniques.some((unique) => unique.isPrimary);
25
- return {
26
- all: safeInflection(() => inflection.allRows?.(resource), `${tableType.toLowerCase()}s`),
27
- one: hasPrimaryKey
28
- ? safeInflection(() => inflection.tableFieldName?.(resource), tableType.toLowerCase())
29
- : null,
30
- create: safeInflection(() => inflection.createField?.(resource), `create${tableType}`),
31
- update: hasPrimaryKey
32
- ? safeInflection(() => inflection.updateByKeys?.(resource), `update${tableType}`)
33
- : null,
34
- delete: hasPrimaryKey
35
- ? safeInflection(() => inflection.deleteByKeys?.(resource), `delete${tableType}`)
36
- : null,
37
- };
38
- }
@@ -1,2 +0,0 @@
1
- import type { GraphileConfig } from 'graphile-config';
2
- export declare const MetaSchemaPlugin: GraphileConfig.Plugin;
@@ -1,23 +0,0 @@
1
- import { getCachedTablesMeta, setCachedTablesMeta } from './cache';
2
- import { extendQueryWithMetaField } from './graphql-meta-field';
3
- import { collectTablesMeta } from './table-meta-builder';
4
- export const MetaSchemaPlugin = {
5
- name: 'MetaSchemaPlugin',
6
- version: '1.0.0',
7
- description: 'Exposes _meta query for database schema introspection',
8
- schema: {
9
- hooks: {
10
- init(input, rawBuild) {
11
- const build = rawBuild;
12
- setCachedTablesMeta(collectTablesMeta(build));
13
- return input;
14
- },
15
- GraphQLObjectType_fields(rawFields, _rawBuild, rawContext) {
16
- const context = rawContext;
17
- if (context.Self?.name !== 'Query')
18
- return rawFields;
19
- return extendQueryWithMetaField(rawFields, getCachedTablesMeta());
20
- },
21
- },
22
- },
23
- };
@@ -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,119 +0,0 @@
1
- import { safeInflection } from './inflection-utils';
2
- import { buildForeignKeyConstraint, } from './constraint-meta-builders';
3
- import { buildFieldList } from './table-meta-context';
4
- import { getRelation, getResourceCodec, getUniques, sameAttributes, } from './table-resource-utils';
5
- function isRecord(value) {
6
- return typeof value === 'object' && value !== null;
7
- }
8
- export function buildBelongsToRelations(codec, attributes, uniques, relations, context) {
9
- const belongsTo = [];
10
- for (const [relationName, relation] of Object.entries(relations)) {
11
- // PostGraphile only sets isReferencee when true (reverse FK);
12
- // forward relations have isReferencee undefined, not false.
13
- if (relation.isReferencee)
14
- continue;
15
- const localAttributes = relation.localAttributes || [];
16
- const isUnique = uniques.some((unique) => sameAttributes(unique.attributes, localAttributes));
17
- const remoteCodec = relation.remoteResource?.codec;
18
- belongsTo.push({
19
- fieldName: relationName,
20
- isUnique,
21
- type: remoteCodec?.name || null,
22
- keys: buildFieldList(localAttributes, codec, attributes, context),
23
- references: { name: remoteCodec?.name || 'unknown' },
24
- });
25
- }
26
- return belongsTo;
27
- }
28
- export function buildReverseRelations(codec, attributes, relations, context) {
29
- const hasOne = [];
30
- const hasMany = [];
31
- for (const [relationName, relation] of Object.entries(relations)) {
32
- if (relation.isReferencee !== true)
33
- continue;
34
- const remoteUniques = getUniques(relation.remoteResource || {});
35
- const remoteAttributes = relation.remoteAttributes || [];
36
- const isUnique = remoteUniques.some((unique) => sameAttributes(unique.attributes, remoteAttributes));
37
- const remoteCodec = relation.remoteResource?.codec;
38
- const meta = {
39
- fieldName: relationName,
40
- isUnique,
41
- type: remoteCodec?.name || null,
42
- keys: buildFieldList(relation.localAttributes || [], codec, attributes, context),
43
- referencedBy: { name: remoteCodec?.name || 'unknown' },
44
- };
45
- if (isUnique) {
46
- hasOne.push(meta);
47
- }
48
- else {
49
- hasMany.push(meta);
50
- }
51
- }
52
- return { hasOne, hasMany };
53
- }
54
- function isManyToManyDetails(value) {
55
- if (!isRecord(value))
56
- return false;
57
- return (isRecord(value.leftTable) &&
58
- isRecord(value.junctionTable) &&
59
- isRecord(value.rightTable) &&
60
- typeof value.leftRelationName === 'string' &&
61
- typeof value.rightRelationName === 'string');
62
- }
63
- function parseManyToManyRelationships(value) {
64
- if (!Array.isArray(value))
65
- return [];
66
- return value.filter(isManyToManyDetails);
67
- }
68
- function getManyToManyRelationships(build, tableResource, codec) {
69
- const relationshipsByResource = build.pgManyToManyRealtionshipsByResource;
70
- if (!(relationshipsByResource instanceof Map))
71
- return [];
72
- const direct = parseManyToManyRelationships(relationshipsByResource.get(tableResource));
73
- if (direct.length > 0)
74
- return direct;
75
- for (const [leftTable, relationships] of relationshipsByResource.entries()) {
76
- const details = parseManyToManyRelationships(relationships);
77
- if (details.length === 0 || !isRecord(leftTable))
78
- continue;
79
- if (leftTable.codec === codec) {
80
- return details;
81
- }
82
- }
83
- return [];
84
- }
85
- function buildManyToManyRelation(details, context) {
86
- const leftCodec = getResourceCodec(details.leftTable);
87
- const junctionCodec = getResourceCodec(details.junctionTable);
88
- const rightCodec = getResourceCodec(details.rightTable);
89
- if (!leftCodec || !junctionCodec || !rightCodec)
90
- return null;
91
- const leftRelation = getRelation(details.leftTable, details.leftRelationName);
92
- const junctionRightRelation = getRelation(details.junctionTable, details.rightRelationName);
93
- if (!leftRelation || !junctionRightRelation)
94
- return null;
95
- const leftJunctionAttributes = leftRelation.remoteAttributes || [];
96
- const leftTableAttributes = leftRelation.localAttributes || [];
97
- const rightJunctionAttributes = junctionRightRelation.localAttributes || [];
98
- const rightTableAttributes = junctionRightRelation.remoteAttributes || [];
99
- const relationFieldName = safeInflection(() => context.build.inflection._manyToManyRelation?.(details), details.rightRelationName || rightCodec.name || null);
100
- const junctionLeftConstraint = buildForeignKeyConstraint(details.leftRelationName || `${junctionCodec.name}_${leftCodec.name}_fkey`, junctionCodec, junctionCodec.attributes, leftJunctionAttributes, leftCodec, leftCodec.attributes, leftTableAttributes, context);
101
- const junctionRightConstraint = buildForeignKeyConstraint(details.rightRelationName || `${junctionCodec.name}_${rightCodec.name}_fkey`, junctionCodec, junctionCodec.attributes, rightJunctionAttributes, rightCodec, rightCodec.attributes, rightTableAttributes, context);
102
- return {
103
- fieldName: relationFieldName,
104
- type: rightCodec.name || null,
105
- junctionTable: { name: junctionCodec.name || 'unknown' },
106
- junctionLeftConstraint,
107
- junctionLeftKeyAttributes: buildFieldList(leftJunctionAttributes, junctionCodec, junctionCodec.attributes, context),
108
- junctionRightConstraint,
109
- junctionRightKeyAttributes: buildFieldList(rightJunctionAttributes, junctionCodec, junctionCodec.attributes, context),
110
- leftKeyAttributes: buildFieldList(leftTableAttributes, leftCodec, leftCodec.attributes, context),
111
- rightKeyAttributes: buildFieldList(rightTableAttributes, rightCodec, rightCodec.attributes, context),
112
- rightTable: { name: rightCodec.name || 'unknown' },
113
- };
114
- }
115
- export function buildManyToManyRelations(resource, codec, context) {
116
- return getManyToManyRelationships(context.build, resource, codec)
117
- .map((details) => buildManyToManyRelation(details, context))
118
- .filter((relation) => relation !== null);
119
- }
@@ -1,15 +0,0 @@
1
- import type { PgCodec, ScopeMeta } from './types';
2
- /**
3
- * Detect provisioning scope metadata for a table.
4
- *
5
- * The `@scope` smart tag emitted by the constructive-db generators is the sole
6
- * source of truth. `apply_scope_fields` knows the exact scope, tier, key column,
7
- * and entity table, and emits them via
8
- * `metaschema.append_table_smart_tags(id, { scope, scopeTier, scopeKey, scopeEntityTable })`.
9
- * PostGraphile surfaces these as `codec.extensions.tags.*`.
10
- *
11
- * There is NO inference from column names — a table without the tag returns
12
- * `null` (the same convention as every other nullable metadata block). This
13
- * avoids guessing key columns, whose names are chosen freely by each generator.
14
- */
15
- export declare function buildScopeMeta(codec: PgCodec, inflectAttr: (attrName: string, codec: PgCodec) => string): ScopeMeta | null;
@@ -1,40 +0,0 @@
1
- const VALID_TIERS = new Set(['global', 'database', 'entity']);
2
- function readString(value) {
3
- return typeof value === 'string' && value.length > 0 ? value : null;
4
- }
5
- /**
6
- * Detect provisioning scope metadata for a table.
7
- *
8
- * The `@scope` smart tag emitted by the constructive-db generators is the sole
9
- * source of truth. `apply_scope_fields` knows the exact scope, tier, key column,
10
- * and entity table, and emits them via
11
- * `metaschema.append_table_smart_tags(id, { scope, scopeTier, scopeKey, scopeEntityTable })`.
12
- * PostGraphile surfaces these as `codec.extensions.tags.*`.
13
- *
14
- * There is NO inference from column names — a table without the tag returns
15
- * `null` (the same convention as every other nullable metadata block). This
16
- * avoids guessing key columns, whose names are chosen freely by each generator.
17
- */
18
- export function buildScopeMeta(codec, inflectAttr) {
19
- const tags = codec.extensions?.tags;
20
- const scope = readString(tags?.scope);
21
- if (!scope)
22
- return null;
23
- const rawTier = readString(tags.scopeTier);
24
- const tier = rawTier && VALID_TIERS.has(rawTier)
25
- ? rawTier
26
- : null;
27
- if (!tier) {
28
- throw new Error(`@scope tag on codec "${codec.name}" is missing a valid scopeTier ` +
29
- `(expected one of global|database|entity, got ${JSON.stringify(rawTier)})`);
30
- }
31
- const keyColumn = readString(tags.scopeKey);
32
- const entityTable = readString(tags.scopeEntityTable);
33
- return {
34
- scope,
35
- tier,
36
- keyColumn: keyColumn ? inflectAttr(keyColumn, codec) : null,
37
- entityTable,
38
- source: 'smartTag'
39
- };
40
- }
@@ -1,29 +0,0 @@
1
- import type { I18nMeta, PgCodec, RealtimeMeta, SearchMeta, StorageMeta } from './types';
2
- /**
3
- * Detect storage metadata from a codec's smart tags.
4
- * Storage tables are identified by @storageFiles and @storageBuckets smart tags.
5
- */
6
- export declare function buildStorageMeta(codec: PgCodec): StorageMeta | null;
7
- /**
8
- * Detect search metadata from a codec's columns and smart tags.
9
- *
10
- * Looks for:
11
- * - tsvector columns (full-text search)
12
- * - vector columns (pgvector semantic search)
13
- * - @searchConfig smart tag (per-table search configuration)
14
- * - @bm25Index smart tag on columns (BM25 search)
15
- * - @trgmSearch smart tag (trigram search)
16
- */
17
- export declare function buildSearchMeta(codec: PgCodec, _build: unknown, inflectAttr: (attrName: string, codec: PgCodec) => string): SearchMeta | null;
18
- /**
19
- * Detect i18n metadata from a codec's @i18n smart tag.
20
- * The @i18n tag value is the name of the translation table.
21
- * Translatable fields are discovered by matching text/citext columns
22
- * between the base table and the translation table codec.
23
- */
24
- export declare function buildI18nMeta(codec: PgCodec, build: unknown, inflectAttr: (attrName: string, codec: PgCodec) => string): I18nMeta | null;
25
- /**
26
- * Detect realtime metadata from a codec's @realtime smart tag.
27
- * Tables tagged with @realtime get subscription fields generated.
28
- */
29
- export declare function buildRealtimeMeta(codec: PgCodec, build: unknown): RealtimeMeta | null;