@webiny/db 5.23.1 → 5.24.0-beta.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.
Files changed (3) hide show
  1. package/index.d.ts +15 -13
  2. package/index.js +9 -12
  3. package/package.json +4 -4
package/index.d.ts CHANGED
@@ -1,16 +1,18 @@
1
- export declare type Key = {
1
+ interface KeyField {
2
+ name: string;
3
+ }
4
+ export interface Key {
2
5
  primary?: boolean;
3
6
  unique?: boolean;
4
7
  name: string;
5
- fields: {
6
- name: string;
7
- }[];
8
- };
9
- export declare type Args = {
10
- __batch?: {
11
- instance: Batch;
12
- operation: Operation;
13
- };
8
+ fields: KeyField[];
9
+ }
10
+ export interface ArgsBatch {
11
+ instance: Batch;
12
+ operation: Operation;
13
+ }
14
+ export interface Args {
15
+ __batch?: ArgsBatch;
14
16
  table?: string;
15
17
  meta?: boolean;
16
18
  limit?: number;
@@ -18,7 +20,7 @@ export declare type Args = {
18
20
  data?: Record<string, any>;
19
21
  query?: Record<string, any>;
20
22
  keys?: Key[];
21
- };
23
+ }
22
24
  export declare type Result<T = any> = [T, Record<string, any>];
23
25
  export interface DbDriver {
24
26
  create: (args: Args) => Promise<Result<true>>;
@@ -51,7 +53,7 @@ declare class Db {
51
53
  read<T = Record<string, any>>(args: Args): Promise<Result<T[]>>;
52
54
  update(args: Args): Promise<Result<true>>;
53
55
  delete(args: Args): Promise<Result<true>>;
54
- createLog(operation: any, args: Args): Promise<Result<true>>;
56
+ createLog(operation: string, args: Args): Promise<Result<true>>;
55
57
  readLogs<T = Record<string, any>>(): Promise<Result<T[]>>;
56
58
  batch<T0 = any, T1 = any, T2 = any, T3 = any, T4 = any, T5 = any, T6 = any, T7 = any, T8 = any, T9 = any>(): Batch<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>;
57
59
  }
@@ -61,7 +63,7 @@ declare class Batch<T0 = any, T1 = any, T2 = any, T3 = any, T4 = any, T5 = any,
61
63
  id: string;
62
64
  meta: Record<string, any>;
63
65
  operations: Operation[];
64
- constructor(db: any);
66
+ constructor(db: Db);
65
67
  push(...operations: Operation[]): this;
66
68
  create(...args: Args[]): this;
67
69
  read(...args: Args[]): this;
package/index.js CHANGED
@@ -18,9 +18,9 @@ const shortId = () => {
18
18
  const time = new Date().getTime();
19
19
  const uniqueId = Math.random().toString(36).slice(-6);
20
20
  return `${time}.${uniqueId}`;
21
- }; // Picks necessary data from received args, ready to be stored in the log table.
22
-
21
+ };
23
22
 
23
+ // Picks necessary data from received args, ready to be stored in the log table.
24
24
  const getCreateLogData = args => {
25
25
  const {
26
26
  table,
@@ -31,7 +31,7 @@ const getCreateLogData = args => {
31
31
  query,
32
32
  keys
33
33
  } = args;
34
- const logData = {
34
+ return {
35
35
  table,
36
36
  meta,
37
37
  limit,
@@ -39,17 +39,11 @@ const getCreateLogData = args => {
39
39
  data,
40
40
  query,
41
41
  keys,
42
- batch: null
43
- };
44
-
45
- if (args.__batch) {
46
- logData.batch = {
42
+ batch: args.__batch ? {
47
43
  id: args.__batch.instance.id,
48
44
  type: args.__batch.instance.type
49
- };
50
- }
51
-
52
- return logData;
45
+ } : null
46
+ };
53
47
  };
54
48
 
55
49
  class Db {
@@ -191,6 +185,9 @@ class Batch {
191
185
  }
192
186
 
193
187
  async execute() {
188
+ /**
189
+ * TODO: figure out which exact type to use instead of any.
190
+ */
194
191
  const promises = [];
195
192
 
196
193
  for (let i = 0; i < this.operations.length; i++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/db",
3
- "version": "5.23.1",
3
+ "version": "5.24.0-beta.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,8 +15,8 @@
15
15
  "devDependencies": {
16
16
  "@babel/cli": "^7.16.0",
17
17
  "@babel/core": "^7.16.0",
18
- "@webiny/cli": "^5.23.1",
19
- "@webiny/project-utils": "^5.23.1",
18
+ "@webiny/cli": "^5.24.0-beta.0",
19
+ "@webiny/project-utils": "^5.24.0-beta.0",
20
20
  "rimraf": "^3.0.2",
21
21
  "typescript": "^4.1.3"
22
22
  },
@@ -24,5 +24,5 @@
24
24
  "build": "yarn webiny run build",
25
25
  "watch": "yarn webiny run watch"
26
26
  },
27
- "gitHead": "a726d09d2647d13e5a4f376cef23463564ef7ca0"
27
+ "gitHead": "05b90b92bbaf2ef3adf275d008c4641580cf5f42"
28
28
  }