@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,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SqlRelationBatchSelection = exports.SqlCountSelection = exports.SqlCollectionSelection = exports.SqlItemSelection = exports.SqlPage = exports.SqlOrderByClause = exports.SqlSortDirection = exports.SqlFilterGroup = exports.SqlFilterGroupKind = exports.SqlFilterCondition = exports.SqlFilterNode = exports.SqlFilterOperator = exports.RowSet = exports.ReadExecutionContext = exports.SqlReadCommand = exports.SqlParameter = exports.SqlReadCommandPurpose = void 0;
4
+ var SqlReadCommandPurpose;
5
+ (function (SqlReadCommandPurpose) {
6
+ SqlReadCommandPurpose["Item"] = "item";
7
+ SqlReadCommandPurpose["Collection"] = "collection";
8
+ SqlReadCommandPurpose["RelationBatch"] = "relation-batch";
9
+ SqlReadCommandPurpose["Count"] = "count";
10
+ })(SqlReadCommandPurpose || (exports.SqlReadCommandPurpose = SqlReadCommandPurpose = {}));
11
+ class SqlParameter {
12
+ name;
13
+ type;
14
+ value;
15
+ constructor(options) {
16
+ this.name = options.name;
17
+ this.value = options.value;
18
+ this.type = options.type;
19
+ }
20
+ }
21
+ exports.SqlParameter = SqlParameter;
22
+ class SqlReadCommand {
23
+ engine;
24
+ sql;
25
+ parameters;
26
+ purpose;
27
+ constructor(options) {
28
+ this.engine = options.engine;
29
+ this.sql = options.sql;
30
+ this.parameters = Object.freeze([...options.parameters]);
31
+ this.purpose = options.purpose;
32
+ }
33
+ }
34
+ exports.SqlReadCommand = SqlReadCommand;
35
+ class ReadExecutionContext {
36
+ requestId;
37
+ principal;
38
+ tenantId;
39
+ telemetry;
40
+ constructor(options = {}) {
41
+ this.requestId = options.requestId;
42
+ this.principal = options.principal;
43
+ this.tenantId = options.tenantId;
44
+ this.telemetry = options.telemetry;
45
+ }
46
+ }
47
+ exports.ReadExecutionContext = ReadExecutionContext;
48
+ class RowSet {
49
+ rows;
50
+ rowCount;
51
+ constructor(options) {
52
+ this.rows = Object.freeze([...options.rows]);
53
+ this.rowCount = options.rowCount;
54
+ }
55
+ static normalize(rawRows) {
56
+ const rows = Array.from(rawRows, (rawRow) => {
57
+ const sortedEntries = Reflect.ownKeys(rawRow)
58
+ .map((key) => [String(key), rawRow[key]])
59
+ .sort(([left], [right]) => left.localeCompare(right));
60
+ const row = {};
61
+ for (const [key, value] of sortedEntries) {
62
+ row[key] = value;
63
+ }
64
+ return Object.freeze(row);
65
+ });
66
+ return new RowSet({ rows, rowCount: rows.length });
67
+ }
68
+ }
69
+ exports.RowSet = RowSet;
70
+ var SqlFilterOperator;
71
+ (function (SqlFilterOperator) {
72
+ SqlFilterOperator["Eq"] = "eq";
73
+ SqlFilterOperator["Ne"] = "ne";
74
+ SqlFilterOperator["InList"] = "inList";
75
+ SqlFilterOperator["Lt"] = "lt";
76
+ SqlFilterOperator["Lte"] = "lte";
77
+ SqlFilterOperator["Gt"] = "gt";
78
+ SqlFilterOperator["Gte"] = "gte";
79
+ SqlFilterOperator["IsNull"] = "isNull";
80
+ SqlFilterOperator["Contains"] = "contains";
81
+ SqlFilterOperator["StartsWith"] = "startsWith";
82
+ SqlFilterOperator["EndsWith"] = "endsWith";
83
+ })(SqlFilterOperator || (exports.SqlFilterOperator = SqlFilterOperator = {}));
84
+ class SqlFilterNode {
85
+ }
86
+ exports.SqlFilterNode = SqlFilterNode;
87
+ class SqlFilterCondition extends SqlFilterNode {
88
+ field;
89
+ operator;
90
+ value;
91
+ constructor(options) {
92
+ super();
93
+ this.field = options.field;
94
+ this.operator = options.operator;
95
+ this.value = options.value;
96
+ }
97
+ }
98
+ exports.SqlFilterCondition = SqlFilterCondition;
99
+ var SqlFilterGroupKind;
100
+ (function (SqlFilterGroupKind) {
101
+ SqlFilterGroupKind["And"] = "and";
102
+ SqlFilterGroupKind["Or"] = "or";
103
+ SqlFilterGroupKind["Not"] = "not";
104
+ })(SqlFilterGroupKind || (exports.SqlFilterGroupKind = SqlFilterGroupKind = {}));
105
+ class SqlFilterGroup extends SqlFilterNode {
106
+ kind;
107
+ nodes;
108
+ constructor(kind, nodes) {
109
+ super();
110
+ this.kind = kind;
111
+ this.nodes = Object.freeze([...nodes]);
112
+ }
113
+ static and(nodes) {
114
+ return new SqlFilterGroup(SqlFilterGroupKind.And, nodes);
115
+ }
116
+ static or(nodes) {
117
+ return new SqlFilterGroup(SqlFilterGroupKind.Or, nodes);
118
+ }
119
+ static not(node) {
120
+ return new SqlFilterGroup(SqlFilterGroupKind.Not, [node]);
121
+ }
122
+ }
123
+ exports.SqlFilterGroup = SqlFilterGroup;
124
+ var SqlSortDirection;
125
+ (function (SqlSortDirection) {
126
+ SqlSortDirection["Asc"] = "asc";
127
+ SqlSortDirection["Desc"] = "desc";
128
+ })(SqlSortDirection || (exports.SqlSortDirection = SqlSortDirection = {}));
129
+ class SqlOrderByClause {
130
+ field;
131
+ direction;
132
+ constructor(options) {
133
+ this.field = options.field;
134
+ this.direction = options.direction;
135
+ }
136
+ }
137
+ exports.SqlOrderByClause = SqlOrderByClause;
138
+ class SqlPage {
139
+ limit;
140
+ offset;
141
+ constructor(options) {
142
+ this.limit = options.limit;
143
+ this.offset = options.offset;
144
+ }
145
+ }
146
+ exports.SqlPage = SqlPage;
147
+ class SqlItemSelection {
148
+ objectId;
149
+ projectedFields;
150
+ key;
151
+ constructor(options) {
152
+ this.objectId = options.objectId;
153
+ this.projectedFields = Object.freeze([...options.projectedFields]);
154
+ this.key = Object.freeze({ ...options.key });
155
+ }
156
+ }
157
+ exports.SqlItemSelection = SqlItemSelection;
158
+ class SqlCollectionSelection {
159
+ objectId;
160
+ projectedFields;
161
+ filter;
162
+ orderBy;
163
+ page;
164
+ constructor(options) {
165
+ this.objectId = options.objectId;
166
+ this.projectedFields = Object.freeze([...options.projectedFields]);
167
+ this.filter = options.filter;
168
+ this.orderBy = Object.freeze([...(options.orderBy ?? [])]);
169
+ this.page = options.page;
170
+ }
171
+ }
172
+ exports.SqlCollectionSelection = SqlCollectionSelection;
173
+ class SqlCountSelection {
174
+ objectId;
175
+ filter;
176
+ constructor(options) {
177
+ this.objectId = options.objectId;
178
+ this.filter = options.filter;
179
+ }
180
+ }
181
+ exports.SqlCountSelection = SqlCountSelection;
182
+ class SqlRelationBatchSelection {
183
+ sourceObjectId;
184
+ relationName;
185
+ projectedFields;
186
+ parentKeys;
187
+ constructor(options) {
188
+ this.sourceObjectId = options.sourceObjectId;
189
+ this.relationName = options.relationName;
190
+ this.projectedFields = Object.freeze([...options.projectedFields]);
191
+ this.parentKeys = Object.freeze(options.parentKeys.map((key) => Object.freeze({ ...key })));
192
+ }
193
+ }
194
+ exports.SqlRelationBatchSelection = SqlRelationBatchSelection;
@@ -0,0 +1,58 @@
1
+ import type { GraphqlCatalog } from '../catalog/graphql_catalog_builder';
2
+ import { ReadExecutionContext, type ReadExecutor, RowSet, SqlCollectionSelection, SqlCountSelection, SqlItemSelection, SqlReadCommand, SqlRelationBatchSelection } from './sql_read_contract';
3
+ export declare class SqlServerReadCompiler {
4
+ compileItem(options: {
5
+ catalog: GraphqlCatalog;
6
+ selection: SqlItemSelection;
7
+ }): SqlReadCommand;
8
+ compileCollection(options: {
9
+ catalog: GraphqlCatalog;
10
+ selection: SqlCollectionSelection;
11
+ }): SqlReadCommand;
12
+ compileCount(options: {
13
+ catalog: GraphqlCatalog;
14
+ selection: SqlCountSelection;
15
+ }): SqlReadCommand;
16
+ compileRelationBatch(options: {
17
+ catalog: GraphqlCatalog;
18
+ selection: SqlRelationBatchSelection;
19
+ }): SqlReadCommand;
20
+ private resolveObject;
21
+ private tableRef;
22
+ private buildSelectList;
23
+ private compileKeyPredicate;
24
+ private compileFilter;
25
+ private compileFilterCondition;
26
+ private buildOrderBy;
27
+ private compileRelationBatchPredicate;
28
+ private resolveFieldByPublicName;
29
+ private resolveFieldByColumn;
30
+ }
31
+ export declare class SqlCatalogReadDispatcher {
32
+ readonly compiler: SqlServerReadCompiler;
33
+ readonly executor: ReadExecutor;
34
+ constructor(options: {
35
+ compiler: SqlServerReadCompiler;
36
+ executor: ReadExecutor;
37
+ });
38
+ readItem(options: {
39
+ catalog: GraphqlCatalog;
40
+ selection: SqlItemSelection;
41
+ context: ReadExecutionContext;
42
+ }): Promise<RowSet>;
43
+ readCollection(options: {
44
+ catalog: GraphqlCatalog;
45
+ selection: SqlCollectionSelection;
46
+ context: ReadExecutionContext;
47
+ }): Promise<RowSet>;
48
+ readCount(options: {
49
+ catalog: GraphqlCatalog;
50
+ selection: SqlCountSelection;
51
+ context: ReadExecutionContext;
52
+ }): Promise<RowSet>;
53
+ readRelationBatch(options: {
54
+ catalog: GraphqlCatalog;
55
+ selection: SqlRelationBatchSelection;
56
+ context: ReadExecutionContext;
57
+ }): Promise<RowSet>;
58
+ }
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SqlCatalogReadDispatcher = exports.SqlServerReadCompiler = void 0;
4
+ const sql_read_contract_1 = require("./sql_read_contract");
5
+ class SqlServerReadCompiler {
6
+ compileItem(options) {
7
+ const object = this.resolveObject(options.catalog, options.selection.objectId);
8
+ const parameters = new SqlParameterBuilder();
9
+ const selectList = this.buildSelectList(object, options.selection.projectedFields);
10
+ const whereClause = this.compileKeyPredicate({
11
+ object,
12
+ publicKeyValues: options.selection.key,
13
+ parameters,
14
+ });
15
+ return new sql_read_contract_1.SqlReadCommand({
16
+ engine: 'sqlserver',
17
+ sql: `SELECT TOP (1) ${selectList} FROM ${this.tableRef(object)} WHERE ${whereClause}`,
18
+ parameters: parameters.build(),
19
+ purpose: sql_read_contract_1.SqlReadCommandPurpose.Item,
20
+ });
21
+ }
22
+ compileCollection(options) {
23
+ const object = this.resolveObject(options.catalog, options.selection.objectId);
24
+ const parameters = new SqlParameterBuilder();
25
+ let sql = `SELECT ${this.buildSelectList(object, options.selection.projectedFields)} FROM ${this.tableRef(object)}`;
26
+ const whereClause = this.compileFilter({
27
+ object,
28
+ filter: options.selection.filter,
29
+ parameters,
30
+ });
31
+ if (whereClause) {
32
+ sql += ` WHERE ${whereClause}`;
33
+ }
34
+ if (options.selection.orderBy.length > 0) {
35
+ sql += ` ORDER BY ${this.buildOrderBy(object, options.selection.orderBy)}`;
36
+ }
37
+ if (options.selection.page instanceof sql_read_contract_1.SqlPage) {
38
+ const offsetName = parameters.add(options.selection.page.offset, 'Int');
39
+ const limitName = parameters.add(options.selection.page.limit, 'Int');
40
+ sql += ` OFFSET @${offsetName} ROWS FETCH NEXT @${limitName} ROWS ONLY`;
41
+ }
42
+ return new sql_read_contract_1.SqlReadCommand({
43
+ engine: 'sqlserver',
44
+ sql,
45
+ parameters: parameters.build(),
46
+ purpose: sql_read_contract_1.SqlReadCommandPurpose.Collection,
47
+ });
48
+ }
49
+ compileCount(options) {
50
+ const object = this.resolveObject(options.catalog, options.selection.objectId);
51
+ const parameters = new SqlParameterBuilder();
52
+ let sql = `SELECT COUNT_BIG(1) AS [totalCount] FROM ${this.tableRef(object)}`;
53
+ const whereClause = this.compileFilter({
54
+ object,
55
+ filter: options.selection.filter,
56
+ parameters,
57
+ });
58
+ if (whereClause) {
59
+ sql += ` WHERE ${whereClause}`;
60
+ }
61
+ return new sql_read_contract_1.SqlReadCommand({
62
+ engine: 'sqlserver',
63
+ sql,
64
+ parameters: parameters.build(),
65
+ purpose: sql_read_contract_1.SqlReadCommandPurpose.Count,
66
+ });
67
+ }
68
+ compileRelationBatch(options) {
69
+ const sourceObject = this.resolveObject(options.catalog, options.selection.sourceObjectId);
70
+ const relation = sourceObject.relations.find((candidate) => candidate.name === options.selection.relationName);
71
+ if (!relation) {
72
+ throw new Error(`Unknown relation ${options.selection.relationName} for ${options.selection.sourceObjectId}.`);
73
+ }
74
+ const targetObject = this.resolveObject(options.catalog, relation.target);
75
+ const parameters = new SqlParameterBuilder();
76
+ const selectList = this.buildSelectList(targetObject, options.selection.projectedFields);
77
+ const whereClause = this.compileRelationBatchPredicate({
78
+ sourceObject,
79
+ targetObject,
80
+ relation,
81
+ parentKeys: options.selection.parentKeys,
82
+ parameters,
83
+ });
84
+ return new sql_read_contract_1.SqlReadCommand({
85
+ engine: 'sqlserver',
86
+ sql: `SELECT ${selectList} FROM ${this.tableRef(targetObject)} WHERE ${whereClause}`,
87
+ parameters: parameters.build(),
88
+ purpose: sql_read_contract_1.SqlReadCommandPurpose.RelationBatch,
89
+ });
90
+ }
91
+ resolveObject(catalog, objectId) {
92
+ const object = catalog.objects.find((candidate) => candidate.id === objectId);
93
+ if (!object) {
94
+ throw new Error(`Unknown catalog object ${objectId}.`);
95
+ }
96
+ return object;
97
+ }
98
+ tableRef(object) {
99
+ return `[${object.source.schemaName}].[${object.source.objectName}]`;
100
+ }
101
+ buildSelectList(object, publicFields) {
102
+ return publicFields
103
+ .map((publicField) => {
104
+ const field = this.resolveFieldByPublicName(object, publicField);
105
+ return `[${field.column}] AS [${field.publicName}]`;
106
+ })
107
+ .join(', ');
108
+ }
109
+ compileKeyPredicate(options) {
110
+ const clauses = [];
111
+ for (const keyColumn of options.object.identity.fields) {
112
+ const field = this.resolveFieldByColumn(options.object, keyColumn);
113
+ if (!(field.publicName in options.publicKeyValues)) {
114
+ throw new Error(`Missing key component ${field.publicName}.`);
115
+ }
116
+ const parameterName = options.parameters.add(options.publicKeyValues[field.publicName], field.type);
117
+ clauses.push(`[${field.column}] = @${parameterName}`);
118
+ }
119
+ return clauses.join(' AND ');
120
+ }
121
+ compileFilter(options) {
122
+ if (!options.filter) {
123
+ return undefined;
124
+ }
125
+ if (options.filter instanceof sql_read_contract_1.SqlFilterCondition) {
126
+ return this.compileFilterCondition(options.object, options.filter, options.parameters);
127
+ }
128
+ if (options.filter instanceof sql_read_contract_1.SqlFilterGroup) {
129
+ if (options.filter.nodes.length === 0) {
130
+ return undefined;
131
+ }
132
+ if (options.filter.kind === sql_read_contract_1.SqlFilterGroupKind.Not) {
133
+ const child = this.compileFilter({
134
+ object: options.object,
135
+ filter: options.filter.nodes[0],
136
+ parameters: options.parameters,
137
+ });
138
+ return child ? `NOT (${child})` : undefined;
139
+ }
140
+ const compiledChildren = options.filter.nodes
141
+ .map((node) => this.compileFilter({ object: options.object, filter: node, parameters: options.parameters }))
142
+ .filter((node) => typeof node === 'string' && node.length > 0);
143
+ if (compiledChildren.length === 0) {
144
+ return undefined;
145
+ }
146
+ const joiner = options.filter.kind === sql_read_contract_1.SqlFilterGroupKind.And ? ' AND ' : ' OR ';
147
+ return `(${compiledChildren.join(joiner)})`;
148
+ }
149
+ throw new Error(`Unsupported filter node ${options.filter.constructor?.name ?? typeof options.filter}.`);
150
+ }
151
+ compileFilterCondition(object, condition, parameters) {
152
+ const field = this.resolveFieldByPublicName(object, condition.field);
153
+ const columnRef = `[${field.column}]`;
154
+ if ((condition.operator === sql_read_contract_1.SqlFilterOperator.Eq || condition.operator === sql_read_contract_1.SqlFilterOperator.Ne) && condition.value == null) {
155
+ throw new Error(`Use isNull instead of eq/ne with null for ${condition.field}.`);
156
+ }
157
+ switch (condition.operator) {
158
+ case sql_read_contract_1.SqlFilterOperator.Eq:
159
+ return `${columnRef} = @${parameters.add(condition.value, field.type)}`;
160
+ case sql_read_contract_1.SqlFilterOperator.Ne:
161
+ return `${columnRef} <> @${parameters.add(condition.value, field.type)}`;
162
+ case sql_read_contract_1.SqlFilterOperator.InList: {
163
+ const values = Array.isArray(condition.value) ? condition.value : [];
164
+ if (values.length === 0) {
165
+ return '1 = 0';
166
+ }
167
+ const parameterRefs = values.map((value) => `@${parameters.add(value, field.type)}`).join(', ');
168
+ return `${columnRef} IN (${parameterRefs})`;
169
+ }
170
+ case sql_read_contract_1.SqlFilterOperator.Lt:
171
+ return `${columnRef} < @${parameters.add(condition.value, field.type)}`;
172
+ case sql_read_contract_1.SqlFilterOperator.Lte:
173
+ return `${columnRef} <= @${parameters.add(condition.value, field.type)}`;
174
+ case sql_read_contract_1.SqlFilterOperator.Gt:
175
+ return `${columnRef} > @${parameters.add(condition.value, field.type)}`;
176
+ case sql_read_contract_1.SqlFilterOperator.Gte:
177
+ return `${columnRef} >= @${parameters.add(condition.value, field.type)}`;
178
+ case sql_read_contract_1.SqlFilterOperator.IsNull:
179
+ if (typeof condition.value !== 'boolean') {
180
+ throw new Error(`isNull expects a boolean for ${condition.field}.`);
181
+ }
182
+ return condition.value ? `${columnRef} IS NULL` : `${columnRef} IS NOT NULL`;
183
+ case sql_read_contract_1.SqlFilterOperator.Contains:
184
+ return `${columnRef} LIKE '%' + @${parameters.add(condition.value, field.type)} + '%'`;
185
+ case sql_read_contract_1.SqlFilterOperator.StartsWith:
186
+ return `${columnRef} LIKE @${parameters.add(condition.value, field.type)} + '%'`;
187
+ case sql_read_contract_1.SqlFilterOperator.EndsWith:
188
+ return `${columnRef} LIKE '%' + @${parameters.add(condition.value, field.type)}`;
189
+ }
190
+ }
191
+ buildOrderBy(object, clauses) {
192
+ return clauses
193
+ .map((clause) => {
194
+ const field = this.resolveFieldByPublicName(object, clause.field);
195
+ const direction = clause.direction === sql_read_contract_1.SqlSortDirection.Asc ? 'ASC' : 'DESC';
196
+ return `[${field.column}] ${direction}`;
197
+ })
198
+ .join(', ');
199
+ }
200
+ compileRelationBatchPredicate(options) {
201
+ if (options.relation.targetFields.length === 1) {
202
+ const sourceField = this.resolveFieldByColumn(options.sourceObject, options.relation.sourceFields[0]);
203
+ const targetField = this.resolveFieldByColumn(options.targetObject, options.relation.targetFields[0]);
204
+ const parameterRefs = options.parentKeys.map((parentKey) => {
205
+ if (!(sourceField.publicName in parentKey)) {
206
+ throw new Error(`Missing parent key component ${sourceField.publicName} for relation ${options.relation.name}.`);
207
+ }
208
+ return `@${options.parameters.add(parentKey[sourceField.publicName], targetField.type)}`;
209
+ });
210
+ return `[${targetField.column}] IN (${parameterRefs.join(', ')})`;
211
+ }
212
+ const disjunctions = [];
213
+ for (const parentKey of options.parentKeys) {
214
+ const conjunctions = [];
215
+ for (let index = 0; index < options.relation.targetFields.length; index += 1) {
216
+ const sourceField = this.resolveFieldByColumn(options.sourceObject, options.relation.sourceFields[index]);
217
+ const targetField = this.resolveFieldByColumn(options.targetObject, options.relation.targetFields[index]);
218
+ if (!(sourceField.publicName in parentKey)) {
219
+ throw new Error(`Missing parent key component ${sourceField.publicName} for relation ${options.relation.name}.`);
220
+ }
221
+ const parameterName = options.parameters.add(parentKey[sourceField.publicName], targetField.type);
222
+ conjunctions.push(`[${targetField.column}] = @${parameterName}`);
223
+ }
224
+ disjunctions.push(`(${conjunctions.join(' AND ')})`);
225
+ }
226
+ return disjunctions.join(' OR ');
227
+ }
228
+ resolveFieldByPublicName(object, publicName) {
229
+ const field = object.fields.find((candidate) => candidate.publicName === publicName);
230
+ if (!field) {
231
+ throw new Error(`Unknown public field ${publicName} for ${object.id}.`);
232
+ }
233
+ return field;
234
+ }
235
+ resolveFieldByColumn(object, column) {
236
+ const field = object.fields.find((candidate) => candidate.column === column);
237
+ if (!field) {
238
+ throw new Error(`Unknown source column ${column} for ${object.id}.`);
239
+ }
240
+ return field;
241
+ }
242
+ }
243
+ exports.SqlServerReadCompiler = SqlServerReadCompiler;
244
+ class SqlCatalogReadDispatcher {
245
+ compiler;
246
+ executor;
247
+ constructor(options) {
248
+ this.compiler = options.compiler;
249
+ this.executor = options.executor;
250
+ }
251
+ readItem(options) {
252
+ const command = this.compiler.compileItem({ catalog: options.catalog, selection: options.selection });
253
+ return this.executor.execute(command, options.context);
254
+ }
255
+ readCollection(options) {
256
+ const command = this.compiler.compileCollection({ catalog: options.catalog, selection: options.selection });
257
+ return this.executor.execute(command, options.context);
258
+ }
259
+ readCount(options) {
260
+ const command = this.compiler.compileCount({ catalog: options.catalog, selection: options.selection });
261
+ return this.executor.execute(command, options.context);
262
+ }
263
+ readRelationBatch(options) {
264
+ const command = this.compiler.compileRelationBatch({ catalog: options.catalog, selection: options.selection });
265
+ return this.executor.execute(command, options.context);
266
+ }
267
+ }
268
+ exports.SqlCatalogReadDispatcher = SqlCatalogReadDispatcher;
269
+ class SqlParameterBuilder {
270
+ parameters = [];
271
+ add(value, type) {
272
+ const name = `p${this.parameters.length}`;
273
+ this.parameters.push(new sql_read_contract_1.SqlParameter({ name, type, value }));
274
+ return name;
275
+ }
276
+ build() {
277
+ return Object.freeze([...this.parameters]);
278
+ }
279
+ }
@@ -0,0 +1,43 @@
1
+ import { type GraphqlCatalog } from '../catalog/graphql_catalog_builder';
2
+ import type { GraphqlOptions, GraphqlSourceDigestFactory } from './graphql_runtime_options';
3
+ export declare class GraphqlArtifactBundle {
4
+ readonly catalogJson: string;
5
+ readonly catalogLockJson: string;
6
+ readonly diagnosticsJson: string;
7
+ readonly schemaGraphql: string;
8
+ constructor(options: {
9
+ catalogJson: string;
10
+ catalogLockJson: string;
11
+ diagnosticsJson: string;
12
+ schemaGraphql: string;
13
+ });
14
+ writeToDirectory(outputDirectory: string): Promise<void>;
15
+ }
16
+ export declare class GraphqlArtifactCompileError extends Error {
17
+ readonly bundle: GraphqlArtifactBundle;
18
+ constructor(options: {
19
+ message: string;
20
+ bundle: GraphqlArtifactBundle;
21
+ });
22
+ }
23
+ export declare class GraphqlArtifactLoadError extends Error {
24
+ constructor(message: string);
25
+ }
26
+ export declare class GraphqlArtifactCompiler {
27
+ readonly catalogFactory: GraphqlOptions['catalogFactory'];
28
+ readonly sdlFactory: GraphqlOptions['sdlFactory'];
29
+ constructor(options: {
30
+ catalogFactory: GraphqlOptions['catalogFactory'];
31
+ sdlFactory?: GraphqlOptions['sdlFactory'];
32
+ });
33
+ compile(): Promise<GraphqlArtifactBundle>;
34
+ writeToDirectory(outputDirectory: string): Promise<GraphqlArtifactBundle>;
35
+ }
36
+ export declare function tryLoadGraphqlCatalogArtifacts(options: {
37
+ artifactDirectory: string;
38
+ currentSourceDigest: string;
39
+ }): Promise<GraphqlCatalog | undefined>;
40
+ export declare function resolveCatalogFromArtifactsOrSource(options: {
41
+ graphql: GraphqlOptions;
42
+ }): Promise<GraphqlCatalog>;
43
+ export type GraphqlSourceDigestResolver = GraphqlSourceDigestFactory;