@naturalcycles/abba 1.25.2 → 1.26.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 +2 -0
- package/dist/abba.js +7 -1
- package/dist/types.d.ts +3 -3
- package/package.json +2 -2
- package/src/abba.ts +14 -2
- package/src/dao/experiment.dao.ts +3 -3
- package/src/types.ts +3 -3
package/dist/abba.d.ts
CHANGED
|
@@ -36,6 +36,8 @@ export declare class Abba {
|
|
|
36
36
|
private updateExclusions;
|
|
37
37
|
/**
|
|
38
38
|
* Delete an experiment. Removes all user assignments and buckets.
|
|
39
|
+
* Requires the experiment to have been inactive for at least 15 minutes in order to
|
|
40
|
+
* avoid row locking issues.
|
|
39
41
|
* Cold method.
|
|
40
42
|
*/
|
|
41
43
|
deleteExperiment(experimentId: string): Promise<void>;
|
package/dist/abba.js
CHANGED
|
@@ -12,7 +12,7 @@ const util_1 = require("./util");
|
|
|
12
12
|
/**
|
|
13
13
|
* 10 minutes
|
|
14
14
|
*/
|
|
15
|
-
const CACHE_TTL = 600_000;
|
|
15
|
+
const CACHE_TTL = 600_000;
|
|
16
16
|
class Abba {
|
|
17
17
|
constructor(cfg) {
|
|
18
18
|
this.cfg = cfg;
|
|
@@ -103,9 +103,15 @@ class Abba {
|
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* Delete an experiment. Removes all user assignments and buckets.
|
|
106
|
+
* Requires the experiment to have been inactive for at least 15 minutes in order to
|
|
107
|
+
* avoid row locking issues.
|
|
106
108
|
* Cold method.
|
|
107
109
|
*/
|
|
108
110
|
async deleteExperiment(experimentId) {
|
|
111
|
+
const experiment = await this.experimentDao.requireById(experimentId);
|
|
112
|
+
const hasBeenInactiveFor15Mins = experiment.status === types_1.AssignmentStatus.Inactive &&
|
|
113
|
+
(0, js_lib_1.localTime)(experiment.updated).isOlderThan(15, 'minute');
|
|
114
|
+
(0, js_lib_1._assert)(hasBeenInactiveFor15Mins, 'Experiment must be inactive for at least 15 minutes before deletion');
|
|
109
115
|
const userAssignmentDeleteQuery = this.userAssignmentDao
|
|
110
116
|
.query()
|
|
111
117
|
.filterEq('experimentId', experimentId);
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommonDB } from '@naturalcycles/db-lib';
|
|
2
|
-
import { AnyObject, BaseDBEntity,
|
|
2
|
+
import { AnyObject, BaseDBEntity, IsoDate, Saved } from '@naturalcycles/js-lib';
|
|
3
3
|
export interface AbbaConfig {
|
|
4
4
|
db: CommonDB;
|
|
5
5
|
}
|
|
@@ -24,11 +24,11 @@ export type BaseExperiment = BaseDBEntity & {
|
|
|
24
24
|
/**
|
|
25
25
|
* Date range start for the experiment assignments
|
|
26
26
|
*/
|
|
27
|
-
startDateIncl:
|
|
27
|
+
startDateIncl: IsoDate;
|
|
28
28
|
/**
|
|
29
29
|
* Date range end for the experiment assignments
|
|
30
30
|
*/
|
|
31
|
-
endDateExcl:
|
|
31
|
+
endDateExcl: IsoDate;
|
|
32
32
|
};
|
|
33
33
|
export type Experiment = BaseExperiment & {
|
|
34
34
|
rules: SegmentationRule[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/abba",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky",
|
|
6
6
|
"build": "dev-lib build",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"url": "https://github.com/NaturalCycles/abba"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
42
|
+
"node": ">=22.10.0"
|
|
43
43
|
},
|
|
44
44
|
"description": "AB test assignment configuration tool for Node.js",
|
|
45
45
|
"author": "Natural Cycles Team",
|
package/src/abba.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _assert, _Memo, _shuffle, pMap, Unsaved } from '@naturalcycles/js-lib'
|
|
1
|
+
import { _assert, _Memo, _shuffle, localTime, pMap, Unsaved } from '@naturalcycles/js-lib'
|
|
2
2
|
import { LRUMemoCache } from '@naturalcycles/nodejs-lib'
|
|
3
3
|
import { SegmentationData } from '.'
|
|
4
4
|
import { bucketDao } from './dao/bucket.dao'
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
/**
|
|
26
26
|
* 10 minutes
|
|
27
27
|
*/
|
|
28
|
-
const CACHE_TTL = 600_000
|
|
28
|
+
const CACHE_TTL = 600_000
|
|
29
29
|
|
|
30
30
|
export class Abba {
|
|
31
31
|
private experimentDao = experimentDao(this.cfg.db)
|
|
@@ -149,9 +149,21 @@ export class Abba {
|
|
|
149
149
|
|
|
150
150
|
/**
|
|
151
151
|
* Delete an experiment. Removes all user assignments and buckets.
|
|
152
|
+
* Requires the experiment to have been inactive for at least 15 minutes in order to
|
|
153
|
+
* avoid row locking issues.
|
|
152
154
|
* Cold method.
|
|
153
155
|
*/
|
|
154
156
|
async deleteExperiment(experimentId: string): Promise<void> {
|
|
157
|
+
const experiment = await this.experimentDao.requireById(experimentId)
|
|
158
|
+
|
|
159
|
+
const hasBeenInactiveFor15Mins =
|
|
160
|
+
experiment.status === AssignmentStatus.Inactive &&
|
|
161
|
+
localTime(experiment.updated).isOlderThan(15, 'minute')
|
|
162
|
+
_assert(
|
|
163
|
+
hasBeenInactiveFor15Mins,
|
|
164
|
+
'Experiment must be inactive for at least 15 minutes before deletion',
|
|
165
|
+
)
|
|
166
|
+
|
|
155
167
|
const userAssignmentDeleteQuery = this.userAssignmentDao
|
|
156
168
|
.query()
|
|
157
169
|
.filterEq('experimentId', experimentId)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommonDao, CommonDB } from '@naturalcycles/db-lib'
|
|
2
|
-
import {
|
|
2
|
+
import { IsoDate, localDate, Saved } from '@naturalcycles/js-lib'
|
|
3
3
|
import { BaseExperiment, Experiment } from '../types'
|
|
4
4
|
|
|
5
5
|
type ExperimentDBM = Saved<BaseExperiment> & {
|
|
@@ -46,8 +46,8 @@ export const experimentDao = (db: CommonDB): ExperimentDao =>
|
|
|
46
46
|
* MySQL Automatically parses Date fields as Date objects
|
|
47
47
|
* For simplicity let's not do that by having this function...
|
|
48
48
|
*/
|
|
49
|
-
function parseMySQLDate(date: string):
|
|
49
|
+
function parseMySQLDate(date: string): IsoDate {
|
|
50
50
|
// @ts-expect-error
|
|
51
51
|
if (date instanceof Date) return localDate(date).toISODate()
|
|
52
|
-
return date
|
|
52
|
+
return date as IsoDate
|
|
53
53
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CommonDB } from '@naturalcycles/db-lib'
|
|
2
|
-
import { AnyObject, BaseDBEntity,
|
|
2
|
+
import { AnyObject, BaseDBEntity, IsoDate, Saved } from '@naturalcycles/js-lib'
|
|
3
3
|
|
|
4
4
|
export interface AbbaConfig {
|
|
5
5
|
db: CommonDB
|
|
@@ -26,11 +26,11 @@ export type BaseExperiment = BaseDBEntity & {
|
|
|
26
26
|
/**
|
|
27
27
|
* Date range start for the experiment assignments
|
|
28
28
|
*/
|
|
29
|
-
startDateIncl:
|
|
29
|
+
startDateIncl: IsoDate
|
|
30
30
|
/**
|
|
31
31
|
* Date range end for the experiment assignments
|
|
32
32
|
*/
|
|
33
|
-
endDateExcl:
|
|
33
|
+
endDateExcl: IsoDate
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export type Experiment = BaseExperiment & {
|