@naturalcycles/abba 1.23.0 → 1.23.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.
@@ -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;
package/dist/types.d.ts CHANGED
@@ -37,10 +37,12 @@ export type Experiment = BaseExperiment & {
37
37
  export type ExperimentWithBuckets = Saved<Experiment> & {
38
38
  buckets: Saved<Bucket>[];
39
39
  };
40
- export type Bucket = BaseDBEntity & {
40
+ export type BaseBucket = BaseDBEntity & {
41
41
  experimentId: string;
42
42
  key: string;
43
43
  ratio: number;
44
+ };
45
+ export type Bucket = BaseBucket & {
44
46
  data: AnyObject | null;
45
47
  };
46
48
  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.23.1",
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
  })
package/src/types.ts CHANGED
@@ -42,10 +42,13 @@ export type ExperimentWithBuckets = Saved<Experiment> & {
42
42
  buckets: Saved<Bucket>[]
43
43
  }
44
44
 
45
- export type Bucket = BaseDBEntity & {
45
+ export type BaseBucket = BaseDBEntity & {
46
46
  experimentId: string
47
47
  key: string
48
48
  ratio: number
49
+ }
50
+
51
+ export type Bucket = BaseBucket & {
49
52
  data: AnyObject | null
50
53
  }
51
54