@fraym/crud 0.9.1 → 0.10.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,13 +1,12 @@
1
1
  import { ClientConfig } from "../config/config";
2
2
  import { CreatedCrudData } from "./create";
3
- import { GetCrudData } from "./getData";
4
3
  import { Filter, GetCrudDataList } from "./getDataList";
5
4
  export interface DeliveryClient {
6
5
  create: (tenantId: string, type: string, data: Record<string, any>) => Promise<CreatedCrudData>;
7
6
  update: (tenantId: string, type: string, id: string, data: Record<string, any>) => Promise<void>;
8
7
  delete: (tenantId: string, type: string, id: string) => Promise<void>;
9
- getData: (tenantId: string, type: string, id: string, returnEmptyDataIfNotFound?: boolean) => Promise<GetCrudData | null>;
10
- getDataList: (tenantId: string, type: string, limit?: number, page?: number, filter?: Filter) => Promise<GetCrudDataList | null>;
8
+ getData: <T extends {}>(tenantId: string, type: string, id: string, returnEmptyDataIfNotFound?: boolean) => Promise<T | null>;
9
+ getDataList: <T extends {}>(tenantId: string, type: string, limit?: number, page?: number, filter?: Filter) => Promise<GetCrudDataList<T> | null>;
11
10
  close: () => Promise<void>;
12
11
  }
13
12
  export declare const newDeliveryClient: (config?: ClientConfig) => Promise<DeliveryClient>;
@@ -1,3 +1,2 @@
1
1
  import { DeliveryServiceClient } from "@fraym/crud-proto";
2
- export type GetCrudData = Record<string, any>;
3
- export declare const getCrudData: (tenantId: string, type: string, id: string, returnEmptyDataIfNotFound: boolean, serviceClient: DeliveryServiceClient) => Promise<GetCrudData | null>;
2
+ export declare const getCrudData: <T extends {}>(tenantId: string, type: string, id: string, returnEmptyDataIfNotFound: boolean, serviceClient: DeliveryServiceClient) => Promise<T | null>;
@@ -1,17 +1,17 @@
1
1
  import { DeliveryServiceClient } from "@fraym/crud-proto";
2
- export interface GetCrudDataList {
2
+ export interface GetCrudDataList<T extends {}> {
3
3
  limit: number;
4
4
  page: number;
5
- data: Record<string, any>[];
5
+ data: T[];
6
6
  }
7
7
  export interface Filter {
8
8
  fields: Record<string, FieldFilter>;
9
- and: Filter[];
10
- or: Filter[];
9
+ and?: Filter[];
10
+ or?: Filter[];
11
11
  }
12
12
  export interface FieldFilter {
13
13
  type: string;
14
14
  operation: string;
15
15
  value: any;
16
16
  }
17
- export declare const getCrudDataList: (tenantId: string, type: string, limit: number, page: number, filter: Filter, serviceClient: DeliveryServiceClient) => Promise<GetCrudDataList | null>;
17
+ export declare const getCrudDataList: <T extends {}>(tenantId: string, type: string, limit: number, page: number, filter: Filter, serviceClient: DeliveryServiceClient) => Promise<GetCrudDataList<T> | null>;
@@ -20,8 +20,8 @@ const getProtobufEntryFilter = (filter) => {
20
20
  }
21
21
  return {
22
22
  fields: fields,
23
- and: filter.and.map(and => getProtobufEntryFilter(and)),
24
- or: filter.or.map(or => getProtobufEntryFilter(or)),
23
+ and: filter.and ? filter.and.map(and => getProtobufEntryFilter(and)) : [],
24
+ or: filter.or ? filter.or.map(or => getProtobufEntryFilter(or)) : [],
25
25
  };
26
26
  };
27
27
  const getCrudDataList = async (tenantId, type, limit, page, filter, serviceClient) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraym/crud",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "license": "UNLICENSED",
5
5
  "homepage": "https://github.com/fraym/crud-nodejs",
6
6
  "repository": {