@memberjunction/record-set-processor 6.1.2 → 6.2.0-edge.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.
Files changed (34) hide show
  1. package/dist/RecordProcessExecutor.d.ts +3 -1
  2. package/dist/RecordProcessExecutor.d.ts.map +1 -1
  3. package/dist/RecordProcessExecutor.js +86 -7
  4. package/dist/RecordProcessExecutor.js.map +1 -1
  5. package/dist/RecordSetProcessor.d.ts.map +1 -1
  6. package/dist/RecordSetProcessor.js +134 -2
  7. package/dist/RecordSetProcessor.js.map +1 -1
  8. package/dist/index.d.ts +1 -0
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +1 -0
  11. package/dist/index.js.map +1 -1
  12. package/dist/processors/ActionRecordProcessor.d.ts +2 -2
  13. package/dist/processors/ActionRecordProcessor.d.ts.map +1 -1
  14. package/dist/processors/ActionRecordProcessor.js.map +1 -1
  15. package/dist/processors/AgentRecordProcessor.d.ts +2 -2
  16. package/dist/processors/AgentRecordProcessor.d.ts.map +1 -1
  17. package/dist/processors/AgentRecordProcessor.js.map +1 -1
  18. package/dist/processors/InferProcessor.d.ts +84 -7
  19. package/dist/processors/InferProcessor.d.ts.map +1 -1
  20. package/dist/processors/InferProcessor.js +652 -14
  21. package/dist/processors/InferProcessor.js.map +1 -1
  22. package/dist/processors/WriteBackProcessor.d.ts +16 -2
  23. package/dist/processors/WriteBackProcessor.d.ts.map +1 -1
  24. package/dist/processors/WriteBackProcessor.js +85 -1
  25. package/dist/processors/WriteBackProcessor.js.map +1 -1
  26. package/dist/watermark/WatermarkService.d.ts +81 -0
  27. package/dist/watermark/WatermarkService.d.ts.map +1 -0
  28. package/dist/watermark/WatermarkService.js +224 -0
  29. package/dist/watermark/WatermarkService.js.map +1 -0
  30. package/dist/writeBack.d.ts +82 -19
  31. package/dist/writeBack.d.ts.map +1 -1
  32. package/dist/writeBack.js +372 -35
  33. package/dist/writeBack.js.map +1 -1
  34. package/package.json +16 -13
@@ -6,43 +6,102 @@
6
6
  */
7
7
  import { IMetadataProvider, UserInfo } from '@memberjunction/core';
8
8
  import { RecordRef } from '@memberjunction/record-set-processor-base';
9
+ /** Provenance information about the executing process run, passed down to write-back and mapped via `$run.*`. */
10
+ export interface RunProvenance {
11
+ ProcessRunID?: string;
12
+ RecordProcessID?: string;
13
+ PromptID?: string;
14
+ PromptVersionHash?: string;
15
+ AIPromptRunID?: string;
16
+ ExecutedAt?: string;
17
+ FeatureValueCacheID?: string;
18
+ }
19
+ /** Foreign-key lookup configuration for resolving a name or match field to a foreign-key ID. */
20
+ export interface FieldLookupConfig {
21
+ /** Target related entity name or ID to look up against. Derived from field metadata if omitted. */
22
+ relatedEntity?: string;
23
+ /** Column on the related entity to match against (default 'Name'). */
24
+ matchField?: string;
25
+ /** Policy when lookup yields no matching record: 'null' (write null), 'fail' (throw error), 'create' (create new record and use its ID). Default 'null'. Note: 'create' creates a new record setting only matchField, intended for lookup/type tables where other columns are nullable or have defaults. */
26
+ onLookupMiss?: 'null' | 'fail' | 'create';
27
+ }
28
+ /** Child record mapping configuration, supporting optional array fan-out. */
29
+ export interface ChildRecordMapping {
30
+ /** Target child entity name. */
31
+ entity: string;
32
+ /** FK field on the child set to the processed record's primary key. */
33
+ parentField: string;
34
+ /** Map of `ChildFieldName -> resultRef`. */
35
+ map: Record<string, string>;
36
+ /** Optional ref resolving to an array for fan-out (one child created per array element). */
37
+ fanOutRef?: string;
38
+ }
39
+ /** Tag output mapping configuration for taxonomy linking. */
40
+ export interface TagOutputMapping {
41
+ /** Result path resolving to a tag string or string array (e.g. "$.tags"). */
42
+ ref: string;
43
+ /** Root tag this feature's values must live under. Required. */
44
+ rootTagId: string;
45
+ /** How deep below the root a value may be placed/created. 1 = direct children only. */
46
+ maxDepth?: number;
47
+ /** Maps to TagEngine's TaxonomyMode. Default 'constrained'. */
48
+ growth?: 'constrained' | 'auto-grow' | 'hybrid';
49
+ /** Minimum semantic-match score to accept an existing tag. */
50
+ matchThreshold?: number;
51
+ /** Entity the TaggedItem points at. Default: the processed entity. */
52
+ taggedEntityName?: string;
53
+ }
9
54
  /** Declarative description of how a work's structured output is written back. */
10
55
  export interface OutputMappingConfig {
11
56
  /** Map of `EntityFieldName -> resultRef` (e.g. `{ "Satisfaction": "$.satisfaction" }`) applied to the processed record. */
12
57
  fields?: Record<string, string>;
13
- /** Optional child record to create from the result. */
14
- childRecord?: {
15
- /** Target child entity name. */
16
- entity: string;
17
- /** FK field on the child set to the processed record's primary key. */
18
- parentField: string;
19
- /** Map of `ChildFieldName -> resultRef`. */
20
- map: Record<string, string>;
21
- };
58
+ /** Optional foreign-key lookup configurations per target field name. */
59
+ fieldLookups?: Record<string, FieldLookupConfig>;
60
+ /** Optional single child record to create from the result (kept for backward compatibility). */
61
+ childRecord?: ChildRecordMapping;
62
+ /** Optional child records to create from the result, supporting fan-out over arrays. */
63
+ childRecords?: ChildRecordMapping[];
64
+ /** Optional tags to link or create via the MJ Tagging system. */
65
+ tags?: TagOutputMapping[];
66
+ }
67
+ /** Preview outcome for a single resolved tag. */
68
+ export interface TagWriteBackPreview {
69
+ tagText: string;
70
+ resolvedTagID?: string;
71
+ resolvedTagName?: string;
72
+ matched: boolean;
73
+ created: boolean;
74
+ rootTagID: string;
75
+ depth?: number;
76
+ error?: string;
22
77
  }
23
78
  /** Outcome of {@link applyOutputMapping}. */
24
79
  export interface WriteBackResult {
25
80
  /** True if the processed record's fields were actually updated (always false on a dry-run). */
26
81
  updatedRecord: boolean;
27
- /** ID of the created child record, when a child mapping was applied (absent on a dry-run). */
82
+ /** ID of the created child record, when a single child mapping was applied (absent on a dry-run). */
28
83
  createdChildID?: string;
84
+ /** IDs of created child records when childRecords (or fan-out) was applied (absent on a dry-run). */
85
+ createdChildIDs?: string[];
86
+ /** IDs of created tagged item records (absent on a dry-run). */
87
+ createdTaggedItemIDs?: string[];
29
88
  /** True when this was a dry-run: values were computed (and field names validated) but NOTHING was saved. */
30
89
  dryRun?: boolean;
31
90
  /** On a dry-run, the resolved field values that WOULD be written to the processed record — the write-back preview. */
32
91
  previewFields?: Record<string, unknown>;
33
- /** On a dry-run with a child mapping, the resolved child values that WOULD be created. */
92
+ /** On a dry-run with a single child mapping, the resolved child values that WOULD be created. */
34
93
  previewChild?: Record<string, unknown>;
94
+ /** On a dry-run with childRecords (or fan-out), the array of resolved child records that WOULD be created. */
95
+ previewChildren?: Array<Record<string, unknown>>;
96
+ /** On a dry-run with tag mappings, the resolved tag previews. */
97
+ previewTags?: TagWriteBackPreview[];
35
98
  }
36
99
  /**
37
- * Applies an {@link OutputMappingConfig} against a work result. Single-primary-key entities only
38
- * (composite keys throw a clear error). Field/child values are resolved from the result via the
39
- * shared resolver, so `"$.path"` reads `result.path`.
100
+ * Applies an {@link OutputMappingConfig} against a work result.
101
+ * Supports updating fields (both single-key and composite-key entities), creating child records
102
+ * (with array fan-out), and linking/creating tags via TagEngine.
40
103
  *
41
- * **Dry-run** (`dryRun: true`): the mapped values are still resolved and the target entity/field
42
- * metadata is still validated, but NO entity is saved and NO child is created — the would-be values
43
- * are returned in `previewFields` / `previewChild` so a dry-run preview can show exactly what an apply
44
- * would write. This is what lets a dry-run of any wrapped work type (Action / Agent / Infer / ML Model)
45
- * compute its effect without mutating data, mirroring the `FieldRulesProcessor` dry-run preview.
104
+ * Values resolve from `$` (result), `record` (parent row) and `$run` (provenance).
46
105
  */
47
106
  export declare function applyOutputMapping(opts: {
48
107
  outputMapping: OutputMappingConfig;
@@ -52,5 +111,9 @@ export declare function applyOutputMapping(opts: {
52
111
  provider?: IMetadataProvider;
53
112
  /** When true, compute + validate the mapping but do NOT save anything (returns a preview instead). */
54
113
  dryRun?: boolean;
114
+ /** Optional run provenance information mapped via `$run.*`. */
115
+ run?: RunProvenance;
116
+ /** Optional memoization cache mapping `${relatedEntityName}|${matchField}|${matchValue}` -> resolved PK. Caches positive hits only to prevent downgrading onLookupMiss policies. */
117
+ lookupCache?: Map<string, string | number>;
55
118
  }): Promise<WriteBackResult>;
56
119
  //# sourceMappingURL=writeBack.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"writeBack.d.ts","sourceRoot":"","sources":["../src/writeBack.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAA4B,iBAAiB,EAAY,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEvG,OAAO,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AAEtE,iFAAiF;AACjF,MAAM,WAAW,mBAAmB;IAChC,2HAA2H;IAC3H,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,uDAAuD;IACvD,WAAW,CAAC,EAAE;QACV,gCAAgC;QAChC,MAAM,EAAE,MAAM,CAAC;QACf,uEAAuE;QACvE,WAAW,EAAE,MAAM,CAAC;QACpB,4CAA4C;QAC5C,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC/B,CAAC;CACL;AAED,6CAA6C;AAC7C,MAAM,WAAW,eAAe;IAC5B,+FAA+F;IAC/F,aAAa,EAAE,OAAO,CAAC;IACvB,8FAA8F;IAC9F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4GAA4G;IAC5G,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,sHAAsH;IACtH,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,0FAA0F;IAC1F,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,EAAE;IAC3C,aAAa,EAAE,mBAAmB,CAAC;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,SAAS,CAAC;IAClB,WAAW,EAAE,QAAQ,CAAC;IACtB,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,sGAAsG;IACtG,MAAM,CAAC,EAA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AC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,iGAAiG;IACjG,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,8GAA8G;IAC9G,eAAe,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,iEAAiE;IACjE,WAAW,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACvC;AAkCD;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,IAAI,EAAE;IAC3C,aAAa,EAAE,mBAAmB,CAAC;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,SAAS,CAAC;IAClB,WAAW,EAAE,QAAQ,CAAC;IACtB,QAAQ,CAAC,EAAE,iBAAiB,CAAC;IAC7B,sGAAsG;IACtG,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,+DAA+D;IAC/D,GAAG,CAAC,EAAE,aAAa,CAAC;IACpB,oLAAoL;IACpL,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;CAC9C,GAAG,OAAO,CAAC,eAAe,CAAC,CAia3B"}
package/dist/writeBack.js CHANGED
@@ -4,23 +4,61 @@
4
4
  * record. Reads from the result use the generic value-mapping resolver (`$` = the result root).
5
5
  * @module @memberjunction/record-set-processor
6
6
  */
7
- import { CompositeKey, Metadata } from '@memberjunction/core';
8
- import { resolveMappingRef } from '@memberjunction/global';
7
+ import { CompositeKey, LogStatus, Metadata, RunView, LogError } from '@memberjunction/core';
8
+ import { EscapeSQLString, UUIDsEqual, resolveMappingRef } from '@memberjunction/global';
9
+ import { TagEngine } from '@memberjunction/tag-engine';
9
10
  /**
10
- * Applies an {@link OutputMappingConfig} against a work result. Single-primary-key entities only
11
- * (composite keys throw a clear error). Field/child values are resolved from the result via the
12
- * shared resolver, so `"$.path"` reads `result.path`.
11
+ * Computes the depth of a tag relative to a root tag.
12
+ * Returns 0 if tagID === rootTagID, 1 for direct children, 2 for grandchildren, etc.
13
+ * Returns -1 if the tag is not a descendant of rootTagID.
14
+ */
15
+ function computeTagDepth(tagID, rootTagID, tagEngine) {
16
+ if (UUIDsEqual(tagID, rootTagID)) {
17
+ return 0;
18
+ }
19
+ let currentID = tagID;
20
+ let depth = 0;
21
+ while (currentID) {
22
+ const currentTag = tagEngine.GetTagByID(currentID);
23
+ if (!currentTag) {
24
+ return -1;
25
+ }
26
+ if (UUIDsEqual(currentTag.ParentID ?? '', rootTagID)) {
27
+ return depth + 1;
28
+ }
29
+ currentID = currentTag.ParentID;
30
+ depth++;
31
+ if (depth > 50) {
32
+ return -1;
33
+ }
34
+ }
35
+ return -1;
36
+ }
37
+ /**
38
+ * Applies an {@link OutputMappingConfig} against a work result.
39
+ * Supports updating fields (both single-key and composite-key entities), creating child records
40
+ * (with array fan-out), and linking/creating tags via TagEngine.
13
41
  *
14
- * **Dry-run** (`dryRun: true`): the mapped values are still resolved and the target entity/field
15
- * metadata is still validated, but NO entity is saved and NO child is created — the would-be values
16
- * are returned in `previewFields` / `previewChild` so a dry-run preview can show exactly what an apply
17
- * would write. This is what lets a dry-run of any wrapped work type (Action / Agent / Infer / ML Model)
18
- * compute its effect without mutating data, mirroring the `FieldRulesProcessor` dry-run preview.
42
+ * Values resolve from `$` (result), `record` (parent row) and `$run` (provenance).
19
43
  */
20
44
  export async function applyOutputMapping(opts) {
21
- const { outputMapping, result, record, contextUser, dryRun } = opts;
45
+ const { outputMapping, result, record, contextUser, dryRun, run } = opts;
22
46
  const provider = opts.provider ?? Metadata.Provider;
23
- const sources = { $: result, record: record.Record ?? {} };
47
+ const lookupCache = opts.lookupCache ?? new Map();
48
+ let payload = result;
49
+ if (typeof payload === 'string') {
50
+ try {
51
+ payload = JSON.parse(payload);
52
+ }
53
+ catch {
54
+ // leave as string if not JSON
55
+ }
56
+ }
57
+ const sources = {
58
+ $: payload,
59
+ record: record.Record ?? {},
60
+ $run: run ?? {},
61
+ };
24
62
  const out = { updatedRecord: false };
25
63
  if (dryRun) {
26
64
  out.dryRun = true;
@@ -31,28 +69,144 @@ export async function applyOutputMapping(opts) {
31
69
  if (!entity) {
32
70
  throw new Error(`applyOutputMapping: entity '${record.EntityID}' not found in metadata`);
33
71
  }
34
- if (entity.PrimaryKeys.length !== 1) {
35
- throw new Error(`applyOutputMapping: write-back currently supports single-primary-key entities only ('${entity.Name}')`);
36
- }
37
72
  // Resolve the mapped values once — shared by the dry-run preview and the real apply.
38
73
  const resolved = {};
39
74
  for (const [field, ref] of Object.entries(outputMapping.fields)) {
40
75
  resolved[field] = resolveMappingRef(ref, sources);
41
76
  }
77
+ // Resolve foreign-key fields where the mapped value is a match string (e.g. 'Director') instead of an ID
78
+ for (const [field, val] of Object.entries(resolved)) {
79
+ if (val === null || val === undefined) {
80
+ continue;
81
+ }
82
+ const fieldInfo = entity.Fields?.find((f) => f.Name.toLowerCase() === field.toLowerCase());
83
+ const lookupConfig = outputMapping.fieldLookups?.[field];
84
+ const isFK = Boolean(lookupConfig || fieldInfo?.RelatedEntity || fieldInfo?.RelatedEntityID);
85
+ if (!isFK) {
86
+ continue;
87
+ }
88
+ // If the value is already a valid UUID, no lookup is required.
89
+ const isUUID = typeof val === 'string' && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(val.trim());
90
+ if (isUUID) {
91
+ resolved[field] = val.trim();
92
+ continue;
93
+ }
94
+ const onLookupMiss = lookupConfig?.onLookupMiss || 'null';
95
+ let matchValue = val;
96
+ if (Array.isArray(matchValue) && matchValue.length > 0) {
97
+ matchValue = matchValue[0];
98
+ }
99
+ if (matchValue && typeof matchValue === 'object' && 'Name' in matchValue) {
100
+ matchValue = matchValue.Name;
101
+ }
102
+ if (typeof matchValue !== 'string' && typeof matchValue !== 'number') {
103
+ if (onLookupMiss === 'fail') {
104
+ throw new Error(`applyOutputMapping: cannot resolve foreign key for field '${field}': value is not a string or number (${typeof matchValue})`);
105
+ }
106
+ resolved[field] = null;
107
+ continue;
108
+ }
109
+ const strVal = String(matchValue).trim();
110
+ if (strVal.length === 0) {
111
+ if (onLookupMiss === 'fail') {
112
+ throw new Error(`applyOutputMapping: cannot resolve foreign key for field '${field}': value resolved to an empty string`);
113
+ }
114
+ resolved[field] = null;
115
+ continue;
116
+ }
117
+ const relatedEntityName = lookupConfig?.relatedEntity ||
118
+ fieldInfo?.RelatedEntity ||
119
+ (fieldInfo?.RelatedEntityID ? provider.EntityByID(fieldInfo.RelatedEntityID)?.Name : undefined);
120
+ if (!relatedEntityName) {
121
+ if (onLookupMiss === 'fail') {
122
+ throw new Error(`applyOutputMapping: cannot resolve foreign key for field '${field}': related entity unknown in metadata`);
123
+ }
124
+ resolved[field] = null;
125
+ continue;
126
+ }
127
+ const matchField = lookupConfig?.matchField || 'Name';
128
+ if (!/^[a-zA-Z0-9_]+$/.test(matchField)) {
129
+ throw new Error(`applyOutputMapping: invalid matchField identifier '${matchField}' for entity '${relatedEntityName}'`);
130
+ }
131
+ const cacheKey = `${relatedEntityName}|${matchField}|${strVal}`;
132
+ if (lookupCache.has(cacheKey)) {
133
+ resolved[field] = lookupCache.get(cacheKey);
134
+ continue;
135
+ }
136
+ const rv = provider && typeof provider.RunView === 'function'
137
+ ? RunView.FromMetadataProvider(provider)
138
+ : (RunView.Provider ? new RunView() : undefined);
139
+ if (!rv) {
140
+ throw new Error(`applyOutputMapping: cannot resolve foreign key for field '${field}': RunView provider is unavailable`);
141
+ }
142
+ const escapedVal = EscapeSQLString(strVal);
143
+ const viewRes = await rv.RunView({
144
+ EntityName: relatedEntityName,
145
+ ExtraFilter: `[${matchField}] = '${escapedVal}'`,
146
+ MaxRows: 1,
147
+ }, contextUser);
148
+ if (viewRes.Success && viewRes.Results && viewRes.Results.length > 0) {
149
+ const matchRow = viewRes.Results[0];
150
+ const relEntity = provider.EntityByName(relatedEntityName);
151
+ const pkFieldName = relEntity?.FirstPrimaryKey?.Name ?? 'ID'; // first-pk-ok: FK target PK resolution
152
+ const resolvedID = matchRow[pkFieldName] ?? matchRow.ID;
153
+ resolved[field] = resolvedID;
154
+ if (typeof resolvedID === 'string' || typeof resolvedID === 'number') {
155
+ lookupCache.set(cacheKey, resolvedID);
156
+ }
157
+ }
158
+ else if (!viewRes.Success) {
159
+ throw new Error(`applyOutputMapping: RunView failed for lookup on '${relatedEntityName}': ${viewRes.ErrorMessage ?? 'unknown error'}`);
160
+ }
161
+ else {
162
+ // Zero-row lookup miss
163
+ if (onLookupMiss === 'null') {
164
+ resolved[field] = null;
165
+ // Do not cache null — keeps positive hits only and prevents downgrading policies (e.g. 'fail' or 'create') across records
166
+ }
167
+ else if (onLookupMiss === 'fail') {
168
+ throw new Error(`applyOutputMapping: lookup for '${field}' on entity '${relatedEntityName}' where [${matchField}]='${strVal}' matched 0 rows (OnLookupMiss=fail)`);
169
+ }
170
+ else if (onLookupMiss === 'create') {
171
+ if (dryRun) {
172
+ resolved[field] = `preview-new-${relatedEntityName}-${strVal}`;
173
+ }
174
+ else {
175
+ const newObj = await provider.GetEntityObject(relatedEntityName, contextUser);
176
+ newObj.NewRecord();
177
+ // Dynamic, config-driven match field — legitimate use of Set()
178
+ newObj.Set(matchField, strVal);
179
+ const created = await newObj.Save();
180
+ if (!created) {
181
+ throw new Error(`applyOutputMapping: failed creating new record in '${relatedEntityName}' with ${matchField}='${strVal}': ${newObj.LatestResult?.CompleteMessage ?? 'unknown error'}`);
182
+ }
183
+ const relEntity = provider.EntityByName(relatedEntityName);
184
+ const pkFieldName = relEntity?.FirstPrimaryKey?.Name ?? 'ID'; // first-pk-ok: FK target PK resolution
185
+ const createdVal = newObj.FirstPrimaryKey?.Value ?? (typeof newObj.Get === 'function' ? newObj.Get(pkFieldName) : undefined); // first-pk-ok: FK target entity single-column PK resolution
186
+ const resolvedPk = typeof createdVal === 'string' || typeof createdVal === 'number'
187
+ ? createdVal
188
+ : newObj.PrimaryKey.ToCompactURLSegment();
189
+ resolved[field] = resolvedPk;
190
+ if (typeof resolvedPk === 'string' || typeof resolvedPk === 'number') {
191
+ lookupCache.set(cacheKey, resolvedPk);
192
+ }
193
+ }
194
+ }
195
+ }
196
+ }
42
197
  if (dryRun) {
43
198
  // Compute-only: surface what an apply WOULD write, persist nothing.
44
199
  out.previewFields = resolved;
45
200
  }
46
201
  else {
47
202
  const obj = await provider.GetEntityObject(entity.Name, contextUser);
48
- // RecordID is the compact CompositeKey segment sourceUtil.serializeRecordId wrote (bare value
49
- // for a single column, "F1|v1||F2|v2" for composite) — parse it, don't assume one column.
203
+ // RecordID is the compact CompositeKey segment (bare value for a single column, "F1|v1||F2|v2" for composite).
50
204
  const loaded = await obj.InnerLoad(CompositeKey.FromURLSegment(entity, record.RecordID));
51
205
  if (!loaded) {
52
206
  throw new Error(`applyOutputMapping: record '${record.RecordID}' of '${entity.Name}' not found`);
53
207
  }
54
208
  for (const [field, value] of Object.entries(resolved)) {
55
- // Dynamic, config-driven field names — the legitimate use of Set() (no compile-time property).
209
+ // Dynamic, config-driven field names — legitimate use of Set() (no compile-time property).
56
210
  obj.Set(field, value);
57
211
  }
58
212
  const saved = await obj.Save();
@@ -62,28 +216,211 @@ export async function applyOutputMapping(opts) {
62
216
  out.updatedRecord = true;
63
217
  }
64
218
  }
65
- // 2) Create a child record.
219
+ // 2) Create child records (single childRecord and/or childRecords with fan-out).
220
+ const childConfigs = [];
66
221
  if (outputMapping.childRecord) {
67
- const childMap = { [outputMapping.childRecord.parentField]: record.RecordID };
68
- for (const [field, ref] of Object.entries(outputMapping.childRecord.map)) {
69
- childMap[field] = resolveMappingRef(ref, sources);
222
+ childConfigs.push({ config: outputMapping.childRecord, isLegacySingle: true });
223
+ }
224
+ if (outputMapping.childRecords && Array.isArray(outputMapping.childRecords)) {
225
+ for (const c of outputMapping.childRecords) {
226
+ childConfigs.push({ config: c, isLegacySingle: false });
70
227
  }
71
- if (dryRun) {
72
- out.previewChild = childMap;
228
+ }
229
+ if (childConfigs.length > 0) {
230
+ const childRecordsToCreate = [];
231
+ for (const { config: childConfig, isLegacySingle } of childConfigs) {
232
+ if (childConfig.fanOutRef) {
233
+ const fanOutVal = resolveMappingRef(childConfig.fanOutRef, sources);
234
+ let items;
235
+ if (Array.isArray(fanOutVal)) {
236
+ items = fanOutVal;
237
+ }
238
+ else if (fanOutVal !== null && fanOutVal !== undefined && typeof fanOutVal === 'object') {
239
+ items = [fanOutVal];
240
+ }
241
+ else {
242
+ items = [];
243
+ if (fanOutVal !== null && fanOutVal !== undefined) {
244
+ LogStatus(`applyOutputMapping: fanOutRef '${childConfig.fanOutRef}' resolved to non-array/non-object value of type '${typeof fanOutVal}'`);
245
+ }
246
+ }
247
+ for (const item of items) {
248
+ const itemSources = {
249
+ $: item,
250
+ item,
251
+ parent: payload,
252
+ record: record.Record ?? {},
253
+ $run: run ?? {},
254
+ };
255
+ const childMap = { [childConfig.parentField]: record.RecordID };
256
+ for (const [field, ref] of Object.entries(childConfig.map)) {
257
+ childMap[field] = resolveMappingRef(ref, itemSources);
258
+ }
259
+ childRecordsToCreate.push({ entity: childConfig.entity, data: childMap, isLegacySingle });
260
+ }
261
+ }
262
+ else {
263
+ const childMap = { [childConfig.parentField]: record.RecordID };
264
+ for (const [field, ref] of Object.entries(childConfig.map)) {
265
+ childMap[field] = resolveMappingRef(ref, sources);
266
+ }
267
+ childRecordsToCreate.push({ entity: childConfig.entity, data: childMap, isLegacySingle });
268
+ }
73
269
  }
74
- else {
75
- const child = await provider.GetEntityObject(outputMapping.childRecord.entity, contextUser);
76
- child.NewRecord();
77
- for (const [field, value] of Object.entries(childMap)) {
78
- child.Set(field, value);
270
+ if (childRecordsToCreate.length > 0) {
271
+ if (dryRun) {
272
+ out.previewChildren = childRecordsToCreate.map((c) => c.data);
273
+ const singleChild = childRecordsToCreate.find((c) => c.isLegacySingle);
274
+ if (singleChild) {
275
+ out.previewChild = singleChild.data;
276
+ }
79
277
  }
80
- const saved = await child.Save();
81
- if (!saved) {
82
- throw new Error(`applyOutputMapping: failed creating '${outputMapping.childRecord.entity}' child: ${child.LatestResult?.CompleteMessage ?? 'unknown error'}`);
278
+ else {
279
+ const createdIDs = [];
280
+ let singleChildID;
281
+ for (const item of childRecordsToCreate) {
282
+ const child = await provider.GetEntityObject(item.entity, contextUser);
283
+ child.NewRecord();
284
+ for (const [field, value] of Object.entries(item.data)) {
285
+ child.Set(field, value);
286
+ }
287
+ const saved = await child.Save();
288
+ if (!saved) {
289
+ throw new Error(`applyOutputMapping: failed creating '${item.entity}' child: ${child.LatestResult?.CompleteMessage ?? 'unknown error'}`);
290
+ }
291
+ const childKey = child.PrimaryKey.ToCompactURLSegment();
292
+ if (childKey && childKey.length > 0) {
293
+ createdIDs.push(childKey);
294
+ if (item.isLegacySingle && !singleChildID) {
295
+ singleChildID = childKey;
296
+ }
297
+ }
298
+ }
299
+ out.createdChildIDs = createdIDs;
300
+ if (singleChildID) {
301
+ out.createdChildID = singleChildID;
302
+ }
303
+ }
304
+ }
305
+ }
306
+ // 3) Apply tags via MJ Tagging system.
307
+ if (outputMapping.tags && outputMapping.tags.length > 0) {
308
+ const previewTags = [];
309
+ const createdTaggedItemIDs = [];
310
+ await TagEngine.Instance.Config(false, contextUser);
311
+ for (const tagMapping of outputMapping.tags) {
312
+ const rawTagVal = resolveMappingRef(tagMapping.ref, sources);
313
+ const tagNames = [];
314
+ if (typeof rawTagVal === 'string') {
315
+ tagNames.push(rawTagVal);
316
+ }
317
+ else if (Array.isArray(rawTagVal)) {
318
+ for (const item of rawTagVal) {
319
+ if (typeof item === 'string') {
320
+ tagNames.push(item);
321
+ }
322
+ else if (item && typeof item === 'object' && 'name' in item && typeof item.name === 'string') {
323
+ tagNames.push(item.name);
324
+ }
325
+ }
83
326
  }
84
- // The child entity is configured — serialize its whole key (bare value for one column, 'F1|v1||F2|v2' for composite).
85
- const childKey = child.PrimaryKey.ToCompactURLSegment();
86
- out.createdChildID = childKey.length > 0 ? childKey : undefined;
327
+ const growthMode = (tagMapping.growth ?? 'constrained');
328
+ const matchThreshold = tagMapping.matchThreshold ?? 0.8;
329
+ for (const tagName of tagNames) {
330
+ if (!tagName || typeof tagName !== 'string' || tagName.trim().length === 0) {
331
+ continue;
332
+ }
333
+ const trimmedName = tagName.trim();
334
+ if (dryRun) {
335
+ let matchedTag = null;
336
+ try {
337
+ matchedTag = await TagEngine.Instance.ResolveTag(trimmedName, 1.0, 'constrained', tagMapping.rootTagId, matchThreshold, contextUser, { dryRun: true });
338
+ }
339
+ catch (error) {
340
+ LogError(`writeBack: ResolveTag dryRun failed: ${error instanceof Error ? error.message : String(error)}`);
341
+ matchedTag = null;
342
+ }
343
+ if (matchedTag) {
344
+ const depth = computeTagDepth(matchedTag.ID, tagMapping.rootTagId, TagEngine.Instance);
345
+ const isNonDescendant = depth < 0;
346
+ const exceedsMaxDepth = isNonDescendant || (tagMapping.maxDepth !== undefined && depth > tagMapping.maxDepth);
347
+ const errorMsg = isNonDescendant
348
+ ? `Matched tag '${matchedTag.Name}' is not a descendant of root tag '${tagMapping.rootTagId}'`
349
+ : (tagMapping.maxDepth !== undefined && depth > tagMapping.maxDepth)
350
+ ? `Match exceeds maxDepth (${depth} > ${tagMapping.maxDepth})`
351
+ : undefined;
352
+ previewTags.push({
353
+ tagText: trimmedName,
354
+ resolvedTagID: matchedTag.ID,
355
+ resolvedTagName: matchedTag.Name,
356
+ matched: true,
357
+ created: false,
358
+ rootTagID: tagMapping.rootTagId,
359
+ depth,
360
+ error: errorMsg,
361
+ });
362
+ }
363
+ else {
364
+ if (growthMode === 'auto-grow') {
365
+ const depth = 1;
366
+ const exceedsMaxDepth = tagMapping.maxDepth !== undefined && depth > tagMapping.maxDepth;
367
+ previewTags.push({
368
+ tagText: trimmedName,
369
+ matched: false,
370
+ created: true,
371
+ rootTagID: tagMapping.rootTagId,
372
+ depth,
373
+ error: exceedsMaxDepth ? `Created tag exceeds maxDepth (${depth} > ${tagMapping.maxDepth})` : undefined,
374
+ });
375
+ }
376
+ else {
377
+ previewTags.push({
378
+ tagText: trimmedName,
379
+ matched: false,
380
+ created: false,
381
+ rootTagID: tagMapping.rootTagId,
382
+ });
383
+ }
384
+ }
385
+ }
386
+ else {
387
+ let wasCreated = false;
388
+ const resolvedTag = await TagEngine.Instance.ResolveTag(trimmedName, 1.0, growthMode, tagMapping.rootTagId, matchThreshold, contextUser, {
389
+ onTagCreated: () => {
390
+ wasCreated = true;
391
+ },
392
+ });
393
+ if (!resolvedTag) {
394
+ continue;
395
+ }
396
+ const depth = computeTagDepth(resolvedTag.ID, tagMapping.rootTagId, TagEngine.Instance);
397
+ if (depth < 0) {
398
+ throw new Error(`applyOutputMapping: tag '${resolvedTag.Name}' is not a descendant of root tag '${tagMapping.rootTagId}'`);
399
+ }
400
+ if (tagMapping.maxDepth !== undefined && depth > tagMapping.maxDepth) {
401
+ throw new Error(`applyOutputMapping: tag '${resolvedTag.Name}' depth (${depth}) exceeds maxDepth (${tagMapping.maxDepth}) under root '${tagMapping.rootTagId}'`);
402
+ }
403
+ let targetEntityID = record.EntityID;
404
+ if (tagMapping.taggedEntityName) {
405
+ const taggedEntity = provider.EntityByName(tagMapping.taggedEntityName);
406
+ if (!taggedEntity) {
407
+ throw new Error(`applyOutputMapping: taggedEntityName '${tagMapping.taggedEntityName}' not found in metadata`);
408
+ }
409
+ targetEntityID = taggedEntity.ID;
410
+ }
411
+ const taggedItem = await TagEngine.Instance.CreateTaggedItem(resolvedTag.ID, targetEntityID, record.RecordID, 1.0, contextUser);
412
+ if (taggedItem) {
413
+ const itemKey = taggedItem.PrimaryKey.ToCompactURLSegment();
414
+ createdTaggedItemIDs.push(itemKey.length > 0 ? itemKey : taggedItem.ID);
415
+ }
416
+ }
417
+ }
418
+ }
419
+ if (dryRun) {
420
+ out.previewTags = previewTags;
421
+ }
422
+ else {
423
+ out.createdTaggedItemIDs = createdTaggedItemIDs;
87
424
  }
88
425
  }
89
426
  return out;
@@ -1 +1 @@
1
- {"version":3,"file":"write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