@milaboratories/pl-drivers 1.5.57 → 1.5.59

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.
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import type { InferSnapshot } from '@milaboratories/pl-tree';
3
3
  import { rsSchema } from '@milaboratories/pl-tree';
4
+ import { RangeBytes } from '@milaboratories/pl-model-common';
4
5
 
5
6
  //
6
7
  // download
@@ -16,8 +17,18 @@ export const OnDemandBlobResourceSnapshot = rsSchema({
16
17
 
17
18
  export type OnDemandBlobResourceSnapshot = InferSnapshot<typeof OnDemandBlobResourceSnapshot>;
18
19
 
19
- export function getSize(bs: OnDemandBlobResourceSnapshot): number {
20
- return bs.kv['ctl/file/blobInfo'].sizeBytes;
20
+ export function getSize(bs: OnDemandBlobResourceSnapshot, range?: RangeBytes): number {
21
+ const size = bs.kv['ctl/file/blobInfo'].sizeBytes;
22
+ if (range) {
23
+ const newSize = range.to - range.from;
24
+ if (newSize > size) {
25
+ throw new Error(`getSize: range (${JSON.stringify(range)}, newSize: ${newSize}) is greater than size (${size})`);
26
+ }
27
+
28
+ return newSize;
29
+ }
30
+
31
+ return size;
21
32
  }
22
33
 
23
34
  //
@@ -11,6 +11,7 @@ import { expect, test } from 'vitest';
11
11
  import { Computable } from '@milaboratories/computable';
12
12
  import { SynchronizedTreeState } from '@milaboratories/pl-tree';
13
13
  import type { ImportResourceSnapshot } from './types';
14
+ import * as env from '../test_env';
14
15
 
15
16
  test('upload a blob', async () => {
16
17
  await withTest(async ({ client, uploader, signer }: TestArg) => {
@@ -226,8 +227,8 @@ test('index a blob', async () => {
226
227
  await withTest(async ({ client, uploader }: TestArg) => {
227
228
  const uploadId = await createBlobIndex(
228
229
  client,
229
- './another_answer_to_the_ultimate_question.txt',
230
- 'library',
230
+ 'another_answer_to_the_ultimate_question.txt',
231
+ env.libraryStorage,
231
232
  );
232
233
  const handleRes = await getSnapshot(client, uploadId);
233
234
 
@@ -0,0 +1,7 @@
1
+ /** A storage where we keep all the assets.
2
+ * If you run tests locally, the storage should be named `library` and point
3
+ * to the `assets` directory in this repository,
4
+ * but in CI the storage is defined in env and it points to S3 bucket. */
5
+ export const libraryStorage = process.env.PL_TEST_STORAGE_ID
6
+ ? process.env.PL_TEST_STORAGE_ID
7
+ : 'library';