@utaba/deep-memory-storage-sqlserver 0.8.0 → 0.9.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/index.cjs CHANGED
@@ -319,6 +319,42 @@ END;
319
319
  }
320
320
 
321
321
  // src/SqlServerStorageProvider.ts
322
+ var PROVIDER_NAME = "sqlserver";
323
+ var TRACKED_METHODS = {
324
+ ensureSchema: () => void 0,
325
+ createRepository: (args) => {
326
+ const cfg = args[0];
327
+ return cfg?.repositoryId;
328
+ },
329
+ getRepository: (args) => args[0],
330
+ listRepositories: () => void 0,
331
+ updateRepository: (args) => args[0],
332
+ deleteRepository: (args) => args[0],
333
+ deleteAllContents: (args) => args[0],
334
+ getRepositoryStats: (args) => args[0],
335
+ getVocabulary: (args) => args[0],
336
+ saveVocabulary: (args) => args[0],
337
+ getVocabularyChangeLog: (args) => args[0],
338
+ createEntity: (args) => args[0],
339
+ getEntity: (args) => args[0],
340
+ getEntityBySlug: (args) => args[0],
341
+ getEntities: (args) => args[0],
342
+ updateEntity: (args) => args[0],
343
+ deleteEntity: (args) => args[0],
344
+ deleteEntities: (args) => args[0],
345
+ deleteEntitiesByType: (args) => args[0],
346
+ findEntities: (args) => args[0],
347
+ createRelationship: (args) => args[0],
348
+ getRelationship: (args) => args[0],
349
+ getEntityRelationships: (args) => args[0],
350
+ deleteRelationship: (args) => args[0],
351
+ deleteRelationships: (args) => args[0],
352
+ deleteRelationshipsByType: (args) => args[0],
353
+ exploreNeighborhood: (args) => args[0],
354
+ findPaths: (args) => args[0],
355
+ getTimeline: (args) => args[0],
356
+ importBulk: (args) => args[0]
357
+ };
322
358
  var ENTITY_COLS_LIGHT = [
323
359
  "entity_id",
324
360
  "slug",
@@ -430,6 +466,53 @@ var SqlServerStorageProvider = class {
430
466
  this.config = config;
431
467
  this.schema = config.schema ?? "dbo";
432
468
  this.ownsPool = !(config.connection instanceof import_mssql.default.ConnectionPool);
469
+ const safeSink = (0, import_deep_memory.createSafeSink)(config.reportUsage);
470
+ if (safeSink) {
471
+ return new Proxy(this, {
472
+ get(target, prop, receiver) {
473
+ const value = Reflect.get(target, prop, receiver);
474
+ if (typeof prop !== "string" || typeof value !== "function") return value;
475
+ const extractRepoId = TRACKED_METHODS[prop];
476
+ if (!extractRepoId) return value;
477
+ const method = value;
478
+ return (...args) => {
479
+ const start = Date.now();
480
+ const repositoryId = extractRepoId(args);
481
+ const emit = () => {
482
+ safeSink({
483
+ provider: PROVIDER_NAME,
484
+ operation: prop,
485
+ unit: "ms",
486
+ value: Date.now() - start,
487
+ ...repositoryId ? { repositoryId } : {},
488
+ timestamp: /* @__PURE__ */ new Date()
489
+ });
490
+ };
491
+ let result;
492
+ try {
493
+ result = method.apply(target, args);
494
+ } catch (err) {
495
+ emit();
496
+ throw err;
497
+ }
498
+ if (result && typeof result.then === "function") {
499
+ return result.then(
500
+ (v) => {
501
+ emit();
502
+ return v;
503
+ },
504
+ (err) => {
505
+ emit();
506
+ throw err;
507
+ }
508
+ );
509
+ }
510
+ emit();
511
+ return result;
512
+ };
513
+ }
514
+ });
515
+ }
433
516
  }
434
517
  t(table) {
435
518
  return `[${this.schema}].[${table}]`;