@naturalcycles/abba 2.14.0 → 2.16.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 CHANGED
@@ -11,11 +11,11 @@ export declare class Abba {
11
11
  * Returns all experiments.
12
12
  * Cached (see CACHE_TTL)
13
13
  */
14
- getAllExperimentsWithBuckets(opts?: GetAllExperimentsOpts): Promise<ExperimentWithBuckets[]>;
14
+ getAllExperimentsWithBuckets(opt?: GetAllExperimentsOpts): Promise<ExperimentWithBuckets[]>;
15
15
  /**
16
16
  * Returns all experiments.
17
17
  */
18
- getAllExperimentsWithBucketsNoCache(opts?: GetAllExperimentsOpts): Promise<ExperimentWithBuckets[]>;
18
+ getAllExperimentsWithBucketsNoCache(opt?: 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
package/dist/abba.js CHANGED
@@ -25,14 +25,14 @@ export class Abba {
25
25
  * Returns all experiments.
26
26
  * Cached (see CACHE_TTL)
27
27
  */
28
- async getAllExperimentsWithBuckets(opts) {
29
- return await this.getAllExperimentsWithBucketsNoCache(opts);
28
+ async getAllExperimentsWithBuckets(opt) {
29
+ return await this.getAllExperimentsWithBucketsNoCache(opt);
30
30
  }
31
31
  /**
32
32
  * Returns all experiments.
33
33
  */
34
- async getAllExperimentsWithBucketsNoCache(opts) {
35
- const experiments = await this.experimentDao.getAllExperiments(opts);
34
+ async getAllExperimentsWithBucketsNoCache(opt) {
35
+ const experiments = await this.experimentDao.getAllExperiments(opt);
36
36
  const buckets = await this.bucketDao.getAll();
37
37
  return experiments.map(experiment => ({
38
38
  ...experiment,
@@ -120,7 +120,7 @@ export class Abba {
120
120
  async updateExclusions(experimentId, updatedExclusions) {
121
121
  const experiments = await this.experimentDao.getAll();
122
122
  const requiresUpdating = [];
123
- experiments.map(experiment => {
123
+ for (const experiment of experiments) {
124
124
  // Make sure it's mutual
125
125
  if (updatedExclusions.includes(experiment.id) &&
126
126
  !experiment.exclusions.includes(experimentId)) {
@@ -133,7 +133,7 @@ export class Abba {
133
133
  experiment.exclusions = experiment.exclusions.filter(id => id !== experimentId);
134
134
  requiresUpdating.push(experiment);
135
135
  }
136
- });
136
+ }
137
137
  await this.experimentDao.saveBatch(requiresUpdating, { saveMethod: 'update' });
138
138
  }
139
139
  async softDeleteExperiment(experimentId) {
@@ -41,6 +41,7 @@ export function experimentDao(db) {
41
41
  */
42
42
  function parseMySQLDate(date) {
43
43
  // @ts-expect-error MySQL may return Date instead of string
44
+ // oxlint-disable-next-line no-restricted-globals -- the MySQL driver may return a Date
44
45
  if (date instanceof Date)
45
46
  return localDate(date).toISODate();
46
47
  return date;
package/dist/util.js CHANGED
@@ -44,15 +44,13 @@ export function determineBucket(buckets) {
44
44
  const bucketRoll = randomService.rollDie();
45
45
  let range;
46
46
  const bucket = buckets.find(b => {
47
- if (!range) {
48
- range = [0, b.ratio];
49
- }
50
- else {
47
+ if (range) {
51
48
  range = [range[1], range[1] + b.ratio];
52
49
  }
53
- if (bucketRoll > range[0] && bucketRoll <= range[1]) {
54
- return b;
50
+ else {
51
+ range = [0, b.ratio];
55
52
  }
53
+ return bucketRoll > range[0] && bucketRoll <= range[1];
56
54
  });
57
55
  _assert(bucket, 'Could not determine bucket from ratios', {
58
56
  code: AbbaErrorCode.BucketDeterminationFailed,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/abba",
3
3
  "type": "module",
4
- "version": "2.14.0",
4
+ "version": "2.16.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/db-lib": "^10",
7
7
  "@naturalcycles/js-lib": "^15",
@@ -10,7 +10,7 @@
10
10
  "tslib": "^2"
11
11
  },
12
12
  "devDependencies": {
13
- "@naturalcycles/dev-lib": "0.0.0",
13
+ "@naturalcycles/dev-lib": "20.79.0",
14
14
  "@types/semver": "^7",
15
15
  "typescript": "^7"
16
16
  },
package/src/abba.ts CHANGED
@@ -54,18 +54,18 @@ export class Abba {
54
54
  */
55
55
  @_Memo({ cacheFactory: () => new LRUMemoCache({ ttl: CACHE_TTL, max: 1 }) })
56
56
  async getAllExperimentsWithBuckets(
57
- opts?: GetAllExperimentsOpts,
57
+ opt?: GetAllExperimentsOpts,
58
58
  ): Promise<ExperimentWithBuckets[]> {
59
- return await this.getAllExperimentsWithBucketsNoCache(opts)
59
+ return await this.getAllExperimentsWithBucketsNoCache(opt)
60
60
  }
61
61
 
62
62
  /**
63
63
  * Returns all experiments.
64
64
  */
65
65
  async getAllExperimentsWithBucketsNoCache(
66
- opts?: GetAllExperimentsOpts,
66
+ opt?: GetAllExperimentsOpts,
67
67
  ): Promise<ExperimentWithBuckets[]> {
68
- const experiments = await this.experimentDao.getAllExperiments(opts)
68
+ const experiments = await this.experimentDao.getAllExperiments(opt)
69
69
  const buckets = await this.bucketDao.getAll()
70
70
 
71
71
  return experiments.map(experiment => ({
@@ -190,7 +190,7 @@ export class Abba {
190
190
  const experiments = await this.experimentDao.getAll()
191
191
 
192
192
  const requiresUpdating: Experiment[] = []
193
- experiments.map(experiment => {
193
+ for (const experiment of experiments) {
194
194
  // Make sure it's mutual
195
195
  if (
196
196
  updatedExclusions.includes(experiment.id) &&
@@ -208,7 +208,7 @@ export class Abba {
208
208
  experiment.exclusions = experiment.exclusions.filter(id => id !== experimentId)
209
209
  requiresUpdating.push(experiment)
210
210
  }
211
- })
211
+ }
212
212
 
213
213
  await this.experimentDao.saveBatch(requiresUpdating, { saveMethod: 'update' })
214
214
  }
@@ -49,6 +49,7 @@ export function experimentDao(db: CommonDB): ExperimentDao {
49
49
  */
50
50
  function parseMySQLDate(date: string): IsoDate {
51
51
  // @ts-expect-error MySQL may return Date instead of string
52
+ // oxlint-disable-next-line no-restricted-globals -- the MySQL driver may return a Date
52
53
  if (date instanceof Date) return localDate(date).toISODate()
53
54
  return date as IsoDate
54
55
  }
package/src/util.ts CHANGED
@@ -68,15 +68,13 @@ export function determineBucket(buckets: readonly Bucket[]): Bucket {
68
68
  const bucketRoll = randomService.rollDie()
69
69
  let range: [number, number] | undefined
70
70
  const bucket = buckets.find(b => {
71
- if (!range) {
72
- range = [0, b.ratio]
73
- } else {
71
+ if (range) {
74
72
  range = [range[1], range[1] + b.ratio]
73
+ } else {
74
+ range = [0, b.ratio]
75
75
  }
76
76
 
77
- if (bucketRoll > range[0] && bucketRoll <= range[1]) {
78
- return b
79
- }
77
+ return bucketRoll > range[0] && bucketRoll <= range[1]
80
78
  })
81
79
 
82
80
  _assert(bucket, 'Could not determine bucket from ratios', {