@objectstack/service-storage 5.1.0 → 6.0.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 +23 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +26 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -349,6 +349,9 @@ __export(index_exports, {
|
|
|
349
349
|
});
|
|
350
350
|
module.exports = __toCommonJS(index_exports);
|
|
351
351
|
|
|
352
|
+
// src/storage-service-plugin.ts
|
|
353
|
+
var import_observability3 = require("@objectstack/observability");
|
|
354
|
+
|
|
352
355
|
// src/local-storage-adapter.ts
|
|
353
356
|
var import_node_fs = require("fs");
|
|
354
357
|
var import_node_path = require("path");
|
|
@@ -1345,6 +1348,7 @@ var StorageServicePlugin = class {
|
|
|
1345
1348
|
this.type = "standard";
|
|
1346
1349
|
this.storage = null;
|
|
1347
1350
|
this.store = null;
|
|
1351
|
+
this.metrics = new import_observability3.NoopMetricsRegistry();
|
|
1348
1352
|
this.options = { adapter: "local", ...options };
|
|
1349
1353
|
}
|
|
1350
1354
|
/** Build a concrete adapter from a values map (settings-derived). */
|
|
@@ -1362,7 +1366,8 @@ var StorageServicePlugin = class {
|
|
|
1362
1366
|
endpoint: values.s3_endpoint || void 0,
|
|
1363
1367
|
accessKeyId: values.s3_access_key_id || void 0,
|
|
1364
1368
|
secretAccessKey: values.s3_secret_access_key || void 0,
|
|
1365
|
-
forcePathStyle: !!values.s3_force_path_style
|
|
1369
|
+
forcePathStyle: !!values.s3_force_path_style,
|
|
1370
|
+
metrics: this.metrics
|
|
1366
1371
|
};
|
|
1367
1372
|
return new S3StorageAdapter(opts);
|
|
1368
1373
|
}
|
|
@@ -1371,10 +1376,12 @@ var StorageServicePlugin = class {
|
|
|
1371
1376
|
basePath: this.options.basePath ?? "/api/v1/storage",
|
|
1372
1377
|
...this.options.local ?? {},
|
|
1373
1378
|
// settings value wins over any constructor-provided local.rootDir
|
|
1374
|
-
rootDir
|
|
1379
|
+
rootDir,
|
|
1380
|
+
metrics: this.metrics
|
|
1375
1381
|
});
|
|
1376
1382
|
}
|
|
1377
1383
|
async init(ctx) {
|
|
1384
|
+
this.metrics = resolveMetrics(ctx, this.options.metrics);
|
|
1378
1385
|
const adapter = this.options.adapter;
|
|
1379
1386
|
let initial;
|
|
1380
1387
|
if (adapter === "s3") {
|
|
@@ -1383,11 +1390,11 @@ var StorageServicePlugin = class {
|
|
|
1383
1390
|
if (!s3Opts) {
|
|
1384
1391
|
throw new Error('StorageServicePlugin: s3 options are required when adapter is "s3"');
|
|
1385
1392
|
}
|
|
1386
|
-
initial = new S3Ctor(s3Opts);
|
|
1393
|
+
initial = new S3Ctor({ ...s3Opts, metrics: this.metrics });
|
|
1387
1394
|
} else {
|
|
1388
1395
|
const rootDir = this.options.local?.rootDir ?? "./storage";
|
|
1389
1396
|
const basePath = this.options.basePath ?? "/api/v1/storage";
|
|
1390
|
-
initial = new LocalStorageAdapter({ rootDir, basePath, ...this.options.local });
|
|
1397
|
+
initial = new LocalStorageAdapter({ rootDir, basePath, ...this.options.local, metrics: this.metrics });
|
|
1391
1398
|
}
|
|
1392
1399
|
this.storage = new SwappableStorageService(initial, (prev, next) => {
|
|
1393
1400
|
const prevName = prev?.constructor?.name ?? "unknown";
|
|
@@ -1397,7 +1404,9 @@ var StorageServicePlugin = class {
|
|
|
1397
1404
|
);
|
|
1398
1405
|
});
|
|
1399
1406
|
ctx.registerService("file-storage", this.storage);
|
|
1400
|
-
ctx.logger.info(
|
|
1407
|
+
ctx.logger.info(
|
|
1408
|
+
`StorageServicePlugin: registered ${adapter} storage adapter (swappable, metrics=${this.metrics.constructor?.name ?? "unknown"})`
|
|
1409
|
+
);
|
|
1401
1410
|
try {
|
|
1402
1411
|
ctx.getService("manifest").register({
|
|
1403
1412
|
id: "com.objectstack.service.storage",
|
|
@@ -1509,6 +1518,15 @@ var StorageServicePlugin = class {
|
|
|
1509
1518
|
});
|
|
1510
1519
|
}
|
|
1511
1520
|
};
|
|
1521
|
+
function resolveMetrics(ctx, override) {
|
|
1522
|
+
if (override) return override;
|
|
1523
|
+
try {
|
|
1524
|
+
const m = ctx.getService(import_observability3.OBSERVABILITY_METRICS_SERVICE);
|
|
1525
|
+
if (m) return m;
|
|
1526
|
+
} catch {
|
|
1527
|
+
}
|
|
1528
|
+
return new import_observability3.NoopMetricsRegistry();
|
|
1529
|
+
}
|
|
1512
1530
|
|
|
1513
1531
|
// src/index.ts
|
|
1514
1532
|
init_s3_storage_adapter();
|