@uniformdev/cli 20.67.0 → 20.67.1-alpha.22

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 +72 -20
  2. package/package.json +9 -9
package/dist/index.mjs CHANGED
@@ -724,6 +724,7 @@ function writeUniformPackage(filename, packageContents) {
724
724
  // src/sync/syncEngine.ts
725
725
  import { diffJson, diffLines } from "diff";
726
726
  import mitt from "mitt";
727
+ import PQueue from "p-queue";
727
728
 
728
729
  // src/sync/serializedDequal.ts
729
730
  var has = Object.prototype.hasOwnProperty;
@@ -777,6 +778,7 @@ function serializedDequal(foo, bar) {
777
778
  }
778
779
 
779
780
  // src/sync/syncEngine.ts
781
+ var DEFAULT_SYNC_ACTION_CONCURRENCY = 10;
780
782
  var syncEngineEvents = mitt();
781
783
  async function syncEngine({
782
784
  source,
@@ -790,7 +792,8 @@ async function syncEngine({
790
792
  onBeforeProcessObject,
791
793
  onBeforeCompareObjects,
792
794
  onBeforeWriteObject,
793
- onError
795
+ onError,
796
+ actionConcurrency = DEFAULT_SYNC_ACTION_CONCURRENCY
794
797
  //verbose = false,
795
798
  }) {
796
799
  const status = new ReactiveStatusUpdate((status2) => syncEngineEvents.emit("statusUpdate", status2));
@@ -909,7 +912,7 @@ async function syncEngine({
909
912
  deletes.push(() => processDelete(targetObject));
910
913
  }
911
914
  actions.push(
912
- () => Promise.all(deletes.map((deleteFn) => deleteFn())).then(() => processUpsert(sourceObject, ids[0]))
915
+ () => runSyncActions(deletes, actionConcurrency).then(() => processUpsert(sourceObject, ids[0]))
913
916
  );
914
917
  } else {
915
918
  actions.push(() => processUpsert(sourceObject, ids[0]));
@@ -928,11 +931,18 @@ async function syncEngine({
928
931
  targetItems.forEach((object4) => {
929
932
  deletes.push(() => processDelete(object4));
930
933
  });
931
- await Promise.all(deletes.map((d) => d()));
934
+ await runSyncActions(deletes, actionConcurrency);
932
935
  }
933
- await Promise.all(actions.map((a) => a()));
936
+ await runSyncActions(actions, actionConcurrency);
934
937
  await Promise.all([source.onSyncComplete?.(false), target.onSyncComplete?.(true)]);
935
938
  }
939
+ var runSyncActions = async (actions, actionConcurrency) => {
940
+ if (actions.length === 0) {
941
+ return;
942
+ }
943
+ const queue = new PQueue({ concurrency: actionConcurrency });
944
+ await queue.addAll(actions);
945
+ };
936
946
  var SyncEngineError = class _SyncEngineError extends Error {
937
947
  constructor(innerError, sourceObject) {
938
948
  super(
@@ -2200,20 +2210,59 @@ import {
2200
2210
  } from "@uniformdev/canvas";
2201
2211
  import { isRichTextNodeType, isRichTextValue, walkRichTextTree } from "@uniformdev/richtext";
2202
2212
  import fsj4 from "fs-jetpack";
2203
- import PQueue2 from "p-queue";
2213
+ import PQueue3 from "p-queue";
2204
2214
  import { join as join10 } from "path";
2205
2215
 
2206
2216
  // src/files/downloadFile.ts
2217
+ import { createWriteStream } from "fs";
2207
2218
  import fsj2 from "fs-jetpack";
2208
- import { join as join8 } from "path";
2219
+ import { dirname as dirname2, join as join8 } from "path";
2220
+ import { Readable } from "stream";
2221
+ import { pipeline } from "stream/promises";
2222
+ var downloadedFilePathCacheByDirectory = /* @__PURE__ */ new Map();
2223
+ var getDownloadedFilePathCache = (filesDirectory) => {
2224
+ const cached = downloadedFilePathCacheByDirectory.get(filesDirectory);
2225
+ if (cached) {
2226
+ return cached;
2227
+ }
2228
+ const cache = fsj2.cwd(filesDirectory).findAsync({ files: true, directories: false }).then((paths) => new Set(paths)).catch(() => /* @__PURE__ */ new Set());
2229
+ downloadedFilePathCacheByDirectory.set(filesDirectory, cache);
2230
+ return cache;
2231
+ };
2232
+ var filePathMatchesSourceId = (filePath, sourceId) => filePath === sourceId || filePath.startsWith(`${sourceId}.`);
2233
+ var hasFilePathMatchingSourceId = (filePaths, sourceId) => {
2234
+ for (const filePath of filePaths) {
2235
+ if (filePathMatchesSourceId(filePath, sourceId)) {
2236
+ return true;
2237
+ }
2238
+ }
2239
+ return false;
2240
+ };
2241
+ var writeResponseBodyToFile = async (response, filePath) => {
2242
+ if (!response.body) {
2243
+ throw new Error("Response does not contain a body");
2244
+ }
2245
+ const tempFilePath = `${filePath}.${process.pid}.${Date.now()}.download`;
2246
+ await fsj2.dirAsync(dirname2(filePath));
2247
+ try {
2248
+ const responseBody = response.body;
2249
+ await pipeline(Readable.fromWeb(responseBody), createWriteStream(tempFilePath));
2250
+ await fsj2.moveAsync(tempFilePath, filePath, { overwrite: true });
2251
+ } catch (error) {
2252
+ await fsj2.removeAsync(tempFilePath).catch(() => void 0);
2253
+ throw error;
2254
+ }
2255
+ };
2209
2256
  var downloadFile = async ({
2210
2257
  fileClient,
2211
2258
  fileUrl,
2212
2259
  directory
2213
2260
  }) => {
2214
2261
  const writeDirectory = getFilesDirectory(directory);
2262
+ const filesDirectory = join8(writeDirectory, FILES_DIRECTORY_NAME);
2215
2263
  const fileName = urlToFileName(fileUrl.toString());
2216
- const fileAlreadyExists = await fsj2.existsAsync(join8(writeDirectory, FILES_DIRECTORY_NAME, fileName));
2264
+ const filePath = join8(filesDirectory, fileName);
2265
+ const fileAlreadyExists = await fsj2.existsAsync(filePath);
2217
2266
  if (fileAlreadyExists) {
2218
2267
  return { url: fileUrl };
2219
2268
  }
@@ -2223,11 +2272,10 @@ var downloadFile = async ({
2223
2272
  return null;
2224
2273
  }
2225
2274
  if (file.sourceId) {
2275
+ const sourceId = file.sourceId;
2226
2276
  try {
2227
- const hashAlreadyExists = await fsj2.findAsync(join8(writeDirectory, FILES_DIRECTORY_NAME), {
2228
- matching: [file.sourceId, `${file.sourceId}.*`]
2229
- });
2230
- if (hashAlreadyExists.length > 0) {
2277
+ const downloadedFilePaths = await getDownloadedFilePathCache(filesDirectory);
2278
+ if (hasFilePathMatchingSourceId(downloadedFilePaths, sourceId)) {
2231
2279
  return { id: file.id, url: fileUrl };
2232
2280
  }
2233
2281
  } catch {
@@ -2238,8 +2286,12 @@ var downloadFile = async ({
2238
2286
  if (!response.ok) {
2239
2287
  return null;
2240
2288
  }
2241
- const fileBuffer = await response.arrayBuffer();
2242
- await fsj2.writeAsync(join8(writeDirectory, FILES_DIRECTORY_NAME, fileName), Buffer.from(fileBuffer));
2289
+ await writeResponseBodyToFile(response, filePath);
2290
+ const downloadedFilePathCache = downloadedFilePathCacheByDirectory.get(filesDirectory);
2291
+ if (downloadedFilePathCache) {
2292
+ const downloadedFilePaths = await downloadedFilePathCache;
2293
+ downloadedFilePaths.add(fileName);
2294
+ }
2243
2295
  return { id: file.id, url: fileUrl };
2244
2296
  };
2245
2297
 
@@ -2251,10 +2303,10 @@ import { createReadStream } from "fs";
2251
2303
  import fsj3 from "fs-jetpack";
2252
2304
  import { imageSizeFromFile } from "image-size/fromFile";
2253
2305
  import normalizeNewline from "normalize-newline";
2254
- import PQueue from "p-queue";
2306
+ import PQueue2 from "p-queue";
2255
2307
  import { join as join9 } from "path";
2256
2308
  var uploadQueueByKey = /* @__PURE__ */ new Map();
2257
- var fileUploadQueue = new PQueue({ concurrency: 10 });
2309
+ var fileUploadQueue = new PQueue2({ concurrency: 10 });
2258
2310
  var uploadFile = async ({
2259
2311
  fileClient,
2260
2312
  fileUrl,
@@ -2434,9 +2486,9 @@ var walkFileUrlsForCompositionOrEntry = ({
2434
2486
  };
2435
2487
 
2436
2488
  // src/files/files.ts
2437
- var fileDownloadQueue = new PQueue2({ concurrency: 10 });
2438
- var fileUploadQueue2 = new PQueue2({ concurrency: 10 });
2439
- var fileUrlReplacementQueue = new PQueue2({ concurrency: 10 });
2489
+ var fileDownloadQueue = new PQueue3({ concurrency: 10 });
2490
+ var fileUploadQueue2 = new PQueue3({ concurrency: 10 });
2491
+ var fileUrlReplacementQueue = new PQueue3({ concurrency: 10 });
2440
2492
  var downloadFileForAsset = async ({
2441
2493
  asset,
2442
2494
  directory,
@@ -12782,7 +12834,7 @@ import yargs40 from "yargs";
12782
12834
 
12783
12835
  // src/webhooksClient.ts
12784
12836
  import { ApiClient as ApiClient4 } from "@uniformdev/context/api";
12785
- import PQueue3 from "p-queue";
12837
+ import PQueue4 from "p-queue";
12786
12838
  import { Svix } from "svix";
12787
12839
  import * as z3 from "zod";
12788
12840
  var WEBHOOKS_DASHBOARD_BASE_PATH = "/api/v1/svix-dashboard";
@@ -12830,7 +12882,7 @@ var WebhooksClient = class extends ApiClient4 {
12830
12882
  };
12831
12883
  }
12832
12884
  async get() {
12833
- const webhooksAPIQueue = new PQueue3({ concurrency: 10 });
12885
+ const webhooksAPIQueue = new PQueue4({ concurrency: 10 });
12834
12886
  const { appId, token } = await this.getToken();
12835
12887
  const svix = new Svix(token);
12836
12888
  const getEndpoints = async ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/cli",
3
- "version": "20.67.0",
3
+ "version": "20.67.1-alpha.22+329be3528c",
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.67.0",
31
- "@uniformdev/canvas": "20.67.0",
32
- "@uniformdev/context": "20.67.0",
33
- "@uniformdev/files": "20.67.0",
34
- "@uniformdev/project-map": "20.67.0",
35
- "@uniformdev/redirect": "20.67.0",
36
- "@uniformdev/richtext": "20.67.0",
30
+ "@uniformdev/assets": "20.67.1-alpha.22+329be3528c",
31
+ "@uniformdev/canvas": "20.67.1-alpha.22+329be3528c",
32
+ "@uniformdev/context": "20.67.1-alpha.22+329be3528c",
33
+ "@uniformdev/files": "20.67.1-alpha.22+329be3528c",
34
+ "@uniformdev/project-map": "20.67.1-alpha.22+329be3528c",
35
+ "@uniformdev/redirect": "20.67.1-alpha.22+329be3528c",
36
+ "@uniformdev/richtext": "20.67.1-alpha.22+329be3528c",
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": "e97ff55db904f9f4b5c21a18a3ad21a94084684c"
83
+ "gitHead": "329be3528c6e4e6d01316386d18059ec0ffcd172"
84
84
  }