d5-api-initializer 0.0.2-alpha.0 → 0.0.2-alpha.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "d5-api-initializer",
3
- "version": "0.0.2-alpha.0",
3
+ "version": "0.0.2-alpha.2",
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
  },
@@ -1,3 +1,100 @@
1
+ declare namespace jsWapi {
2
+ type JSWapiInvoker = {
3
+ setFilters(filters: any): JSWapiInvoker;
4
+ setParams(params: any): JSWapiInvoker;
5
+ setRowsPerPage(number: number): JSWapiInvoker;
6
+ setPage(number: number): JSWapiInvoker;
7
+ setPagesPredict(number: number): JSWapiInvoker;
8
+ setColumns(columns: string[]): JSWapiInvoker;
9
+ addColumns(columns: string[]): JSWapiInvoker;
10
+ setSorts(sorts: string[]): JSWapiInvoker;
11
+ addSorts(sorts: string[]): JSWapiInvoker;
12
+ setAggregatedColumns(columns: any): JSWapiInvoker;
13
+ putAggregatedColumns(columns: any): JSWapiInvoker;
14
+ setNestedColumns(columns: any): JSWapiInvoker;
15
+ putNestedColumns(columns: any): JSWapiInvoker;
16
+ setHierarchy(parentColumn: string, requestKind?: number): JSWapiInvoker;
17
+ setSrcRequest(srcRequest: any): JSWapiInvoker;
18
+ setFirstRows(number: number): JSWapiInvoker;
19
+ setOperRightCheck(check: boolean): JSWapiInvoker;
20
+ putRequest(objectName: string, req: any): JSWapiInvoker;
21
+ setRequest(req: any): JSWapiInvoker;
22
+ getRequest(objectName?: string): Record<string, any>[];
23
+ getSrcRequest(): Record<string, any>[];
24
+ getFirstRows(): number;
25
+ invoke(): JSWapiResponse;
26
+ };
27
+ type JSWapiRequest = {
28
+ getColumns(): string[];
29
+ getSorts(): string[];
30
+ getAggregatedColumns(): any;
31
+ getNestedColumns(): any;
32
+ getFilters(): any;
33
+ getParams(): any;
34
+ getUserId(): number;
35
+ getPage(): number;
36
+ getFirstRows(): number;
37
+ getRowsPerPage(): number;
38
+ getLanguage(): string;
39
+ getRequest(object: string): Record<string, any>[];
40
+ getFilter(filterName: string): any;
41
+ getFilterEqualOneValue(filterName: string): any;
42
+ getParam(filterName: string): any;
43
+ getExcelFileAsJson(fileRequestId: string): any;
44
+ getFileAsString(fileRequestId: string): any;
45
+ setColumns(columns: string[]): JSWapiRequest;
46
+ setSorts(sorts: string[]): JSWapiRequest;
47
+ setAggregatedColumns(columns: any): JSWapiRequest;
48
+ setNestedColumns(columns: any): JSWapiRequest;
49
+ setFilters(filters: any): JSWapiRequest;
50
+ setParams(params: any): JSWapiRequest;
51
+ setPage(number: number): JSWapiRequest;
52
+ setRowsPerPage(number: number): JSWapiRequest;
53
+ setFirstRows(number: number): JSWapiRequest;
54
+ setRequest(request: any): JSWapiRequest;
55
+ setHierarchy(parentColumn: string, requestKind?: number): JSWapiRequest;
56
+ };
57
+ type JSWapiResponse = {};
58
+ type BinaryDataStream = unknown;
59
+ interface JSWapiHttpResponse {
60
+ getStatusCode(): number;
61
+ getBody(): string;
62
+ getBodyAsInputStream(): BinaryDataStream;
63
+ getHeader(name: string): string;
64
+ isSuccessful(): boolean;
65
+ }
66
+ type IHttpCallback = (resp: JSWapiHttpResponse) => any;
67
+ interface JSWapiHttp {
68
+ setHeader(key: string, value: string): JSWapiHttp;
69
+ setTimeout(milliseconds: number): JSWapiHttp;
70
+ GET(cb: IHttpCallback): any;
71
+ POST(body: string, cb: IHttpCallback): any;
72
+ PUT(body: string, cb: IHttpCallback): any;
73
+ PATCH(body: string, cb: IHttpCallback): any;
74
+ }
75
+ type JSWapiMeta<Params = {}> = {
76
+ parameters?: Params;
77
+ externalObject?: string;
78
+ objectName: string;
79
+ externalFieldsMap?: Record<string, string>;
80
+ };
81
+ interface JSWapiObject {
82
+ getName(): string;
83
+ newJSWapiHttp(url: string): JSWapiHttp;
84
+ putJSWapiOper(operation: string, callback: (request: JSWapiRequest, response: JSWapiResponse) => void): void;
85
+ }
86
+ function putJSWapiObject(objectName: string, init: (object: JSWapiObject) => void): void;
87
+ interface JSWapiEngine {
88
+ getExternalName(): string;
89
+ getExternalObjectFields(): Record<string, string>;
90
+ getExternalSystemParameters(): Record<string, any>;
91
+ getName(): string;
92
+ newJSWapiHttp(url: string): JSWapiHttp;
93
+ putJSWapiOper(operation: string, callback: (jsWapiRequest: JSWapiRequest, jsWapiResponse: JSWapiResponse) => void): void;
94
+ }
95
+ function setJSWapiEngine(init: (object: JSWapiEngine) => void): void;
96
+ }
97
+
1
98
  declare class ApiHttpResponse {
2
99
  private readonly _jsWapiHttpResponse;
3
100
  constructor(jsWapiHttpResponse: jsWapi.JSWapiHttpResponse);
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();
@@ -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
- }
@@ -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,9 +0,0 @@
1
- export default class ApiJoinInvoker {
2
- readonly _jsWapiJoinInvoker: any;
3
-
4
- constructor(jsWapiJoinInvoker: any) {
5
- this._jsWapiJoinInvoker = jsWapiJoinInvoker;
6
- }
7
-
8
- //TODO: implement methods.
9
- }
@@ -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
- }