@rudderjs/orm 1.9.1 → 1.9.3
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/aggregate.d.ts +16 -7
- package/dist/aggregate.d.ts.map +1 -1
- package/dist/aggregate.js +27 -29
- package/dist/aggregate.js.map +1 -1
- package/dist/index.d.ts +49 -127
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +149 -919
- package/dist/index.js.map +1 -1
- package/dist/relations/pivot-accessors.d.ts +127 -0
- package/dist/relations/pivot-accessors.d.ts.map +1 -0
- package/dist/relations/pivot-accessors.js +211 -0
- package/dist/relations/pivot-accessors.js.map +1 -0
- package/dist/relations/pivot-deferred.d.ts +13 -0
- package/dist/relations/pivot-deferred.d.ts.map +1 -0
- package/dist/relations/pivot-deferred.js +210 -0
- package/dist/relations/pivot-deferred.js.map +1 -0
- package/dist/relations/pivot-meta.d.ts +50 -0
- package/dist/relations/pivot-meta.d.ts.map +1 -0
- package/dist/relations/pivot-meta.js +34 -0
- package/dist/relations/pivot-meta.js.map +1 -0
- package/dist/relations/where-has.d.ts +53 -0
- package/dist/relations/where-has.d.ts.map +1 -0
- package/dist/relations/where-has.js +239 -0
- package/dist/relations/where-has.js.map +1 -0
- package/dist/utils.d.ts +35 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +63 -0
- package/dist/utils.js.map +1 -0
- package/package.json +5 -2
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { camelHead } from '../utils.js';
|
|
2
|
+
import { resolveBelongsToManyMeta, resolveMorphToManyMeta, resolveMorphedByManyMeta, } from './pivot-meta.js';
|
|
3
|
+
// ─── Constraint capture ────────────────────────────────────
|
|
4
|
+
/**
|
|
5
|
+
* Run the constrain callback against a recording-only QueryBuilder that
|
|
6
|
+
* captures `.where()` calls into a flat `WhereClause[]` and treats every
|
|
7
|
+
* other chainable method as a no-op. Nested `whereHas` inside the callback
|
|
8
|
+
* throws — recursive predicates are deferred to v2.
|
|
9
|
+
*/
|
|
10
|
+
export function captureConstraintWheres(constrain) {
|
|
11
|
+
const wheres = [];
|
|
12
|
+
const recorder = new Proxy({}, {
|
|
13
|
+
get(_t, prop) {
|
|
14
|
+
const name = String(prop);
|
|
15
|
+
if (name === 'where') {
|
|
16
|
+
return (col, opOrVal, maybeVal) => {
|
|
17
|
+
if (maybeVal === undefined) {
|
|
18
|
+
wheres.push({ column: col, operator: '=', value: opOrVal });
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
wheres.push({ column: col, operator: opOrVal, value: maybeVal });
|
|
22
|
+
}
|
|
23
|
+
return recorder;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (name === 'whereHas' || name === 'whereDoesntHave' || name === 'withWhereHas') {
|
|
27
|
+
return () => {
|
|
28
|
+
throw new Error(`[RudderJS ORM] Nested ${name} inside a whereHas constrain callback is deferred to v2. ` +
|
|
29
|
+
`Filter on flat columns inside the callback for now.`);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (name === 'orWhere') {
|
|
33
|
+
return () => {
|
|
34
|
+
throw new Error(`[RudderJS ORM] orWhere inside a whereHas constrain callback is not supported in v1 — ` +
|
|
35
|
+
`the WhereClause contract has no boolean flag, so the OR semantic can't round-trip to the adapter. ` +
|
|
36
|
+
`Compose the predicate with where() (AND), or run two queries and merge in app code.`);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// All other chainable methods record nothing and return the recorder so
|
|
40
|
+
// `q.orderBy('x').limit(1)` chains through silently. Terminal methods
|
|
41
|
+
// (find/get/etc.) don't make sense in a constrain callback — they'd
|
|
42
|
+
// execute mid-build — but we don't intercept them here; they'd just
|
|
43
|
+
// return the recorder which then fails downstream. Keep the contract
|
|
44
|
+
// simple.
|
|
45
|
+
return () => recorder;
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
constrain(recorder);
|
|
49
|
+
return wheres;
|
|
50
|
+
}
|
|
51
|
+
// ─── belongsTo lookup ──────────────────────────────────────
|
|
52
|
+
/**
|
|
53
|
+
* Resolve the `belongsTo` relation declaration on `Self` that points at
|
|
54
|
+
* `ParentCtor`. When `relation` is given, looks it up directly. Otherwise
|
|
55
|
+
* scans `Self.relations` for a single `belongsTo` whose `model()` resolves
|
|
56
|
+
* to `ParentCtor` — throws on zero or multiple candidates.
|
|
57
|
+
*/
|
|
58
|
+
export function resolveBelongsToFor(Self, ParentCtor, relation) {
|
|
59
|
+
if (relation !== undefined) {
|
|
60
|
+
const def = Self.relations[relation];
|
|
61
|
+
if (!def)
|
|
62
|
+
throw new Error(`[RudderJS ORM] Relation "${relation}" is not defined on ${Self.name}.`);
|
|
63
|
+
if (def.type !== 'belongsTo') {
|
|
64
|
+
throw new Error(`[RudderJS ORM] Relation "${relation}" on ${Self.name} is "${def.type}", not "belongsTo".`);
|
|
65
|
+
}
|
|
66
|
+
return def;
|
|
67
|
+
}
|
|
68
|
+
const candidates = [];
|
|
69
|
+
for (const [name, def] of Object.entries(Self.relations)) {
|
|
70
|
+
if (def.type !== 'belongsTo')
|
|
71
|
+
continue;
|
|
72
|
+
const btDef = def;
|
|
73
|
+
if (btDef.model() === ParentCtor)
|
|
74
|
+
candidates.push([name, btDef]);
|
|
75
|
+
}
|
|
76
|
+
if (candidates.length === 0) {
|
|
77
|
+
throw new Error(`[RudderJS ORM] whereBelongsTo: ${Self.name} has no belongsTo relation pointing at ${ParentCtor.name}. ` +
|
|
78
|
+
`Pass a relation name explicitly.`);
|
|
79
|
+
}
|
|
80
|
+
if (candidates.length > 1) {
|
|
81
|
+
const names = candidates.map(([n]) => n).join(', ');
|
|
82
|
+
throw new Error(`[RudderJS ORM] whereBelongsTo: ${Self.name} has multiple belongsTo relations pointing at ${ParentCtor.name} (${names}). ` +
|
|
83
|
+
`Pass the relation name explicitly.`);
|
|
84
|
+
}
|
|
85
|
+
return candidates[0][1];
|
|
86
|
+
}
|
|
87
|
+
// ─── Predicate builder ─────────────────────────────────────
|
|
88
|
+
/**
|
|
89
|
+
* Build the {@link RelationExistencePredicate} for a relation declared on
|
|
90
|
+
* `Parent`. `morphTo` is rejected before reaching this function (the related
|
|
91
|
+
* table is dynamic).
|
|
92
|
+
*/
|
|
93
|
+
export function buildRelationPredicate(Parent, relation, def, exists, constraintWheres) {
|
|
94
|
+
const Related = def.model();
|
|
95
|
+
if (def.type === 'belongsToMany') {
|
|
96
|
+
const meta = resolveBelongsToManyMeta(Parent, Related, def);
|
|
97
|
+
return {
|
|
98
|
+
relation,
|
|
99
|
+
exists,
|
|
100
|
+
relatedTable: Related.getTable(),
|
|
101
|
+
parentColumn: meta.parentKey,
|
|
102
|
+
relatedColumn: meta.relatedKey,
|
|
103
|
+
constraintWheres,
|
|
104
|
+
through: {
|
|
105
|
+
pivotTable: meta.pivotTable,
|
|
106
|
+
foreignPivotKey: meta.foreignPivotKey,
|
|
107
|
+
relatedPivotKey: meta.relatedPivotKey,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (def.type === 'morphToMany') {
|
|
112
|
+
const meta = resolveMorphToManyMeta(Parent, Related, def);
|
|
113
|
+
return {
|
|
114
|
+
relation,
|
|
115
|
+
exists,
|
|
116
|
+
relatedTable: Related.getTable(),
|
|
117
|
+
parentColumn: meta.parentKey,
|
|
118
|
+
relatedColumn: meta.relatedKey,
|
|
119
|
+
constraintWheres,
|
|
120
|
+
extraEquals: { [meta.morphTypeKey]: meta.morphTypeValue },
|
|
121
|
+
through: {
|
|
122
|
+
pivotTable: meta.pivotTable,
|
|
123
|
+
foreignPivotKey: meta.foreignPivotKey,
|
|
124
|
+
relatedPivotKey: meta.relatedPivotKey,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (def.type === 'morphedByMany') {
|
|
129
|
+
const meta = resolveMorphedByManyMeta(Parent, Related, def);
|
|
130
|
+
return {
|
|
131
|
+
relation,
|
|
132
|
+
exists,
|
|
133
|
+
relatedTable: Related.getTable(),
|
|
134
|
+
parentColumn: meta.parentKey,
|
|
135
|
+
relatedColumn: meta.relatedKey,
|
|
136
|
+
constraintWheres,
|
|
137
|
+
extraEquals: { [meta.morphTypeKey]: meta.morphTypeValue },
|
|
138
|
+
through: {
|
|
139
|
+
pivotTable: meta.pivotTable,
|
|
140
|
+
foreignPivotKey: meta.foreignPivotKey,
|
|
141
|
+
relatedPivotKey: meta.relatedPivotKey,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (def.type === 'morphMany' || def.type === 'morphOne') {
|
|
146
|
+
const idCol = `${def.morphName}Id`;
|
|
147
|
+
const typeCol = `${def.morphName}Type`;
|
|
148
|
+
const localCol = def.localKey ?? Parent.primaryKey;
|
|
149
|
+
const typeVal = def.morphType ?? Parent.morphAlias ?? Parent.name;
|
|
150
|
+
return {
|
|
151
|
+
relation,
|
|
152
|
+
exists,
|
|
153
|
+
relatedTable: Related.getTable(),
|
|
154
|
+
parentColumn: localCol,
|
|
155
|
+
relatedColumn: idCol,
|
|
156
|
+
constraintWheres,
|
|
157
|
+
extraEquals: { [typeCol]: typeVal },
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (def.type === 'belongsTo') {
|
|
161
|
+
const fk = def.foreignKey ?? `${camelHead(Related.name)}Id`;
|
|
162
|
+
const localCol = def.localKey ?? fk;
|
|
163
|
+
return {
|
|
164
|
+
relation,
|
|
165
|
+
exists,
|
|
166
|
+
relatedTable: Related.getTable(),
|
|
167
|
+
parentColumn: localCol,
|
|
168
|
+
relatedColumn: Related.primaryKey,
|
|
169
|
+
constraintWheres,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
// hasOne / hasMany — related table holds the FK pointing back to Parent.
|
|
173
|
+
const fk = def.foreignKey ?? `${camelHead(Parent.name)}Id`;
|
|
174
|
+
const localCol = def.localKey ?? Parent.primaryKey;
|
|
175
|
+
return {
|
|
176
|
+
relation,
|
|
177
|
+
exists,
|
|
178
|
+
relatedTable: Related.getTable(),
|
|
179
|
+
parentColumn: localCol,
|
|
180
|
+
relatedColumn: fk,
|
|
181
|
+
constraintWheres,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
// ─── Public attach helpers ─────────────────────────────────
|
|
185
|
+
/**
|
|
186
|
+
* Build the predicate for a relation declared on `Parent` and dispatch it to
|
|
187
|
+
* the adapter via `q.whereRelationExists(predicate)`. Returns the same
|
|
188
|
+
* QueryBuilder for chaining (the adapter mutates in place).
|
|
189
|
+
*
|
|
190
|
+
* `morphTo` throws — the related table isn't statically known so a single
|
|
191
|
+
* EXISTS subquery can't represent it. Filter on the discriminator + id
|
|
192
|
+
* columns directly when you need that semantic.
|
|
193
|
+
*/
|
|
194
|
+
export function attachWhereHas(Parent, q, relation, exists, constrain) {
|
|
195
|
+
const def = Parent.relations[relation];
|
|
196
|
+
if (!def) {
|
|
197
|
+
throw new Error(`[RudderJS ORM] Relation "${relation}" is not defined on ${Parent.name}.`);
|
|
198
|
+
}
|
|
199
|
+
if (def.type === 'morphTo') {
|
|
200
|
+
throw new Error(`[RudderJS ORM] morphTo "${relation}" cannot be used with whereHas — the related table is dynamic. ` +
|
|
201
|
+
`Filter on ${def.morphName}Id / ${def.morphName}Type directly instead.`);
|
|
202
|
+
}
|
|
203
|
+
const constraintWheres = constrain ? captureConstraintWheres(constrain) : [];
|
|
204
|
+
const predicate = buildRelationPredicate(Parent, relation, def, exists, constraintWheres);
|
|
205
|
+
return q.whereRelationExists(predicate);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* `withWhereHas` — run `whereHas` AND eager-load the relation under the
|
|
209
|
+
* same constraint when the adapter implements `withConstrained`. Adapters
|
|
210
|
+
* without it fall back to plain `with(relation)` (constraint applies only
|
|
211
|
+
* to the parent filter, not the eagerly loaded children).
|
|
212
|
+
*/
|
|
213
|
+
export function attachWithWhereHas(Parent, q, relation, constrain) {
|
|
214
|
+
const constraintWheres = constrain ? captureConstraintWheres(constrain) : [];
|
|
215
|
+
// Reuse attachWhereHas for the parent-side filter — it re-runs the
|
|
216
|
+
// constrain callback against a fresh recorder, so the WhereClause[] we
|
|
217
|
+
// capture above and the one captured inside attachWhereHas come from
|
|
218
|
+
// distinct recorder instances. That's intentional: each captures the
|
|
219
|
+
// same constraint independently and neither is mutated by the adapter.
|
|
220
|
+
attachWhereHas(Parent, q, relation, true, constrain);
|
|
221
|
+
const withConstrained = q.withConstrained;
|
|
222
|
+
if (constraintWheres.length > 0 && typeof withConstrained === 'function') {
|
|
223
|
+
return withConstrained.call(q, relation, constraintWheres);
|
|
224
|
+
}
|
|
225
|
+
return q.with(relation);
|
|
226
|
+
}
|
|
227
|
+
export function attachWhereBelongsTo(Self, q, parent, relation) {
|
|
228
|
+
const ParentCtor = parent.constructor;
|
|
229
|
+
const def = resolveBelongsToFor(Self, ParentCtor, relation);
|
|
230
|
+
const Related = def.model();
|
|
231
|
+
const fk = def.foreignKey ?? `${camelHead(Related.name)}Id`;
|
|
232
|
+
const localCol = def.localKey ?? fk;
|
|
233
|
+
const parentVal = parent[ParentCtor.primaryKey];
|
|
234
|
+
if (parentVal === undefined || parentVal === null) {
|
|
235
|
+
throw new Error(`[RudderJS ORM] whereBelongsTo: parent.${ParentCtor.primaryKey} is unset on ${ParentCtor.name}.`);
|
|
236
|
+
}
|
|
237
|
+
return q.where(localCol, parentVal);
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=where-has.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"where-has.js","sourceRoot":"","sources":["../../src/relations/where-has.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,iBAAiB,CAAA;AAcxB,8DAA8D;AAE9D;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,SAA2C;IAE3C,MAAM,MAAM,GAAkB,EA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3B,MAAgB,EAChB,QAAiB;IAEjB,MAAM,UAAU,GAAG,MAAM,CAAC,WAA2B,CAAA;IACrD,MAAM,GAAG,GAAU,mBAAmB,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAA;IAClE,MAAM,OAAO,GAAM,GAAG,CAAC,KAAK,EAAkB,CAAA;IAC9C,MAAM,EAAE,GAAW,GAAG,CAAC,UAAU,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAA;IACnE,MAAM,QAAQ,GAAK,GAAG,CAAC,QAAQ,IAAM,EAAE,CAAA;IACvC,MAAM,SAAS,GAAK,MAA6C,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IACxF,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CACb,yCAAyC,UAAU,CAAC,UAAU,gBAAgB,UAAU,CAAC,IAAI,GAAG,CACjG,CAAA;IACH,CAAC;IACD,OAAO,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;AACrC,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lowercase first character. Used for camelCase identifier construction
|
|
3
|
+
* (e.g. class name → foreign key column: `Author` → `authorId`).
|
|
4
|
+
*/
|
|
5
|
+
export declare function camelHead(s: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Uppercase first character. Used for aggregate suffix construction
|
|
8
|
+
* (`sum` + `views` → `SumViews`).
|
|
9
|
+
*/
|
|
10
|
+
export declare function capitalize(s: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Read a dynamic property by string key from a Model instance (or any
|
|
13
|
+
* object with typed fields). Encapsulates the unsafe-cast that TS otherwise
|
|
14
|
+
* forces at every dynamic-field-access site. Returns `unknown` — the caller
|
|
15
|
+
* is responsible for whatever narrowing is appropriate.
|
|
16
|
+
*/
|
|
17
|
+
export declare function readField(obj: object, key: string): unknown;
|
|
18
|
+
/**
|
|
19
|
+
* Write a dynamic property by string key onto a Model instance (or any
|
|
20
|
+
* object with typed fields). Mirror of {@link readField}.
|
|
21
|
+
*/
|
|
22
|
+
export declare function writeField(obj: object, key: string, value: unknown): void;
|
|
23
|
+
/**
|
|
24
|
+
* Delete a dynamic property by string key on a Model instance.
|
|
25
|
+
* Mirror of {@link readField}. Used by `instance.refresh()` when pruning
|
|
26
|
+
* stale fields before re-reading the row.
|
|
27
|
+
*/
|
|
28
|
+
export declare function deleteField(obj: object, key: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Loose attribute equality used by dirty tracking and relation predicates.
|
|
31
|
+
* Handles primitives, nulls, Dates (by getTime), and plain objects (by JSON
|
|
32
|
+
* round-trip). Returns false for objects that don't round-trip cleanly.
|
|
33
|
+
*/
|
|
34
|
+
export declare function attrEqual(a: unknown, b: unknown): boolean;
|
|
35
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAG5C;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAE3D;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAE1D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAQzD"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lowercase first character. Used for camelCase identifier construction
|
|
3
|
+
* (e.g. class name → foreign key column: `Author` → `authorId`).
|
|
4
|
+
*/
|
|
5
|
+
export function camelHead(s) {
|
|
6
|
+
return s.charAt(0).toLowerCase() + s.slice(1);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Uppercase first character. Used for aggregate suffix construction
|
|
10
|
+
* (`sum` + `views` → `SumViews`).
|
|
11
|
+
*/
|
|
12
|
+
export function capitalize(s) {
|
|
13
|
+
if (s.length === 0)
|
|
14
|
+
return s;
|
|
15
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Read a dynamic property by string key from a Model instance (or any
|
|
19
|
+
* object with typed fields). Encapsulates the unsafe-cast that TS otherwise
|
|
20
|
+
* forces at every dynamic-field-access site. Returns `unknown` — the caller
|
|
21
|
+
* is responsible for whatever narrowing is appropriate.
|
|
22
|
+
*/
|
|
23
|
+
export function readField(obj, key) {
|
|
24
|
+
return obj[key];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Write a dynamic property by string key onto a Model instance (or any
|
|
28
|
+
* object with typed fields). Mirror of {@link readField}.
|
|
29
|
+
*/
|
|
30
|
+
export function writeField(obj, key, value) {
|
|
31
|
+
obj[key] = value;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Delete a dynamic property by string key on a Model instance.
|
|
35
|
+
* Mirror of {@link readField}. Used by `instance.refresh()` when pruning
|
|
36
|
+
* stale fields before re-reading the row.
|
|
37
|
+
*/
|
|
38
|
+
export function deleteField(obj, key) {
|
|
39
|
+
delete obj[key];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Loose attribute equality used by dirty tracking and relation predicates.
|
|
43
|
+
* Handles primitives, nulls, Dates (by getTime), and plain objects (by JSON
|
|
44
|
+
* round-trip). Returns false for objects that don't round-trip cleanly.
|
|
45
|
+
*/
|
|
46
|
+
export function attrEqual(a, b) {
|
|
47
|
+
if (a === b)
|
|
48
|
+
return true;
|
|
49
|
+
if (a == null && b == null)
|
|
50
|
+
return true;
|
|
51
|
+
if (a instanceof Date && b instanceof Date)
|
|
52
|
+
return a.getTime() === b.getTime();
|
|
53
|
+
if (typeof a === 'object' && a !== null && typeof b === 'object' && b !== null) {
|
|
54
|
+
try {
|
|
55
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,CAAS;IACjC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAC/C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAA;IAC5B,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAC/C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,GAAW;IAChD,OAAQ,GAA+B,CAAC,GAAG,CAAC,CAAA;AAC9C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,GAAW,EAAE,KAAc;IAChE,GAA+B,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAC/C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,GAAW;IAClD,OAAQ,GAA+B,CAAC,GAAG,CAAC,CAAA;AAC9C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CAAC,CAAU,EAAE,CAAU;IAC9C,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACxB,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,IAAI;QAAE,OAAO,IAAI,CAAA;IACvC,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,IAAI;QAAE,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,OAAO,EAAE,CAAA;IAC9E,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QAC/E,IAAI,CAAC;YAAC,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QAAC,CAAC;QAAC,MAAM,CAAC;YAAC,OAAO,KAAK,CAAA;QAAC,CAAC;IAC/E,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rudderjs/orm",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
"directory": "packages/orm"
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
13
|
+
},
|
|
11
14
|
"files": [
|
|
12
15
|
"dist",
|
|
13
16
|
"boost"
|
|
@@ -29,7 +32,7 @@
|
|
|
29
32
|
}
|
|
30
33
|
},
|
|
31
34
|
"dependencies": {
|
|
32
|
-
"@rudderjs/contracts": "^1.
|
|
35
|
+
"@rudderjs/contracts": "^1.7.0"
|
|
33
36
|
},
|
|
34
37
|
"devDependencies": {
|
|
35
38
|
"@types/node": "^20.0.0",
|