Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/drivers/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export interface S3DriverOptions {
* Enabled by default to speedup `clear()` operation. Set to `false` if provider is not implementing [DeleteObject](https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjects.html).
*/
bulkDelete?: boolean;

/**
* akin to AWS_SESSION_TOKEN if using temp credentials.
*/
sessionToken?: string;
}

export interface S3ItemOptions {
Expand Down Expand Up @@ -84,6 +89,7 @@ const driver: DriverFactory<S3DriverOptions> = (options) => {
service: "s3",
accessKeyId: options.accessKeyId,
secretAccessKey: options.secretAccessKey,
sessionToken: options.sessionToken,
region: options.region,
});
}
Expand Down
23 changes: 16 additions & 7 deletions src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,21 @@ export interface TraceContext {
};
}

type MaybeTracedStorage<T extends StorageValue> = Storage<T> & {
__traced?: boolean;
};
/**
* Runtime-only brand attached to wrapped storages so re-wrapping is a no-op.
* Kept off the public return type.
*/
type TracedBrand = { __traced?: boolean };

/**
* Wraps a storage instance with tracing capabilities.
* All storage operations will emit tracing events through Node.js diagnostics channels.
*/
export function withTracing<T extends StorageValue>(storage: MaybeTracedStorage<T>): Storage<T> {
export function withTracing(storage: Storage<any>): Storage<StorageValue>;
export function withTracing<T extends Storage<any>>(storage: T): T;
export function withTracing<T extends Storage<any>>(storage: T): T {
// Avoid wrapping already traced storages
if (storage.__traced) {
if ((storage as TracedBrand).__traced) {
return storage;
}

Expand Down Expand Up @@ -107,7 +111,10 @@ export function withTracing<T extends StorageValue>(storage: MaybeTracedStorage<
return channel ? channel.tracePromise(exec, data) : exec();
}

const tracedStorage: MaybeTracedStorage<T> = { ...storage, __traced: true };
const tracedStorage: T & TracedBrand = {
...storage,
__traced: true,
};

// Helper to get mount info for a key
const getMountInfo = (key: string) => {
Expand Down Expand Up @@ -160,7 +167,9 @@ export function withTracing<T extends StorageValue>(storage: MaybeTracedStorage<
}

for (const operation in operations) {
tracedStorage[operation] = wrapOperation(operation as TracedOperation);
(tracedStorage as Record<TracedOperation, any>)[operation] = wrapOperation(
operation as TracedOperation,
);
}

// Wrap aliases
Expand Down