@travetto/runtime 5.0.0-rc.11 → 5.0.0-rc.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/runtime",
3
- "version": "5.0.0-rc.11",
3
+ "version": "5.0.0-rc.12",
4
4
  "description": "Runtime for travetto applications.",
5
5
  "keywords": [
6
6
  "console-manager",
package/src/binary.ts CHANGED
@@ -9,6 +9,9 @@ import { text as toText, arrayBuffer as toBuffer } from 'node:stream/consumers';
9
9
 
10
10
  import { BinaryInput, BlobMeta } from './types';
11
11
  import { AppError } from './error';
12
+ import { Util } from './util';
13
+
14
+ const BlobMetaⲐ = Symbol.for('@travetto/runtime:blob-meta');
12
15
 
13
16
  /**
14
17
  * Common functions for dealing with binary data/streams
@@ -74,18 +77,22 @@ export class BinaryUtil {
74
77
  new File([], path.basename(metadata.filename), { type: metadata.contentType }) :
75
78
  new Blob([], { type: metadata.contentType });
76
79
 
77
- Object.defineProperties(out, {
80
+ return Object.defineProperties(out, {
78
81
  size: { value: size },
79
82
  stream: { value: () => ReadableStream.from(go()) },
80
83
  arrayBuffer: { value: () => toBuffer(go()) },
81
84
  text: { value: () => toText(go()) },
82
85
  bytes: { value: () => toBuffer(go()).then(v => new Uint8Array(v)) },
86
+ [BlobMetaⲐ]: { value: metadata }
83
87
  });
88
+ }
84
89
 
85
- // @ts-expect-error
86
- out.meta = metadata;
87
-
88
- return out;
90
+ /**
91
+ * Get blob metadata
92
+ */
93
+ static getBlobMeta(blob: Blob): BlobMeta | undefined {
94
+ const withMeta: Blob & { [BlobMetaⲐ]?: BlobMeta } = blob;
95
+ return withMeta[BlobMetaⲐ];
89
96
  }
90
97
 
91
98
  /**
@@ -105,4 +112,19 @@ export class BinaryUtil {
105
112
  },
106
113
  });
107
114
  }
115
+
116
+ /**
117
+ * Get a hashed location/path for a blob
118
+ */
119
+ static hashedBlobLocation(meta: BlobMeta): string {
120
+ const hash = meta.hash ?? Util.uuid();
121
+
122
+ let parts = hash.match(/(.{1,4})/g)!.slice();
123
+ if (parts.length > 4) {
124
+ parts = [...parts.slice(0, 4), parts.slice(4).join('')];
125
+ }
126
+
127
+ const ext = path.extname(meta.filename ?? '') || '.bin';
128
+ return `${parts.join('/')}${ext}`;
129
+ }
108
130
  }
package/src/global.d.ts CHANGED
@@ -1,20 +1,12 @@
1
- import { BlobMeta } from './types';
1
+ import './types';
2
2
 
3
- // https://github.com/microsoft/TypeScript/issues/59012
4
3
  declare const write: unique symbol;
5
4
  declare global {
5
+ // https://github.com/microsoft/TypeScript/issues/59012
6
6
  interface WritableStreamDefaultWriter<W = any> {
7
7
  [write]?: (a: W) => void;
8
8
  }
9
9
  interface Function {
10
10
  Ⲑid: string;
11
11
  }
12
-
13
- interface Blob {
14
- readonly meta?: Readonly<BlobMeta>;
15
- }
16
-
17
- interface File {
18
- readonly meta?: Readonly<BlobMeta>;
19
- }
20
12
  }