@chunkd/source 11.0.0 → 11.1.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/README.md +4 -1
- package/build/src/middleware.d.ts +6 -0
- package/build/src/range.d.ts +14 -3
- package/build/src/range.js +14 -3
- package/build/src/range.js.map +1 -1
- package/build/src/source.d.ts +13 -3
- package/build/src/source.js +1 -0
- package/build/src/source.js.map +1 -1
- package/build/src/view.d.ts +2 -1
- package/build/src/view.js +5 -2
- package/build/src/view.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Base interface for all sources used by `@chunkd`
|
|
|
5
5
|
````typescript
|
|
6
6
|
export interface Source {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* human friendly name of the source type
|
|
9
9
|
* @example "aws:s3", "file", "memory"
|
|
10
10
|
*/
|
|
11
11
|
type: string;
|
|
@@ -23,6 +23,9 @@ export interface Source {
|
|
|
23
23
|
/** Read the metadata before a fetch request */
|
|
24
24
|
head(): Promise<SourceMetadata>;
|
|
25
25
|
|
|
26
|
+
/** close the source, sources like files sometimes have open file handles that need to be closed */
|
|
27
|
+
close?(): Promise<void>;
|
|
28
|
+
|
|
26
29
|
/**
|
|
27
30
|
* Directly read bytes from the source
|
|
28
31
|
*
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { Source } from './source.js';
|
|
2
|
+
/** A {@link Source.fetch} fetch represented as a object */
|
|
2
3
|
export interface SourceRequest {
|
|
4
|
+
/** Source that triggered the request */
|
|
3
5
|
source: Source;
|
|
6
|
+
/** Offset that is attempting to be read see {@link Source.fetch} */
|
|
4
7
|
offset: number;
|
|
8
|
+
/** Number of bytes to read, or undefined see {@link Source.fetch} */
|
|
5
9
|
length: number | undefined;
|
|
6
10
|
}
|
|
7
11
|
export type SourceCallback = (req: SourceRequest) => Promise<ArrayBuffer>;
|
|
8
12
|
export interface SourceMiddleware {
|
|
9
13
|
name: string;
|
|
10
14
|
fetch(req: SourceRequest, next: SourceCallback): Promise<ArrayBuffer>;
|
|
15
|
+
/** When a source is closed, this call back is fired */
|
|
16
|
+
onClose?(source: Source): Promise<void>;
|
|
11
17
|
}
|
package/build/src/range.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
export declare const ContentRange: {
|
|
2
|
-
/** Convert a offset/length to a range request
|
|
2
|
+
/** Convert a offset/length to a range request
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* ContentRange.toRange(10) // "bytes=10"
|
|
7
|
+
* ContentRange.toRange(0, 1024) // "bytes=0-1023"
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
3
10
|
toRange(offset: number, length?: number): string;
|
|
4
11
|
/**
|
|
5
|
-
* Parse a
|
|
6
|
-
*
|
|
12
|
+
* Parse a Content-Range header to extract the size of the source
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* ContentRange.parseRange("bytes 200-1000/67589"); // 67589
|
|
17
|
+
* ```
|
|
7
18
|
* @throws if range is not a Content-Range with size
|
|
8
19
|
*/
|
|
9
20
|
parseSize(range: string): number;
|
package/build/src/range.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
export const ContentRange = {
|
|
2
|
-
/** Convert a offset/length to a range request
|
|
2
|
+
/** Convert a offset/length to a range request
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* ContentRange.toRange(10) // "bytes=10"
|
|
7
|
+
* ContentRange.toRange(0, 1024) // "bytes=0-1023"
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
3
10
|
toRange(offset, length) {
|
|
4
11
|
if (length == null)
|
|
5
12
|
return `bytes=${offset}`;
|
|
@@ -8,8 +15,12 @@ export const ContentRange = {
|
|
|
8
15
|
return `bytes=${offset}-${offset + length - 1}`;
|
|
9
16
|
},
|
|
10
17
|
/**
|
|
11
|
-
* Parse a
|
|
12
|
-
*
|
|
18
|
+
* Parse a Content-Range header to extract the size of the source
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* ContentRange.parseRange("bytes 200-1000/67589"); // 67589
|
|
23
|
+
* ```
|
|
13
24
|
* @throws if range is not a Content-Range with size
|
|
14
25
|
*/
|
|
15
26
|
parseSize(range) {
|
package/build/src/range.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.js","sourceRoot":"","sources":["../../src/range.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B
|
|
1
|
+
{"version":3,"file":"range.js","sourceRoot":"","sources":["../../src/range.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B;;;;;;;OAOG;IACH,OAAO,CAAC,MAAc,EAAE,MAAe;QACrC,IAAI,MAAM,IAAI,IAAI;YAAE,OAAO,SAAS,MAAM,EAAE,CAAC;QAC7C,IAAI,MAAM,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;QAClG,OAAO,SAAS,MAAM,IAAI,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC;IAClD,CAAC;IAED;;;;;;;;OAQG;IACH,SAAS,CAAC,KAAa;QACrB,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACxC,IAAI,IAAI,KAAK,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,KAAK,CAAC,CAAC;QACjF,IAAI,MAAM,IAAI,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,KAAK,CAAC,CAAC;QAC/E,MAAM,CAAC,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5B,IAAI,KAAK,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,KAAK,CAAC,CAAC;QAC9E,OAAO,MAAM,CAAC;IAChB,CAAC;CACF,CAAC"}
|
package/build/src/source.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/** @typedef {Error} SourceError */
|
|
1
2
|
export interface Source {
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
+
* human friendly name of the source type
|
|
4
5
|
* @example "aws:s3", "file", "memory"
|
|
5
6
|
*/
|
|
6
7
|
type: string;
|
|
@@ -10,9 +11,14 @@ export interface Source {
|
|
|
10
11
|
* @example "s3://linz-imagery/catalog.json" or "file:///home/blacha/18_126359_137603.webp"
|
|
11
12
|
*/
|
|
12
13
|
url: URL;
|
|
13
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Metadata about the object the source represents
|
|
16
|
+
*
|
|
17
|
+
* Some information such as {@link SourceMetadata.size|size} or {@link SourceMetadata.eTag|eTag} can be read after the first {@link fetch}
|
|
18
|
+
* other information requires {@link head|head()} to be called.
|
|
19
|
+
*/
|
|
14
20
|
metadata?: SourceMetadata;
|
|
15
|
-
/**
|
|
21
|
+
/** head the source to read the Metadata and sets {@link metadata} */
|
|
16
22
|
head(): Promise<SourceMetadata>;
|
|
17
23
|
/** close the source, sources like files sometimes have open file handles that need to be closed */
|
|
18
24
|
close?(): Promise<void>;
|
|
@@ -27,6 +33,9 @@ export interface Source {
|
|
|
27
33
|
*```
|
|
28
34
|
* @param offset Byte to start reading form
|
|
29
35
|
* @param length optional number of bytes to read
|
|
36
|
+
*
|
|
37
|
+
* @throws {SourceError} on read failures.
|
|
38
|
+
* @throws {SourceError} if the file is modified between reads.
|
|
30
39
|
*/
|
|
31
40
|
fetch(offset: number, length?: number): Promise<ArrayBuffer>;
|
|
32
41
|
}
|
|
@@ -39,5 +48,6 @@ export interface SourceMetadata {
|
|
|
39
48
|
contentType?: string;
|
|
40
49
|
contentDisposition?: string;
|
|
41
50
|
lastModified?: string;
|
|
51
|
+
/** Extra metadata from the source, see individual sources to see what values are added */
|
|
42
52
|
metadata?: Record<string, unknown>;
|
|
43
53
|
}
|
package/build/src/source.js
CHANGED
package/build/src/source.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../src/source.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../../src/source.ts"],"names":[],"mappings":"AAAA,mCAAmC"}
|
package/build/src/view.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { Source, SourceMetadata } from './source.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Wrap a source with middleware to modify requests to the sources
|
|
5
5
|
*
|
|
6
|
-
* @see @
|
|
6
|
+
* @see {@link SourceMiddleware}
|
|
7
|
+
* @see @chunkd/middle for example middleware
|
|
7
8
|
*/
|
|
8
9
|
export declare class SourceView implements Source {
|
|
9
10
|
source: Source;
|
package/build/src/view.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Wrap a source with middleware to modify requests to the sources
|
|
3
3
|
*
|
|
4
|
-
* @see @
|
|
4
|
+
* @see {@link SourceMiddleware}
|
|
5
|
+
* @see @chunkd/middle for example middleware
|
|
5
6
|
*/
|
|
6
7
|
export class SourceView {
|
|
7
8
|
source;
|
|
@@ -28,7 +29,9 @@ export class SourceView {
|
|
|
28
29
|
return this.source.head();
|
|
29
30
|
}
|
|
30
31
|
async close() {
|
|
31
|
-
|
|
32
|
+
await this.source.close?.();
|
|
33
|
+
for (const middleware of this.middleware)
|
|
34
|
+
await middleware.onClose?.(this.source);
|
|
32
35
|
}
|
|
33
36
|
async fetch(offset, length) {
|
|
34
37
|
const middleware = this.middleware;
|
package/build/src/view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/view.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,OAAO,UAAU;IACrB,MAAM,CAAS;IACf,UAAU,CAAqB;IAE/B,MAAM,CAAC,EAAE,CAAC,CAAS;QACjB,IAAI,YAAY,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QACnC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,YAAY,MAAc,EAAE,aAAiC,EAAE;QAC7D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IACzB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;IAC9B,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;QAC5B,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,UAAU;YAAE,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpF,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,MAAc,EAAE,MAAe;QACzC,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QACnC,IAAI,UAAU,IAAI,IAAI,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC5F,MAAM,OAAO,GAAmB,CAAC,GAAkB,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QAClG,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED,6CAA6C;IAC7C,KAAK,CAAC,GAAG,CAAC,OAAuB,EAAE,MAAc,EAAE,MAAe;QAChE,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QACnC,IAAI,UAAU,IAAI,IAAI;YAAE,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAEzE,SAAS,aAAa,CAAC,UAA4B,EAAE,IAAoB;YACvE,OAAO,CAAC,GAAkB,EAAwB,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACnF,CAAC;QAED,KAAK,IAAI,CAAC,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;YAAE,OAAO,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QACjG,OAAO,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACnD,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chunkd/source",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16.0.0"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"test": "node --test"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@types/node": "^18.
|
|
21
|
+
"@types/node": "^18.16.19"
|
|
22
22
|
},
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public"
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"files": [
|
|
27
27
|
"build/src"
|
|
28
28
|
],
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "1214cfe32bc6a0962bd8127382d863ec957840fc"
|
|
30
30
|
}
|