graphile-settings 6.5.2 → 6.5.4

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 +4 -3
  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
@@ -12,7 +12,7 @@ export { ManyToManyOptInPlugin, ManyToManyOptInPreset, } from './many-to-many-pr
12
12
  export { createUniqueLookupPlugin, PrimaryKeyOnlyPlugin, NoUniqueLookupPlugin, PrimaryKeyOnlyPreset, NoUniqueLookupPreset, } from './primary-key-only';
13
13
  export type { UniqueLookupOptions } from './primary-key-only';
14
14
  export { MetaSchemaPlugin, MetaSchemaPreset, } from './meta-schema';
15
- export type { TableMeta, FieldMeta, TypeMeta, IndexMeta, ConstraintsMeta, PrimaryKeyConstraintMeta, UniqueConstraintMeta, ForeignKeyConstraintMeta, RelationsMeta, BelongsToRelation, HasRelation, ManyToManyRelation, InflectionMeta, QueryMeta, } from './meta-schema/types';
15
+ export type { TableMeta, FieldMeta, TypeMeta, IndexMeta, ConstraintsMeta, PrimaryKeyConstraintMeta, UniqueConstraintMeta, ForeignKeyConstraintMeta, RelationsMeta, BelongsToRelation, HasRelation, ManyToManyRelation, InflectionMeta, QueryMeta, } from 'graphile-meta';
16
16
  export { PgTypeMappingsPlugin, PgTypeMappingsPreset, } from './pg-type-mappings';
17
17
  export type { TypeMapping } from './pg-type-mappings';
18
18
  export { PublicKeySignature } from './PublicKeySignature';
@@ -1,22 +1,7 @@
1
1
  /**
2
2
  * PostGraphile v5 Meta Schema Plugin
3
3
  *
4
- * Exposes a `_meta` GraphQL query that provides metadata about tables, fields,
5
- * constraints, indexes, and relations for code generation tooling.
4
+ * Re-exported from the `graphile-meta` package for backward compatibility.
6
5
  */
7
- import type { GraphileConfig } from 'graphile-config';
8
- import { cachedTablesMeta } from './meta-schema/cache';
9
- import { buildScalarEncoding } from './meta-schema/encoding-meta-builders';
10
- import { MetaSchemaPlugin } from './meta-schema/plugin';
11
- import { buildFieldMeta, pgTypeToGqlType } from './meta-schema/type-mappings';
12
- export { MetaSchemaPlugin };
13
- export declare const MetaSchemaPreset: GraphileConfig.Preset;
14
- /** @internal Exported for testing only */
15
- export { pgTypeToGqlType as _pgTypeToGqlType };
16
- /** @internal Exported for testing only */
17
- export { buildFieldMeta as _buildFieldMeta };
18
- /** @internal Exported for testing only */
19
- export { cachedTablesMeta as _cachedTablesMeta };
20
- /** @internal Exported for testing only */
21
- export { buildScalarEncoding as _buildScalarEncoding };
22
- export default MetaSchemaPlugin;
6
+ export { _buildFieldMeta, _buildScalarEncoding, _cachedTablesMeta, _pgTypeToGqlType, MetaSchemaPlugin, MetaSchemaPreset, } from 'graphile-meta';
7
+ export { MetaSchemaPlugin as default } from 'graphile-meta';
@@ -1,23 +1,7 @@
1
1
  /**
2
2
  * PostGraphile v5 Meta Schema Plugin
3
3
  *
4
- * Exposes a `_meta` GraphQL query that provides metadata about tables, fields,
5
- * constraints, indexes, and relations for code generation tooling.
4
+ * Re-exported from the `graphile-meta` package for backward compatibility.
6
5
  */
7
- import { cachedTablesMeta } from './meta-schema/cache';
8
- import { buildScalarEncoding } from './meta-schema/encoding-meta-builders';
9
- import { MetaSchemaPlugin } from './meta-schema/plugin';
10
- import { buildFieldMeta, pgTypeToGqlType } from './meta-schema/type-mappings';
11
- export { MetaSchemaPlugin };
12
- export const MetaSchemaPreset = {
13
- plugins: [MetaSchemaPlugin],
14
- };
15
- /** @internal Exported for testing only */
16
- export { pgTypeToGqlType as _pgTypeToGqlType };
17
- /** @internal Exported for testing only */
18
- export { buildFieldMeta as _buildFieldMeta };
19
- /** @internal Exported for testing only */
20
- export { cachedTablesMeta as _cachedTablesMeta };
21
- /** @internal Exported for testing only */
22
- export { buildScalarEncoding as _buildScalarEncoding };
23
- export default MetaSchemaPlugin;
6
+ export { _buildFieldMeta, _buildScalarEncoding, _cachedTablesMeta, _pgTypeToGqlType, MetaSchemaPlugin, MetaSchemaPreset, } from 'graphile-meta';
7
+ export { MetaSchemaPlugin as default } from 'graphile-meta';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphile-settings",
3
- "version": "6.5.2",
3
+ "version": "6.5.4",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "graphile settings",
6
6
  "main": "index.js",
@@ -53,8 +53,9 @@
53
53
  "graphile-config": "1.0.1",
54
54
  "graphile-connection-filter": "^2.5.2",
55
55
  "graphile-i18n": "^2.5.2",
56
- "graphile-llm": "^1.5.2",
56
+ "graphile-llm": "^1.5.3",
57
57
  "graphile-ltree": "^2.5.2",
58
+ "graphile-meta": "^1.1.1",
58
59
  "graphile-pg-aggregates": "^2.5.2",
59
60
  "graphile-postgis": "^3.5.2",
60
61
  "graphile-presigned-url-plugin": "^1.4.0",
@@ -89,5 +90,5 @@
89
90
  "constructive",
90
91
  "graphql"
91
92
  ],
92
- "gitHead": "dd16395013ff8c9d5e4cd2f5f5bec72c46f4099b"
93
+ "gitHead": "31f7cd3d3cc28cf069056eae5b2a0d4198d154a1"
93
94
  }
@@ -12,7 +12,7 @@ export { ManyToManyOptInPlugin, ManyToManyOptInPreset, } from './many-to-many-pr
12
12
  export { createUniqueLookupPlugin, PrimaryKeyOnlyPlugin, NoUniqueLookupPlugin, PrimaryKeyOnlyPreset, NoUniqueLookupPreset, } from './primary-key-only';
13
13
  export type { UniqueLookupOptions } from './primary-key-only';
14
14
  export { MetaSchemaPlugin, MetaSchemaPreset, } from './meta-schema';
15
- export type { TableMeta, FieldMeta, TypeMeta, IndexMeta, ConstraintsMeta, PrimaryKeyConstraintMeta, UniqueConstraintMeta, ForeignKeyConstraintMeta, RelationsMeta, BelongsToRelation, HasRelation, ManyToManyRelation, InflectionMeta, QueryMeta, } from './meta-schema/types';
15
+ export type { TableMeta, FieldMeta, TypeMeta, IndexMeta, ConstraintsMeta, PrimaryKeyConstraintMeta, UniqueConstraintMeta, ForeignKeyConstraintMeta, RelationsMeta, BelongsToRelation, HasRelation, ManyToManyRelation, InflectionMeta, QueryMeta, } from 'graphile-meta';
16
16
  export { PgTypeMappingsPlugin, PgTypeMappingsPreset, } from './pg-type-mappings';
17
17
  export type { TypeMapping } from './pg-type-mappings';
18
18
  export { PublicKeySignature } from './PublicKeySignature';
@@ -1,22 +1,7 @@
1
1
  /**
2
2
  * PostGraphile v5 Meta Schema Plugin
3
3
  *
4
- * Exposes a `_meta` GraphQL query that provides metadata about tables, fields,
5
- * constraints, indexes, and relations for code generation tooling.
4
+ * Re-exported from the `graphile-meta` package for backward compatibility.
6
5
  */
7
- import type { GraphileConfig } from 'graphile-config';
8
- import { cachedTablesMeta } from './meta-schema/cache';
9
- import { buildScalarEncoding } from './meta-schema/encoding-meta-builders';
10
- import { MetaSchemaPlugin } from './meta-schema/plugin';
11
- import { buildFieldMeta, pgTypeToGqlType } from './meta-schema/type-mappings';
12
- export { MetaSchemaPlugin };
13
- export declare const MetaSchemaPreset: GraphileConfig.Preset;
14
- /** @internal Exported for testing only */
15
- export { pgTypeToGqlType as _pgTypeToGqlType };
16
- /** @internal Exported for testing only */
17
- export { buildFieldMeta as _buildFieldMeta };
18
- /** @internal Exported for testing only */
19
- export { cachedTablesMeta as _cachedTablesMeta };
20
- /** @internal Exported for testing only */
21
- export { buildScalarEncoding as _buildScalarEncoding };
22
- export default MetaSchemaPlugin;
6
+ export { _buildFieldMeta, _buildScalarEncoding, _cachedTablesMeta, _pgTypeToGqlType, MetaSchemaPlugin, MetaSchemaPreset, } from 'graphile-meta';
7
+ export { MetaSchemaPlugin as default } from 'graphile-meta';
@@ -2,21 +2,16 @@
2
2
  /**
3
3
  * PostGraphile v5 Meta Schema Plugin
4
4
  *
5
- * Exposes a `_meta` GraphQL query that provides metadata about tables, fields,
6
- * constraints, indexes, and relations for code generation tooling.
5
+ * Re-exported from the `graphile-meta` package for backward compatibility.
7
6
  */
8
7
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports._buildScalarEncoding = exports._cachedTablesMeta = exports._buildFieldMeta = exports._pgTypeToGqlType = exports.MetaSchemaPreset = exports.MetaSchemaPlugin = void 0;
10
- const cache_1 = require("./meta-schema/cache");
11
- Object.defineProperty(exports, "_cachedTablesMeta", { enumerable: true, get: function () { return cache_1.cachedTablesMeta; } });
12
- const encoding_meta_builders_1 = require("./meta-schema/encoding-meta-builders");
13
- Object.defineProperty(exports, "_buildScalarEncoding", { enumerable: true, get: function () { return encoding_meta_builders_1.buildScalarEncoding; } });
14
- const plugin_1 = require("./meta-schema/plugin");
15
- Object.defineProperty(exports, "MetaSchemaPlugin", { enumerable: true, get: function () { return plugin_1.MetaSchemaPlugin; } });
16
- const type_mappings_1 = require("./meta-schema/type-mappings");
17
- Object.defineProperty(exports, "_buildFieldMeta", { enumerable: true, get: function () { return type_mappings_1.buildFieldMeta; } });
18
- Object.defineProperty(exports, "_pgTypeToGqlType", { enumerable: true, get: function () { return type_mappings_1.pgTypeToGqlType; } });
19
- exports.MetaSchemaPreset = {
20
- plugins: [plugin_1.MetaSchemaPlugin],
21
- };
22
- exports.default = plugin_1.MetaSchemaPlugin;
8
+ exports.default = exports.MetaSchemaPreset = exports.MetaSchemaPlugin = exports._pgTypeToGqlType = exports._cachedTablesMeta = exports._buildScalarEncoding = exports._buildFieldMeta = void 0;
9
+ var graphile_meta_1 = require("graphile-meta");
10
+ Object.defineProperty(exports, "_buildFieldMeta", { enumerable: true, get: function () { return graphile_meta_1._buildFieldMeta; } });
11
+ Object.defineProperty(exports, "_buildScalarEncoding", { enumerable: true, get: function () { return graphile_meta_1._buildScalarEncoding; } });
12
+ Object.defineProperty(exports, "_cachedTablesMeta", { enumerable: true, get: function () { return graphile_meta_1._cachedTablesMeta; } });
13
+ Object.defineProperty(exports, "_pgTypeToGqlType", { enumerable: true, get: function () { return graphile_meta_1._pgTypeToGqlType; } });
14
+ Object.defineProperty(exports, "MetaSchemaPlugin", { enumerable: true, get: function () { return graphile_meta_1.MetaSchemaPlugin; } });
15
+ Object.defineProperty(exports, "MetaSchemaPreset", { enumerable: true, get: function () { return graphile_meta_1.MetaSchemaPreset; } });
16
+ var graphile_meta_2 = require("graphile-meta");
17
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return graphile_meta_2.MetaSchemaPlugin; } });
@@ -1,4 +0,0 @@
1
- import type { TableMeta } from './types';
2
- export declare let cachedTablesMeta: TableMeta[];
3
- export declare function getCachedTablesMeta(): TableMeta[];
4
- export declare function setCachedTablesMeta(tablesMeta: TableMeta[]): void;
@@ -1,7 +0,0 @@
1
- export let cachedTablesMeta = [];
2
- export function getCachedTablesMeta() {
3
- return cachedTablesMeta;
4
- }
5
- export function setCachedTablesMeta(tablesMeta) {
6
- cachedTablesMeta = tablesMeta;
7
- }
@@ -1,13 +0,0 @@
1
- import { type BuildContext } from './table-meta-context';
2
- import type { ForeignKeyConstraintMeta, PgAttribute, PgCodec, PgRelation, PgUnique, PrimaryKeyConstraintMeta, UniqueConstraintMeta } from './types';
3
- export declare function buildForeignKeyConstraint(constraintName: string, localCodec: PgCodec, localAttributes: Record<string, PgAttribute>, localAttributeNames: string[], remoteCodec: PgCodec | undefined, remoteAttributes: Record<string, PgAttribute>, remoteAttributeNames: string[], context: BuildContext): ForeignKeyConstraintMeta;
4
- export declare function buildIndexes(codec: PgCodec, attributes: Record<string, PgAttribute>, uniques: PgUnique[], context: BuildContext): {
5
- name: string;
6
- isUnique: boolean;
7
- isPrimary: boolean;
8
- columns: string[];
9
- fields: import("./types").FieldMeta[];
10
- }[];
11
- export declare function buildPrimaryKey(codec: PgCodec, attributes: Record<string, PgAttribute>, uniques: PgUnique[], context: BuildContext): PrimaryKeyConstraintMeta | null;
12
- export declare function buildUniqueConstraints(codec: PgCodec, attributes: Record<string, PgAttribute>, uniques: PgUnique[], context: BuildContext): UniqueConstraintMeta[];
13
- export declare function buildForeignKeyConstraints(codec: PgCodec, attributes: Record<string, PgAttribute>, relations: Record<string, PgRelation>, context: BuildContext): ForeignKeyConstraintMeta[];
@@ -1,51 +0,0 @@
1
- import { buildFieldMeta } from './type-mappings';
2
- import { buildFieldList } from './table-meta-context';
3
- export function buildForeignKeyConstraint(constraintName, localCodec, localAttributes, localAttributeNames, remoteCodec, remoteAttributes, remoteAttributeNames, context) {
4
- const referencedTable = remoteCodec?.name || 'unknown';
5
- const referencedFields = remoteAttributeNames.map((attrName) => remoteCodec ? context.inflectAttr(attrName, remoteCodec) : attrName);
6
- return {
7
- name: constraintName,
8
- fields: buildFieldList(localAttributeNames, localCodec, localAttributes, context),
9
- referencedTable,
10
- referencedFields,
11
- refFields: remoteAttributeNames.map((attrName) => buildFieldMeta(remoteCodec ? context.inflectAttr(attrName, remoteCodec) : attrName, remoteAttributes[attrName], context.build)),
12
- refTable: { name: referencedTable },
13
- };
14
- }
15
- export function buildIndexes(codec, attributes, uniques, context) {
16
- return uniques.map((unique) => ({
17
- name: unique.tags?.name || `${codec.name}_${unique.attributes.join('_')}_idx`,
18
- isUnique: true,
19
- isPrimary: !!unique.isPrimary,
20
- columns: unique.attributes.map((attrName) => context.inflectAttr(attrName, codec)),
21
- fields: buildFieldList(unique.attributes, codec, attributes, context),
22
- }));
23
- }
24
- export function buildPrimaryKey(codec, attributes, uniques, context) {
25
- const primaryUnique = uniques.find((unique) => unique.isPrimary);
26
- if (!primaryUnique)
27
- return null;
28
- return {
29
- name: primaryUnique.tags?.name || `${codec.name}_pkey`,
30
- fields: buildFieldList(primaryUnique.attributes, codec, attributes, context),
31
- };
32
- }
33
- export function buildUniqueConstraints(codec, attributes, uniques, context) {
34
- return uniques
35
- .filter((unique) => !unique.isPrimary)
36
- .map((unique) => ({
37
- name: unique.tags?.name || `${codec.name}_${unique.attributes.join('_')}_key`,
38
- fields: buildFieldList(unique.attributes, codec, attributes, context),
39
- }));
40
- }
41
- export function buildForeignKeyConstraints(codec, attributes, relations, context) {
42
- const constraints = [];
43
- for (const [relationName, relation] of Object.entries(relations)) {
44
- if (relation.isReferencee)
45
- continue;
46
- const remoteCodec = relation.remoteResource?.codec;
47
- const remoteAttributes = remoteCodec?.attributes || {};
48
- constraints.push(buildForeignKeyConstraint(relationName, codec, attributes, relation.localAttributes || [], remoteCodec, remoteAttributes, relation.remoteAttributes || [], context));
49
- }
50
- return constraints;
51
- }
@@ -1,2 +0,0 @@
1
- import type { PgAttribute, ScalarEncodingMeta } from './types';
2
- export declare function buildScalarEncoding(attr: PgAttribute | null | undefined): ScalarEncodingMeta | null;
@@ -1,84 +0,0 @@
1
- /**
2
- * Scalar encoding contracts — the one piece of field metadata standard GraphQL
3
- * introspection can't provide.
4
- *
5
- * Introspection tells a client a field's scalar *name* (`GeoJSON`, `LTree`,
6
- * `Interval`, `BigInt`, `vector`, …) but not how to serialize/parse it or its
7
- * structural parameters (geometry subtype/SRID, vector dimensions, ltree
8
- * dot-path semantics). Without that, generated clients treat these as opaque
9
- * strings / `any` and mis-encode inputs or fail to parse outputs.
10
- *
11
- * `kind` is derived deterministically from the *underlying* codec (array and
12
- * domain wrappers unwrapped first, first match wins) so exactly one kind is
13
- * ever assigned and nothing can clobber it. Structural extras (subtype, SRID,
14
- * dimensions) are read verbatim from attribute extensions — never guessed, and
15
- * `null` when absent.
16
- */
17
- /** pg type name → encoding kind. Plain scalars are intentionally absent → null. */
18
- const KIND_BY_PG_TYPE = {
19
- int8: 'bigint',
20
- bigint: 'bigint',
21
- numeric: 'bigint',
22
- timestamptz: 'datetime',
23
- timestamp: 'datetime',
24
- date: 'date',
25
- time: 'time',
26
- timetz: 'time',
27
- interval: 'interval',
28
- uuid: 'uuid',
29
- geometry: 'geojson',
30
- geography: 'geojson',
31
- point: 'point',
32
- inet: 'inet',
33
- cidr: 'inet',
34
- ltree: 'ltree',
35
- vector: 'vector',
36
- bytea: 'bytea'
37
- };
38
- /** Unwrap array-of and domain-of wrappers to the underlying scalar/record codec. */
39
- function underlyingCodec(codec) {
40
- let current = codec ?? null;
41
- const seen = new Set();
42
- while (current && !seen.has(current) && (current.arrayOfCodec || current.domainOfCodec)) {
43
- seen.add(current);
44
- current = current.arrayOfCodec || current.domainOfCodec || null;
45
- }
46
- return current;
47
- }
48
- /** True when a codec is a composite/record type (has named attributes). */
49
- function isCompositeCodec(codec) {
50
- return !!codec?.attributes && Object.keys(codec.attributes).length > 0;
51
- }
52
- export function buildScalarEncoding(attr) {
53
- const codec = underlyingCodec(attr?.codec);
54
- if (!codec)
55
- return null;
56
- const ext = attr?.extensions ?? undefined;
57
- const kind = KIND_BY_PG_TYPE[codec.name];
58
- if (!kind) {
59
- // Composite/record types are the only non-mapped scalars worth describing;
60
- // everything else (text, int, bool, json, enum, …) is fully covered by gqlType.
61
- if (isCompositeCodec(codec)) {
62
- return { kind: 'composite', fields: null };
63
- }
64
- return null;
65
- }
66
- switch (kind) {
67
- case 'geojson':
68
- return {
69
- kind,
70
- geometrySubtype: typeof ext?.geometrySubtype === 'string' ? ext.geometrySubtype : null,
71
- srid: typeof ext?.geometrySrid === 'number' ? ext.geometrySrid : null
72
- };
73
- case 'vector':
74
- return {
75
- kind,
76
- elementType: 'float',
77
- dimensions: typeof ext?.vectorDimensions === 'number' ? ext.vectorDimensions : null
78
- };
79
- case 'ltree':
80
- return { kind, dotPath: true };
81
- default:
82
- return { kind };
83
- }
84
- }
@@ -1,4 +0,0 @@
1
- import type { TableMeta } from './types';
2
- type FieldMap = Record<string, unknown>;
3
- export declare function extendQueryWithMetaField(fields: FieldMap, tablesMeta: TableMeta[]): FieldMap;
4
- export {};
@@ -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
- }