@milaboratories/pl-drivers 1.3.3 → 1.3.4

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": "@milaboratories/pl-drivers",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "Drivers and a low-level clients for log streaming, downloading and uploading files from and to pl",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",
@@ -26,11 +26,11 @@
26
26
  "tar-fs": "^3.0.6",
27
27
  "undici": "^6.19.8",
28
28
  "zod": "^3.23.8",
29
- "@milaboratories/pl-tree": "^1.4.5",
30
29
  "@milaboratories/ts-helpers": "^1.1.0",
31
- "@milaboratories/pl-model-common": "^1.4.0",
32
- "@milaboratories/pl-client": "^2.5.4",
33
- "@milaboratories/computable": "^2.2.0"
30
+ "@milaboratories/computable": "^2.2.0",
31
+ "@milaboratories/pl-tree": "^1.4.5",
32
+ "@milaboratories/pl-model-common": "^1.5.0",
33
+ "@milaboratories/pl-client": "^2.5.4"
34
34
  },
35
35
  "devDependencies": {
36
36
  "typescript": "~5.5.4",
@@ -19,7 +19,6 @@ test('should ok when get all storages from ls driver', async () => {
19
19
  logger,
20
20
  client,
21
21
  signer,
22
- await DefaultVirtualLocalStorages(),
23
22
  [],
24
23
  () => {
25
24
  throw Error();
@@ -46,7 +45,6 @@ test('should ok when list files from remote storage in ls driver', async () => {
46
45
  logger,
47
46
  client,
48
47
  signer,
49
- await DefaultVirtualLocalStorages(),
50
48
  [],
51
49
  () => {
52
50
  throw Error();
@@ -88,7 +86,6 @@ test('should ok when list files from local storage in ls driver', async () => {
88
86
  logger,
89
87
  client,
90
88
  signer,
91
- await DefaultVirtualLocalStorages(),
92
89
  [],
93
90
  () => {
94
91
  throw Error();
@@ -112,7 +109,6 @@ test('should ok when list files from local storage in ls driver and correctly ap
112
109
  logger,
113
110
  client,
114
111
  signer,
115
- await DefaultVirtualLocalStorages(),
116
112
  [{ storageId: 'test_storage', localPath: path.join(assetsPath, 'ls_dir_structure_test') }],
117
113
  async () => [dialogRet]
118
114
  );
@@ -154,7 +150,6 @@ test('should ok when get file using local dialog, and read its content', async (
154
150
  logger,
155
151
  client,
156
152
  signer,
157
- await DefaultVirtualLocalStorages(),
158
153
  [],
159
154
  async () => [path.join(assetsPath, 'answer_to_the_ultimate_question.txt')]
160
155
  );
package/src/drivers/ls.ts CHANGED
@@ -27,6 +27,7 @@ import {
27
27
  import { LocalStorageProjection, VirtualLocalStorageSpec } from './types';
28
28
  import { createLsFilesClient } from '../clients/helpers';
29
29
  import { validateAbsolute } from '../helpers/validate';
30
+ import { DefaultVirtualLocalStorages } from './virtual_storages';
30
31
 
31
32
  /**
32
33
  * Extends public and safe SDK's driver API with methods used internally in the middle
@@ -161,8 +162,7 @@ export class LsDriver implements InternalLsDriver {
161
162
  const virtualStorages = [...this.virtualStoragesMap.values()].map((s) => ({
162
163
  name: s.name,
163
164
  handle: createLocalStorageHandle(s.name, s.root),
164
- initialFullPath: s.initialPath,
165
- isInitialPathHome: s.isInitialPathHome
165
+ initialFullPath: s.initialPath
166
166
  }));
167
167
 
168
168
  const otherStorages = Object.entries(this.storageIdToResourceId!).map(
@@ -234,13 +234,15 @@ export class LsDriver implements InternalLsDriver {
234
234
  logger: MiLogger,
235
235
  client: PlClient,
236
236
  signer: Signer,
237
- virtualStorages: VirtualLocalStorageSpec[],
238
237
  /** Pl storages available locally */
239
238
  localProjections: LocalStorageProjection[],
240
- openFileDialogCallback: OpenFileDialogCallback
239
+ openFileDialogCallback: OpenFileDialogCallback,
240
+ virtualStorages?: VirtualLocalStorageSpec[]
241
241
  ): Promise<LsDriver> {
242
242
  const lsClient = createLsFilesClient(client, logger);
243
243
 
244
+ if (!virtualStorages) virtualStorages = await DefaultVirtualLocalStorages();
245
+
244
246
  // validating inputs
245
247
  for (const vp of virtualStorages) validateAbsolute(vp.root);
246
248
  for (const lp of localProjections) if (lp.localPath !== '') validateAbsolute(lp.localPath);
@@ -50,7 +50,4 @@ export type VirtualLocalStorageSpec = {
50
50
 
51
51
  /** Used as hint to UI controls to, set as initial path during browsing */
52
52
  readonly initialPath: string;
53
-
54
- /** Shows if the initial path is home, so this storage should be chosen by default. */
55
- readonly isInitialPathHome: boolean;
56
53
  };
@@ -11,34 +11,31 @@ export async function DefaultVirtualLocalStorages(): Promise<VirtualLocalStorage
11
11
  {
12
12
  name: 'local',
13
13
  root: '/',
14
- initialPath: home,
15
- isInitialPathHome: true
14
+ initialPath: home
16
15
  }
17
16
  ];
17
+ else {
18
+ // determine the drive on which user's home folder is stored
19
+ const homeRoot = path.parse(home).root; // e.g. C:\
20
+ const homeDrive = homeRoot.replaceAll(':\\', ''); // e.g. C drive.
18
21
 
19
- const homeRoot = path.parse(home).root; // e.g. C:\
20
- const homeDrive = homeRoot.replaceAll(':\\', ''); // e.g. C drive.
21
- const wmic = await util.promisify(exec)('wmic logicaldisk get name');
22
- const drives = windowsDrives(wmic.stdout);
22
+ // code below inspired by
23
+ // https://stackoverflow.com/a/52411712/769192
23
24
 
24
- return windowsStorages(drives, homeDrive, home);
25
- }
26
-
27
- export function windowsDrives(wmicStdout: string): string[] {
28
- return wmicStdout
29
- .split('\r\n')
30
- .filter((line) => line.includes(':'))
31
- .map((line) => line.trim().replaceAll(':', ''));
32
- }
25
+ const wmic = await util.promisify(exec)('wmic logicaldisk get name');
26
+ // parsing wmic output
27
+ const drives = wmic.stdout
28
+ .split('\r\n')
29
+ .filter((line) => line.includes(':'))
30
+ .map((line) => line.trim().replaceAll(':', ''));
33
31
 
34
- export function windowsStorages(drives: string[], homeDrive: string, home: string) {
35
- return drives.map((d) => {
36
- const isInitialPathHome = d == homeDrive;
37
- return {
38
- name: `local_disk_${d}`,
39
- root: `${d}:\\`,
40
- initialPath: isInitialPathHome ? home : `${d}:\\`,
41
- isInitialPathHome
42
- };
43
- });
32
+ return drives.map((drive) => {
33
+ const isHomeDrive = drive == homeDrive;
34
+ return {
35
+ name: `local_disk_${drive}`,
36
+ root: `${drive}:\\`,
37
+ initialPath: isHomeDrive ? home : `${drive}:\\`
38
+ }
39
+ });
40
+ }
44
41
  }