@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/src/util.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
+
import { Saved } from '@naturalcycles/js-lib'
|
|
1
2
|
import { satisfies } from 'semver'
|
|
2
|
-
import { Bucket } from './
|
|
3
|
-
import { BucketInput, SegmentationData, SegmentationRule } from '.'
|
|
3
|
+
import { Bucket, SegmentationData, SegmentationRule } from './types'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Generate a random number between 0 and 100
|
|
7
|
-
*
|
|
8
|
-
* @returns
|
|
9
7
|
*/
|
|
10
8
|
export const rollDie = (): number => {
|
|
11
9
|
return Math.random() * 100
|
|
@@ -13,12 +11,8 @@ export const rollDie = (): number => {
|
|
|
13
11
|
|
|
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
|
-
export const determineAssignment = (sampling: number, buckets: Bucket[]): number | null => {
|
|
15
|
+
export const determineAssignment = (sampling: number, buckets: Saved<Bucket>[]): number | null => {
|
|
22
16
|
// Should this person be considered for the experiment?
|
|
23
17
|
if (rollDie() > sampling) {
|
|
24
18
|
return null
|
|
@@ -30,11 +24,8 @@ export const determineAssignment = (sampling: number, buckets: Bucket[]): number
|
|
|
30
24
|
|
|
31
25
|
/**
|
|
32
26
|
* Determines which bucket a user assignment will recieve
|
|
33
|
-
*
|
|
34
|
-
* @param buckets
|
|
35
|
-
* @returns
|
|
36
27
|
*/
|
|
37
|
-
export const determineBucket = (buckets: Bucket[]): number => {
|
|
28
|
+
export const determineBucket = (buckets: Saved<Bucket>[]): number => {
|
|
38
29
|
const bucketRoll = rollDie()
|
|
39
30
|
let range: [number, number] | undefined
|
|
40
31
|
const bucket = buckets.find(b => {
|
|
@@ -58,11 +49,8 @@ export const determineBucket = (buckets: Bucket[]): number => {
|
|
|
58
49
|
|
|
59
50
|
/**
|
|
60
51
|
* Validate the total ratio of the buckets equals 100
|
|
61
|
-
*
|
|
62
|
-
* @param buckets
|
|
63
|
-
* @returns
|
|
64
52
|
*/
|
|
65
|
-
export const validateTotalBucketRatio = (buckets:
|
|
53
|
+
export const validateTotalBucketRatio = (buckets: Bucket[]): void => {
|
|
66
54
|
const bucketSum = buckets.reduce((sum, current) => sum + current.ratio, 0)
|
|
67
55
|
if (bucketSum !== 100) {
|
|
68
56
|
throw new Error('Total bucket ratio must be 100 before you can activate an experiment')
|
|
@@ -88,10 +76,6 @@ export const validateSegmentationRules = (
|
|
|
88
76
|
|
|
89
77
|
/**
|
|
90
78
|
* Validate a users segmentation data against a single rule
|
|
91
|
-
*
|
|
92
|
-
* @param rule
|
|
93
|
-
* @param segmentationData
|
|
94
|
-
* @returns
|
|
95
79
|
*/
|
|
96
80
|
export const validateSegmentationRule = (
|
|
97
81
|
rule: SegmentationRule,
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
2
|
-
|
|
3
|
-
const { Decimal } = require('./runtime/index-browser')
|
|
4
|
-
|
|
5
|
-
const Prisma = {}
|
|
6
|
-
|
|
7
|
-
exports.Prisma = Prisma
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Prisma Client JS version: 3.13.0
|
|
11
|
-
* Query Engine version: efdf9b1183dddfd4258cd181a72125755215ab7b
|
|
12
|
-
*/
|
|
13
|
-
Prisma.prismaVersion = {
|
|
14
|
-
client: '3.13.0',
|
|
15
|
-
engine: 'efdf9b1183dddfd4258cd181a72125755215ab7b',
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
Prisma.PrismaClientKnownRequestError = () => {
|
|
19
|
-
throw new Error(`PrismaClientKnownRequestError is unable to be run in the browser.
|
|
20
|
-
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`)
|
|
21
|
-
}
|
|
22
|
-
Prisma.PrismaClientUnknownRequestError = () => {
|
|
23
|
-
throw new Error(`PrismaClientUnknownRequestError is unable to be run in the browser.
|
|
24
|
-
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`)
|
|
25
|
-
}
|
|
26
|
-
Prisma.PrismaClientRustPanicError = () => {
|
|
27
|
-
throw new Error(`PrismaClientRustPanicError is unable to be run in the browser.
|
|
28
|
-
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`)
|
|
29
|
-
}
|
|
30
|
-
Prisma.PrismaClientInitializationError = () => {
|
|
31
|
-
throw new Error(`PrismaClientInitializationError is unable to be run in the browser.
|
|
32
|
-
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`)
|
|
33
|
-
}
|
|
34
|
-
Prisma.PrismaClientValidationError = () => {
|
|
35
|
-
throw new Error(`PrismaClientValidationError is unable to be run in the browser.
|
|
36
|
-
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`)
|
|
37
|
-
}
|
|
38
|
-
Prisma.Decimal = Decimal
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Re-export of sql-template-tag
|
|
42
|
-
*/
|
|
43
|
-
Prisma.sql = () => {
|
|
44
|
-
throw new Error(`sqltag is unable to be run in the browser.
|
|
45
|
-
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`)
|
|
46
|
-
}
|
|
47
|
-
Prisma.empty = () => {
|
|
48
|
-
throw new Error(`empty is unable to be run in the browser.
|
|
49
|
-
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`)
|
|
50
|
-
}
|
|
51
|
-
Prisma.join = () => {
|
|
52
|
-
throw new Error(`join is unable to be run in the browser.
|
|
53
|
-
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`)
|
|
54
|
-
}
|
|
55
|
-
Prisma.raw = () => {
|
|
56
|
-
throw new Error(`raw is unable to be run in the browser.
|
|
57
|
-
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`)
|
|
58
|
-
}
|
|
59
|
-
Prisma.validator = () => val => val
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Shorthand utilities for JSON filtering
|
|
63
|
-
*/
|
|
64
|
-
Prisma.DbNull = 'DbNull'
|
|
65
|
-
Prisma.JsonNull = 'JsonNull'
|
|
66
|
-
Prisma.AnyNull = 'AnyNull'
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Enums
|
|
70
|
-
*/
|
|
71
|
-
// Based on
|
|
72
|
-
// https://github.com/microsoft/TypeScript/issues/3192#issuecomment-261720275
|
|
73
|
-
function makeEnum(x) {
|
|
74
|
-
return x
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
exports.Prisma.BucketScalarFieldEnum = makeEnum({
|
|
78
|
-
id: 'id',
|
|
79
|
-
experimentId: 'experimentId',
|
|
80
|
-
key: 'key',
|
|
81
|
-
ratio: 'ratio',
|
|
82
|
-
createdAt: 'createdAt',
|
|
83
|
-
updatedAt: 'updatedAt',
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
exports.Prisma.ExperimentScalarFieldEnum = makeEnum({
|
|
87
|
-
id: 'id',
|
|
88
|
-
name: 'name',
|
|
89
|
-
status: 'status',
|
|
90
|
-
sampling: 'sampling',
|
|
91
|
-
createdAt: 'createdAt',
|
|
92
|
-
updatedAt: 'updatedAt',
|
|
93
|
-
description: 'description',
|
|
94
|
-
rules: 'rules',
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
exports.Prisma.UserAssignmentScalarFieldEnum = makeEnum({
|
|
98
|
-
id: 'id',
|
|
99
|
-
userId: 'userId',
|
|
100
|
-
experimentId: 'experimentId',
|
|
101
|
-
bucketId: 'bucketId',
|
|
102
|
-
createdAt: 'createdAt',
|
|
103
|
-
updatedAt: 'updatedAt',
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
exports.Prisma.SortOrder = makeEnum({
|
|
107
|
-
asc: 'asc',
|
|
108
|
-
desc: 'desc',
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
exports.Prisma.NullableJsonNullValueInput = makeEnum({
|
|
112
|
-
DbNull: 'DbNull',
|
|
113
|
-
JsonNull: 'JsonNull',
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
exports.Prisma.JsonNullValueFilter = makeEnum({
|
|
117
|
-
DbNull: 'DbNull',
|
|
118
|
-
JsonNull: 'JsonNull',
|
|
119
|
-
AnyNull: 'AnyNull',
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
exports.Prisma.ModelName = makeEnum({
|
|
123
|
-
Bucket: 'Bucket',
|
|
124
|
-
Experiment: 'Experiment',
|
|
125
|
-
UserAssignment: 'UserAssignment',
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Create the Client
|
|
130
|
-
*/
|
|
131
|
-
class PrismaClient {
|
|
132
|
-
constructor() {
|
|
133
|
-
throw new Error(
|
|
134
|
-
`PrismaClient is unable to be run in the browser.
|
|
135
|
-
In case this error is unexpected for you, please report it in https://github.com/prisma/prisma/issues`,
|
|
136
|
-
)
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
exports.PrismaClient = PrismaClient
|
|
140
|
-
|
|
141
|
-
Object.assign(exports, Prisma)
|