@uniformdev/cli 18.27.1-alpha.23 → 18.28.0

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 +82 -44
  2. package/package.json +6 -6
package/dist/index.mjs CHANGED
@@ -48,16 +48,22 @@ async function createArraySyncEngineDataSource({
48
48
  onSyncComplete
49
49
  }) {
50
50
  const objectIndex = objects.reduce((result, current) => {
51
- const identifier = selectIdentifier11(current);
52
- if (result[identifier]) {
53
- throw new Error(`Identifier ${identifier} was not unique.`);
51
+ const rawIdentifiers = selectIdentifier11(current);
52
+ const identifiers = Array.isArray(rawIdentifiers) ? rawIdentifiers : [rawIdentifiers];
53
+ while (identifiers.length > 0) {
54
+ const identifier = identifiers.pop();
55
+ if (!identifier)
56
+ continue;
57
+ if (result[identifier]) {
58
+ throw new Error(`Identifier ${identifier} was not unique.`);
59
+ }
60
+ result[identifier] = {
61
+ id: identifier,
62
+ object: current,
63
+ providerId: identifier,
64
+ displayName: selectDisplayName11(current)[0]
65
+ };
54
66
  }
55
- result[identifier] = {
56
- id: identifier,
57
- object: current,
58
- providerId: identifier,
59
- displayName: selectDisplayName11(current)
60
- };
61
67
  return result;
62
68
  }, {});
63
69
  async function* getObjects() {
@@ -75,7 +81,11 @@ async function createArraySyncEngineDataSource({
75
81
  },
76
82
  writeObject: async (objectToWrite) => {
77
83
  const id = selectIdentifier11(objectToWrite.object);
78
- objectIndex[id] = objectToWrite;
84
+ if (Array.isArray(id)) {
85
+ id.forEach((i) => objectIndex[i] = objectToWrite);
86
+ } else {
87
+ objectIndex[id] = objectToWrite;
88
+ }
79
89
  },
80
90
  extractCurrent,
81
91
  onSyncComplete: onSyncComplete ? (isTarget) => onSyncComplete(isTarget, extractCurrent()) : void 0
@@ -249,7 +259,7 @@ async function createFileSyncEngineDataSource({
249
259
  return ext === `.json` || ext === `.yaml` || ext === `.yml`;
250
260
  })
251
261
  );
252
- const getFullFilename = (id) => join(directory, `${id}.${format}`);
262
+ const getFullFilename = (id) => join(directory, `${Array.isArray(id) ? id[0] : id}.${format}`);
253
263
  async function* getObjects() {
254
264
  for (const filename of filenames) {
255
265
  const fullFilename = join(directory, filename);
@@ -257,7 +267,7 @@ async function createFileSyncEngineDataSource({
257
267
  const contents = await readFileToObject(fullFilename);
258
268
  const object = {
259
269
  id: selectIdentifier11(contents),
260
- displayName: selectDisplayName11(contents),
270
+ displayName: selectDisplayName11(contents)[0],
261
271
  providerId: fullFilename,
262
272
  object: omit(contents, ["$schema"])
263
273
  };
@@ -326,16 +336,42 @@ async function syncEngine({
326
336
  }) {
327
337
  var _a, _b;
328
338
  const targetItems = /* @__PURE__ */ new Map();
339
+ const deleteTracker = /* @__PURE__ */ new Set();
340
+ const processDelete = async (object) => {
341
+ if (deleteTracker.has(object))
342
+ return;
343
+ deleteTracker.add(object);
344
+ if (!whatIf) {
345
+ try {
346
+ await target.deleteObject(object.providerId, object);
347
+ } catch (e) {
348
+ throw new SyncEngineError(e, object);
349
+ }
350
+ }
351
+ log({
352
+ action: "delete",
353
+ id: object.id[0],
354
+ providerId: object.providerId,
355
+ displayName: object.displayName ?? object.providerId,
356
+ whatIf,
357
+ diff: diffLines(JSON.stringify(object.object, null, 2), "")
358
+ });
359
+ };
329
360
  for await (const obj of target.objects) {
330
- targetItems.set(obj.id, obj);
361
+ if (Array.isArray(obj.id)) {
362
+ obj.id.forEach((o) => targetItems.set(o, obj));
363
+ } else {
364
+ targetItems.set(obj.id, obj);
365
+ }
331
366
  }
332
367
  const actions = [];
333
368
  let sourceHasItems = false;
334
369
  for await (const sourceObject of source.objects) {
335
370
  sourceHasItems = true;
336
- const id = sourceObject.id;
337
- const targetObject = targetItems.get(id);
338
- if (targetObject) {
371
+ const ids = Array.isArray(sourceObject.id) ? sourceObject.id : [sourceObject.id];
372
+ const targetObject = targetItems.get(ids[0]);
373
+ const invalidTargetObjects = ids.map((i) => targetItems.get(i)).filter((o) => o !== targetObject);
374
+ if (targetObject && invalidTargetObjects.length == 0) {
339
375
  if (!compareContents(sourceObject, targetObject)) {
340
376
  if (mode === "createOrUpdate" || mode === "mirror") {
341
377
  const process2 = async (sourceObject2, targetObject2) => {
@@ -348,7 +384,7 @@ async function syncEngine({
348
384
  }
349
385
  log({
350
386
  action: "update",
351
- id,
387
+ id: ids[0],
352
388
  providerId: sourceObject2.providerId,
353
389
  displayName: sourceObject2.displayName ?? sourceObject2.providerId,
354
390
  whatIf,
@@ -358,9 +394,9 @@ async function syncEngine({
358
394
  actions.push(process2(sourceObject, targetObject));
359
395
  }
360
396
  }
361
- targetItems.delete(id);
397
+ ids.forEach((i) => targetItems.delete(i));
362
398
  } else {
363
- const process2 = async (sourceObject2, id2) => {
399
+ const process2 = async (sourceObject2, id) => {
364
400
  if (!whatIf) {
365
401
  try {
366
402
  await target.writeObject(sourceObject2);
@@ -370,14 +406,30 @@ async function syncEngine({
370
406
  }
371
407
  log({
372
408
  action: "create",
373
- id: id2,
374
- providerId: id2,
409
+ id,
410
+ providerId: id,
375
411
  displayName: sourceObject2.displayName ?? sourceObject2.providerId,
376
412
  whatIf,
377
413
  diff: diffLines("", JSON.stringify(sourceObject2.object, null, 2))
378
414
  });
379
415
  };
380
- actions.push(process2(sourceObject, id));
416
+ if (invalidTargetObjects.length > 0) {
417
+ [...invalidTargetObjects, targetObject].forEach(
418
+ (o) => {
419
+ var _a2;
420
+ return (_a2 = o == null ? void 0 : o.id) == null ? void 0 : _a2.forEach((i) => targetItems.delete(i));
421
+ }
422
+ );
423
+ const deletes = invalidTargetObjects.filter((io) => typeof io !== "undefined").map(async (io) => {
424
+ await processDelete(io);
425
+ });
426
+ if (targetObject) {
427
+ deletes.push(processDelete(targetObject));
428
+ }
429
+ actions.push(Promise.all(deletes).then(() => process2(sourceObject, ids[0])));
430
+ } else {
431
+ actions.push(process2(sourceObject, ids[0]));
432
+ }
381
433
  }
382
434
  }
383
435
  await Promise.all(actions);
@@ -389,24 +441,7 @@ async function syncEngine({
389
441
  }
390
442
  const deletes = [];
391
443
  targetItems.forEach(async (object) => {
392
- const process2 = async (object2) => {
393
- if (!whatIf) {
394
- try {
395
- await target.deleteObject(object2.providerId, object2);
396
- } catch (e) {
397
- throw new SyncEngineError(e, object2);
398
- }
399
- }
400
- log({
401
- action: "delete",
402
- id: object2.id,
403
- providerId: object2.providerId,
404
- displayName: object2.displayName ?? object2.providerId,
405
- whatIf,
406
- diff: diffLines(JSON.stringify(object2.object, null, 2), "")
407
- });
408
- };
409
- deletes.push(process2(object));
444
+ deletes.push(processDelete(object));
410
445
  });
411
446
  await Promise.all(deletes);
412
447
  }
@@ -3190,7 +3225,7 @@ import { PostHog } from "posthog-node";
3190
3225
  // package.json
3191
3226
  var package_default = {
3192
3227
  name: "@uniformdev/cli",
3193
- version: "18.27.0",
3228
+ version: "18.28.0",
3194
3229
  description: "Uniform command line interface tool",
3195
3230
  license: "SEE LICENSE IN LICENSE.txt",
3196
3231
  main: "./cli.js",
@@ -3223,7 +3258,7 @@ var package_default = {
3223
3258
  "js-yaml": "^4.1.0",
3224
3259
  jsonwebtoken: "9.0.0",
3225
3260
  "lodash.isequalwith": "^4.4.0",
3226
- open: "8.4.0",
3261
+ open: "9.0.0",
3227
3262
  ora: "6.2.0",
3228
3263
  "posthog-node": "2.6.0",
3229
3264
  slugify: "1.6.5",
@@ -4677,7 +4712,10 @@ var ProjectMapNodeListModule = {
4677
4712
  import { UncachedProjectMapClient as UncachedProjectMapClient9 } from "@uniformdev/project-map";
4678
4713
 
4679
4714
  // src/commands/project-map/commands/ProjectMapNode/_util.ts
4680
- var selectIdentifier10 = (source, projectId) => projectId + source.projectMapId + source.id + source.path;
4715
+ var selectIdentifier10 = (source, projectId) => [
4716
+ projectId + source.projectMapId + source.id,
4717
+ projectId + source.projectMapId + source.path
4718
+ ];
4681
4719
  var selectFilename = (source) => `${source.pathSegment}_${source.id}`;
4682
4720
  var selectDisplayName10 = (source) => `${source.name} (pid: ${source.id})`;
4683
4721
 
@@ -4695,7 +4733,7 @@ function createProjectMapNodeEngineDataSource({
4695
4733
  const result = {
4696
4734
  id: selectIdentifier10({ ...def, projectMapId: projectMap.id }, projectId),
4697
4735
  displayName: selectDisplayName10(def),
4698
- providerId: selectIdentifier10({ ...def, projectMapId: projectMap.id }, projectId),
4736
+ providerId: selectIdentifier10({ ...def, projectMapId: projectMap.id }, projectId)[0],
4699
4737
  object: { ...def, projectMapId: projectMap.id }
4700
4738
  };
4701
4739
  yield result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/cli",
3
- "version": "18.27.1-alpha.23+ed7d9bfa0",
3
+ "version": "18.28.0",
4
4
  "description": "Uniform command line interface tool",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./cli.js",
@@ -16,9 +16,9 @@
16
16
  "format": "prettier --write \"src/**/*.{js,ts,tsx}\""
17
17
  },
18
18
  "dependencies": {
19
- "@uniformdev/canvas": "18.27.1-alpha.23+ed7d9bfa0",
20
- "@uniformdev/context": "18.27.1-alpha.23+ed7d9bfa0",
21
- "@uniformdev/project-map": "18.27.1-alpha.23+ed7d9bfa0",
19
+ "@uniformdev/canvas": "18.28.0",
20
+ "@uniformdev/context": "18.28.0",
21
+ "@uniformdev/project-map": "18.28.0",
22
22
  "chalk": "^5.2.0",
23
23
  "diff": "^5.0.0",
24
24
  "dotenv": "^16.0.3",
@@ -33,7 +33,7 @@
33
33
  "js-yaml": "^4.1.0",
34
34
  "jsonwebtoken": "9.0.0",
35
35
  "lodash.isequalwith": "^4.4.0",
36
- "open": "8.4.0",
36
+ "open": "9.0.0",
37
37
  "ora": "6.2.0",
38
38
  "posthog-node": "2.6.0",
39
39
  "slugify": "1.6.5",
@@ -59,5 +59,5 @@
59
59
  "publishConfig": {
60
60
  "access": "public"
61
61
  },
62
- "gitHead": "ed7d9bfa014db103691c2d2030b1549770a48d6b"
62
+ "gitHead": "97d916ca20965e8a86d2454847114068895ccddd"
63
63
  }