flamerest 1.0.30 → 1.0.33

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/REST.d.ts +24 -6
  2. package/REST.js +2 -2
  3. package/package.json +1 -1
package/REST.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * @param {string} type Тип
6
6
  * @param {string} responseType Тип ответа: json или blob
7
7
  */
8
- export function request(url: string, params: object | string, type: string, responseType: string): object
8
+ export function request(url: string, params: object | string, type?: string, responseType?: string): object
9
9
 
10
10
  /**
11
11
  * Получить выборку из таблицы через REST
@@ -21,7 +21,7 @@ export function request(url: string, params: object | string, type: string, resp
21
21
  * @param titles Это чтобы мы могли контроллить какие названия полей мы будет загружать при экспорте, чтобы они были как в таблице
22
22
  * @return Promise<object>
23
23
  */
24
- export function get(table: string, where: object | string | null, expand: object | string | null, fields: object | Array<string> | string | null, sortfields: object | Array<string> | string | null, page: number, perPage: number, RemoveDuplicates, format, titles): object
24
+ export function get<T>(table: string, where?: object | string | null, expand?: object | string | null, fields?: object | Array<string> | string | null, sortfields?: object | Array<string> | string | null, page?: number, perPage?: number, RemoveDuplicates?, format?, titles?): Promise<Rows<T>>;
25
25
 
26
26
  /**
27
27
  * Получить все записи по запросу [постранично]
@@ -29,7 +29,25 @@ export function get(table: string, where: object | string | null, expand: object
29
29
  * @param {object} params
30
30
  * @returns
31
31
  */
32
- export function all(table: string, params: {where: object, fields: object|Array<string>, sort: Array<string>, page: number, perPage: number}): object;
32
+ export function all<T>(table: string, params?: { where?: object, fields?: object | Array<string>, sort?: Array<string>, page?: number, perPage?: number }): Promise<Rows<T>>;
33
+
34
+ /**
35
+ * Стандартный ответ от Request с несколькими строками
36
+ */
37
+ type Rows<T> = {
38
+ type: string,
39
+ status: Number,
40
+ ok: boolean,
41
+ data?: Array<T>,
42
+ errors: Object|undefined,
43
+ message: string|undefined,
44
+ pages: {
45
+ page: integer,
46
+ perPage: integer,
47
+ count: Number,
48
+ total: Number,
49
+ }
50
+ }
33
51
 
34
52
  /**
35
53
  * Получить одну запись по ID или по условию выборки [первая запись]
@@ -38,14 +56,14 @@ export function all(table: string, params: {where: object, fields: object|Array<
38
56
  * @param {object|Array} fields
39
57
  * @param {string} primaryKeyName если указан ID, то указать название первичного ключа, если от id он отличается
40
58
  */
41
- export function one(table: string, IDOrWhere: number|string|object, fields: object|Array<string>, primaryKeyName: string): object;
59
+ export function one<T>(table: string, IDOrWhere: number | string | object, fields?: object | Array<string> | null, primaryKeyName?: string): Promise<T | null>;
42
60
 
43
61
  /**
44
62
  * Создать новую запись
45
63
  * @param table
46
64
  * @param values
47
65
  */
48
- export function create(table: string, values: object)
66
+ export function create<T>(table: string, values: object): Promise<T>
49
67
 
50
68
  /**
51
69
  * Удалить запись
@@ -53,7 +71,7 @@ export function create(table: string, values: object)
53
71
  * @param id
54
72
  * @param byFields Если указан, удаляет по этим параметрам
55
73
  */
56
- export function remove(table: string, id: number | string, byFields: object)
74
+ export function remove(table: string, id: number | string, byFields?: object)
57
75
 
58
76
  /**
59
77
  * Редактировать значения
package/REST.js CHANGED
@@ -359,7 +359,7 @@ class FLAMEREST {
359
359
  * @param {number|string|object} IDOrWhere
360
360
  * @param {object|Array} fields
361
361
  * @param {string} primaryKeyName
362
- * @returns {object}
362
+ * @returns {object|null}
363
363
  */
364
364
  async one(table, IDOrWhere, fields = null, primaryKeyName = 'id') {
365
365
 
@@ -370,7 +370,7 @@ class FLAMEREST {
370
370
 
371
371
  let resp = await this.get(table, where , null, fields, null, 1, 1);
372
372
  if(resp.errors) return resp;
373
- if(resp.data.length === 0) return resp;
373
+ if(resp.data.length === 0) return null;
374
374
 
375
375
  return resp.data[0];
376
376
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flamerest",
3
- "version": "1.0.30",
3
+ "version": "1.0.33",
4
4
  "description": "",
5
5
  "main": "REST.js",
6
6
  "typings": "./REST.d.ts",