@dx-do/client 7.17.0 → 7.17.1

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.
package/dist/index.cjs.js CHANGED
@@ -64900,16 +64900,20 @@ exports.ServiceExport = void 0;
64900
64900
  ServiceExport.parseImport = parseImport;
64901
64901
  /**
64902
64902
  * As {@link parseImport}, plus the envelope's provenance: which tenant the file came from
64903
- * (absent for a bare body or an envelope that did not record it) and when.
64903
+ * (absent for a bare body or an envelope that did not record it) and when, and whether
64904
+ * it is a single-service export (`service export`, or a bare body of one service and no links),
64905
+ * which carries no child links.
64904
64906
  * @throws Error when the input is neither shape.
64905
64907
  */
64906
64908
  function parseImportFile(raw) {
64907
64909
  const body = parseImport(raw);
64908
64910
  const asEnvelope = EnvelopeShape.safeParse(raw);
64909
- if (!asEnvelope.success)
64910
- return { body };
64911
+ if (!asEnvelope.success) {
64912
+ return { body, singleService: body.vertices.length === 1 && !body.edges.length };
64913
+ }
64911
64914
  return {
64912
64915
  body,
64916
+ singleService: asEnvelope.data.kind === 'service',
64913
64917
  ...(asEnvelope.data.sourceTenant ? { sourceTenant: asEnvelope.data.sourceTenant } : {}),
64914
64918
  exportedAt: asEnvelope.data.exportedAt,
64915
64919
  };
@@ -64950,8 +64954,12 @@ exports.ServiceImport = void 0;
64950
64954
  /**
64951
64955
  * Plan saving `file` into a target whose current state for the same names is `target`
64952
64956
  * (missing names = new services).
64957
+ *
64958
+ * @param opts.keepChildren - an existing service the file gives no child links keeps the
64959
+ * target's (a single-service export carries none). Its descendants ride along unchanged,
64960
+ * since a save rejects a link to a service it does not carry.
64953
64961
  */
64954
- function planImport(file, target) {
64962
+ function planImport(file, target, opts = {}) {
64955
64963
  const blockers = [];
64956
64964
  const names = new Set(file.vertices.map((v) => v.attributes.name));
64957
64965
  const dangling = file.edges.filter((e) => !names.has(e.sourceExternalId) || !names.has(e.targetExternalId));
@@ -64974,7 +64982,32 @@ exports.ServiceImport = void 0;
64974
64982
  metricsKeptFromTarget.push(name);
64975
64983
  return { ...v, externalId: name, attributes: { ...v.attributes, root_service: null, metrics: targetMetrics } };
64976
64984
  });
64977
- const body = { vertices, edges: file.edges };
64985
+ const childrenKept = [];
64986
+ const keptEdges = [];
64987
+ if (opts.keepChildren) {
64988
+ for (const name of names) {
64989
+ if (!target.vertices[name] || file.edges.some((e) => e.sourceExternalId === name))
64990
+ continue;
64991
+ const kids = exports.ServiceTransform.childEdges(target.edges, name);
64992
+ if (!kids.length)
64993
+ continue;
64994
+ keptEdges.push(...kids);
64995
+ childrenKept.push({ service: name, children: kids.map((e) => e.targetExternalId).sort() });
64996
+ }
64997
+ }
64998
+ const carried = exports.ServiceBulk.descendantClosure(target, keptEdges.map((e) => e.targetExternalId))
64999
+ .filter((n) => !names.has(n))
65000
+ .sort();
65001
+ const inPayload = new Set([...names, ...carried]);
65002
+ const carriedEdges = target.edges.filter((e) => carried.includes(e.sourceExternalId));
65003
+ const leaving = carriedEdges.filter((e) => !inPayload.has(e.targetExternalId));
65004
+ if (leaving.length) {
65005
+ blockers.push(`kept links lead outside the target's read: ${leaving.map((e) => `${e.sourceExternalId}→${e.targetExternalId}`).join(', ')}`);
65006
+ }
65007
+ const body = {
65008
+ vertices: [...vertices, ...carried.flatMap((n) => target.vertices[n] ?? [])],
65009
+ edges: [...file.edges, ...keptEdges, ...carriedEdges],
65010
+ };
64978
65011
  for (const parent of names) {
64979
65012
  try {
64980
65013
  exports.ServiceTransform.assertWeightsWithinLimit(file.edges, parent);
@@ -64985,7 +65018,7 @@ exports.ServiceImport = void 0;
64985
65018
  }
64986
65019
  const after = {
64987
65020
  vertices: { ...target.vertices, ...Object.fromEntries(vertices.map((v) => [v.attributes.name, v])) },
64988
- edges: [...target.edges.filter((e) => !names.has(e.sourceExternalId)), ...file.edges],
65021
+ edges: [...target.edges.filter((e) => !names.has(e.sourceExternalId)), ...file.edges, ...keptEdges],
64989
65022
  };
64990
65023
  const diff = exports.ServiceBulk.diffGraphs(target, after).filter((d) => names.has(d.service));
64991
65024
  const created = diff.filter((d) => d.status === 'created').map((d) => d.service).sort();
@@ -64999,6 +65032,8 @@ exports.ServiceImport = void 0;
64999
65032
  metricsDropped: metricsDropped.sort(),
65000
65033
  metricsKeptFromTarget: metricsKeptFromTarget.sort(),
65001
65034
  blockers,
65035
+ childrenKept,
65036
+ carried,
65002
65037
  };
65003
65038
  }
65004
65039
  ServiceImport.planImport = planImport;
@@ -89302,11 +89337,29 @@ class ServiceService {
89302
89337
  */
89303
89338
  async planImport(file, opts = {}) {
89304
89339
  const body = opts.prefix ? exports.ServiceImport.renameBody(file, opts.prefix) : file;
89305
- // Read only names the services list knows, so new ones aren't probed one 404 at a time.
89340
+ // The services list lags a create by minutes, so a name it lacks may still exist and
89341
+ // must be checked directly; trusting the list would overwrite that service as new.
89306
89342
  const listed = new Set((await this.getAllServices(100)).map((s) => s.name));
89307
- const names = body.vertices.map((v) => v.attributes.name).filter((n) => listed.has(n));
89343
+ const all = body.vertices.map((v) => v.attributes.name);
89344
+ const { results: unlistedFound } = await dist$1.PromisePool.for(all.filter((n) => !listed.has(n)))
89345
+ .withConcurrency(8)
89346
+ .handleError((e) => {
89347
+ throw e;
89348
+ })
89349
+ .process(async (name) => {
89350
+ try {
89351
+ await this.getService(name, false);
89352
+ return name;
89353
+ }
89354
+ catch (e) {
89355
+ if (e.httpCode !== 404)
89356
+ throw e;
89357
+ return null;
89358
+ }
89359
+ });
89360
+ const names = [...all.filter((n) => listed.has(n)), ...unlistedFound.filter((n) => n !== null)];
89308
89361
  const target = await this.readServiceGraph(names, { allowMissing: true });
89309
- const plan = exports.ServiceImport.planImport(body, target);
89362
+ const plan = exports.ServiceImport.planImport(body, target, { keepChildren: opts.keepChildren ?? false });
89310
89363
  const cap = await this.getServiceLimit();
89311
89364
  const headroom = cap.limit - cap.totalServiceCnt;
89312
89365
  if (plan.created.length > headroom) {