@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.
Files changed (58) hide show
  1. package/dist/abba.d.ts +45 -72
  2. package/dist/abba.js +119 -165
  3. package/dist/dao/bucket.dao.d.ts +5 -0
  4. package/dist/dao/bucket.dao.js +15 -0
  5. package/dist/dao/experiment.dao.d.ts +10 -0
  6. package/dist/dao/experiment.dao.js +19 -0
  7. package/dist/dao/userAssignment.dao.d.ts +5 -0
  8. package/dist/dao/userAssignment.dao.js +15 -0
  9. package/dist/index.d.ts +0 -1
  10. package/dist/index.js +1 -1
  11. package/dist/migrations/init.sql +47 -0
  12. package/dist/types.d.ts +30 -7
  13. package/dist/util.d.ts +5 -21
  14. package/dist/util.js +0 -16
  15. package/package.json +9 -9
  16. package/readme.md +14 -15
  17. package/src/abba.ts +160 -191
  18. package/src/dao/bucket.dao.ts +13 -0
  19. package/src/dao/experiment.dao.ts +22 -0
  20. package/src/dao/userAssignment.dao.ts +13 -0
  21. package/src/index.ts +0 -3
  22. package/src/migrations/init.sql +47 -0
  23. package/src/types.ts +41 -7
  24. package/src/util.ts +5 -21
  25. package/dist/prisma-output/index-browser.js +0 -141
  26. package/dist/prisma-output/index.d.ts +0 -5526
  27. package/dist/prisma-output/index.js +0 -217
  28. package/dist/prisma-output/libquery_engine-darwin-arm64.dylib.node +0 -0
  29. package/dist/prisma-output/libquery_engine-darwin.dylib.node +0 -0
  30. package/dist/prisma-output/libquery_engine-debian-openssl-1.1.x.so.node +0 -0
  31. package/dist/prisma-output/libquery_engine-debian-openssl-3.0.x.so.node +0 -0
  32. package/dist/prisma-output/runtime/esm/index-browser.mjs +0 -2370
  33. package/dist/prisma-output/runtime/esm/index.mjs +0 -40587
  34. package/dist/prisma-output/runtime/esm/proxy.mjs +0 -113
  35. package/dist/prisma-output/runtime/index-browser.d.ts +0 -269
  36. package/dist/prisma-output/runtime/index-browser.js +0 -2621
  37. package/dist/prisma-output/runtime/index.d.ts +0 -1384
  38. package/dist/prisma-output/runtime/index.js +0 -59183
  39. package/dist/prisma-output/runtime/proxy.d.ts +0 -1384
  40. package/dist/prisma-output/runtime/proxy.js +0 -13576
  41. package/dist/prisma-output/schema.prisma +0 -47
  42. package/src/prisma-output/index-browser.js +0 -141
  43. package/src/prisma-output/index.d.ts +0 -5526
  44. package/src/prisma-output/index.js +0 -217
  45. package/src/prisma-output/libquery_engine-darwin-arm64.dylib.node +0 -0
  46. package/src/prisma-output/libquery_engine-darwin.dylib.node +0 -0
  47. package/src/prisma-output/libquery_engine-debian-openssl-1.1.x.so.node +0 -0
  48. package/src/prisma-output/libquery_engine-debian-openssl-3.0.x.so.node +0 -0
  49. package/src/prisma-output/runtime/esm/index-browser.mjs +0 -2370
  50. package/src/prisma-output/runtime/esm/index.mjs +0 -40587
  51. package/src/prisma-output/runtime/esm/proxy.mjs +0 -113
  52. package/src/prisma-output/runtime/index-browser.d.ts +0 -269
  53. package/src/prisma-output/runtime/index-browser.js +0 -2621
  54. package/src/prisma-output/runtime/index.d.ts +0 -1384
  55. package/src/prisma-output/runtime/index.js +0 -59183
  56. package/src/prisma-output/runtime/proxy.d.ts +0 -1384
  57. package/src/prisma-output/runtime/proxy.js +0 -13576
  58. 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 './prisma-output'
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: BucketInput[]): void => {
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)