@naturalcycles/abba 2.5.0 → 2.7.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.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { __decorate } from "tslib";
2
- import { _shuffle } from '@naturalcycles/js-lib';
3
- import { localTime } from '@naturalcycles/js-lib/datetime';
4
- import { _Memo } from '@naturalcycles/js-lib/decorators';
5
- import { _assert } from '@naturalcycles/js-lib/error';
6
- import { pMap } from '@naturalcycles/js-lib/promise';
2
+ import { _shuffle } from '@naturalcycles/js-lib/array/array.util.js';
3
+ import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js';
4
+ import { _Memo } from '@naturalcycles/js-lib/decorators/memo.decorator.js';
5
+ import { _assert } from '@naturalcycles/js-lib/error/assert.js';
6
+ import { pMap } from '@naturalcycles/js-lib/promise/pMap.js';
7
7
  import { LRUMemoCache } from '@naturalcycles/nodejs-lib/lruMemoCache';
8
8
  import { bucketDao } from './dao/bucket.dao.js';
9
9
  import { experimentDao } from './dao/experiment.dao.js';
package/dist/types.d.ts CHANGED
@@ -88,7 +88,9 @@ export declare enum SegmentationRuleOperator {
88
88
  NotEqualsText = "notEqualsText",
89
89
  Semver = "semver",
90
90
  Regex = "regex",
91
- Boolean = "boolean"
91
+ Boolean = "boolean",
92
+ GreaterThan = "greaterThan",
93
+ LessThan = "lessThan"
92
94
  }
93
95
  export type SegmentationRuleFn = (segmentationProp: string | boolean | number | null | undefined, ruleValue: SegmentationRule['value']) => boolean;
94
96
  export interface ExperimentAssignmentStatistics {
package/dist/types.js CHANGED
@@ -21,6 +21,8 @@ export var SegmentationRuleOperator;
21
21
  SegmentationRuleOperator["NotEqualsText"] = "notEqualsText";
22
22
  SegmentationRuleOperator["Semver"] = "semver";
23
23
  SegmentationRuleOperator["Regex"] = "regex";
24
- /* eslint-disable id-blacklist*/
24
+ /* eslint-disable id-denylist */
25
25
  SegmentationRuleOperator["Boolean"] = "boolean";
26
+ SegmentationRuleOperator["GreaterThan"] = "greaterThan";
27
+ SegmentationRuleOperator["LessThan"] = "lessThan";
26
28
  })(SegmentationRuleOperator || (SegmentationRuleOperator = {}));
package/dist/util.js CHANGED
@@ -111,6 +111,16 @@ export const segmentationRuleMap = {
111
111
  // Anything else cannot be true
112
112
  return keyValue?.toString() !== 'true';
113
113
  },
114
+ [SegmentationRuleOperator.GreaterThan](keyValue, ruleValue) {
115
+ if (keyValue === null || keyValue === undefined)
116
+ return false;
117
+ return keyValue > ruleValue;
118
+ },
119
+ [SegmentationRuleOperator.LessThan](keyValue, ruleValue) {
120
+ if (keyValue === null || keyValue === undefined)
121
+ return false;
122
+ return keyValue < ruleValue;
123
+ },
114
124
  };
115
125
  /**
116
126
  * Returns true if an experiment is able to generate new assignments based on status and start/end dates
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/abba",
3
3
  "type": "module",
4
- "version": "2.5.0",
4
+ "version": "2.7.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/db-lib": "^10",
7
7
  "@naturalcycles/js-lib": "^15",
@@ -10,8 +10,8 @@
10
10
  "tslib": "^2"
11
11
  },
12
12
  "devDependencies": {
13
- "@naturalcycles/dev-lib": "*",
14
- "@types/semver": "^7"
13
+ "@types/semver": "^7",
14
+ "@naturalcycles/dev-lib": "18.4.2"
15
15
  },
16
16
  "exports": {
17
17
  ".": "./dist/index.js"
package/src/abba.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { _shuffle } from '@naturalcycles/js-lib'
2
- import { localTime } from '@naturalcycles/js-lib/datetime'
3
- import { _Memo } from '@naturalcycles/js-lib/decorators'
4
- import { _assert } from '@naturalcycles/js-lib/error'
5
- import { pMap } from '@naturalcycles/js-lib/promise'
1
+ import { _shuffle } from '@naturalcycles/js-lib/array/array.util.js'
2
+ import { localTime } from '@naturalcycles/js-lib/datetime/localTime.js'
3
+ import { _Memo } from '@naturalcycles/js-lib/decorators/memo.decorator.js'
4
+ import { _assert } from '@naturalcycles/js-lib/error/assert.js'
5
+ import { pMap } from '@naturalcycles/js-lib/promise/pMap.js'
6
6
  import type { Unsaved } from '@naturalcycles/js-lib/types'
7
7
  import { LRUMemoCache } from '@naturalcycles/nodejs-lib/lruMemoCache'
8
8
  import { bucketDao } from './dao/bucket.dao.js'
package/src/types.ts CHANGED
@@ -100,8 +100,10 @@ export enum SegmentationRuleOperator {
100
100
  NotEqualsText = 'notEqualsText',
101
101
  Semver = 'semver',
102
102
  Regex = 'regex',
103
- /* eslint-disable id-blacklist*/
103
+ /* eslint-disable id-denylist */
104
104
  Boolean = 'boolean',
105
+ GreaterThan = 'greaterThan',
106
+ LessThan = 'lessThan',
105
107
  }
106
108
 
107
109
  export type SegmentationRuleFn = (
package/src/util.ts CHANGED
@@ -140,6 +140,14 @@ export const segmentationRuleMap: Record<SegmentationRuleOperator, SegmentationR
140
140
  // Anything else cannot be true
141
141
  return keyValue?.toString() !== 'true'
142
142
  },
143
+ [SegmentationRuleOperator.GreaterThan](keyValue, ruleValue) {
144
+ if (keyValue === null || keyValue === undefined) return false
145
+ return keyValue > ruleValue
146
+ },
147
+ [SegmentationRuleOperator.LessThan](keyValue, ruleValue) {
148
+ if (keyValue === null || keyValue === undefined) return false
149
+ return keyValue < ruleValue
150
+ },
143
151
  }
144
152
 
145
153
  /**
@@ -1,54 +0,0 @@
1
- -- CreateTable
2
- CREATE TABLE IF NOT EXISTS `Bucket` (
3
- `id` VARCHAR(50) NOT NULL,
4
- `experimentId` VARCHAR(50) NOT NULL,
5
- `key` VARCHAR(10) NOT NULL,
6
- `ratio` INTEGER NOT NULL,
7
- `data` JSON NULL,
8
- `created` INT NOT NULL,
9
- `updated` INT NOT NULL,
10
-
11
- PRIMARY KEY (`id`)
12
- ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
13
-
14
- -- CreateTable
15
- CREATE TABLE IF NOT EXISTS `Experiment` (
16
- `id` VARCHAR(50) NOT NULL,
17
- `key` VARCHAR(50) NOT NULL,
18
- `status` INTEGER NOT NULL,
19
- `sampling` INTEGER NOT NULL,
20
- `description` VARCHAR(240) NULL,
21
- `startDateIncl` DATE NOT NULL,
22
- `endDateExcl` DATE NOT NULL,
23
- `created` INT NOT NULL,
24
- `updated` INT NOT NULL,
25
- `rules` JSON NULL,
26
- `exclusions` JSON NULL,
27
- `data` JSON NULL,
28
- `deleted` BOOLEAN NOT NULL DEFAULT FALSE,
29
-
30
- PRIMARY KEY (`id`),
31
- UNIQUE INDEX `key_unique` (`key`)
32
- ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
33
-
34
- -- CreateTable
35
- CREATE TABLE IF NOT EXISTS `UserAssignment` (
36
- `id` VARCHAR(50) NOT NULL,
37
- `userId` VARCHAR(191) NOT NULL,
38
- `experimentId` VARCHAR(50) NOT NULL,
39
- `bucketId` VARCHAR(50) NULL,
40
- `created` INT NOT NULL,
41
- `updated` INT NOT NULL,
42
-
43
- UNIQUE INDEX `UserAssignment_userId_experimentId_key`(`userId`, `experimentId`),
44
- PRIMARY KEY (`id`)
45
- ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
46
-
47
- -- AddForeignKey
48
- ALTER TABLE `Bucket` ADD CONSTRAINT `Bucket_experimentId_fkey` FOREIGN KEY (`experimentId`) REFERENCES `Experiment`(`id`);
49
-
50
- -- AddForeignKey
51
- ALTER TABLE `UserAssignment` ADD CONSTRAINT `UserAssignment_bucketId_fkey` FOREIGN KEY (`bucketId`) REFERENCES `Bucket`(`id`);
52
-
53
- -- AddForeignKey
54
- ALTER TABLE `UserAssignment` ADD CONSTRAINT `UserAssignment_experimentId_fkey` FOREIGN KEY (`experimentId`) REFERENCES `Experiment`(`id`);