@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 +83 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +85 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _utaba_deep_memory_types from '@utaba/deep-memory/types';
|
|
2
|
-
import { StorageRepositoryConfig, StoredRepository, RepositoryFilter, PaginatedResult, StoredRepositorySummary, RepositoryUpdate, RepositoryStats, MemoryVocabulary, PaginationOptions, VocabularyChangeRecord, StoredEntity, StoredEntityUpdate, StorageFindQuery, StoredRelationship, RelationshipQueryOptions, StorageExploreOptions, StorageNeighborhood, StoragePathOptions, StoragePathResult, StorageTimelineOptions, StorageTimelineResult, ExportChunk, ImportChunk, BulkImportResult, SearchOptions, SearchHit } from '@utaba/deep-memory/types';
|
|
2
|
+
import { UsageSink, StorageRepositoryConfig, StoredRepository, RepositoryFilter, PaginatedResult, StoredRepositorySummary, RepositoryUpdate, RepositoryStats, MemoryVocabulary, PaginationOptions, VocabularyChangeRecord, StoredEntity, StoredEntityUpdate, StorageFindQuery, StoredRelationship, RelationshipQueryOptions, StorageExploreOptions, StorageNeighborhood, StoragePathOptions, StoragePathResult, StorageTimelineOptions, StorageTimelineResult, ExportChunk, ImportChunk, BulkImportResult, SearchOptions, SearchHit } from '@utaba/deep-memory/types';
|
|
3
3
|
import sql from 'mssql';
|
|
4
4
|
import { StorageProvider, EnsureSchemaResult, SearchProvider, SearchableEntity } from '@utaba/deep-memory/providers';
|
|
5
5
|
|
|
@@ -9,6 +9,12 @@ interface SqlServerStorageProviderConfig {
|
|
|
9
9
|
connection: sql.config | sql.ConnectionPool;
|
|
10
10
|
/** SQL Server schema name (default: 'dbo') */
|
|
11
11
|
schema?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Optional usage sink. When provided, the provider emits one
|
|
14
|
+
* {@link OperationUsage} record per public method call reporting
|
|
15
|
+
* wall-clock execution time in milliseconds. Never exposed to AI agents.
|
|
16
|
+
*/
|
|
17
|
+
reportUsage?: UsageSink;
|
|
12
18
|
}
|
|
13
19
|
declare class SqlServerStorageProvider implements StorageProvider {
|
|
14
20
|
private pool;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _utaba_deep_memory_types from '@utaba/deep-memory/types';
|
|
2
|
-
import { StorageRepositoryConfig, StoredRepository, RepositoryFilter, PaginatedResult, StoredRepositorySummary, RepositoryUpdate, RepositoryStats, MemoryVocabulary, PaginationOptions, VocabularyChangeRecord, StoredEntity, StoredEntityUpdate, StorageFindQuery, StoredRelationship, RelationshipQueryOptions, StorageExploreOptions, StorageNeighborhood, StoragePathOptions, StoragePathResult, StorageTimelineOptions, StorageTimelineResult, ExportChunk, ImportChunk, BulkImportResult, SearchOptions, SearchHit } from '@utaba/deep-memory/types';
|
|
2
|
+
import { UsageSink, StorageRepositoryConfig, StoredRepository, RepositoryFilter, PaginatedResult, StoredRepositorySummary, RepositoryUpdate, RepositoryStats, MemoryVocabulary, PaginationOptions, VocabularyChangeRecord, StoredEntity, StoredEntityUpdate, StorageFindQuery, StoredRelationship, RelationshipQueryOptions, StorageExploreOptions, StorageNeighborhood, StoragePathOptions, StoragePathResult, StorageTimelineOptions, StorageTimelineResult, ExportChunk, ImportChunk, BulkImportResult, SearchOptions, SearchHit } from '@utaba/deep-memory/types';
|
|
3
3
|
import sql from 'mssql';
|
|
4
4
|
import { StorageProvider, EnsureSchemaResult, SearchProvider, SearchableEntity } from '@utaba/deep-memory/providers';
|
|
5
5
|
|
|
@@ -9,6 +9,12 @@ interface SqlServerStorageProviderConfig {
|
|
|
9
9
|
connection: sql.config | sql.ConnectionPool;
|
|
10
10
|
/** SQL Server schema name (default: 'dbo') */
|
|
11
11
|
schema?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Optional usage sink. When provided, the provider emits one
|
|
14
|
+
* {@link OperationUsage} record per public method call reporting
|
|
15
|
+
* wall-clock execution time in milliseconds. Never exposed to AI agents.
|
|
16
|
+
*/
|
|
17
|
+
reportUsage?: UsageSink;
|
|
12
18
|
}
|
|
13
19
|
declare class SqlServerStorageProvider implements StorageProvider {
|
|
14
20
|
private pool;
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
RelationshipNotFoundError,
|
|
9
9
|
DuplicateRelationshipError,
|
|
10
10
|
ProviderError,
|
|
11
|
-
matchesPropertyFilters
|
|
11
|
+
matchesPropertyFilters,
|
|
12
|
+
createSafeSink
|
|
12
13
|
} from "@utaba/deep-memory";
|
|
13
14
|
|
|
14
15
|
// src/schema.ts
|
|
@@ -288,6 +289,42 @@ END;
|
|
|
288
289
|
}
|
|
289
290
|
|
|
290
291
|
// src/SqlServerStorageProvider.ts
|
|
292
|
+
var PROVIDER_NAME = "sqlserver";
|
|
293
|
+
var TRACKED_METHODS = {
|
|
294
|
+
ensureSchema: () => void 0,
|
|
295
|
+
createRepository: (args) => {
|
|
296
|
+
const cfg = args[0];
|
|
297
|
+
return cfg?.repositoryId;
|
|
298
|
+
},
|
|
299
|
+
getRepository: (args) => args[0],
|
|
300
|
+
listRepositories: () => void 0,
|
|
301
|
+
updateRepository: (args) => args[0],
|
|
302
|
+
deleteRepository: (args) => args[0],
|
|
303
|
+
deleteAllContents: (args) => args[0],
|
|
304
|
+
getRepositoryStats: (args) => args[0],
|
|
305
|
+
getVocabulary: (args) => args[0],
|
|
306
|
+
saveVocabulary: (args) => args[0],
|
|
307
|
+
getVocabularyChangeLog: (args) => args[0],
|
|
308
|
+
createEntity: (args) => args[0],
|
|
309
|
+
getEntity: (args) => args[0],
|
|
310
|
+
getEntityBySlug: (args) => args[0],
|
|
311
|
+
getEntities: (args) => args[0],
|
|
312
|
+
updateEntity: (args) => args[0],
|
|
313
|
+
deleteEntity: (args) => args[0],
|
|
314
|
+
deleteEntities: (args) => args[0],
|
|
315
|
+
deleteEntitiesByType: (args) => args[0],
|
|
316
|
+
findEntities: (args) => args[0],
|
|
317
|
+
createRelationship: (args) => args[0],
|
|
318
|
+
getRelationship: (args) => args[0],
|
|
319
|
+
getEntityRelationships: (args) => args[0],
|
|
320
|
+
deleteRelationship: (args) => args[0],
|
|
321
|
+
deleteRelationships: (args) => args[0],
|
|
322
|
+
deleteRelationshipsByType: (args) => args[0],
|
|
323
|
+
exploreNeighborhood: (args) => args[0],
|
|
324
|
+
findPaths: (args) => args[0],
|
|
325
|
+
getTimeline: (args) => args[0],
|
|
326
|
+
importBulk: (args) => args[0]
|
|
327
|
+
};
|
|
291
328
|
var ENTITY_COLS_LIGHT = [
|
|
292
329
|
"entity_id",
|
|
293
330
|
"slug",
|
|
@@ -399,6 +436,53 @@ var SqlServerStorageProvider = class {
|
|
|
399
436
|
this.config = config;
|
|
400
437
|
this.schema = config.schema ?? "dbo";
|
|
401
438
|
this.ownsPool = !(config.connection instanceof sql.ConnectionPool);
|
|
439
|
+
const safeSink = createSafeSink(config.reportUsage);
|
|
440
|
+
if (safeSink) {
|
|
441
|
+
return new Proxy(this, {
|
|
442
|
+
get(target, prop, receiver) {
|
|
443
|
+
const value = Reflect.get(target, prop, receiver);
|
|
444
|
+
if (typeof prop !== "string" || typeof value !== "function") return value;
|
|
445
|
+
const extractRepoId = TRACKED_METHODS[prop];
|
|
446
|
+
if (!extractRepoId) return value;
|
|
447
|
+
const method = value;
|
|
448
|
+
return (...args) => {
|
|
449
|
+
const start = Date.now();
|
|
450
|
+
const repositoryId = extractRepoId(args);
|
|
451
|
+
const emit = () => {
|
|
452
|
+
safeSink({
|
|
453
|
+
provider: PROVIDER_NAME,
|
|
454
|
+
operation: prop,
|
|
455
|
+
unit: "ms",
|
|
456
|
+
value: Date.now() - start,
|
|
457
|
+
...repositoryId ? { repositoryId } : {},
|
|
458
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
459
|
+
});
|
|
460
|
+
};
|
|
461
|
+
let result;
|
|
462
|
+
try {
|
|
463
|
+
result = method.apply(target, args);
|
|
464
|
+
} catch (err) {
|
|
465
|
+
emit();
|
|
466
|
+
throw err;
|
|
467
|
+
}
|
|
468
|
+
if (result && typeof result.then === "function") {
|
|
469
|
+
return result.then(
|
|
470
|
+
(v) => {
|
|
471
|
+
emit();
|
|
472
|
+
return v;
|
|
473
|
+
},
|
|
474
|
+
(err) => {
|
|
475
|
+
emit();
|
|
476
|
+
throw err;
|
|
477
|
+
}
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
emit();
|
|
481
|
+
return result;
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
}
|
|
402
486
|
}
|
|
403
487
|
t(table) {
|
|
404
488
|
return `[${this.schema}].[${table}]`;
|