@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.js
CHANGED
|
@@ -316,6 +316,12 @@ var init_s3_storage_adapter = __esm({
|
|
|
316
316
|
}
|
|
317
317
|
});
|
|
318
318
|
|
|
319
|
+
// src/storage-service-plugin.ts
|
|
320
|
+
import {
|
|
321
|
+
OBSERVABILITY_METRICS_SERVICE,
|
|
322
|
+
NoopMetricsRegistry as NoopMetricsRegistry3
|
|
323
|
+
} from "@objectstack/observability";
|
|
324
|
+
|
|
319
325
|
// src/local-storage-adapter.ts
|
|
320
326
|
import { promises as fs, createReadStream, createWriteStream } from "fs";
|
|
321
327
|
import { join, dirname } from "path";
|
|
@@ -1315,6 +1321,7 @@ var StorageServicePlugin = class {
|
|
|
1315
1321
|
this.type = "standard";
|
|
1316
1322
|
this.storage = null;
|
|
1317
1323
|
this.store = null;
|
|
1324
|
+
this.metrics = new NoopMetricsRegistry3();
|
|
1318
1325
|
this.options = { adapter: "local", ...options };
|
|
1319
1326
|
}
|
|
1320
1327
|
/** Build a concrete adapter from a values map (settings-derived). */
|
|
@@ -1332,7 +1339,8 @@ var StorageServicePlugin = class {
|
|
|
1332
1339
|
endpoint: values.s3_endpoint || void 0,
|
|
1333
1340
|
accessKeyId: values.s3_access_key_id || void 0,
|
|
1334
1341
|
secretAccessKey: values.s3_secret_access_key || void 0,
|
|
1335
|
-
forcePathStyle: !!values.s3_force_path_style
|
|
1342
|
+
forcePathStyle: !!values.s3_force_path_style,
|
|
1343
|
+
metrics: this.metrics
|
|
1336
1344
|
};
|
|
1337
1345
|
return new S3StorageAdapter(opts);
|
|
1338
1346
|
}
|
|
@@ -1341,10 +1349,12 @@ var StorageServicePlugin = class {
|
|
|
1341
1349
|
basePath: this.options.basePath ?? "/api/v1/storage",
|
|
1342
1350
|
...this.options.local ?? {},
|
|
1343
1351
|
// settings value wins over any constructor-provided local.rootDir
|
|
1344
|
-
rootDir
|
|
1352
|
+
rootDir,
|
|
1353
|
+
metrics: this.metrics
|
|
1345
1354
|
});
|
|
1346
1355
|
}
|
|
1347
1356
|
async init(ctx) {
|
|
1357
|
+
this.metrics = resolveMetrics(ctx, this.options.metrics);
|
|
1348
1358
|
const adapter = this.options.adapter;
|
|
1349
1359
|
let initial;
|
|
1350
1360
|
if (adapter === "s3") {
|
|
@@ -1353,11 +1363,11 @@ var StorageServicePlugin = class {
|
|
|
1353
1363
|
if (!s3Opts) {
|
|
1354
1364
|
throw new Error('StorageServicePlugin: s3 options are required when adapter is "s3"');
|
|
1355
1365
|
}
|
|
1356
|
-
initial = new S3Ctor(s3Opts);
|
|
1366
|
+
initial = new S3Ctor({ ...s3Opts, metrics: this.metrics });
|
|
1357
1367
|
} else {
|
|
1358
1368
|
const rootDir = this.options.local?.rootDir ?? "./storage";
|
|
1359
1369
|
const basePath = this.options.basePath ?? "/api/v1/storage";
|
|
1360
|
-
initial = new LocalStorageAdapter({ rootDir, basePath, ...this.options.local });
|
|
1370
|
+
initial = new LocalStorageAdapter({ rootDir, basePath, ...this.options.local, metrics: this.metrics });
|
|
1361
1371
|
}
|
|
1362
1372
|
this.storage = new SwappableStorageService(initial, (prev, next) => {
|
|
1363
1373
|
const prevName = prev?.constructor?.name ?? "unknown";
|
|
@@ -1367,7 +1377,9 @@ var StorageServicePlugin = class {
|
|
|
1367
1377
|
);
|
|
1368
1378
|
});
|
|
1369
1379
|
ctx.registerService("file-storage", this.storage);
|
|
1370
|
-
ctx.logger.info(
|
|
1380
|
+
ctx.logger.info(
|
|
1381
|
+
`StorageServicePlugin: registered ${adapter} storage adapter (swappable, metrics=${this.metrics.constructor?.name ?? "unknown"})`
|
|
1382
|
+
);
|
|
1371
1383
|
try {
|
|
1372
1384
|
ctx.getService("manifest").register({
|
|
1373
1385
|
id: "com.objectstack.service.storage",
|
|
@@ -1479,6 +1491,15 @@ var StorageServicePlugin = class {
|
|
|
1479
1491
|
});
|
|
1480
1492
|
}
|
|
1481
1493
|
};
|
|
1494
|
+
function resolveMetrics(ctx, override) {
|
|
1495
|
+
if (override) return override;
|
|
1496
|
+
try {
|
|
1497
|
+
const m = ctx.getService(OBSERVABILITY_METRICS_SERVICE);
|
|
1498
|
+
if (m) return m;
|
|
1499
|
+
} catch {
|
|
1500
|
+
}
|
|
1501
|
+
return new NoopMetricsRegistry3();
|
|
1502
|
+
}
|
|
1482
1503
|
|
|
1483
1504
|
// src/index.ts
|
|
1484
1505
|
init_s3_storage_adapter();
|