@dx-do/client 7.1.0 → 7.2.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.
package/dist/index.cjs.js CHANGED
@@ -28541,55 +28541,6 @@ const MetadataMetricQuerySchema = v4.z.looseObject({
28541
28541
  .describe('Optional server hints; currently supports `ForceRange`'),
28542
28542
  });
28543
28543
 
28544
- const MetricRegisterSchema = v4.z.looseObject({
28545
- id: v4.z.string().optional(),
28546
- sourceName: v4.z.string(),
28547
- attributeName: v4.z.string(),
28548
- type: v4.z.number().optional(),
28549
- typeEnum: v4.z.array(v4.z.string()).optional(),
28550
- attributes: v4.z.record(v4.z.string(), v4.z.unknown()).optional(),
28551
- firstSeen: v4.z.number().optional(),
28552
- lastSeen: v4.z.number().optional(),
28553
- });
28554
- const MetricRegisterRequestSchema = v4.z.looseObject({
28555
- sync: v4.z.boolean().optional(),
28556
- metrics: v4.z.array(MetricRegisterSchema),
28557
- });
28558
- const MetricRegisterSourceSchema = v4.z.looseObject({
28559
- sourceId: v4.z.string().optional(),
28560
- name: v4.z.string().optional(),
28561
- });
28562
- const MetricRegisterResponseSchema = v4.z.looseObject({
28563
- metrics: v4.z.array(MetricRegisterSchema).optional(),
28564
- sources: v4.z.array(MetricRegisterSourceSchema).optional(),
28565
- });
28566
-
28567
- const MetricAttributeSchema = v4.z.looseObject({
28568
- id: v4.z.string().optional(),
28569
- sourceName: v4.z.string().optional(),
28570
- type: v4.z
28571
- .number()
28572
- .describe('Bitwise OR of one or more `typeEnum` values (see METRIC_TYPE_ENUM in ./type-enum.ts). Decode with `decodeMetricTypeBits(value)` for human-readable names. e.g. 268436481 = MONITOR_INT_DURATION + TYPE_INFO_FRONTEND.'),
28573
- attributeName: v4.z.string().optional(),
28574
- attributes: v4.z.record(v4.z.string(), v4.z.unknown()).optional(),
28575
- firstSeen: v4.z.number().optional(),
28576
- lastSeen: v4.z.number().optional(),
28577
- live: v4.z.boolean().optional(),
28578
- });
28579
- const MetricFolderSchema = v4.z.looseObject({
28580
- sourceId: v4.z.string().optional(),
28581
- sourceName: v4.z.string().optional(),
28582
- folderName: v4.z.string().optional(),
28583
- firstSeen: v4.z.number().optional(),
28584
- lastSeen: v4.z.number().optional(),
28585
- live: v4.z.boolean().optional(),
28586
- });
28587
- const MetadataMetricQueryResponseV2Schema = v4.z.looseObject({
28588
- metrics: v4.z.array(MetricAttributeSchema).optional(),
28589
- folders: v4.z.array(MetricFolderSchema).optional(),
28590
- analytics: v4.z.record(v4.z.string(), v4.z.unknown()).optional(),
28591
- });
28592
-
28593
28544
  /**
28594
28545
  * Canonical `typeEnum` → bit-value mapping for the metric `type` integer
28595
28546
  * stored on every Metrics-Metadata `MetricAttribute` descriptor.
@@ -28728,6 +28679,120 @@ function decodeMetricTypeBits(n) {
28728
28679
  return { matched, residual: working >>> 0 };
28729
28680
  }
28730
28681
 
28682
+ /**
28683
+ * Reserved `attributes` key for tag-differentiated metrics: its value is the
28684
+ * array of attribute names that form the metric's primary key. See
28685
+ * `docs/data-store-doc/metadata-index.html` §3.1.3.
28686
+ */
28687
+ const TAGS_ATTRIBUTE_KEY = '@tags';
28688
+ const MetricRegisterSchema = v4.z.looseObject({
28689
+ id: v4.z.string().optional(),
28690
+ sourceName: v4.z.string(),
28691
+ attributeName: v4.z.string(),
28692
+ type: v4.z.number().optional(),
28693
+ typeEnum: v4.z
28694
+ .array(v4.z.string())
28695
+ .optional()
28696
+ .describe('Metric type as typeEnum names (see METRIC_TYPE_ENUM). Including TYPE_TAGS makes the server evaluate attributes["@tags"] for metric uniqueness.'),
28697
+ attributes: v4.z
28698
+ .record(v4.z.string(), v4.z.unknown())
28699
+ .optional()
28700
+ .describe('Metadata attributes; values are usually strings. The reserved key "@tags" takes an array of attribute names that form the metric primary key (tag-differentiated metrics) — requires the TYPE_TAGS type flag, and each named attribute must be present with a non-empty string value.'),
28701
+ firstSeen: v4.z.number().optional(),
28702
+ lastSeen: v4.z.number().optional(),
28703
+ });
28704
+ /** True when the metric's type (numeric or enum form) carries the TYPE_TAGS flag. */
28705
+ function hasTypeTagsFlag(metric) {
28706
+ if (metric.typeEnum?.includes('TYPE_TAGS')) {
28707
+ return true;
28708
+ }
28709
+ return (metric.type !== undefined &&
28710
+ (metric.type & METRIC_TYPE_ENUM.TYPE_TAGS) !== 0);
28711
+ }
28712
+ /**
28713
+ * Request-side variant of {@link MetricRegisterSchema} enforcing the server's
28714
+ * tag-registration restrictions (§3.1.3). Kept off the response path — server
28715
+ * responses are validated defensively and must stay tolerant.
28716
+ */
28717
+ const MetricRegisterInputSchema = MetricRegisterSchema.superRefine((metric, ctx) => {
28718
+ const tags = metric.attributes?.[TAGS_ATTRIBUTE_KEY];
28719
+ if (tags === undefined) {
28720
+ if (hasTypeTagsFlag(metric)) {
28721
+ ctx.addIssue({
28722
+ code: 'custom',
28723
+ path: ['attributes', TAGS_ATTRIBUTE_KEY],
28724
+ message: 'TYPE_TAGS requires a non-empty attributes["@tags"] array naming the tag attributes',
28725
+ });
28726
+ }
28727
+ return;
28728
+ }
28729
+ if (!Array.isArray(tags) ||
28730
+ tags.length === 0 ||
28731
+ tags.some((t) => typeof t !== 'string' || t.length === 0)) {
28732
+ ctx.addIssue({
28733
+ code: 'custom',
28734
+ path: ['attributes', TAGS_ATTRIBUTE_KEY],
28735
+ message: 'attributes["@tags"] must be a non-empty array of non-empty tag attribute names',
28736
+ });
28737
+ return;
28738
+ }
28739
+ for (const tag of tags) {
28740
+ const value = metric.attributes?.[tag];
28741
+ if (typeof value !== 'string' || value.length === 0) {
28742
+ ctx.addIssue({
28743
+ code: 'custom',
28744
+ path: ['attributes', tag],
28745
+ message: `tag '${tag}' listed in @tags needs a non-empty string value in attributes`,
28746
+ });
28747
+ }
28748
+ }
28749
+ if (!hasTypeTagsFlag(metric)) {
28750
+ ctx.addIssue({
28751
+ code: 'custom',
28752
+ path: ['typeEnum'],
28753
+ message: '@tags requires a metric type carrying TYPE_TAGS; specify type or typeEnum',
28754
+ });
28755
+ }
28756
+ });
28757
+ const MetricRegisterRequestSchema = v4.z.looseObject({
28758
+ sync: v4.z.boolean().optional(),
28759
+ metrics: v4.z.array(MetricRegisterInputSchema),
28760
+ });
28761
+ const MetricRegisterSourceSchema = v4.z.looseObject({
28762
+ sourceId: v4.z.string().optional(),
28763
+ name: v4.z.string().optional(),
28764
+ });
28765
+ const MetricRegisterResponseSchema = v4.z.looseObject({
28766
+ metrics: v4.z.array(MetricRegisterSchema).optional(),
28767
+ sources: v4.z.array(MetricRegisterSourceSchema).optional(),
28768
+ });
28769
+
28770
+ const MetricAttributeSchema = v4.z.looseObject({
28771
+ id: v4.z.string().optional(),
28772
+ sourceName: v4.z.string().optional(),
28773
+ type: v4.z
28774
+ .number()
28775
+ .describe('Bitwise OR of one or more `typeEnum` values (see METRIC_TYPE_ENUM in ./type-enum.ts). Decode with `decodeMetricTypeBits(value)` for human-readable names. e.g. 268436481 = MONITOR_INT_DURATION + TYPE_INFO_FRONTEND.'),
28776
+ attributeName: v4.z.string().optional(),
28777
+ attributes: v4.z.record(v4.z.string(), v4.z.unknown()).optional(),
28778
+ firstSeen: v4.z.number().optional(),
28779
+ lastSeen: v4.z.number().optional(),
28780
+ live: v4.z.boolean().optional(),
28781
+ });
28782
+ const MetricFolderSchema = v4.z.looseObject({
28783
+ sourceId: v4.z.string().optional(),
28784
+ sourceName: v4.z.string().optional(),
28785
+ folderName: v4.z.string().optional(),
28786
+ firstSeen: v4.z.number().optional(),
28787
+ lastSeen: v4.z.number().optional(),
28788
+ live: v4.z.boolean().optional(),
28789
+ });
28790
+ const MetadataMetricQueryResponseV2Schema = v4.z.looseObject({
28791
+ metrics: v4.z.array(MetricAttributeSchema).optional(),
28792
+ folders: v4.z.array(MetricFolderSchema).optional(),
28793
+ analytics: v4.z.record(v4.z.string(), v4.z.unknown()).optional(),
28794
+ });
28795
+
28731
28796
  /**
28732
28797
  * Wire format for `POST /nass/metricValue/store`.
28733
28798
  *
@@ -79550,6 +79615,29 @@ class DataStoreFeaturesService {
79550
79615
  }
79551
79616
  }
79552
79617
 
79618
+ /**
79619
+ * A metric registered with `attributes["@tags"]` must carry the TYPE_TAGS
79620
+ * flag — without it the server treats "@tags" as an ordinary attribute and
79621
+ * registers a metric with the wrong identity. Added here (not in the caller)
79622
+ * so every registration path gets it; idempotent when the flag is already set.
79623
+ * When the metric has no type at all the flag is not invented — schema
79624
+ * validation rejects that case with an explicit message.
79625
+ */
79626
+ function ensureTypeTagsFlag(metric) {
79627
+ if (metric.attributes?.[TAGS_ATTRIBUTE_KEY] === undefined) {
79628
+ return metric;
79629
+ }
79630
+ const normalized = { ...metric };
79631
+ if (normalized.typeEnum !== undefined &&
79632
+ !normalized.typeEnum.includes('TYPE_TAGS')) {
79633
+ normalized.typeEnum = [...normalized.typeEnum, 'TYPE_TAGS'];
79634
+ }
79635
+ if (normalized.type !== undefined &&
79636
+ (normalized.type & METRIC_TYPE_ENUM.TYPE_TAGS) === 0) {
79637
+ normalized.type = normalized.type | METRIC_TYPE_ENUM.TYPE_TAGS;
79638
+ }
79639
+ return normalized;
79640
+ }
79553
79641
  /**
79554
79642
  * Service for issuing metric metadata queries against the DX SaaS DataStore
79555
79643
  * API (`/metadata/queryMetric`).
@@ -79590,14 +79678,18 @@ class DataStoreMetricsMetadataService {
79590
79678
  * Registers one or more metrics via `POST /metadata/registerMetric`.
79591
79679
  *
79592
79680
  * @remarks The request is validated against {@link MetricRegisterRequestSchema}.
79593
- * If the response fails schema validation, a warning is logged but the raw
79594
- * API response is still returned.
79681
+ * Metrics carrying an `attributes["@tags"]` array get the TYPE_TAGS flag
79682
+ * added to their type automatically (idempotent). If the response fails
79683
+ * schema validation, a warning is logged but the raw API response is
79684
+ * still returned.
79595
79685
  *
79596
- * @throws ZodError if the request fails schema validation.
79686
+ * @throws ZodError if the request fails schema validation — including the
79687
+ * tag-registration restrictions ("@tags" non-empty, every listed tag
79688
+ * present with a non-empty string value, TYPE_TAGS never set without tags).
79597
79689
  */
79598
79690
  async registerMetrics(metrics, sync) {
79599
79691
  const body = {
79600
- metrics,
79692
+ metrics: metrics.map((m) => ensureTypeTagsFlag(m)),
79601
79693
  ...(sync !== undefined ? { sync } : {}),
79602
79694
  };
79603
79695
  MetricRegisterRequestSchema.parse(body);
@@ -80916,6 +81008,7 @@ exports.MetricAttributeSchema = MetricAttributeSchema;
80916
81008
  exports.MetricBatchService = MetricBatchService;
80917
81009
  exports.MetricFolderSchema = MetricFolderSchema;
80918
81010
  exports.MetricGroupingService = MetricGroupingService;
81011
+ exports.MetricRegisterInputSchema = MetricRegisterInputSchema;
80919
81012
  exports.MetricRegisterRequestSchema = MetricRegisterRequestSchema;
80920
81013
  exports.MetricRegisterResponseSchema = MetricRegisterResponseSchema;
80921
81014
  exports.MetricRegisterSchema = MetricRegisterSchema;
@@ -81028,6 +81121,7 @@ exports.SourceNameRegExSpecifierSchema = SourceNameRegExSpecifierSchema;
81028
81121
  exports.SourceNameSpecifierSchema = SourceNameSpecifierSchema;
81029
81122
  exports.StatusPageComponentSchema = StatusPageComponentSchema;
81030
81123
  exports.StatusPageComponentsSchema = StatusPageComponentsSchema;
81124
+ exports.TAGS_ATTRIBUTE_KEY = TAGS_ATTRIBUTE_KEY;
81031
81125
  exports.TASService = TASService;
81032
81126
  exports.TC_METRIC_CAP = TC_METRIC_CAP;
81033
81127
  exports.TasAddFlowsFilterSchema = TasAddFlowsFilterSchema;
@@ -81220,6 +81314,7 @@ exports.getUserTokenSub = getUserTokenSub;
81220
81314
  exports.getUserTokenTid = getUserTokenTid;
81221
81315
  exports.getVertexAttributeValue = getVertexAttributeValue;
81222
81316
  exports.getVertexAttributeValueOrNull = getVertexAttributeValueOrNull;
81317
+ exports.hasTypeTagsFlag = hasTypeTagsFlag;
81223
81318
  exports.hasVertexAttribute = hasVertexAttribute;
81224
81319
  exports.incrementVariant = incrementVariant;
81225
81320
  exports.inventorySearchRequestBodyExample = inventorySearchRequestBodyExample;