@uniformdev/cli 20.70.1-alpha.10 → 20.70.1-alpha.6

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 (2) hide show
  1. package/dist/index.mjs +56 -182
  2. package/package.json +9 -9
package/dist/index.mjs CHANGED
@@ -628,9 +628,6 @@ export default uniformConfig({
628
628
  `;
629
629
 
630
630
  // src/sync/fileSyncEngineDataSource.ts
631
- function isErrorWithCode(error, code) {
632
- return typeof error === "object" && error !== null && "code" in error && error.code === code;
633
- }
634
631
  async function createFileSyncEngineDataSource({
635
632
  directory,
636
633
  format = "yaml",
@@ -691,7 +688,7 @@ ${e?.message}`));
691
688
  }
692
689
  await unlink(providerId);
693
690
  },
694
- writeObject: async (object4, existingObject) => {
691
+ writeObject: async (object4) => {
695
692
  const filename = selectFilename3 ? join(directory, `${selectFilename3(object4.object)}.${format}`) : getFullFilename(object4.id);
696
693
  let contents = object4.object;
697
694
  if (selectSchemaUrl2) {
@@ -704,18 +701,6 @@ ${e?.message}`));
704
701
  console.log(`Writing file ${filename}`);
705
702
  }
706
703
  emitWithFormat(contents, format, filename);
707
- if (existingObject?.providerId && existingObject.providerId !== filename) {
708
- if (verbose) {
709
- console.log(`Deleting file ${existingObject.providerId}`);
710
- }
711
- try {
712
- await unlink(existingObject.providerId);
713
- } catch (error) {
714
- if (!isErrorWithCode(error, "ENOENT")) {
715
- throw error;
716
- }
717
- }
718
- }
719
704
  }
720
705
  };
721
706
  }
@@ -739,7 +724,6 @@ function writeUniformPackage(filename, packageContents) {
739
724
  // src/sync/syncEngine.ts
740
725
  import { diffJson, diffLines } from "diff";
741
726
  import mitt from "mitt";
742
- import PQueue from "p-queue";
743
727
 
744
728
  // src/sync/serializedDequal.ts
745
729
  var has = Object.prototype.hasOwnProperty;
@@ -806,8 +790,7 @@ async function syncEngine({
806
790
  onBeforeProcessObject,
807
791
  onBeforeCompareObjects,
808
792
  onBeforeWriteObject,
809
- onError,
810
- actionConcurrency
793
+ onError
811
794
  //verbose = false,
812
795
  }) {
813
796
  const status = new ReactiveStatusUpdate((status2) => syncEngineEvents.emit("statusUpdate", status2));
@@ -856,46 +839,43 @@ async function syncEngine({
856
839
  const ids = Array.isArray(sourceObject.id) ? sourceObject.id : [sourceObject.id];
857
840
  const targetObject = targetItems.get(ids[0]);
858
841
  status.compared++;
859
- const invalidTargetObjects = ids.map((i) => targetItems.get(i)).filter(
860
- (invalidTargetObject) => typeof invalidTargetObject !== "undefined" && invalidTargetObject.object !== targetObject?.object
861
- );
862
- const targetIds = Array.isArray(targetObject?.id) ? targetObject.id : [targetObject?.id];
863
- const processedIds = new Set([...ids, ...targetIds].filter((id) => typeof id === "string"));
864
- const processUpdate = async (sourceObject2, targetObject2) => {
865
- try {
866
- if (!whatIf) {
867
- const finalSourceObject = onBeforeWriteObject ? await onBeforeWriteObject(sourceObject2, targetObject2) : sourceObject2;
868
- await target.writeObject(finalSourceObject, targetObject2);
869
- status.changesApplied++;
870
- }
871
- } catch (e) {
872
- if (onError) {
873
- onError(e, sourceObject2);
874
- } else {
875
- throw new SyncEngineError(e, sourceObject2);
876
- }
877
- } finally {
878
- log2({
879
- action: "update",
880
- id: ids[0],
881
- providerId: sourceObject2.providerId,
882
- displayName: sourceObject2.displayName ?? sourceObject2.providerId,
883
- whatIf,
884
- diff: () => diffJson(targetObject2.object, sourceObject2.object)
885
- });
886
- }
887
- };
842
+ const invalidTargetObjects = ids.map((i) => targetItems.get(i)).filter((o) => o?.object !== targetObject?.object);
888
843
  if (targetObject && invalidTargetObjects.length === 0) {
889
844
  sourceObject = onBeforeCompareObjects ? await onBeforeCompareObjects(sourceObject, targetObject) : sourceObject;
890
845
  const compareResult = compareContents(sourceObject, targetObject);
891
846
  if (!compareResult) {
892
847
  if (mode === "createOrUpdate" || mode === "mirror") {
893
848
  status.changeCount++;
894
- 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));
895
874
  }
896
875
  }
897
- processedIds.forEach((i) => targetItems.delete(i));
876
+ ids.forEach((i) => targetItems.delete(i));
898
877
  } else {
878
+ status.changeCount++;
899
879
  const processUpsert = async (sourceObject2, id) => {
900
880
  try {
901
881
  if (!whatIf) {
@@ -921,73 +901,38 @@ async function syncEngine({
921
901
  }
922
902
  };
923
903
  if (invalidTargetObjects.length > 0) {
924
- if (mode === "createOrUpdate" && !targetObject && invalidTargetObjects.length === 1) {
925
- const matchedTargetObject = invalidTargetObjects[0];
926
- sourceObject = onBeforeCompareObjects ? await onBeforeCompareObjects(sourceObject, matchedTargetObject) : sourceObject;
927
- const compareResult = compareContents(sourceObject, matchedTargetObject);
928
- if (!compareResult) {
929
- status.changeCount++;
930
- actions.push(() => processUpdate(sourceObject, matchedTargetObject));
931
- }
932
- (Array.isArray(matchedTargetObject.id) ? matchedTargetObject.id : [matchedTargetObject.id]).forEach(
933
- (i) => targetItems.delete(i)
934
- );
935
- continue;
936
- }
937
- if (mode !== "mirror") {
938
- continue;
939
- }
940
- status.changeCount++;
941
904
  [...invalidTargetObjects, targetObject].forEach((o) => {
942
905
  (Array.isArray(o?.id) ? o?.id : [o?.id])?.forEach((i) => i && targetItems.delete(i));
943
906
  });
944
- const deletes = invalidTargetObjects.map(
945
- (invalidTargetObject) => () => processDelete(invalidTargetObject)
946
- );
907
+ const deletes = invalidTargetObjects.filter((invalidTargetObject) => typeof invalidTargetObject !== "undefined").map((invalidTargetObject) => () => processDelete(invalidTargetObject));
947
908
  if (targetObject) {
948
909
  deletes.push(() => processDelete(targetObject));
949
910
  }
950
- actions.push(async () => {
951
- for (const deleteFn of deletes) {
952
- await deleteFn();
953
- }
954
- await processUpsert(sourceObject, ids[0]);
955
- });
911
+ actions.push(
912
+ () => Promise.all(deletes.map((deleteFn) => deleteFn())).then(() => processUpsert(sourceObject, ids[0]))
913
+ );
956
914
  } else {
957
- status.changeCount++;
958
915
  actions.push(() => processUpsert(sourceObject, ids[0]));
959
916
  }
960
917
  }
961
918
  }
962
- const orphanTargetObjects = new Set(targetItems.values());
919
+ status.changeCount += targetItems.size;
920
+ status.compared += targetItems.size;
963
921
  if (mode === "mirror") {
964
- status.changeCount += orphanTargetObjects.size;
965
- status.compared += orphanTargetObjects.size;
966
- if (!sourceHasItems && !allowEmptySource && orphanTargetObjects.size > 0) {
922
+ if (!sourceHasItems && !allowEmptySource && targetItems.size > 0) {
967
923
  throw new Error(
968
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.`
969
925
  );
970
926
  }
971
927
  const deletes = [];
972
- orphanTargetObjects.forEach((object4) => {
928
+ targetItems.forEach((object4) => {
973
929
  deletes.push(() => processDelete(object4));
974
930
  });
975
- await runSyncActions(deletes, actionConcurrency);
931
+ await Promise.all(deletes.map((d) => d()));
976
932
  }
977
- await runSyncActions(actions, actionConcurrency);
933
+ await Promise.all(actions.map((a) => a()));
978
934
  await Promise.all([source.onSyncComplete?.(false), target.onSyncComplete?.(true)]);
979
935
  }
980
- var runSyncActions = async (actions, actionConcurrency) => {
981
- if (actions.length === 0) {
982
- return;
983
- }
984
- if (typeof actionConcurrency === "undefined") {
985
- await Promise.all(actions.map((action) => action()));
986
- return;
987
- }
988
- const queue = new PQueue({ concurrency: actionConcurrency });
989
- await queue.addAll(actions);
990
- };
991
936
  var SyncEngineError = class _SyncEngineError extends Error {
992
937
  constructor(innerError, sourceObject) {
993
938
  super(
@@ -2255,64 +2200,20 @@ import {
2255
2200
  } from "@uniformdev/canvas";
2256
2201
  import { isRichTextNodeType, isRichTextValue, walkRichTextTree } from "@uniformdev/richtext";
2257
2202
  import fsj4 from "fs-jetpack";
2258
- import PQueue3 from "p-queue";
2203
+ import PQueue2 from "p-queue";
2259
2204
  import { join as join10 } from "path";
2260
2205
 
2261
2206
  // src/files/downloadFile.ts
2262
- import { createWriteStream } from "fs";
2263
2207
  import fsj2 from "fs-jetpack";
2264
- import { dirname as dirname2, join as join8 } from "path";
2265
- import { Readable } from "stream";
2266
- import { pipeline } from "stream/promises";
2267
- var downloadedFilePathCacheByDirectory = /* @__PURE__ */ new Map();
2268
- var tempDownloadFileCounter = 0;
2269
- var getTempDownloadFilePath = (filePath) => {
2270
- tempDownloadFileCounter += 1;
2271
- return `${filePath}.${process.pid}.${Date.now()}.${tempDownloadFileCounter}.download`;
2272
- };
2273
- var getDownloadedFilePathCache = (filesDirectory) => {
2274
- const cached = downloadedFilePathCacheByDirectory.get(filesDirectory);
2275
- if (cached) {
2276
- return cached;
2277
- }
2278
- const cache = fsj2.cwd(filesDirectory).findAsync({ files: true, directories: false }).then((paths) => new Set(paths)).catch(() => /* @__PURE__ */ new Set());
2279
- downloadedFilePathCacheByDirectory.set(filesDirectory, cache);
2280
- return cache;
2281
- };
2282
- var filePathMatchesSourceId = (filePath, sourceId) => filePath === sourceId || filePath.startsWith(`${sourceId}.`);
2283
- var hasFilePathMatchingSourceId = (filePaths, sourceId) => {
2284
- for (const filePath of filePaths) {
2285
- if (filePathMatchesSourceId(filePath, sourceId)) {
2286
- return true;
2287
- }
2288
- }
2289
- return false;
2290
- };
2291
- var writeResponseBodyToFile = async (response, filePath) => {
2292
- if (!response.body) {
2293
- throw new Error("Response does not contain a body");
2294
- }
2295
- const tempFilePath = getTempDownloadFilePath(filePath);
2296
- await fsj2.dirAsync(dirname2(filePath));
2297
- try {
2298
- const responseBody = response.body;
2299
- await pipeline(Readable.fromWeb(responseBody), createWriteStream(tempFilePath));
2300
- await fsj2.moveAsync(tempFilePath, filePath, { overwrite: true });
2301
- } catch (error) {
2302
- await fsj2.removeAsync(tempFilePath).catch(() => void 0);
2303
- throw error;
2304
- }
2305
- };
2208
+ import { join as join8 } from "path";
2306
2209
  var downloadFile = async ({
2307
2210
  fileClient,
2308
2211
  fileUrl,
2309
2212
  directory
2310
2213
  }) => {
2311
2214
  const writeDirectory = getFilesDirectory(directory);
2312
- const filesDirectory = join8(writeDirectory, FILES_DIRECTORY_NAME);
2313
2215
  const fileName = urlToFileName(fileUrl.toString());
2314
- const filePath = join8(filesDirectory, fileName);
2315
- const fileAlreadyExists = await fsj2.existsAsync(filePath);
2216
+ const fileAlreadyExists = await fsj2.existsAsync(join8(writeDirectory, FILES_DIRECTORY_NAME, fileName));
2316
2217
  if (fileAlreadyExists) {
2317
2218
  return { url: fileUrl };
2318
2219
  }
@@ -2322,10 +2223,11 @@ var downloadFile = async ({
2322
2223
  return null;
2323
2224
  }
2324
2225
  if (file.sourceId) {
2325
- const sourceId = file.sourceId;
2326
2226
  try {
2327
- const downloadedFilePaths = await getDownloadedFilePathCache(filesDirectory);
2328
- if (hasFilePathMatchingSourceId(downloadedFilePaths, sourceId)) {
2227
+ const hashAlreadyExists = await fsj2.findAsync(join8(writeDirectory, FILES_DIRECTORY_NAME), {
2228
+ matching: [file.sourceId, `${file.sourceId}.*`]
2229
+ });
2230
+ if (hashAlreadyExists.length > 0) {
2329
2231
  return { id: file.id, url: fileUrl };
2330
2232
  }
2331
2233
  } catch {
@@ -2336,12 +2238,8 @@ var downloadFile = async ({
2336
2238
  if (!response.ok) {
2337
2239
  return null;
2338
2240
  }
2339
- await writeResponseBodyToFile(response, filePath);
2340
- const downloadedFilePathCache = downloadedFilePathCacheByDirectory.get(filesDirectory);
2341
- if (downloadedFilePathCache) {
2342
- const downloadedFilePaths = await downloadedFilePathCache;
2343
- downloadedFilePaths.add(fileName);
2344
- }
2241
+ const fileBuffer = await response.arrayBuffer();
2242
+ await fsj2.writeAsync(join8(writeDirectory, FILES_DIRECTORY_NAME, fileName), Buffer.from(fileBuffer));
2345
2243
  return { id: file.id, url: fileUrl };
2346
2244
  };
2347
2245
 
@@ -2353,10 +2251,10 @@ import { createReadStream } from "fs";
2353
2251
  import fsj3 from "fs-jetpack";
2354
2252
  import { imageSizeFromFile } from "image-size/fromFile";
2355
2253
  import normalizeNewline from "normalize-newline";
2356
- import PQueue2 from "p-queue";
2254
+ import PQueue from "p-queue";
2357
2255
  import { join as join9 } from "path";
2358
2256
  var uploadQueueByKey = /* @__PURE__ */ new Map();
2359
- var fileUploadQueue = new PQueue2({ concurrency: 10 });
2257
+ var fileUploadQueue = new PQueue({ concurrency: 10 });
2360
2258
  var uploadFile = async ({
2361
2259
  fileClient,
2362
2260
  fileUrl,
@@ -2536,9 +2434,9 @@ var walkFileUrlsForCompositionOrEntry = ({
2536
2434
  };
2537
2435
 
2538
2436
  // src/files/files.ts
2539
- var fileDownloadQueue = new PQueue3({ concurrency: 10 });
2540
- var fileUploadQueue2 = new PQueue3({ concurrency: 10 });
2541
- var fileUrlReplacementQueue = new PQueue3({ concurrency: 10 });
2437
+ var fileDownloadQueue = new PQueue2({ concurrency: 10 });
2438
+ var fileUploadQueue2 = new PQueue2({ concurrency: 10 });
2439
+ var fileUrlReplacementQueue = new PQueue2({ concurrency: 10 });
2542
2440
  var downloadFileForAsset = async ({
2543
2441
  asset,
2544
2442
  directory,
@@ -2865,7 +2763,6 @@ function writeCanvasPackage(filename, packageContents) {
2865
2763
  }
2866
2764
 
2867
2765
  // src/commands/canvas/commands/asset/pull.ts
2868
- var ASSET_PULL_ACTION_CONCURRENCY = 10;
2869
2766
  var AssetPullModule = {
2870
2767
  command: "pull <directory>",
2871
2768
  describe: "Pulls all assets to local files in a directory",
@@ -2964,7 +2861,6 @@ var AssetPullModule = {
2964
2861
  target,
2965
2862
  mode,
2966
2863
  whatIf,
2967
- actionConcurrency: ASSET_PULL_ACTION_CONCURRENCY,
2968
2864
  allowEmptySource: allowEmptySource ?? true,
2969
2865
  log: createSyncEngineConsoleLogger({ diffMode }),
2970
2866
  onBeforeCompareObjects: async (sourceObject) => {
@@ -2992,7 +2888,6 @@ var AssetPullModule = {
2992
2888
  };
2993
2889
 
2994
2890
  // src/commands/canvas/commands/asset/push.ts
2995
- var ASSET_PUSH_ACTION_CONCURRENCY = 10;
2996
2891
  var AssetPushModule = {
2997
2892
  command: "push <directory>",
2998
2893
  describe: "Pushes all assets from files in a directory to Uniform",
@@ -3068,7 +2963,6 @@ var AssetPushModule = {
3068
2963
  target,
3069
2964
  mode,
3070
2965
  whatIf,
3071
- actionConcurrency: ASSET_PUSH_ACTION_CONCURRENCY,
3072
2966
  allowEmptySource,
3073
2967
  log: createSyncEngineConsoleLogger({ diffMode }),
3074
2968
  onBeforeCompareObjects: async (sourceObject, targetObject) => {
@@ -12269,20 +12163,6 @@ var selectIdentifier15 = (source, projectId) => [
12269
12163
  ];
12270
12164
  var selectFilename = (source) => cleanFileName(`${source.pathSegment}_${source.id}`);
12271
12165
  var selectDisplayName15 = (source) => `${source.name} (pid: ${source.id})`;
12272
- function alignProjectMapNodeWithTargetIdentifier(sourceObject, targetObject) {
12273
- if (!targetObject) {
12274
- return sourceObject;
12275
- }
12276
- return {
12277
- ...sourceObject,
12278
- id: targetObject.id,
12279
- providerId: targetObject.providerId,
12280
- object: {
12281
- ...sourceObject.object,
12282
- id: targetObject.object.id
12283
- }
12284
- };
12285
- }
12286
12166
 
12287
12167
  // src/commands/project-map/ProjectMapNodeEngineDataSource.ts
12288
12168
  function createProjectMapNodeEngineDataSource({
@@ -12499,12 +12379,6 @@ var ProjectMapNodePushModule = {
12499
12379
  whatIf,
12500
12380
  allowEmptySource,
12501
12381
  log: createSyncEngineConsoleLogger({ diffMode }),
12502
- onBeforeCompareObjects: async (sourceObject, targetObject) => {
12503
- return alignProjectMapNodeWithTargetIdentifier(sourceObject, targetObject);
12504
- },
12505
- onBeforeWriteObject: async (sourceObject, targetObject) => {
12506
- return alignProjectMapNodeWithTargetIdentifier(sourceObject, targetObject);
12507
- },
12508
12382
  onError: (error, object4) => {
12509
12383
  if (error.message.includes(__INTERNAL_MISSING_PARENT_NODE_ERROR)) {
12510
12384
  nodesFailedDueToMissingParent.add(object4.object);
@@ -12908,7 +12782,7 @@ import yargs40 from "yargs";
12908
12782
 
12909
12783
  // src/webhooksClient.ts
12910
12784
  import { ApiClient as ApiClient4 } from "@uniformdev/context/api";
12911
- import PQueue4 from "p-queue";
12785
+ import PQueue3 from "p-queue";
12912
12786
  import { Svix } from "svix";
12913
12787
  import * as z3 from "zod";
12914
12788
  var WEBHOOKS_DASHBOARD_BASE_PATH = "/api/v1/svix-dashboard";
@@ -12956,7 +12830,7 @@ var WebhooksClient = class extends ApiClient4 {
12956
12830
  };
12957
12831
  }
12958
12832
  async get() {
12959
- const webhooksAPIQueue = new PQueue4({ concurrency: 10 });
12833
+ const webhooksAPIQueue = new PQueue3({ concurrency: 10 });
12960
12834
  const { appId, token } = await this.getToken();
12961
12835
  const svix = new Svix(token);
12962
12836
  const getEndpoints = async ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/cli",
3
- "version": "20.70.1-alpha.10+6e0ecaf156",
3
+ "version": "20.70.1-alpha.6+9aeb4f32ae",
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": "^8.5.2",
29
29
  "@thi.ng/mime": "^2.2.23",
30
- "@uniformdev/assets": "20.70.1-alpha.10+6e0ecaf156",
31
- "@uniformdev/canvas": "20.70.1-alpha.10+6e0ecaf156",
32
- "@uniformdev/context": "20.70.1-alpha.10+6e0ecaf156",
33
- "@uniformdev/files": "20.70.1-alpha.10+6e0ecaf156",
34
- "@uniformdev/project-map": "20.70.1-alpha.10+6e0ecaf156",
35
- "@uniformdev/redirect": "20.70.1-alpha.10+6e0ecaf156",
36
- "@uniformdev/richtext": "20.70.1-alpha.10+6e0ecaf156",
30
+ "@uniformdev/assets": "20.70.1-alpha.6+9aeb4f32ae",
31
+ "@uniformdev/canvas": "20.70.1-alpha.6+9aeb4f32ae",
32
+ "@uniformdev/context": "20.70.1-alpha.6+9aeb4f32ae",
33
+ "@uniformdev/files": "20.70.1-alpha.6+9aeb4f32ae",
34
+ "@uniformdev/project-map": "20.70.1-alpha.6+9aeb4f32ae",
35
+ "@uniformdev/redirect": "20.70.1-alpha.6+9aeb4f32ae",
36
+ "@uniformdev/richtext": "20.70.1-alpha.6+9aeb4f32ae",
37
37
  "call-bind": "^1.0.2",
38
38
  "colorette": "2.0.20",
39
39
  "cosmiconfig": "9.0.2",
@@ -79,5 +79,5 @@
79
79
  "publishConfig": {
80
80
  "access": "public"
81
81
  },
82
- "gitHead": "6e0ecaf15691da45ddab84cc3ca11c4d048bbbdd"
82
+ "gitHead": "9aeb4f32aeef86de9ce119eeb1516f5f8c6b6063"
83
83
  }