@naturalcycles/abba 2.2.0 → 2.3.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/abba.d.ts +3 -2
- package/dist/abba.js +10 -4
- package/package.json +1 -1
- package/src/abba.ts +11 -4
package/dist/abba.d.ts
CHANGED
|
@@ -18,9 +18,10 @@ export declare class Abba {
|
|
|
18
18
|
getAllExperimentsWithBucketsNoCache(opts?: GetAllExperimentsOpts): Promise<ExperimentWithBuckets[]>;
|
|
19
19
|
getUserExperiments(userId: string): Promise<UserExperiment[]>;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Changes all user assignments from one userId to another, as long as no
|
|
22
|
+
* assignment for a given experiment already exists with the new userId.
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
+
mergeAssignmentsForUserIds(fromUserId: string, intoUserId: string): Promise<void>;
|
|
24
25
|
/**
|
|
25
26
|
* Creates a new experiment.
|
|
26
27
|
* Cold method.
|
package/dist/abba.js
CHANGED
|
@@ -58,11 +58,17 @@ export class Abba {
|
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Changes all user assignments from one userId to another, as long as no
|
|
62
|
+
* assignment for a given experiment already exists with the new userId.
|
|
62
63
|
*/
|
|
63
|
-
async
|
|
64
|
-
const
|
|
65
|
-
await this.userAssignmentDao.
|
|
64
|
+
async mergeAssignmentsForUserIds(fromUserId, intoUserId) {
|
|
65
|
+
const fromAssignments = await this.userAssignmentDao.getBy('userId', fromUserId);
|
|
66
|
+
const existingIntoAssignments = await this.userAssignmentDao.getBy('userId', intoUserId);
|
|
67
|
+
await pMap(fromAssignments, async (from) => {
|
|
68
|
+
if (!existingIntoAssignments.some(into => into.experimentId === from.experimentId)) {
|
|
69
|
+
await this.userAssignmentDao.patch(from, { userId: intoUserId });
|
|
70
|
+
}
|
|
71
|
+
});
|
|
66
72
|
}
|
|
67
73
|
/**
|
|
68
74
|
* Creates a new experiment.
|
package/package.json
CHANGED
package/src/abba.ts
CHANGED
|
@@ -94,11 +94,18 @@ export class Abba {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
97
|
+
* Changes all user assignments from one userId to another, as long as no
|
|
98
|
+
* assignment for a given experiment already exists with the new userId.
|
|
98
99
|
*/
|
|
99
|
-
async
|
|
100
|
-
const
|
|
101
|
-
await this.userAssignmentDao.
|
|
100
|
+
async mergeAssignmentsForUserIds(fromUserId: string, intoUserId: string): Promise<void> {
|
|
101
|
+
const fromAssignments = await this.userAssignmentDao.getBy('userId', fromUserId)
|
|
102
|
+
const existingIntoAssignments = await this.userAssignmentDao.getBy('userId', intoUserId)
|
|
103
|
+
|
|
104
|
+
await pMap(fromAssignments, async from => {
|
|
105
|
+
if (!existingIntoAssignments.some(into => into.experimentId === from.experimentId)) {
|
|
106
|
+
await this.userAssignmentDao.patch(from, { userId: intoUserId })
|
|
107
|
+
}
|
|
108
|
+
})
|
|
102
109
|
}
|
|
103
110
|
|
|
104
111
|
/**
|