@naturalcycles/abba 1.7.0 → 1.9.1
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 +45 -72
- package/dist/abba.js +119 -165
- package/dist/dao/bucket.dao.d.ts +5 -0
- package/dist/dao/bucket.dao.js +15 -0
- package/dist/dao/experiment.dao.d.ts +10 -0
- package/dist/dao/experiment.dao.js +19 -0
- package/dist/dao/userAssignment.dao.d.ts +5 -0
- package/dist/dao/userAssignment.dao.js +15 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -1
- package/dist/migrations/init.sql +47 -0
- package/dist/types.d.ts +30 -7
- package/dist/util.d.ts +5 -21
- package/dist/util.js +0 -16
- package/package.json +9 -9
- package/readme.md +14 -15
- package/src/abba.ts +160 -191
- package/src/dao/bucket.dao.ts +13 -0
- package/src/dao/experiment.dao.ts +22 -0
- package/src/dao/userAssignment.dao.ts +13 -0
- package/src/index.ts +0 -3
- package/src/migrations/init.sql +47 -0
- package/src/types.ts +41 -7
- package/src/util.ts +5 -21
- package/dist/prisma-output/index-browser.js +0 -141
- package/dist/prisma-output/index.d.ts +0 -5526
- package/dist/prisma-output/index.js +0 -217
- package/dist/prisma-output/libquery_engine-darwin-arm64.dylib.node +0 -0
- package/dist/prisma-output/libquery_engine-darwin.dylib.node +0 -0
- package/dist/prisma-output/libquery_engine-debian-openssl-1.1.x.so.node +0 -0
- package/dist/prisma-output/libquery_engine-debian-openssl-3.0.x.so.node +0 -0
- package/dist/prisma-output/runtime/esm/index-browser.mjs +0 -2370
- package/dist/prisma-output/runtime/esm/index.mjs +0 -40587
- package/dist/prisma-output/runtime/esm/proxy.mjs +0 -113
- package/dist/prisma-output/runtime/index-browser.d.ts +0 -269
- package/dist/prisma-output/runtime/index-browser.js +0 -2621
- package/dist/prisma-output/runtime/index.d.ts +0 -1384
- package/dist/prisma-output/runtime/index.js +0 -59183
- package/dist/prisma-output/runtime/proxy.d.ts +0 -1384
- package/dist/prisma-output/runtime/proxy.js +0 -13576
- package/dist/prisma-output/schema.prisma +0 -47
- package/src/prisma-output/index-browser.js +0 -141
- package/src/prisma-output/index.d.ts +0 -5526
- package/src/prisma-output/index.js +0 -217
- package/src/prisma-output/libquery_engine-darwin-arm64.dylib.node +0 -0
- package/src/prisma-output/libquery_engine-darwin.dylib.node +0 -0
- package/src/prisma-output/libquery_engine-debian-openssl-1.1.x.so.node +0 -0
- package/src/prisma-output/libquery_engine-debian-openssl-3.0.x.so.node +0 -0
- package/src/prisma-output/runtime/esm/index-browser.mjs +0 -2370
- package/src/prisma-output/runtime/esm/index.mjs +0 -40587
- package/src/prisma-output/runtime/esm/proxy.mjs +0 -113
- package/src/prisma-output/runtime/index-browser.d.ts +0 -269
- package/src/prisma-output/runtime/index-browser.js +0 -2621
- package/src/prisma-output/runtime/index.d.ts +0 -1384
- package/src/prisma-output/runtime/index.js +0 -59183
- package/src/prisma-output/runtime/proxy.d.ts +0 -1384
- package/src/prisma-output/runtime/proxy.js +0 -13576
- package/src/prisma-output/schema.prisma +0 -47
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { CommonDB } from '@naturalcycles/db-lib';
|
|
2
|
+
import { BaseDBEntity, Saved } from '@naturalcycles/js-lib';
|
|
3
|
+
export interface AbbaConfig {
|
|
4
|
+
db: CommonDB;
|
|
5
|
+
}
|
|
6
|
+
export declare type BaseExperiment = BaseDBEntity<number> & {
|
|
7
|
+
name: string;
|
|
8
|
+
status: number;
|
|
9
|
+
sampling: number;
|
|
10
|
+
description: string | null;
|
|
11
|
+
};
|
|
12
|
+
export declare type Experiment = BaseExperiment & {
|
|
13
|
+
rules: SegmentationRule[];
|
|
14
|
+
};
|
|
15
|
+
export declare type ExperimentWithBuckets = Saved<Experiment> & {
|
|
16
|
+
buckets: Saved<Bucket>[];
|
|
17
|
+
};
|
|
18
|
+
export interface BucketInput {
|
|
19
|
+
experimentId: number;
|
|
20
|
+
key: string;
|
|
21
|
+
ratio: number;
|
|
22
|
+
}
|
|
23
|
+
export declare type Bucket = BaseDBEntity<number> & {
|
|
24
|
+
experimentId: number;
|
|
25
|
+
key: string;
|
|
26
|
+
ratio: number;
|
|
4
27
|
};
|
|
5
|
-
export declare type
|
|
6
|
-
|
|
28
|
+
export declare type UserAssignment = BaseDBEntity<number> & {
|
|
29
|
+
userId: string;
|
|
30
|
+
experimentId: number;
|
|
31
|
+
bucketId: number | null;
|
|
7
32
|
};
|
|
8
|
-
export declare type ExperimentInput = Unsaved<Experiment>;
|
|
9
|
-
export declare type BucketInput = Unsaved<Bucket>;
|
|
10
33
|
export declare type SegmentationData = Record<string, string | boolean | number>;
|
|
11
34
|
export declare enum AssignmentStatus {
|
|
12
35
|
Active = 1,
|
package/dist/util.d.ts
CHANGED
|
@@ -1,33 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Saved } from '@naturalcycles/js-lib';
|
|
2
|
+
import { Bucket, SegmentationData, SegmentationRule } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Generate a random number between 0 and 100
|
|
5
|
-
*
|
|
6
|
-
* @returns
|
|
7
5
|
*/
|
|
8
6
|
export declare const rollDie: () => number;
|
|
9
7
|
/**
|
|
10
8
|
* Determines a users assignment for this experiment. Returns null if they are not considered to be in the sampling group
|
|
11
|
-
*
|
|
12
|
-
* @param sampling
|
|
13
|
-
* @param buckets
|
|
14
|
-
* @returns
|
|
15
9
|
*/
|
|
16
|
-
export declare const determineAssignment: (sampling: number, buckets: Bucket[]) => number | null;
|
|
10
|
+
export declare const determineAssignment: (sampling: number, buckets: Saved<Bucket>[]) => number | null;
|
|
17
11
|
/**
|
|
18
12
|
* Determines which bucket a user assignment will recieve
|
|
19
|
-
*
|
|
20
|
-
* @param buckets
|
|
21
|
-
* @returns
|
|
22
13
|
*/
|
|
23
|
-
export declare const determineBucket: (buckets: Bucket[]) => number;
|
|
14
|
+
export declare const determineBucket: (buckets: Saved<Bucket>[]) => number;
|
|
24
15
|
/**
|
|
25
16
|
* Validate the total ratio of the buckets equals 100
|
|
26
|
-
*
|
|
27
|
-
* @param buckets
|
|
28
|
-
* @returns
|
|
29
17
|
*/
|
|
30
|
-
export declare const validateTotalBucketRatio: (buckets:
|
|
18
|
+
export declare const validateTotalBucketRatio: (buckets: Bucket[]) => void;
|
|
31
19
|
/**
|
|
32
20
|
* Validate a users segmentation data against multiple rules. Returns false if any fail
|
|
33
21
|
*
|
|
@@ -38,9 +26,5 @@ export declare const validateTotalBucketRatio: (buckets: BucketInput[]) => void;
|
|
|
38
26
|
export declare const validateSegmentationRules: (rules: SegmentationRule[], segmentationData: SegmentationData) => boolean;
|
|
39
27
|
/**
|
|
40
28
|
* Validate a users segmentation data against a single rule
|
|
41
|
-
*
|
|
42
|
-
* @param rule
|
|
43
|
-
* @param segmentationData
|
|
44
|
-
* @returns
|
|
45
29
|
*/
|
|
46
30
|
export declare const validateSegmentationRule: (rule: SegmentationRule, data: SegmentationData) => boolean;
|
package/dist/util.js
CHANGED
|
@@ -4,8 +4,6 @@ exports.validateSegmentationRule = exports.validateSegmentationRules = exports.v
|
|
|
4
4
|
const semver_1 = require("semver");
|
|
5
5
|
/**
|
|
6
6
|
* Generate a random number between 0 and 100
|
|
7
|
-
*
|
|
8
|
-
* @returns
|
|
9
7
|
*/
|
|
10
8
|
const rollDie = () => {
|
|
11
9
|
return Math.random() * 100;
|
|
@@ -13,10 +11,6 @@ const rollDie = () => {
|
|
|
13
11
|
exports.rollDie = rollDie;
|
|
14
12
|
/**
|
|
15
13
|
* Determines a users assignment for this experiment. Returns null if they are not considered to be in the sampling group
|
|
16
|
-
*
|
|
17
|
-
* @param sampling
|
|
18
|
-
* @param buckets
|
|
19
|
-
* @returns
|
|
20
14
|
*/
|
|
21
15
|
const determineAssignment = (sampling, buckets) => {
|
|
22
16
|
// Should this person be considered for the experiment?
|
|
@@ -29,9 +23,6 @@ const determineAssignment = (sampling, buckets) => {
|
|
|
29
23
|
exports.determineAssignment = determineAssignment;
|
|
30
24
|
/**
|
|
31
25
|
* Determines which bucket a user assignment will recieve
|
|
32
|
-
*
|
|
33
|
-
* @param buckets
|
|
34
|
-
* @returns
|
|
35
26
|
*/
|
|
36
27
|
const determineBucket = (buckets) => {
|
|
37
28
|
const bucketRoll = (0, exports.rollDie)();
|
|
@@ -55,9 +46,6 @@ const determineBucket = (buckets) => {
|
|
|
55
46
|
exports.determineBucket = determineBucket;
|
|
56
47
|
/**
|
|
57
48
|
* Validate the total ratio of the buckets equals 100
|
|
58
|
-
*
|
|
59
|
-
* @param buckets
|
|
60
|
-
* @returns
|
|
61
49
|
*/
|
|
62
50
|
const validateTotalBucketRatio = (buckets) => {
|
|
63
51
|
const bucketSum = buckets.reduce((sum, current) => sum + current.ratio, 0);
|
|
@@ -83,10 +71,6 @@ const validateSegmentationRules = (rules, segmentationData) => {
|
|
|
83
71
|
exports.validateSegmentationRules = validateSegmentationRules;
|
|
84
72
|
/**
|
|
85
73
|
* Validate a users segmentation data against a single rule
|
|
86
|
-
*
|
|
87
|
-
* @param rule
|
|
88
|
-
* @param segmentationData
|
|
89
|
-
* @returns
|
|
90
74
|
*/
|
|
91
75
|
const validateSegmentationRule = (rule, data) => {
|
|
92
76
|
const { key, value, operator } = rule;
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/abba",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
|
-
"build": "build
|
|
7
|
-
"build-prod": "build-prod
|
|
8
|
-
"copy-prisma-output": "cp -R src/prisma-output dist"
|
|
6
|
+
"build": "build",
|
|
7
|
+
"build-prod": "build-prod"
|
|
9
8
|
},
|
|
10
9
|
"dependencies": {
|
|
11
|
-
"@
|
|
10
|
+
"@naturalcycles/db-lib": "^8.40.1",
|
|
11
|
+
"@naturalcycles/js-lib": "^14.98.2",
|
|
12
|
+
"@naturalcycles/nodejs-lib": "^12.70.1",
|
|
12
13
|
"semver": "^7.3.5"
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {
|
|
15
|
-
"@naturalcycles/dev-lib": "^12.
|
|
16
|
-
"@types/node": "^
|
|
16
|
+
"@naturalcycles/dev-lib": "^12.19.2",
|
|
17
|
+
"@types/node": "^17.0.34",
|
|
17
18
|
"@types/semver": "^7.3.9",
|
|
18
|
-
"jest": "^
|
|
19
|
-
"prisma": "^3.13.0"
|
|
19
|
+
"jest": "^28.1.0"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"dist",
|
package/readme.md
CHANGED
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
|
|
45
45
|
### Built With
|
|
46
46
|
|
|
47
|
-
- [
|
|
47
|
+
- [@naturalcycles/db-lib](https://github.com/NaturalCycles/db-lib)
|
|
48
48
|
|
|
49
49
|
<p align="right">(<a href="#top">back to top</a>)</p>
|
|
50
50
|
|
|
@@ -77,9 +77,8 @@ This template doesn't rely on any external dependencies or services._
|
|
|
77
77
|
npm install @naturalcyles/abba
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
2.
|
|
81
|
-
[
|
|
82
|
-
to generate the required DB Schema
|
|
80
|
+
2. Install the schema into your MySQL db instance using the migration script found
|
|
81
|
+
[here](https://github.com/NaturalCycles/abba/blob/master/src/migrations/init.sql).
|
|
83
82
|
|
|
84
83
|
<p align="right">(<a href="#top">back to top</a>)</p>
|
|
85
84
|
|
|
@@ -91,14 +90,14 @@ This template doesn't rely on any external dependencies or services._
|
|
|
91
90
|
|
|
92
91
|
### Create an instance of Abba
|
|
93
92
|
|
|
94
|
-
|
|
95
|
-
exist it will fallback to trying to use the `ABBA_DB_URL` which must be added to your environment
|
|
96
|
-
variables.
|
|
93
|
+
(Currently supports MySQL, probably all DocumentDBs but not verified.)
|
|
97
94
|
|
|
98
95
|
```js
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
type AbbaConfig = {
|
|
97
|
+
db: CommonDB // from @naturalcycles/db-lib
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const abba = new Abba(config: AbbaConfig)
|
|
102
101
|
```
|
|
103
102
|
|
|
104
103
|
### Create a new experiment
|
|
@@ -109,7 +108,7 @@ Creates a new experiment
|
|
|
109
108
|
async createExperiment(
|
|
110
109
|
input: ExperimentInput,
|
|
111
110
|
buckets: BucketInput[]
|
|
112
|
-
): Promise<Experiment
|
|
111
|
+
): Promise<Saved<Experiment>>
|
|
113
112
|
```
|
|
114
113
|
|
|
115
114
|
### Update an experiment
|
|
@@ -121,7 +120,7 @@ async updateExperiment(
|
|
|
121
120
|
id: number,
|
|
122
121
|
input: ExperimentInput,
|
|
123
122
|
buckets: BucketInput[]
|
|
124
|
-
): Promise<Experiment
|
|
123
|
+
): Promise<Saved<Experiment>>
|
|
125
124
|
```
|
|
126
125
|
|
|
127
126
|
### Delete an experiment
|
|
@@ -141,7 +140,7 @@ Gets all existing user assignments
|
|
|
141
140
|
```js
|
|
142
141
|
async getAllExistingUserAssignments(
|
|
143
142
|
userId: string
|
|
144
|
-
): Promise<UserAssignment[]>
|
|
143
|
+
): Promise<Saved<UserAssignment>[]>
|
|
145
144
|
```
|
|
146
145
|
|
|
147
146
|
### Get a users assignment
|
|
@@ -155,7 +154,7 @@ async getUserAssignment(
|
|
|
155
154
|
userId: string,
|
|
156
155
|
existingOnly: boolean,
|
|
157
156
|
segmentationData?: SegmentationData,
|
|
158
|
-
): Promise<UserAssignment | null>
|
|
157
|
+
): Promise<Saved<UserAssignment> | null>
|
|
159
158
|
```
|
|
160
159
|
|
|
161
160
|
### Generate user assignments
|
|
@@ -167,7 +166,7 @@ attempt to generate new assignments.
|
|
|
167
166
|
async generateUserAssignments(
|
|
168
167
|
userId: string,
|
|
169
168
|
segmentationData: SegmentationData,
|
|
170
|
-
): Promise<UserAssignment[]>
|
|
169
|
+
): Promise<Saved<UserAssignment>[]>
|
|
171
170
|
```
|
|
172
171
|
|
|
173
172
|
### Getting assignment statistics
|