@travetto/model 4.0.6 → 4.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Datastore abstraction for core operations.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datastore",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"directory": "module/model"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@travetto/config": "^4.0
|
|
30
|
-
"@travetto/di": "^4.0
|
|
31
|
-
"@travetto/registry": "^4.0
|
|
32
|
-
"@travetto/schema": "^4.0
|
|
29
|
+
"@travetto/config": "^4.1.0",
|
|
30
|
+
"@travetto/di": "^4.1.0",
|
|
31
|
+
"@travetto/registry": "^4.1.0",
|
|
32
|
+
"@travetto/schema": "^4.1.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@travetto/cli": "^4.0
|
|
36
|
-
"@travetto/test": "^4.0
|
|
35
|
+
"@travetto/cli": "^4.1.0",
|
|
36
|
+
"@travetto/test": "^4.1.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependenciesMeta": {
|
|
39
39
|
"@travetto/cli": {
|
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Class } from '@travetto/base';
|
|
2
2
|
import { ModelType } from '../../types/model';
|
|
3
3
|
|
|
4
4
|
class Cls { id: string; }
|
|
5
5
|
export const StreamModel: Class<ModelType> = Cls;
|
|
6
|
-
export const STREAMS = '_streams';
|
|
7
|
-
|
|
8
|
-
export class ModelStreamUtil {
|
|
9
|
-
static enforceRange(start: number, end: number | undefined, size: number): [start: number, end: number] {
|
|
10
|
-
|
|
11
|
-
end ??= size - 1;
|
|
12
|
-
|
|
13
|
-
if (Number.isNaN(start) || Number.isNaN(end) || !Number.isFinite(start) || start >= size || start < 0) {
|
|
14
|
-
throw new AppError('Invalid position, out of range', 'data');
|
|
15
|
-
}
|
|
16
|
-
if (end >= size) {
|
|
17
|
-
end = size - 1;
|
|
18
|
-
}
|
|
19
|
-
return [start, end];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
6
|
+
export const STREAMS = '_streams';
|
package/src/provider/file.ts
CHANGED
|
@@ -21,7 +21,7 @@ import { ModelCrudUtil } from '../internal/service/crud';
|
|
|
21
21
|
import { ModelExpiryUtil } from '../internal/service/expiry';
|
|
22
22
|
import { NotFoundError } from '../error/not-found';
|
|
23
23
|
import { ExistsError } from '../error/exists';
|
|
24
|
-
import {
|
|
24
|
+
import { StreamModel, STREAMS } from '../internal/service/stream';
|
|
25
25
|
|
|
26
26
|
type Suffix = '.bin' | '.meta' | '.json' | '.expires';
|
|
27
27
|
|
|
@@ -194,7 +194,7 @@ export class FileModelService implements ModelCrudSupport, ModelStreamSupport, M
|
|
|
194
194
|
const file = await this.#find(STREAMS, BIN, location);
|
|
195
195
|
const meta = await this.describeStream(location);
|
|
196
196
|
|
|
197
|
-
[start, end] =
|
|
197
|
+
[start, end] = StreamUtil.enforceRange(start, end, meta.size);
|
|
198
198
|
|
|
199
199
|
const stream = createReadStream(file, { start, end });
|
|
200
200
|
return { stream, range: [start, end] };
|
package/src/provider/memory.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { ExistsError } from '../error/exists';
|
|
|
18
18
|
import { ModelIndexedSupport } from '../service/indexed';
|
|
19
19
|
import { ModelIndexedUtil } from '../internal/service/indexed';
|
|
20
20
|
import { ModelStorageUtil } from '../internal/service/storage';
|
|
21
|
-
import {
|
|
21
|
+
import { StreamModel, STREAMS } from '../internal/service/stream';
|
|
22
22
|
import { IndexConfig } from '../registry/types';
|
|
23
23
|
|
|
24
24
|
const STREAM_META = `${STREAMS}_meta`;
|
|
@@ -253,7 +253,7 @@ export class MemoryModelService implements ModelCrudSupport, ModelStreamSupport,
|
|
|
253
253
|
const streams = this.#find(STREAMS, location, 'notfound');
|
|
254
254
|
const buffer = streams.get(location)!;
|
|
255
255
|
|
|
256
|
-
[start, end] =
|
|
256
|
+
[start, end] = StreamUtil.enforceRange(start, end, buffer.length);
|
|
257
257
|
|
|
258
258
|
const stream = await StreamUtil.bufferToStream(buffer.subarray(start, end + 1));
|
|
259
259
|
return { stream, range: [start, end] };
|