@comake/skl-js-engine 1.4.3 → 1.5.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.
@@ -25,11 +25,20 @@ export declare class SKLEngine implements SKLEngineInterface {
25
25
  private readonly skdsEndpointUrl;
26
26
  private readonly scriptPath;
27
27
  private readonly logger;
28
+ private readonly readCache?;
29
+ private readonly readCachePolicy?;
30
+ private readonly readCacheNamespace?;
31
+ private readonly readCacheSingleflight;
28
32
  constructor(options: SklEngineOptions);
29
33
  setCodeExecutor(codeExecutor: ICodeExecutor): void;
30
34
  executeRawQuery<T extends RawQueryResult>(query: string): Promise<T[]>;
31
35
  executeRawUpdate(query: string): Promise<void>;
32
36
  executeRawConstructQuery(query: string, frame?: Frame): Promise<GraphObject>;
37
+ private cloneForReadCache;
38
+ private stripBypassCacheFromFindOneOptions;
39
+ private stripBypassCacheFromFindAllOptions;
40
+ private stripBypassCacheFromWhere;
41
+ private runReadWithCache;
33
42
  find(options?: FindOneOptions): Promise<Entity>;
34
43
  findBy(where: FindOptionsWhere, notFoundErrorMessage?: string): Promise<Entity>;
35
44
  findByIfExists(options: FindOptionsWhere): Promise<Entity | undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"SklEngine.d.ts","sourceRoot":"","sources":["../src/SklEngine.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAqB,WAAW,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAgBhD,OAAO,EAAE,WAAW,EAAyB,MAAM,qBAAqB,CAAC;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,E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O,CAAC,yBAAyB;IAQjC,OAAO,CAAC,qBAAqB;IAiB7B,OAAO,CAAC,0BAA0B;IAKlC,OAAO,CAAC,0BAA0B;IAgBlC,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,gBAAgB;IAwCxB,OAAO,CAAC,gBAAgB;YA2DV,iBAAiB;YAqBjB,wBAAwB;IA8CtC,IAAI,KAAK,IAAI,OAAO,WAAW,CAE9B;IAEY,qBAAqB,CAAC,YAAY,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CA+BpF"}
package/dist/SklEngine.js CHANGED
@@ -25,16 +25,22 @@ const SequencePath_1 = require("./storage/operator/SequencePath");
25
25
  const ZeroOrMorePath_1 = require("./storage/operator/ZeroOrMorePath");
26
26
  const SparqlQueryAdapter_1 = require("./storage/query-adapter/sparql/SparqlQueryAdapter");
27
27
  const PerformanceLogger_1 = require("./util/PerformanceLogger");
28
+ const ReadCacheHelper_1 = require("./util/ReadCacheHelper");
28
29
  const Util_1 = require("./util/Util");
29
30
  const Vocabularies_1 = require("./util/Vocabularies");
31
+ const DEFAULT_READ_CACHE_TTL_MS = 60000;
30
32
  class SKLEngine {
31
33
  constructor(options) {
34
+ this.readCacheSingleflight = new ReadCacheHelper_1.ReadCacheSingleflight();
32
35
  this.queryAdapter = new SparqlQueryAdapter_1.SparqlQueryAdapter(options);
33
36
  this.disableValidation = options.disableValidation;
34
37
  this.globalCallbacks = options.callbacks;
35
38
  this.inputFiles = options.inputFiles;
36
39
  this.skdsEndpointUrl = options.endpointUrl;
37
40
  this.scriptPath = options.scriptPath;
41
+ this.readCache = options.readCache;
42
+ this.readCachePolicy = options.readCachePolicy;
43
+ this.readCacheNamespace = options.readCacheNamespace;
38
44
  if (options.functions) {
39
45
  this.functions = Object.fromEntries(Object.entries(options.functions).map(([key, func]) => [
40
46
  key,
@@ -64,19 +70,102 @@ class SKLEngine {
64
70
  async executeRawConstructQuery(query, frame) {
65
71
  return await this.queryAdapter.executeRawConstructQuery(query, frame);
66
72
  }
73
+ cloneForReadCache(value) {
74
+ try {
75
+ return structuredClone(value);
76
+ }
77
+ catch {
78
+ return value;
79
+ }
80
+ }
81
+ stripBypassCacheFromFindOneOptions(options) {
82
+ if (!options) {
83
+ return options;
84
+ }
85
+ const { bypassCache, ...rest } = options;
86
+ return rest;
87
+ }
88
+ stripBypassCacheFromFindAllOptions(options) {
89
+ if (!options) {
90
+ return options;
91
+ }
92
+ const { bypassCache, ...rest } = options;
93
+ return rest;
94
+ }
95
+ stripBypassCacheFromWhere(where) {
96
+ if (!where) {
97
+ return where;
98
+ }
99
+ const { bypassCache, ...rest } = where;
100
+ return rest;
101
+ }
102
+ async runReadWithCache(params) {
103
+ if (params.bypassCache) {
104
+ return await params.execute();
105
+ }
106
+ if (!this.readCache || !this.readCachePolicy) {
107
+ return await params.execute();
108
+ }
109
+ const policyDecision = this.readCachePolicy({
110
+ operation: params.operation,
111
+ args: params.args,
112
+ endpointUrl: this.skdsEndpointUrl,
113
+ namespace: this.readCacheNamespace
114
+ });
115
+ if (!policyDecision.cache) {
116
+ return await params.execute();
117
+ }
118
+ const ttlMs = policyDecision.ttlMs ?? DEFAULT_READ_CACHE_TTL_MS;
119
+ if (ttlMs <= 0) {
120
+ return await params.execute();
121
+ }
122
+ const cacheKey = (0, ReadCacheHelper_1.buildReadCacheKey)({
123
+ operation: params.operation,
124
+ args: params.args,
125
+ endpointUrl: this.skdsEndpointUrl,
126
+ namespace: this.readCacheNamespace,
127
+ keyHint: policyDecision.keyHint
128
+ });
129
+ return await this.readCacheSingleflight.do(cacheKey, async () => {
130
+ try {
131
+ const cached = await this.readCache?.get(cacheKey);
132
+ if (cached !== undefined) {
133
+ return this.cloneForReadCache(cached);
134
+ }
135
+ }
136
+ catch (error) {
137
+ this.logger.debug('Read cache lookup failed; continuing without cache', error);
138
+ }
139
+ const result = await params.execute();
140
+ try {
141
+ await this.readCache?.set(cacheKey, this.cloneForReadCache(result), ttlMs);
142
+ }
143
+ catch (error) {
144
+ this.logger.debug('Read cache write failed; continuing without cache', error);
145
+ }
146
+ return result;
147
+ });
148
+ }
67
149
  async find(options) {
150
+ const bypassCache = options?.bypassCache;
151
+ const optionsWithoutBypass = this.stripBypassCacheFromFindOneOptions(options);
68
152
  return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.find', async () => {
69
153
  const context = {
70
154
  entities: [],
71
155
  operation: 'find',
72
- operationParameters: { options },
156
+ operationParameters: { options: optionsWithoutBypass },
73
157
  sklEngine: this
74
158
  };
75
159
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.BEFORE, context);
76
160
  try {
77
- const entity = await this.queryAdapter.find(options);
161
+ const entity = await this.runReadWithCache({
162
+ operation: 'find',
163
+ args: [optionsWithoutBypass],
164
+ bypassCache,
165
+ execute: async () => await this.queryAdapter.find(optionsWithoutBypass)
166
+ });
78
167
  if (!entity) {
79
- throw new Error(`No schema found with fields matching ${JSON.stringify(options)}`);
168
+ throw new Error(`No schema found with fields matching ${JSON.stringify(optionsWithoutBypass)}`);
80
169
  }
81
170
  const updatedContext = { ...context, entities: [entity] };
82
171
  const afterHookResult = await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.AFTER, updatedContext, entity);
@@ -86,31 +175,38 @@ class SKLEngine {
86
175
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.ERROR, context, error);
87
176
  throw error;
88
177
  }
89
- }, { options });
178
+ }, { options: optionsWithoutBypass });
90
179
  }
91
180
  async findBy(where, notFoundErrorMessage) {
181
+ const bypassCache = where?.bypassCache;
182
+ const whereWithoutBypass = this.stripBypassCacheFromWhere(where);
92
183
  return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.findBy', async () => {
93
184
  const context = {
94
185
  entities: [],
95
186
  operation: 'findBy',
96
- operationParameters: { where },
187
+ operationParameters: { where: whereWithoutBypass },
97
188
  sklEngine: this
98
189
  };
99
190
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.BEFORE, context);
100
191
  try {
101
- const entity = await this.queryAdapter.findBy(where);
192
+ const entity = await this.runReadWithCache({
193
+ operation: 'findBy',
194
+ args: [whereWithoutBypass, notFoundErrorMessage],
195
+ bypassCache,
196
+ execute: async () => await this.queryAdapter.findBy(whereWithoutBypass)
197
+ });
102
198
  if (entity) {
103
199
  const updatedContext = { ...context, entities: [entity] };
104
200
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.AFTER, updatedContext, entity);
105
201
  return entity;
106
202
  }
107
- throw new Error(notFoundErrorMessage ?? `No schema found with fields matching ${JSON.stringify(where)}`);
203
+ throw new Error(notFoundErrorMessage ?? `No schema found with fields matching ${JSON.stringify(whereWithoutBypass)}`);
108
204
  }
109
205
  catch (error) {
110
206
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.ERROR, context, error);
111
207
  throw error;
112
208
  }
113
- }, { where });
209
+ }, { where: whereWithoutBypass });
114
210
  }
115
211
  async findByIfExists(options) {
116
212
  try {
@@ -122,16 +218,23 @@ class SKLEngine {
122
218
  }
123
219
  }
124
220
  async findAll(options) {
221
+ const bypassCache = options?.bypassCache;
222
+ const optionsWithoutBypass = this.stripBypassCacheFromFindAllOptions(options);
125
223
  return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.findAll', async () => {
126
224
  const context = {
127
225
  entities: [],
128
226
  operation: 'findAll',
129
- operationParameters: { options },
227
+ operationParameters: { options: optionsWithoutBypass },
130
228
  sklEngine: this
131
229
  };
132
230
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.BEFORE, context);
133
231
  try {
134
- const entities = await this.queryAdapter.findAll(options);
232
+ const entities = await this.runReadWithCache({
233
+ operation: 'findAll',
234
+ args: [optionsWithoutBypass],
235
+ bypassCache,
236
+ execute: async () => await this.queryAdapter.findAll(optionsWithoutBypass)
237
+ });
135
238
  const updatedContext = { ...context, entities };
136
239
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.AFTER, updatedContext, entities);
137
240
  return entities;
@@ -140,7 +243,7 @@ class SKLEngine {
140
243
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.ERROR, context, error);
141
244
  throw error;
142
245
  }
143
- }, { options });
246
+ }, { options: optionsWithoutBypass });
144
247
  }
145
248
  async groupBy(options) {
146
249
  return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.groupBy', async () => {
@@ -188,7 +291,14 @@ class SKLEngine {
188
291
  return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.exists', async () => this.queryAdapter.exists(options), { options });
189
292
  }
190
293
  async count(options) {
191
- return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.count', async () => this.queryAdapter.count(options), { options });
294
+ const bypassCache = options?.bypassCache;
295
+ const optionsWithoutBypass = this.stripBypassCacheFromFindAllOptions(options);
296
+ return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.count', async () => await this.runReadWithCache({
297
+ operation: 'count',
298
+ args: [optionsWithoutBypass],
299
+ bypassCache,
300
+ execute: async () => await this.queryAdapter.count(optionsWithoutBypass)
301
+ }), { options: optionsWithoutBypass });
192
302
  }
193
303
  async save(entityOrEntities, options) {
194
304
  return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.save', async () => {