@camunda8/cli 4.6.0-alpha.3 → 4.6.0-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.
@@ -43,7 +43,8 @@ version resolution.
43
43
  Detection happens in `parseTemplateRef()` in `template-ref.ts`
44
44
  before any cache call. An id found locally (`.camunda/element-templates/`
45
45
  or the Modeler user-data dir, see `resolveTemplateId`) never reaches
46
- `requireCachePresent()`; only the OOTB fallback does.
46
+ `requireCachePresent()`; only the OOTB fallback does. `update` reads the
47
+ cache only on a local gap (see `templatePool` in `commands/migrate.ts`).
47
48
  - **`saveCache` and `apply --in-place` writes are atomic.** Both
48
49
  use a sibling temp file + `renameSync`. Anything else that
49
50
  overwrites a user-owned file (cache or BPMN) must follow the same
@@ -8700,7 +8700,7 @@ function emptyFacts() {
8700
8700
  feelSkipped: []
8701
8701
  };
8702
8702
  }
8703
- function buildStepPlan(entries, sourceValues, template) {
8703
+ function buildStepPlan(entries, sourceValues, template, unverifiedReads = false) {
8704
8704
  const facts = emptyFacts();
8705
8705
  const writes = [];
8706
8706
  const write = (entry, to, value) => {
@@ -8726,6 +8726,13 @@ function buildStepPlan(entries, sourceValues, template) {
8726
8726
  return target;
8727
8727
  };
8728
8728
  for (const entry of entries) {
8729
+ if (unverifiedReads) {
8730
+ for (const guard of entry.when) {
8731
+ if (!lookup(sourceValues, guard.path)) {
8732
+ facts.noMatch.push({ from: guard.path, to: entry.to });
8733
+ }
8734
+ }
8735
+ }
8729
8736
  const active = entry.when.every((g) => evalGuard(g, sourceValues));
8730
8737
  if (entry.kind === "set") {
8731
8738
  if (active) {
@@ -8768,6 +8775,9 @@ function buildStepPlan(entries, sourceValues, template) {
8768
8775
  continue;
8769
8776
  }
8770
8777
  if (!source) {
8778
+ if (unverifiedReads) {
8779
+ facts.noMatch.push({ from: entry.from, to: entry.to });
8780
+ }
8771
8781
  continue;
8772
8782
  }
8773
8783
  let value = source.value;
@@ -10064,12 +10074,12 @@ async function resolveTemplateId(ref, {
10064
10074
  async function resolveOotbTemplate(ref, {
10065
10075
  executionPlatformVersion,
10066
10076
  requireEngineCompatibility = false,
10067
- templates
10077
+ loadTemplates
10068
10078
  } = {}) {
10069
10079
  const logger = c8ctl2.getLogger();
10070
10080
  requireCachePresent();
10071
10081
  nudgeIfStale(logger);
10072
- const candidates = templates ? templates.filter((t) => t.id === ref.id) : findById(ref.id);
10082
+ const candidates = loadTemplates ? loadTemplates().filter((t) => t.id === ref.id) : findById(ref.id);
10073
10083
  if (candidates.length === 0) {
10074
10084
  throw new Error(
10075
10085
  `Element template '${ref.id}' not found. Run 'c8ctl element-template sync' to refresh the cache, or use 'c8ctl element-template search <query>' to find an id.`
@@ -11501,6 +11511,7 @@ function withNames(template, field, value) {
11501
11511
  function buildReport({
11502
11512
  fromTemplate,
11503
11513
  toTemplate,
11514
+ via = [toTemplate],
11504
11515
  before,
11505
11516
  after,
11506
11517
  facts,
@@ -11620,7 +11631,7 @@ function buildReport({
11620
11631
  template: facts.templateSkipped,
11621
11632
  noMatch: facts.noMatch,
11622
11633
  feel: facts.feelSkipped,
11623
- unchecked: uncheckedFields(fromTemplate, toTemplate)
11634
+ unchecked: uncheckedFields(fromTemplate, via)
11624
11635
  };
11625
11636
  return {
11626
11637
  from: templateRef(fromTemplate),
@@ -11639,10 +11650,12 @@ function buildReport({
11639
11650
  ).length && survivingSets.length === facts.set.length && dropped.length === 0 && skipped.guard.length === 0 && skipped.template.length === 0 && skipped.noMatch.length === 0 && skipped.unchecked.length === 0
11640
11651
  };
11641
11652
  }
11642
- function uncheckedFields(fromTemplate, toTemplate) {
11653
+ function uncheckedFields(fromTemplate, via) {
11643
11654
  return fromTemplate.properties.filter(
11644
- (p) => p.binding && p.type !== "Hidden" && bindingTargetKey(p.binding) === void 0 && !toTemplate.properties.some(
11645
- (t) => t.type !== "Hidden" && sameBinding(t.binding, p.binding)
11655
+ (p) => p.binding && p.type !== "Hidden" && bindingTargetKey(p.binding) === void 0 && via.some(
11656
+ (template) => !template.properties.some(
11657
+ (t) => t.type !== "Hidden" && sameBinding(t.binding, p.binding)
11658
+ )
11646
11659
  )
11647
11660
  ).map((p) => {
11648
11661
  const binding = { ...p.binding };
@@ -12034,10 +12047,10 @@ function readPaths(entry) {
12034
12047
  }
12035
12048
  return paths;
12036
12049
  }
12037
- function findCoverageGap(steps, appliedId, appliedVersion, templates, hop) {
12038
- let shape = templates.find(
12050
+ function findCoverageGap(steps, appliedId, appliedVersion, appliedShapeKnown, templates, hop) {
12051
+ let shape = appliedShapeKnown ? templates.find(
12039
12052
  (t) => t.id === appliedId && (versionOf(t) ?? 0) === appliedVersion
12040
- );
12053
+ ) : void 0;
12041
12054
  for (const step of steps) {
12042
12055
  for (const entry of step.entries) {
12043
12056
  for (const path of readPaths(entry)) {
@@ -12079,6 +12092,7 @@ function reachableHop(recipe, sourceId, drainedVersion) {
12079
12092
  function resolveSteps({
12080
12093
  appliedId,
12081
12094
  appliedVersion,
12095
+ appliedShapeKnown = true,
12082
12096
  target,
12083
12097
  templates,
12084
12098
  recipe
@@ -12106,6 +12120,7 @@ function resolveSteps({
12106
12120
  rungs,
12107
12121
  appliedId,
12108
12122
  appliedVersion,
12123
+ appliedShapeKnown,
12109
12124
  templates,
12110
12125
  hop && { targetId: target.id, entries: hop.entries }
12111
12126
  );
@@ -12273,7 +12288,7 @@ function resolveMapWrites(maps, before, fromTemplate, target) {
12273
12288
  function valuesOf(element) {
12274
12289
  return enumerateElementValues(getExtensionElements(element.businessObject));
12275
12290
  }
12276
- function applyApplication(modeler, catalog, element, application, mapWrites = []) {
12291
+ function applyApplication(modeler, catalog, element, application, mapWrites = [], unverifiedReads = false) {
12277
12292
  const { template, step } = application;
12278
12293
  const applied = readAppliedTemplate(element.businessObject);
12279
12294
  if (applied?.id === template.id && applied.version === (template.version ?? 0)) {
@@ -12285,7 +12300,7 @@ function applyApplication(modeler, catalog, element, application, mapWrites = []
12285
12300
  writes: recipeWrites,
12286
12301
  facts,
12287
12302
  activeProperties
12288
- } = buildStepPlan(step?.entries ?? [], values, clone);
12303
+ } = buildStepPlan(step?.entries ?? [], values, clone, unverifiedReads);
12289
12304
  assertNoAmbiguousWrites([...recipeWrites, ...mapWrites]);
12290
12305
  const stepWrites = [...recipeWrites, ...mapWrites];
12291
12306
  const writes = [
@@ -12372,6 +12387,7 @@ function migrateElement({
12372
12387
  modeler,
12373
12388
  element,
12374
12389
  fromTemplate,
12390
+ sourceKnown = true,
12375
12391
  target,
12376
12392
  templates,
12377
12393
  recipe,
@@ -12387,6 +12403,7 @@ function migrateElement({
12387
12403
  const { steps, refusal } = resolveSteps({
12388
12404
  appliedId: fromTemplate.id,
12389
12405
  appliedVersion: fromTemplate.version ?? 0,
12406
+ appliedShapeKnown: sourceKnown,
12390
12407
  target,
12391
12408
  templates,
12392
12409
  recipe
@@ -12419,7 +12436,8 @@ function migrateElement({
12419
12436
  catalog,
12420
12437
  current,
12421
12438
  application,
12422
- isFinal ? mapPlan.writes : []
12439
+ isFinal ? mapPlan.writes : [],
12440
+ index === 0 && !sourceKnown
12423
12441
  );
12424
12442
  if (result) {
12425
12443
  current = result.element;
@@ -12451,6 +12469,7 @@ function migrateElement({
12451
12469
  const report = buildReport({
12452
12470
  fromTemplate: reportSource,
12453
12471
  toTemplate: target,
12472
+ via: applications.map((a) => a.template),
12454
12473
  before,
12455
12474
  after: allFacts.at(-1)?.after ?? before,
12456
12475
  facts,
@@ -13281,22 +13300,33 @@ function createModeler() {
13281
13300
  moddleExtensions: { zeebe: vendor.ZeebeModdleExtension }
13282
13301
  });
13283
13302
  }
13284
- function templatePool(cachedTemplates, searchDir) {
13303
+ function templatePool(searchDir) {
13285
13304
  const local = /* @__PURE__ */ new Map();
13286
13305
  const localOf = (id) => {
13287
13306
  const templates = local.get(id) ?? findLocalTemplates(searchDir, id);
13288
13307
  local.set(id, templates);
13289
13308
  return templates;
13290
13309
  };
13310
+ const withoutCache = /* @__PURE__ */ new Set();
13311
+ let cached;
13312
+ const cache = () => {
13313
+ cached ??= loadCache() ?? [];
13314
+ return cached;
13315
+ };
13291
13316
  const identity2 = (t) => JSON.stringify([t.id, t.version ?? 0]);
13292
13317
  return {
13293
13318
  localOf,
13319
+ cache,
13320
+ resolvedWithoutCache: (id) => withoutCache.add(id),
13294
13321
  pool(ids) {
13295
- const shadowing = [...new Set(ids)].filter((id) => id !== void 0).flatMap(localOf);
13322
+ const known = [...new Set(ids)].filter((id) => id !== void 0);
13323
+ const shadowing = known.flatMap(localOf);
13324
+ const isLocal = (id) => withoutCache.has(id) || localOf(id).length > 0;
13325
+ if (cached === void 0 && known.every(isLocal)) return shadowing;
13296
13326
  const shadowed = new Set(shadowing.map(identity2));
13297
13327
  return [
13298
13328
  ...shadowing,
13299
- ...cachedTemplates.filter((t) => !shadowed.has(identity2(t)))
13329
+ ...cache().filter((t) => !shadowed.has(identity2(t)))
13300
13330
  ];
13301
13331
  }
13302
13332
  };
@@ -13305,27 +13335,28 @@ async function resolveTarget({
13305
13335
  templateId,
13306
13336
  to,
13307
13337
  executionPlatformVersion,
13308
- cachedTemplates,
13309
13338
  templatePool: templatePool2
13310
13339
  }) {
13311
13340
  const arg = to ?? templateId;
13312
13341
  const ref = parseTemplateRef(arg);
13313
- if (ref?.kind === "id") {
13314
- resolveCatalog(
13315
- migrationTemplates(
13316
- templatePool2.pool([ref.id]).filter((t) => t.id === ref.id)
13317
- )
13318
- );
13319
- }
13342
+ const checkConflicts = (id) => resolveCatalog(
13343
+ migrationTemplates(templatePool2.pool([id]).filter((t) => t.id === id))
13344
+ );
13345
+ if (ref?.kind === "id") checkConflicts(ref.id);
13320
13346
  const target = ref?.kind === "id" ? await resolveTemplateId(ref, {
13321
13347
  localTemplates: templatePool2.localOf(ref.id),
13322
13348
  executionPlatformVersion,
13323
13349
  requireEngineCompatibility: true,
13324
- templates: cachedTemplates
13350
+ loadTemplates: () => {
13351
+ const cached = templatePool2.cache();
13352
+ checkConflicts(ref.id);
13353
+ return cached;
13354
+ }
13325
13355
  }) : await readTemplateFromPathOrUrl(arg);
13326
13356
  if (!isMigrationTemplate(target)) {
13327
13357
  throw new Error("The target template has no id.");
13328
13358
  }
13359
+ if (ref?.kind !== "id") templatePool2.resolvedWithoutCache(target.id);
13329
13360
  return target;
13330
13361
  }
13331
13362
  var selected = (element, id) => ({
@@ -13426,13 +13457,23 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13426
13457
  const selected2 = selectElements(modeler, templateId, elementId);
13427
13458
  const valuesOf2 = (element) => enumerateElementValues(getExtensionElements(element.businessObject));
13428
13459
  redaction.values = selected2.flatMap(({ element }) => valuesOf2(element));
13429
- const cachedTemplates = loadCache() ?? [];
13430
13460
  const pool2 = templatePool(
13431
- cachedTemplates,
13432
13461
  bpmnFilePath ? dirname6(input.source) : process.cwd()
13433
13462
  );
13463
+ const localVersions = pool2.localOf(templateId).map((t) => t.version ?? 0);
13464
+ if (selected2.some(
13465
+ ({ element }) => !localVersions.includes(
13466
+ readAppliedTemplate(element.businessObject)?.version ?? 0
13467
+ )
13468
+ )) {
13469
+ pool2.cache();
13470
+ }
13434
13471
  const lineages = (ids) => migrationTemplates(pool2.pool(ids)).filter((t) => ids.includes(t.id));
13435
- redaction.templates = lineages([templateId, parsed.to]);
13472
+ redaction.templates = lineages([templateId]);
13473
+ const toRef = parseTemplateRef(parsed.to);
13474
+ if (toRef?.kind === "id") {
13475
+ redaction.templates = lineages([templateId, toRef.id]);
13476
+ }
13436
13477
  const recipe = parsed.recipePath ? loadRecipeFile(parsed.recipePath) : void 0;
13437
13478
  if (recipe && !recipe.sources.some((s) => s.sourceTemplateId === templateId)) {
13438
13479
  throw new Error(
@@ -13443,9 +13484,60 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13443
13484
  templateId,
13444
13485
  to: parsed.to,
13445
13486
  executionPlatformVersion: engineVersion,
13446
- cachedTemplates,
13447
13487
  templatePool: pool2
13448
13488
  });
13489
+ redaction.templates = [...lineages([templateId, target.id]), target];
13490
+ const targetRecipe = recipe ?? embeddedRecipe(target);
13491
+ const floors = (targetRecipe?.sources ?? []).flatMap(
13492
+ (s) => s.kind === "change" && s.sourceTemplateId === templateId ? [s.minSourceVersion ?? 0] : []
13493
+ );
13494
+ const localLatest = latestOf(
13495
+ compatibleTemplates(pool2.localOf(templateId), engineVersion),
13496
+ templateId
13497
+ );
13498
+ let localRecipe;
13499
+ try {
13500
+ localRecipe = localLatest && readEmbeddedRecipe(localLatest);
13501
+ } catch {
13502
+ }
13503
+ const reachedLocally = (appliedVersion) => Math.max(
13504
+ appliedVersion,
13505
+ ...(localRecipe?.sources ?? []).flatMap(
13506
+ (s) => s.kind === "upgrade" && s.sourceTemplateId === templateId && s.toVersion > appliedVersion && s.toVersion <= (localLatest?.version ?? 0) ? [s.toVersion] : []
13507
+ )
13508
+ );
13509
+ if (floors.length > 0 && selected2.some(({ element }) => {
13510
+ const reached = reachedLocally(
13511
+ readAppliedTemplate(element.businessObject)?.version ?? 0
13512
+ );
13513
+ return floors.every((floor) => floor > reached);
13514
+ })) {
13515
+ pool2.cache();
13516
+ }
13517
+ const sourceLatest = target.id === templateId ? void 0 : latestOf(
13518
+ compatibleTemplates(pool2.pool([templateId]), engineVersion).filter(
13519
+ (t) => t.id === templateId
13520
+ ),
13521
+ templateId
13522
+ );
13523
+ let sourceRecipe;
13524
+ try {
13525
+ sourceRecipe = sourceLatest && readEmbeddedRecipe(sourceLatest);
13526
+ } catch {
13527
+ }
13528
+ const stepVersions = [targetRecipe, sourceRecipe].flatMap((r) => r?.sources ?? []).flatMap(
13529
+ (s) => s.kind === "upgrade" && s.sourceTemplateId === templateId ? [s.toVersion] : []
13530
+ );
13531
+ const lowestApplied = Math.min(
13532
+ ...selected2.map(
13533
+ ({ element }) => readAppliedTemplate(element.businessObject)?.version ?? 0
13534
+ )
13535
+ );
13536
+ if (stepVersions.some(
13537
+ (v) => v > lowestApplied && !localVersions.includes(v) && !(target.id === templateId && (target.version ?? 0) === v)
13538
+ )) {
13539
+ pool2.cache();
13540
+ }
13449
13541
  const cache = compatibleTemplates(
13450
13542
  pool2.pool([templateId, target.id]),
13451
13543
  engineVersion
@@ -13455,25 +13547,28 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13455
13547
  [target]
13456
13548
  );
13457
13549
  redaction.templates = [...lineages([templateId, target.id]), target];
13458
- if (recipe) validateRecipeOwner(recipe, target);
13459
- const targetRecipe = recipe ?? embeddedRecipe(target);
13550
+ if (targetRecipe) validateRecipeOwner(targetRecipe, target);
13460
13551
  const fromTemplateOf = (applied) => {
13461
13552
  const isApplied = (t) => t.id === applied.id && (t.version ?? 0) === applied.version;
13462
- return templates.find(isApplied) ?? lineages([applied.id]).find(isApplied) ?? {
13463
- id: applied.id,
13464
- version: applied.version,
13465
- properties: []
13553
+ const source = templates.find(isApplied) ?? lineages([applied.id]).find(isApplied);
13554
+ return {
13555
+ source,
13556
+ fromTemplate: source ?? {
13557
+ id: applied.id,
13558
+ version: applied.version,
13559
+ properties: []
13560
+ }
13466
13561
  };
13467
13562
  };
13468
13563
  for (const { element } of selected2) {
13469
13564
  const applied = readAppliedTemplate(element.businessObject);
13470
13565
  if (!applied || applied.id === target.id) continue;
13471
13566
  const catalog = resolveCatalog(templates, [
13472
- fromTemplateOf(applied),
13567
+ fromTemplateOf(applied).fromTemplate,
13473
13568
  target
13474
13569
  ]);
13475
- const sourceLatest = latestOf(catalog, applied.id);
13476
- if (sourceLatest) embeddedRecipe(sourceLatest);
13570
+ const sourceLatest2 = latestOf(catalog, applied.id);
13571
+ if (sourceLatest2) embeddedRecipe(sourceLatest2);
13477
13572
  }
13478
13573
  if (!isEngineCompatible(target, engineVersion)) {
13479
13574
  throw new Error(
@@ -13518,12 +13613,13 @@ async function runMigrateInternal({ parsed, templateId, elementId, bpmnFilePath
13518
13613
  });
13519
13614
  continue;
13520
13615
  }
13521
- const fromTemplate = fromTemplateOf(applied);
13616
+ const { source, fromTemplate } = fromTemplateOf(applied);
13522
13617
  try {
13523
13618
  const result = migrateElement({
13524
13619
  modeler: migrationModeler,
13525
13620
  element,
13526
13621
  fromTemplate,
13622
+ sourceKnown: source !== void 0,
13527
13623
  target,
13528
13624
  templates,
13529
13625
  recipe,
@@ -228,7 +228,17 @@ that moved.
228
228
  templates first (see above), with `isEngineCompatible` as the eligibility
229
229
  rule; the cache is required only on the fallback. Steps, the applied source
230
230
  and redaction read template versions from the cache, with the local versions
231
- of the involved ids shadowing cached ones of the same id and version.
231
+ of the involved ids shadowing cached ones of the same id and version. The
232
+ cache is read only on a local gap: the target falls back to it, an involved
233
+ id has neither a local template nor a `--to` file or URL, or an applied
234
+ version or a recipe step version has no local template. A fully local
235
+ update never reads the cache, so a corrupt cache does not stop it.
236
+ - **Unavailable source.** When the applied version is found nowhere, the
237
+ engine gets a stub with the applied id and version and no properties. Recipe
238
+ reads against the stub are not checked for coverage. Values it cannot read,
239
+ such as `zeebe:calledElement`, are taken from the element and count as
240
+ unchecked unless the target binds them identically, so a write still needs
241
+ `--allow-lossy`.
232
242
  - **Recipe location.** A recipe is carried by the template it migrates *to*, in
233
243
  `metadata.migratesFrom`, so it travels with the template through the
234
244
  marketplace and the cache. `metadata` is the schema's free-form area; it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camunda8/cli",
3
- "version": "4.6.0-alpha.3",
3
+ "version": "4.6.0-alpha.4",
4
4
  "description": "Camunda 8 CLI - minimal-dependency CLI for Camunda 8 operations",
5
5
  "type": "module",
6
6
  "engines": {