@naturalcycles/abba 1.23.0 → 1.24.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.
@@ -1,5 +1,10 @@
1
1
  import { CommonDao, CommonDB } from '@naturalcycles/db-lib';
2
- import { Bucket } from '../types';
3
- export declare class BucketDao extends CommonDao<Bucket> {
2
+ import { Saved } from '@naturalcycles/js-lib';
3
+ import { BaseBucket, Bucket } from '../types';
4
+ type BucketDBM = Saved<BaseBucket> & {
5
+ data: string | null;
6
+ };
7
+ export declare class BucketDao extends CommonDao<Bucket, BucketDBM> {
4
8
  }
5
9
  export declare const bucketDao: (db: CommonDB) => BucketDao;
10
+ export {};
@@ -8,5 +8,17 @@ exports.BucketDao = BucketDao;
8
8
  const bucketDao = (db) => new BucketDao({
9
9
  db,
10
10
  table: 'Bucket',
11
+ hooks: {
12
+ beforeBMToDBM: bm => {
13
+ return {
14
+ ...bm,
15
+ data: bm.data ? JSON.stringify(bm.data) : null,
16
+ };
17
+ },
18
+ beforeDBMToBM: dbm => ({
19
+ ...dbm,
20
+ data: dbm.data ? JSON.parse(dbm.data) : null,
21
+ }),
22
+ },
11
23
  });
12
24
  exports.bucketDao = bucketDao;
@@ -4,6 +4,7 @@ import { BaseExperiment, Experiment } from '../types';
4
4
  type ExperimentDBM = Saved<BaseExperiment> & {
5
5
  rules: string | null;
6
6
  exclusions: string | null;
7
+ data: string | null;
7
8
  };
8
9
  export declare class ExperimentDao extends CommonDao<Experiment, ExperimentDBM> {
9
10
  }
@@ -18,6 +18,7 @@ const experimentDao = (db) => new ExperimentDao({
18
18
  exclusions: bm.exclusions.length
19
19
  ? JSON.stringify(bm.exclusions.map(exclusion => exclusion.toString()))
20
20
  : null,
21
+ data: bm.data ? JSON.stringify(bm.data) : null,
21
22
  }),
22
23
  beforeDBMToBM: dbm => ({
23
24
  ...dbm,
@@ -29,6 +30,7 @@ const experimentDao = (db) => new ExperimentDao({
29
30
  exclusions: (dbm.exclusions &&
30
31
  JSON.parse(dbm.exclusions).map((exclusion) => exclusion.toString())) ||
31
32
  [],
33
+ data: dbm.data ? JSON.parse(dbm.data) : null,
32
34
  }),
33
35
  },
34
36
  });
@@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS `Experiment` (
24
24
  `updated` INT NOT NULL,
25
25
  `rules` JSON NULL,
26
26
  `exclusions` JSON NULL,
27
+ `data` JSON NULL,
27
28
 
28
29
  PRIMARY KEY (`id`),
29
30
  UNIQUE INDEX `key_unique` (`key`)
package/dist/types.d.ts CHANGED
@@ -33,14 +33,17 @@ export type BaseExperiment = BaseDBEntity & {
33
33
  export type Experiment = BaseExperiment & {
34
34
  rules: SegmentationRule[];
35
35
  exclusions: string[];
36
+ data: AnyObject | null;
36
37
  };
37
38
  export type ExperimentWithBuckets = Saved<Experiment> & {
38
39
  buckets: Saved<Bucket>[];
39
40
  };
40
- export type Bucket = BaseDBEntity & {
41
+ export type BaseBucket = BaseDBEntity & {
41
42
  experimentId: string;
42
43
  key: string;
43
44
  ratio: number;
45
+ };
46
+ export type Bucket = BaseBucket & {
44
47
  data: AnyObject | null;
45
48
  };
46
49
  export type UserAssignment = BaseDBEntity & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/abba",
3
- "version": "1.23.0",
3
+ "version": "1.24.0",
4
4
  "scripts": {
5
5
  "prepare": "husky"
6
6
  },
@@ -1,10 +1,27 @@
1
1
  import { CommonDao, CommonDB } from '@naturalcycles/db-lib'
2
- import { Bucket } from '../types'
2
+ import { Saved } from '@naturalcycles/js-lib'
3
+ import { BaseBucket, Bucket } from '../types'
3
4
 
4
- export class BucketDao extends CommonDao<Bucket> {}
5
+ type BucketDBM = Saved<BaseBucket> & {
6
+ data: string | null
7
+ }
8
+
9
+ export class BucketDao extends CommonDao<Bucket, BucketDBM> {}
5
10
 
6
11
  export const bucketDao = (db: CommonDB): BucketDao =>
7
12
  new BucketDao({
8
13
  db,
9
14
  table: 'Bucket',
15
+ hooks: {
16
+ beforeBMToDBM: bm => {
17
+ return {
18
+ ...bm,
19
+ data: bm.data ? JSON.stringify(bm.data) : null,
20
+ }
21
+ },
22
+ beforeDBMToBM: dbm => ({
23
+ ...dbm,
24
+ data: dbm.data ? JSON.parse(dbm.data) : null,
25
+ }),
26
+ },
10
27
  })
@@ -5,6 +5,7 @@ import { BaseExperiment, Experiment } from '../types'
5
5
  type ExperimentDBM = Saved<BaseExperiment> & {
6
6
  rules: string | null
7
7
  exclusions: string | null
8
+ data: string | null
8
9
  }
9
10
 
10
11
  export class ExperimentDao extends CommonDao<Experiment, ExperimentDBM> {}
@@ -22,6 +23,7 @@ export const experimentDao = (db: CommonDB): ExperimentDao =>
22
23
  exclusions: bm.exclusions.length
23
24
  ? JSON.stringify(bm.exclusions.map(exclusion => exclusion.toString()))
24
25
  : null,
26
+ data: bm.data ? JSON.stringify(bm.data) : null,
25
27
  }),
26
28
  beforeDBMToBM: dbm => ({
27
29
  ...dbm,
@@ -34,6 +36,7 @@ export const experimentDao = (db: CommonDB): ExperimentDao =>
34
36
  (dbm.exclusions &&
35
37
  JSON.parse(dbm.exclusions).map((exclusion: string | number) => exclusion.toString())) ||
36
38
  [],
39
+ data: dbm.data ? JSON.parse(dbm.data) : null,
37
40
  }),
38
41
  },
39
42
  })
@@ -24,6 +24,7 @@ CREATE TABLE IF NOT EXISTS `Experiment` (
24
24
  `updated` INT NOT NULL,
25
25
  `rules` JSON NULL,
26
26
  `exclusions` JSON NULL,
27
+ `data` JSON NULL,
27
28
 
28
29
  PRIMARY KEY (`id`),
29
30
  UNIQUE INDEX `key_unique` (`key`)
package/src/types.ts CHANGED
@@ -36,16 +36,20 @@ export type BaseExperiment = BaseDBEntity & {
36
36
  export type Experiment = BaseExperiment & {
37
37
  rules: SegmentationRule[]
38
38
  exclusions: string[]
39
+ data: AnyObject | null
39
40
  }
40
41
 
41
42
  export type ExperimentWithBuckets = Saved<Experiment> & {
42
43
  buckets: Saved<Bucket>[]
43
44
  }
44
45
 
45
- export type Bucket = BaseDBEntity & {
46
+ export type BaseBucket = BaseDBEntity & {
46
47
  experimentId: string
47
48
  key: string
48
49
  ratio: number
50
+ }
51
+
52
+ export type Bucket = BaseBucket & {
49
53
  data: AnyObject | null
50
54
  }
51
55