@memberjunction/record-comparison 6.2.0 → 6.3.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.
- package/README.md +114 -16
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -4,50 +4,148 @@ Framework-agnostic **record comparison** primitive for MemberJunction.
|
|
|
4
4
|
|
|
5
5
|
`RecordComparisonEngine` loads a set of records for a single entity and computes a
|
|
6
6
|
structured, field-level delta between them — a survivor candidate plus its potential
|
|
7
|
-
matches diffed column-by-column. It performs
|
|
7
|
+
matches diffed column-by-column. It performs one read-only load (`RunView` with
|
|
8
8
|
`ResultType: 'simple'` and a targeted field list) and never mutates records.
|
|
9
9
|
|
|
10
|
+
It is one piece of MJ's duplicate management feature. The end-to-end picture — detection,
|
|
11
|
+
LLM reasoning, review and merging — is in the
|
|
12
|
+
[Duplicate Management Guide](../../guides/DUPLICATE_MANAGEMENT_GUIDE.md).
|
|
13
|
+
|
|
10
14
|
## Why this package exists
|
|
11
15
|
|
|
12
16
|
The comparison logic is needed by two callers that sit on **opposite sides** of the
|
|
13
17
|
dependency graph:
|
|
14
18
|
|
|
15
|
-
- The **LLM duplicate-detection reasoning path** (`@memberjunction/ai-vector-dupe`),
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
- The **LLM duplicate-detection reasoning path** (`@memberjunction/ai-vector-dupe`), whose
|
|
20
|
+
`MatchedSetDeltaBuilder` feeds the differing-field deltas of a matched set to the reasoning
|
|
21
|
+
provider as context.
|
|
22
|
+
- The **side-by-side comparison panel** in the UI (`@memberjunction/ng-record-merge`, used by the
|
|
23
|
+
entity grid's merge flow), which reaches the engine through the `RecordComparison.Compare`
|
|
24
|
+
**Remote Operation** this package registers.
|
|
20
25
|
|
|
21
|
-
`@memberjunction/core-entities-server` depends on `@memberjunction/ai-vector-dupe`, so
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
implementation
|
|
26
|
+
`@memberjunction/core-entities-server` depends on `@memberjunction/ai-vector-dupe`, so the dupe
|
|
27
|
+
package sits *lower* in the graph and cannot reach an engine that lives in a server package
|
|
28
|
+
without a build cycle. Hoisting the engine into this low-level package (it depends only on
|
|
29
|
+
`@memberjunction/core`, `@memberjunction/core-entities` and `@memberjunction/global`) gives both
|
|
30
|
+
sides one implementation, no cycle, and no duplicated delta logic.
|
|
26
31
|
|
|
27
32
|
## Usage
|
|
28
33
|
|
|
34
|
+
### On the server
|
|
35
|
+
|
|
29
36
|
```typescript
|
|
30
37
|
import { RecordComparisonEngine } from '@memberjunction/record-comparison';
|
|
31
38
|
import { CompositeKey } from '@memberjunction/core';
|
|
32
39
|
|
|
33
40
|
const engine = new RecordComparisonEngine();
|
|
34
41
|
|
|
35
|
-
// By entity name
|
|
42
|
+
// By entity name — resolves the entity from the (request-scoped) provider's metadata.
|
|
36
43
|
const result = await engine.CompareRecords(
|
|
37
44
|
{ EntityName: 'Accounts', Keys: [survivorKey, candidateKey] },
|
|
38
45
|
contextUser,
|
|
39
46
|
provider // request-scoped IMetadataProvider (multi-provider safety)
|
|
40
47
|
);
|
|
41
48
|
|
|
42
|
-
// With an already-resolved EntityInfo
|
|
49
|
+
// With an already-resolved EntityInfo and an injected RunView (the dupe path) — skips the
|
|
43
50
|
// by-name lookup and reuses the caller's request-scoped RunView.
|
|
44
51
|
const result2 = await engine.CompareRecordsForEntity(
|
|
45
52
|
entityInfo,
|
|
46
53
|
[sourceKey, ...candidateKeys],
|
|
47
54
|
contextUser,
|
|
48
|
-
{ runView }
|
|
55
|
+
{ RunViewInstance: runView, IncludeFields: ['Name', 'Email', 'Phone'] }
|
|
49
56
|
);
|
|
57
|
+
|
|
58
|
+
if (result.Success) {
|
|
59
|
+
for (const field of result.Fields.filter(f => f.Differs)) {
|
|
60
|
+
console.log(field.DisplayName, field.Cells.map(c => c.Value));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
50
63
|
```
|
|
51
64
|
|
|
52
|
-
|
|
53
|
-
|
|
65
|
+
The engine never throws for ordinary failures: check `result.Success` and read
|
|
66
|
+
`result.ErrorMessage`.
|
|
67
|
+
|
|
68
|
+
### From any client: the `RecordComparison.Compare` Remote Operation
|
|
69
|
+
|
|
70
|
+
This package registers `RecordComparisonCompareServerOperation` under the operation key
|
|
71
|
+
`RecordComparison.Compare`. The typed client base, `RecordComparisonCompareOperation`, is
|
|
72
|
+
generated into `@memberjunction/core-entities`, so the browser calls the same contract over the
|
|
73
|
+
generic remote-operation transport — there is no bespoke resolver or GraphQL client:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { RecordComparisonCompareOperation } from '@memberjunction/core-entities';
|
|
77
|
+
|
|
78
|
+
const op = new RecordComparisonCompareOperation();
|
|
79
|
+
const result = await op.Execute(
|
|
80
|
+
{
|
|
81
|
+
EntityName: 'Accounts',
|
|
82
|
+
Keys: [
|
|
83
|
+
{ KeyValuePairs: [{ FieldName: 'ID', Value: survivorId }] },
|
|
84
|
+
{ KeyValuePairs: [{ FieldName: 'ID', Value: candidateId }] },
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
{ provider: this.ProviderToUse }
|
|
88
|
+
);
|
|
89
|
+
if (result.Success && result.Output) {
|
|
90
|
+
const { Records, Fields } = result.Output;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
In Angular, `RecordComparisonService.GetRecordComparison()` in `@memberjunction/ng-record-merge`
|
|
95
|
+
wraps exactly this call. The operation runs as the calling user, so entity permissions and
|
|
96
|
+
row-level security apply to the records it loads. Make sure the server bootstrap loads this
|
|
97
|
+
package (`LoadRecordComparisonCompareOperation()` is the tree-shaking anchor) so the registration
|
|
98
|
+
exists.
|
|
99
|
+
|
|
100
|
+
## What gets compared
|
|
101
|
+
|
|
102
|
+
| Rule | Detail |
|
|
103
|
+
|---|---|
|
|
104
|
+
| Field set | The `IncludeFields` list (case-insensitive) when given; otherwise every field except primary keys and `__mj_*` system columns. |
|
|
105
|
+
| Field order | Name fields first, then `DefaultInView` fields, then by `Sequence`, then by name. |
|
|
106
|
+
| Reference column | `Keys[0]` is the reference (the survivor candidate). Every other record's cell carries `EqualsReference`. |
|
|
107
|
+
| Equality | Trimmed, case-insensitive string comparison; `null` equals only `null`/`undefined`. |
|
|
108
|
+
| Empty fields | A field whose value is empty in **every** record is dropped — it carries no signal. |
|
|
109
|
+
| `Differs` | `true` when any cell differs from the reference. |
|
|
110
|
+
| Record label | The first name field's value, falling back to the key's values. |
|
|
111
|
+
| Loading | One `RunView` that ORs every key's `WHERE` clause, `MaxRows` = number of keys, run as the context user. Works for single-column and composite keys of any column name. |
|
|
112
|
+
|
|
113
|
+
## Result shape
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
interface RecordComparisonResult {
|
|
117
|
+
Success: boolean;
|
|
118
|
+
ErrorMessage?: string;
|
|
119
|
+
EntityName: string;
|
|
120
|
+
Records: RecordComparisonRecord[]; // one per input key, ColumnIndex aligned with Keys
|
|
121
|
+
Fields: RecordComparisonFieldDelta[]; // one per compared, non-empty field
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
interface RecordComparisonFieldDelta {
|
|
125
|
+
FieldName: string;
|
|
126
|
+
DisplayName: string;
|
|
127
|
+
Category: string | null;
|
|
128
|
+
Cells: { ColumnIndex: number; Value: string | number | boolean | null; EqualsReference: boolean }[];
|
|
129
|
+
Differs: boolean;
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`Fields` is a plain-data delta matrix (no `BaseEntity` instances), so it serializes cleanly over
|
|
134
|
+
the wire and into a reasoning prompt.
|
|
135
|
+
|
|
136
|
+
> **Field-level security.** The engine loads values as the context user, so a field the user may
|
|
137
|
+
> not read never reaches them. The duplicate-reasoning path additionally drops fields that any
|
|
138
|
+
> role is restricted from (`GetIndexRestrictedFieldNames`), because its prompt and stored
|
|
139
|
+
> reasoning are read by everyone who can see the duplicate run — see
|
|
140
|
+
> `MatchedSetDeltaBuilder` in `@memberjunction/ai-vector-dupe`.
|
|
141
|
+
|
|
142
|
+
## Development
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
pnpm run build
|
|
146
|
+
pnpm run test
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## License
|
|
150
|
+
|
|
151
|
+
Business Source License 1.1 — see [LICENSE](../../LICENSE) for details.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/record-comparison",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.3.0-edge.0",
|
|
5
5
|
"description": "MemberJunction: Framework-agnostic record comparison engine — loads a set of records for one entity and computes a structured field-level delta. Shared by the duplicate-detection reasoning path and the UI side-by-side comparison panel.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"author": "MemberJunction.com",
|
|
12
12
|
"license": "BUSL-1.1",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@memberjunction/core": "6.
|
|
15
|
-
"@memberjunction/core-entities": "6.
|
|
16
|
-
"@memberjunction/global": "6.
|
|
14
|
+
"@memberjunction/core": "6.3.0-edge.0",
|
|
15
|
+
"@memberjunction/core-entities": "6.3.0-edge.0",
|
|
16
|
+
"@memberjunction/global": "6.3.0-edge.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "24.10.11",
|