flamerest 1.0.47 → 1.0.48
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.
- package/REST.d.ts +5 -5
- package/REST.js +40 -32
- package/package.json +1 -1
package/REST.d.ts
CHANGED
|
@@ -39,8 +39,8 @@ type Rows<T> = {
|
|
|
39
39
|
status: Number,
|
|
40
40
|
ok: boolean,
|
|
41
41
|
data?: Array<T>,
|
|
42
|
-
errors: Object|undefined,
|
|
43
|
-
message: string|undefined,
|
|
42
|
+
errors: Object | undefined,
|
|
43
|
+
message: string | undefined,
|
|
44
44
|
pages: {
|
|
45
45
|
page: Number,
|
|
46
46
|
perPage: Number,
|
|
@@ -63,7 +63,7 @@ export function one<T>(table: string, IDOrWhere: number | string | object, field
|
|
|
63
63
|
* @param table
|
|
64
64
|
* @param values
|
|
65
65
|
*/
|
|
66
|
-
export function create<T>(table: string, values: object): Promise<SavedObject<T>>
|
|
66
|
+
export function create<T>(table: string, values: object, appendTo: number | string | null = null, insertAfter: number | string | null = null, insertFirst: number | string | null = null): Promise<SavedObject<T>>
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* Удалить запись
|
|
@@ -71,7 +71,7 @@ export function create<T>(table: string, values: object): Promise<SavedObject<T>
|
|
|
71
71
|
* @param id
|
|
72
72
|
* @param byFields Если указан, удаляет по этим параметрам
|
|
73
73
|
*/
|
|
74
|
-
export function remove(table: string, id: number | string, byFields?: object): Promise<boolean|Array<any>>
|
|
74
|
+
export function remove(table: string, id: number | string, byFields?: object): Promise<boolean | Array<any>>
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* Редактировать значения
|
|
@@ -79,7 +79,7 @@ export function remove(table: string, id: number | string, byFields?: object): P
|
|
|
79
79
|
* @param ID
|
|
80
80
|
* @param values
|
|
81
81
|
*/
|
|
82
|
-
export function edit<T>(table: string, ID: number | string, values: object): Promise<SavedObject<T>>
|
|
82
|
+
export function edit<T>(table: string, ID: number | string, values: object, appendTo: number | string | null = null, insertAfter: number | string | null = null, insertFirst: number | string | null = null): Promise<SavedObject<T>>
|
|
83
83
|
|
|
84
84
|
|
|
85
85
|
/**
|
package/REST.js
CHANGED
|
@@ -97,7 +97,7 @@ class FLAMEREST {
|
|
|
97
97
|
// Ошибка валидации: Собираем все ошибки полей
|
|
98
98
|
case 422:
|
|
99
99
|
let Errs = {};
|
|
100
|
-
for(let err of ResolveBody.errors) {
|
|
100
|
+
for (let err of ResolveBody.errors) {
|
|
101
101
|
Errs[err['field']] = Errs[err['field']] === undefined ? err['message'] : Errs[err['field']] + ". " + err['message']
|
|
102
102
|
}
|
|
103
103
|
ResolveBody.errors = Errs;
|
|
@@ -367,15 +367,15 @@ class FLAMEREST {
|
|
|
367
367
|
* @returns {object|null}
|
|
368
368
|
*/
|
|
369
369
|
async one(table, IDOrWhere, fields = null, primaryKeyName = 'id') {
|
|
370
|
-
|
|
370
|
+
|
|
371
371
|
let where = {};
|
|
372
|
-
if(typeof IDOrWhere === 'string' || typeof IDOrWhere === 'number') where = {[primaryKeyName]:id};
|
|
373
|
-
else if(typeof IDOrWhere === 'object') where = IDOrWhere;
|
|
372
|
+
if (typeof IDOrWhere === 'string' || typeof IDOrWhere === 'number') where = { [primaryKeyName]: id };
|
|
373
|
+
else if (typeof IDOrWhere === 'object') where = IDOrWhere;
|
|
374
374
|
else throw "Нужно передавать ID или объект";
|
|
375
375
|
|
|
376
|
-
let resp = await this.get(table, where
|
|
377
|
-
if(resp.errors) return resp;
|
|
378
|
-
if(resp.data.length === 0) return null;
|
|
376
|
+
let resp = await this.get(table, where, null, fields, null, 1, 1);
|
|
377
|
+
if (resp.errors) return resp;
|
|
378
|
+
if (resp.data.length === 0) return null;
|
|
379
379
|
|
|
380
380
|
return resp.data[0];
|
|
381
381
|
}
|
|
@@ -385,7 +385,7 @@ class FLAMEREST {
|
|
|
385
385
|
* @param table
|
|
386
386
|
* @param values
|
|
387
387
|
*/
|
|
388
|
-
async create(table, values) {
|
|
388
|
+
async create(table, values, appendTo = null, insertAfter = null, insertFirst = null) {
|
|
389
389
|
|
|
390
390
|
// Нормализуем имена таблиц
|
|
391
391
|
table = table.replace(/_/g, "");
|
|
@@ -393,7 +393,11 @@ class FLAMEREST {
|
|
|
393
393
|
// Подготовить значения
|
|
394
394
|
await this.prepare(values);
|
|
395
395
|
|
|
396
|
-
return this.request(this.SERVER + '/api/' + this.version + '/' + table + '/create'
|
|
396
|
+
return this.request(this.SERVER + '/api/' + this.version + '/' + table + '/create?'
|
|
397
|
+
+ (appendTo ? '&appendTo=' + appendTo : '')
|
|
398
|
+
+ (insertAfter ? '&insertAfter=' + insertAfter : '')
|
|
399
|
+
+ (insertFirst ? '&insertFirst=' + insertFirst : '')
|
|
400
|
+
, JSON.stringify(values), 'POST');
|
|
397
401
|
|
|
398
402
|
}
|
|
399
403
|
|
|
@@ -409,11 +413,11 @@ class FLAMEREST {
|
|
|
409
413
|
table = table.replace(/_/g, "");
|
|
410
414
|
|
|
411
415
|
let params = {};
|
|
412
|
-
if(byFields instanceof Object) params = byFields;
|
|
413
|
-
|
|
416
|
+
if (byFields instanceof Object) params = byFields;
|
|
417
|
+
|
|
414
418
|
let resp = await this.request(this.SERVER + '/api/' + this.version + '/' + table + '/delete?id=' + id, JSON.stringify(params), 'DELETE');
|
|
415
419
|
|
|
416
|
-
if(resp.status === 204) return true;
|
|
420
|
+
if (resp.status === 204) return true;
|
|
417
421
|
|
|
418
422
|
return resp;
|
|
419
423
|
|
|
@@ -425,7 +429,7 @@ class FLAMEREST {
|
|
|
425
429
|
* @param ID
|
|
426
430
|
* @param values
|
|
427
431
|
*/
|
|
428
|
-
async edit(table, ID, values) {
|
|
432
|
+
async edit(table, ID, values, appendTo = null, insertAfter = null, insertFirst = null) {
|
|
429
433
|
|
|
430
434
|
// Нормализуем имена таблиц
|
|
431
435
|
table = table.replace(/_/g, "");
|
|
@@ -433,7 +437,11 @@ class FLAMEREST {
|
|
|
433
437
|
// Подготовить значения
|
|
434
438
|
await this.prepare(values);
|
|
435
439
|
|
|
436
|
-
return this.request(this.SERVER + '/api/' + this.version + '/' + table + '/update?id=' + ID
|
|
440
|
+
return this.request(this.SERVER + '/api/' + this.version + '/' + table + '/update?id=' + ID
|
|
441
|
+
+ (appendTo ? '&appendTo=' + appendTo : '')
|
|
442
|
+
+ (insertAfter ? '&insertAfter=' + insertAfter : '')
|
|
443
|
+
+ (insertFirst ? '&insertFirst=' + insertFirst : '')
|
|
444
|
+
, JSON.stringify(values), 'PATCH');
|
|
437
445
|
}
|
|
438
446
|
|
|
439
447
|
/**
|
|
@@ -455,9 +463,9 @@ class FLAMEREST {
|
|
|
455
463
|
async auth(username, password) {
|
|
456
464
|
|
|
457
465
|
let resp = await this.request(this.SERVER + '/auth/auth', JSON.stringify({ login: username, password: password }), 'POST');
|
|
458
|
-
|
|
459
|
-
if(resp.errors) return resp;
|
|
460
|
-
if(resp.data.length === 0) {resp.errors = []; return resp;}
|
|
466
|
+
|
|
467
|
+
if (resp.errors) return resp;
|
|
468
|
+
if (resp.data.length === 0) { resp.errors = []; return resp; }
|
|
461
469
|
|
|
462
470
|
return resp.data;
|
|
463
471
|
|
|
@@ -466,9 +474,9 @@ class FLAMEREST {
|
|
|
466
474
|
async signup(username, password) {
|
|
467
475
|
|
|
468
476
|
let resp = await this.request(this.SERVER + '/auth/signup', JSON.stringify({ login: username, password: password }), 'POST');
|
|
469
|
-
|
|
470
|
-
if(resp.errors) return resp;
|
|
471
|
-
if(resp.data.length === 0) {resp.errors = []; return resp;}
|
|
477
|
+
|
|
478
|
+
if (resp.errors) return resp;
|
|
479
|
+
if (resp.data.length === 0) { resp.errors = []; return resp; }
|
|
472
480
|
|
|
473
481
|
return resp.data;
|
|
474
482
|
|
|
@@ -487,20 +495,20 @@ class FLAMEREST {
|
|
|
487
495
|
|
|
488
496
|
// Если в один из параметров передан FileList или input[type=file], т.е. нужно загрузить файлы
|
|
489
497
|
for (let val in values) {
|
|
490
|
-
|
|
498
|
+
|
|
491
499
|
// Преобразуем
|
|
492
500
|
let value = values[val];
|
|
493
501
|
let isRef = false;
|
|
494
|
-
if (value instanceof Object
|
|
495
|
-
&& value.hasOwnProperty('_value')
|
|
502
|
+
if (value instanceof Object
|
|
503
|
+
&& value.hasOwnProperty('_value')
|
|
496
504
|
&& (
|
|
497
|
-
value._value instanceof Event ||
|
|
498
|
-
value._value instanceof HTMLInputElement ||
|
|
499
|
-
value._value instanceof ClipboardEvent ||
|
|
500
|
-
value._value instanceof DataTransfer ||
|
|
505
|
+
value._value instanceof Event ||
|
|
506
|
+
value._value instanceof HTMLInputElement ||
|
|
507
|
+
value._value instanceof ClipboardEvent ||
|
|
508
|
+
value._value instanceof DataTransfer ||
|
|
501
509
|
value._value instanceof FileList
|
|
502
|
-
|
|
503
|
-
) {value = value.value; isRef = true}
|
|
510
|
+
)
|
|
511
|
+
) { value = value.value; isRef = true }
|
|
504
512
|
|
|
505
513
|
if (value instanceof Event && value.target instanceof HTMLInputElement && value.target.type === 'file') value = value.target.files;
|
|
506
514
|
if (value instanceof HTMLInputElement && value.type === 'file') value = value.files;
|
|
@@ -534,13 +542,13 @@ class FLAMEREST {
|
|
|
534
542
|
readFileAsync(file) {
|
|
535
543
|
return new Promise((resolve, reject) => {
|
|
536
544
|
let reader = new FileReader();
|
|
537
|
-
|
|
545
|
+
|
|
538
546
|
reader.onloadend = () => {
|
|
539
547
|
resolve(reader.result);
|
|
540
548
|
};
|
|
541
|
-
|
|
549
|
+
|
|
542
550
|
reader.onerror = reject;
|
|
543
|
-
|
|
551
|
+
|
|
544
552
|
reader.readAsDataURL(file);
|
|
545
553
|
})
|
|
546
554
|
}
|