@travetto/model
Advanced tools
Comparing version 5.0.7 to 5.0.8
{ | ||
"name": "@travetto/model", | ||
"version": "5.0.7", | ||
"version": "5.0.8", | ||
"description": "Datastore abstraction for core operations.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -182,3 +182,3 @@ <!-- This file was generated by @travetto/doc and should not be modified directly --> | ||
*/ | ||
describeBlob(location: string): Promise<BlobMeta>; | ||
getBlobMeta(location: string): Promise<BlobMeta>; | ||
@@ -190,2 +190,25 @@ /** | ||
deleteBlob(location: string): Promise<void>; | ||
/** | ||
* Update blob metadata | ||
* @param location The location of the blob | ||
*/ | ||
updateBlobMeta(location: string, meta: BlobMeta): Promise<void>; | ||
/** | ||
* Produces an externally usable URL for sharing limited read access to a specific resource | ||
* | ||
* @param location The asset location to read from | ||
* @param exp Expiry | ||
*/ | ||
getBlobReadUrl?(location: string, exp?: TimeSpan): Promise<string>; | ||
/** | ||
* Produces an externally usable URL for sharing allowing direct write access | ||
* | ||
* @param location The asset location to write to | ||
* @param meta The metadata to associate with the final asset | ||
* @param exp Expiry | ||
*/ | ||
getBlobWriteUrl?(location: string, meta: BlobMeta, exp?: TimeSpan): Promise<string>; | ||
} | ||
@@ -192,0 +215,0 @@ ``` |
@@ -34,3 +34,3 @@ import { hasFunction } from '@travetto/runtime'; | ||
/** | ||
* Type guard for determining if service supports streaming operation | ||
* Type guard for determining if service supports blob operations | ||
*/ | ||
@@ -45,3 +45,3 @@ export const isBlobSupported = hasFunction<ModelBlobSupport>('getBlob'); | ||
/** | ||
* Type guard for determining if service supports streaming operation | ||
* Type guard for determining if service supports bulk operation | ||
*/ | ||
@@ -48,0 +48,0 @@ export const isBulkSupported = hasFunction<ModelBulkSupport>('processBulk'); |
@@ -1,2 +0,2 @@ | ||
import { BinaryInput, BlobMeta, ByteRange } from '@travetto/runtime'; | ||
import { BinaryInput, BlobMeta, ByteRange, TimeSpan } from '@travetto/runtime'; | ||
@@ -29,3 +29,3 @@ /** | ||
*/ | ||
describeBlob(location: string): Promise<BlobMeta>; | ||
getBlobMeta(location: string): Promise<BlobMeta>; | ||
@@ -37,2 +37,25 @@ /** | ||
deleteBlob(location: string): Promise<void>; | ||
/** | ||
* Update blob metadata | ||
* @param location The location of the blob | ||
*/ | ||
updateBlobMeta(location: string, meta: BlobMeta): Promise<void>; | ||
/** | ||
* Produces an externally usable URL for sharing limited read access to a specific resource | ||
* | ||
* @param location The asset location to read from | ||
* @param exp Expiry | ||
*/ | ||
getBlobReadUrl?(location: string, exp?: TimeSpan): Promise<string>; | ||
/** | ||
* Produces an externally usable URL for sharing allowing direct write access | ||
* | ||
* @param location The asset location to write to | ||
* @param meta The metadata to associate with the final asset | ||
* @param exp Expiry | ||
*/ | ||
getBlobWriteUrl?(location: string, meta: BlobMeta, exp?: TimeSpan): Promise<string>; | ||
} |
@@ -25,4 +25,4 @@ import assert from 'node:assert'; | ||
await service.upsertBlob(id, buffer); | ||
const m = await service.describeBlob(id); | ||
const retrieved = await service.describeBlob(id); | ||
const m = await service.getBlobMeta(id); | ||
const retrieved = await service.getBlobMeta(id); | ||
assert.deepStrictEqual(m, retrieved); | ||
@@ -39,9 +39,9 @@ } | ||
await service.upsertBlob(id, buffer, { hash: '10' }); | ||
assert((await service.describeBlob(id)).hash === '10'); | ||
assert((await service.getBlobMeta(id)).hash === '10'); | ||
await service.upsertBlob(id, buffer, { hash: '20' }); | ||
assert((await service.describeBlob(id)).hash === '20'); | ||
assert((await service.getBlobMeta(id)).hash === '20'); | ||
await service.upsertBlob(id, buffer, { hash: '30' }, false); | ||
assert((await service.describeBlob(id)).hash === '20'); | ||
assert((await service.getBlobMeta(id)).hash === '20'); | ||
} | ||
@@ -56,3 +56,3 @@ | ||
await service.upsertBlob(id, buffer); | ||
const { hash } = await service.describeBlob(id); | ||
const { hash } = await service.getBlobMeta(id); | ||
@@ -139,2 +139,63 @@ const retrieved = await service.getBlob(id); | ||
} | ||
@Test() | ||
async metadataUpdate() { | ||
const service = await this.service; | ||
await this.writeAndGet(); | ||
await service.updateBlobMeta('orange', { | ||
contentType: 'text/yml', | ||
filename: 'orange.yml' | ||
}); | ||
const savedMeta = await service.getBlobMeta('orange'); | ||
assert('text/yml' === savedMeta.contentType); | ||
assert('orange.yml' === savedMeta.filename); | ||
assert(undefined === savedMeta.hash); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
@Test({ skip: (x: unknown) => !(x as ModelBlobSuite).serviceClass.prototype.getBlobWriteUrl }) | ||
async signedUrl() { | ||
const service = await this.service; | ||
const buffer = Buffer.alloc(1.5 * 10000); | ||
for (let i = 0; i < buffer.length; i++) { | ||
buffer.writeUInt8(Math.trunc(Math.random() * 255), i); | ||
} | ||
const writable = await service.getBlobWriteUrl!('largeFile/one', { | ||
contentType: 'image/jpeg', | ||
}); | ||
console.log(writable); | ||
assert(writable); | ||
const res = await fetch(writable, { | ||
method: 'PUT', | ||
body: new File([buffer], 'gary', { type: 'image/jpeg' }), | ||
}); | ||
console.error(await res.text()); | ||
assert(res.ok); | ||
await service.updateBlobMeta('largeFile/one', { | ||
contentType: 'image/jpeg', | ||
title: 'orange', | ||
filename: 'gary', | ||
size: buffer.length, | ||
}); | ||
const found = await service.getBlob('largeFile/one'); | ||
assert(found.size === buffer.length); | ||
assert(found.type === 'image/jpeg'); | ||
assert(BinaryUtil.getBlobMeta(found)?.title === 'orange'); | ||
assert(BinaryUtil.getBlobMeta(found)?.filename === 'gary'); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
160159
2512
370