@constructive-io/graphql-server 4.5.0 → 4.5.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/esm/index.js +0 -2
- package/esm/middleware/api.js +1 -1
- package/esm/middleware/auth.js +1 -1
- package/esm/middleware/debug-memory.js +1 -1
- package/esm/middleware/error-handler.js +1 -1
- package/esm/middleware/graphile.js +1 -1
- package/esm/server.js +2 -7
- package/index.d.ts +0 -1
- package/index.js +0 -2
- package/middleware/api.js +3 -3
- package/middleware/auth.js +2 -2
- package/middleware/debug-memory.js +2 -2
- package/middleware/error-handler.js +2 -2
- package/middleware/graphile.js +2 -2
- package/package.json +7 -6
- package/server.js +2 -7
- package/types.d.ts +2 -9
- package/esm/options.js +0 -232
- package/options.d.ts +0 -131
- package/options.js +0 -244
package/esm/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export * from './server';
|
|
2
|
-
// Export options module - types, defaults, type guards, and utility functions
|
|
3
|
-
export * from './options';
|
|
4
2
|
// Export middleware for use in testing packages
|
|
5
3
|
export { createApiMiddleware, getSubdomain, getApiConfig } from './middleware/api';
|
|
6
4
|
export { createAuthenticateMiddleware } from './middleware/auth';
|
package/esm/middleware/api.js
CHANGED
package/esm/middleware/auth.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
|
-
import { getNodeEnv } from '@
|
|
2
|
+
import { getNodeEnv } from '@pgpmjs/env';
|
|
3
3
|
import { Logger } from '@pgpmjs/logger';
|
|
4
4
|
import { createGraphileInstance, graphileCache } from 'graphile-cache';
|
|
5
5
|
import { ConstructivePreset, makePgService } from 'graphile-settings';
|
package/esm/server.js
CHANGED
|
@@ -18,7 +18,6 @@ import { graphile } from './middleware/graphile';
|
|
|
18
18
|
import { multipartBridge } from './middleware/multipart-bridge';
|
|
19
19
|
import { createUploadAuthenticateMiddleware, uploadRoute } from './middleware/upload';
|
|
20
20
|
import { debugMemory } from './middleware/debug-memory';
|
|
21
|
-
import { normalizeServerOptions } from './options';
|
|
22
21
|
const log = new Logger('server');
|
|
23
22
|
/**
|
|
24
23
|
* Creates and starts a GraphQL server instance
|
|
@@ -42,12 +41,8 @@ const log = new Logger('server');
|
|
|
42
41
|
* ```
|
|
43
42
|
*/
|
|
44
43
|
export const GraphQLServer = (rawOpts = {}) => {
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
// Apply environment variable overrides via getEnvOptions
|
|
48
|
-
// Cast to PgpmOptions for backward compatibility with getEnvOptions
|
|
49
|
-
const envOptions = getEnvOptions(normalizedOpts);
|
|
50
|
-
const app = new Server(envOptions);
|
|
44
|
+
const opts = getEnvOptions(rawOpts);
|
|
45
|
+
const app = new Server(opts);
|
|
51
46
|
app.addEventListener();
|
|
52
47
|
app.listen();
|
|
53
48
|
};
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export * from './server';
|
|
2
|
-
export * from './options';
|
|
3
2
|
export { createApiMiddleware, getSubdomain, getApiConfig } from './middleware/api';
|
|
4
3
|
export { createAuthenticateMiddleware } from './middleware/auth';
|
|
5
4
|
export { createUploadAuthenticateMiddleware } from './middleware/upload';
|
package/index.js
CHANGED
|
@@ -16,8 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.flushService = exports.flush = exports.graphile = exports.cors = exports.createUploadAuthenticateMiddleware = exports.createAuthenticateMiddleware = exports.getApiConfig = exports.getSubdomain = exports.createApiMiddleware = void 0;
|
|
18
18
|
__exportStar(require("./server"), exports);
|
|
19
|
-
// Export options module - types, defaults, type guards, and utility functions
|
|
20
|
-
__exportStar(require("./options"), exports);
|
|
21
19
|
// Export middleware for use in testing packages
|
|
22
20
|
var api_1 = require("./middleware/api");
|
|
23
21
|
Object.defineProperty(exports, "createApiMiddleware", { enumerable: true, get: function () { return api_1.createApiMiddleware; } });
|
package/middleware/api.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createApiMiddleware = exports.getApiConfig = exports.getSvcKey = exports.getSubdomain = void 0;
|
|
7
|
-
const
|
|
7
|
+
const env_1 = require("@pgpmjs/env");
|
|
8
8
|
const logger_1 = require("@pgpmjs/logger");
|
|
9
9
|
const server_utils_1 = require("@pgpmjs/server-utils");
|
|
10
10
|
const url_domains_1 = require("@constructive-io/url-domains");
|
|
@@ -13,7 +13,7 @@ const _50x_1 = __importDefault(require("../errors/50x"));
|
|
|
13
13
|
const _404_message_1 = __importDefault(require("../errors/404-message"));
|
|
14
14
|
require("./types");
|
|
15
15
|
const log = new logger_1.Logger('api');
|
|
16
|
-
const isDev = () => (0,
|
|
16
|
+
const isDev = () => (0, env_1.getNodeEnv)() === 'development';
|
|
17
17
|
// =============================================================================
|
|
18
18
|
// SQL Queries
|
|
19
19
|
// =============================================================================
|
|
@@ -247,7 +247,7 @@ const resolveDomainLookup = async (ctx) => {
|
|
|
247
247
|
return toApiStructure(row, opts, rlsModule);
|
|
248
248
|
};
|
|
249
249
|
const buildDevFallbackError = async (ctx, req) => {
|
|
250
|
-
if ((0,
|
|
250
|
+
if ((0, env_1.getNodeEnv)() !== 'development')
|
|
251
251
|
return null;
|
|
252
252
|
const isPublic = ctx.opts.api?.isPublic ?? false;
|
|
253
253
|
const apis = await queryApiList(ctx.pool, isPublic);
|
package/middleware/auth.js
CHANGED
|
@@ -4,13 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createAuthenticateMiddleware = void 0;
|
|
7
|
-
const
|
|
7
|
+
const env_1 = require("@pgpmjs/env");
|
|
8
8
|
const logger_1 = require("@pgpmjs/logger");
|
|
9
9
|
const pg_cache_1 = require("pg-cache");
|
|
10
10
|
const pg_query_context_1 = __importDefault(require("pg-query-context"));
|
|
11
11
|
require("./types"); // for Request type
|
|
12
12
|
const log = new logger_1.Logger('auth');
|
|
13
|
-
const isDev = () => (0,
|
|
13
|
+
const isDev = () => (0, env_1.getNodeEnv)() === 'development';
|
|
14
14
|
const createAuthenticateMiddleware = (opts) => {
|
|
15
15
|
return async (req, res, next) => {
|
|
16
16
|
const api = req.api;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.debugMemory = void 0;
|
|
4
|
-
const
|
|
4
|
+
const env_1 = require("@pgpmjs/env");
|
|
5
5
|
const logger_1 = require("@pgpmjs/logger");
|
|
6
6
|
const server_utils_1 = require("@pgpmjs/server-utils");
|
|
7
7
|
const graphile_cache_1 = require("graphile-cache");
|
|
@@ -22,7 +22,7 @@ const toMB = (bytes) => `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
|
22
22
|
* In production, it returns 404.
|
|
23
23
|
*/
|
|
24
24
|
const debugMemory = (_req, res) => {
|
|
25
|
-
if ((0,
|
|
25
|
+
if ((0, env_1.getNodeEnv)() !== 'development') {
|
|
26
26
|
res.status(404).send('Not found');
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
@@ -4,14 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.notFoundHandler = exports.errorHandler = void 0;
|
|
7
|
-
const
|
|
7
|
+
const env_1 = require("@pgpmjs/env");
|
|
8
8
|
const logger_1 = require("@pgpmjs/logger");
|
|
9
9
|
const api_errors_1 = require("../errors/api-errors");
|
|
10
10
|
const _404_message_1 = __importDefault(require("../errors/404-message"));
|
|
11
11
|
const _50x_1 = __importDefault(require("../errors/50x"));
|
|
12
12
|
require("./types");
|
|
13
13
|
const log = new logger_1.Logger('error-handler');
|
|
14
|
-
const isDevelopment = () => (0,
|
|
14
|
+
const isDevelopment = () => (0, env_1.getNodeEnv)() === 'development';
|
|
15
15
|
const wantsJson = (req) => {
|
|
16
16
|
const accept = req.get('Accept') || '';
|
|
17
17
|
return accept.includes('application/json') || accept.includes('application/graphql-response+json');
|
package/middleware/graphile.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.getInFlightCount = getInFlightCount;
|
|
|
8
8
|
exports.getInFlightKeys = getInFlightKeys;
|
|
9
9
|
exports.clearInFlightMap = clearInFlightMap;
|
|
10
10
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
11
|
-
const
|
|
11
|
+
const env_1 = require("@pgpmjs/env");
|
|
12
12
|
const logger_1 = require("@pgpmjs/logger");
|
|
13
13
|
const graphile_cache_1 = require("graphile-cache");
|
|
14
14
|
const graphile_settings_1 = require("graphile-settings");
|
|
@@ -62,7 +62,7 @@ const SAFE_ERROR_CODES = new Set([
|
|
|
62
62
|
* and logs the original.
|
|
63
63
|
*/
|
|
64
64
|
const maskError = (error) => {
|
|
65
|
-
if ((0,
|
|
65
|
+
if ((0, env_1.getNodeEnv)() === 'development') {
|
|
66
66
|
return error;
|
|
67
67
|
}
|
|
68
68
|
// Only expose errors with codes on the safe allowlist.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/graphql-server",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.1",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "Constructive GraphQL Server",
|
|
6
6
|
"main": "index.js",
|
|
@@ -39,13 +39,14 @@
|
|
|
39
39
|
"backend"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@constructive-io/graphql-env": "^3.2.
|
|
43
|
-
"@constructive-io/graphql-types": "^3.1.
|
|
42
|
+
"@constructive-io/graphql-env": "^3.2.2",
|
|
43
|
+
"@constructive-io/graphql-types": "^3.1.2",
|
|
44
44
|
"@constructive-io/s3-utils": "^2.7.0",
|
|
45
45
|
"@constructive-io/upload-names": "^2.7.0",
|
|
46
46
|
"@constructive-io/url-domains": "^2.7.0",
|
|
47
47
|
"@graphile-contrib/pg-many-to-many": "2.0.0-rc.1",
|
|
48
48
|
"@graphile/simplify-inflection": "8.0.0-rc.3",
|
|
49
|
+
"@pgpmjs/env": "^2.13.0",
|
|
49
50
|
"@pgpmjs/logger": "^2.2.0",
|
|
50
51
|
"@pgpmjs/server-utils": "^3.2.0",
|
|
51
52
|
"@pgpmjs/types": "^2.17.0",
|
|
@@ -59,7 +60,7 @@
|
|
|
59
60
|
"graphile-build-pg": "5.0.0-rc.5",
|
|
60
61
|
"graphile-cache": "^3.1.0",
|
|
61
62
|
"graphile-config": "1.0.0-rc.5",
|
|
62
|
-
"graphile-settings": "^4.
|
|
63
|
+
"graphile-settings": "^4.6.0",
|
|
63
64
|
"graphile-utils": "5.0.0-rc.5",
|
|
64
65
|
"graphql": "^16.9.0",
|
|
65
66
|
"graphql-upload": "^13.0.0",
|
|
@@ -82,10 +83,10 @@
|
|
|
82
83
|
"@types/multer": "^1.4.12",
|
|
83
84
|
"@types/pg": "^8.16.0",
|
|
84
85
|
"@types/request-ip": "^0.0.41",
|
|
85
|
-
"graphile-test": "4.3.
|
|
86
|
+
"graphile-test": "4.3.1",
|
|
86
87
|
"makage": "^0.1.10",
|
|
87
88
|
"nodemon": "^3.1.10",
|
|
88
89
|
"ts-node": "^10.9.2"
|
|
89
90
|
},
|
|
90
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "1c9efe4ecd5a6b8daa14fe42214ecf8c5b664198"
|
|
91
92
|
}
|
package/server.js
CHANGED
|
@@ -24,7 +24,6 @@ const graphile_1 = require("./middleware/graphile");
|
|
|
24
24
|
const multipart_bridge_1 = require("./middleware/multipart-bridge");
|
|
25
25
|
const upload_1 = require("./middleware/upload");
|
|
26
26
|
const debug_memory_1 = require("./middleware/debug-memory");
|
|
27
|
-
const options_1 = require("./options");
|
|
28
27
|
const log = new logger_1.Logger('server');
|
|
29
28
|
/**
|
|
30
29
|
* Creates and starts a GraphQL server instance
|
|
@@ -48,12 +47,8 @@ const log = new logger_1.Logger('server');
|
|
|
48
47
|
* ```
|
|
49
48
|
*/
|
|
50
49
|
const GraphQLServer = (rawOpts = {}) => {
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
// Apply environment variable overrides via getEnvOptions
|
|
54
|
-
// Cast to PgpmOptions for backward compatibility with getEnvOptions
|
|
55
|
-
const envOptions = (0, graphql_env_1.getEnvOptions)(normalizedOpts);
|
|
56
|
-
const app = new Server(envOptions);
|
|
50
|
+
const opts = (0, graphql_env_1.getEnvOptions)(rawOpts);
|
|
51
|
+
const app = new Server(opts);
|
|
57
52
|
app.addEventListener();
|
|
58
53
|
app.listen();
|
|
59
54
|
};
|
package/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PgpmOptions } from '@pgpmjs/types';
|
|
2
|
+
import type { ApiOptions as ApiConfig } from '@constructive-io/graphql-types';
|
|
2
3
|
export interface CorsModuleData {
|
|
3
4
|
urls: string[];
|
|
4
5
|
}
|
|
@@ -47,13 +48,5 @@ export type ApiError = {
|
|
|
47
48
|
};
|
|
48
49
|
export type ApiConfigResult = ApiStructure | ApiError | null;
|
|
49
50
|
export type ApiOptions = PgpmOptions & {
|
|
50
|
-
api?:
|
|
51
|
-
enableServicesApi?: boolean;
|
|
52
|
-
exposedSchemas?: string[];
|
|
53
|
-
anonRole?: string;
|
|
54
|
-
roleName?: string;
|
|
55
|
-
defaultDatabaseId?: string;
|
|
56
|
-
metaSchemas?: string[];
|
|
57
|
-
isPublic?: boolean;
|
|
58
|
-
};
|
|
51
|
+
api?: ApiConfig;
|
|
59
52
|
};
|
package/esm/options.js
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GraphQL Server Options - Configuration utilities
|
|
3
|
-
*
|
|
4
|
-
* This module provides type-safe configuration utilities for the GraphQL server.
|
|
5
|
-
* It includes type guards for runtime validation and utility functions for
|
|
6
|
-
* configuration normalization.
|
|
7
|
-
*
|
|
8
|
-
* The main configuration type is `ConstructiveOptions` from @constructive-io/graphql-types.
|
|
9
|
-
*
|
|
10
|
-
* @module options
|
|
11
|
-
*/
|
|
12
|
-
import deepmerge from 'deepmerge';
|
|
13
|
-
import { graphileDefaults, graphileFeatureDefaults, apiDefaults } from '@constructive-io/graphql-types';
|
|
14
|
-
// ============================================
|
|
15
|
-
// Default Configuration
|
|
16
|
-
// ============================================
|
|
17
|
-
/**
|
|
18
|
-
* Default configuration values for GraphQL server
|
|
19
|
-
*
|
|
20
|
-
* Provides sensible defaults for all currently active fields.
|
|
21
|
-
*/
|
|
22
|
-
export const serverDefaults = {
|
|
23
|
-
pg: {
|
|
24
|
-
host: 'localhost',
|
|
25
|
-
port: 5432,
|
|
26
|
-
user: 'postgres',
|
|
27
|
-
password: 'password',
|
|
28
|
-
database: 'postgres'
|
|
29
|
-
},
|
|
30
|
-
server: {
|
|
31
|
-
host: 'localhost',
|
|
32
|
-
port: 3000,
|
|
33
|
-
trustProxy: false,
|
|
34
|
-
strictAuth: false
|
|
35
|
-
},
|
|
36
|
-
api: apiDefaults,
|
|
37
|
-
graphile: graphileDefaults,
|
|
38
|
-
features: graphileFeatureDefaults
|
|
39
|
-
};
|
|
40
|
-
// ============================================
|
|
41
|
-
// Type Guards
|
|
42
|
-
// ============================================
|
|
43
|
-
/**
|
|
44
|
-
* List of all recognized fields in ConstructiveOptions
|
|
45
|
-
*/
|
|
46
|
-
const RECOGNIZED_FIELDS = [
|
|
47
|
-
'pg',
|
|
48
|
-
'server',
|
|
49
|
-
'api',
|
|
50
|
-
'graphile',
|
|
51
|
-
'features',
|
|
52
|
-
'db',
|
|
53
|
-
'cdn',
|
|
54
|
-
'deployment',
|
|
55
|
-
'migrations',
|
|
56
|
-
'jobs'
|
|
57
|
-
];
|
|
58
|
-
/**
|
|
59
|
-
* Type guard to validate if an unknown value is a valid ConstructiveOptions object
|
|
60
|
-
*
|
|
61
|
-
* Validates that:
|
|
62
|
-
* 1. The value is a non-null object
|
|
63
|
-
* 2. Contains at least one recognized field from the interface
|
|
64
|
-
* 3. All recognized fields that exist have object values (not primitives)
|
|
65
|
-
*
|
|
66
|
-
* @param opts - Unknown value to validate
|
|
67
|
-
* @returns True if opts is a valid ConstructiveOptions object
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* if (isConstructiveOptions(unknownConfig)) {
|
|
72
|
-
* // TypeScript knows unknownConfig is ConstructiveOptions
|
|
73
|
-
* const { pg, server } = unknownConfig;
|
|
74
|
-
* }
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
export function isConstructiveOptions(opts) {
|
|
78
|
-
if (opts === null || opts === undefined) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
if (typeof opts !== 'object') {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
const obj = opts;
|
|
85
|
-
// Check for at least one recognized field from the interface
|
|
86
|
-
const hasRecognizedField = RECOGNIZED_FIELDS.some((field) => field in obj);
|
|
87
|
-
if (!hasRecognizedField) {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
// Validate that recognized fields have object values (not primitives)
|
|
91
|
-
for (const field of RECOGNIZED_FIELDS) {
|
|
92
|
-
if (field in obj && obj[field] !== undefined && obj[field] !== null) {
|
|
93
|
-
if (typeof obj[field] !== 'object') {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return true;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Type guard to check if an object has PostgreSQL configuration
|
|
102
|
-
*
|
|
103
|
-
* @param opts - Unknown value to check
|
|
104
|
-
* @returns True if opts has a defined pg property
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* if (hasPgConfig(config)) {
|
|
109
|
-
* console.log(config.pg.host);
|
|
110
|
-
* }
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
export function hasPgConfig(opts) {
|
|
114
|
-
if (opts === null || opts === undefined || typeof opts !== 'object') {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
return 'pg' in opts && opts.pg !== undefined;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Type guard to check if an object has HTTP server configuration
|
|
121
|
-
*
|
|
122
|
-
* @param opts - Unknown value to check
|
|
123
|
-
* @returns True if opts has a defined server property
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* if (hasServerConfig(config)) {
|
|
128
|
-
* console.log(config.server.port);
|
|
129
|
-
* }
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
export function hasServerConfig(opts) {
|
|
133
|
-
if (opts === null || opts === undefined || typeof opts !== 'object') {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
return 'server' in opts && opts.server !== undefined;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Type guard to check if an object has API configuration
|
|
140
|
-
*
|
|
141
|
-
* @param opts - Unknown value to check
|
|
142
|
-
* @returns True if opts has a defined api property
|
|
143
|
-
*
|
|
144
|
-
* @example
|
|
145
|
-
* ```typescript
|
|
146
|
-
* if (hasApiConfig(config)) {
|
|
147
|
-
* console.log(config.api.exposedSchemas);
|
|
148
|
-
* }
|
|
149
|
-
* ```
|
|
150
|
-
*/
|
|
151
|
-
export function hasApiConfig(opts) {
|
|
152
|
-
if (opts === null || opts === undefined || typeof opts !== 'object') {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
return 'api' in opts && opts.api !== undefined;
|
|
156
|
-
}
|
|
157
|
-
// ============================================
|
|
158
|
-
// Internal Utilities
|
|
159
|
-
// ============================================
|
|
160
|
-
/**
|
|
161
|
-
* Array merge strategy that replaces arrays (source wins over target).
|
|
162
|
-
* This ensures that when a user specifies an array value, it replaces
|
|
163
|
-
* the default rather than merging/concatenating.
|
|
164
|
-
*
|
|
165
|
-
* @internal
|
|
166
|
-
*/
|
|
167
|
-
const replaceArrays = (_target, source) => source;
|
|
168
|
-
// ============================================
|
|
169
|
-
// Utility Functions
|
|
170
|
-
// ============================================
|
|
171
|
-
/**
|
|
172
|
-
* Legacy field names that indicate old configuration format
|
|
173
|
-
*/
|
|
174
|
-
const LEGACY_FIELDS = [
|
|
175
|
-
'schemas', // Old array-style schema config (should be graphile.schema)
|
|
176
|
-
'pgConfig', // Old naming (should be pg)
|
|
177
|
-
'serverPort', // Flat config (should be server.port)
|
|
178
|
-
'serverHost', // Flat config (should be server.host)
|
|
179
|
-
'dbConfig', // Old naming (should be db)
|
|
180
|
-
'postgraphile', // Old Graphile v4 naming (should be graphile)
|
|
181
|
-
'pgPool', // Direct pool config (deprecated)
|
|
182
|
-
'jwtSecret', // Flat JWT config (should be in api or auth)
|
|
183
|
-
'watchPg' // Old PostGraphile v4 option
|
|
184
|
-
];
|
|
185
|
-
/**
|
|
186
|
-
* Detects if the given options object uses a deprecated/legacy format
|
|
187
|
-
*
|
|
188
|
-
* Checks for presence of legacy field names that indicate the configuration
|
|
189
|
-
* needs to be migrated to ConstructiveOptions format.
|
|
190
|
-
*
|
|
191
|
-
* @param opts - Unknown value to check
|
|
192
|
-
* @returns True if legacy configuration patterns are detected
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* ```typescript
|
|
196
|
-
* if (isLegacyOptions(config)) {
|
|
197
|
-
* console.warn('Detected legacy configuration format. Please migrate to ConstructiveOptions.');
|
|
198
|
-
* }
|
|
199
|
-
* ```
|
|
200
|
-
*/
|
|
201
|
-
export function isLegacyOptions(opts) {
|
|
202
|
-
if (opts === null || opts === undefined || typeof opts !== 'object') {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
const obj = opts;
|
|
206
|
-
return LEGACY_FIELDS.some((field) => field in obj);
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Normalizes input to a ConstructiveOptions object with defaults applied
|
|
210
|
-
*
|
|
211
|
-
* Accepts ConstructiveOptions and returns a fully normalized object
|
|
212
|
-
* with default values applied via deep merge. User-provided values override defaults.
|
|
213
|
-
*
|
|
214
|
-
* @param opts - ConstructiveOptions to normalize
|
|
215
|
-
* @returns ConstructiveOptions with defaults filled in
|
|
216
|
-
*
|
|
217
|
-
* @example
|
|
218
|
-
* ```typescript
|
|
219
|
-
* // Partial config - missing fields filled from defaults
|
|
220
|
-
* const normalized = normalizeServerOptions({
|
|
221
|
-
* pg: { database: 'myapp' }
|
|
222
|
-
* });
|
|
223
|
-
*
|
|
224
|
-
* // normalized.pg.host === 'localhost' (from default)
|
|
225
|
-
* // normalized.pg.database === 'myapp' (from user config)
|
|
226
|
-
* // normalized.server.port === 3000 (from default)
|
|
227
|
-
* ```
|
|
228
|
-
*/
|
|
229
|
-
export function normalizeServerOptions(opts) {
|
|
230
|
-
// Deep merge with defaults - user options override defaults
|
|
231
|
-
return deepmerge(serverDefaults, opts, { arrayMerge: replaceArrays });
|
|
232
|
-
}
|
package/options.d.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GraphQL Server Options - Configuration utilities
|
|
3
|
-
*
|
|
4
|
-
* This module provides type-safe configuration utilities for the GraphQL server.
|
|
5
|
-
* It includes type guards for runtime validation and utility functions for
|
|
6
|
-
* configuration normalization.
|
|
7
|
-
*
|
|
8
|
-
* The main configuration type is `ConstructiveOptions` from @constructive-io/graphql-types.
|
|
9
|
-
*
|
|
10
|
-
* @module options
|
|
11
|
-
*/
|
|
12
|
-
import type { PgConfig } from 'pg-env';
|
|
13
|
-
import type { ServerOptions, CDNOptions, DeploymentOptions, MigrationOptions, JobsConfig, PgTestConnectionOptions } from '@pgpmjs/types';
|
|
14
|
-
import type { ConstructiveOptions, GraphileOptions, GraphileFeatureOptions, ApiOptions } from '@constructive-io/graphql-types';
|
|
15
|
-
export type { PgConfig, ServerOptions, CDNOptions, DeploymentOptions, MigrationOptions, JobsConfig, PgTestConnectionOptions, GraphileOptions, GraphileFeatureOptions, ApiOptions, ConstructiveOptions };
|
|
16
|
-
export type CdnOptions = CDNOptions;
|
|
17
|
-
export type JobsOptions = JobsConfig;
|
|
18
|
-
export type DbOptions = PgTestConnectionOptions;
|
|
19
|
-
/**
|
|
20
|
-
* Default configuration values for GraphQL server
|
|
21
|
-
*
|
|
22
|
-
* Provides sensible defaults for all currently active fields.
|
|
23
|
-
*/
|
|
24
|
-
export declare const serverDefaults: Partial<ConstructiveOptions>;
|
|
25
|
-
/**
|
|
26
|
-
* Type guard to validate if an unknown value is a valid ConstructiveOptions object
|
|
27
|
-
*
|
|
28
|
-
* Validates that:
|
|
29
|
-
* 1. The value is a non-null object
|
|
30
|
-
* 2. Contains at least one recognized field from the interface
|
|
31
|
-
* 3. All recognized fields that exist have object values (not primitives)
|
|
32
|
-
*
|
|
33
|
-
* @param opts - Unknown value to validate
|
|
34
|
-
* @returns True if opts is a valid ConstructiveOptions object
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* if (isConstructiveOptions(unknownConfig)) {
|
|
39
|
-
* // TypeScript knows unknownConfig is ConstructiveOptions
|
|
40
|
-
* const { pg, server } = unknownConfig;
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export declare function isConstructiveOptions(opts: unknown): opts is ConstructiveOptions;
|
|
45
|
-
/**
|
|
46
|
-
* Type guard to check if an object has PostgreSQL configuration
|
|
47
|
-
*
|
|
48
|
-
* @param opts - Unknown value to check
|
|
49
|
-
* @returns True if opts has a defined pg property
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```typescript
|
|
53
|
-
* if (hasPgConfig(config)) {
|
|
54
|
-
* console.log(config.pg.host);
|
|
55
|
-
* }
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export declare function hasPgConfig(opts: unknown): opts is {
|
|
59
|
-
pg: Partial<PgConfig>;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Type guard to check if an object has HTTP server configuration
|
|
63
|
-
*
|
|
64
|
-
* @param opts - Unknown value to check
|
|
65
|
-
* @returns True if opts has a defined server property
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* if (hasServerConfig(config)) {
|
|
70
|
-
* console.log(config.server.port);
|
|
71
|
-
* }
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
export declare function hasServerConfig(opts: unknown): opts is {
|
|
75
|
-
server: ServerOptions;
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* Type guard to check if an object has API configuration
|
|
79
|
-
*
|
|
80
|
-
* @param opts - Unknown value to check
|
|
81
|
-
* @returns True if opts has a defined api property
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```typescript
|
|
85
|
-
* if (hasApiConfig(config)) {
|
|
86
|
-
* console.log(config.api.exposedSchemas);
|
|
87
|
-
* }
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
export declare function hasApiConfig(opts: unknown): opts is {
|
|
91
|
-
api: ApiOptions;
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Detects if the given options object uses a deprecated/legacy format
|
|
95
|
-
*
|
|
96
|
-
* Checks for presence of legacy field names that indicate the configuration
|
|
97
|
-
* needs to be migrated to ConstructiveOptions format.
|
|
98
|
-
*
|
|
99
|
-
* @param opts - Unknown value to check
|
|
100
|
-
* @returns True if legacy configuration patterns are detected
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```typescript
|
|
104
|
-
* if (isLegacyOptions(config)) {
|
|
105
|
-
* console.warn('Detected legacy configuration format. Please migrate to ConstructiveOptions.');
|
|
106
|
-
* }
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
export declare function isLegacyOptions(opts: unknown): boolean;
|
|
110
|
-
/**
|
|
111
|
-
* Normalizes input to a ConstructiveOptions object with defaults applied
|
|
112
|
-
*
|
|
113
|
-
* Accepts ConstructiveOptions and returns a fully normalized object
|
|
114
|
-
* with default values applied via deep merge. User-provided values override defaults.
|
|
115
|
-
*
|
|
116
|
-
* @param opts - ConstructiveOptions to normalize
|
|
117
|
-
* @returns ConstructiveOptions with defaults filled in
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```typescript
|
|
121
|
-
* // Partial config - missing fields filled from defaults
|
|
122
|
-
* const normalized = normalizeServerOptions({
|
|
123
|
-
* pg: { database: 'myapp' }
|
|
124
|
-
* });
|
|
125
|
-
*
|
|
126
|
-
* // normalized.pg.host === 'localhost' (from default)
|
|
127
|
-
* // normalized.pg.database === 'myapp' (from user config)
|
|
128
|
-
* // normalized.server.port === 3000 (from default)
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
export declare function normalizeServerOptions(opts: ConstructiveOptions): ConstructiveOptions;
|
package/options.js
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* GraphQL Server Options - Configuration utilities
|
|
4
|
-
*
|
|
5
|
-
* This module provides type-safe configuration utilities for the GraphQL server.
|
|
6
|
-
* It includes type guards for runtime validation and utility functions for
|
|
7
|
-
* configuration normalization.
|
|
8
|
-
*
|
|
9
|
-
* The main configuration type is `ConstructiveOptions` from @constructive-io/graphql-types.
|
|
10
|
-
*
|
|
11
|
-
* @module options
|
|
12
|
-
*/
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.serverDefaults = void 0;
|
|
18
|
-
exports.isConstructiveOptions = isConstructiveOptions;
|
|
19
|
-
exports.hasPgConfig = hasPgConfig;
|
|
20
|
-
exports.hasServerConfig = hasServerConfig;
|
|
21
|
-
exports.hasApiConfig = hasApiConfig;
|
|
22
|
-
exports.isLegacyOptions = isLegacyOptions;
|
|
23
|
-
exports.normalizeServerOptions = normalizeServerOptions;
|
|
24
|
-
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
25
|
-
const graphql_types_1 = require("@constructive-io/graphql-types");
|
|
26
|
-
// ============================================
|
|
27
|
-
// Default Configuration
|
|
28
|
-
// ============================================
|
|
29
|
-
/**
|
|
30
|
-
* Default configuration values for GraphQL server
|
|
31
|
-
*
|
|
32
|
-
* Provides sensible defaults for all currently active fields.
|
|
33
|
-
*/
|
|
34
|
-
exports.serverDefaults = {
|
|
35
|
-
pg: {
|
|
36
|
-
host: 'localhost',
|
|
37
|
-
port: 5432,
|
|
38
|
-
user: 'postgres',
|
|
39
|
-
password: 'password',
|
|
40
|
-
database: 'postgres'
|
|
41
|
-
},
|
|
42
|
-
server: {
|
|
43
|
-
host: 'localhost',
|
|
44
|
-
port: 3000,
|
|
45
|
-
trustProxy: false,
|
|
46
|
-
strictAuth: false
|
|
47
|
-
},
|
|
48
|
-
api: graphql_types_1.apiDefaults,
|
|
49
|
-
graphile: graphql_types_1.graphileDefaults,
|
|
50
|
-
features: graphql_types_1.graphileFeatureDefaults
|
|
51
|
-
};
|
|
52
|
-
// ============================================
|
|
53
|
-
// Type Guards
|
|
54
|
-
// ============================================
|
|
55
|
-
/**
|
|
56
|
-
* List of all recognized fields in ConstructiveOptions
|
|
57
|
-
*/
|
|
58
|
-
const RECOGNIZED_FIELDS = [
|
|
59
|
-
'pg',
|
|
60
|
-
'server',
|
|
61
|
-
'api',
|
|
62
|
-
'graphile',
|
|
63
|
-
'features',
|
|
64
|
-
'db',
|
|
65
|
-
'cdn',
|
|
66
|
-
'deployment',
|
|
67
|
-
'migrations',
|
|
68
|
-
'jobs'
|
|
69
|
-
];
|
|
70
|
-
/**
|
|
71
|
-
* Type guard to validate if an unknown value is a valid ConstructiveOptions object
|
|
72
|
-
*
|
|
73
|
-
* Validates that:
|
|
74
|
-
* 1. The value is a non-null object
|
|
75
|
-
* 2. Contains at least one recognized field from the interface
|
|
76
|
-
* 3. All recognized fields that exist have object values (not primitives)
|
|
77
|
-
*
|
|
78
|
-
* @param opts - Unknown value to validate
|
|
79
|
-
* @returns True if opts is a valid ConstructiveOptions object
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* if (isConstructiveOptions(unknownConfig)) {
|
|
84
|
-
* // TypeScript knows unknownConfig is ConstructiveOptions
|
|
85
|
-
* const { pg, server } = unknownConfig;
|
|
86
|
-
* }
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
function isConstructiveOptions(opts) {
|
|
90
|
-
if (opts === null || opts === undefined) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
if (typeof opts !== 'object') {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
const obj = opts;
|
|
97
|
-
// Check for at least one recognized field from the interface
|
|
98
|
-
const hasRecognizedField = RECOGNIZED_FIELDS.some((field) => field in obj);
|
|
99
|
-
if (!hasRecognizedField) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
// Validate that recognized fields have object values (not primitives)
|
|
103
|
-
for (const field of RECOGNIZED_FIELDS) {
|
|
104
|
-
if (field in obj && obj[field] !== undefined && obj[field] !== null) {
|
|
105
|
-
if (typeof obj[field] !== 'object') {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Type guard to check if an object has PostgreSQL configuration
|
|
114
|
-
*
|
|
115
|
-
* @param opts - Unknown value to check
|
|
116
|
-
* @returns True if opts has a defined pg property
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* ```typescript
|
|
120
|
-
* if (hasPgConfig(config)) {
|
|
121
|
-
* console.log(config.pg.host);
|
|
122
|
-
* }
|
|
123
|
-
* ```
|
|
124
|
-
*/
|
|
125
|
-
function hasPgConfig(opts) {
|
|
126
|
-
if (opts === null || opts === undefined || typeof opts !== 'object') {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
return 'pg' in opts && opts.pg !== undefined;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Type guard to check if an object has HTTP server configuration
|
|
133
|
-
*
|
|
134
|
-
* @param opts - Unknown value to check
|
|
135
|
-
* @returns True if opts has a defined server property
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```typescript
|
|
139
|
-
* if (hasServerConfig(config)) {
|
|
140
|
-
* console.log(config.server.port);
|
|
141
|
-
* }
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
144
|
-
function hasServerConfig(opts) {
|
|
145
|
-
if (opts === null || opts === undefined || typeof opts !== 'object') {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
return 'server' in opts && opts.server !== undefined;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Type guard to check if an object has API configuration
|
|
152
|
-
*
|
|
153
|
-
* @param opts - Unknown value to check
|
|
154
|
-
* @returns True if opts has a defined api property
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* ```typescript
|
|
158
|
-
* if (hasApiConfig(config)) {
|
|
159
|
-
* console.log(config.api.exposedSchemas);
|
|
160
|
-
* }
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
function hasApiConfig(opts) {
|
|
164
|
-
if (opts === null || opts === undefined || typeof opts !== 'object') {
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
return 'api' in opts && opts.api !== undefined;
|
|
168
|
-
}
|
|
169
|
-
// ============================================
|
|
170
|
-
// Internal Utilities
|
|
171
|
-
// ============================================
|
|
172
|
-
/**
|
|
173
|
-
* Array merge strategy that replaces arrays (source wins over target).
|
|
174
|
-
* This ensures that when a user specifies an array value, it replaces
|
|
175
|
-
* the default rather than merging/concatenating.
|
|
176
|
-
*
|
|
177
|
-
* @internal
|
|
178
|
-
*/
|
|
179
|
-
const replaceArrays = (_target, source) => source;
|
|
180
|
-
// ============================================
|
|
181
|
-
// Utility Functions
|
|
182
|
-
// ============================================
|
|
183
|
-
/**
|
|
184
|
-
* Legacy field names that indicate old configuration format
|
|
185
|
-
*/
|
|
186
|
-
const LEGACY_FIELDS = [
|
|
187
|
-
'schemas', // Old array-style schema config (should be graphile.schema)
|
|
188
|
-
'pgConfig', // Old naming (should be pg)
|
|
189
|
-
'serverPort', // Flat config (should be server.port)
|
|
190
|
-
'serverHost', // Flat config (should be server.host)
|
|
191
|
-
'dbConfig', // Old naming (should be db)
|
|
192
|
-
'postgraphile', // Old Graphile v4 naming (should be graphile)
|
|
193
|
-
'pgPool', // Direct pool config (deprecated)
|
|
194
|
-
'jwtSecret', // Flat JWT config (should be in api or auth)
|
|
195
|
-
'watchPg' // Old PostGraphile v4 option
|
|
196
|
-
];
|
|
197
|
-
/**
|
|
198
|
-
* Detects if the given options object uses a deprecated/legacy format
|
|
199
|
-
*
|
|
200
|
-
* Checks for presence of legacy field names that indicate the configuration
|
|
201
|
-
* needs to be migrated to ConstructiveOptions format.
|
|
202
|
-
*
|
|
203
|
-
* @param opts - Unknown value to check
|
|
204
|
-
* @returns True if legacy configuration patterns are detected
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* ```typescript
|
|
208
|
-
* if (isLegacyOptions(config)) {
|
|
209
|
-
* console.warn('Detected legacy configuration format. Please migrate to ConstructiveOptions.');
|
|
210
|
-
* }
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
function isLegacyOptions(opts) {
|
|
214
|
-
if (opts === null || opts === undefined || typeof opts !== 'object') {
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
const obj = opts;
|
|
218
|
-
return LEGACY_FIELDS.some((field) => field in obj);
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Normalizes input to a ConstructiveOptions object with defaults applied
|
|
222
|
-
*
|
|
223
|
-
* Accepts ConstructiveOptions and returns a fully normalized object
|
|
224
|
-
* with default values applied via deep merge. User-provided values override defaults.
|
|
225
|
-
*
|
|
226
|
-
* @param opts - ConstructiveOptions to normalize
|
|
227
|
-
* @returns ConstructiveOptions with defaults filled in
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* ```typescript
|
|
231
|
-
* // Partial config - missing fields filled from defaults
|
|
232
|
-
* const normalized = normalizeServerOptions({
|
|
233
|
-
* pg: { database: 'myapp' }
|
|
234
|
-
* });
|
|
235
|
-
*
|
|
236
|
-
* // normalized.pg.host === 'localhost' (from default)
|
|
237
|
-
* // normalized.pg.database === 'myapp' (from user config)
|
|
238
|
-
* // normalized.server.port === 3000 (from default)
|
|
239
|
-
* ```
|
|
240
|
-
*/
|
|
241
|
-
function normalizeServerOptions(opts) {
|
|
242
|
-
// Deep merge with defaults - user options override defaults
|
|
243
|
-
return (0, deepmerge_1.default)(exports.serverDefaults, opts, { arrayMerge: replaceArrays });
|
|
244
|
-
}
|