@comake/skl-js-engine 0.1.3 → 0.2.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/Skql.js DELETED
@@ -1,351 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Skql = void 0;
7
- const openapi_operation_executor_1 = require("@comake/openapi-operation-executor");
8
- const axios_1 = __importDefault(require("axios"));
9
- const rdf_validate_shacl_1 = __importDefault(require("rdf-validate-shacl"));
10
- const Mapper_1 = require("./mapping/Mapper");
11
- const MemoryQueryAdapter_1 = require("./storage/memory/MemoryQueryAdapter");
12
- const SparqlQueryAdapter_1 = require("./storage/sparql/SparqlQueryAdapter");
13
- const Util_1 = require("./util/Util");
14
- const Vocabularies_1 = require("./util/Vocabularies");
15
- class Skql {
16
- constructor(options) {
17
- switch (options.type) {
18
- case 'memory':
19
- this.adapter = new MemoryQueryAdapter_1.MemoryQueryAdapter(options);
20
- break;
21
- case 'sparql':
22
- this.adapter = new SparqlQueryAdapter_1.SparqlQueryAdapter(options);
23
- break;
24
- default:
25
- throw new Error('No schema source found in setSchema args.');
26
- }
27
- this.inputFiles = options.inputFiles;
28
- this.mapper = new Mapper_1.Mapper({ functions: options.functions });
29
- // eslint-disable-next-line func-style
30
- const getVerbHandler = (getTarget, property) => async (verbArgs) => this.handleVerb(property, verbArgs);
31
- this.verb = new Proxy({}, { get: getVerbHandler });
32
- }
33
- async executeRawQuery(query) {
34
- return await this.adapter.executeRawQuery(query);
35
- }
36
- async executeRawEntityQuery(query, frame) {
37
- return await this.adapter.executeRawEntityQuery(query, frame);
38
- }
39
- async find(options) {
40
- const entity = await this.adapter.find(options);
41
- if (entity) {
42
- return entity;
43
- }
44
- throw new Error(`No schema found with fields matching ${JSON.stringify(options)}`);
45
- }
46
- async findBy(where) {
47
- const entity = await this.adapter.findBy(where);
48
- if (entity) {
49
- return entity;
50
- }
51
- throw new Error(`No schema found with fields matching ${JSON.stringify(where)}`);
52
- }
53
- async findAll(options) {
54
- return await this.adapter.findAll(options);
55
- }
56
- async findAllBy(where) {
57
- return await this.adapter.findAllBy(where);
58
- }
59
- async exists(where) {
60
- return await this.adapter.exists(where);
61
- }
62
- async count(where) {
63
- return await this.adapter.count(where);
64
- }
65
- async save(entityOrEntities) {
66
- if (Array.isArray(entityOrEntities)) {
67
- return await this.adapter.save(entityOrEntities);
68
- }
69
- return await this.adapter.save(entityOrEntities);
70
- }
71
- async destroy(entityOrEntities) {
72
- if (Array.isArray(entityOrEntities)) {
73
- return await this.adapter.destroy(entityOrEntities);
74
- }
75
- return await this.adapter.destroy(entityOrEntities);
76
- }
77
- async destroyAll() {
78
- return await this.adapter.destroyAll();
79
- }
80
- async performMapping(args, mapping, frame) {
81
- const nonReferenceMappings = await this.resolveMappingReferences(mapping);
82
- return await this.mapper.apply(args, nonReferenceMappings, frame ?? {});
83
- }
84
- async performMappingAndConvertToJSON(args, mapping, frame, convertToJsonDeep = true) {
85
- const nonReferenceMappings = await this.resolveMappingReferences(mapping);
86
- const jsonLd = await this.mapper.apply(args, nonReferenceMappings, frame ?? {});
87
- return (0, Util_1.toJSON)(jsonLd, convertToJsonDeep);
88
- }
89
- async handleVerb(verbName, verbArgs) {
90
- const verb = await this.findVerbWithName(verbName);
91
- if (verbArgs.noun) {
92
- return this.handleNounMappingVerb(verb, verbArgs);
93
- }
94
- if (verbArgs.account) {
95
- return this.handleIntegrationVerb(verb, verbArgs);
96
- }
97
- throw new Error(`Verb parameters must include either a noun or an account.`);
98
- }
99
- async findVerbWithName(verbName) {
100
- try {
101
- return await this.findBy({ type: Vocabularies_1.SKL.Verb, [Vocabularies_1.RDFS.label]: verbName });
102
- }
103
- catch {
104
- throw new Error(`Failed to find the verb ${verbName} in the schema.`);
105
- }
106
- }
107
- async handleIntegrationVerb(verb, args) {
108
- await this.assertVerbParamsMatchParameterSchemas(args, verb);
109
- const account = await this.findBy({ id: args.account });
110
- const integrationId = account[Vocabularies_1.SKL.integration]['@id'];
111
- const mapping = await this.findVerbIntegrationMapping(verb['@id'], integrationId);
112
- const operationArgs = await this.performParameterMappingOnArgsIfDefined(args, mapping);
113
- const operationInfo = await this.performOperationMappingWithArgs(args, mapping);
114
- const rawReturnValue = await this.performOperation(operationInfo, operationArgs, account);
115
- if (operationInfo[Vocabularies_1.SKL.schemeName] && rawReturnValue.authorizationUrl) {
116
- return {
117
- '@type': '@json',
118
- '@value': rawReturnValue,
119
- };
120
- }
121
- if (mapping[Vocabularies_1.SKL.returnValueMapping]) {
122
- const mappedReturnValue = await this.performReturnValueMappingWithFrame(rawReturnValue.data, mapping, verb);
123
- await this.assertVerbReturnValueMatchesReturnTypeSchema(mappedReturnValue, verb);
124
- return mappedReturnValue;
125
- }
126
- return rawReturnValue;
127
- }
128
- async findVerbIntegrationMapping(verbId, integrationId) {
129
- return await this.findBy({
130
- type: Vocabularies_1.SKL.VerbIntegrationMapping,
131
- [Vocabularies_1.SKL.verb]: verbId,
132
- [Vocabularies_1.SKL.integration]: integrationId,
133
- });
134
- }
135
- async performOperationMappingWithArgs(args, mapping) {
136
- return await this.performMapping(args, mapping[Vocabularies_1.SKL.operationMapping]);
137
- }
138
- async performOperation(operationInfo, operationArgs, account) {
139
- if (operationInfo[Vocabularies_1.SKL.schemeName]) {
140
- return await this.performSecuritySchemeStageWithCredentials(operationInfo, operationArgs, account);
141
- }
142
- if (operationInfo[Vocabularies_1.SKL.dataSource]) {
143
- return await this.getDataFromDataSource((0, Util_1.getValueIfDefined)(operationInfo[Vocabularies_1.SKL.dataSource]));
144
- }
145
- if (operationInfo[Vocabularies_1.SKL.operationId]) {
146
- return await this.performOpenapiOperationWithCredentials((0, Util_1.getValueIfDefined)(operationInfo[Vocabularies_1.SKL.operationId]), operationArgs, account);
147
- }
148
- throw new Error('Operation not supported.');
149
- }
150
- async performReturnValueMappingWithFrame(data, mapping, verb) {
151
- return await this.performMapping(data, mapping[Vocabularies_1.SKL.returnValueMapping], {
152
- ...(0, Util_1.getValueIfDefined)(verb[Vocabularies_1.SKL.returnValueFrame]),
153
- ...(0, Util_1.getValueIfDefined)(mapping[Vocabularies_1.SKL.returnValueFrame]),
154
- });
155
- }
156
- async resolveMappingReferences(mapping) {
157
- if (Array.isArray(mapping)) {
158
- return await Promise.all(mapping.map(async (subMapping) => await this.resolveMappingReferences(subMapping)));
159
- }
160
- return mapping;
161
- }
162
- async performParameterMappingOnArgsIfDefined(args, mapping, convertToJsonDeep = true) {
163
- if (mapping[Vocabularies_1.SKL.parameterMapping]) {
164
- return await this.performMappingAndConvertToJSON(args, mapping[Vocabularies_1.SKL.parameterMapping], (0, Util_1.getValueIfDefined)(mapping[Vocabularies_1.SKL.parameterMappingFrame]), convertToJsonDeep);
165
- }
166
- return args;
167
- }
168
- async getOpenApiDescriptionForIntegration(integrationId) {
169
- const openApiDescriptionSchema = await this.findBy({
170
- type: Vocabularies_1.SKL.OpenApiDescription,
171
- [Vocabularies_1.SKL.integration]: integrationId,
172
- });
173
- return (0, Util_1.getValueIfDefined)(openApiDescriptionSchema[Vocabularies_1.SKL.openApiDescription]);
174
- }
175
- async findSecurityCredentialsForAccount(accountId) {
176
- return await this.findBy({
177
- type: Vocabularies_1.SKL.SecurityCredentials,
178
- [Vocabularies_1.SKL.account]: accountId,
179
- });
180
- }
181
- async findSecurityCredentialsForAccountIfDefined(accountId) {
182
- try {
183
- return await this.findSecurityCredentialsForAccount(accountId);
184
- }
185
- catch {
186
- return undefined;
187
- }
188
- }
189
- async createOpenApiOperationExecutorWithSpec(openApiDescription) {
190
- const executor = new openapi_operation_executor_1.OpenApiOperationExecutor();
191
- await executor.setOpenapiSpec(openApiDescription);
192
- return executor;
193
- }
194
- async handleNounMappingVerb(verb, args) {
195
- const mapping = await this.findVerbNounMapping(verb['@id'], args.noun);
196
- if (mapping[Vocabularies_1.SKL.returnValueMapping]) {
197
- return await this.performMapping(args, mapping[Vocabularies_1.SKL.returnValueMapping], {
198
- ...(0, Util_1.getValueIfDefined)(verb[Vocabularies_1.SKL.returnValueFrame]),
199
- ...(0, Util_1.getValueIfDefined)(mapping[Vocabularies_1.SKL.returnValueFrame]),
200
- });
201
- }
202
- const verbArgs = await this.performParameterMappingOnArgsIfDefined(args, mapping, false);
203
- const verbInfoJsonLd = await this.performVerbMappingWithArgs(args, mapping);
204
- const mappedVerb = await this.findBy({
205
- id: (0, Util_1.getValueIfDefined)(verbInfoJsonLd[Vocabularies_1.SKL.verb]),
206
- });
207
- return this.handleIntegrationVerb(mappedVerb, verbArgs);
208
- }
209
- async findVerbNounMapping(verbId, noun) {
210
- return await this.findBy({
211
- type: Vocabularies_1.SKL.VerbNounMapping,
212
- [Vocabularies_1.SKL.verb]: verbId,
213
- [Vocabularies_1.SKL.noun]: noun,
214
- });
215
- }
216
- async performVerbMappingWithArgs(args, mapping) {
217
- return await this.performMapping(args, mapping[Vocabularies_1.SKL.verbMapping]);
218
- }
219
- async assertVerbParamsMatchParameterSchemas(verbParams, verb) {
220
- const verbParamsAsJsonLd = {
221
- '@context': (0, Util_1.getValueIfDefined)(verb[Vocabularies_1.SKL.parametersContext]),
222
- '@type': Vocabularies_1.SKL.Parameters,
223
- ...verbParams,
224
- };
225
- const parametersSchema = verb[Vocabularies_1.SKL.parameters];
226
- const report = await this.convertToQuadsAndValidateAgainstShape(verbParamsAsJsonLd, parametersSchema);
227
- if (!report.conforms) {
228
- throw new Error(`${verb[Vocabularies_1.RDFS.label]} parameters do not conform to the schema`);
229
- }
230
- }
231
- async performOpenapiOperationWithCredentials(operationId, operationArgs, account) {
232
- const integrationId = account[Vocabularies_1.SKL.integration]['@id'];
233
- const openApiDescription = await this.getOpenApiDescriptionForIntegration(integrationId);
234
- const openApiExecutor = await this.createOpenApiOperationExecutorWithSpec(openApiDescription);
235
- const securityCredentials = await this.findSecurityCredentialsForAccountIfDefined(account['@id']);
236
- const configuration = {
237
- accessToken: securityCredentials
238
- ? (0, Util_1.getValueIfDefined)(securityCredentials[Vocabularies_1.SKL.accessToken])
239
- : undefined,
240
- apiKey: securityCredentials
241
- ? (0, Util_1.getValueIfDefined)(securityCredentials[Vocabularies_1.SKL.apiKey])
242
- : undefined,
243
- basePath: (0, Util_1.getValueIfDefined)(account[Vocabularies_1.SKL.overrideBasePath]),
244
- };
245
- return await openApiExecutor.executeOperation(operationId, configuration, operationArgs)
246
- .catch(async (error) => {
247
- if (axios_1.default.isAxiosError(error) && await this.isInvalidTokenError(error, integrationId) && securityCredentials) {
248
- const refreshedConfiguration = await this.refreshOpenApiToken(securityCredentials, openApiExecutor, integrationId);
249
- return await openApiExecutor.executeOperation(operationId, refreshedConfiguration, operationArgs);
250
- }
251
- throw error;
252
- });
253
- }
254
- async isInvalidTokenError(error, integrationId) {
255
- const integration = await this.findBy({ id: integrationId });
256
- const errorMatcher = (0, Util_1.getValueIfDefined)(integration[Vocabularies_1.SKL.invalidTokenErrorMatcher]);
257
- if (errorMatcher && (error.response?.status === errorMatcher.status)) {
258
- if (!errorMatcher.messageRegex) {
259
- return true;
260
- }
261
- if (error.response?.statusText &&
262
- new RegExp(errorMatcher.messageRegex, 'u').test(error.response?.statusText)) {
263
- return true;
264
- }
265
- }
266
- return false;
267
- }
268
- async refreshOpenApiToken(securityCredentialsSchema, openApiExecutor, integrationId) {
269
- const getOauthTokenVerb = await this.findBy({ type: Vocabularies_1.SKL.Verb, [Vocabularies_1.RDFS.label]: 'getOauthTokens' });
270
- const mapping = await this.findVerbIntegrationMapping(getOauthTokenVerb['@id'], integrationId);
271
- const operationArgs = await this.performParameterMappingOnArgsIfDefined({ refreshToken: (0, Util_1.getValueIfDefined)(securityCredentialsSchema[Vocabularies_1.SKL.refreshToken]) }, mapping);
272
- const operationInfoJsonLd = await this.performOperationMappingWithArgs({}, mapping);
273
- const configuration = this.getConfigurationFromSecurityCredentials(securityCredentialsSchema);
274
- const rawReturnValue = await openApiExecutor.executeSecuritySchemeStage((0, Util_1.getValueIfDefined)(operationInfoJsonLd[Vocabularies_1.SKL.schemeName]), (0, Util_1.getValueIfDefined)(operationInfoJsonLd[Vocabularies_1.SKL.oauthFlow]), (0, Util_1.getValueIfDefined)(operationInfoJsonLd[Vocabularies_1.SKL.stage]), configuration, operationArgs);
275
- const mappedReturnValue = await this.performReturnValueMappingWithFrame(rawReturnValue.data, mapping, getOauthTokenVerb);
276
- await this.assertVerbReturnValueMatchesReturnTypeSchema(mappedReturnValue, getOauthTokenVerb);
277
- securityCredentialsSchema[Vocabularies_1.SKL.accessToken] = (0, Util_1.getValueIfDefined)(mappedReturnValue[Vocabularies_1.SKL.accessToken]);
278
- securityCredentialsSchema[Vocabularies_1.SKL.refreshToken] = (0, Util_1.getValueIfDefined)(mappedReturnValue[Vocabularies_1.SKL.refreshToken]);
279
- await this.save(securityCredentialsSchema);
280
- return { accessToken: (0, Util_1.getValueIfDefined)(securityCredentialsSchema[Vocabularies_1.SKL.accessToken]) };
281
- }
282
- getConfigurationFromSecurityCredentials(securityCredentialsSchema) {
283
- const username = (0, Util_1.getValueIfDefined)(securityCredentialsSchema[Vocabularies_1.SKL.clientId]);
284
- const password = (0, Util_1.getValueIfDefined)(securityCredentialsSchema[Vocabularies_1.SKL.clientSecret]);
285
- const accessToken = (0, Util_1.getValueIfDefined)(securityCredentialsSchema[Vocabularies_1.SKL.accessToken]);
286
- return { username, password, accessToken };
287
- }
288
- async assertVerbReturnValueMatchesReturnTypeSchema(returnValue, verb) {
289
- const returnTypeSchemaObject = verb[Vocabularies_1.SKL.returnValue];
290
- let report;
291
- if (returnValue && Object.keys(returnValue).length > 0 && returnTypeSchemaObject) {
292
- if (returnValue['@id']) {
293
- returnTypeSchemaObject[Vocabularies_1.SHACL.targetNode] = { '@id': returnValue['@id'] };
294
- }
295
- else {
296
- returnTypeSchemaObject[Vocabularies_1.SHACL.targetClass] = { '@id': returnValue['@type'] };
297
- }
298
- report = await this.convertToQuadsAndValidateAgainstShape(returnValue, returnTypeSchemaObject);
299
- }
300
- if (report && !report?.conforms) {
301
- throw new Error(`Return value ${returnValue['@id']} does not conform to the schema`);
302
- }
303
- }
304
- async convertToQuadsAndValidateAgainstShape(value, shape) {
305
- const valueAsQuads = await (0, Util_1.convertJsonLdToQuads)([value]);
306
- const shapeQuads = await (0, Util_1.convertJsonLdToQuads)(shape);
307
- const validator = new rdf_validate_shacl_1.default(shapeQuads);
308
- return validator.validate(valueAsQuads);
309
- }
310
- async performSecuritySchemeStageWithCredentials(operationInfo, operationArgs, account) {
311
- const integrationId = account[Vocabularies_1.SKL.integration]['@id'];
312
- const openApiDescription = await this.getOpenApiDescriptionForIntegration(integrationId);
313
- const securityCredentialsSchema = await this.findSecurityCredentialsForAccountIfDefined(account['@id']);
314
- let configuration;
315
- if (securityCredentialsSchema) {
316
- configuration = this.getConfigurationFromSecurityCredentials(securityCredentialsSchema);
317
- operationArgs.client_id = (0, Util_1.getValueIfDefined)(securityCredentialsSchema[Vocabularies_1.SKL.clientId]);
318
- }
319
- else {
320
- configuration = {};
321
- }
322
- const openApiExecutor = await this.createOpenApiOperationExecutorWithSpec(openApiDescription);
323
- return await openApiExecutor.executeSecuritySchemeStage((0, Util_1.getValueIfDefined)(operationInfo[Vocabularies_1.SKL.schemeName]), (0, Util_1.getValueIfDefined)(operationInfo[Vocabularies_1.SKL.oauthFlow]), (0, Util_1.getValueIfDefined)(operationInfo[Vocabularies_1.SKL.stage]), configuration, operationArgs);
324
- }
325
- async getDataFromDataSource(dataSourceId) {
326
- const dataSource = await this.findBy({ id: dataSourceId });
327
- if (dataSource['@type'] === Vocabularies_1.SKL.JsonDataSource) {
328
- const data = this.getDataFromJsonDataSource(dataSource);
329
- return { data };
330
- }
331
- throw new Error(`DataSource type ${dataSource['@type']} is not supported.`);
332
- }
333
- getDataFromJsonDataSource(dataSource) {
334
- if (dataSource[Vocabularies_1.SKL.source]) {
335
- const sourceValue = (0, Util_1.getValueIfDefined)(dataSource[Vocabularies_1.SKL.source]);
336
- return this.getJsonDataFromSource(sourceValue);
337
- }
338
- return (0, Util_1.getValueIfDefined)(dataSource[Vocabularies_1.SKL.data]);
339
- }
340
- getJsonDataFromSource(source) {
341
- if (this.inputFiles && source in this.inputFiles) {
342
- const file = this.inputFiles[source];
343
- return JSON.parse(file);
344
- }
345
- // eslint-disable-next-line unicorn/expiring-todo-comments
346
- // TODO add support for remote sources
347
- throw new Error(`Failed to get data from source ${source}`);
348
- }
349
- }
350
- exports.Skql = Skql;
351
- //# sourceMappingURL=Skql.js.map
package/dist/Skql.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Skql.js","sourceRoot":"","sources":["../src/Skql.ts"],"names":[],"mappings":";;;;;;AAMA,mFAA8E;AAE9E,kDAA0B;AAI1B,4EAAgD;AAEhD,6CAA0C;AAE1C,4EAAyE;AAGzE,4EAAyE;AAGzE,sCAIqB;AAErB,sDAAuD;AAkBvD,MAAa,IAAI;IAMf,YAAmB,OAAoB;QACrC,QAAQ,OAAO,CAAC,IAAI,EAAE;YACpB,KAAK,QAAQ;gBACX,IAAI,CAAC,OAAO,GAAG,IAAI,uCAAkB,CAAC,OAAO,CAAC,CAAC;gBAC/C,MAAM;YACR,KAAK,QAAQ;gBACX,IAAI,CAAC,OAAO,GAAG,IAAI,uCAAkB,CAAC,OAAO,CAAC,CAAC;gBAC/C,MAAM;YACR;gBACE,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;SAChE;QAED,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;QAE3D,sCAAsC;QACtC,MAAM,cAAc,GAAG,CAAC,SAAwB,EAAE,QAAgB,EAAe,EAAE,CACjF,KAAK,EAAC,QAAoB,EAAuB,EAAE,CACjD,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,QAAQ,CAA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IAAA,wBAAiB,EAAS,UAAU,CAAC,kBAAG,CAAC,MAAM,CAAC,CAAE,CAAC;YACvE,OAAO,IAAI,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;SAChD;QACD,OAAO,IAAA,wBAAiB,EAAa,UAAU,CAAC,kBAAG,CAAC,IAAI,CAAC,CAAE,CAAC;IAC9D,CAAC;IAEO,qBAAqB,CAAC,MAAc;QAC1C,IAAI,IAAI,CAAC,UAAU,IAAI,MAAM,IAAI,IAAI,CAAC,UAAU,EAAE;YAChD,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YACrC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SACzB;QACD,0DAA0D;QAC1D,sCAAsC;QACtC,MAAM,IAAI,KAAK,CAAC,kCAAkC,MAAM,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF;AAreD,oBAqeC"}
@@ -1,12 +0,0 @@
1
- export declare type AggregateOperatorType = 'max';
2
- export interface AggregateOperatorArgs<T> {
3
- operator: AggregateOperatorType;
4
- value: T;
5
- }
6
- export declare class AggregateOperator<T> {
7
- readonly type = "aggregate";
8
- readonly operator: AggregateOperatorType;
9
- readonly value: T;
10
- constructor(args: AggregateOperatorArgs<T>);
11
- static isAggregateOperator(value: any): boolean;
12
- }
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AggregateOperator = void 0;
4
- class AggregateOperator {
5
- constructor(args) {
6
- this.type = 'aggregate';
7
- this.operator = args.operator;
8
- this.value = args.value;
9
- }
10
- static isAggregateOperator(value) {
11
- return typeof value === 'object' &&
12
- 'type' in value &&
13
- value.type === 'aggregate';
14
- }
15
- }
16
- exports.AggregateOperator = AggregateOperator;
17
- //# sourceMappingURL=AggregateOperator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AggregateOperator.js","sourceRoot":"","sources":["../../src/storage/AggregateOperator.ts"],"names":[],"mappings":";;;AAOA,MAAa,iBAAiB;IAK5B,YAAmB,IAA8B;QAJjC,SAAI,GAAG,WAAW,CAAC;QAKjC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IAC1B,CAAC;IAEM,MAAM,CAAC,mBAAmB,CAAC,KAAU;QAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ;YAC9B,MAAM,IAAI,KAAK;YACf,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC;IAC/B,CAAC;CACF;AAfD,8CAeC"}
@@ -1,28 +0,0 @@
1
- import type { Entity } from '../util/Types';
2
- import type { FindOneOptions, FindAllOptions, FindOptionsWhere } from './FindOptionsTypes';
3
- import type { QueryAdapter } from './QueryAdapter';
4
- /**
5
- * A {@link QueryAdapter} that stores data in memory.
6
- */
7
- export declare class MemoryQueryAdapter implements QueryAdapter {
8
- private readonly schemas;
9
- constructor(schemas: Entity[]);
10
- find(options?: FindOneOptions): Promise<Entity | null>;
11
- findBy(where: FindOptionsWhere): Promise<Entity | null>;
12
- findAll(options?: FindAllOptions): Promise<Entity[]>;
13
- findAllBy(where: FindOptionsWhere): Promise<Entity[]>;
14
- private entityMatchesQuery;
15
- private entityMatchesField;
16
- private fieldValueMatchesField;
17
- private findOptionWhereMatchesNodeObject;
18
- private handleOperator;
19
- private isInstanceOf;
20
- private getSubClassesOf;
21
- exists(where: FindOptionsWhere): Promise<boolean>;
22
- save(entity: Entity): Promise<Entity>;
23
- save(entities: Entity[]): Promise<Entity[]>;
24
- private saveEntity;
25
- destroy(entity: Entity): Promise<Entity>;
26
- destroy(entities: Entity[]): Promise<Entity[]>;
27
- private destroyEntity;
28
- }
@@ -1,215 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemoryQueryAdapter = void 0;
4
- const TripleUtil_1 = require("../util/TripleUtil");
5
- const Util_1 = require("../util/Util");
6
- const Vocabularies_1 = require("../util/Vocabularies");
7
- const FindOperator_1 = require("./FindOperator");
8
- /**
9
- * A {@link QueryAdapter} that stores data in memory.
10
- */
11
- class MemoryQueryAdapter {
12
- constructor(schemas) {
13
- this.schemas = {};
14
- for (const schema of schemas) {
15
- this.schemas[schema['@id']] = schema;
16
- }
17
- }
18
- async find(options) {
19
- if (options?.where?.id && Object.keys(options.where).length === 1 && typeof options.where.id === 'string') {
20
- return this.schemas[options.where.id] ?? null;
21
- }
22
- if (options?.where) {
23
- for (const entity of Object.values(this.schemas)) {
24
- const matches = await this.entityMatchesQuery(entity, options.where);
25
- if (matches) {
26
- return entity;
27
- }
28
- }
29
- return null;
30
- }
31
- return Object.values(this.schemas)[0] ?? null;
32
- }
33
- async findBy(where) {
34
- return this.find({ where });
35
- }
36
- async findAll(options) {
37
- let results = [];
38
- if (options?.where?.id && Object.keys(options.where).length === 1 && typeof options.where.id === 'string') {
39
- const schema = this.schemas[options.where.id];
40
- if (schema) {
41
- results = [schema];
42
- }
43
- }
44
- else if (options?.where) {
45
- for (const entity of Object.values(this.schemas)) {
46
- const matches = await this.entityMatchesQuery(entity, options.where);
47
- if (matches) {
48
- results.push(entity);
49
- }
50
- }
51
- }
52
- else {
53
- results = Object.values(this.schemas);
54
- }
55
- if (options?.limit ?? options?.offset) {
56
- const start = options?.offset ?? 0;
57
- const end = options?.limit && options?.offset
58
- ? options.offset + options.limit
59
- : options?.limit ?? undefined;
60
- return results.slice(start, end);
61
- }
62
- return results;
63
- }
64
- async findAllBy(where) {
65
- return this.findAll({ where });
66
- }
67
- async entityMatchesQuery(entity, where) {
68
- for (const [fieldName, fieldValue] of Object.entries(where)) {
69
- const matches = await this.entityMatchesField(entity, fieldName, fieldValue);
70
- if (!matches) {
71
- return false;
72
- }
73
- }
74
- return true;
75
- }
76
- async entityMatchesField(entity, fieldName, fieldValue) {
77
- if (FindOperator_1.FindOperator.isFindOperator(fieldValue)) {
78
- return await this.handleOperator(fieldValue.operator, {
79
- in: async () => {
80
- const values = fieldValue.value;
81
- for (const valueItem of values) {
82
- if (await this.entityMatchesField(entity, fieldName, valueItem)) {
83
- return true;
84
- }
85
- }
86
- return false;
87
- },
88
- not: async () => {
89
- if (FindOperator_1.FindOperator.isFindOperator(fieldValue.value)) {
90
- return !await this.entityMatchesField(entity, fieldName, fieldValue.value);
91
- }
92
- const valueItem = fieldValue.value;
93
- return !await this.entityMatchesField(entity, fieldName, valueItem);
94
- },
95
- equal: async () => {
96
- const valueItem = fieldValue.value;
97
- return this.entityMatchesField(entity, fieldName, valueItem);
98
- },
99
- });
100
- }
101
- if (fieldName === 'id') {
102
- return entity['@id'] === fieldValue;
103
- }
104
- if (fieldName === 'type') {
105
- return this.isInstanceOf(entity, fieldValue);
106
- }
107
- if (Array.isArray(fieldValue)) {
108
- for (const valueItem of fieldValue) {
109
- if (!await this.entityMatchesField(entity, fieldName, valueItem)) {
110
- return false;
111
- }
112
- }
113
- return true;
114
- }
115
- if (typeof fieldValue === 'object') {
116
- if (Array.isArray(entity[fieldName])) {
117
- for (const subFieldValue of entity[fieldName]) {
118
- const matches = await this.findOptionWhereMatchesNodeObject(fieldValue, subFieldValue);
119
- if (matches) {
120
- return true;
121
- }
122
- }
123
- return false;
124
- }
125
- if (typeof entity[fieldName] === 'object') {
126
- return await this.findOptionWhereMatchesNodeObject(fieldValue, entity[fieldName]);
127
- }
128
- return false;
129
- }
130
- if (Array.isArray(entity[fieldName])) {
131
- return entity[fieldName].some((field) => this.fieldValueMatchesField(fieldValue, field));
132
- }
133
- return this.fieldValueMatchesField(fieldValue, entity[fieldName]);
134
- }
135
- fieldValueMatchesField(fieldValue, field) {
136
- if (typeof field === 'object') {
137
- if (field['@id']) {
138
- return field['@id'] === fieldValue;
139
- }
140
- if (field['@value']) {
141
- const jsValue = (0, TripleUtil_1.toJSValueFromDataType)(field['@value'], field['@type']);
142
- return jsValue === fieldValue;
143
- }
144
- }
145
- return field === fieldValue;
146
- }
147
- async findOptionWhereMatchesNodeObject(fieldValue, nodeObject) {
148
- if (nodeObject['@id'] && Object.keys(nodeObject).length === 1) {
149
- const subEntity = await this.findBy({ id: nodeObject['@id'] });
150
- if (subEntity) {
151
- return this.entityMatchesQuery(subEntity, fieldValue);
152
- }
153
- return false;
154
- }
155
- return this.entityMatchesQuery(nodeObject, fieldValue);
156
- }
157
- async handleOperator(operator, operatorHandlers) {
158
- if (operator in operatorHandlers) {
159
- return await operatorHandlers[operator]();
160
- }
161
- throw new Error(`Unsupported operator "${operator}"`);
162
- }
163
- isInstanceOf(entity, targetClass) {
164
- const classes = this.getSubClassesOf(targetClass);
165
- const entityTypes = (0, Util_1.ensureArray)(entity['@type']);
166
- return entityTypes.some((type) => classes.includes(type));
167
- }
168
- getSubClassesOf(targetClass) {
169
- // Cache subclassesOf
170
- return Object.values(this.schemas).reduce((subClasses, schema) => {
171
- const subClassOf = (0, Util_1.ensureArray)(schema[Vocabularies_1.RDFS.subClassOf]);
172
- const isSubClassOfTarget = subClassOf.some((subClass) => subClass['@id'] === targetClass);
173
- if (isSubClassOfTarget) {
174
- subClasses = [
175
- ...subClasses,
176
- schema['@id'],
177
- ...this.getSubClassesOf(schema['@id']),
178
- ];
179
- }
180
- return subClasses;
181
- }, [targetClass]);
182
- }
183
- async exists(where) {
184
- const res = await this.find({ where });
185
- return res !== null;
186
- }
187
- async save(entityOrEntities) {
188
- if (Array.isArray(entityOrEntities)) {
189
- return entityOrEntities.map((entity) => this.saveEntity(entity));
190
- }
191
- return this.saveEntity(entityOrEntities);
192
- }
193
- saveEntity(entity) {
194
- const savedEntity = { ...entity };
195
- this.schemas[entity['@id']] = savedEntity;
196
- return savedEntity;
197
- }
198
- async destroy(entityOrEntities) {
199
- if (Array.isArray(entityOrEntities)) {
200
- return entityOrEntities.map((entity) => this.destroyEntity(entity));
201
- }
202
- return this.destroyEntity(entityOrEntities);
203
- }
204
- destroyEntity(entity) {
205
- const existingEntity = this.schemas[entity['@id']];
206
- if (!existingEntity) {
207
- throw new Error(`Entity with id ${entity['@id']} does not exist.`);
208
- }
209
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
210
- delete this.schemas[existingEntity['@id']];
211
- return existingEntity;
212
- }
213
- }
214
- exports.MemoryQueryAdapter = MemoryQueryAdapter;
215
- //# sourceMappingURL=MemoryQueryAdapter.js.map