@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.esm.js CHANGED
@@ -64878,16 +64878,20 @@ var ServiceExport;
64878
64878
  ServiceExport.parseImport = parseImport;
64879
64879
  /**
64880
64880
  * As {@link parseImport}, plus the envelope's provenance: which tenant the file came from
64881
- * (absent for a bare body or an envelope that did not record it) and when.
64881
+ * (absent for a bare body or an envelope that did not record it) and when, and whether
64882
+ * it is a single-service export (`service export`, or a bare body of one service and no links),
64883
+ * which carries no child links.
64882
64884
  * @throws Error when the input is neither shape.
64883
64885
  */
64884
64886
  function parseImportFile(raw) {
64885
64887
  const body = parseImport(raw);
64886
64888
  const asEnvelope = EnvelopeShape.safeParse(raw);
64887
- if (!asEnvelope.success)
64888
- return { body };
64889
+ if (!asEnvelope.success) {
64890
+ return { body, singleService: body.vertices.length === 1 && !body.edges.length };
64891
+ }
64889
64892
  return {
64890
64893
  body,
64894
+ singleService: asEnvelope.data.kind === 'service',
64891
64895
  ...(asEnvelope.data.sourceTenant ? { sourceTenant: asEnvelope.data.sourceTenant } : {}),
64892
64896
  exportedAt: asEnvelope.data.exportedAt,
64893
64897
  };
@@ -64928,8 +64932,12 @@ var ServiceImport;
64928
64932
  /**
64929
64933
  * Plan saving `file` into a target whose current state for the same names is `target`
64930
64934
  * (missing names = new services).
64935
+ *
64936
+ * @param opts.keepChildren - an existing service the file gives no child links keeps the
64937
+ * target's (a single-service export carries none). Its descendants ride along unchanged,
64938
+ * since a save rejects a link to a service it does not carry.
64931
64939
  */
64932
- function planImport(file, target) {
64940
+ function planImport(file, target, opts = {}) {
64933
64941
  const blockers = [];
64934
64942
  const names = new Set(file.vertices.map((v) => v.attributes.name));
64935
64943
  const dangling = file.edges.filter((e) => !names.has(e.sourceExternalId) || !names.has(e.targetExternalId));
@@ -64952,7 +64960,32 @@ var ServiceImport;
64952
64960
  metricsKeptFromTarget.push(name);
64953
64961
  return { ...v, externalId: name, attributes: { ...v.attributes, root_service: null, metrics: targetMetrics } };
64954
64962
  });
64955
- const body = { vertices, edges: file.edges };
64963
+ const childrenKept = [];
64964
+ const keptEdges = [];
64965
+ if (opts.keepChildren) {
64966
+ for (const name of names) {
64967
+ if (!target.vertices[name] || file.edges.some((e) => e.sourceExternalId === name))
64968
+ continue;
64969
+ const kids = ServiceTransform.childEdges(target.edges, name);
64970
+ if (!kids.length)
64971
+ continue;
64972
+ keptEdges.push(...kids);
64973
+ childrenKept.push({ service: name, children: kids.map((e) => e.targetExternalId).sort() });
64974
+ }
64975
+ }
64976
+ const carried = ServiceBulk.descendantClosure(target, keptEdges.map((e) => e.targetExternalId))
64977
+ .filter((n) => !names.has(n))
64978
+ .sort();
64979
+ const inPayload = new Set([...names, ...carried]);
64980
+ const carriedEdges = target.edges.filter((e) => carried.includes(e.sourceExternalId));
64981
+ const leaving = carriedEdges.filter((e) => !inPayload.has(e.targetExternalId));
64982
+ if (leaving.length) {
64983
+ blockers.push(`kept links lead outside the target's read: ${leaving.map((e) => `${e.sourceExternalId}→${e.targetExternalId}`).join(', ')}`);
64984
+ }
64985
+ const body = {
64986
+ vertices: [...vertices, ...carried.flatMap((n) => target.vertices[n] ?? [])],
64987
+ edges: [...file.edges, ...keptEdges, ...carriedEdges],
64988
+ };
64956
64989
  for (const parent of names) {
64957
64990
  try {
64958
64991
  ServiceTransform.assertWeightsWithinLimit(file.edges, parent);
@@ -64963,7 +64996,7 @@ var ServiceImport;
64963
64996
  }
64964
64997
  const after = {
64965
64998
  vertices: { ...target.vertices, ...Object.fromEntries(vertices.map((v) => [v.attributes.name, v])) },
64966
- edges: [...target.edges.filter((e) => !names.has(e.sourceExternalId)), ...file.edges],
64999
+ edges: [...target.edges.filter((e) => !names.has(e.sourceExternalId)), ...file.edges, ...keptEdges],
64967
65000
  };
64968
65001
  const diff = ServiceBulk.diffGraphs(target, after).filter((d) => names.has(d.service));
64969
65002
  const created = diff.filter((d) => d.status === 'created').map((d) => d.service).sort();
@@ -64977,6 +65010,8 @@ var ServiceImport;
64977
65010
  metricsDropped: metricsDropped.sort(),
64978
65011
  metricsKeptFromTarget: metricsKeptFromTarget.sort(),
64979
65012
  blockers,
65013
+ childrenKept,
65014
+ carried,
64980
65015
  };
64981
65016
  }
64982
65017
  ServiceImport.planImport = planImport;
@@ -89280,11 +89315,29 @@ class ServiceService {
89280
89315
  */
89281
89316
  async planImport(file, opts = {}) {
89282
89317
  const body = opts.prefix ? ServiceImport.renameBody(file, opts.prefix) : file;
89283
- // Read only names the services list knows, so new ones aren't probed one 404 at a time.
89318
+ // The services list lags a create by minutes, so a name it lacks may still exist and
89319
+ // must be checked directly; trusting the list would overwrite that service as new.
89284
89320
  const listed = new Set((await this.getAllServices(100)).map((s) => s.name));
89285
- const names = body.vertices.map((v) => v.attributes.name).filter((n) => listed.has(n));
89321
+ const all = body.vertices.map((v) => v.attributes.name);
89322
+ const { results: unlistedFound } = await dist$1.PromisePool.for(all.filter((n) => !listed.has(n)))
89323
+ .withConcurrency(8)
89324
+ .handleError((e) => {
89325
+ throw e;
89326
+ })
89327
+ .process(async (name) => {
89328
+ try {
89329
+ await this.getService(name, false);
89330
+ return name;
89331
+ }
89332
+ catch (e) {
89333
+ if (e.httpCode !== 404)
89334
+ throw e;
89335
+ return null;
89336
+ }
89337
+ });
89338
+ const names = [...all.filter((n) => listed.has(n)), ...unlistedFound.filter((n) => n !== null)];
89286
89339
  const target = await this.readServiceGraph(names, { allowMissing: true });
89287
- const plan = ServiceImport.planImport(body, target);
89340
+ const plan = ServiceImport.planImport(body, target, { keepChildren: opts.keepChildren ?? false });
89288
89341
  const cap = await this.getServiceLimit();
89289
89342
  const headroom = cap.limit - cap.totalServiceCnt;
89290
89343
  if (plan.created.length > headroom) {