@jackchuka/gql-ingest 4.1.0 → 4.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.js CHANGED
@@ -14550,6 +14550,11 @@ var DataMapper = class {
14550
14550
  variables[graphqlVar] = this.mapNestedObject(row, mappingValue, variableTypes, outputStore);
14551
14551
  }
14552
14552
  }
14553
+ if (outputStore) {
14554
+ for (const [key, value] of Object.entries(variables)) {
14555
+ variables[key] = this.resolveRefsInData(value, row, outputStore);
14556
+ }
14557
+ }
14553
14558
  return variables;
14554
14559
  }
14555
14560
  getValueByPath(obj, dataPath) {
@@ -14595,12 +14600,44 @@ var DataMapper = class {
14595
14600
  }
14596
14601
  return mappingObj;
14597
14602
  }
14603
+ /**
14604
+ * Recursively walk a resolved value and resolve any $ref objects found in data.
14605
+ * Unlike mapping-level $ref (where key is a JSONPath into the row), data-level
14606
+ * $ref uses key as a literal lookup value unless it starts with "$.".
14607
+ */
14608
+ resolveRefsInData(value, row, outputStore) {
14609
+ if (Array.isArray(value)) {
14610
+ let changed = false;
14611
+ const mapped = value.map((item) => {
14612
+ const resolved = this.resolveRefsInData(item, row, outputStore);
14613
+ if (resolved !== item) changed = true;
14614
+ return resolved;
14615
+ });
14616
+ return changed ? mapped : value;
14617
+ }
14618
+ if (typeof value === "object" && value !== null) {
14619
+ if (this.isRefMapping(value)) {
14620
+ const keyStr = value.key.startsWith("$.") ? String(this.getValueByPath(row, this.stripJsonPathPrefix(value.key)) ?? value.key) : value.key;
14621
+ return this.lookupRef(outputStore, value.$ref, keyStr, value.field);
14622
+ }
14623
+ let changed = false;
14624
+ const result = {};
14625
+ for (const [k, v] of Object.entries(value)) {
14626
+ const resolved = this.resolveRefsInData(v, row, outputStore);
14627
+ if (resolved !== v) changed = true;
14628
+ result[k] = resolved;
14629
+ }
14630
+ return changed ? result : value;
14631
+ }
14632
+ return value;
14633
+ }
14598
14634
  stripJsonPathPrefix(jsonPath) {
14599
14635
  return jsonPath.startsWith("$.") ? jsonPath.substring(2) : jsonPath;
14600
14636
  }
14601
14637
  isRefMapping(value) {
14602
14638
  return typeof value === "object" && value !== null && !Array.isArray(value) && "$ref" in value && "key" in value && "field" in value;
14603
14639
  }
14640
+ /** Resolve a mapping-level $ref — throws on any failure so the row is skipped. */
14604
14641
  resolveRef(row, ref, outputStore) {
14605
14642
  if (!outputStore) {
14606
14643
  throw new RefResolutionError(`$ref to "${ref.$ref}" found but no output store is available`);
@@ -14611,20 +14648,33 @@ var DataMapper = class {
14611
14648
  throw new RefResolutionError(`$ref lookup key "${ref.key}" not found in current row`);
14612
14649
  }
14613
14650
  const keyStr = String(lookupKeyValue);
14614
- const entityStore = outputStore.get(ref.$ref);
14651
+ const value = this.lookupRef(outputStore, ref.$ref, keyStr, ref.field);
14652
+ if (value === void 0) {
14653
+ throw new RefResolutionError(
14654
+ `$ref resolution failed for "${ref.$ref}[${keyStr}].${ref.field}"`
14655
+ );
14656
+ }
14657
+ return value;
14658
+ }
14659
+ /**
14660
+ * Core ref lookup: entityName -> key -> field.
14661
+ * Returns undefined with a warning on miss (caller decides whether to throw).
14662
+ */
14663
+ lookupRef(outputStore, entityName, keyStr, field) {
14664
+ const entityStore = outputStore.get(entityName);
14615
14665
  if (!entityStore) {
14616
- throw new RefResolutionError(`$ref entity "${ref.$ref}" not found in output store`);
14666
+ this.logger.warn(`$ref entity "${entityName}" not found in output store`);
14667
+ return void 0;
14617
14668
  }
14618
14669
  const captured = entityStore.get(keyStr);
14619
14670
  if (!captured) {
14620
- throw new RefResolutionError(
14621
- `$ref key "${keyStr}" not found in entity "${ref.$ref}" output store`
14622
- );
14671
+ this.logger.warn(`$ref key "${keyStr}" not found in entity "${entityName}" output store`);
14672
+ return void 0;
14623
14673
  }
14624
- const value = captured[ref.field];
14674
+ const value = captured[field];
14625
14675
  if (value === void 0) {
14626
- throw new RefResolutionError(
14627
- `$ref field "${ref.field}" not found in captured output for "${ref.$ref}[${keyStr}]"`
14676
+ this.logger.warn(
14677
+ `$ref field "${field}" not found in captured output for "${entityName}[${keyStr}]"`
14628
14678
  );
14629
14679
  }
14630
14680
  return value;