@macss/modular-api 0.4.6 → 0.4.8
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/README.md +70 -8
- package/dist/core/logger/logger.d.ts +1 -0
- package/dist/core/logger/logger.js +1 -0
- package/dist/core/logger/logging_middleware.js +11 -0
- package/dist/core/modular_api.d.ts +8 -0
- package/dist/core/modular_api.js +99 -42
- package/dist/core/official_plugins.d.ts +35 -0
- package/dist/core/official_plugins.js +213 -0
- package/dist/core/plugin.d.ts +163 -0
- package/dist/core/plugin.js +304 -0
- package/dist/core/request_pipeline_audit.d.ts +15 -0
- package/dist/core/request_pipeline_audit.js +29 -0
- package/dist/core/unhandled_request_error_handler.d.ts +2 -0
- package/dist/core/unhandled_request_error_handler.js +17 -0
- package/dist/graphql/catalog/graphql_catalog_builder.d.ts +149 -0
- package/dist/graphql/catalog/graphql_catalog_builder.js +564 -0
- package/dist/graphql/metadata/graphql_metadata_parser.d.ts +53 -0
- package/dist/graphql/metadata/graphql_metadata_parser.js +373 -0
- package/dist/graphql/read/sql_read_contract.d.ts +155 -0
- package/dist/graphql/read/sql_read_contract.js +194 -0
- package/dist/graphql/read/sqlserver_read_compiler.d.ts +58 -0
- package/dist/graphql/read/sqlserver_read_compiler.js +279 -0
- package/dist/graphql/runtime/graphql_artifacts.d.ts +43 -0
- package/dist/graphql/runtime/graphql_artifacts.js +512 -0
- package/dist/graphql/runtime/graphql_runtime_options.d.ts +52 -0
- package/dist/graphql/runtime/graphql_runtime_options.js +60 -0
- package/dist/graphql/runtime/graphql_runtime_plugin.d.ts +18 -0
- package/dist/graphql/runtime/graphql_runtime_plugin.js +946 -0
- package/dist/graphql/schema/graphql_schema_sdl_generator.d.ts +17 -0
- package/dist/graphql/schema/graphql_schema_sdl_generator.js +221 -0
- package/dist/graphql/sqlserver/physical_model.d.ts +28 -0
- package/dist/graphql/sqlserver/physical_model.js +8 -0
- package/dist/graphql/sqlserver/sql_server_connection_settings.d.ts +15 -0
- package/dist/graphql/sqlserver/sql_server_connection_settings.js +28 -0
- package/dist/graphql/sqlserver/sql_server_metadata_reader.d.ts +39 -0
- package/dist/graphql/sqlserver/sql_server_metadata_reader.js +294 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +58 -1
- package/dist/openapi/swagger_docs.d.ts +4 -0
- package/dist/openapi/swagger_docs.js +6 -2
- package/package.json +8 -6
|
@@ -0,0 +1,564 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphqlCatalogBuilder = exports.GraphqlCatalogNaming = exports.GraphqlCatalogPaginationMode = exports.GraphqlCatalogRelationCardinality = exports.GraphqlCatalogFieldVisibility = exports.GraphqlCatalogIdentityMode = exports.GraphqlCatalogOrigin = exports.GraphqlCatalogDiagnosticSeverity = exports.GraphqlCatalogBuildMode = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const physical_model_1 = require("../sqlserver/physical_model");
|
|
6
|
+
var GraphqlCatalogBuildMode;
|
|
7
|
+
(function (GraphqlCatalogBuildMode) {
|
|
8
|
+
GraphqlCatalogBuildMode["Compile"] = "compile";
|
|
9
|
+
GraphqlCatalogBuildMode["Runtime"] = "runtime";
|
|
10
|
+
})(GraphqlCatalogBuildMode || (exports.GraphqlCatalogBuildMode = GraphqlCatalogBuildMode = {}));
|
|
11
|
+
var GraphqlCatalogDiagnosticSeverity;
|
|
12
|
+
(function (GraphqlCatalogDiagnosticSeverity) {
|
|
13
|
+
GraphqlCatalogDiagnosticSeverity["Error"] = "error";
|
|
14
|
+
GraphqlCatalogDiagnosticSeverity["Warning"] = "warning";
|
|
15
|
+
GraphqlCatalogDiagnosticSeverity["Info"] = "info";
|
|
16
|
+
})(GraphqlCatalogDiagnosticSeverity || (exports.GraphqlCatalogDiagnosticSeverity = GraphqlCatalogDiagnosticSeverity = {}));
|
|
17
|
+
var GraphqlCatalogOrigin;
|
|
18
|
+
(function (GraphqlCatalogOrigin) {
|
|
19
|
+
GraphqlCatalogOrigin["Inferred"] = "inferred";
|
|
20
|
+
GraphqlCatalogOrigin["Annotated"] = "annotated";
|
|
21
|
+
})(GraphqlCatalogOrigin || (exports.GraphqlCatalogOrigin = GraphqlCatalogOrigin = {}));
|
|
22
|
+
var GraphqlCatalogIdentityMode;
|
|
23
|
+
(function (GraphqlCatalogIdentityMode) {
|
|
24
|
+
GraphqlCatalogIdentityMode["Single"] = "single";
|
|
25
|
+
GraphqlCatalogIdentityMode["Composite"] = "composite";
|
|
26
|
+
GraphqlCatalogIdentityMode["None"] = "none";
|
|
27
|
+
})(GraphqlCatalogIdentityMode || (exports.GraphqlCatalogIdentityMode = GraphqlCatalogIdentityMode = {}));
|
|
28
|
+
var GraphqlCatalogFieldVisibility;
|
|
29
|
+
(function (GraphqlCatalogFieldVisibility) {
|
|
30
|
+
GraphqlCatalogFieldVisibility["Public"] = "public";
|
|
31
|
+
GraphqlCatalogFieldVisibility["Hidden"] = "hidden";
|
|
32
|
+
})(GraphqlCatalogFieldVisibility || (exports.GraphqlCatalogFieldVisibility = GraphqlCatalogFieldVisibility = {}));
|
|
33
|
+
var GraphqlCatalogRelationCardinality;
|
|
34
|
+
(function (GraphqlCatalogRelationCardinality) {
|
|
35
|
+
GraphqlCatalogRelationCardinality["One"] = "one";
|
|
36
|
+
GraphqlCatalogRelationCardinality["Many"] = "many";
|
|
37
|
+
})(GraphqlCatalogRelationCardinality || (exports.GraphqlCatalogRelationCardinality = GraphqlCatalogRelationCardinality = {}));
|
|
38
|
+
var GraphqlCatalogPaginationMode;
|
|
39
|
+
(function (GraphqlCatalogPaginationMode) {
|
|
40
|
+
GraphqlCatalogPaginationMode["Offset"] = "offset";
|
|
41
|
+
GraphqlCatalogPaginationMode["None"] = "none";
|
|
42
|
+
})(GraphqlCatalogPaginationMode || (exports.GraphqlCatalogPaginationMode = GraphqlCatalogPaginationMode = {}));
|
|
43
|
+
class GraphqlCatalogNaming {
|
|
44
|
+
static typeNameForObjectName(value) {
|
|
45
|
+
const tokens = GraphqlCatalogNaming.tokenize(value);
|
|
46
|
+
if (tokens.length === 0) {
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
return tokens.map((token) => GraphqlCatalogNaming.pascalToken(token)).join('');
|
|
50
|
+
}
|
|
51
|
+
static publicFieldNameForColumn(value) {
|
|
52
|
+
const tokens = GraphqlCatalogNaming.tokenize(value);
|
|
53
|
+
if (tokens.length === 0) {
|
|
54
|
+
return '';
|
|
55
|
+
}
|
|
56
|
+
const head = GraphqlCatalogNaming.pascalToken(tokens[0]);
|
|
57
|
+
const tail = tokens.slice(1).map((token) => GraphqlCatalogNaming.pascalToken(token)).join('');
|
|
58
|
+
return GraphqlCatalogNaming.camelToken(head) + tail;
|
|
59
|
+
}
|
|
60
|
+
static tokenize(value) {
|
|
61
|
+
const trimmed = value.trim();
|
|
62
|
+
if (!trimmed) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
const tokens = [];
|
|
66
|
+
const segmentPattern = /[A-Za-z0-9]+/g;
|
|
67
|
+
const wordPattern = /[A-Z]+(?:\d+)?(?=[A-Z][a-z]|$)|[A-Z]?[a-z]+\d*|\d+/g;
|
|
68
|
+
const segments = trimmed.match(segmentPattern) ?? [];
|
|
69
|
+
for (const segment of segments) {
|
|
70
|
+
const words = segment.match(wordPattern) ?? [];
|
|
71
|
+
for (const word of words) {
|
|
72
|
+
if (word) {
|
|
73
|
+
tokens.push(word);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return tokens;
|
|
78
|
+
}
|
|
79
|
+
static pascalToken(token) {
|
|
80
|
+
if (!token) {
|
|
81
|
+
return token;
|
|
82
|
+
}
|
|
83
|
+
if (/^\d+$/.test(token)) {
|
|
84
|
+
return token;
|
|
85
|
+
}
|
|
86
|
+
const lower = token.toLowerCase();
|
|
87
|
+
return `${lower[0].toUpperCase()}${lower.slice(1)}`;
|
|
88
|
+
}
|
|
89
|
+
static camelToken(token) {
|
|
90
|
+
if (!token) {
|
|
91
|
+
return token;
|
|
92
|
+
}
|
|
93
|
+
return `${token[0].toLowerCase()}${token.slice(1)}`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.GraphqlCatalogNaming = GraphqlCatalogNaming;
|
|
97
|
+
class GraphqlCatalogBuilder {
|
|
98
|
+
providerVersion;
|
|
99
|
+
sourceRoot;
|
|
100
|
+
buildMode;
|
|
101
|
+
engine;
|
|
102
|
+
constructor(options) {
|
|
103
|
+
this.providerVersion = options.providerVersion;
|
|
104
|
+
this.sourceRoot = options.sourceRoot;
|
|
105
|
+
this.buildMode = options.buildMode;
|
|
106
|
+
this.engine = options.engine;
|
|
107
|
+
}
|
|
108
|
+
build(options) {
|
|
109
|
+
const diagnostics = [];
|
|
110
|
+
const physicalObjectsById = new Map(options.physicalCatalog.objects.map((object) => [object.id, object]));
|
|
111
|
+
const contexts = new Map();
|
|
112
|
+
const objectIds = Object.keys(options.metadata.objects).sort((left, right) => left.localeCompare(right));
|
|
113
|
+
for (const objectId of objectIds) {
|
|
114
|
+
const physicalObject = physicalObjectsById.get(objectId);
|
|
115
|
+
if (!physicalObject) {
|
|
116
|
+
diagnostics.push({
|
|
117
|
+
severity: GraphqlCatalogDiagnosticSeverity.Error,
|
|
118
|
+
code: 'metadata_object_unknown',
|
|
119
|
+
message: 'Metadata references an object not present in the physical model.',
|
|
120
|
+
objectId,
|
|
121
|
+
});
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const objectMetadata = options.metadata.objects[objectId];
|
|
125
|
+
const identity = this.resolveIdentity({
|
|
126
|
+
physicalObject,
|
|
127
|
+
objectMetadata,
|
|
128
|
+
diagnostics,
|
|
129
|
+
});
|
|
130
|
+
const typeName = objectMetadata.name ?? GraphqlCatalogNaming.typeNameForObjectName(physicalObject.objectName);
|
|
131
|
+
const itemField = identity.mode === GraphqlCatalogIdentityMode.None
|
|
132
|
+
? undefined
|
|
133
|
+
: GraphqlCatalogNaming.publicFieldNameForColumn(typeName);
|
|
134
|
+
const collectionField = `${GraphqlCatalogNaming.publicFieldNameForColumn(typeName)}List`;
|
|
135
|
+
contexts.set(objectId, {
|
|
136
|
+
physicalObject,
|
|
137
|
+
objectMetadata,
|
|
138
|
+
typeName,
|
|
139
|
+
itemField,
|
|
140
|
+
collectionField,
|
|
141
|
+
identity,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
const objects = Array.from(contexts.keys())
|
|
145
|
+
.map((objectId) => this.buildObject({
|
|
146
|
+
context: contexts.get(objectId),
|
|
147
|
+
allContexts: contexts,
|
|
148
|
+
defaultsLimit: options.metadata.defaultsLimit,
|
|
149
|
+
diagnostics,
|
|
150
|
+
}))
|
|
151
|
+
.sort((left, right) => left.id.localeCompare(right.id));
|
|
152
|
+
this.detectDuplicateObjectNames(objects, diagnostics);
|
|
153
|
+
const sortedDiagnostics = this.sortDiagnostics(diagnostics);
|
|
154
|
+
const catalogWithoutDigest = {
|
|
155
|
+
catalogVersion: '1.0.0',
|
|
156
|
+
provider: {
|
|
157
|
+
kind: 'sql',
|
|
158
|
+
engine: this.engine,
|
|
159
|
+
providerVersion: this.providerVersion,
|
|
160
|
+
},
|
|
161
|
+
build: {
|
|
162
|
+
mode: this.buildMode,
|
|
163
|
+
sourceRoot: this.sourceRoot,
|
|
164
|
+
sourceDigest: '',
|
|
165
|
+
},
|
|
166
|
+
objects,
|
|
167
|
+
diagnostics: sortedDiagnostics,
|
|
168
|
+
};
|
|
169
|
+
return {
|
|
170
|
+
...catalogWithoutDigest,
|
|
171
|
+
build: {
|
|
172
|
+
...catalogWithoutDigest.build,
|
|
173
|
+
sourceDigest: this.computeSourceDigest(catalogWithoutDigest),
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
resolveIdentity(options) {
|
|
178
|
+
const annotatedKey = options.objectMetadata.key;
|
|
179
|
+
if (annotatedKey && annotatedKey.length > 0) {
|
|
180
|
+
return {
|
|
181
|
+
mode: annotatedKey.length === 1 ? GraphqlCatalogIdentityMode.Single : GraphqlCatalogIdentityMode.Composite,
|
|
182
|
+
fields: Object.freeze([...annotatedKey]),
|
|
183
|
+
origin: GraphqlCatalogOrigin.Annotated,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
if (options.physicalObject.identityFields.length > 0) {
|
|
187
|
+
return {
|
|
188
|
+
mode: options.physicalObject.identityFields.length === 1
|
|
189
|
+
? GraphqlCatalogIdentityMode.Single
|
|
190
|
+
: GraphqlCatalogIdentityMode.Composite,
|
|
191
|
+
fields: Object.freeze([...options.physicalObject.identityFields]),
|
|
192
|
+
origin: GraphqlCatalogOrigin.Inferred,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
if (options.physicalObject.kind === physical_model_1.PhysicalObjectKind.View) {
|
|
196
|
+
options.diagnostics.push({
|
|
197
|
+
severity: GraphqlCatalogDiagnosticSeverity.Error,
|
|
198
|
+
code: 'view_missing_identity',
|
|
199
|
+
message: 'Published view requires explicit identity metadata.',
|
|
200
|
+
objectId: options.physicalObject.id,
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
mode: GraphqlCatalogIdentityMode.None,
|
|
205
|
+
fields: Object.freeze([]),
|
|
206
|
+
origin: GraphqlCatalogOrigin.Inferred,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
buildObject(options) {
|
|
210
|
+
const physicalObject = options.context.physicalObject;
|
|
211
|
+
const objectMetadata = options.context.objectMetadata;
|
|
212
|
+
const fields = [...physicalObject.fields]
|
|
213
|
+
.map((field) => this.buildField({
|
|
214
|
+
objectId: physicalObject.id,
|
|
215
|
+
physicalField: field,
|
|
216
|
+
fieldMetadata: objectMetadata.fields[field.column],
|
|
217
|
+
diagnostics: options.diagnostics,
|
|
218
|
+
}))
|
|
219
|
+
.sort((left, right) => {
|
|
220
|
+
const byPublicName = left.publicName.localeCompare(right.publicName);
|
|
221
|
+
if (byPublicName !== 0) {
|
|
222
|
+
return byPublicName;
|
|
223
|
+
}
|
|
224
|
+
return left.column.localeCompare(right.column);
|
|
225
|
+
});
|
|
226
|
+
this.detectDuplicateFieldNames(physicalObject.id, fields, options.diagnostics);
|
|
227
|
+
const relations = this.buildRelations({
|
|
228
|
+
context: options.context,
|
|
229
|
+
allContexts: options.allContexts,
|
|
230
|
+
diagnostics: options.diagnostics,
|
|
231
|
+
});
|
|
232
|
+
const pagination = this.resolvePagination(objectMetadata.limit, options.defaultsLimit);
|
|
233
|
+
return {
|
|
234
|
+
id: physicalObject.id,
|
|
235
|
+
kind: physicalObject.kind,
|
|
236
|
+
readonly: true,
|
|
237
|
+
source: {
|
|
238
|
+
schemaName: physicalObject.schemaName,
|
|
239
|
+
objectName: physicalObject.objectName,
|
|
240
|
+
},
|
|
241
|
+
graphql: {
|
|
242
|
+
typeName: options.context.typeName,
|
|
243
|
+
collectionField: options.context.collectionField,
|
|
244
|
+
itemField: options.context.itemField,
|
|
245
|
+
},
|
|
246
|
+
identity: options.context.identity,
|
|
247
|
+
fields: Object.freeze(fields),
|
|
248
|
+
relations,
|
|
249
|
+
capabilities: {
|
|
250
|
+
item: options.context.identity.mode !== GraphqlCatalogIdentityMode.None,
|
|
251
|
+
collection: true,
|
|
252
|
+
filter: fields.some((field) => field.visibility === GraphqlCatalogFieldVisibility.Public && field.filterable),
|
|
253
|
+
sort: fields.some((field) => field.visibility === GraphqlCatalogFieldVisibility.Public && field.sortable),
|
|
254
|
+
pagination,
|
|
255
|
+
},
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
buildField(options) {
|
|
259
|
+
const type = this.normalizeScalar({
|
|
260
|
+
objectId: options.objectId,
|
|
261
|
+
column: options.physicalField.column,
|
|
262
|
+
nativeType: options.physicalField.nativeType,
|
|
263
|
+
diagnostics: options.diagnostics,
|
|
264
|
+
});
|
|
265
|
+
const publicName = options.fieldMetadata?.name ?? GraphqlCatalogNaming.publicFieldNameForColumn(options.physicalField.column);
|
|
266
|
+
const visibility = options.fieldMetadata?.hidden ? GraphqlCatalogFieldVisibility.Hidden : GraphqlCatalogFieldVisibility.Public;
|
|
267
|
+
const filterable = visibility === GraphqlCatalogFieldVisibility.Public && !options.fieldMetadata?.noFilter && type !== 'Json';
|
|
268
|
+
const sortable = visibility === GraphqlCatalogFieldVisibility.Public && !options.fieldMetadata?.noSort && type !== 'Json';
|
|
269
|
+
return {
|
|
270
|
+
column: options.physicalField.column,
|
|
271
|
+
publicName,
|
|
272
|
+
type,
|
|
273
|
+
nullable: options.physicalField.nullable,
|
|
274
|
+
visibility,
|
|
275
|
+
filterable,
|
|
276
|
+
sortable,
|
|
277
|
+
sensitive: options.fieldMetadata?.sensitive ?? false,
|
|
278
|
+
origin: options.fieldMetadata ? GraphqlCatalogOrigin.Annotated : GraphqlCatalogOrigin.Inferred,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
buildRelations(options) {
|
|
282
|
+
const relations = [];
|
|
283
|
+
const physicalObject = options.context.physicalObject;
|
|
284
|
+
if (physicalObject.kind === physical_model_1.PhysicalObjectKind.Table) {
|
|
285
|
+
for (const relationSeed of physicalObject.relations) {
|
|
286
|
+
const targetContext = options.allContexts.get(relationSeed.targetObjectId);
|
|
287
|
+
if (!targetContext) {
|
|
288
|
+
options.diagnostics.push({
|
|
289
|
+
severity: GraphqlCatalogDiagnosticSeverity.Error,
|
|
290
|
+
code: 'relation_target_unknown',
|
|
291
|
+
message: 'Relation target is not published in the governed catalog.',
|
|
292
|
+
objectId: physicalObject.id,
|
|
293
|
+
field: relationSeed.name,
|
|
294
|
+
});
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
relations.push({
|
|
298
|
+
name: GraphqlCatalogNaming.publicFieldNameForColumn(relationSeed.name),
|
|
299
|
+
target: relationSeed.targetObjectId,
|
|
300
|
+
cardinality: GraphqlCatalogRelationCardinality.One,
|
|
301
|
+
sourceFields: Object.freeze([...relationSeed.sourceFields]),
|
|
302
|
+
targetFields: Object.freeze([...relationSeed.targetFields]),
|
|
303
|
+
origin: GraphqlCatalogOrigin.Inferred,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
for (const relationMetadata of options.context.objectMetadata.relations) {
|
|
309
|
+
const targetContext = options.allContexts.get(relationMetadata.target);
|
|
310
|
+
if (!targetContext || targetContext.identity.mode === GraphqlCatalogIdentityMode.None) {
|
|
311
|
+
options.diagnostics.push({
|
|
312
|
+
severity: GraphqlCatalogDiagnosticSeverity.Error,
|
|
313
|
+
code: 'relation_target_unknown',
|
|
314
|
+
message: 'Relation target is not published with usable identity.',
|
|
315
|
+
objectId: physicalObject.id,
|
|
316
|
+
field: relationMetadata.name,
|
|
317
|
+
});
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
relations.push({
|
|
321
|
+
name: relationMetadata.name,
|
|
322
|
+
target: relationMetadata.target,
|
|
323
|
+
cardinality: relationMetadata.cardinality === 'to-many'
|
|
324
|
+
? GraphqlCatalogRelationCardinality.Many
|
|
325
|
+
: GraphqlCatalogRelationCardinality.One,
|
|
326
|
+
sourceFields: Object.freeze([...relationMetadata.via]),
|
|
327
|
+
targetFields: Object.freeze([...targetContext.identity.fields]),
|
|
328
|
+
origin: GraphqlCatalogOrigin.Annotated,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
relations.sort((left, right) => {
|
|
333
|
+
const byName = left.name.localeCompare(right.name);
|
|
334
|
+
if (byName !== 0) {
|
|
335
|
+
return byName;
|
|
336
|
+
}
|
|
337
|
+
return left.target.localeCompare(right.target);
|
|
338
|
+
});
|
|
339
|
+
return Object.freeze(relations);
|
|
340
|
+
}
|
|
341
|
+
resolvePagination(objectLimit, defaultsLimit) {
|
|
342
|
+
const effectiveLimit = objectLimit ?? defaultsLimit ?? { defaultValue: 50, maxValue: 200 };
|
|
343
|
+
return {
|
|
344
|
+
mode: GraphqlCatalogPaginationMode.Offset,
|
|
345
|
+
defaultLimit: effectiveLimit.defaultValue,
|
|
346
|
+
maxLimit: effectiveLimit.maxValue,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
normalizeScalar(options) {
|
|
350
|
+
const normalized = options.nativeType.trim().toLowerCase();
|
|
351
|
+
if (normalized.startsWith('bigint')) {
|
|
352
|
+
return 'Long';
|
|
353
|
+
}
|
|
354
|
+
if (normalized.startsWith('int') || normalized.startsWith('smallint') || normalized.startsWith('tinyint')) {
|
|
355
|
+
return 'Int';
|
|
356
|
+
}
|
|
357
|
+
if (normalized.startsWith('decimal') ||
|
|
358
|
+
normalized.startsWith('numeric') ||
|
|
359
|
+
normalized.startsWith('money') ||
|
|
360
|
+
normalized.startsWith('smallmoney')) {
|
|
361
|
+
return 'Decimal';
|
|
362
|
+
}
|
|
363
|
+
if (normalized.startsWith('float') || normalized.startsWith('real')) {
|
|
364
|
+
return 'Float';
|
|
365
|
+
}
|
|
366
|
+
if (normalized.startsWith('bit')) {
|
|
367
|
+
return 'Boolean';
|
|
368
|
+
}
|
|
369
|
+
if (normalized.startsWith('date') && !normalized.startsWith('datetime')) {
|
|
370
|
+
return 'Date';
|
|
371
|
+
}
|
|
372
|
+
if (normalized.startsWith('datetime') ||
|
|
373
|
+
normalized.startsWith('smalldatetime') ||
|
|
374
|
+
normalized.startsWith('datetimeoffset')) {
|
|
375
|
+
return 'DateTime';
|
|
376
|
+
}
|
|
377
|
+
if (normalized.startsWith('uniqueidentifier')) {
|
|
378
|
+
return 'Uuid';
|
|
379
|
+
}
|
|
380
|
+
if (normalized.startsWith('json')) {
|
|
381
|
+
return 'Json';
|
|
382
|
+
}
|
|
383
|
+
if (normalized.startsWith('char') ||
|
|
384
|
+
normalized.startsWith('nchar') ||
|
|
385
|
+
normalized.startsWith('varchar') ||
|
|
386
|
+
normalized.startsWith('nvarchar') ||
|
|
387
|
+
normalized.startsWith('text') ||
|
|
388
|
+
normalized.startsWith('ntext') ||
|
|
389
|
+
normalized.startsWith('xml')) {
|
|
390
|
+
return 'String';
|
|
391
|
+
}
|
|
392
|
+
options.diagnostics.push({
|
|
393
|
+
severity: GraphqlCatalogDiagnosticSeverity.Warning,
|
|
394
|
+
code: 'unsupported_scalar',
|
|
395
|
+
message: `Native type ${options.nativeType} is not mapped explicitly in the v1 scalar domain.`,
|
|
396
|
+
objectId: options.objectId,
|
|
397
|
+
field: options.column,
|
|
398
|
+
});
|
|
399
|
+
return 'String';
|
|
400
|
+
}
|
|
401
|
+
detectDuplicateFieldNames(objectId, fields, diagnostics) {
|
|
402
|
+
const counts = new Map();
|
|
403
|
+
for (const field of fields) {
|
|
404
|
+
counts.set(field.publicName, (counts.get(field.publicName) ?? 0) + 1);
|
|
405
|
+
}
|
|
406
|
+
const duplicates = Array.from(counts.entries())
|
|
407
|
+
.filter(([, count]) => count > 1)
|
|
408
|
+
.map(([publicName]) => publicName)
|
|
409
|
+
.sort((left, right) => left.localeCompare(right));
|
|
410
|
+
for (const publicName of duplicates) {
|
|
411
|
+
diagnostics.push({
|
|
412
|
+
severity: GraphqlCatalogDiagnosticSeverity.Error,
|
|
413
|
+
code: 'duplicate_public_name',
|
|
414
|
+
message: 'Multiple fields derive the same public GraphQL name.',
|
|
415
|
+
objectId,
|
|
416
|
+
field: publicName,
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
detectDuplicateObjectNames(objects, diagnostics) {
|
|
421
|
+
const typeCounts = new Map();
|
|
422
|
+
const itemCounts = new Map();
|
|
423
|
+
const collectionCounts = new Map();
|
|
424
|
+
for (const object of objects) {
|
|
425
|
+
typeCounts.set(object.graphql.typeName, (typeCounts.get(object.graphql.typeName) ?? 0) + 1);
|
|
426
|
+
collectionCounts.set(object.graphql.collectionField, (collectionCounts.get(object.graphql.collectionField) ?? 0) + 1);
|
|
427
|
+
if (object.graphql.itemField) {
|
|
428
|
+
itemCounts.set(object.graphql.itemField, (itemCounts.get(object.graphql.itemField) ?? 0) + 1);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
for (const object of objects) {
|
|
432
|
+
if ((typeCounts.get(object.graphql.typeName) ?? 0) > 1) {
|
|
433
|
+
diagnostics.push({
|
|
434
|
+
severity: GraphqlCatalogDiagnosticSeverity.Error,
|
|
435
|
+
code: 'duplicate_public_name',
|
|
436
|
+
message: 'Multiple objects derive the same GraphQL type name.',
|
|
437
|
+
objectId: object.id,
|
|
438
|
+
field: object.graphql.typeName,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
if ((collectionCounts.get(object.graphql.collectionField) ?? 0) > 1) {
|
|
442
|
+
diagnostics.push({
|
|
443
|
+
severity: GraphqlCatalogDiagnosticSeverity.Error,
|
|
444
|
+
code: 'duplicate_public_name',
|
|
445
|
+
message: 'Multiple objects derive the same collection field name.',
|
|
446
|
+
objectId: object.id,
|
|
447
|
+
field: object.graphql.collectionField,
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
if (object.graphql.itemField && (itemCounts.get(object.graphql.itemField) ?? 0) > 1) {
|
|
451
|
+
diagnostics.push({
|
|
452
|
+
severity: GraphqlCatalogDiagnosticSeverity.Error,
|
|
453
|
+
code: 'duplicate_public_name',
|
|
454
|
+
message: 'Multiple objects derive the same item field name.',
|
|
455
|
+
objectId: object.id,
|
|
456
|
+
field: object.graphql.itemField,
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
sortDiagnostics(diagnostics) {
|
|
462
|
+
const severityRank = {
|
|
463
|
+
[GraphqlCatalogDiagnosticSeverity.Error]: 0,
|
|
464
|
+
[GraphqlCatalogDiagnosticSeverity.Warning]: 1,
|
|
465
|
+
[GraphqlCatalogDiagnosticSeverity.Info]: 2,
|
|
466
|
+
};
|
|
467
|
+
return Object.freeze([...diagnostics].sort((left, right) => {
|
|
468
|
+
const bySeverity = severityRank[left.severity] - severityRank[right.severity];
|
|
469
|
+
if (bySeverity !== 0) {
|
|
470
|
+
return bySeverity;
|
|
471
|
+
}
|
|
472
|
+
const byCode = left.code.localeCompare(right.code);
|
|
473
|
+
if (byCode !== 0) {
|
|
474
|
+
return byCode;
|
|
475
|
+
}
|
|
476
|
+
const byObjectId = (left.objectId ?? '').localeCompare(right.objectId ?? '');
|
|
477
|
+
if (byObjectId !== 0) {
|
|
478
|
+
return byObjectId;
|
|
479
|
+
}
|
|
480
|
+
const byField = (left.field ?? '').localeCompare(right.field ?? '');
|
|
481
|
+
if (byField !== 0) {
|
|
482
|
+
return byField;
|
|
483
|
+
}
|
|
484
|
+
return left.message.localeCompare(right.message);
|
|
485
|
+
}));
|
|
486
|
+
}
|
|
487
|
+
computeSourceDigest(catalog) {
|
|
488
|
+
const payload = {
|
|
489
|
+
engine: this.engine,
|
|
490
|
+
providerVersion: this.providerVersion,
|
|
491
|
+
sourceRoot: this.sourceRoot,
|
|
492
|
+
buildMode: this.buildMode,
|
|
493
|
+
objects: catalog.objects.map((object) => this.objectDigestMap(object)),
|
|
494
|
+
};
|
|
495
|
+
const canonicalJson = JSON.stringify(this.canonicalize(payload));
|
|
496
|
+
return (0, node_crypto_1.createHash)('sha256').update(canonicalJson).digest('hex');
|
|
497
|
+
}
|
|
498
|
+
objectDigestMap(object) {
|
|
499
|
+
return {
|
|
500
|
+
id: object.id,
|
|
501
|
+
kind: object.kind,
|
|
502
|
+
source: {
|
|
503
|
+
schemaName: object.source.schemaName,
|
|
504
|
+
objectName: object.source.objectName,
|
|
505
|
+
sourceFile: object.source.sourceFile,
|
|
506
|
+
providerObjectId: object.source.providerObjectId,
|
|
507
|
+
},
|
|
508
|
+
graphql: {
|
|
509
|
+
typeName: object.graphql.typeName,
|
|
510
|
+
collectionField: object.graphql.collectionField,
|
|
511
|
+
itemField: object.graphql.itemField,
|
|
512
|
+
},
|
|
513
|
+
identity: {
|
|
514
|
+
mode: object.identity.mode,
|
|
515
|
+
fields: object.identity.fields,
|
|
516
|
+
origin: object.identity.origin,
|
|
517
|
+
},
|
|
518
|
+
fields: object.fields.map((field) => ({
|
|
519
|
+
column: field.column,
|
|
520
|
+
publicName: field.publicName,
|
|
521
|
+
type: field.type,
|
|
522
|
+
nullable: field.nullable,
|
|
523
|
+
visibility: field.visibility,
|
|
524
|
+
filterable: field.filterable,
|
|
525
|
+
sortable: field.sortable,
|
|
526
|
+
sensitive: field.sensitive,
|
|
527
|
+
origin: field.origin,
|
|
528
|
+
})),
|
|
529
|
+
relations: object.relations.map((relation) => ({
|
|
530
|
+
name: relation.name,
|
|
531
|
+
target: relation.target,
|
|
532
|
+
cardinality: relation.cardinality,
|
|
533
|
+
sourceFields: relation.sourceFields,
|
|
534
|
+
targetFields: relation.targetFields,
|
|
535
|
+
origin: relation.origin,
|
|
536
|
+
})),
|
|
537
|
+
capabilities: {
|
|
538
|
+
item: object.capabilities.item,
|
|
539
|
+
collection: object.capabilities.collection,
|
|
540
|
+
filter: object.capabilities.filter,
|
|
541
|
+
sort: object.capabilities.sort,
|
|
542
|
+
pagination: {
|
|
543
|
+
mode: object.capabilities.pagination.mode,
|
|
544
|
+
defaultLimit: object.capabilities.pagination.defaultLimit,
|
|
545
|
+
maxLimit: object.capabilities.pagination.maxLimit,
|
|
546
|
+
},
|
|
547
|
+
},
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
canonicalize(value) {
|
|
551
|
+
if (Array.isArray(value)) {
|
|
552
|
+
return value.map((entry) => this.canonicalize(entry));
|
|
553
|
+
}
|
|
554
|
+
if (value && typeof value === 'object') {
|
|
555
|
+
const sorted = {};
|
|
556
|
+
for (const key of Object.keys(value).sort((left, right) => left.localeCompare(right))) {
|
|
557
|
+
sorted[key] = this.canonicalize(value[key]);
|
|
558
|
+
}
|
|
559
|
+
return sorted;
|
|
560
|
+
}
|
|
561
|
+
return value;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
exports.GraphqlCatalogBuilder = GraphqlCatalogBuilder;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type PhysicalCatalog } from '../sqlserver/physical_model';
|
|
2
|
+
export declare enum GraphqlMetadataSeverity {
|
|
3
|
+
Error = "error",
|
|
4
|
+
Warning = "warning"
|
|
5
|
+
}
|
|
6
|
+
export interface GraphqlMetadataDiagnostic {
|
|
7
|
+
readonly severity: GraphqlMetadataSeverity;
|
|
8
|
+
readonly code: string;
|
|
9
|
+
readonly message: string;
|
|
10
|
+
readonly objectId?: string;
|
|
11
|
+
readonly field?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface GraphqlMetadataLimit {
|
|
14
|
+
readonly defaultValue: number;
|
|
15
|
+
readonly maxValue: number;
|
|
16
|
+
}
|
|
17
|
+
export interface GraphqlFieldMetadata {
|
|
18
|
+
readonly hidden: boolean;
|
|
19
|
+
readonly sensitive: boolean;
|
|
20
|
+
readonly noFilter: boolean;
|
|
21
|
+
readonly noSort: boolean;
|
|
22
|
+
readonly name?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface GraphqlRelationMetadata {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly cardinality: string;
|
|
27
|
+
readonly target: string;
|
|
28
|
+
readonly via: readonly string[];
|
|
29
|
+
}
|
|
30
|
+
export interface GraphqlObjectMetadata {
|
|
31
|
+
readonly publish: true;
|
|
32
|
+
readonly name?: string;
|
|
33
|
+
readonly key?: readonly string[];
|
|
34
|
+
readonly fields: Readonly<Record<string, GraphqlFieldMetadata>>;
|
|
35
|
+
readonly relations: readonly GraphqlRelationMetadata[];
|
|
36
|
+
readonly limit?: GraphqlMetadataLimit;
|
|
37
|
+
}
|
|
38
|
+
export interface GraphqlMetadataFile {
|
|
39
|
+
readonly schema?: string;
|
|
40
|
+
readonly version: number;
|
|
41
|
+
readonly defaultsLimit?: GraphqlMetadataLimit;
|
|
42
|
+
readonly objects: Readonly<Record<string, GraphqlObjectMetadata>>;
|
|
43
|
+
}
|
|
44
|
+
export interface GraphqlMetadataParseResult {
|
|
45
|
+
readonly metadata: GraphqlMetadataFile | null;
|
|
46
|
+
readonly diagnostics: readonly GraphqlMetadataDiagnostic[];
|
|
47
|
+
}
|
|
48
|
+
export declare class GraphqlMetadataParser {
|
|
49
|
+
parse(options: {
|
|
50
|
+
rawJsonc: string;
|
|
51
|
+
physicalCatalog: PhysicalCatalog;
|
|
52
|
+
}): GraphqlMetadataParseResult;
|
|
53
|
+
}
|