@uniformdev/cli 20.61.2-alpha.4 → 20.62.1-alpha.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.
@@ -22,7 +22,7 @@ import { fetch as undiciFetch, ProxyAgent } from "undici";
22
22
  // package.json
23
23
  var package_default = {
24
24
  name: "@uniformdev/cli",
25
- version: "20.61.1",
25
+ version: "20.62.0",
26
26
  description: "Uniform command line interface tool",
27
27
  license: "SEE LICENSE IN LICENSE.txt",
28
28
  main: "./cli.js",
@@ -1,4 +1,4 @@
1
- import "./chunk-G6VN2UTK.mjs";
1
+ import "./chunk-RKOT64CV.mjs";
2
2
 
3
3
  // src/sync/allSerializableEntitiesConfig.ts
4
4
  var allSerializableEntitiesConfig = {
package/dist/index.mjs CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  withFormatOptions,
19
19
  withProjectOptions,
20
20
  withTeamOptions
21
- } from "./chunk-G6VN2UTK.mjs";
21
+ } from "./chunk-RKOT64CV.mjs";
22
22
 
23
23
  // src/index.ts
24
24
  import * as dotenv from "dotenv";
@@ -625,9 +625,6 @@ export default uniformConfig({
625
625
  `;
626
626
 
627
627
  // src/sync/fileSyncEngineDataSource.ts
628
- function isErrorWithCode(error, code) {
629
- return typeof error === "object" && error !== null && "code" in error && error.code === code;
630
- }
631
628
  async function createFileSyncEngineDataSource({
632
629
  directory,
633
630
  format = "yaml",
@@ -688,7 +685,7 @@ ${e?.message}`));
688
685
  }
689
686
  await unlink(providerId);
690
687
  },
691
- writeObject: async (object4, existingObject) => {
688
+ writeObject: async (object4) => {
692
689
  const filename = selectFilename3 ? join(directory, `${selectFilename3(object4.object)}.${format}`) : getFullFilename(object4.id);
693
690
  let contents = object4.object;
694
691
  if (selectSchemaUrl2) {
@@ -701,18 +698,6 @@ ${e?.message}`));
701
698
  console.log(`Writing file ${filename}`);
702
699
  }
703
700
  emitWithFormat(contents, format, filename);
704
- if (existingObject?.providerId && existingObject.providerId !== filename) {
705
- if (verbose) {
706
- console.log(`Deleting file ${existingObject.providerId}`);
707
- }
708
- try {
709
- await unlink(existingObject.providerId);
710
- } catch (error) {
711
- if (!isErrorWithCode(error, "ENOENT")) {
712
- throw error;
713
- }
714
- }
715
- }
716
701
  }
717
702
  };
718
703
  }
@@ -736,6 +721,7 @@ function writeUniformPackage(filename, packageContents) {
736
721
  // src/sync/syncEngine.ts
737
722
  import { diffJson, diffLines } from "diff";
738
723
  import mitt from "mitt";
724
+ import PQueue from "p-queue";
739
725
 
740
726
  // src/sync/serializedDequal.ts
741
727
  var has = Object.prototype.hasOwnProperty;
@@ -789,6 +775,7 @@ function serializedDequal(foo, bar) {
789
775
  }
790
776
 
791
777
  // src/sync/syncEngine.ts
778
+ var DEFAULT_SYNC_ACTION_CONCURRENCY = 10;
792
779
  var syncEngineEvents = mitt();
793
780
  async function syncEngine({
794
781
  source,
@@ -802,7 +789,8 @@ async function syncEngine({
802
789
  onBeforeProcessObject,
803
790
  onBeforeCompareObjects,
804
791
  onBeforeWriteObject,
805
- onError
792
+ onError,
793
+ actionConcurrency = DEFAULT_SYNC_ACTION_CONCURRENCY
806
794
  //verbose = false,
807
795
  }) {
808
796
  const status = new ReactiveStatusUpdate((status2) => syncEngineEvents.emit("statusUpdate", status2));
@@ -851,46 +839,43 @@ async function syncEngine({
851
839
  const ids = Array.isArray(sourceObject.id) ? sourceObject.id : [sourceObject.id];
852
840
  const targetObject = targetItems.get(ids[0]);
853
841
  status.compared++;
854
- const invalidTargetObjects = ids.map((i) => targetItems.get(i)).filter(
855
- (invalidTargetObject) => typeof invalidTargetObject !== "undefined" && invalidTargetObject.object !== targetObject?.object
856
- );
857
- const targetIds = Array.isArray(targetObject?.id) ? targetObject.id : [targetObject?.id];
858
- const processedIds = new Set([...ids, ...targetIds].filter((id) => typeof id === "string"));
859
- const processUpdate = async (sourceObject2, targetObject2) => {
860
- try {
861
- if (!whatIf) {
862
- const finalSourceObject = onBeforeWriteObject ? await onBeforeWriteObject(sourceObject2, targetObject2) : sourceObject2;
863
- await target.writeObject(finalSourceObject, targetObject2);
864
- status.changesApplied++;
865
- }
866
- } catch (e) {
867
- if (onError) {
868
- onError(e, sourceObject2);
869
- } else {
870
- throw new SyncEngineError(e, sourceObject2);
871
- }
872
- } finally {
873
- log2({
874
- action: "update",
875
- id: ids[0],
876
- providerId: sourceObject2.providerId,
877
- displayName: sourceObject2.displayName ?? sourceObject2.providerId,
878
- whatIf,
879
- diff: () => diffJson(targetObject2.object, sourceObject2.object)
880
- });
881
- }
882
- };
842
+ const invalidTargetObjects = ids.map((i) => targetItems.get(i)).filter((o) => o?.object !== targetObject?.object);
883
843
  if (targetObject && invalidTargetObjects.length === 0) {
884
844
  sourceObject = onBeforeCompareObjects ? await onBeforeCompareObjects(sourceObject, targetObject) : sourceObject;
885
845
  const compareResult = compareContents(sourceObject, targetObject);
886
846
  if (!compareResult) {
887
847
  if (mode === "createOrUpdate" || mode === "mirror") {
888
848
  status.changeCount++;
889
- actions.push(() => processUpdate(sourceObject, targetObject));
849
+ const process2 = async (sourceObject2, targetObject2) => {
850
+ try {
851
+ if (!whatIf) {
852
+ const finalSourceObject = onBeforeWriteObject ? await onBeforeWriteObject(sourceObject2, targetObject2) : sourceObject2;
853
+ await target.writeObject(finalSourceObject, targetObject2);
854
+ status.changesApplied++;
855
+ }
856
+ } catch (e) {
857
+ if (onError) {
858
+ onError(e, sourceObject2);
859
+ } else {
860
+ throw new SyncEngineError(e, sourceObject2);
861
+ }
862
+ } finally {
863
+ log2({
864
+ action: "update",
865
+ id: ids[0],
866
+ providerId: sourceObject2.providerId,
867
+ displayName: sourceObject2.displayName ?? sourceObject2.providerId,
868
+ whatIf,
869
+ diff: () => diffJson(targetObject2.object, sourceObject2.object)
870
+ });
871
+ }
872
+ };
873
+ actions.push(() => process2(sourceObject, targetObject));
890
874
  }
891
875
  }
892
- processedIds.forEach((i) => targetItems.delete(i));
876
+ ids.forEach((i) => targetItems.delete(i));
893
877
  } else {
878
+ status.changeCount++;
894
879
  const processUpsert = async (sourceObject2, id) => {
895
880
  try {
896
881
  if (!whatIf) {
@@ -916,23 +901,6 @@ async function syncEngine({
916
901
  }
917
902
  };
918
903
  if (invalidTargetObjects.length > 0) {
919
- if (mode === "createOrUpdate" && !targetObject && invalidTargetObjects.length === 1) {
920
- const matchedTargetObject = invalidTargetObjects[0];
921
- sourceObject = onBeforeCompareObjects ? await onBeforeCompareObjects(sourceObject, matchedTargetObject) : sourceObject;
922
- const compareResult = compareContents(sourceObject, matchedTargetObject);
923
- if (!compareResult) {
924
- status.changeCount++;
925
- actions.push(() => processUpdate(sourceObject, matchedTargetObject));
926
- }
927
- (Array.isArray(matchedTargetObject.id) ? matchedTargetObject.id : [matchedTargetObject.id]).forEach(
928
- (i) => targetItems.delete(i)
929
- );
930
- continue;
931
- }
932
- if (mode !== "mirror") {
933
- continue;
934
- }
935
- status.changeCount++;
936
904
  [...invalidTargetObjects, targetObject].forEach((o) => {
937
905
  (Array.isArray(o?.id) ? o?.id : [o?.id])?.forEach((i) => i && targetItems.delete(i));
938
906
  });
@@ -941,32 +909,37 @@ async function syncEngine({
941
909
  deletes.push(() => processDelete(targetObject));
942
910
  }
943
911
  actions.push(
944
- () => Promise.all(deletes.map((deleteFn) => deleteFn())).then(() => processUpsert(sourceObject, ids[0]))
912
+ () => runSyncActions(deletes, actionConcurrency).then(() => processUpsert(sourceObject, ids[0]))
945
913
  );
946
914
  } else {
947
- status.changeCount++;
948
915
  actions.push(() => processUpsert(sourceObject, ids[0]));
949
916
  }
950
917
  }
951
918
  }
952
- const orphanTargetObjects = new Set(targetItems.values());
919
+ status.changeCount += targetItems.size;
920
+ status.compared += targetItems.size;
953
921
  if (mode === "mirror") {
954
- status.changeCount += orphanTargetObjects.size;
955
- status.compared += orphanTargetObjects.size;
956
- if (!sourceHasItems && !allowEmptySource && orphanTargetObjects.size > 0) {
922
+ if (!sourceHasItems && !allowEmptySource && targetItems.size > 0) {
957
923
  throw new Error(
958
924
  `Sync source (${source.name}) is empty and mode is mirror. This would cause deletion of everything in the target (${target.name}), and most likely indicates an error in source definition.`
959
925
  );
960
926
  }
961
927
  const deletes = [];
962
- orphanTargetObjects.forEach((object4) => {
928
+ targetItems.forEach((object4) => {
963
929
  deletes.push(() => processDelete(object4));
964
930
  });
965
- await Promise.all(deletes.map((d) => d()));
931
+ await runSyncActions(deletes, actionConcurrency);
966
932
  }
967
- await Promise.all(actions.map((a) => a()));
933
+ await runSyncActions(actions, actionConcurrency);
968
934
  await Promise.all([source.onSyncComplete?.(false), target.onSyncComplete?.(true)]);
969
935
  }
936
+ var runSyncActions = async (actions, actionConcurrency) => {
937
+ if (actions.length === 0) {
938
+ return;
939
+ }
940
+ const queue = new PQueue({ concurrency: actionConcurrency });
941
+ await queue.addAll(actions);
942
+ };
970
943
  var SyncEngineError = class _SyncEngineError extends Error {
971
944
  constructor(innerError, sourceObject) {
972
945
  super(
@@ -2234,20 +2207,59 @@ import {
2234
2207
  } from "@uniformdev/canvas";
2235
2208
  import { isRichTextNodeType, isRichTextValue, walkRichTextTree } from "@uniformdev/richtext";
2236
2209
  import fsj4 from "fs-jetpack";
2237
- import PQueue2 from "p-queue";
2210
+ import PQueue3 from "p-queue";
2238
2211
  import { join as join10 } from "path";
2239
2212
 
2240
2213
  // src/files/downloadFile.ts
2214
+ import { createWriteStream } from "fs";
2241
2215
  import fsj2 from "fs-jetpack";
2242
- import { join as join8 } from "path";
2216
+ import { dirname as dirname2, join as join8 } from "path";
2217
+ import { Readable } from "stream";
2218
+ import { pipeline } from "stream/promises";
2219
+ var downloadedFilePathCacheByDirectory = /* @__PURE__ */ new Map();
2220
+ var getDownloadedFilePathCache = (filesDirectory) => {
2221
+ const cached = downloadedFilePathCacheByDirectory.get(filesDirectory);
2222
+ if (cached) {
2223
+ return cached;
2224
+ }
2225
+ const cache = fsj2.cwd(filesDirectory).findAsync({ files: true, directories: false }).then((paths) => new Set(paths)).catch(() => /* @__PURE__ */ new Set());
2226
+ downloadedFilePathCacheByDirectory.set(filesDirectory, cache);
2227
+ return cache;
2228
+ };
2229
+ var filePathMatchesSourceId = (filePath, sourceId) => filePath === sourceId || filePath.startsWith(`${sourceId}.`);
2230
+ var hasFilePathMatchingSourceId = (filePaths, sourceId) => {
2231
+ for (const filePath of filePaths) {
2232
+ if (filePathMatchesSourceId(filePath, sourceId)) {
2233
+ return true;
2234
+ }
2235
+ }
2236
+ return false;
2237
+ };
2238
+ var writeResponseBodyToFile = async (response, filePath) => {
2239
+ if (!response.body) {
2240
+ throw new Error("Response does not contain a body");
2241
+ }
2242
+ const tempFilePath = `${filePath}.${process.pid}.${Date.now()}.download`;
2243
+ await fsj2.dirAsync(dirname2(filePath));
2244
+ try {
2245
+ const responseBody = response.body;
2246
+ await pipeline(Readable.fromWeb(responseBody), createWriteStream(tempFilePath));
2247
+ await fsj2.moveAsync(tempFilePath, filePath, { overwrite: true });
2248
+ } catch (error) {
2249
+ await fsj2.removeAsync(tempFilePath).catch(() => void 0);
2250
+ throw error;
2251
+ }
2252
+ };
2243
2253
  var downloadFile = async ({
2244
2254
  fileClient,
2245
2255
  fileUrl,
2246
2256
  directory
2247
2257
  }) => {
2248
2258
  const writeDirectory = getFilesDirectory(directory);
2259
+ const filesDirectory = join8(writeDirectory, FILES_DIRECTORY_NAME);
2249
2260
  const fileName = urlToFileName(fileUrl.toString());
2250
- const fileAlreadyExists = await fsj2.existsAsync(join8(writeDirectory, FILES_DIRECTORY_NAME, fileName));
2261
+ const filePath = join8(filesDirectory, fileName);
2262
+ const fileAlreadyExists = await fsj2.existsAsync(filePath);
2251
2263
  if (fileAlreadyExists) {
2252
2264
  return { url: fileUrl };
2253
2265
  }
@@ -2257,11 +2269,10 @@ var downloadFile = async ({
2257
2269
  return null;
2258
2270
  }
2259
2271
  if (file.sourceId) {
2272
+ const sourceId = file.sourceId;
2260
2273
  try {
2261
- const hashAlreadyExists = await fsj2.findAsync(join8(writeDirectory, FILES_DIRECTORY_NAME), {
2262
- matching: [file.sourceId, `${file.sourceId}.*`]
2263
- });
2264
- if (hashAlreadyExists.length > 0) {
2274
+ const downloadedFilePaths = await getDownloadedFilePathCache(filesDirectory);
2275
+ if (hasFilePathMatchingSourceId(downloadedFilePaths, sourceId)) {
2265
2276
  return { id: file.id, url: fileUrl };
2266
2277
  }
2267
2278
  } catch {
@@ -2272,8 +2283,12 @@ var downloadFile = async ({
2272
2283
  if (!response.ok) {
2273
2284
  return null;
2274
2285
  }
2275
- const fileBuffer = await response.arrayBuffer();
2276
- await fsj2.writeAsync(join8(writeDirectory, FILES_DIRECTORY_NAME, fileName), Buffer.from(fileBuffer));
2286
+ await writeResponseBodyToFile(response, filePath);
2287
+ const downloadedFilePathCache = downloadedFilePathCacheByDirectory.get(filesDirectory);
2288
+ if (downloadedFilePathCache) {
2289
+ const downloadedFilePaths = await downloadedFilePathCache;
2290
+ downloadedFilePaths.add(fileName);
2291
+ }
2277
2292
  return { id: file.id, url: fileUrl };
2278
2293
  };
2279
2294
 
@@ -2284,10 +2299,10 @@ import { fileTypeFromBuffer } from "file-type";
2284
2299
  import fsj3 from "fs-jetpack";
2285
2300
  import sizeOf from "image-size";
2286
2301
  import normalizeNewline from "normalize-newline";
2287
- import PQueue from "p-queue";
2302
+ import PQueue2 from "p-queue";
2288
2303
  import { join as join9 } from "path";
2289
2304
  var uploadQueueByKey = /* @__PURE__ */ new Map();
2290
- var fileUploadQueue = new PQueue({ concurrency: 10 });
2305
+ var fileUploadQueue = new PQueue2({ concurrency: 10 });
2291
2306
  var uploadFile = async ({
2292
2307
  fileClient,
2293
2308
  fileUrl,
@@ -2572,7 +2587,7 @@ var downloadFilesForCompositionOrEntry = async ({
2572
2587
  directory,
2573
2588
  fileClient
2574
2589
  }) => {
2575
- const fileDownloadQueue = new PQueue2({ concurrency: 10 });
2590
+ const fileDownloadQueue = new PQueue3({ concurrency: 10 });
2576
2591
  await walkFileUrlsForCompositionOrEntry({
2577
2592
  entity,
2578
2593
  callback: ({ fileUrl }) => {
@@ -2588,7 +2603,7 @@ var uploadFilesForCompositionOrEntry = async ({
2588
2603
  directory,
2589
2604
  fileClient
2590
2605
  }) => {
2591
- const fileUploadQueue2 = new PQueue2({ concurrency: 10 });
2606
+ const fileUploadQueue2 = new PQueue3({ concurrency: 10 });
2592
2607
  const urlReplacementMap = /* @__PURE__ */ new Map();
2593
2608
  walkFileUrlsForCompositionOrEntry({
2594
2609
  entity: entity.object,
@@ -2621,7 +2636,7 @@ var replaceRemoteUrlsWithLocalReferences = async ({
2621
2636
  let sourceEntityAsString = JSON.stringify(sourceEntity);
2622
2637
  const targetEntityAsString = JSON.stringify(targetEntity);
2623
2638
  const writeDirectory = getFilesDirectory(directory);
2624
- const fileUrlReplacementQueue = new PQueue2({ concurrency: 10 });
2639
+ const fileUrlReplacementQueue = new PQueue3({ concurrency: 10 });
2625
2640
  walkFileUrlsForCompositionOrEntry({
2626
2641
  entity: sourceEntity.object,
2627
2642
  callback: ({ fileUrl }) => {
@@ -2661,7 +2676,7 @@ var replaceLocalUrlsWithRemoteReferences = async ({
2661
2676
  fileClient
2662
2677
  }) => {
2663
2678
  let entityAsString = JSON.stringify(entity);
2664
- const fileUrlReplacementQueue = new PQueue2({ concurrency: 10 });
2679
+ const fileUrlReplacementQueue = new PQueue3({ concurrency: 10 });
2665
2680
  walkFileUrlsForCompositionOrEntry({
2666
2681
  entity: entity.object,
2667
2682
  callback: ({ fileUrl }) => {
@@ -11994,20 +12009,6 @@ var selectIdentifier15 = (source, projectId) => [
11994
12009
  ];
11995
12010
  var selectFilename = (source) => cleanFileName(`${source.pathSegment}_${source.id}`);
11996
12011
  var selectDisplayName15 = (source) => `${source.name} (pid: ${source.id})`;
11997
- function alignProjectMapNodeWithTargetIdentifier(sourceObject, targetObject) {
11998
- if (!targetObject) {
11999
- return sourceObject;
12000
- }
12001
- return {
12002
- ...sourceObject,
12003
- id: targetObject.id,
12004
- providerId: targetObject.providerId,
12005
- object: {
12006
- ...sourceObject.object,
12007
- id: targetObject.object.id
12008
- }
12009
- };
12010
- }
12011
12012
 
12012
12013
  // src/commands/project-map/ProjectMapNodeEngineDataSource.ts
12013
12014
  function createProjectMapNodeEngineDataSource({
@@ -12224,12 +12225,6 @@ var ProjectMapNodePushModule = {
12224
12225
  whatIf,
12225
12226
  allowEmptySource,
12226
12227
  log: createSyncEngineConsoleLogger({ diffMode }),
12227
- onBeforeCompareObjects: async (sourceObject, targetObject) => {
12228
- return alignProjectMapNodeWithTargetIdentifier(sourceObject, targetObject);
12229
- },
12230
- onBeforeWriteObject: async (sourceObject, targetObject) => {
12231
- return alignProjectMapNodeWithTargetIdentifier(sourceObject, targetObject);
12232
- },
12233
12228
  onError: (error, object4) => {
12234
12229
  if (error.message.includes(__INTERNAL_MISSING_PARENT_NODE_ERROR)) {
12235
12230
  nodesFailedDueToMissingParent.add(object4.object);
@@ -12633,7 +12628,7 @@ import yargs40 from "yargs";
12633
12628
 
12634
12629
  // src/webhooksClient.ts
12635
12630
  import { ApiClient as ApiClient4 } from "@uniformdev/context/api";
12636
- import PQueue3 from "p-queue";
12631
+ import PQueue4 from "p-queue";
12637
12632
  import { Svix } from "svix";
12638
12633
  import * as z3 from "zod/v3";
12639
12634
  var WEBHOOKS_DASHBOARD_BASE_PATH = "/api/v1/svix-dashboard";
@@ -12681,7 +12676,7 @@ var WebhooksClient = class extends ApiClient4 {
12681
12676
  };
12682
12677
  }
12683
12678
  async get() {
12684
- const webhooksAPIQueue = new PQueue3({ concurrency: 10 });
12679
+ const webhooksAPIQueue = new PQueue4({ concurrency: 10 });
12685
12680
  const { appId, token } = await this.getToken();
12686
12681
  const svix = new Svix(token);
12687
12682
  const getEndpoints = async ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/cli",
3
- "version": "20.61.2-alpha.4+06664f4ab6",
3
+ "version": "20.62.1-alpha.4+295a1c3116",
4
4
  "description": "Uniform command line interface tool",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./cli.js",
@@ -27,13 +27,13 @@
27
27
  "dependencies": {
28
28
  "@inquirer/prompts": "^7.10.1",
29
29
  "@thi.ng/mime": "^2.2.23",
30
- "@uniformdev/assets": "20.61.2-alpha.4+06664f4ab6",
31
- "@uniformdev/canvas": "20.61.2-alpha.4+06664f4ab6",
32
- "@uniformdev/context": "20.61.2-alpha.4+06664f4ab6",
33
- "@uniformdev/files": "20.61.2-alpha.4+06664f4ab6",
34
- "@uniformdev/project-map": "20.61.2-alpha.4+06664f4ab6",
35
- "@uniformdev/redirect": "20.61.2-alpha.4+06664f4ab6",
36
- "@uniformdev/richtext": "20.61.2-alpha.4+06664f4ab6",
30
+ "@uniformdev/assets": "20.62.1-alpha.4+295a1c3116",
31
+ "@uniformdev/canvas": "20.62.1-alpha.4+295a1c3116",
32
+ "@uniformdev/context": "20.62.1-alpha.4+295a1c3116",
33
+ "@uniformdev/files": "20.62.1-alpha.4+295a1c3116",
34
+ "@uniformdev/project-map": "20.62.1-alpha.4+295a1c3116",
35
+ "@uniformdev/redirect": "20.62.1-alpha.4+295a1c3116",
36
+ "@uniformdev/richtext": "20.62.1-alpha.4+295a1c3116",
37
37
  "call-bind": "^1.0.2",
38
38
  "colorette": "2.0.20",
39
39
  "cosmiconfig": "9.0.0",
@@ -80,5 +80,5 @@
80
80
  "publishConfig": {
81
81
  "access": "public"
82
82
  },
83
- "gitHead": "06664f4ab66e0ea0fcf234095dd2024c86739a83"
83
+ "gitHead": "295a1c31168e58eee9ca865d6c53d2cd7f6fe913"
84
84
  }