@comake/skl-js-engine 1.4.3 → 1.5.1

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,22 @@ 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 wrapReadCacheValue;
39
+ private isReadCacheEnvelope;
40
+ private stripBypassCacheFromFindOneOptions;
41
+ private stripBypassCacheFromFindAllOptions;
42
+ private stripBypassCacheFromWhere;
43
+ private runReadWithCache;
33
44
  find(options?: FindOneOptions): Promise<Entity>;
34
45
  findBy(where: FindOptionsWhere, notFoundErrorMessage?: string): Promise<Entity>;
35
46
  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;AA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C,OAAO,CAAC,4CAA4C;YAOtC,kDAAkD;YAgElD,qCAAqC;YAUrC,8CAA8C;YAuC9C,qBAAqB;IAYnC,OAAO,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,23 @@ 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;
32
+ const READ_CACHE_ENVELOPE_MARKER = '__sklReadCacheEnvelopeV1';
30
33
  class SKLEngine {
31
34
  constructor(options) {
35
+ this.readCacheSingleflight = new ReadCacheHelper_1.ReadCacheSingleflight();
32
36
  this.queryAdapter = new SparqlQueryAdapter_1.SparqlQueryAdapter(options);
33
37
  this.disableValidation = options.disableValidation;
34
38
  this.globalCallbacks = options.callbacks;
35
39
  this.inputFiles = options.inputFiles;
36
40
  this.skdsEndpointUrl = options.endpointUrl;
37
41
  this.scriptPath = options.scriptPath;
42
+ this.readCache = options.readCache;
43
+ this.readCachePolicy = options.readCachePolicy;
44
+ this.readCacheNamespace = options.readCacheNamespace;
38
45
  if (options.functions) {
39
46
  this.functions = Object.fromEntries(Object.entries(options.functions).map(([key, func]) => [
40
47
  key,
@@ -64,19 +71,117 @@ class SKLEngine {
64
71
  async executeRawConstructQuery(query, frame) {
65
72
  return await this.queryAdapter.executeRawConstructQuery(query, frame);
66
73
  }
74
+ cloneForReadCache(value) {
75
+ try {
76
+ return structuredClone(value);
77
+ }
78
+ catch {
79
+ return value;
80
+ }
81
+ }
82
+ wrapReadCacheValue(value) {
83
+ return {
84
+ [READ_CACHE_ENVELOPE_MARKER]: true,
85
+ value
86
+ };
87
+ }
88
+ isReadCacheEnvelope(value) {
89
+ if (!value || typeof value !== 'object') {
90
+ return false;
91
+ }
92
+ return value[READ_CACHE_ENVELOPE_MARKER] === true;
93
+ }
94
+ stripBypassCacheFromFindOneOptions(options) {
95
+ if (!options) {
96
+ return options;
97
+ }
98
+ const { bypassCache, ...rest } = options;
99
+ return rest;
100
+ }
101
+ stripBypassCacheFromFindAllOptions(options) {
102
+ if (!options) {
103
+ return options;
104
+ }
105
+ const { bypassCache, ...rest } = options;
106
+ return rest;
107
+ }
108
+ stripBypassCacheFromWhere(where) {
109
+ if (!where) {
110
+ return where;
111
+ }
112
+ const { bypassCache, ...rest } = where;
113
+ return rest;
114
+ }
115
+ async runReadWithCache(params) {
116
+ if (params.bypassCache) {
117
+ return await params.execute();
118
+ }
119
+ if (!this.readCache || !this.readCachePolicy) {
120
+ return await params.execute();
121
+ }
122
+ const policyDecision = this.readCachePolicy({
123
+ operation: params.operation,
124
+ args: params.args,
125
+ endpointUrl: this.skdsEndpointUrl,
126
+ namespace: this.readCacheNamespace
127
+ });
128
+ if (!policyDecision.cache) {
129
+ return await params.execute();
130
+ }
131
+ const ttlMs = policyDecision.ttlMs ?? DEFAULT_READ_CACHE_TTL_MS;
132
+ if (ttlMs <= 0) {
133
+ return await params.execute();
134
+ }
135
+ const cacheKey = (0, ReadCacheHelper_1.buildReadCacheKey)({
136
+ operation: params.operation,
137
+ args: params.args,
138
+ endpointUrl: this.skdsEndpointUrl,
139
+ namespace: this.readCacheNamespace,
140
+ keyHint: policyDecision.keyHint
141
+ });
142
+ return await this.readCacheSingleflight.do(cacheKey, async () => {
143
+ try {
144
+ const cached = await this.readCache?.get(cacheKey);
145
+ if (cached !== undefined) {
146
+ if (this.isReadCacheEnvelope(cached)) {
147
+ return this.cloneForReadCache(cached.value);
148
+ }
149
+ return this.cloneForReadCache(cached);
150
+ }
151
+ }
152
+ catch (error) {
153
+ this.logger.debug('Read cache lookup failed; continuing without cache', error);
154
+ }
155
+ const result = await params.execute();
156
+ try {
157
+ await this.readCache?.set(cacheKey, this.wrapReadCacheValue(this.cloneForReadCache(result)), ttlMs);
158
+ }
159
+ catch (error) {
160
+ this.logger.debug('Read cache write failed; continuing without cache', error);
161
+ }
162
+ return result;
163
+ });
164
+ }
67
165
  async find(options) {
166
+ const bypassCache = options?.bypassCache;
167
+ const optionsWithoutBypass = this.stripBypassCacheFromFindOneOptions(options);
68
168
  return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.find', async () => {
69
169
  const context = {
70
170
  entities: [],
71
171
  operation: 'find',
72
- operationParameters: { options },
172
+ operationParameters: { options: optionsWithoutBypass },
73
173
  sklEngine: this
74
174
  };
75
175
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.BEFORE, context);
76
176
  try {
77
- const entity = await this.queryAdapter.find(options);
177
+ const entity = await this.runReadWithCache({
178
+ operation: 'find',
179
+ args: [optionsWithoutBypass],
180
+ bypassCache,
181
+ execute: async () => await this.queryAdapter.find(optionsWithoutBypass)
182
+ });
78
183
  if (!entity) {
79
- throw new Error(`No schema found with fields matching ${JSON.stringify(options)}`);
184
+ throw new Error(`No schema found with fields matching ${JSON.stringify(optionsWithoutBypass)}`);
80
185
  }
81
186
  const updatedContext = { ...context, entities: [entity] };
82
187
  const afterHookResult = await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.AFTER, updatedContext, entity);
@@ -86,31 +191,38 @@ class SKLEngine {
86
191
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.ERROR, context, error);
87
192
  throw error;
88
193
  }
89
- }, { options });
194
+ }, { options: optionsWithoutBypass });
90
195
  }
91
196
  async findBy(where, notFoundErrorMessage) {
197
+ const bypassCache = where?.bypassCache;
198
+ const whereWithoutBypass = this.stripBypassCacheFromWhere(where);
92
199
  return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.findBy', async () => {
93
200
  const context = {
94
201
  entities: [],
95
202
  operation: 'findBy',
96
- operationParameters: { where },
203
+ operationParameters: { where: whereWithoutBypass },
97
204
  sklEngine: this
98
205
  };
99
206
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.BEFORE, context);
100
207
  try {
101
- const entity = await this.queryAdapter.findBy(where);
208
+ const entity = await this.runReadWithCache({
209
+ operation: 'findBy',
210
+ args: [whereWithoutBypass, notFoundErrorMessage],
211
+ bypassCache,
212
+ execute: async () => await this.queryAdapter.findBy(whereWithoutBypass)
213
+ });
102
214
  if (entity) {
103
215
  const updatedContext = { ...context, entities: [entity] };
104
216
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.AFTER, updatedContext, entity);
105
217
  return entity;
106
218
  }
107
- throw new Error(notFoundErrorMessage ?? `No schema found with fields matching ${JSON.stringify(where)}`);
219
+ throw new Error(notFoundErrorMessage ?? `No schema found with fields matching ${JSON.stringify(whereWithoutBypass)}`);
108
220
  }
109
221
  catch (error) {
110
222
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.ERROR, context, error);
111
223
  throw error;
112
224
  }
113
- }, { where });
225
+ }, { where: whereWithoutBypass });
114
226
  }
115
227
  async findByIfExists(options) {
116
228
  try {
@@ -122,16 +234,23 @@ class SKLEngine {
122
234
  }
123
235
  }
124
236
  async findAll(options) {
237
+ const bypassCache = options?.bypassCache;
238
+ const optionsWithoutBypass = this.stripBypassCacheFromFindAllOptions(options);
125
239
  return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.findAll', async () => {
126
240
  const context = {
127
241
  entities: [],
128
242
  operation: 'findAll',
129
- operationParameters: { options },
243
+ operationParameters: { options: optionsWithoutBypass },
130
244
  sklEngine: this
131
245
  };
132
246
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.BEFORE, context);
133
247
  try {
134
- const entities = await this.queryAdapter.findAll(options);
248
+ const entities = await this.runReadWithCache({
249
+ operation: 'findAll',
250
+ args: [optionsWithoutBypass],
251
+ bypassCache,
252
+ execute: async () => await this.queryAdapter.findAll(optionsWithoutBypass)
253
+ });
135
254
  const updatedContext = { ...context, entities };
136
255
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.AFTER, updatedContext, entities);
137
256
  return entities;
@@ -140,7 +259,7 @@ class SKLEngine {
140
259
  await globalHooks_1.globalHooks.execute(globalHooks_1.HookTypes.READ, globalHooks_1.HookStages.ERROR, context, error);
141
260
  throw error;
142
261
  }
143
- }, { options });
262
+ }, { options: optionsWithoutBypass });
144
263
  }
145
264
  async groupBy(options) {
146
265
  return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.groupBy', async () => {
@@ -188,7 +307,14 @@ class SKLEngine {
188
307
  return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.exists', async () => this.queryAdapter.exists(options), { options });
189
308
  }
190
309
  async count(options) {
191
- return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.count', async () => this.queryAdapter.count(options), { options });
310
+ const bypassCache = options?.bypassCache;
311
+ const optionsWithoutBypass = this.stripBypassCacheFromFindAllOptions(options);
312
+ return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.count', async () => await this.runReadWithCache({
313
+ operation: 'count',
314
+ args: [optionsWithoutBypass],
315
+ bypassCache,
316
+ execute: async () => await this.queryAdapter.count(optionsWithoutBypass)
317
+ }), { options: optionsWithoutBypass });
192
318
  }
193
319
  async save(entityOrEntities, options) {
194
320
  return PerformanceLogger_1.PerformanceLogger.withSpanRoot('SklEngine.save', async () => {