@ultimat3/storage 31.27.0 → 31.28.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/CLAUDE.md +1 -1
- package/README.md +1 -1
- package/package.json +2 -2
- package/src/storage-instrument-multipart.ts +74 -0
- package/src/storage-instrument.ts +17 -2
package/CLAUDE.md
CHANGED
|
@@ -72,7 +72,7 @@ A rule marked `†` has its full text in [`docs/history/storage-rules.md`](../..
|
|
|
72
72
|
| `upload-scanner*.ts` / `upload-scan.ts` | the `uploadScanner` port + memory (EICAR) reference; `promoteAttachment` scans a per-attempt copy |
|
|
73
73
|
| `image-warm.ts` | `warmVariants`: a stored image's variants written ahead of `/media`, under its keys, the revision off the bytes read; core's spec, so a warmed variant is the one a miss would store |
|
|
74
74
|
| `storage.ts` | `defineStorage` + module-level `storage()` / `disk()` |
|
|
75
|
-
| `storage-instrument.ts` | each resolved disk: `storage.<verb>` bus event + client span |
|
|
75
|
+
| `storage-instrument.ts` / `storage-instrument-multipart.ts` | each resolved disk: `storage.<verb>` bus event + client span; its `multipart` session changes as `storage.multipart` (`op`) |
|
|
76
76
|
| `grant.ts` | `grantUpload` — the ONE way a presigned PUT is minted; the client never names a key |
|
|
77
77
|
| `accept.ts` | `acceptSignedUpload` / `readSignedObject` — the two decisions a `/_storage` route is made of |
|
|
78
78
|
| `attachment.ts` | `pending/` → row promotion, `sweepOrphans` and `deleteVariants` |
|
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ const stored = [...sessions.objects().values()].map((bytes) => new TextDecoder()
|
|
|
58
58
|
|
|
59
59
|
Server-side only, like both other drivers: nothing an island imports reaches it.
|
|
60
60
|
|
|
61
|
-
Every call on a disk `defineStorage` resolves is a `storage.<verb>` event on `@ultimat3/core`'s instrumentation bus (`put`, `get`, `stat`, `copy`, `delete`, `list`; `{ disk, key, bytes?, durationMs, error? }`) inside a `storage.<verb>` client span. `disk()` hands out that instrumented view, so it is not `===` the driver you declared — compare `.name`. A driver you hold directly reports nothing. A method patched in a test — assigned on the disk, or `spyOn(driver, 'put')` on the driver you declared — runs on the next call and is still reported. `spyOn(disk, …)` does nothing: Bun's `spyOn` never writes through a Proxy (as of bun 1.4.4), so spy on the driver.
|
|
61
|
+
Every call on a disk `defineStorage` resolves is a `storage.<verb>` event on `@ultimat3/core`'s instrumentation bus (`put`, `get`, `stat`, `copy`, `delete`, `list`; `{ disk, key, bytes?, durationMs, error? }`), and each change its `multipart` capability makes to an upload session is `storage.multipart` with `op` `create` · `part` · `complete` · `abort` (signing a part URL and listing parts are not events) inside a `storage.<verb>` client span. `disk()` hands out that instrumented view, so it is not `===` the driver you declared — compare `.name`. A driver you hold directly reports nothing. A method patched in a test — assigned on the disk, or `spyOn(driver, 'put')` on the driver you declared — runs on the next call and is still reported. `spyOn(disk, …)` does nothing: Bun's `spyOn` never writes through a Proxy (as of bun 1.4.4), so spy on the driver.
|
|
62
62
|
|
|
63
63
|
`region` is what requests are signed for; unset, that is `auto`. An endpoint that expects another
|
|
64
64
|
region refuses the first write, list or delete with `X_CONFIG_INVALID`, and the fix names the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/storage",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.28.0",
|
|
4
4
|
"description": "Named disks over Bun.file and Bun.s3: safe keys, signed URLs, sniffed uploads",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -43,6 +43,6 @@
|
|
|
43
43
|
"test": "bun test"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@ultimat3/core": "31.
|
|
46
|
+
"@ultimat3/core": "31.28.0"
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Single responsibility: a resolved disk's multipart capability, its four session-changing calls
|
|
2
|
+
// each reported as `storage.multipart` (`op` create | part | complete | abort) inside a client span.
|
|
3
|
+
// Signing a part URL and listing parts or sessions change nothing, and pass through unreported.
|
|
4
|
+
|
|
5
|
+
import type { StorageMultipartEvent } from '@ultimat3/core';
|
|
6
|
+
import { instrument, subscribed, withSpan } from '@ultimat3/core';
|
|
7
|
+
import type { MultipartCapability } from './multipart';
|
|
8
|
+
|
|
9
|
+
type MultipartOp = StorageMultipartEvent['op'];
|
|
10
|
+
|
|
11
|
+
/** The bytes the answer states: a stored part's `size`, or the assembled object's. */
|
|
12
|
+
const sizeOf = (answer: unknown): number | undefined =>
|
|
13
|
+
typeof answer === 'object' &&
|
|
14
|
+
answer !== null &&
|
|
15
|
+
'size' in answer &&
|
|
16
|
+
typeof answer.size === 'number'
|
|
17
|
+
? answer.size
|
|
18
|
+
: undefined;
|
|
19
|
+
|
|
20
|
+
/** `capability` for the disk named `disk`, its session changes reported. The rest is its own. */
|
|
21
|
+
export function instrumentedMultipart(
|
|
22
|
+
disk: string,
|
|
23
|
+
driverName: string,
|
|
24
|
+
capability: MultipartCapability,
|
|
25
|
+
): MultipartCapability {
|
|
26
|
+
const report = async <T>(op: MultipartOp, key: string, work: () => Promise<T>): Promise<T> => {
|
|
27
|
+
const started = performance.now();
|
|
28
|
+
const emit = (extra: { bytes?: number; error?: unknown }): void => {
|
|
29
|
+
if (!subscribed('storage.multipart')) return;
|
|
30
|
+
const event: StorageMultipartEvent = {
|
|
31
|
+
disk,
|
|
32
|
+
key,
|
|
33
|
+
op,
|
|
34
|
+
durationMs: performance.now() - started,
|
|
35
|
+
...extra,
|
|
36
|
+
};
|
|
37
|
+
instrument('storage.multipart', event);
|
|
38
|
+
};
|
|
39
|
+
try {
|
|
40
|
+
const answer = await withSpan('storage.multipart', work, {
|
|
41
|
+
kind: 'client',
|
|
42
|
+
attributes: {
|
|
43
|
+
'ultimate.storage.disk': disk,
|
|
44
|
+
'ultimate.storage.driver': driverName,
|
|
45
|
+
'ultimate.storage.multipart.op': op,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const bytes = sizeOf(answer);
|
|
49
|
+
emit(bytes === undefined ? {} : { bytes });
|
|
50
|
+
return answer;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
emit({ error });
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const { receivePart } = capability;
|
|
57
|
+
return {
|
|
58
|
+
create: (key, options) => report('create', key, () => capability.create(key, options)),
|
|
59
|
+
signPart: (...args) => capability.signPart(...args),
|
|
60
|
+
listParts: (key, uploadId) => capability.listParts(key, uploadId),
|
|
61
|
+
complete: (key, uploadId, parts) =>
|
|
62
|
+
report('complete', key, () => capability.complete(key, uploadId, parts)),
|
|
63
|
+
abort: (key, uploadId) => report('abort', key, () => capability.abort(key, uploadId)),
|
|
64
|
+
listUploads: (prefix) => capability.listUploads(prefix),
|
|
65
|
+
...(receivePart === undefined
|
|
66
|
+
? {}
|
|
67
|
+
: {
|
|
68
|
+
receivePart: (key, uploadId, partNumber, bytes) =>
|
|
69
|
+
report('part', key, () =>
|
|
70
|
+
receivePart.call(capability, key, uploadId, partNumber, bytes),
|
|
71
|
+
),
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
import type { StorageEvent } from '@ultimat3/core';
|
|
6
6
|
import { instrument, subscribed, withSpan } from '@ultimat3/core';
|
|
7
7
|
import type { StorageDriver } from './driver';
|
|
8
|
+
import type { MultipartCapability } from './multipart';
|
|
9
|
+
import { instrumentedMultipart } from './storage-instrument-multipart';
|
|
8
10
|
|
|
9
11
|
type StorageVerb = 'put' | 'get' | 'stat' | 'copy' | 'delete' | 'list';
|
|
10
12
|
|
|
@@ -48,8 +50,8 @@ function report(name: `storage.${StorageVerb}`, event: StorageEvent): void {
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
|
-
* The driver, every contract method wrapped
|
|
52
|
-
* `
|
|
53
|
+
* The driver, every contract method wrapped — `multipart`'s session changes too — and every other
|
|
54
|
+
* member (a test disk's `objects()`, `registerAs`) passed through bound to the driver. The driver's calls to its OWN
|
|
53
55
|
* methods stay unwrapped: one caller's call is one event.
|
|
54
56
|
*
|
|
55
57
|
* A wrapper is reused only while the driver still holds the method it wraps. A cache keyed on the
|
|
@@ -64,6 +66,18 @@ export function instrumentedDisk(disk: string, driver: StorageDriver): StorageDr
|
|
|
64
66
|
const unwrapped = new WeakMap<object, unknown>();
|
|
65
67
|
const raw = (value: unknown): unknown =>
|
|
66
68
|
typeof value === 'function' ? (unwrapped.get(value) ?? value) : value;
|
|
69
|
+
// The capability's session changes are reported too (`storage-instrument-multipart.ts`): one view
|
|
70
|
+
// per capability object, so `disk.multipart` is the same object on every read until replaced.
|
|
71
|
+
let multipart:
|
|
72
|
+
| { readonly raw: MultipartCapability; readonly view: MultipartCapability }
|
|
73
|
+
| undefined;
|
|
74
|
+
const multipartView = (raw: MultipartCapability | undefined): MultipartCapability | undefined => {
|
|
75
|
+
if (raw === undefined) return undefined;
|
|
76
|
+
if (multipart?.raw !== raw) {
|
|
77
|
+
multipart = { raw, view: instrumentedMultipart(disk, driver.name, raw) };
|
|
78
|
+
}
|
|
79
|
+
return multipart.view;
|
|
80
|
+
};
|
|
67
81
|
const view: StorageDriver = new Proxy(driver, {
|
|
68
82
|
// Only a write ON the disk patches the driver. An object inheriting from the disk
|
|
69
83
|
// (`Object.create(disk)`) reaches this trap as `receiver` and keeps the member as its own;
|
|
@@ -80,6 +94,7 @@ export function instrumentedDisk(disk: string, driver: StorageDriver): StorageDr
|
|
|
80
94
|
),
|
|
81
95
|
get(target, property) {
|
|
82
96
|
const value: unknown = Reflect.get(target, property, target);
|
|
97
|
+
if (property === 'multipart') return multipartView(target.multipart);
|
|
83
98
|
if (typeof value !== 'function') return value;
|
|
84
99
|
const known = wrapped.get(property);
|
|
85
100
|
if (known?.method === value) return known.bound;
|