@macss/modular-api 0.4.5 → 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.
Files changed (49) hide show
  1. package/README.md +70 -8
  2. package/dist/core/body_parser_error_handler.d.ts +15 -0
  3. package/dist/core/body_parser_error_handler.js +35 -0
  4. package/dist/core/logger/logger.d.ts +1 -0
  5. package/dist/core/logger/logger.js +1 -0
  6. package/dist/core/logger/logging_middleware.js +11 -0
  7. package/dist/core/modular_api.d.ts +17 -0
  8. package/dist/core/modular_api.js +107 -43
  9. package/dist/core/official_plugins.d.ts +35 -0
  10. package/dist/core/official_plugins.js +213 -0
  11. package/dist/core/plugin.d.ts +163 -0
  12. package/dist/core/plugin.js +304 -0
  13. package/dist/core/request_pipeline_audit.d.ts +15 -0
  14. package/dist/core/request_pipeline_audit.js +29 -0
  15. package/dist/core/schema/field.d.ts +2 -1
  16. package/dist/core/schema/field.js +4 -0
  17. package/dist/core/unhandled_request_error_handler.d.ts +2 -0
  18. package/dist/core/unhandled_request_error_handler.js +17 -0
  19. package/dist/core/usecase.js +1 -0
  20. package/dist/core/usecase_handler.js +3 -2
  21. package/dist/graphql/catalog/graphql_catalog_builder.d.ts +149 -0
  22. package/dist/graphql/catalog/graphql_catalog_builder.js +564 -0
  23. package/dist/graphql/metadata/graphql_metadata_parser.d.ts +53 -0
  24. package/dist/graphql/metadata/graphql_metadata_parser.js +373 -0
  25. package/dist/graphql/read/sql_read_contract.d.ts +155 -0
  26. package/dist/graphql/read/sql_read_contract.js +194 -0
  27. package/dist/graphql/read/sqlserver_read_compiler.d.ts +58 -0
  28. package/dist/graphql/read/sqlserver_read_compiler.js +279 -0
  29. package/dist/graphql/runtime/graphql_artifacts.d.ts +43 -0
  30. package/dist/graphql/runtime/graphql_artifacts.js +512 -0
  31. package/dist/graphql/runtime/graphql_runtime_options.d.ts +52 -0
  32. package/dist/graphql/runtime/graphql_runtime_options.js +60 -0
  33. package/dist/graphql/runtime/graphql_runtime_plugin.d.ts +18 -0
  34. package/dist/graphql/runtime/graphql_runtime_plugin.js +946 -0
  35. package/dist/graphql/schema/graphql_schema_sdl_generator.d.ts +17 -0
  36. package/dist/graphql/schema/graphql_schema_sdl_generator.js +221 -0
  37. package/dist/graphql/sqlserver/physical_model.d.ts +28 -0
  38. package/dist/graphql/sqlserver/physical_model.js +8 -0
  39. package/dist/graphql/sqlserver/sql_server_connection_settings.d.ts +15 -0
  40. package/dist/graphql/sqlserver/sql_server_connection_settings.js +28 -0
  41. package/dist/graphql/sqlserver/sql_server_metadata_reader.d.ts +39 -0
  42. package/dist/graphql/sqlserver/sql_server_metadata_reader.js +294 -0
  43. package/dist/index.d.ts +17 -0
  44. package/dist/index.js +58 -1
  45. package/dist/openapi/swagger_docs.d.ts +11 -6
  46. package/dist/openapi/swagger_docs.js +16 -193
  47. package/package.json +9 -6
  48. package/dist/core/usecase_test_handler.d.ts +0 -27
  49. package/dist/core/usecase_test_handler.js +0 -60
@@ -0,0 +1,512 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphqlArtifactCompiler = exports.GraphqlArtifactLoadError = exports.GraphqlArtifactCompileError = exports.GraphqlArtifactBundle = void 0;
4
+ exports.tryLoadGraphqlCatalogArtifacts = tryLoadGraphqlCatalogArtifacts;
5
+ exports.resolveCatalogFromArtifactsOrSource = resolveCatalogFromArtifactsOrSource;
6
+ const promises_1 = require("node:fs/promises");
7
+ const node_path_1 = require("node:path");
8
+ const graphql_catalog_builder_1 = require("../catalog/graphql_catalog_builder");
9
+ const graphql_schema_sdl_generator_1 = require("../schema/graphql_schema_sdl_generator");
10
+ const physical_model_1 = require("../sqlserver/physical_model");
11
+ const CATALOG_FILE_NAME = 'catalog.json';
12
+ const CATALOG_LOCK_FILE_NAME = 'catalog.lock';
13
+ const DIAGNOSTICS_FILE_NAME = 'diagnostics.json';
14
+ const SCHEMA_FILE_NAME = 'schema.graphql';
15
+ const DIAGNOSTIC_SEVERITY_ORDER = {
16
+ [graphql_catalog_builder_1.GraphqlCatalogDiagnosticSeverity.Error]: 0,
17
+ [graphql_catalog_builder_1.GraphqlCatalogDiagnosticSeverity.Warning]: 1,
18
+ [graphql_catalog_builder_1.GraphqlCatalogDiagnosticSeverity.Info]: 2,
19
+ };
20
+ class GraphqlArtifactBundle {
21
+ catalogJson;
22
+ catalogLockJson;
23
+ diagnosticsJson;
24
+ schemaGraphql;
25
+ constructor(options) {
26
+ this.catalogJson = options.catalogJson;
27
+ this.catalogLockJson = options.catalogLockJson;
28
+ this.diagnosticsJson = options.diagnosticsJson;
29
+ this.schemaGraphql = options.schemaGraphql;
30
+ }
31
+ async writeToDirectory(outputDirectory) {
32
+ await (0, promises_1.mkdir)(outputDirectory, { recursive: true });
33
+ await (0, promises_1.writeFile)(artifactPath(outputDirectory, CATALOG_FILE_NAME), this.catalogJson, 'utf8');
34
+ await (0, promises_1.writeFile)(artifactPath(outputDirectory, CATALOG_LOCK_FILE_NAME), this.catalogLockJson, 'utf8');
35
+ await (0, promises_1.writeFile)(artifactPath(outputDirectory, DIAGNOSTICS_FILE_NAME), this.diagnosticsJson, 'utf8');
36
+ await (0, promises_1.writeFile)(artifactPath(outputDirectory, SCHEMA_FILE_NAME), this.schemaGraphql, 'utf8');
37
+ }
38
+ }
39
+ exports.GraphqlArtifactBundle = GraphqlArtifactBundle;
40
+ class GraphqlArtifactCompileError extends Error {
41
+ bundle;
42
+ constructor(options) {
43
+ super(options.message);
44
+ this.name = 'GraphqlArtifactCompileError';
45
+ this.bundle = options.bundle;
46
+ }
47
+ }
48
+ exports.GraphqlArtifactCompileError = GraphqlArtifactCompileError;
49
+ class GraphqlArtifactLoadError extends Error {
50
+ constructor(message) {
51
+ super(message);
52
+ this.name = 'GraphqlArtifactLoadError';
53
+ }
54
+ }
55
+ exports.GraphqlArtifactLoadError = GraphqlArtifactLoadError;
56
+ class GraphqlArtifactCompiler {
57
+ catalogFactory;
58
+ sdlFactory;
59
+ constructor(options) {
60
+ this.catalogFactory = options.catalogFactory;
61
+ this.sdlFactory = options.sdlFactory ?? ((catalog) => new graphql_schema_sdl_generator_1.GraphqlSchemaSdlGenerator().generate(catalog));
62
+ }
63
+ async compile() {
64
+ const rawCatalog = await this.catalogFactory();
65
+ const catalog = canonicalCatalog(rawCatalog);
66
+ const bundle = new GraphqlArtifactBundle({
67
+ catalogJson: prettyJson(catalogToJson(catalog)),
68
+ catalogLockJson: prettyJson(catalogLockToJson(catalog)),
69
+ diagnosticsJson: prettyJson(diagnosticsToJson(catalog.diagnostics)),
70
+ schemaGraphql: normalizedSchema(this.sdlFactory(catalog)),
71
+ });
72
+ const blockingDiagnostics = catalog.diagnostics.filter((diagnostic) => diagnostic.severity === graphql_catalog_builder_1.GraphqlCatalogDiagnosticSeverity.Error);
73
+ if (blockingDiagnostics.length > 0) {
74
+ throw new GraphqlArtifactCompileError({
75
+ message: 'GraphQL artifact compilation failed because blocking diagnostics exist.',
76
+ bundle,
77
+ });
78
+ }
79
+ return bundle;
80
+ }
81
+ async writeToDirectory(outputDirectory) {
82
+ try {
83
+ const bundle = await this.compile();
84
+ await bundle.writeToDirectory(outputDirectory);
85
+ return bundle;
86
+ }
87
+ catch (error) {
88
+ if (error instanceof GraphqlArtifactCompileError) {
89
+ await error.bundle.writeToDirectory(outputDirectory);
90
+ }
91
+ throw error;
92
+ }
93
+ }
94
+ }
95
+ exports.GraphqlArtifactCompiler = GraphqlArtifactCompiler;
96
+ async function tryLoadGraphqlCatalogArtifacts(options) {
97
+ const catalogPath = artifactPath(options.artifactDirectory, CATALOG_FILE_NAME);
98
+ const lockPath = artifactPath(options.artifactDirectory, CATALOG_LOCK_FILE_NAME);
99
+ if (!(await fileExists(catalogPath)) || !(await fileExists(lockPath))) {
100
+ return undefined;
101
+ }
102
+ const lockJson = parseJsonObject(await (0, promises_1.readFile)(lockPath, 'utf8'), 'catalog.lock must be a JSON object.');
103
+ const lock = catalogLockFromJson(lockJson);
104
+ if (lock.sourceDigest !== options.currentSourceDigest) {
105
+ return undefined;
106
+ }
107
+ const catalogJson = parseJsonObject(await (0, promises_1.readFile)(catalogPath, 'utf8'), 'catalog.json must be a JSON object.');
108
+ const catalog = canonicalCatalog(catalogFromJson(catalogJson));
109
+ if (catalog.catalogVersion !== lock.catalogVersion ||
110
+ catalog.build.sourceDigest !== lock.sourceDigest ||
111
+ catalog.provider.providerVersion !== lock.providerVersion) {
112
+ return undefined;
113
+ }
114
+ return catalog;
115
+ }
116
+ async function resolveCatalogFromArtifactsOrSource(options) {
117
+ const artifactDirectory = options.graphql.artifactDirectory;
118
+ const sourceDigestFactory = options.graphql.sourceDigestFactory;
119
+ if (artifactDirectory && sourceDigestFactory) {
120
+ try {
121
+ const currentSourceDigest = await Promise.resolve(sourceDigestFactory());
122
+ const prebuiltCatalog = await tryLoadGraphqlCatalogArtifacts({
123
+ artifactDirectory,
124
+ currentSourceDigest,
125
+ });
126
+ if (prebuiltCatalog) {
127
+ return prebuiltCatalog;
128
+ }
129
+ }
130
+ catch (error) {
131
+ throw new GraphqlArtifactLoadError(String(error instanceof Error ? error.message : error));
132
+ }
133
+ }
134
+ return options.graphql.catalogFactory();
135
+ }
136
+ function artifactPath(directory, fileName) {
137
+ return (0, node_path_1.join)(directory, fileName);
138
+ }
139
+ async function fileExists(filePath) {
140
+ try {
141
+ await (0, promises_1.access)(filePath);
142
+ return true;
143
+ }
144
+ catch {
145
+ return false;
146
+ }
147
+ }
148
+ function prettyJson(payload) {
149
+ return `${JSON.stringify(canonicalize(payload), undefined, 2)}\n`;
150
+ }
151
+ function normalizedSchema(schema) {
152
+ return schema.endsWith('\n') ? schema : `${schema}\n`;
153
+ }
154
+ function canonicalCatalog(catalog) {
155
+ return {
156
+ catalogVersion: catalog.catalogVersion,
157
+ provider: catalog.provider,
158
+ build: catalog.build,
159
+ objects: [...catalog.objects].map(canonicalObject).sort((left, right) => left.id.localeCompare(right.id)),
160
+ diagnostics: [...catalog.diagnostics].sort(compareDiagnostics),
161
+ };
162
+ }
163
+ function canonicalObject(object) {
164
+ return {
165
+ ...object,
166
+ fields: [...object.fields].sort((left, right) => {
167
+ const publicName = left.publicName.localeCompare(right.publicName);
168
+ return publicName !== 0 ? publicName : left.column.localeCompare(right.column);
169
+ }),
170
+ relations: [...object.relations].sort((left, right) => {
171
+ const name = left.name.localeCompare(right.name);
172
+ return name !== 0 ? name : left.target.localeCompare(right.target);
173
+ }),
174
+ };
175
+ }
176
+ function compareDiagnostics(left, right) {
177
+ const severity = DIAGNOSTIC_SEVERITY_ORDER[left.severity] - DIAGNOSTIC_SEVERITY_ORDER[right.severity];
178
+ if (severity !== 0) {
179
+ return severity;
180
+ }
181
+ const code = left.code.localeCompare(right.code);
182
+ if (code !== 0) {
183
+ return code;
184
+ }
185
+ const objectId = (left.objectId ?? '').localeCompare(right.objectId ?? '');
186
+ if (objectId !== 0) {
187
+ return objectId;
188
+ }
189
+ const field = (left.field ?? '').localeCompare(right.field ?? '');
190
+ if (field !== 0) {
191
+ return field;
192
+ }
193
+ return left.message.localeCompare(right.message);
194
+ }
195
+ function catalogToJson(catalog) {
196
+ return {
197
+ catalogVersion: catalog.catalogVersion,
198
+ provider: {
199
+ kind: catalog.provider.kind,
200
+ engine: catalog.provider.engine,
201
+ providerVersion: catalog.provider.providerVersion,
202
+ },
203
+ build: {
204
+ mode: catalog.build.mode,
205
+ sourceRoot: catalog.build.sourceRoot,
206
+ sourceDigest: catalog.build.sourceDigest,
207
+ },
208
+ objects: catalog.objects.map((object) => ({
209
+ id: object.id,
210
+ kind: object.kind,
211
+ readonly: object.readonly,
212
+ source: {
213
+ schemaName: object.source.schemaName,
214
+ objectName: object.source.objectName,
215
+ sourceFile: object.source.sourceFile ?? null,
216
+ providerObjectId: object.source.providerObjectId ?? null,
217
+ },
218
+ graphql: {
219
+ typeName: object.graphql.typeName,
220
+ collectionField: object.graphql.collectionField,
221
+ itemField: object.graphql.itemField ?? null,
222
+ },
223
+ identity: {
224
+ mode: object.identity.mode,
225
+ fields: [...object.identity.fields],
226
+ origin: object.identity.origin,
227
+ },
228
+ fields: object.fields.map((field) => ({
229
+ column: field.column,
230
+ publicName: field.publicName,
231
+ type: field.type,
232
+ nullable: field.nullable,
233
+ visibility: field.visibility,
234
+ filterable: field.filterable,
235
+ sortable: field.sortable,
236
+ sensitive: field.sensitive,
237
+ origin: field.origin,
238
+ })),
239
+ relations: object.relations.map((relation) => ({
240
+ name: relation.name,
241
+ target: relation.target,
242
+ cardinality: relation.cardinality,
243
+ sourceFields: [...relation.sourceFields],
244
+ targetFields: [...relation.targetFields],
245
+ origin: relation.origin,
246
+ })),
247
+ capabilities: {
248
+ item: object.capabilities.item,
249
+ collection: object.capabilities.collection,
250
+ filter: object.capabilities.filter,
251
+ sort: object.capabilities.sort,
252
+ pagination: {
253
+ mode: object.capabilities.pagination.mode,
254
+ defaultLimit: object.capabilities.pagination.defaultLimit,
255
+ maxLimit: object.capabilities.pagination.maxLimit,
256
+ },
257
+ },
258
+ })),
259
+ diagnostics: diagnosticsToJson(catalog.diagnostics),
260
+ };
261
+ }
262
+ function catalogLockToJson(catalog) {
263
+ return {
264
+ catalogVersion: catalog.catalogVersion,
265
+ sourceDigest: catalog.build.sourceDigest,
266
+ providerVersion: catalog.provider.providerVersion,
267
+ };
268
+ }
269
+ function diagnosticsToJson(diagnostics) {
270
+ return diagnostics.map((diagnostic) => ({
271
+ severity: diagnostic.severity,
272
+ code: diagnostic.code,
273
+ message: diagnostic.message,
274
+ objectId: diagnostic.objectId ?? null,
275
+ field: diagnostic.field ?? null,
276
+ }));
277
+ }
278
+ function catalogFromJson(json) {
279
+ const providerJson = requireObject(json.provider, 'catalog.json provider must be an object.');
280
+ const buildJson = requireObject(json.build, 'catalog.json build must be an object.');
281
+ const objectsJson = requireArray(json.objects, 'catalog.json objects must be an array.');
282
+ const diagnosticsJson = Array.isArray(json.diagnostics) ? json.diagnostics : [];
283
+ return {
284
+ catalogVersion: requireString(json.catalogVersion, 'catalog.json catalogVersion must be a string.'),
285
+ provider: {
286
+ kind: requireString(providerJson.kind, 'catalog.json provider.kind must be a string.'),
287
+ engine: requireString(providerJson.engine, 'catalog.json provider.engine must be a string.'),
288
+ providerVersion: requireString(providerJson.providerVersion, 'catalog.json provider.providerVersion must be a string.'),
289
+ },
290
+ build: {
291
+ mode: requireBuildMode(buildJson.mode),
292
+ sourceRoot: requireString(buildJson.sourceRoot, 'catalog.json build.sourceRoot must be a string.'),
293
+ sourceDigest: requireString(buildJson.sourceDigest, 'catalog.json build.sourceDigest must be a string.'),
294
+ },
295
+ objects: objectsJson.map((objectJson) => objectFromJson(requireObject(objectJson, 'catalog.json object must be an object.'))),
296
+ diagnostics: diagnosticsJson.map((diagnosticJson) => diagnosticFromJson(requireObject(diagnosticJson, 'catalog.json diagnostic must be an object.'))),
297
+ };
298
+ }
299
+ function catalogLockFromJson(json) {
300
+ return {
301
+ catalogVersion: requireString(json.catalogVersion, 'catalog.lock catalogVersion must be a string.'),
302
+ sourceDigest: requireString(json.sourceDigest, 'catalog.lock sourceDigest must be a string.'),
303
+ providerVersion: requireString(json.providerVersion, 'catalog.lock providerVersion must be a string.'),
304
+ };
305
+ }
306
+ function objectFromJson(json) {
307
+ const sourceJson = requireObject(json.source, 'catalog.json object.source must be an object.');
308
+ const graphqlJson = requireObject(json.graphql, 'catalog.json object.graphql must be an object.');
309
+ const identityJson = requireObject(json.identity, 'catalog.json object.identity must be an object.');
310
+ const capabilitiesJson = requireObject(json.capabilities, 'catalog.json object.capabilities must be an object.');
311
+ const paginationJson = requireObject(capabilitiesJson.pagination, 'catalog.json object.capabilities.pagination must be an object.');
312
+ return {
313
+ id: requireString(json.id, 'catalog.json object.id must be a string.'),
314
+ kind: requirePhysicalObjectKind(json.kind),
315
+ readonly: requireBoolean(json.readonly, 'catalog.json object.readonly must be a boolean.'),
316
+ source: {
317
+ schemaName: requireString(sourceJson.schemaName, 'catalog.json object.source.schemaName must be a string.'),
318
+ objectName: requireString(sourceJson.objectName, 'catalog.json object.source.objectName must be a string.'),
319
+ sourceFile: nullableString(sourceJson.sourceFile),
320
+ providerObjectId: nullableString(sourceJson.providerObjectId),
321
+ },
322
+ graphql: {
323
+ typeName: requireString(graphqlJson.typeName, 'catalog.json object.graphql.typeName must be a string.'),
324
+ collectionField: requireString(graphqlJson.collectionField, 'catalog.json object.graphql.collectionField must be a string.'),
325
+ itemField: nullableString(graphqlJson.itemField),
326
+ },
327
+ identity: {
328
+ mode: requireIdentityMode(identityJson.mode),
329
+ fields: requireStringArray(identityJson.fields, 'catalog.json object.identity.fields must be a string array.'),
330
+ origin: requireOrigin(identityJson.origin),
331
+ },
332
+ fields: requireArray(json.fields, 'catalog.json object.fields must be an array.').map((fieldJson) => {
333
+ const field = requireObject(fieldJson, 'catalog.json field must be an object.');
334
+ return {
335
+ column: requireString(field.column, 'catalog.json field.column must be a string.'),
336
+ publicName: requireString(field.publicName, 'catalog.json field.publicName must be a string.'),
337
+ type: requireString(field.type, 'catalog.json field.type must be a string.'),
338
+ nullable: requireBoolean(field.nullable, 'catalog.json field.nullable must be a boolean.'),
339
+ visibility: requireFieldVisibility(field.visibility),
340
+ filterable: requireBoolean(field.filterable, 'catalog.json field.filterable must be a boolean.'),
341
+ sortable: requireBoolean(field.sortable, 'catalog.json field.sortable must be a boolean.'),
342
+ sensitive: requireBoolean(field.sensitive, 'catalog.json field.sensitive must be a boolean.'),
343
+ origin: requireOrigin(field.origin),
344
+ };
345
+ }),
346
+ relations: requireArray(json.relations, 'catalog.json object.relations must be an array.').map((relationJson) => {
347
+ const relation = requireObject(relationJson, 'catalog.json relation must be an object.');
348
+ return {
349
+ name: requireString(relation.name, 'catalog.json relation.name must be a string.'),
350
+ target: requireString(relation.target, 'catalog.json relation.target must be a string.'),
351
+ cardinality: requireRelationCardinality(relation.cardinality),
352
+ sourceFields: requireStringArray(relation.sourceFields, 'catalog.json relation.sourceFields must be a string array.'),
353
+ targetFields: requireStringArray(relation.targetFields, 'catalog.json relation.targetFields must be a string array.'),
354
+ origin: requireOrigin(relation.origin),
355
+ };
356
+ }),
357
+ capabilities: {
358
+ item: requireBoolean(capabilitiesJson.item, 'catalog.json capabilities.item must be a boolean.'),
359
+ collection: requireBoolean(capabilitiesJson.collection, 'catalog.json capabilities.collection must be a boolean.'),
360
+ filter: requireBoolean(capabilitiesJson.filter, 'catalog.json capabilities.filter must be a boolean.'),
361
+ sort: requireBoolean(capabilitiesJson.sort, 'catalog.json capabilities.sort must be a boolean.'),
362
+ pagination: {
363
+ mode: requirePaginationMode(paginationJson.mode),
364
+ defaultLimit: requireNumber(paginationJson.defaultLimit, 'catalog.json pagination.defaultLimit must be a number.'),
365
+ maxLimit: requireNumber(paginationJson.maxLimit, 'catalog.json pagination.maxLimit must be a number.'),
366
+ },
367
+ },
368
+ };
369
+ }
370
+ function diagnosticFromJson(json) {
371
+ return {
372
+ severity: requireDiagnosticSeverity(json.severity),
373
+ code: requireString(json.code, 'catalog.json diagnostic.code must be a string.'),
374
+ message: requireString(json.message, 'catalog.json diagnostic.message must be a string.'),
375
+ objectId: nullableString(json.objectId),
376
+ field: nullableString(json.field),
377
+ };
378
+ }
379
+ function parseJsonObject(text, errorMessage) {
380
+ let decoded;
381
+ try {
382
+ decoded = JSON.parse(text);
383
+ }
384
+ catch (error) {
385
+ throw new GraphqlArtifactLoadError(String(error instanceof Error ? error.message : error));
386
+ }
387
+ if (!decoded || typeof decoded !== 'object' || Array.isArray(decoded)) {
388
+ throw new GraphqlArtifactLoadError(errorMessage);
389
+ }
390
+ return decoded;
391
+ }
392
+ function requireObject(value, errorMessage) {
393
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
394
+ throw new GraphqlArtifactLoadError(errorMessage);
395
+ }
396
+ return value;
397
+ }
398
+ function requireArray(value, errorMessage) {
399
+ if (!Array.isArray(value)) {
400
+ throw new GraphqlArtifactLoadError(errorMessage);
401
+ }
402
+ return value;
403
+ }
404
+ function requireString(value, errorMessage) {
405
+ if (typeof value !== 'string') {
406
+ throw new GraphqlArtifactLoadError(errorMessage);
407
+ }
408
+ return value;
409
+ }
410
+ function nullableString(value) {
411
+ return typeof value === 'string' ? value : undefined;
412
+ }
413
+ function requireBoolean(value, errorMessage) {
414
+ if (typeof value !== 'boolean') {
415
+ throw new GraphqlArtifactLoadError(errorMessage);
416
+ }
417
+ return value;
418
+ }
419
+ function requireNumber(value, errorMessage) {
420
+ if (typeof value !== 'number') {
421
+ throw new GraphqlArtifactLoadError(errorMessage);
422
+ }
423
+ return value;
424
+ }
425
+ function requireStringArray(value, errorMessage) {
426
+ const array = requireArray(value, errorMessage);
427
+ return array.map((item) => requireString(item, errorMessage));
428
+ }
429
+ function requireBuildMode(value) {
430
+ switch (value) {
431
+ case graphql_catalog_builder_1.GraphqlCatalogBuildMode.Compile:
432
+ case graphql_catalog_builder_1.GraphqlCatalogBuildMode.Runtime:
433
+ return value;
434
+ default:
435
+ throw new GraphqlArtifactLoadError(`Unknown build mode ${String(value)}.`);
436
+ }
437
+ }
438
+ function requirePhysicalObjectKind(value) {
439
+ switch (value) {
440
+ case physical_model_1.PhysicalObjectKind.Table:
441
+ case physical_model_1.PhysicalObjectKind.View:
442
+ return value;
443
+ default:
444
+ throw new GraphqlArtifactLoadError(`Unknown object kind ${String(value)}.`);
445
+ }
446
+ }
447
+ function requireIdentityMode(value) {
448
+ switch (value) {
449
+ case graphql_catalog_builder_1.GraphqlCatalogIdentityMode.Single:
450
+ case graphql_catalog_builder_1.GraphqlCatalogIdentityMode.Composite:
451
+ case graphql_catalog_builder_1.GraphqlCatalogIdentityMode.None:
452
+ return value;
453
+ default:
454
+ throw new GraphqlArtifactLoadError(`Unknown identity mode ${String(value)}.`);
455
+ }
456
+ }
457
+ function requireOrigin(value) {
458
+ switch (value) {
459
+ case graphql_catalog_builder_1.GraphqlCatalogOrigin.Inferred:
460
+ case graphql_catalog_builder_1.GraphqlCatalogOrigin.Annotated:
461
+ return value;
462
+ default:
463
+ throw new GraphqlArtifactLoadError(`Unknown origin ${String(value)}.`);
464
+ }
465
+ }
466
+ function requireFieldVisibility(value) {
467
+ switch (value) {
468
+ case graphql_catalog_builder_1.GraphqlCatalogFieldVisibility.Public:
469
+ case graphql_catalog_builder_1.GraphqlCatalogFieldVisibility.Hidden:
470
+ return value;
471
+ default:
472
+ throw new GraphqlArtifactLoadError(`Unknown field visibility ${String(value)}.`);
473
+ }
474
+ }
475
+ function requireRelationCardinality(value) {
476
+ switch (value) {
477
+ case graphql_catalog_builder_1.GraphqlCatalogRelationCardinality.One:
478
+ case graphql_catalog_builder_1.GraphqlCatalogRelationCardinality.Many:
479
+ return value;
480
+ default:
481
+ throw new GraphqlArtifactLoadError(`Unknown relation cardinality ${String(value)}.`);
482
+ }
483
+ }
484
+ function requirePaginationMode(value) {
485
+ switch (value) {
486
+ case graphql_catalog_builder_1.GraphqlCatalogPaginationMode.Offset:
487
+ case graphql_catalog_builder_1.GraphqlCatalogPaginationMode.None:
488
+ return value;
489
+ default:
490
+ throw new GraphqlArtifactLoadError(`Unknown pagination mode ${String(value)}.`);
491
+ }
492
+ }
493
+ function requireDiagnosticSeverity(value) {
494
+ switch (value) {
495
+ case graphql_catalog_builder_1.GraphqlCatalogDiagnosticSeverity.Error:
496
+ case graphql_catalog_builder_1.GraphqlCatalogDiagnosticSeverity.Warning:
497
+ case graphql_catalog_builder_1.GraphqlCatalogDiagnosticSeverity.Info:
498
+ return value;
499
+ default:
500
+ throw new GraphqlArtifactLoadError(`Unknown diagnostic severity ${String(value)}.`);
501
+ }
502
+ }
503
+ function canonicalize(value) {
504
+ if (Array.isArray(value)) {
505
+ return value.map((entry) => canonicalize(entry));
506
+ }
507
+ if (value && typeof value === 'object') {
508
+ const entries = Object.entries(value).sort(([left], [right]) => left.localeCompare(right));
509
+ return Object.fromEntries(entries.map(([key, entryValue]) => [key, canonicalize(entryValue)]));
510
+ }
511
+ return value;
512
+ }
@@ -0,0 +1,52 @@
1
+ import type { GraphqlCatalog } from '../catalog/graphql_catalog_builder';
2
+ import type { ReadExecutor } from '../read/sql_read_contract';
3
+ export type GraphqlEventSink = (event: GraphqlRequestEvent) => void | Promise<void>;
4
+ export type GraphqlSourceDigestFactory = () => string | Promise<string>;
5
+ export declare enum GraphqlRequestPhase {
6
+ Started = "started",
7
+ Completed = "completed"
8
+ }
9
+ export declare class GraphqlRequestEvent {
10
+ readonly phase: GraphqlRequestPhase;
11
+ readonly requestId: string;
12
+ readonly method: string;
13
+ readonly path: string;
14
+ readonly statusCode?: number;
15
+ constructor(options: {
16
+ phase: GraphqlRequestPhase;
17
+ requestId: string;
18
+ method: string;
19
+ path: string;
20
+ statusCode?: number;
21
+ });
22
+ }
23
+ export declare const graphqlDefaultReadExecutorCapabilityId = "modular_api.sql.read_executor";
24
+ export declare class GraphqlOptions {
25
+ readonly catalogFactory: () => Promise<GraphqlCatalog>;
26
+ readonly executor?: ReadExecutor;
27
+ readonly executionCapabilityId?: string;
28
+ readonly introspectionEnabled: boolean;
29
+ readonly maxDepth: number;
30
+ readonly maxComplexity: number;
31
+ readonly defaultLimit: number;
32
+ readonly maxLimit: number;
33
+ readonly onEvent?: GraphqlEventSink;
34
+ readonly artifactDirectory?: string;
35
+ readonly sourceDigestFactory?: GraphqlSourceDigestFactory;
36
+ readonly sdlFactory: (catalog: GraphqlCatalog) => string;
37
+ constructor(options: {
38
+ catalogFactory: () => Promise<GraphqlCatalog>;
39
+ executor?: ReadExecutor;
40
+ executionCapabilityId?: string;
41
+ introspectionEnabled?: boolean;
42
+ maxDepth?: number;
43
+ maxComplexity?: number;
44
+ defaultLimit?: number;
45
+ maxLimit?: number;
46
+ onEvent?: GraphqlEventSink;
47
+ artifactDirectory?: string;
48
+ sourceDigestFactory?: GraphqlSourceDigestFactory;
49
+ sdlFactory?: (catalog: GraphqlCatalog) => string;
50
+ });
51
+ get resolvedExecutionCapabilityId(): string;
52
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphqlOptions = exports.graphqlDefaultReadExecutorCapabilityId = exports.GraphqlRequestEvent = exports.GraphqlRequestPhase = void 0;
4
+ const graphql_schema_sdl_generator_1 = require("../schema/graphql_schema_sdl_generator");
5
+ var GraphqlRequestPhase;
6
+ (function (GraphqlRequestPhase) {
7
+ GraphqlRequestPhase["Started"] = "started";
8
+ GraphqlRequestPhase["Completed"] = "completed";
9
+ })(GraphqlRequestPhase || (exports.GraphqlRequestPhase = GraphqlRequestPhase = {}));
10
+ class GraphqlRequestEvent {
11
+ phase;
12
+ requestId;
13
+ method;
14
+ path;
15
+ statusCode;
16
+ constructor(options) {
17
+ this.phase = options.phase;
18
+ this.requestId = options.requestId;
19
+ this.method = options.method;
20
+ this.path = options.path;
21
+ this.statusCode = options.statusCode;
22
+ }
23
+ }
24
+ exports.GraphqlRequestEvent = GraphqlRequestEvent;
25
+ exports.graphqlDefaultReadExecutorCapabilityId = 'modular_api.sql.read_executor';
26
+ class GraphqlOptions {
27
+ catalogFactory;
28
+ executor;
29
+ executionCapabilityId;
30
+ introspectionEnabled;
31
+ maxDepth;
32
+ maxComplexity;
33
+ defaultLimit;
34
+ maxLimit;
35
+ onEvent;
36
+ artifactDirectory;
37
+ sourceDigestFactory;
38
+ sdlFactory;
39
+ constructor(options) {
40
+ if (options.executor && options.executionCapabilityId) {
41
+ throw new Error('GraphQL runtime accepts either a direct executor or an execution capability id, not both.');
42
+ }
43
+ this.catalogFactory = options.catalogFactory;
44
+ this.executor = options.executor;
45
+ this.executionCapabilityId = options.executionCapabilityId;
46
+ this.introspectionEnabled = options.introspectionEnabled ?? false;
47
+ this.maxDepth = options.maxDepth ?? 8;
48
+ this.maxComplexity = options.maxComplexity ?? 500;
49
+ this.defaultLimit = options.defaultLimit ?? 50;
50
+ this.maxLimit = options.maxLimit ?? 200;
51
+ this.onEvent = options.onEvent;
52
+ this.artifactDirectory = options.artifactDirectory;
53
+ this.sourceDigestFactory = options.sourceDigestFactory;
54
+ this.sdlFactory = options.sdlFactory ?? ((catalog) => new graphql_schema_sdl_generator_1.GraphqlSchemaSdlGenerator().generate(catalog));
55
+ }
56
+ get resolvedExecutionCapabilityId() {
57
+ return this.executionCapabilityId ?? exports.graphqlDefaultReadExecutorCapabilityId;
58
+ }
59
+ }
60
+ exports.GraphqlOptions = GraphqlOptions;
@@ -0,0 +1,18 @@
1
+ import type { HealthService } from '../../core/health/health_service';
2
+ import type { Plugin, PluginHost, PluginManifest, PluginValidationResult } from '../../core/plugin';
3
+ import { GraphqlOptions } from './graphql_runtime_options';
4
+ export declare class GraphqlRuntimePlugin implements Plugin {
5
+ private readonly options;
6
+ private readonly healthService;
7
+ readonly manifest: PluginManifest;
8
+ private readonly state;
9
+ constructor(options: GraphqlOptions | undefined, healthService: HealthService);
10
+ setup(host: PluginHost): void;
11
+ validate(host: PluginHost): Promise<PluginValidationResult[]>;
12
+ shutdown(): Promise<void>;
13
+ private resolveExecutor;
14
+ private validationFailure;
15
+ private handleRequest;
16
+ private emitEvent;
17
+ private executeRequest;
18
+ }