@cosmneo/onion-lasagna 0.3.0 → 0.4.0
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/dist/{chunk-XWKHOLIP.js → chunk-4HMXTGHK.js} +2 -2
- package/dist/chunk-4RFWJ5XZ.js +192 -0
- package/dist/chunk-4RFWJ5XZ.js.map +1 -0
- package/dist/{chunk-4BVOLXDJ.js → chunk-4YBAV6LZ.js} +2 -2
- package/dist/chunk-ANLXZHUS.js +230 -0
- package/dist/chunk-ANLXZHUS.js.map +1 -0
- package/dist/chunk-BG2FY27M.js +36 -0
- package/dist/chunk-BG2FY27M.js.map +1 -0
- package/dist/chunk-FEY2GSVT.js +1 -0
- package/dist/chunk-FEY2GSVT.js.map +1 -0
- package/dist/{chunk-2BVCU32G.js → chunk-HNEAH6OZ.js} +121 -2
- package/dist/chunk-HNEAH6OZ.js.map +1 -0
- package/dist/chunk-NQMFWI6Q.js +1 -0
- package/dist/chunk-NQMFWI6Q.js.map +1 -0
- package/dist/chunk-TZRBETT3.js +127 -0
- package/dist/chunk-TZRBETT3.js.map +1 -0
- package/dist/{chunk-MF2JDREK.js → chunk-UNVB4INM.js} +1 -1
- package/dist/{chunk-MF2JDREK.js.map → chunk-UNVB4INM.js.map} +1 -1
- package/dist/chunk-VBG3UYQR.js +119 -0
- package/dist/chunk-VBG3UYQR.js.map +1 -0
- package/dist/events/index.js +3 -4
- package/dist/events/server/index.js +3 -4
- package/dist/events/shared/index.js +2 -3
- package/dist/graphql/field/index.cjs +189 -0
- package/dist/graphql/field/index.cjs.map +1 -0
- package/dist/graphql/field/index.d.cts +214 -0
- package/dist/graphql/field/index.d.ts +214 -0
- package/dist/graphql/field/index.js +25 -0
- package/dist/graphql/field/index.js.map +1 -0
- package/dist/graphql/index.cjs +1148 -0
- package/dist/graphql/index.cjs.map +1 -0
- package/dist/graphql/index.d.cts +8 -0
- package/dist/graphql/index.d.ts +8 -0
- package/dist/graphql/index.js +49 -0
- package/dist/graphql/index.js.map +1 -0
- package/dist/graphql/sdl/index.cjs +241 -0
- package/dist/graphql/sdl/index.cjs.map +1 -0
- package/dist/graphql/sdl/index.d.cts +77 -0
- package/dist/graphql/sdl/index.d.ts +77 -0
- package/dist/graphql/sdl/index.js +8 -0
- package/dist/graphql/sdl/index.js.map +1 -0
- package/dist/graphql/server/index.cjs +505 -0
- package/dist/graphql/server/index.cjs.map +1 -0
- package/dist/graphql/server/index.d.cts +268 -0
- package/dist/graphql/server/index.d.ts +268 -0
- package/dist/graphql/server/index.js +15 -0
- package/dist/graphql/server/index.js.map +1 -0
- package/dist/graphql/shared/index.cjs +586 -0
- package/dist/graphql/shared/index.cjs.map +1 -0
- package/dist/graphql/shared/index.d.cts +82 -0
- package/dist/graphql/shared/index.d.ts +82 -0
- package/dist/graphql/shared/index.js +16 -0
- package/dist/graphql/shared/index.js.map +1 -0
- package/dist/http/index.cjs.map +1 -1
- package/dist/http/index.js +2 -3
- package/dist/http/route/index.cjs.map +1 -1
- package/dist/http/route/index.d.cts +4 -0
- package/dist/http/route/index.d.ts +4 -0
- package/dist/http/route/index.js +1 -1
- package/dist/http/shared/index.js +1 -2
- package/dist/index.cjs +672 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +43 -1
- package/dist/index.js.map +1 -1
- package/dist/schema-definition.type-C9PntBVc.d.cts +166 -0
- package/dist/schema-definition.type-CuhQLDr0.d.ts +166 -0
- package/package.json +31 -1
- package/dist/chunk-2BVCU32G.js.map +0 -1
- package/dist/chunk-H5TNDC5U.js +0 -138
- package/dist/chunk-H5TNDC5U.js.map +0 -1
- /package/dist/{chunk-XWKHOLIP.js.map → chunk-4HMXTGHK.js.map} +0 -0
- /package/dist/{chunk-4BVOLXDJ.js.map → chunk-4YBAV6LZ.js.map} +0 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/presentation/graphql/sdl/index.ts
|
|
21
|
+
var sdl_exports = {};
|
|
22
|
+
__export(sdl_exports, {
|
|
23
|
+
generateGraphQLSDL: () => generateGraphQLSDL
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(sdl_exports);
|
|
26
|
+
|
|
27
|
+
// src/presentation/graphql/field/types/schema-definition.type.ts
|
|
28
|
+
function isFieldDefinition(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && "_isGraphQLField" in value && value._isGraphQLField === true;
|
|
30
|
+
}
|
|
31
|
+
function isSchemaDefinition(value) {
|
|
32
|
+
return typeof value === "object" && value !== null && "_isGraphQLSchema" in value && value._isGraphQLSchema === true;
|
|
33
|
+
}
|
|
34
|
+
function collectFields(config, basePath = "") {
|
|
35
|
+
const fields = [];
|
|
36
|
+
for (const [key, value] of Object.entries(config)) {
|
|
37
|
+
const fullKey = basePath ? `${basePath}.${key}` : key;
|
|
38
|
+
if (isFieldDefinition(value)) {
|
|
39
|
+
fields.push({ key: fullKey, field: value });
|
|
40
|
+
} else if (isSchemaDefinition(value)) {
|
|
41
|
+
fields.push(...collectFields(value.fields, fullKey));
|
|
42
|
+
} else if (typeof value === "object" && value !== null) {
|
|
43
|
+
fields.push(...collectFields(value, fullKey));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return fields;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/presentation/graphql/field/utils.ts
|
|
50
|
+
function generateFieldId(key) {
|
|
51
|
+
return key.split(".").map(
|
|
52
|
+
(segment, index) => index === 0 ? segment : segment.charAt(0).toUpperCase() + segment.slice(1)
|
|
53
|
+
).join("");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/presentation/graphql/sdl/generate.ts
|
|
57
|
+
function generateGraphQLSDL(schema, config) {
|
|
58
|
+
const fields = isSchemaDefinition(schema) ? schema.fields : schema;
|
|
59
|
+
const collectedFields = collectFields(fields);
|
|
60
|
+
const includeDescriptions = config?.includeDescriptions ?? true;
|
|
61
|
+
const includeDeprecations = config?.includeDeprecations ?? true;
|
|
62
|
+
const queries = [];
|
|
63
|
+
const mutations = [];
|
|
64
|
+
const subscriptions = [];
|
|
65
|
+
for (const { key, field } of collectedFields) {
|
|
66
|
+
const fieldId = generateFieldId(key);
|
|
67
|
+
if (field.operation === "query") {
|
|
68
|
+
queries.push({ fieldId, field });
|
|
69
|
+
} else if (field.operation === "mutation") {
|
|
70
|
+
mutations.push({ fieldId, field });
|
|
71
|
+
} else if (field.operation === "subscription") {
|
|
72
|
+
subscriptions.push({ fieldId, field });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const namedTypes = /* @__PURE__ */ new Map();
|
|
76
|
+
const lines = [];
|
|
77
|
+
if (config?.preamble) {
|
|
78
|
+
lines.push(config.preamble);
|
|
79
|
+
lines.push("");
|
|
80
|
+
}
|
|
81
|
+
if (queries.length > 0) {
|
|
82
|
+
lines.push("type Query {");
|
|
83
|
+
for (const { fieldId, field } of queries) {
|
|
84
|
+
const fieldLine = buildFieldLine(
|
|
85
|
+
fieldId,
|
|
86
|
+
field,
|
|
87
|
+
namedTypes,
|
|
88
|
+
includeDescriptions,
|
|
89
|
+
includeDeprecations
|
|
90
|
+
);
|
|
91
|
+
lines.push(fieldLine);
|
|
92
|
+
}
|
|
93
|
+
lines.push("}");
|
|
94
|
+
lines.push("");
|
|
95
|
+
}
|
|
96
|
+
if (mutations.length > 0) {
|
|
97
|
+
lines.push("type Mutation {");
|
|
98
|
+
for (const { fieldId, field } of mutations) {
|
|
99
|
+
const fieldLine = buildFieldLine(
|
|
100
|
+
fieldId,
|
|
101
|
+
field,
|
|
102
|
+
namedTypes,
|
|
103
|
+
includeDescriptions,
|
|
104
|
+
includeDeprecations
|
|
105
|
+
);
|
|
106
|
+
lines.push(fieldLine);
|
|
107
|
+
}
|
|
108
|
+
lines.push("}");
|
|
109
|
+
lines.push("");
|
|
110
|
+
}
|
|
111
|
+
if (subscriptions.length > 0) {
|
|
112
|
+
lines.push("type Subscription {");
|
|
113
|
+
for (const { fieldId, field } of subscriptions) {
|
|
114
|
+
const fieldLine = buildFieldLine(
|
|
115
|
+
fieldId,
|
|
116
|
+
field,
|
|
117
|
+
namedTypes,
|
|
118
|
+
includeDescriptions,
|
|
119
|
+
includeDeprecations
|
|
120
|
+
);
|
|
121
|
+
lines.push(fieldLine);
|
|
122
|
+
}
|
|
123
|
+
lines.push("}");
|
|
124
|
+
lines.push("");
|
|
125
|
+
}
|
|
126
|
+
for (const [, typeBody] of namedTypes) {
|
|
127
|
+
lines.push(typeBody);
|
|
128
|
+
lines.push("");
|
|
129
|
+
}
|
|
130
|
+
return lines.join("\n").trimEnd() + "\n";
|
|
131
|
+
}
|
|
132
|
+
function buildFieldLine(fieldId, field, namedTypes, includeDescriptions, includeDeprecations) {
|
|
133
|
+
const parts = [];
|
|
134
|
+
if (includeDescriptions && field.docs.description) {
|
|
135
|
+
const escaped = field.docs.description.replace(/"""/g, '\\"""');
|
|
136
|
+
parts.push(` """${escaped}"""`);
|
|
137
|
+
}
|
|
138
|
+
const inputTypeName = field.input ? `${capitalize(fieldId)}Input` : void 0;
|
|
139
|
+
const outputTypeName = field.output ? `${capitalize(fieldId)}Output` : void 0;
|
|
140
|
+
if (field.input && inputTypeName) {
|
|
141
|
+
const jsonSchema = field.input.toJsonSchema();
|
|
142
|
+
namedTypes.set(inputTypeName, buildInputType(inputTypeName, jsonSchema));
|
|
143
|
+
}
|
|
144
|
+
if (field.output && outputTypeName) {
|
|
145
|
+
const jsonSchema = field.output.toJsonSchema();
|
|
146
|
+
namedTypes.set(outputTypeName, buildOutputType(outputTypeName, jsonSchema));
|
|
147
|
+
}
|
|
148
|
+
let signature = ` ${fieldId}`;
|
|
149
|
+
if (inputTypeName) {
|
|
150
|
+
signature += `(input: ${inputTypeName}!)`;
|
|
151
|
+
}
|
|
152
|
+
signature += ": ";
|
|
153
|
+
signature += outputTypeName ?? "JSON";
|
|
154
|
+
if (includeDeprecations && field.docs.deprecated) {
|
|
155
|
+
const reason = field.docs.deprecationReason;
|
|
156
|
+
signature += reason ? ` @deprecated(reason: "${escapeSDLString(reason)}")` : " @deprecated";
|
|
157
|
+
}
|
|
158
|
+
if (parts.length > 0) {
|
|
159
|
+
return parts.join("\n") + "\n" + signature;
|
|
160
|
+
}
|
|
161
|
+
return signature;
|
|
162
|
+
}
|
|
163
|
+
function buildInputType(typeName, jsonSchema) {
|
|
164
|
+
const lines = [`input ${typeName} {`];
|
|
165
|
+
if (jsonSchema.properties && typeof jsonSchema.properties === "object") {
|
|
166
|
+
const required = new Set(
|
|
167
|
+
Array.isArray(jsonSchema.required) ? jsonSchema.required : []
|
|
168
|
+
);
|
|
169
|
+
for (const [propName, propSchema] of Object.entries(
|
|
170
|
+
jsonSchema.properties
|
|
171
|
+
)) {
|
|
172
|
+
const graphqlType = jsonSchemaToGraphQLType(propSchema);
|
|
173
|
+
const isRequired = required.has(propName);
|
|
174
|
+
lines.push(` ${propName}: ${graphqlType}${isRequired ? "!" : ""}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
lines.push("}");
|
|
178
|
+
return lines.join("\n");
|
|
179
|
+
}
|
|
180
|
+
function buildOutputType(typeName, jsonSchema) {
|
|
181
|
+
const lines = [`type ${typeName} {`];
|
|
182
|
+
if (jsonSchema.properties && typeof jsonSchema.properties === "object") {
|
|
183
|
+
const required = new Set(
|
|
184
|
+
Array.isArray(jsonSchema.required) ? jsonSchema.required : []
|
|
185
|
+
);
|
|
186
|
+
for (const [propName, propSchema] of Object.entries(
|
|
187
|
+
jsonSchema.properties
|
|
188
|
+
)) {
|
|
189
|
+
const graphqlType = jsonSchemaToGraphQLType(propSchema);
|
|
190
|
+
const isRequired = required.has(propName);
|
|
191
|
+
lines.push(` ${propName}: ${graphqlType}${isRequired ? "!" : ""}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
lines.push("}");
|
|
195
|
+
return lines.join("\n");
|
|
196
|
+
}
|
|
197
|
+
function jsonSchemaToGraphQLType(schema) {
|
|
198
|
+
if (!schema || typeof schema !== "object") return "JSON";
|
|
199
|
+
if (schema.enum && Array.isArray(schema.enum)) {
|
|
200
|
+
return "String";
|
|
201
|
+
}
|
|
202
|
+
const type = schema.type;
|
|
203
|
+
switch (type) {
|
|
204
|
+
case "string":
|
|
205
|
+
return "String";
|
|
206
|
+
case "integer":
|
|
207
|
+
return "Int";
|
|
208
|
+
case "number":
|
|
209
|
+
return "Float";
|
|
210
|
+
case "boolean":
|
|
211
|
+
return "Boolean";
|
|
212
|
+
case "array": {
|
|
213
|
+
const items = schema.items;
|
|
214
|
+
if (items) {
|
|
215
|
+
return `[${jsonSchemaToGraphQLType(items)}]`;
|
|
216
|
+
}
|
|
217
|
+
return "[JSON]";
|
|
218
|
+
}
|
|
219
|
+
case "object":
|
|
220
|
+
return "JSON";
|
|
221
|
+
default:
|
|
222
|
+
if (schema.oneOf || schema.anyOf || schema.allOf) {
|
|
223
|
+
return "JSON";
|
|
224
|
+
}
|
|
225
|
+
if (schema.properties) {
|
|
226
|
+
return "JSON";
|
|
227
|
+
}
|
|
228
|
+
return "JSON";
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function capitalize(str) {
|
|
232
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
233
|
+
}
|
|
234
|
+
function escapeSDLString(str) {
|
|
235
|
+
return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
|
|
236
|
+
}
|
|
237
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
238
|
+
0 && (module.exports = {
|
|
239
|
+
generateGraphQLSDL
|
|
240
|
+
});
|
|
241
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/presentation/graphql/sdl/index.ts","../../../src/presentation/graphql/field/types/schema-definition.type.ts","../../../src/presentation/graphql/field/utils.ts","../../../src/presentation/graphql/sdl/generate.ts"],"sourcesContent":["/**\n * @fileoverview GraphQL SDL generation module exports.\n *\n * @module graphql/sdl\n *\n * @example Generate SDL\n * ```typescript\n * import { generateGraphQLSDL } from '@cosmneo/onion-lasagna/graphql/sdl';\n *\n * const sdl = generateGraphQLSDL(schema);\n * ```\n */\n\nexport { generateGraphQLSDL } from './generate';\nexport type { GraphQLSDLConfig } from './types';\n","/**\n * @fileoverview GraphQL schema definition types for grouping fields.\n *\n * Mirrors the HTTP router definition pattern with hierarchical grouping,\n * dotted-key access, and deep merge support.\n *\n * @module graphql/field/types/schema-definition\n */\n\nimport type { GraphQLFieldDefinition, GraphQLOperationType } from './field-definition.type';\nimport type { SchemaAdapter } from '../../../http/schema/types';\n\n// ============================================================================\n// Schema Types\n// ============================================================================\n\n/**\n * A schema entry can be a field definition, a nested config, or a schema definition.\n */\nexport type GraphQLSchemaEntry =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n | GraphQLFieldDefinition<GraphQLOperationType, any, any, any>\n | GraphQLSchemaConfig\n | GraphQLSchemaDefinition;\n\n/**\n * Configuration for a GraphQL schema (group of fields).\n */\nexport interface GraphQLSchemaConfig {\n readonly [key: string]: GraphQLSchemaEntry;\n}\n\n/**\n * Schema-level defaults applied to all child fields.\n */\nexport interface GraphQLSchemaDefaults {\n /** Default tags for all fields. Merged with field-specific tags. */\n readonly tags?: readonly string[];\n\n /** Default context schema. Applied to fields that don't define their own. */\n readonly context?: SchemaAdapter;\n}\n\n/**\n * A fully defined GraphQL schema.\n */\nexport interface GraphQLSchemaDefinition<T extends GraphQLSchemaConfig = GraphQLSchemaConfig> {\n /** The fields and nested groups in this schema. */\n readonly fields: T;\n\n /** Default values applied to all child fields. */\n readonly defaults?: GraphQLSchemaDefaults;\n\n /**\n * Marker to identify this as a GraphQL schema definition.\n * @internal\n */\n readonly _isGraphQLSchema: true;\n}\n\n// ============================================================================\n// Type Guards\n// ============================================================================\n\n/**\n * Checks if a value is a GraphQLFieldDefinition.\n */\nexport function isFieldDefinition(value: unknown): value is GraphQLFieldDefinition {\n return (\n typeof value === 'object' &&\n value !== null &&\n '_isGraphQLField' in value &&\n (value as GraphQLFieldDefinition)._isGraphQLField === true\n );\n}\n\n/**\n * Checks if a value is a GraphQLSchemaDefinition.\n */\nexport function isSchemaDefinition(value: unknown): value is GraphQLSchemaDefinition {\n return (\n typeof value === 'object' &&\n value !== null &&\n '_isGraphQLSchema' in value &&\n (value as GraphQLSchemaDefinition)._isGraphQLSchema === true\n );\n}\n\n// ============================================================================\n// Utility Types\n// ============================================================================\n\n/**\n * Flattens a schema into a map of dotted keys to field definitions.\n */\nexport type FlattenSchema<\n T extends GraphQLSchemaConfig,\n Prefix extends string = '',\n> = T extends GraphQLSchemaConfig\n ? {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [K in keyof T]: T[K] extends GraphQLFieldDefinition<any, any, any, any>\n ? { [P in `${Prefix}${K & string}`]: T[K] }\n : T[K] extends GraphQLSchemaConfig\n ? FlattenSchema<T[K], `${Prefix}${K & string}.`>\n : never;\n }[keyof T] extends infer U\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n U extends Record<string, GraphQLFieldDefinition<any, any, any, any>>\n ? U\n : never\n : never\n : never;\n\n/**\n * Gets all field keys from a schema.\n */\nexport type SchemaKeys<\n T extends GraphQLSchemaConfig,\n Prefix extends string = '',\n> = T extends GraphQLSchemaConfig\n ? {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [K in keyof T]: T[K] extends GraphQLFieldDefinition<any, any, any, any>\n ? `${Prefix}${K & string}`\n : T[K] extends GraphQLSchemaConfig\n ? SchemaKeys<T[K], `${Prefix}${K & string}.`>\n : never;\n }[keyof T]\n : never;\n\n/**\n * Gets a field by its dotted key path.\n */\nexport type GetField<\n T extends GraphQLSchemaConfig,\n K extends string,\n> = K extends `${infer Head}.${infer Tail}`\n ? Head extends keyof T\n ? T[Head] extends GraphQLSchemaConfig\n ? GetField<T[Head], Tail>\n : never\n : never\n : K extends keyof T\n ? // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T[K] extends GraphQLFieldDefinition<any, any, any, any>\n ? T[K]\n : never\n : never;\n\n// ============================================================================\n// Deep Merge Types\n// ============================================================================\n\n/**\n * Deep-merges two schema configs at the type level.\n */\nexport type DeepMergeSchemas<A extends GraphQLSchemaConfig, B extends GraphQLSchemaConfig> = {\n readonly [K in keyof A | keyof B]: K extends keyof A\n ? K extends keyof B\n ? A[K] extends GraphQLSchemaConfig\n ? B[K] extends GraphQLSchemaConfig\n ? DeepMergeSchemas<A[K], B[K]>\n : B[K]\n : B[K]\n : A[K]\n : K extends keyof B\n ? B[K]\n : never;\n};\n\n/**\n * Recursively deep-merges N schema configs left-to-right.\n */\nexport type DeepMergeSchemasAll<T extends readonly GraphQLSchemaConfig[]> = T extends readonly [\n infer Only extends GraphQLSchemaConfig,\n]\n ? Only\n : T extends readonly [\n infer First extends GraphQLSchemaConfig,\n infer Second extends GraphQLSchemaConfig,\n ...infer Rest extends readonly GraphQLSchemaConfig[],\n ]\n ? DeepMergeSchemasAll<[DeepMergeSchemas<First, Second>, ...Rest]>\n : GraphQLSchemaConfig;\n\n// ============================================================================\n// Runtime Utilities\n// ============================================================================\n\n/**\n * Collects all fields from a schema into a flat array.\n */\nexport function collectFields(\n config: GraphQLSchemaConfig,\n basePath = '',\n): { key: string; field: GraphQLFieldDefinition }[] {\n const fields: { key: string; field: GraphQLFieldDefinition }[] = [];\n\n for (const [key, value] of Object.entries(config)) {\n const fullKey = basePath ? `${basePath}.${key}` : key;\n\n if (isFieldDefinition(value)) {\n fields.push({ key: fullKey, field: value });\n } else if (isSchemaDefinition(value)) {\n fields.push(...collectFields(value.fields, fullKey));\n } else if (typeof value === 'object' && value !== null) {\n fields.push(...collectFields(value as GraphQLSchemaConfig, fullKey));\n }\n }\n\n return fields;\n}\n","/**\n * @fileoverview GraphQL field utility functions.\n *\n * @module graphql/field/utils\n */\n\n/**\n * Generates a field ID from a schema key path.\n *\n * This is the **single source of truth** for the naming convention used across:\n * - SDL generation (`type Query { usersGet(...) }`)\n * - Yoga resolver map keys\n * - Client query string field names\n *\n * Converts dotted key paths to camelCase:\n * - `\"users.get\"` → `\"usersGet\"`\n * - `\"projects.members.list\"` → `\"projectsMembersList\"`\n * - `\"getUser\"` → `\"getUser\"` (single segment unchanged)\n *\n * @param key - The dotted schema key path\n * @returns A camelCase field ID string\n */\nexport function generateFieldId(key: string): string {\n return key\n .split('.')\n .map((segment, index) =>\n index === 0 ? segment : segment.charAt(0).toUpperCase() + segment.slice(1),\n )\n .join('');\n}\n","/**\n * @fileoverview GraphQL SDL generation from schema definitions.\n *\n * The `generateGraphQLSDL` function creates a complete GraphQL Schema\n * Definition Language string from a schema definition.\n *\n * Input/output schemas are converted to JSON Schema via `toJsonSchema()`,\n * then mapped to GraphQL type definitions.\n *\n * @module graphql/sdl/generate\n */\n\nimport type { SchemaAdapter, JsonSchema } from '../../http/schema/types';\nimport type {\n GraphQLSchemaConfig,\n GraphQLSchemaDefinition,\n GraphQLFieldDefinition,\n} from '../field/types';\nimport { isSchemaDefinition, collectFields } from '../field/types';\nimport { generateFieldId } from '../field/utils';\nimport type { GraphQLSDLConfig } from './types';\n\n// ============================================================================\n// Public API\n// ============================================================================\n\n/**\n * Generates a GraphQL SDL string from a schema definition.\n *\n * Walks the schema structure, extracts JSON schemas from all field\n * definitions, and builds a complete SDL with Query, Mutation, and\n * type definitions.\n *\n * @param schema - Schema definition or schema config\n * @param config - Optional SDL generation configuration\n * @returns Complete GraphQL SDL string\n *\n * @example Basic usage\n * ```typescript\n * import { generateGraphQLSDL } from '@cosmneo/onion-lasagna/graphql/sdl';\n *\n * const sdl = generateGraphQLSDL(projectSchema, {\n * preamble: 'scalar DateTime',\n * });\n *\n * console.log(sdl);\n * // type Query {\n * // projectsGet(input: ProjectsGetInput!): ProjectsGetOutput\n * // projectsList: ProjectsListOutput\n * // }\n * // ...\n * ```\n */\nexport function generateGraphQLSDL<T extends GraphQLSchemaConfig>(\n schema: T | GraphQLSchemaDefinition<T>,\n config?: GraphQLSDLConfig,\n): string {\n const fields = isSchemaDefinition(schema) ? schema.fields : schema;\n const collectedFields = collectFields(fields);\n\n const includeDescriptions = config?.includeDescriptions ?? true;\n const includeDeprecations = config?.includeDeprecations ?? true;\n\n // Partition fields by operation type\n const queries: { fieldId: string; field: GraphQLFieldDefinition }[] = [];\n const mutations: { fieldId: string; field: GraphQLFieldDefinition }[] = [];\n const subscriptions: { fieldId: string; field: GraphQLFieldDefinition }[] = [];\n\n for (const { key, field } of collectedFields) {\n const fieldId = generateFieldId(key);\n if (field.operation === 'query') {\n queries.push({ fieldId, field });\n } else if (field.operation === 'mutation') {\n mutations.push({ fieldId, field });\n } else if (field.operation === 'subscription') {\n subscriptions.push({ fieldId, field });\n }\n }\n\n // Collect all named types that need to be emitted\n const namedTypes: Map<string, string> = new Map();\n const lines: string[] = [];\n\n // Preamble\n if (config?.preamble) {\n lines.push(config.preamble);\n lines.push('');\n }\n\n // Build Query type\n if (queries.length > 0) {\n lines.push('type Query {');\n for (const { fieldId, field } of queries) {\n const fieldLine = buildFieldLine(\n fieldId,\n field,\n namedTypes,\n includeDescriptions,\n includeDeprecations,\n );\n lines.push(fieldLine);\n }\n lines.push('}');\n lines.push('');\n }\n\n // Build Mutation type\n if (mutations.length > 0) {\n lines.push('type Mutation {');\n for (const { fieldId, field } of mutations) {\n const fieldLine = buildFieldLine(\n fieldId,\n field,\n namedTypes,\n includeDescriptions,\n includeDeprecations,\n );\n lines.push(fieldLine);\n }\n lines.push('}');\n lines.push('');\n }\n\n // Build Subscription type\n if (subscriptions.length > 0) {\n lines.push('type Subscription {');\n for (const { fieldId, field } of subscriptions) {\n const fieldLine = buildFieldLine(\n fieldId,\n field,\n namedTypes,\n includeDescriptions,\n includeDeprecations,\n );\n lines.push(fieldLine);\n }\n lines.push('}');\n lines.push('');\n }\n\n // Emit named types (inputs and outputs)\n for (const [, typeBody] of namedTypes) {\n lines.push(typeBody);\n lines.push('');\n }\n\n return lines.join('\\n').trimEnd() + '\\n';\n}\n\n// ============================================================================\n// Internal Helpers\n// ============================================================================\n\n/**\n * Builds a single field line for a root type (Query/Mutation/Subscription).\n */\nfunction buildFieldLine(\n fieldId: string,\n field: GraphQLFieldDefinition,\n namedTypes: Map<string, string>,\n includeDescriptions: boolean,\n includeDeprecations: boolean,\n): string {\n const parts: string[] = [];\n\n // Description as SDL doc string (escaped to prevent triple-quote injection)\n if (includeDescriptions && field.docs.description) {\n const escaped = field.docs.description.replace(/\"\"\"/g, '\\\\\"\"\"');\n parts.push(` \"\"\"${escaped}\"\"\"`);\n }\n\n // Build args and return type\n const inputTypeName = field.input ? `${capitalize(fieldId)}Input` : undefined;\n const outputTypeName = field.output ? `${capitalize(fieldId)}Output` : undefined;\n\n // Register named input type\n if (field.input && inputTypeName) {\n const jsonSchema = (field.input as SchemaAdapter).toJsonSchema();\n namedTypes.set(inputTypeName, buildInputType(inputTypeName, jsonSchema));\n }\n\n // Register named output type\n if (field.output && outputTypeName) {\n const jsonSchema = (field.output as SchemaAdapter).toJsonSchema();\n namedTypes.set(outputTypeName, buildOutputType(outputTypeName, jsonSchema));\n }\n\n // Build field signature\n let signature = ` ${fieldId}`;\n\n if (inputTypeName) {\n signature += `(input: ${inputTypeName}!)`;\n }\n\n signature += ': ';\n signature += outputTypeName ?? 'JSON';\n\n // Deprecation directive\n if (includeDeprecations && field.docs.deprecated) {\n const reason = field.docs.deprecationReason;\n signature += reason ? ` @deprecated(reason: \"${escapeSDLString(reason)}\")` : ' @deprecated';\n }\n\n if (parts.length > 0) {\n return parts.join('\\n') + '\\n' + signature;\n }\n return signature;\n}\n\n/**\n * Builds a GraphQL input type from a JSON schema.\n */\nfunction buildInputType(typeName: string, jsonSchema: JsonSchema): string {\n const lines: string[] = [`input ${typeName} {`];\n\n if (jsonSchema.properties && typeof jsonSchema.properties === 'object') {\n const required = new Set(\n Array.isArray(jsonSchema.required) ? (jsonSchema.required as string[]) : [],\n );\n\n for (const [propName, propSchema] of Object.entries(\n jsonSchema.properties as Record<string, JsonSchema>,\n )) {\n const graphqlType = jsonSchemaToGraphQLType(propSchema);\n const isRequired = required.has(propName);\n lines.push(` ${propName}: ${graphqlType}${isRequired ? '!' : ''}`);\n }\n }\n\n lines.push('}');\n return lines.join('\\n');\n}\n\n/**\n * Builds a GraphQL output type from a JSON schema.\n */\nfunction buildOutputType(typeName: string, jsonSchema: JsonSchema): string {\n const lines: string[] = [`type ${typeName} {`];\n\n if (jsonSchema.properties && typeof jsonSchema.properties === 'object') {\n const required = new Set(\n Array.isArray(jsonSchema.required) ? (jsonSchema.required as string[]) : [],\n );\n\n for (const [propName, propSchema] of Object.entries(\n jsonSchema.properties as Record<string, JsonSchema>,\n )) {\n const graphqlType = jsonSchemaToGraphQLType(propSchema);\n const isRequired = required.has(propName);\n lines.push(` ${propName}: ${graphqlType}${isRequired ? '!' : ''}`);\n }\n }\n\n lines.push('}');\n return lines.join('\\n');\n}\n\n/**\n * Converts a JSON schema to a GraphQL type string.\n */\nfunction jsonSchemaToGraphQLType(schema: JsonSchema): string {\n if (!schema || typeof schema !== 'object') return 'JSON';\n\n // Handle enum\n if (schema.enum && Array.isArray(schema.enum)) {\n return 'String';\n }\n\n // Handle type\n const type = schema.type as string | undefined;\n\n switch (type) {\n case 'string':\n return 'String';\n case 'integer':\n return 'Int';\n case 'number':\n return 'Float';\n case 'boolean':\n return 'Boolean';\n case 'array': {\n const items = schema.items as JsonSchema | undefined;\n if (items) {\n return `[${jsonSchemaToGraphQLType(items)}]`;\n }\n return '[JSON]';\n }\n case 'object':\n return 'JSON';\n default:\n // Handle oneOf, anyOf, allOf — fallback to JSON\n if (schema.oneOf || schema.anyOf || schema.allOf) {\n return 'JSON';\n }\n // Object without explicit type but has properties\n if (schema.properties) {\n return 'JSON';\n }\n return 'JSON';\n }\n}\n\n/**\n * Capitalizes the first letter of a string.\n */\nfunction capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\n/**\n * Escapes a string for use in SDL quoted string literals.\n * Handles backslashes, quotes, newlines, and triple-quote injection.\n */\nfunction escapeSDLString(str: string): string {\n return str\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r')\n .replace(/\\t/g, '\\\\t');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmEO,SAAS,kBAAkB,OAAiD;AACjF,SACE,OAAO,UAAU,YACjB,UAAU,QACV,qBAAqB,SACpB,MAAiC,oBAAoB;AAE1D;AAKO,SAAS,mBAAmB,OAAkD;AACnF,SACE,OAAO,UAAU,YACjB,UAAU,QACV,sBAAsB,SACrB,MAAkC,qBAAqB;AAE5D;AA2GO,SAAS,cACd,QACA,WAAW,IACuC;AAClD,QAAM,SAA2D,CAAC;AAElE,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,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A,MACT;AAEA,UAAI,OAAO,YAAY;AACrB,eAAO;AAAA,MACT;AACA,aAAO;AAAA,EACX;AACF;AAKA,SAAS,WAAW,KAAqB;AACvC,SAAO,IAAI,OAAO,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;AAClD;AAMA,SAAS,gBAAgB,KAAqB;AAC5C,SAAO,IACJ,QAAQ,OAAO,MAAM,EACrB,QAAQ,MAAM,KAAK,EACnB,QAAQ,OAAO,KAAK,EACpB,QAAQ,OAAO,KAAK,EACpB,QAAQ,OAAO,KAAK;AACzB;","names":[]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { d as GraphQLSchemaConfig, f as GraphQLSchemaDefinition } from '../../schema-definition.type-C9PntBVc.cjs';
|
|
2
|
+
import '../../http/schema/types.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Types for GraphQL SDL generation.
|
|
6
|
+
*
|
|
7
|
+
* @module graphql/sdl/types
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for SDL generation.
|
|
11
|
+
*/
|
|
12
|
+
interface GraphQLSDLConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Additional SDL to prepend (e.g., custom scalars, directives).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* generateGraphQLSDL(schema, {
|
|
19
|
+
* preamble: 'scalar DateTime\nscalar UUID',
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
readonly preamble?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to include descriptions as SDL doc strings.
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
readonly includeDescriptions?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to include @deprecated directives.
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
readonly includeDeprecations?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @fileoverview GraphQL SDL generation from schema definitions.
|
|
38
|
+
*
|
|
39
|
+
* The `generateGraphQLSDL` function creates a complete GraphQL Schema
|
|
40
|
+
* Definition Language string from a schema definition.
|
|
41
|
+
*
|
|
42
|
+
* Input/output schemas are converted to JSON Schema via `toJsonSchema()`,
|
|
43
|
+
* then mapped to GraphQL type definitions.
|
|
44
|
+
*
|
|
45
|
+
* @module graphql/sdl/generate
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Generates a GraphQL SDL string from a schema definition.
|
|
50
|
+
*
|
|
51
|
+
* Walks the schema structure, extracts JSON schemas from all field
|
|
52
|
+
* definitions, and builds a complete SDL with Query, Mutation, and
|
|
53
|
+
* type definitions.
|
|
54
|
+
*
|
|
55
|
+
* @param schema - Schema definition or schema config
|
|
56
|
+
* @param config - Optional SDL generation configuration
|
|
57
|
+
* @returns Complete GraphQL SDL string
|
|
58
|
+
*
|
|
59
|
+
* @example Basic usage
|
|
60
|
+
* ```typescript
|
|
61
|
+
* import { generateGraphQLSDL } from '@cosmneo/onion-lasagna/graphql/sdl';
|
|
62
|
+
*
|
|
63
|
+
* const sdl = generateGraphQLSDL(projectSchema, {
|
|
64
|
+
* preamble: 'scalar DateTime',
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* console.log(sdl);
|
|
68
|
+
* // type Query {
|
|
69
|
+
* // projectsGet(input: ProjectsGetInput!): ProjectsGetOutput
|
|
70
|
+
* // projectsList: ProjectsListOutput
|
|
71
|
+
* // }
|
|
72
|
+
* // ...
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare function generateGraphQLSDL<T extends GraphQLSchemaConfig>(schema: T | GraphQLSchemaDefinition<T>, config?: GraphQLSDLConfig): string;
|
|
76
|
+
|
|
77
|
+
export { type GraphQLSDLConfig, generateGraphQLSDL };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { d as GraphQLSchemaConfig, f as GraphQLSchemaDefinition } from '../../schema-definition.type-CuhQLDr0.js';
|
|
2
|
+
import '../../http/schema/types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @fileoverview Types for GraphQL SDL generation.
|
|
6
|
+
*
|
|
7
|
+
* @module graphql/sdl/types
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for SDL generation.
|
|
11
|
+
*/
|
|
12
|
+
interface GraphQLSDLConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Additional SDL to prepend (e.g., custom scalars, directives).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* generateGraphQLSDL(schema, {
|
|
19
|
+
* preamble: 'scalar DateTime\nscalar UUID',
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
readonly preamble?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to include descriptions as SDL doc strings.
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
readonly includeDescriptions?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether to include @deprecated directives.
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
readonly includeDeprecations?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @fileoverview GraphQL SDL generation from schema definitions.
|
|
38
|
+
*
|
|
39
|
+
* The `generateGraphQLSDL` function creates a complete GraphQL Schema
|
|
40
|
+
* Definition Language string from a schema definition.
|
|
41
|
+
*
|
|
42
|
+
* Input/output schemas are converted to JSON Schema via `toJsonSchema()`,
|
|
43
|
+
* then mapped to GraphQL type definitions.
|
|
44
|
+
*
|
|
45
|
+
* @module graphql/sdl/generate
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Generates a GraphQL SDL string from a schema definition.
|
|
50
|
+
*
|
|
51
|
+
* Walks the schema structure, extracts JSON schemas from all field
|
|
52
|
+
* definitions, and builds a complete SDL with Query, Mutation, and
|
|
53
|
+
* type definitions.
|
|
54
|
+
*
|
|
55
|
+
* @param schema - Schema definition or schema config
|
|
56
|
+
* @param config - Optional SDL generation configuration
|
|
57
|
+
* @returns Complete GraphQL SDL string
|
|
58
|
+
*
|
|
59
|
+
* @example Basic usage
|
|
60
|
+
* ```typescript
|
|
61
|
+
* import { generateGraphQLSDL } from '@cosmneo/onion-lasagna/graphql/sdl';
|
|
62
|
+
*
|
|
63
|
+
* const sdl = generateGraphQLSDL(projectSchema, {
|
|
64
|
+
* preamble: 'scalar DateTime',
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* console.log(sdl);
|
|
68
|
+
* // type Query {
|
|
69
|
+
* // projectsGet(input: ProjectsGetInput!): ProjectsGetOutput
|
|
70
|
+
* // projectsList: ProjectsListOutput
|
|
71
|
+
* // }
|
|
72
|
+
* // ...
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare function generateGraphQLSDL<T extends GraphQLSchemaConfig>(schema: T | GraphQLSchemaDefinition<T>, config?: GraphQLSDLConfig): string;
|
|
76
|
+
|
|
77
|
+
export { type GraphQLSDLConfig, generateGraphQLSDL };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|