@milaboratories/pl-drivers 1.3.26 → 1.4.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.
Files changed (78) hide show
  1. package/dist/clients/constructors.d.ts +14 -0
  2. package/dist/clients/constructors.d.ts.map +1 -0
  3. package/dist/clients/download.d.ts +19 -14
  4. package/dist/clients/download.d.ts.map +1 -1
  5. package/dist/clients/helpers.d.ts +4 -13
  6. package/dist/clients/helpers.d.ts.map +1 -1
  7. package/dist/clients/upload.d.ts +15 -13
  8. package/dist/clients/upload.d.ts.map +1 -1
  9. package/dist/drivers/{download_and_logs_blob.d.ts → download_blob.d.ts} +13 -40
  10. package/dist/drivers/download_blob.d.ts.map +1 -0
  11. package/dist/drivers/download_blob_task.d.ts +34 -0
  12. package/dist/drivers/download_blob_task.d.ts.map +1 -0
  13. package/dist/drivers/download_url.d.ts +11 -9
  14. package/dist/drivers/download_url.d.ts.map +1 -1
  15. package/dist/drivers/helpers/download_local_handle.d.ts +9 -0
  16. package/dist/drivers/helpers/download_local_handle.d.ts.map +1 -0
  17. package/dist/drivers/helpers/download_remote_handle.d.ts +8 -0
  18. package/dist/drivers/helpers/download_remote_handle.d.ts.map +1 -0
  19. package/dist/drivers/helpers/files_cache.d.ts +2 -1
  20. package/dist/drivers/helpers/files_cache.d.ts.map +1 -1
  21. package/dist/drivers/helpers/helpers.d.ts +2 -24
  22. package/dist/drivers/helpers/helpers.d.ts.map +1 -1
  23. package/dist/drivers/helpers/logs_handle.d.ts +13 -0
  24. package/dist/drivers/helpers/logs_handle.d.ts.map +1 -0
  25. package/dist/drivers/helpers/ls_remote_import_handle.d.ts +8 -0
  26. package/dist/drivers/helpers/ls_remote_import_handle.d.ts.map +1 -0
  27. package/dist/drivers/logs.d.ts +1 -5
  28. package/dist/drivers/logs.d.ts.map +1 -1
  29. package/dist/drivers/logs_stream.d.ts.map +1 -1
  30. package/dist/drivers/ls.d.ts.map +1 -1
  31. package/dist/drivers/types.d.ts +47 -4
  32. package/dist/drivers/types.d.ts.map +1 -1
  33. package/dist/drivers/upload.d.ts +2 -28
  34. package/dist/drivers/upload.d.ts.map +1 -1
  35. package/dist/drivers/upload_task.d.ts +41 -0
  36. package/dist/drivers/upload_task.d.ts.map +1 -0
  37. package/dist/helpers/download.d.ts +2 -2
  38. package/dist/helpers/download.d.ts.map +1 -1
  39. package/dist/index.d.ts +2 -2
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +2 -2
  42. package/dist/index.js.map +1 -1
  43. package/dist/index.mjs +1537 -1526
  44. package/dist/index.mjs.map +1 -1
  45. package/package.json +6 -6
  46. package/src/clients/constructors.ts +54 -0
  47. package/src/clients/download.test.ts +9 -6
  48. package/src/clients/download.ts +74 -64
  49. package/src/clients/helpers.ts +2 -53
  50. package/src/clients/upload.ts +136 -102
  51. package/src/drivers/download_blob.test.ts +12 -11
  52. package/src/drivers/{download_and_logs_blob.ts → download_blob.ts} +154 -290
  53. package/src/drivers/download_blob_task.ts +126 -0
  54. package/src/drivers/download_url.test.ts +1 -1
  55. package/src/drivers/download_url.ts +44 -37
  56. package/src/drivers/helpers/download_local_handle.ts +29 -0
  57. package/src/drivers/helpers/download_remote_handle.ts +40 -0
  58. package/src/drivers/helpers/files_cache.test.ts +7 -6
  59. package/src/drivers/helpers/files_cache.ts +6 -5
  60. package/src/drivers/helpers/helpers.ts +6 -100
  61. package/src/drivers/helpers/logs_handle.ts +52 -0
  62. package/src/drivers/helpers/ls_remote_import_handle.ts +43 -0
  63. package/src/drivers/logs.test.ts +14 -14
  64. package/src/drivers/logs.ts +3 -43
  65. package/src/drivers/logs_stream.ts +32 -6
  66. package/src/drivers/ls.test.ts +1 -2
  67. package/src/drivers/ls.ts +26 -28
  68. package/src/drivers/types.ts +48 -0
  69. package/src/drivers/upload.test.ts +8 -18
  70. package/src/drivers/upload.ts +38 -271
  71. package/src/drivers/upload_task.ts +251 -0
  72. package/src/helpers/download.ts +18 -15
  73. package/src/index.ts +2 -2
  74. package/dist/drivers/download_and_logs_blob.d.ts.map +0 -1
  75. package/dist/drivers/helpers/ls_list_entry.d.ts +0 -44
  76. package/dist/drivers/helpers/ls_list_entry.d.ts.map +0 -1
  77. package/src/drivers/helpers/ls_list_entry.test.ts +0 -55
  78. package/src/drivers/helpers/ls_list_entry.ts +0 -147
package/src/index.ts CHANGED
@@ -3,9 +3,9 @@ export * from './clients/progress';
3
3
  export * from './clients/download';
4
4
  export * from './clients/ls_api';
5
5
  export * from './clients/logs';
6
- export * from './clients/helpers';
6
+ export * from './clients/constructors';
7
7
 
8
- export * from './drivers/download_and_logs_blob';
8
+ export * from './drivers/download_blob';
9
9
  export * from './drivers/upload';
10
10
  export * from './drivers/logs_stream';
11
11
  export * from './drivers/logs';
@@ -1 +0,0 @@
1
- {"version":3,"file":"download_and_logs_blob.d.ts","sourceRoot":"","sources":["../../src/drivers/download_and_logs_blob.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,UAAU,EACV,aAAa,EACb,uBAAuB,EACvB,OAAO,EACR,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,cAAc,EACd,QAAQ,EAER,MAAM,EACN,YAAY,EACb,MAAM,4BAA4B,CAAC;AAKpC,OAAO,EAAE,cAAc,EAA0C,MAAM,qBAAqB,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAS7C,OAAO,EACL,aAAa,EACb,YAAY,EACZ,WAAW,EAKX,gBAAgB,EAGjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,YAAY,EACZ,UAAU,EACV,eAAe,EACf,sBAAsB,EACtB,cAAc,EACd,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,0DAA0D;AAC1D,eAAO,MAAM,4BAA4B;;;;;;;;EAMvC,CAAC;AAEH,MAAM,MAAM,4BAA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EAAE,MAAM,EACpB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,oBAAoB,CAAC;YAiBlB,WAAW;IA0BzB,OAAO,CAAC,UAAU;YAQJ,mBAAmB;IAKjC,2CAA2C;IACrC,UAAU;IAShB,OAAO,CAAC,WAAW;CAGpB;AAkHD,qBAAa,QAAQ;IASjB,QAAQ,CAAC,cAAc,EAAE,cAAc;IACvC,QAAQ,CAAC,KAAK,EAAE,gBAAgB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,MAAM,EAAE,eAAe;IAXlC,QAAQ,CAAC,OAAO,iBAAwB;IACxC,QAAQ,CAAC,MAAM,eAAsB;IACrC,QAAQ,CAAC,SAAS,kBAAyB;IAC3C,KAAK,EAAE,GAAG,GAAG,SAAS,CAAC;IACvB,IAAI,UAAS;IACb,SAAS,SAAK;gBAGH,cAAc,EAAE,cAAc,EAC9B,KAAK,EAAE,gBAAgB,EACvB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,eAAe;IAGlC,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM;IAK7B,QAAQ;IAqCd,OAAO,IAAI,YAAY,CAAC,sBAAsB,CAAC,GAAG,SAAS;IAmB3D,OAAO,CAAC,OAAO;IAMf,KAAK,CAAC,MAAM,EAAE,MAAM;IAIpB,OAAO,CAAC,QAAQ;CAIjB"}
@@ -1,44 +0,0 @@
1
- import { MiLogger, Signer } from '@milaboratories/ts-helpers';
2
- import { Timestamp } from '../../proto/google/protobuf/timestamp';
3
- import { Dirent, Stats } from 'node:fs';
4
- import { ImportFileHandleIndexData, ImportFileHandleUploadData } from '../types';
5
- import * as sdk from '@milaboratories/pl-model-common';
6
- /** A duck-typing interface for grpc results. */
7
- export interface ListResponse {
8
- items: ListItem[];
9
- delimiter: string;
10
- }
11
- /** @deprecated */
12
- export interface ListItem {
13
- isDir: boolean;
14
- name: string;
15
- fullName: string;
16
- lastModified?: Timestamp;
17
- size: bigint;
18
- directory: string;
19
- }
20
- /** @deprecated */
21
- export declare function toLsEntries(info: {
22
- storageName: string;
23
- list: ListResponse;
24
- signer: Signer;
25
- remote: boolean;
26
- }): sdk.ListFilesResult;
27
- /** @deprecated */
28
- export declare function toFileHandle(info: {
29
- storageName: string;
30
- item: ListItem;
31
- signer: Signer;
32
- remote: boolean;
33
- }): sdk.ImportFileHandle;
34
- export declare function createIndexImportHandle(storageName: string, path: string): sdk.ImportFileHandleIndex;
35
- export declare function createUploadImportHandle(localPath: string, signer: Signer, sizeBytes: bigint, modificationTimeSeconds: bigint): sdk.ImportFileHandleUpload;
36
- export declare function parseUploadHandle(handle: sdk.ImportFileHandleUpload): ImportFileHandleUploadData;
37
- export declare function parseIndexHandle(handle: sdk.ImportFileHandleIndex): ImportFileHandleIndexData;
38
- export declare function toListItem(logger: MiLogger, info: {
39
- directory: string;
40
- fullName: string;
41
- dirent: Dirent;
42
- stat: Stats;
43
- }): ListItem | undefined;
44
- //# sourceMappingURL=ls_list_entry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ls_list_entry.d.ts","sourceRoot":"","sources":["../../../src/drivers/helpers/ls_list_entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAY,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,KAAK,GAAG,MAAM,iCAAiC,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAEjF,gDAAgD;AAChD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AACD,kBAAkB;AAClB,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,E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
- import { ConsoleLoggerAdapter, HmacSha256Signer } from '@milaboratories/ts-helpers';
2
- import { parseUploadHandle, toFileHandle, toListItem } from './ls_list_entry';
3
- import type { Dirent, Stats } from 'node:fs';
4
- import { ImportFileHandleUpload } from '@milaboratories/pl-model-common';
5
-
6
- test('toFileHandle should ok when encode data for UploadBlob', () => {
7
- const signer = new HmacSha256Signer('abc');
8
-
9
- const handle = toFileHandle({
10
- storageName: 'library',
11
- signer,
12
- remote: false,
13
- item: {
14
- directory: 'C:\\programFiles\\',
15
- name: 'file.txt',
16
- size: 20n,
17
- isDir: false,
18
- fullName: 'C:\\programFiles\\file.txt',
19
- lastModified: { seconds: 150n, nanos: 260 }
20
- }
21
- }) as ImportFileHandleUpload;
22
- const got = parseUploadHandle(handle);
23
-
24
- expect(got.modificationTime).toEqual('150');
25
- expect(got.localPath).toEqual('C:\\programFiles\\file.txt');
26
- expect(got.pathSignature).not.toHaveLength(0);
27
- expect(got.sizeBytes).toEqual('20');
28
- });
29
-
30
- test('toListItem should ok', () => {
31
- const got = toListItem(new ConsoleLoggerAdapter(), {
32
- fullName: 'C:\\programFiles\\file.txt',
33
- dirent: {
34
- isFile: () => true,
35
- isDirectory: () => false,
36
- name: 'file.txt'
37
- } as Dirent,
38
- directory: 'C:\\programFiles\\',
39
- stat: {
40
- mtimeMs: 150000,
41
- size: 20
42
- } as Stats
43
- });
44
-
45
- expect(got).toMatchObject({
46
- isDir: false,
47
- name: 'file.txt',
48
- fullName: 'C:\\programFiles\\file.txt',
49
- lastModified: {
50
- seconds: 150n,
51
- nanos: 0
52
- },
53
- size: 20n
54
- });
55
- });
@@ -1,147 +0,0 @@
1
- import { MiLogger, notEmpty, Signer } from '@milaboratories/ts-helpers';
2
- import * as sdk from '@milaboratories/pl-model-common';
3
- import { Timestamp } from '../../proto/google/protobuf/timestamp';
4
- import { Dirent, Stats } from 'node:fs';
5
- import { z } from 'zod';
6
- import { ImportFileHandleIndexData, ImportFileHandleUploadData } from '../types';
7
-
8
- /** A duck-typing interface for grpc results. */
9
- export interface ListResponse {
10
- items: ListItem[];
11
- delimiter: string;
12
- }
13
- /** @deprecated */
14
- export interface ListItem {
15
- isDir: boolean;
16
- name: string;
17
- fullName: string;
18
- lastModified?: Timestamp;
19
- size: bigint;
20
- directory: string;
21
- }
22
-
23
- /** @deprecated */
24
- export function toLsEntries(info: {
25
- storageName: string;
26
- list: ListResponse;
27
- signer: Signer;
28
- remote: boolean;
29
- }): sdk.ListFilesResult {
30
- const parent = info.list.items.length > 0 ? info.list.items[0]?.directory : undefined;
31
-
32
- return {
33
- parent: parent,
34
- entries: info.list.items.map((item) => toLsEntry(item, info))
35
- };
36
- }
37
-
38
- /** @deprecated */
39
- function toLsEntry(
40
- item: ListItem,
41
- info: {
42
- storageName: string;
43
- list: ListResponse;
44
- signer: Signer;
45
- remote: boolean;
46
- }
47
- ): sdk.LsEntry {
48
- if (item.isDir)
49
- return {
50
- type: 'dir',
51
- name: item.name,
52
- fullPath: item.fullName
53
- };
54
-
55
- return {
56
- type: 'file',
57
- name: item.name,
58
- fullPath: item.fullName,
59
- handle: toFileHandle({ item: item, ...info })
60
- };
61
- }
62
-
63
- /** @deprecated */
64
- export function toFileHandle(info: {
65
- storageName: string;
66
- item: ListItem;
67
- signer: Signer;
68
- remote: boolean;
69
- }): sdk.ImportFileHandle {
70
- if (info.remote) {
71
- return createIndexImportHandle(info.storageName, info.item.fullName);
72
- }
73
-
74
- return createUploadImportHandle(
75
- info.item.fullName,
76
- info.signer,
77
- info.item.size,
78
- notEmpty(info.item.lastModified).seconds
79
- );
80
- }
81
-
82
- export function createIndexImportHandle(
83
- storageName: string,
84
- path: string
85
- ): sdk.ImportFileHandleIndex {
86
- const data: ImportFileHandleIndexData = {
87
- storageId: storageName,
88
- path: path
89
- };
90
-
91
- return `index://index/${encodeURIComponent(JSON.stringify(data))}`;
92
- }
93
-
94
- export function createUploadImportHandle(
95
- localPath: string,
96
- signer: Signer,
97
- sizeBytes: bigint,
98
- modificationTimeSeconds: bigint
99
- ): sdk.ImportFileHandleUpload {
100
- const data: ImportFileHandleUploadData = {
101
- localPath,
102
- pathSignature: signer.sign(localPath),
103
- sizeBytes: String(sizeBytes),
104
- modificationTime: String(modificationTimeSeconds)
105
- };
106
-
107
- return `upload://upload/${encodeURIComponent(JSON.stringify(data))}`;
108
- }
109
-
110
- export function parseUploadHandle(handle: sdk.ImportFileHandleUpload): ImportFileHandleUploadData {
111
- const url = new URL(handle);
112
- return ImportFileHandleUploadData.parse(
113
- JSON.parse(decodeURIComponent(url.pathname.substring(1)))
114
- );
115
- }
116
-
117
- export function parseIndexHandle(handle: sdk.ImportFileHandleIndex): ImportFileHandleIndexData {
118
- const url = new URL(handle);
119
- return ImportFileHandleIndexData.parse(JSON.parse(decodeURIComponent(url.pathname.substring(1))));
120
- }
121
-
122
- export function toListItem(
123
- logger: MiLogger,
124
- info: {
125
- directory: string;
126
- fullName: string;
127
- dirent: Dirent;
128
- stat: Stats;
129
- }
130
- ): ListItem | undefined {
131
- if (!(info.dirent.isFile() || info.dirent.isDirectory())) {
132
- logger.warn(`tried to get non-dir and non-file ${info.dirent.name}, skip it`);
133
- return;
134
- }
135
-
136
- return {
137
- directory: info.directory,
138
- isDir: info.dirent.isDirectory(),
139
- name: info.dirent.name,
140
- fullName: info.fullName,
141
- lastModified: {
142
- seconds: BigInt(Math.floor(info.stat.mtimeMs / 1000)),
143
- nanos: 0
144
- },
145
- size: BigInt(info.stat.size)
146
- };
147
- }