@constructive-io/graphql-codegen 2.22.1 → 2.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/codegen/barrel.d.ts +5 -1
- package/cli/codegen/barrel.js +13 -11
- package/cli/codegen/index.d.ts +3 -3
- package/cli/codegen/index.js +15 -9
- package/cli/codegen/orm/client-generator.js +3 -2
- package/cli/codegen/orm/custom-ops-generator.js +17 -4
- package/cli/codegen/orm/input-types-generator.js +129 -18
- package/cli/codegen/orm/model-generator.js +2 -1
- package/cli/codegen/orm/query-builder.d.ts +1 -1
- package/cli/codegen/orm/query-builder.js +2 -2
- package/cli/codegen/schema-types-generator.js +5 -5
- package/cli/codegen/utils.d.ts +6 -1
- package/cli/codegen/utils.js +23 -8
- package/cli/commands/generate-orm.d.ts +5 -3
- package/cli/commands/generate-orm.js +65 -84
- package/cli/commands/generate.d.ts +2 -0
- package/cli/commands/generate.js +66 -87
- package/cli/commands/shared.d.ts +74 -0
- package/cli/commands/shared.js +88 -0
- package/cli/index.js +75 -45
- package/cli/introspect/index.d.ts +8 -5
- package/cli/introspect/index.js +19 -7
- package/cli/introspect/infer-tables.d.ts +51 -0
- package/cli/introspect/infer-tables.js +550 -0
- package/cli/introspect/source/endpoint.d.ts +34 -0
- package/cli/introspect/source/endpoint.js +35 -0
- package/cli/introspect/source/file.d.ts +20 -0
- package/cli/introspect/source/file.js +103 -0
- package/cli/introspect/source/index.d.ts +48 -0
- package/cli/introspect/source/index.js +72 -0
- package/cli/introspect/source/types.d.ts +58 -0
- package/cli/introspect/source/types.js +27 -0
- package/cli/introspect/transform.d.ts +5 -6
- package/cli/introspect/transform.js +0 -173
- package/cli/watch/cache.d.ts +3 -4
- package/cli/watch/cache.js +6 -10
- package/cli/watch/poller.d.ts +1 -2
- package/cli/watch/poller.js +27 -45
- package/cli/watch/types.d.ts +0 -3
- package/core/ast.js +4 -4
- package/core/query-builder.js +12 -12
- package/esm/cli/codegen/barrel.d.ts +5 -1
- package/esm/cli/codegen/barrel.js +13 -11
- package/esm/cli/codegen/index.d.ts +3 -3
- package/esm/cli/codegen/index.js +18 -12
- package/esm/cli/codegen/orm/client-generator.js +3 -2
- package/esm/cli/codegen/orm/custom-ops-generator.js +18 -5
- package/esm/cli/codegen/orm/input-types-generator.js +130 -19
- package/esm/cli/codegen/orm/model-generator.js +3 -2
- package/esm/cli/codegen/orm/query-builder.d.ts +1 -1
- package/esm/cli/codegen/orm/query-builder.js +2 -2
- package/esm/cli/codegen/schema-types-generator.js +6 -6
- package/esm/cli/codegen/utils.d.ts +6 -1
- package/esm/cli/codegen/utils.js +22 -8
- package/esm/cli/commands/generate-orm.d.ts +5 -3
- package/esm/cli/commands/generate-orm.js +65 -84
- package/esm/cli/commands/generate.d.ts +2 -0
- package/esm/cli/commands/generate.js +66 -87
- package/esm/cli/commands/shared.d.ts +74 -0
- package/esm/cli/commands/shared.js +84 -0
- package/esm/cli/index.js +76 -46
- package/esm/cli/introspect/index.d.ts +8 -5
- package/esm/cli/introspect/index.js +10 -3
- package/esm/cli/introspect/infer-tables.d.ts +51 -0
- package/esm/cli/introspect/infer-tables.js +547 -0
- package/esm/cli/introspect/source/endpoint.d.ts +34 -0
- package/esm/cli/introspect/source/endpoint.js +31 -0
- package/esm/cli/introspect/source/file.d.ts +20 -0
- package/esm/cli/introspect/source/file.js +66 -0
- package/esm/cli/introspect/source/index.d.ts +48 -0
- package/esm/cli/introspect/source/index.js +54 -0
- package/esm/cli/introspect/source/types.d.ts +58 -0
- package/esm/cli/introspect/source/types.js +23 -0
- package/esm/cli/introspect/transform.d.ts +5 -6
- package/esm/cli/introspect/transform.js +0 -172
- package/esm/cli/watch/cache.d.ts +3 -4
- package/esm/cli/watch/cache.js +7 -11
- package/esm/cli/watch/poller.d.ts +1 -2
- package/esm/cli/watch/poller.js +28 -46
- package/esm/cli/watch/types.d.ts +0 -3
- package/esm/core/ast.js +4 -4
- package/esm/core/query-builder.js +12 -12
- package/esm/generators/mutations.js +3 -3
- package/esm/generators/select.js +7 -7
- package/esm/types/config.d.ts +21 -5
- package/esm/types/config.js +2 -1
- package/generators/mutations.js +3 -3
- package/generators/select.js +7 -7
- package/package.json +5 -3
- package/types/config.d.ts +21 -5
- package/types/config.js +2 -1
- package/cli/introspect/fetch-meta.d.ts +0 -31
- package/cli/introspect/fetch-meta.js +0 -108
- package/cli/introspect/meta-query.d.ts +0 -111
- package/cli/introspect/meta-query.js +0 -191
- package/esm/cli/introspect/fetch-meta.d.ts +0 -31
- package/esm/cli/introspect/fetch-meta.js +0 -104
- package/esm/cli/introspect/meta-query.d.ts +0 -111
- package/esm/cli/introspect/meta-query.js +0 -188
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.FileSchemaSource = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* File Schema Source
|
|
39
|
+
*
|
|
40
|
+
* Loads GraphQL schema from a local .graphql SDL file and converts it
|
|
41
|
+
* to introspection format using the graphql package.
|
|
42
|
+
*/
|
|
43
|
+
const fs = __importStar(require("node:fs"));
|
|
44
|
+
const path = __importStar(require("node:path"));
|
|
45
|
+
const graphql_1 = require("graphql");
|
|
46
|
+
const types_1 = require("./types");
|
|
47
|
+
/**
|
|
48
|
+
* Schema source that loads from a local GraphQL schema file
|
|
49
|
+
*
|
|
50
|
+
* Supports .graphql files containing SDL (Schema Definition Language).
|
|
51
|
+
* The SDL is parsed using graphql-js and converted to introspection format.
|
|
52
|
+
*/
|
|
53
|
+
class FileSchemaSource {
|
|
54
|
+
options;
|
|
55
|
+
constructor(options) {
|
|
56
|
+
this.options = options;
|
|
57
|
+
}
|
|
58
|
+
async fetch() {
|
|
59
|
+
const absolutePath = path.isAbsolute(this.options.schemaPath)
|
|
60
|
+
? this.options.schemaPath
|
|
61
|
+
: path.resolve(process.cwd(), this.options.schemaPath);
|
|
62
|
+
// Check file exists
|
|
63
|
+
if (!fs.existsSync(absolutePath)) {
|
|
64
|
+
throw new types_1.SchemaSourceError(`Schema file not found: ${absolutePath}`, this.describe());
|
|
65
|
+
}
|
|
66
|
+
// Read file content
|
|
67
|
+
let sdl;
|
|
68
|
+
try {
|
|
69
|
+
sdl = await fs.promises.readFile(absolutePath, 'utf-8');
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
throw new types_1.SchemaSourceError(`Failed to read schema file: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
|
|
73
|
+
}
|
|
74
|
+
// Validate non-empty
|
|
75
|
+
if (!sdl.trim()) {
|
|
76
|
+
throw new types_1.SchemaSourceError('Schema file is empty', this.describe());
|
|
77
|
+
}
|
|
78
|
+
// Parse SDL to GraphQL schema
|
|
79
|
+
let schema;
|
|
80
|
+
try {
|
|
81
|
+
schema = (0, graphql_1.buildSchema)(sdl);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
throw new types_1.SchemaSourceError(`Invalid GraphQL SDL: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
|
|
85
|
+
}
|
|
86
|
+
// Convert to introspection format
|
|
87
|
+
let introspectionResult;
|
|
88
|
+
try {
|
|
89
|
+
introspectionResult = (0, graphql_1.introspectionFromSchema)(schema);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
throw new types_1.SchemaSourceError(`Failed to generate introspection: ${err instanceof Error ? err.message : 'Unknown error'}`, this.describe(), err instanceof Error ? err : undefined);
|
|
93
|
+
}
|
|
94
|
+
// Convert graphql-js introspection result to our mutable type
|
|
95
|
+
// The graphql-js types are readonly, but our types are mutable
|
|
96
|
+
const introspection = JSON.parse(JSON.stringify(introspectionResult));
|
|
97
|
+
return { introspection };
|
|
98
|
+
}
|
|
99
|
+
describe() {
|
|
100
|
+
return `file: ${this.options.schemaPath}`;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.FileSchemaSource = FileSchemaSource;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Source Module
|
|
3
|
+
*
|
|
4
|
+
* Provides a unified interface for loading GraphQL schemas from different sources:
|
|
5
|
+
* - Live GraphQL endpoints (via introspection)
|
|
6
|
+
* - Static .graphql schema files
|
|
7
|
+
*/
|
|
8
|
+
export * from './types';
|
|
9
|
+
export * from './endpoint';
|
|
10
|
+
export * from './file';
|
|
11
|
+
import type { SchemaSource } from './types';
|
|
12
|
+
export interface CreateSchemaSourceOptions {
|
|
13
|
+
/**
|
|
14
|
+
* GraphQL endpoint URL (for live introspection)
|
|
15
|
+
*/
|
|
16
|
+
endpoint?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Path to GraphQL schema file (.graphql)
|
|
19
|
+
*/
|
|
20
|
+
schema?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Optional authorization header for endpoint requests
|
|
23
|
+
*/
|
|
24
|
+
authorization?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Optional additional headers for endpoint requests
|
|
27
|
+
*/
|
|
28
|
+
headers?: Record<string, string>;
|
|
29
|
+
/**
|
|
30
|
+
* Request timeout in milliseconds (for endpoint requests)
|
|
31
|
+
*/
|
|
32
|
+
timeout?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a schema source based on configuration
|
|
36
|
+
*
|
|
37
|
+
* @param options - Source configuration
|
|
38
|
+
* @returns Appropriate SchemaSource implementation
|
|
39
|
+
* @throws Error if neither endpoint nor schema is provided
|
|
40
|
+
*/
|
|
41
|
+
export declare function createSchemaSource(options: CreateSchemaSourceOptions): SchemaSource;
|
|
42
|
+
/**
|
|
43
|
+
* Validate that source options are valid (at least one source specified)
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateSourceOptions(options: CreateSchemaSourceOptions): {
|
|
46
|
+
valid: boolean;
|
|
47
|
+
error?: string;
|
|
48
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.createSchemaSource = createSchemaSource;
|
|
18
|
+
exports.validateSourceOptions = validateSourceOptions;
|
|
19
|
+
/**
|
|
20
|
+
* Schema Source Module
|
|
21
|
+
*
|
|
22
|
+
* Provides a unified interface for loading GraphQL schemas from different sources:
|
|
23
|
+
* - Live GraphQL endpoints (via introspection)
|
|
24
|
+
* - Static .graphql schema files
|
|
25
|
+
*/
|
|
26
|
+
__exportStar(require("./types"), exports);
|
|
27
|
+
__exportStar(require("./endpoint"), exports);
|
|
28
|
+
__exportStar(require("./file"), exports);
|
|
29
|
+
const endpoint_1 = require("./endpoint");
|
|
30
|
+
const file_1 = require("./file");
|
|
31
|
+
/**
|
|
32
|
+
* Create a schema source based on configuration
|
|
33
|
+
*
|
|
34
|
+
* @param options - Source configuration
|
|
35
|
+
* @returns Appropriate SchemaSource implementation
|
|
36
|
+
* @throws Error if neither endpoint nor schema is provided
|
|
37
|
+
*/
|
|
38
|
+
function createSchemaSource(options) {
|
|
39
|
+
if (options.schema) {
|
|
40
|
+
return new file_1.FileSchemaSource({
|
|
41
|
+
schemaPath: options.schema,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (options.endpoint) {
|
|
45
|
+
return new endpoint_1.EndpointSchemaSource({
|
|
46
|
+
endpoint: options.endpoint,
|
|
47
|
+
authorization: options.authorization,
|
|
48
|
+
headers: options.headers,
|
|
49
|
+
timeout: options.timeout,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
throw new Error('Either endpoint or schema must be provided. ' +
|
|
53
|
+
'Use --endpoint for live introspection or --schema for a local file.');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Validate that source options are valid (at least one source specified)
|
|
57
|
+
*/
|
|
58
|
+
function validateSourceOptions(options) {
|
|
59
|
+
if (!options.endpoint && !options.schema) {
|
|
60
|
+
return {
|
|
61
|
+
valid: false,
|
|
62
|
+
error: 'Either endpoint or schema must be provided',
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (options.endpoint && options.schema) {
|
|
66
|
+
return {
|
|
67
|
+
valid: false,
|
|
68
|
+
error: 'Cannot use both endpoint and schema. Choose one source.',
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return { valid: true };
|
|
72
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema Source Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the interface for schema sources, allowing the codegen pipeline
|
|
5
|
+
* to work with both live GraphQL endpoints and static schema files.
|
|
6
|
+
*/
|
|
7
|
+
import type { IntrospectionQueryResponse } from '../../../types/introspection';
|
|
8
|
+
/**
|
|
9
|
+
* Result from fetching a schema source
|
|
10
|
+
*/
|
|
11
|
+
export interface SchemaSourceResult {
|
|
12
|
+
/**
|
|
13
|
+
* The GraphQL introspection data
|
|
14
|
+
*/
|
|
15
|
+
introspection: IntrospectionQueryResponse;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Abstract interface for schema sources
|
|
19
|
+
*
|
|
20
|
+
* Implementations:
|
|
21
|
+
* - EndpointSchemaSource: Fetches from a live GraphQL endpoint
|
|
22
|
+
* - FileSchemaSource: Loads from a local .graphql schema file
|
|
23
|
+
*/
|
|
24
|
+
export interface SchemaSource {
|
|
25
|
+
/**
|
|
26
|
+
* Fetch or load the GraphQL introspection data
|
|
27
|
+
* @throws SchemaSourceError if fetching fails
|
|
28
|
+
*/
|
|
29
|
+
fetch(): Promise<SchemaSourceResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Human-readable description of the source (for logging)
|
|
32
|
+
* @example "endpoint: https://api.example.com/graphql"
|
|
33
|
+
* @example "file: ./schema.graphql"
|
|
34
|
+
*/
|
|
35
|
+
describe(): string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Error thrown when a schema source fails to fetch
|
|
39
|
+
*/
|
|
40
|
+
export declare class SchemaSourceError extends Error {
|
|
41
|
+
/**
|
|
42
|
+
* Description of the source that failed
|
|
43
|
+
*/
|
|
44
|
+
readonly source: string;
|
|
45
|
+
/**
|
|
46
|
+
* Original error that caused the failure
|
|
47
|
+
*/
|
|
48
|
+
readonly cause?: Error;
|
|
49
|
+
constructor(message: string,
|
|
50
|
+
/**
|
|
51
|
+
* Description of the source that failed
|
|
52
|
+
*/
|
|
53
|
+
source: string,
|
|
54
|
+
/**
|
|
55
|
+
* Original error that caused the failure
|
|
56
|
+
*/
|
|
57
|
+
cause?: Error);
|
|
58
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SchemaSourceError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when a schema source fails to fetch
|
|
6
|
+
*/
|
|
7
|
+
class SchemaSourceError extends Error {
|
|
8
|
+
source;
|
|
9
|
+
cause;
|
|
10
|
+
constructor(message,
|
|
11
|
+
/**
|
|
12
|
+
* Description of the source that failed
|
|
13
|
+
*/
|
|
14
|
+
source,
|
|
15
|
+
/**
|
|
16
|
+
* Original error that caused the failure
|
|
17
|
+
*/
|
|
18
|
+
cause) {
|
|
19
|
+
super(`${message} (source: ${source})`);
|
|
20
|
+
this.source = source;
|
|
21
|
+
this.cause = cause;
|
|
22
|
+
this.name = 'SchemaSourceError';
|
|
23
|
+
// Maintain proper prototype chain
|
|
24
|
+
Object.setPrototypeOf(this, SchemaSourceError.prototype);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.SchemaSourceError = SchemaSourceError;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Table utility functions for CleanTable[]
|
|
3
|
+
*
|
|
4
|
+
* Note: The _meta transform functions have been removed.
|
|
5
|
+
* Tables are now inferred from standard GraphQL introspection
|
|
6
|
+
* using inferTablesFromIntrospection() in ./infer-tables.ts
|
|
3
7
|
*/
|
|
4
8
|
import type { CleanTable } from '../../types/schema';
|
|
5
|
-
import type { MetaQueryResponse } from './meta-query';
|
|
6
|
-
/**
|
|
7
|
-
* Transform _meta response to CleanTable array
|
|
8
|
-
*/
|
|
9
|
-
export declare function transformMetaToCleanTables(metaResponse: MetaQueryResponse): CleanTable[];
|
|
10
9
|
/**
|
|
11
10
|
* Get table names from CleanTable array
|
|
12
11
|
*/
|
|
@@ -1,181 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformMetaToCleanTables = transformMetaToCleanTables;
|
|
4
3
|
exports.getTableNames = getTableNames;
|
|
5
4
|
exports.findTable = findTable;
|
|
6
5
|
exports.filterTables = filterTables;
|
|
7
|
-
/**
|
|
8
|
-
* Transform _meta response to CleanTable array
|
|
9
|
-
*/
|
|
10
|
-
function transformMetaToCleanTables(metaResponse) {
|
|
11
|
-
const { tables } = metaResponse._meta;
|
|
12
|
-
return tables.map((table) => transformTable(table));
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Transform a single MetaTable to CleanTable
|
|
16
|
-
*/
|
|
17
|
-
function transformTable(table) {
|
|
18
|
-
return {
|
|
19
|
-
name: table.name,
|
|
20
|
-
fields: transformFields(table.fields),
|
|
21
|
-
relations: transformRelations(table.relations),
|
|
22
|
-
inflection: transformInflection(table.inflection),
|
|
23
|
-
query: transformQuery(table.query),
|
|
24
|
-
constraints: transformConstraints(table),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Transform MetaField[] to CleanField[]
|
|
29
|
-
*/
|
|
30
|
-
function transformFields(fields) {
|
|
31
|
-
return fields.map((field) => ({
|
|
32
|
-
name: field.name,
|
|
33
|
-
type: transformFieldType(field.type),
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Transform MetaFieldType to CleanFieldType
|
|
38
|
-
*/
|
|
39
|
-
function transformFieldType(type) {
|
|
40
|
-
return {
|
|
41
|
-
gqlType: type.gqlType,
|
|
42
|
-
isArray: type.isArray,
|
|
43
|
-
modifier: type.modifier,
|
|
44
|
-
pgAlias: type.pgAlias,
|
|
45
|
-
pgType: type.pgType,
|
|
46
|
-
subtype: type.subtype,
|
|
47
|
-
typmod: type.typmod,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Transform table relations
|
|
52
|
-
*/
|
|
53
|
-
function transformRelations(relations) {
|
|
54
|
-
return {
|
|
55
|
-
belongsTo: relations.belongsTo.map(transformBelongsTo),
|
|
56
|
-
hasOne: relations.hasOne.map(transformHasOne),
|
|
57
|
-
hasMany: relations.hasMany.map(transformHasMany),
|
|
58
|
-
manyToMany: relations.manyToMany.map(transformManyToMany),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Transform belongsTo relation
|
|
63
|
-
*/
|
|
64
|
-
function transformBelongsTo(rel) {
|
|
65
|
-
return {
|
|
66
|
-
fieldName: rel.fieldName,
|
|
67
|
-
isUnique: rel.isUnique,
|
|
68
|
-
referencesTable: rel.references.name,
|
|
69
|
-
type: rel.type,
|
|
70
|
-
keys: transformFields(rel.keys),
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Transform hasOne relation
|
|
75
|
-
*/
|
|
76
|
-
function transformHasOne(rel) {
|
|
77
|
-
return {
|
|
78
|
-
fieldName: rel.fieldName,
|
|
79
|
-
isUnique: rel.isUnique,
|
|
80
|
-
referencedByTable: rel.referencedBy.name,
|
|
81
|
-
type: rel.type,
|
|
82
|
-
keys: transformFields(rel.keys),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Transform hasMany relation
|
|
87
|
-
*/
|
|
88
|
-
function transformHasMany(rel) {
|
|
89
|
-
return {
|
|
90
|
-
fieldName: rel.fieldName,
|
|
91
|
-
isUnique: rel.isUnique,
|
|
92
|
-
referencedByTable: rel.referencedBy.name,
|
|
93
|
-
type: rel.type,
|
|
94
|
-
keys: transformFields(rel.keys),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Transform manyToMany relation
|
|
99
|
-
*/
|
|
100
|
-
function transformManyToMany(rel) {
|
|
101
|
-
return {
|
|
102
|
-
fieldName: rel.fieldName,
|
|
103
|
-
rightTable: rel.rightTable.name,
|
|
104
|
-
junctionTable: rel.junctionTable.name,
|
|
105
|
-
type: rel.type,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Transform inflection data
|
|
110
|
-
*/
|
|
111
|
-
function transformInflection(inflection) {
|
|
112
|
-
return {
|
|
113
|
-
allRows: inflection.allRows,
|
|
114
|
-
allRowsSimple: inflection.allRowsSimple,
|
|
115
|
-
conditionType: inflection.conditionType,
|
|
116
|
-
connection: inflection.connection,
|
|
117
|
-
createField: inflection.createField,
|
|
118
|
-
createInputType: inflection.createInputType,
|
|
119
|
-
createPayloadType: inflection.createPayloadType,
|
|
120
|
-
deleteByPrimaryKey: inflection.deleteByPrimaryKey,
|
|
121
|
-
deletePayloadType: inflection.deletePayloadType,
|
|
122
|
-
edge: inflection.edge,
|
|
123
|
-
edgeField: inflection.edgeField,
|
|
124
|
-
enumType: inflection.enumType,
|
|
125
|
-
filterType: inflection.filterType,
|
|
126
|
-
inputType: inflection.inputType,
|
|
127
|
-
orderByType: inflection.orderByType,
|
|
128
|
-
patchField: inflection.patchField,
|
|
129
|
-
patchType: inflection.patchType,
|
|
130
|
-
tableFieldName: inflection.tableFieldName,
|
|
131
|
-
tableType: inflection.tableType,
|
|
132
|
-
typeName: inflection.typeName,
|
|
133
|
-
updateByPrimaryKey: inflection.updateByPrimaryKey,
|
|
134
|
-
updatePayloadType: inflection.updatePayloadType,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Transform query names
|
|
139
|
-
*/
|
|
140
|
-
function transformQuery(query) {
|
|
141
|
-
return {
|
|
142
|
-
all: query.all,
|
|
143
|
-
one: query.one,
|
|
144
|
-
create: query.create,
|
|
145
|
-
update: query.update,
|
|
146
|
-
delete: query.delete,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Transform constraints
|
|
151
|
-
*/
|
|
152
|
-
function transformConstraints(table) {
|
|
153
|
-
return {
|
|
154
|
-
primaryKey: table.primaryKeyConstraints.map(transformConstraint),
|
|
155
|
-
foreignKey: table.foreignKeyConstraints.map(transformForeignKeyConstraint),
|
|
156
|
-
unique: table.uniqueConstraints.map(transformConstraint),
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Transform a basic constraint
|
|
161
|
-
*/
|
|
162
|
-
function transformConstraint(constraint) {
|
|
163
|
-
return {
|
|
164
|
-
name: constraint.name,
|
|
165
|
-
fields: transformFields(constraint.fields),
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Transform a foreign key constraint
|
|
170
|
-
*/
|
|
171
|
-
function transformForeignKeyConstraint(constraint) {
|
|
172
|
-
return {
|
|
173
|
-
name: constraint.name,
|
|
174
|
-
fields: transformFields(constraint.fields),
|
|
175
|
-
refTable: constraint.refTable.name,
|
|
176
|
-
refFields: transformFields(constraint.refFields),
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
6
|
/**
|
|
180
7
|
* Get table names from CleanTable array
|
|
181
8
|
*/
|
package/cli/watch/cache.d.ts
CHANGED
|
@@ -4,11 +4,10 @@
|
|
|
4
4
|
* Only stores the hash in memory - no file I/O during normal operation.
|
|
5
5
|
* Touch file feature is optional and only writes when explicitly configured.
|
|
6
6
|
*/
|
|
7
|
-
import type { MetaQueryResponse } from '../introspect/meta-query';
|
|
8
7
|
import type { IntrospectionQueryResponse } from '../../types/introspection';
|
|
9
8
|
/**
|
|
10
9
|
* Lightweight in-memory schema cache
|
|
11
|
-
* Only stores the
|
|
10
|
+
* Only stores the schema hash string to detect changes
|
|
12
11
|
*/
|
|
13
12
|
export declare class SchemaCache {
|
|
14
13
|
/** Current schema hash (in-memory only) */
|
|
@@ -17,7 +16,7 @@ export declare class SchemaCache {
|
|
|
17
16
|
* Check if schema has changed by comparing hashes
|
|
18
17
|
* This is the hot path - must be efficient
|
|
19
18
|
*/
|
|
20
|
-
hasChanged(
|
|
19
|
+
hasChanged(schema: IntrospectionQueryResponse): Promise<{
|
|
21
20
|
changed: boolean;
|
|
22
21
|
newHash: string;
|
|
23
22
|
}>;
|
|
@@ -34,7 +33,7 @@ export declare class SchemaCache {
|
|
|
34
33
|
*/
|
|
35
34
|
clear(): void;
|
|
36
35
|
/**
|
|
37
|
-
* Compute hash from
|
|
36
|
+
* Compute hash from schema response
|
|
38
37
|
*/
|
|
39
38
|
private computeHash;
|
|
40
39
|
}
|
package/cli/watch/cache.js
CHANGED
|
@@ -46,7 +46,7 @@ const path = __importStar(require("node:path"));
|
|
|
46
46
|
const hash_1 = require("./hash");
|
|
47
47
|
/**
|
|
48
48
|
* Lightweight in-memory schema cache
|
|
49
|
-
* Only stores the
|
|
49
|
+
* Only stores the schema hash string to detect changes
|
|
50
50
|
*/
|
|
51
51
|
class SchemaCache {
|
|
52
52
|
/** Current schema hash (in-memory only) */
|
|
@@ -55,8 +55,8 @@ class SchemaCache {
|
|
|
55
55
|
* Check if schema has changed by comparing hashes
|
|
56
56
|
* This is the hot path - must be efficient
|
|
57
57
|
*/
|
|
58
|
-
async hasChanged(
|
|
59
|
-
const newHash = await this.computeHash(
|
|
58
|
+
async hasChanged(schema) {
|
|
59
|
+
const newHash = await this.computeHash(schema);
|
|
60
60
|
const changed = this.currentHash === null || this.currentHash !== newHash;
|
|
61
61
|
return { changed, newHash };
|
|
62
62
|
}
|
|
@@ -79,14 +79,10 @@ class SchemaCache {
|
|
|
79
79
|
this.currentHash = null;
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
|
-
* Compute hash from
|
|
82
|
+
* Compute hash from schema response
|
|
83
83
|
*/
|
|
84
|
-
async computeHash(
|
|
85
|
-
|
|
86
|
-
// This is more efficient than stringifying both together
|
|
87
|
-
const metaHash = await (0, hash_1.hashObject)(meta);
|
|
88
|
-
const schemaHash = await (0, hash_1.hashObject)(schema);
|
|
89
|
-
return (0, hash_1.combineHashes)(metaHash, schemaHash);
|
|
84
|
+
async computeHash(schema) {
|
|
85
|
+
return (0, hash_1.hashObject)(schema);
|
|
90
86
|
}
|
|
91
87
|
}
|
|
92
88
|
exports.SchemaCache = SchemaCache;
|
package/cli/watch/poller.d.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* No file I/O during normal polling - only touchFile is optional file write.
|
|
6
6
|
*/
|
|
7
7
|
import { EventEmitter } from 'node:events';
|
|
8
|
-
import type { MetaQueryResponse } from '../introspect/meta-query';
|
|
9
8
|
import type { IntrospectionQueryResponse } from '../../types/introspection';
|
|
10
9
|
import { SchemaCache } from './cache';
|
|
11
10
|
import type { PollResult, WatchOptions } from './types';
|
|
@@ -62,4 +61,4 @@ export declare class SchemaPoller extends EventEmitter {
|
|
|
62
61
|
/**
|
|
63
62
|
* Utility to compute schema hash without full poll
|
|
64
63
|
*/
|
|
65
|
-
export declare function computeSchemaHash(
|
|
64
|
+
export declare function computeSchemaHash(schema: IntrospectionQueryResponse): Promise<string>;
|