@milaboratories/pl-middle-layer 1.74.14 → 1.74.16

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.
@@ -1373,7 +1373,7 @@ var MiddleLayer = class MiddleLayer {
1373
1373
  ops.defaultTreeOptions.logStat = getDebugFlags().logTreeStats;
1374
1374
  ops.debugOps.dumpInitialTreeState = getDebugFlags().dumpInitialTreeState;
1375
1375
  if (ops.defaultTreeOptions.traversalMode === void 0 && getDebugFlags().treeTraversalMode !== void 0) ops.defaultTreeOptions.traversalMode = getDebugFlags().treeTraversalMode;
1376
- const { projects, templates, sharingOutbox, sharingState, folders } = await pl.withWriteTx("MLInitialization", async (tx) => {
1376
+ const initTxP = pl.withWriteTx("MLInitialization", async (tx) => {
1377
1377
  const lazyInit = async (fieldName, type) => {
1378
1378
  const f = field(tx.clientRoot, fieldName);
1379
1379
  tx.createField(f, "Dynamic");
@@ -1386,23 +1386,40 @@ var MiddleLayer = class MiddleLayer {
1386
1386
  }
1387
1387
  return { existing: fData.value };
1388
1388
  };
1389
- const projectsR = await lazyInit(ProjectsField, ProjectsResourceType);
1390
- const templatesR = await lazyInit(TemplatesField, TemplatesResourceType);
1391
- const outboxR = await lazyInit(SharingOutboxField, SharingOutboxResourceType);
1392
- const stateR = await lazyInit(SharingStateField, SharingStateResourceType);
1393
- const foldersR = await lazyInit(FoldersField, FoldersResourceType);
1389
+ const [projectsR, templatesR, outboxR, stateR, foldersR] = await Promise.all([
1390
+ lazyInit(ProjectsField, ProjectsResourceType),
1391
+ lazyInit(TemplatesField, TemplatesResourceType),
1392
+ lazyInit(SharingOutboxField, SharingOutboxResourceType),
1393
+ lazyInit(SharingStateField, SharingStateResourceType),
1394
+ lazyInit(FoldersField, FoldersResourceType)
1395
+ ]);
1394
1396
  await tx.commit();
1395
1397
  const idOf = async (r) => "existing" in r ? r.existing : await r.ref.globalId;
1398
+ const [projects, templates, sharingState, sharingOutbox, folders] = await Promise.all([
1399
+ idOf(projectsR),
1400
+ idOf(templatesR),
1401
+ idOf(stateR),
1402
+ idOf(outboxR),
1403
+ idOf(foldersR)
1404
+ ]);
1396
1405
  return {
1397
- projects: await idOf(projectsR),
1398
- templates: await idOf(templatesR),
1399
- sharingState: await idOf(stateR),
1400
- sharingOutbox: await idOf(outboxR),
1401
- folders: await idOf(foldersR)
1406
+ projects,
1407
+ templates,
1408
+ sharingState,
1409
+ sharingOutbox,
1410
+ folders
1402
1411
  };
1403
1412
  });
1413
+ const driverKitP = initDriverKit(pl, workdir, ops.frontendDownloadPath, ops);
1414
+ const [initTx, driverKitR] = await Promise.allSettled([initTxP, driverKitP]);
1415
+ if (initTx.status === "rejected") {
1416
+ if (driverKitR.status === "fulfilled") await driverKitR.value.dispose();
1417
+ throw initTx.reason;
1418
+ }
1419
+ if (driverKitR.status === "rejected") throw driverKitR.reason;
1420
+ const { projects, templates, sharingOutbox, sharingState, folders } = initTx.value;
1421
+ const driverKit = driverKitR.value;
1404
1422
  const logger = ops.logger;
1405
- const driverKit = await initDriverKit(pl, workdir, ops.frontendDownloadPath, ops);
1406
1423
  const retryHttpDispatcher = new RetryAgent(pl.httpDispatcher);
1407
1424
  const v2RegistryProvider = new V2RegistryProvider(retryHttpDispatcher);
1408
1425
  const bpPreparer = new BlockPackPreparer(v2RegistryProvider, driverKit.signer, retryHttpDispatcher);
@@ -1450,12 +1467,16 @@ var MiddleLayer = class MiddleLayer {
1450
1467
  }
1451
1468
  };
1452
1469
  const openedProjects = new WatchableValue([]);
1453
- const projectListTC = await createProjectList(pl, projects, openedProjects, env);
1454
- const templateListTC = await createTemplateList(pl, templates, env);
1455
- const foldersTC = await createFolderList(pl, folders, projectListTC.tree, templateListTC.tree, openedProjects, env);
1456
- const outgoingTC = await createOutgoingShares(pl, sharingOutbox, env);
1457
- const sharingStateTree = await createSharingStateTree(pl, sharingState, env);
1458
- const availableSharesTree = await createAvailableSharesTree(pl, env);
1470
+ const projectListP = createProjectList(pl, projects, openedProjects, env);
1471
+ const templateListP = createTemplateList(pl, templates, env);
1472
+ const [projectListTC, templateListTC, foldersTC, outgoingTC, sharingStateTree, availableSharesTree] = await Promise.all([
1473
+ projectListP,
1474
+ templateListP,
1475
+ createFolderList(pl, folders, projectListP.then((tc) => tc.tree), templateListP.then((tc) => tc.tree), openedProjects, env),
1476
+ createOutgoingShares(pl, sharingOutbox, env),
1477
+ createSharingStateTree(pl, sharingState, env),
1478
+ createAvailableSharesTree(pl, env)
1479
+ ]);
1459
1480
  const availableShares = createAvailableSharesComputable(availableSharesTree, sharingStateTree, pl.userResources.authUser);
1460
1481
  const liveEnvelopes = createLiveEnvelopesComputable(availableSharesTree);
1461
1482
  return new MiddleLayer(env, driverKit, driverKit.signer, projects, templates, sharingOutbox, sharingState, folders, openedProjects, projectListTC.tree, templateListTC.tree, foldersTC.tree, outgoingTC.tree, sharingStateTree, availableSharesTree, v2RegistryProvider, projectListTC.computable, templateListTC.computable, foldersTC.computable, outgoingTC.computable, availableShares, liveEnvelopes);