d5-api-initializer 0.0.2-alpha.0 → 0.0.2-alpha.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.
- package/package.json +4 -1
- package/CHANGELOG.md +0 -0
- package/build.js +0 -14
- package/scripts/releaseChangelog.mjs +0 -50
- package/src/api-interfaces.ts +0 -43
- package/src/classes/ApiCore.ts +0 -74
- package/src/classes/ApiHttpRequest.ts +0 -68
- package/src/classes/ApiHttpResponse.ts +0 -27
- package/src/classes/ApiInvoker.ts +0 -199
- package/src/classes/ApiJoinInvoker.ts +0 -9
- package/src/classes/ApiObjectCollectionIterator.ts +0 -63
- package/src/classes/ApiObjectInitializer.ts +0 -87
- package/src/classes/ApiRequest.ts +0 -337
- package/src/classes/ApiResponse.ts +0 -72
- package/src/classes/EngineInitializer.ts +0 -88
- package/src/classes/UserMessages.ts +0 -38
- package/src/engine-index.ts +0 -4
- package/src/index.ts +0 -3
- package/src/lib-index.ts +0 -3
- package/tsconfig.json +0 -35
- package/tsup.config.ts +0 -46
- package/types/jsWapi.d.ts +0 -105
- package/webpack.config.js +0 -44
- package/zip-build.js +0 -50
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "d5-api-initializer",
|
|
3
|
-
"version": "0.0.2-alpha.
|
|
3
|
+
"version": "0.0.2-alpha.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"dependencies": {},
|
|
6
6
|
"main": "publish/cjs/d5-api-initializer",
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"default": "./publish/cjs/d5-api-initializer.cjs"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
+
"files": [
|
|
18
|
+
"publish"
|
|
19
|
+
],
|
|
17
20
|
"engines": {
|
|
18
21
|
"node": ">=18"
|
|
19
22
|
},
|
package/CHANGELOG.md
DELETED
|
File without changes
|
package/build.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
require('dotenv').config();
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const {zipDirectories} = require('./zip-build');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const archivePath = path.resolve(__dirname, 'build/initializer.zip');
|
|
8
|
-
|
|
9
|
-
fs.mkdirSync('build', {recursive: true});
|
|
10
|
-
|
|
11
|
-
zipDirectories([{
|
|
12
|
-
'source': path.resolve(__dirname, 'dist'),
|
|
13
|
-
'put_at_root': true
|
|
14
|
-
}], archivePath);
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import {execSync} from 'child_process';
|
|
3
|
-
import {Command} from 'commander';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const program = new Command();
|
|
7
|
-
|
|
8
|
-
program.name('changelog');
|
|
9
|
-
|
|
10
|
-
program.command('changelog')
|
|
11
|
-
.option('-p, --prev-tag <string>', 'previous version')
|
|
12
|
-
.action(async ({prevTag}) => {
|
|
13
|
-
// Отримати останній тег
|
|
14
|
-
const lastTag = execSync('git describe --tags --abbrev=0 --match "v*"').toString().trim();
|
|
15
|
-
|
|
16
|
-
// Отримати список комітів з останнього тегу
|
|
17
|
-
const commits = execSync(`git log ${prevTag}..${lastTag} --format=\"hash:%h;;author:%an;;title:%s\"`).toString().trim().split('\n').map(commit => {
|
|
18
|
-
const [hash, author, title] = commit.split(';;');
|
|
19
|
-
return {
|
|
20
|
-
hash: hash.slice('hash:'.length),
|
|
21
|
-
author: author.slice('author:'.length),
|
|
22
|
-
title: title.slice('title:'.length),
|
|
23
|
-
};
|
|
24
|
-
}).filter(({title}) => title.startsWith('[LOG]'));
|
|
25
|
-
|
|
26
|
-
console.log(lastTag);
|
|
27
|
-
console.log(commits);
|
|
28
|
-
|
|
29
|
-
// Сформувати markdown список
|
|
30
|
-
const markdown = commits.map(({title, hash, author}) => {
|
|
31
|
-
return `- ${title.slice('[LOG]'.length)} - @${author} [View](https://bitbucket.org/macc-systems/d5-cli/commits/${hash})`;
|
|
32
|
-
}).join('\n');
|
|
33
|
-
|
|
34
|
-
// Додати список комітів до CHANGELOG.md
|
|
35
|
-
const changelog = fs.readFileSync('CHANGELOG.md', 'utf-8');
|
|
36
|
-
const nowFormatted = new Date().toLocaleDateString('en-US', {
|
|
37
|
-
month: 'short',
|
|
38
|
-
day: 'numeric',
|
|
39
|
-
year: 'numeric',
|
|
40
|
-
});
|
|
41
|
-
const newChangelog = `## _${lastTag}_\n\n${nowFormatted}\n\n${markdown}\n\n${changelog}`;
|
|
42
|
-
|
|
43
|
-
fs.writeFileSync('CHANGELOG.md', newChangelog);
|
|
44
|
-
|
|
45
|
-
console.log('Зміни успішно записані в CHANGELOG.md');
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
program.parse();
|
package/src/api-interfaces.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import ApiCore from './classes/ApiCore';
|
|
2
|
-
import ApiRequest from './classes/ApiRequest';
|
|
3
|
-
import ApiResponse from './classes/ApiResponse';
|
|
4
|
-
import ApiHttpResponse from './classes/ApiHttpResponse';
|
|
5
|
-
|
|
6
|
-
export interface IFilterValue {
|
|
7
|
-
'='?: string | number | Array<string | number>;
|
|
8
|
-
'>'?: string | number | Array<string | number>;
|
|
9
|
-
'>='?: string | number | Array<string | number>;
|
|
10
|
-
'<'?: string | number | Array<string | number>;
|
|
11
|
-
'<='?: string | number | Array<string | number>;
|
|
12
|
-
'!='?: string | number | Array<string | number>;
|
|
13
|
-
'between'?: string | number | Array<string | number>;
|
|
14
|
-
'like'?: string | number | Array<string | number>;
|
|
15
|
-
'%'?: string | number | Array<string | number>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface IFilter {
|
|
19
|
-
[fieldName: string]: IFilterValue;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface IFiltersCollection {
|
|
23
|
-
[property: string]: IFilterValue | IFilter[];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface IMappedCollection {
|
|
27
|
-
[name: string]: any;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type IApiOperation<MetaParams> = (apiCore: ApiCore, apiRequest: ApiRequest, apiResponse: ApiResponse, meta?: jsWapi.JSWapiMeta<MetaParams>) => void;
|
|
31
|
-
|
|
32
|
-
export interface IApiOperations<MetaParams = Record<string, any>> {
|
|
33
|
-
[key: string]: IApiOperation<MetaParams>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type IHttpCallback = (apiHttpResponse: ApiHttpResponse) => any | void
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export enum LanguageCode {
|
|
40
|
-
ua = 'ua',
|
|
41
|
-
ru = 'ru',
|
|
42
|
-
en = 'eng',
|
|
43
|
-
}
|
package/src/classes/ApiCore.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import ApiHttpRequest from './ApiHttpRequest';
|
|
2
|
-
import ApiInvoker from './ApiInvoker';
|
|
3
|
-
import ApiRequest from './ApiRequest';
|
|
4
|
-
import UserMessages from './UserMessages';
|
|
5
|
-
import {LanguageCode} from '../api-interfaces';
|
|
6
|
-
import ApiObjectCollectionIterator from "./ApiObjectCollectionIterator";
|
|
7
|
-
|
|
8
|
-
type HTTPSender = {
|
|
9
|
-
newJSWapiHttp(url: string): jsWapi.JSWapiHttp
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default class ApiCore {
|
|
13
|
-
private readonly httpSender: HTTPSender;
|
|
14
|
-
private readonly _request: ApiRequest;
|
|
15
|
-
|
|
16
|
-
constructor({http, request}: { http: HTTPSender, request: ApiRequest }) {
|
|
17
|
-
this.httpSender = http;
|
|
18
|
-
this._request = request;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Переводит и форматирует строку из словаря переводов согласно текущего языка приложения.
|
|
23
|
-
* @param msgKey
|
|
24
|
-
* @param params
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* {
|
|
28
|
-
* ...
|
|
29
|
-
* "myKey": 'some text with {0}'
|
|
30
|
-
* ...
|
|
31
|
-
* }
|
|
32
|
-
* t('myKey', ['placeholder text']) // 'some text with placeholder text'
|
|
33
|
-
*/
|
|
34
|
-
t(msgKey: string, params?: string[]): string {
|
|
35
|
-
UserMessages.lang = this._request.lang || LanguageCode.ua;
|
|
36
|
-
return UserMessages.format(msgKey, params);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
newHttpRequest(url: string): ApiHttpRequest {
|
|
40
|
-
return new ApiHttpRequest(this.httpSender.newJSWapiHttp(url));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
newApiInvoker(objectName: string, operName: string): ApiInvoker {
|
|
44
|
-
return new ApiInvoker(this._request.newJSWapiInvoker(objectName, operName), objectName);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
newApiObjectCollectionIterator(objectName: string): ApiObjectCollectionIterator {
|
|
48
|
-
return new ApiObjectCollectionIterator({
|
|
49
|
-
invoker: this.newApiInvoker(objectName, 'List')
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
newApiException(message: string, code?: string | number): Error {
|
|
54
|
-
if (code) {
|
|
55
|
-
// @ts-ignore
|
|
56
|
-
return new JSWapiException(code.toString(), message);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
return new JSWapiException(message);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/*
|
|
64
|
-
* Will be implemented later
|
|
65
|
-
*
|
|
66
|
-
newApiJoinInvoker(alias: string, request: ApiRequest | ApiInvoker): ApiJoinInvoker {
|
|
67
|
-
if (request instanceof ApiRequest) {
|
|
68
|
-
return new ApiJoinInvoker(this._jsWapiRequest.newJSWapiJoinInvoker(alias, request._jsWapiRequest));
|
|
69
|
-
} else if (request instanceof ApiInvoker) {
|
|
70
|
-
return new ApiJoinInvoker(this._jsWapiRequest.newJSWapiJoinInvoker(alias, request._jsWapiInvoker));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
*/
|
|
74
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import ApiHttpResponse from './ApiHttpResponse';
|
|
2
|
-
import {IHttpCallback, IMappedCollection} from '../api-interfaces';
|
|
3
|
-
|
|
4
|
-
export default class ApiHttpRequest {
|
|
5
|
-
private _jsWapiHttp: jsWapi.JSWapiHttp;
|
|
6
|
-
|
|
7
|
-
constructor(jsWapiHttp: jsWapi.JSWapiHttp) {
|
|
8
|
-
this._jsWapiHttp = jsWapiHttp;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
set headers(headers: IMappedCollection) {
|
|
12
|
-
for (const headersKey in headers) {
|
|
13
|
-
this._jsWapiHttp = this._jsWapiHttp.setHeader(headersKey, JSON.stringify(headers[headersKey]));
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
set timeout(milliseconds: number) {
|
|
18
|
-
this._jsWapiHttp = this._jsWapiHttp.setTimeout(milliseconds);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
setHeader(name: string, value: any): ApiHttpRequest {
|
|
22
|
-
this._jsWapiHttp = this._jsWapiHttp.setHeader(name, ''.concat(value));
|
|
23
|
-
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
setHeaders(headers: IMappedCollection): ApiHttpRequest {
|
|
28
|
-
for (const headersKey in headers) {
|
|
29
|
-
this._jsWapiHttp = this._jsWapiHttp.setHeader(headersKey, ''.concat(headers[headersKey]));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
setTimeout(milliseconds: number): ApiHttpRequest {
|
|
36
|
-
this._jsWapiHttp = this._jsWapiHttp.setTimeout(milliseconds);
|
|
37
|
-
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
GET(callback?: IHttpCallback): ApiHttpResponse | any | void {
|
|
42
|
-
return this._jsWapiHttp.GET(this._getWrappedCallback(callback));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
POST(requestBody: IMappedCollection, callback?: IHttpCallback): ApiHttpResponse | any | void {
|
|
46
|
-
return this._jsWapiHttp.POST(JSON.stringify(requestBody), this._getWrappedCallback(callback));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
PUT(requestBody: IMappedCollection, callback?: IHttpCallback): ApiHttpResponse | any | void {
|
|
50
|
-
return this._jsWapiHttp.PUT(JSON.stringify(requestBody), this._getWrappedCallback(callback));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
PATCH(requestBody: IMappedCollection, callback: IHttpCallback): ApiHttpResponse | any | void {
|
|
54
|
-
return this._jsWapiHttp.PATCH(JSON.stringify(requestBody), this._getWrappedCallback(callback));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private _getWrappedCallback(callback: IHttpCallback) {
|
|
58
|
-
/*
|
|
59
|
-
Wraps this IHttpCallback with simple callback, which is passed to native Wapi,
|
|
60
|
-
to gain access to ApiHttpResponse methods while processing response in callback
|
|
61
|
-
*/
|
|
62
|
-
return (res: any) => {
|
|
63
|
-
if (callback) {
|
|
64
|
-
return callback(new ApiHttpResponse(res));
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export default class ApiHttpResponse {
|
|
2
|
-
private readonly _jsWapiHttpResponse: jsWapi.JSWapiHttpResponse;
|
|
3
|
-
|
|
4
|
-
constructor(jsWapiHttpResponse: jsWapi.JSWapiHttpResponse) {
|
|
5
|
-
this._jsWapiHttpResponse = jsWapiHttpResponse;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
get statusCode(): number {
|
|
9
|
-
return this._jsWapiHttpResponse.getStatusCode();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
get body(): string {
|
|
13
|
-
return this._jsWapiHttpResponse.getBody();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
get bodyAsStream(): jsWapi.BinaryDataStream {
|
|
17
|
-
return this._jsWapiHttpResponse.getBodyAsInputStream();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
getHeader(name: string): string {
|
|
21
|
-
return this._jsWapiHttpResponse.getHeader(name);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
isSuccessful(): boolean {
|
|
25
|
-
return this._jsWapiHttpResponse.isSuccessful();
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import ApiResponse from './ApiResponse';
|
|
2
|
-
import {IFiltersCollection, IMappedCollection} from '../api-interfaces';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface IInvoker<T> {
|
|
6
|
-
setColumns(columns: string[]): T;
|
|
7
|
-
setFilters(filters: IFiltersCollection): T;
|
|
8
|
-
setSorts(sorts: string[]): T;
|
|
9
|
-
addColumns(columns: string[]): T;
|
|
10
|
-
addSorts(sorts: string[]): T;
|
|
11
|
-
objectName: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default class ApiInvoker implements IInvoker<ApiInvoker>{
|
|
15
|
-
public _jsWapiInvoker: jsWapi.JSWapiInvoker;
|
|
16
|
-
protected readonly _objectName: string;
|
|
17
|
-
|
|
18
|
-
constructor(jsWapiInvoker: jsWapi.JSWapiInvoker, objectName: string) {
|
|
19
|
-
this._jsWapiInvoker = jsWapiInvoker;
|
|
20
|
-
this._objectName = objectName;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/* ----------------------------Accessors---------------------------- */
|
|
24
|
-
get objectName(): string {
|
|
25
|
-
return this._objectName;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
set filters(filters: IFiltersCollection) {
|
|
29
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setFilters(filters);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
set params(params: IMappedCollection) {
|
|
33
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setParams(params);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
set rowsPerPage(amount: number) {
|
|
37
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setRowsPerPage(amount);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
set page(number: number) {
|
|
41
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setPage(number);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
set pagesPredict(amount: number) {
|
|
45
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setPagesPredict(amount);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
set request(request: IMappedCollection | any[]) {
|
|
49
|
-
if (Array.isArray(request)) {
|
|
50
|
-
this._jsWapiInvoker = this._jsWapiInvoker.putRequest(this._objectName, request);
|
|
51
|
-
} else {
|
|
52
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setRequest(request);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
get request() {
|
|
57
|
-
return this._jsWapiInvoker.getRequest();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
set columns(columns: string[]) {
|
|
61
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setColumns(columns);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
set sorts(sorts: string[]) {
|
|
65
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setSorts(sorts);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
set aggregatedColumns(aggregatedColumns: IMappedCollection) {
|
|
69
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setAggregatedColumns(aggregatedColumns);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
set nestedColumns(nestedColumns: IMappedCollection) {
|
|
73
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setNestedColumns(nestedColumns);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/* -----------------------------Setters----------------------------- */
|
|
77
|
-
setHierarchy(parentColumn: string, requestKind?: number) {
|
|
78
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setHierarchy(parentColumn, requestKind);
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
setFilters(filters: IFiltersCollection): ApiInvoker {
|
|
83
|
-
this.filters = filters;
|
|
84
|
-
|
|
85
|
-
return this;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
setParams(params: IMappedCollection): ApiInvoker {
|
|
89
|
-
this.params = params;
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
setPage(number: number): ApiInvoker {
|
|
94
|
-
this.page = number;
|
|
95
|
-
return this;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
setRowsPerPage(amount: number): ApiInvoker {
|
|
99
|
-
this.rowsPerPage = amount;
|
|
100
|
-
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
setPagesPredict(amount: number): ApiInvoker {
|
|
105
|
-
this.pagesPredict = amount;
|
|
106
|
-
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
setRequest(request: IMappedCollection | any[]): ApiInvoker {
|
|
111
|
-
this.request = request;
|
|
112
|
-
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
getRequest(requestName: string): IMappedCollection[] {
|
|
117
|
-
return this._jsWapiInvoker.getRequest(requestName);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
setSrcRequest(srcRequest: IMappedCollection): ApiInvoker {
|
|
121
|
-
this._jsWapiInvoker = this._jsWapiInvoker.setSrcRequest(srcRequest);
|
|
122
|
-
return this;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
getSrcRequest(): Record<string, any> {
|
|
126
|
-
throw new Error('not implemented');
|
|
127
|
-
return this._jsWapiInvoker.getSrcRequest();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
setColumns(columns: string[]): ApiInvoker {
|
|
131
|
-
this.columns = columns;
|
|
132
|
-
|
|
133
|
-
return this;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
setAggregatedColumns(aggregatedColumns: IMappedCollection): ApiInvoker {
|
|
137
|
-
this.aggregatedColumns = aggregatedColumns;
|
|
138
|
-
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
setNestedColumns(nestedColumns: IMappedCollection): ApiInvoker {
|
|
143
|
-
this.nestedColumns = nestedColumns;
|
|
144
|
-
|
|
145
|
-
return this;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
setSorts(sorts: string[]): ApiInvoker {
|
|
149
|
-
this.sorts = sorts;
|
|
150
|
-
|
|
151
|
-
return this;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
setFirstRows(firstRows: number) {
|
|
155
|
-
this._jsWapiInvoker.setFirstRows(firstRows);
|
|
156
|
-
|
|
157
|
-
return this;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
setOperRightCheck(check: boolean) {
|
|
161
|
-
this._jsWapiInvoker.setOperRightCheck(check);
|
|
162
|
-
|
|
163
|
-
return this;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
getFirstRows(): number {
|
|
167
|
-
return this._jsWapiInvoker.getFirstRows();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/* -----------------------------Adders------------------------------ */
|
|
171
|
-
addColumns(columns: string[]): ApiInvoker {
|
|
172
|
-
this._jsWapiInvoker = this._jsWapiInvoker.addColumns(columns);
|
|
173
|
-
|
|
174
|
-
return this;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
addAggregatedColumns(aggregatedColumns: IMappedCollection): ApiInvoker {
|
|
178
|
-
this._jsWapiInvoker = this._jsWapiInvoker.putAggregatedColumns(aggregatedColumns);
|
|
179
|
-
|
|
180
|
-
return this;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
addNestedColumns(nestedColumns: IMappedCollection): ApiInvoker {
|
|
184
|
-
this._jsWapiInvoker = this._jsWapiInvoker.putNestedColumns(nestedColumns);
|
|
185
|
-
|
|
186
|
-
return this;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
addSorts(sorts: string[]): ApiInvoker {
|
|
190
|
-
this._jsWapiInvoker = this._jsWapiInvoker.addSorts(sorts);
|
|
191
|
-
|
|
192
|
-
return this;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/* ------------------------------Other------------------------------ */
|
|
196
|
-
invoke(): ApiResponse {
|
|
197
|
-
return new ApiResponse(this._jsWapiInvoker.invoke(), this._objectName);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import ApiResponse from "./ApiResponse";
|
|
2
|
-
import ApiInvoker, {IInvoker} from "./ApiInvoker";
|
|
3
|
-
import {IFiltersCollection} from "../api-interfaces";
|
|
4
|
-
|
|
5
|
-
export default class ApiObjectCollectionIterator implements IInvoker<ApiObjectCollectionIterator> {
|
|
6
|
-
private _invoker: ApiInvoker;
|
|
7
|
-
|
|
8
|
-
constructor({invoker}: {invoker: ApiInvoker}) {
|
|
9
|
-
this._invoker = invoker;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
get objectName(): string {
|
|
13
|
-
return this._invoker.objectName
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/* -----------------------------Setters----------------------------- */
|
|
17
|
-
setColumns(columns: string[]): ApiObjectCollectionIterator {
|
|
18
|
-
this._invoker.setColumns(columns)
|
|
19
|
-
return this;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
setFilters(filters: IFiltersCollection): ApiObjectCollectionIterator {
|
|
23
|
-
this._invoker.setFilters(filters)
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
setSorts(sorts: string[]): ApiObjectCollectionIterator {
|
|
28
|
-
this._invoker.setSorts(sorts)
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/* -----------------------------Adders------------------------------ */
|
|
33
|
-
addSorts(sorts: string[]): ApiObjectCollectionIterator {
|
|
34
|
-
this._invoker.addSorts(sorts);
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
addColumns(columns: string[]): ApiObjectCollectionIterator {
|
|
39
|
-
this._invoker.addColumns(columns);
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/* ------------------------------Other------------------------------ */
|
|
44
|
-
*invoke(): Generator<ApiResponse> {
|
|
45
|
-
let data = null,
|
|
46
|
-
pageCount = 1;
|
|
47
|
-
let lastPage = false
|
|
48
|
-
const rowsPerPage = 100;
|
|
49
|
-
while (!lastPage) {
|
|
50
|
-
this._invoker.page = pageCount;
|
|
51
|
-
this._invoker.rowsPerPage = rowsPerPage;
|
|
52
|
-
data = new ApiResponse(this._invoker.invoke(), this.objectName).getResponse();
|
|
53
|
-
pageCount++;
|
|
54
|
-
if(Array.isArray(data)) {
|
|
55
|
-
for (let i = 0; i < data.length; i++) {
|
|
56
|
-
yield data[i];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
lastPage = data.length < rowsPerPage;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import ApiCore from './ApiCore';
|
|
2
|
-
import ApiRequest from './ApiRequest';
|
|
3
|
-
import ApiResponse from './ApiResponse';
|
|
4
|
-
import {IApiOperations, LanguageCode} from '../api-interfaces';
|
|
5
|
-
import UserMessages from './UserMessages';
|
|
6
|
-
|
|
7
|
-
export interface ApiObjectInitializerConstructor {
|
|
8
|
-
objectName: string,
|
|
9
|
-
operations: IApiOperations,
|
|
10
|
-
translations?: Record<LanguageCode, Record<string, string>>,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
abstract class ApiInitializer<MetaParams> {
|
|
14
|
-
protected _api: typeof jsWapi;
|
|
15
|
-
protected _operations: IApiOperations<MetaParams>;
|
|
16
|
-
|
|
17
|
-
constructor(settings: ApiObjectInitializerConstructor);
|
|
18
|
-
constructor(objectName: string, operations: IApiOperations<MetaParams>);
|
|
19
|
-
constructor(objectName: string, operations: IApiOperations<MetaParams>, options: Pick<ApiObjectInitializerConstructor, 'translations'>);
|
|
20
|
-
constructor(settings: string | ApiObjectInitializerConstructor, operations?: IApiOperations<MetaParams>, options?: Pick<ApiObjectInitializerConstructor, 'translations'>) {
|
|
21
|
-
this._api = jsWapi;
|
|
22
|
-
const throwError = (msg: string) => {
|
|
23
|
-
throw new Error(msg);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
if (typeof settings === 'string') {
|
|
27
|
-
if (!operations) throwError('The second argument "operations" is required');
|
|
28
|
-
this._operations = operations;
|
|
29
|
-
this.internalCreate(settings);
|
|
30
|
-
options?.translations && this.initTranslation(options.translations);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const {objectName, operations: opers, translations} = settings as ApiObjectInitializerConstructor;
|
|
34
|
-
|
|
35
|
-
if (!opers) throwError('Property "operations" in the settings is required');
|
|
36
|
-
this._operations = opers;
|
|
37
|
-
this.internalCreate(objectName);
|
|
38
|
-
translations && this.initTranslation(translations);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
protected _initOperations(objectName?: string) {
|
|
42
|
-
for (const operationName in this._operations) {
|
|
43
|
-
this.putOperation(operationName, objectName);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
protected abstract internalCreate(objectName: string): void;
|
|
48
|
-
protected abstract putOperation(operationName: string, objectName?: string): void;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Инициализация словаря переводов.
|
|
52
|
-
* @param translations
|
|
53
|
-
* @example Пример строки перевода
|
|
54
|
-
* { ...
|
|
55
|
-
* "ru": {"key": 'some text {0} {1}'}
|
|
56
|
-
* ...
|
|
57
|
-
* }
|
|
58
|
-
*
|
|
59
|
-
* core.t('key', ['test1', 'test2']); // 'some text test1 test2'
|
|
60
|
-
*/
|
|
61
|
-
initTranslation(translations: Record<LanguageCode, Record<string, string>>) {
|
|
62
|
-
UserMessages.appendDictionary(translations);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export default class ApiObjectInitializer<MetaParams = undefined> extends ApiInitializer<MetaParams> {
|
|
68
|
-
private jsWapiObject: jsWapi.JSWapiObject;
|
|
69
|
-
|
|
70
|
-
protected internalCreate(objectName: string) {
|
|
71
|
-
this._api.putJSWapiObject(objectName, (jsWapiObject) => {
|
|
72
|
-
this.jsWapiObject = jsWapiObject;
|
|
73
|
-
this._initOperations(objectName);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
protected putOperation(operationName: string, objectName?: string) {
|
|
78
|
-
this.jsWapiObject.putJSWapiOper(operationName, (jsWapiRequest, jsWapiResponse) => {
|
|
79
|
-
const request = new ApiRequest(jsWapiRequest, objectName)
|
|
80
|
-
return this._operations[operationName](
|
|
81
|
-
new ApiCore({http: this.jsWapiObject, request}),
|
|
82
|
-
request,
|
|
83
|
-
new ApiResponse(jsWapiResponse, objectName)
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
};
|