@team-internet/apiconnector 10.0.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.
Files changed (58) hide show
  1. package/.devcontainer/Dockerfile +66 -0
  2. package/.devcontainer/devcontainer.json +30 -0
  3. package/.devcontainer/docker-compose.yml +11 -0
  4. package/.devcontainer/supporting_files/configuration/.czrc +1 -0
  5. package/.devcontainer/supporting_files/configuration/.p10k.zsh +1735 -0
  6. package/.devcontainer/supporting_files/configuration/.zshrc +23 -0
  7. package/.devcontainer/supporting_files/configuration/p10k-instant-prompt-vscode.zsh +323 -0
  8. package/.devcontainer/supporting_files/scripts/post-create.sh +11 -0
  9. package/.nycrc +6 -0
  10. package/CHANGELOG.md +582 -0
  11. package/CONTRIBUTING.md +132 -0
  12. package/LICENSE +21 -0
  13. package/README.md +56 -0
  14. package/dist/apiclient.d.ts +233 -0
  15. package/dist/apiclient.js +517 -0
  16. package/dist/column.d.ts +40 -0
  17. package/dist/column.js +52 -0
  18. package/dist/customlogger.d.ts +15 -0
  19. package/dist/customlogger.js +23 -0
  20. package/dist/index.d.ts +16 -0
  21. package/dist/index.js +16 -0
  22. package/dist/logger.d.ts +14 -0
  23. package/dist/logger.js +21 -0
  24. package/dist/record.d.ts +31 -0
  25. package/dist/record.js +42 -0
  26. package/dist/response.d.ts +264 -0
  27. package/dist/response.js +512 -0
  28. package/dist/responseparser.d.ts +1 -0
  29. package/dist/responseparser.js +36 -0
  30. package/dist/responsetemplatemanager.d.ts +65 -0
  31. package/dist/responsetemplatemanager.js +111 -0
  32. package/dist/responsetranslator.d.ts +32 -0
  33. package/dist/responsetranslator.js +144 -0
  34. package/dist/socketconfig.d.ts +62 -0
  35. package/dist/socketconfig.js +107 -0
  36. package/package.json +86 -0
  37. package/src/apiclient.ts +579 -0
  38. package/src/column.ts +57 -0
  39. package/src/customlogger.ts +29 -0
  40. package/src/index.ts +18 -0
  41. package/src/logger.ts +23 -0
  42. package/src/record.ts +46 -0
  43. package/src/response.ts +562 -0
  44. package/src/responseparser.ts +35 -0
  45. package/src/responsetemplatemanager.ts +136 -0
  46. package/src/responsetranslator.ts +191 -0
  47. package/src/socketconfig.ts +116 -0
  48. package/tests/apiclient.spec.ts +610 -0
  49. package/tests/app.js +47 -0
  50. package/tests/column.spec.ts +23 -0
  51. package/tests/index.spec.ts +22 -0
  52. package/tests/record.spec.ts +31 -0
  53. package/tests/response.spec.ts +341 -0
  54. package/tests/responseparser.spec.ts +13 -0
  55. package/tests/responsetemplatemanager.spec.ts +52 -0
  56. package/tests/socketconfig.spec.ts +14 -0
  57. package/tsconfig.json +7 -0
  58. package/typedoc.json +7 -0
package/dist/logger.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Logger class
3
+ */
4
+ export class Logger {
5
+ /**
6
+ * output/log given data
7
+ * @param post request string used
8
+ * @param r Response object
9
+ * @param error error message or null
10
+ * @return current Logger instance for method chaining
11
+ */
12
+ log(post, r, error = null) {
13
+ console.dir(r.getCommand());
14
+ console.log(post);
15
+ if (error) {
16
+ console.error(`HTTP communication failed: ${error}`);
17
+ }
18
+ console.log(r.getPlain());
19
+ return this;
20
+ }
21
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Record class
3
+ */
4
+ export declare class Record {
5
+ /**
6
+ * row data container
7
+ */
8
+ private data;
9
+ /**
10
+ * Constructor
11
+ * @param data data object (use column names as object keys)
12
+ */
13
+ constructor(data: any);
14
+ /**
15
+ * get row data
16
+ * @returns row data
17
+ */
18
+ getData(): any;
19
+ /**
20
+ * get row data for given column
21
+ * @param key column name
22
+ * @returns row data for given column or null if column does not exist
23
+ */
24
+ getDataByKey(key: string): string | null;
25
+ /**
26
+ * check if record has data for given column
27
+ * @param key column name
28
+ * @returns boolean result
29
+ */
30
+ private hasData;
31
+ }
package/dist/record.js ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Record class
3
+ */
4
+ export class Record {
5
+ /**
6
+ * row data container
7
+ */
8
+ data;
9
+ /**
10
+ * Constructor
11
+ * @param data data object (use column names as object keys)
12
+ */
13
+ constructor(data) {
14
+ this.data = data;
15
+ }
16
+ /**
17
+ * get row data
18
+ * @returns row data
19
+ */
20
+ getData() {
21
+ return this.data;
22
+ }
23
+ /**
24
+ * get row data for given column
25
+ * @param key column name
26
+ * @returns row data for given column or null if column does not exist
27
+ */
28
+ getDataByKey(key) {
29
+ if (this.hasData(key)) {
30
+ return this.data[key];
31
+ }
32
+ return null;
33
+ }
34
+ /**
35
+ * check if record has data for given column
36
+ * @param key column name
37
+ * @returns boolean result
38
+ */
39
+ hasData(key) {
40
+ return Object.prototype.hasOwnProperty.call(this.data, key);
41
+ }
42
+ }
@@ -0,0 +1,264 @@
1
+ import { Column } from "./column.js";
2
+ import { Record } from "./record.js";
3
+ /**
4
+ * Response Class
5
+ */
6
+ export declare class Response {
7
+ /**
8
+ * plain API response
9
+ */
10
+ protected raw: string;
11
+ /**
12
+ * hash representation of plain API response
13
+ */
14
+ protected hash: any;
15
+ /**
16
+ * The API Command used within this request
17
+ */
18
+ private command;
19
+ /**
20
+ * Column names available in this responsse
21
+ * NOTE: this includes also FIRST, LAST, LIMIT, COUNT, TOTAL
22
+ * and maybe further specific columns in case of a list query
23
+ */
24
+ private columnkeys;
25
+ /**
26
+ * Container of Column Instances
27
+ */
28
+ private columns;
29
+ /**
30
+ * Record Index we currently point to in record list
31
+ */
32
+ private recordIndex;
33
+ /**
34
+ * Record List (List of rows)
35
+ */
36
+ private records;
37
+ /**
38
+ * Constructor
39
+ * @param raw API plain response
40
+ * @param cmd API command used within this request
41
+ * @param ph placeholder array to get vars in response description dynamically replaced
42
+ */
43
+ constructor(raw: string, cmd?: any, ph?: any);
44
+ /**
45
+ * Get API response code
46
+ * @returns API response code
47
+ */
48
+ getCode(): number;
49
+ /**
50
+ * Get API response description
51
+ * @returns API response description
52
+ */
53
+ getDescription(): string;
54
+ /**
55
+ * Get Plain API response
56
+ * @returns Plain API response
57
+ */
58
+ getPlain(): string;
59
+ /**
60
+ * Get Queuetime of API response
61
+ * @returns Queuetime of API response
62
+ */
63
+ getQueuetime(): number;
64
+ /**
65
+ * Get API response as Hash
66
+ * @returns API response hash
67
+ */
68
+ getHash(): any;
69
+ /**
70
+ * Get Runtime of API response
71
+ * @returns Runtime of API response
72
+ */
73
+ getRuntime(): number;
74
+ /**
75
+ * Check if current API response represents an error case
76
+ * API response code is an 5xx code
77
+ * @returns boolean result
78
+ */
79
+ isError(): boolean;
80
+ /**
81
+ * Check if current API response represents a success case
82
+ * API response code is an 2xx code
83
+ * @returns boolean result
84
+ */
85
+ isSuccess(): boolean;
86
+ /**
87
+ * Check if current API response represents a temporary error case
88
+ * API response code is an 4xx code
89
+ * @returns boolean result
90
+ */
91
+ isTmpError(): boolean;
92
+ /**
93
+ * Check if current operation is returned as pending
94
+ * @returns boolean result
95
+ */
96
+ isPending(): boolean;
97
+ /**
98
+ * Add a column to the column list
99
+ * @param key column name
100
+ * @param data array of column data
101
+ * @returns Current Response Instance for method chaining
102
+ */
103
+ addColumn(key: string, data: string[]): Response;
104
+ /**
105
+ * Add a record to the record list
106
+ * @param h row hash data
107
+ * @returns Current Response Instance for method chaining
108
+ */
109
+ addRecord(h: any): Response;
110
+ /**
111
+ * Get column by column name
112
+ * @param key column name
113
+ * @returns column instance or null if column does not exist
114
+ */
115
+ getColumn(key: string): Column | null;
116
+ /**
117
+ * Get Data by Column Name and Index
118
+ * @param colkey column name
119
+ * @param index column data index
120
+ * @returns column data at index or null if not found
121
+ */
122
+ getColumnIndex(colkey: string, index: number): string | null;
123
+ /**
124
+ * Get Column Names
125
+ * @returns Array of Column Names
126
+ */
127
+ getColumnKeys(): string[];
128
+ /**
129
+ * Get List of Columns
130
+ * @returns Array of Columns
131
+ */
132
+ getColumns(): Column[];
133
+ /**
134
+ * Get Command used in this request
135
+ * @returns command
136
+ */
137
+ getCommand(): any;
138
+ /**
139
+ * Get Command used in this request in plain text format
140
+ * @return command as plain text
141
+ */
142
+ getCommandPlain(): string;
143
+ /**
144
+ * Get Page Number of current List Query
145
+ * @returns page number or null in case of a non-list response
146
+ */
147
+ getCurrentPageNumber(): number | null;
148
+ /**
149
+ * Get Record of current record index
150
+ * @returns Record or null in case of a non-list response
151
+ */
152
+ getCurrentRecord(): Record | null;
153
+ /**
154
+ * Get Index of first row in this response
155
+ * @returns first row index
156
+ */
157
+ getFirstRecordIndex(): number | null;
158
+ /**
159
+ * Get last record index of the current list query
160
+ * @returns record index or null for a non-list response
161
+ */
162
+ getLastRecordIndex(): number | null;
163
+ /**
164
+ * Get Response as List Hash including useful meta data for tables
165
+ * @returns hash including list meta data and array of rows in hash notation
166
+ */
167
+ getListHash(): any;
168
+ /**
169
+ * Get next record in record list
170
+ * @returns Record or null in case there's no further record
171
+ */
172
+ getNextRecord(): Record | null;
173
+ /**
174
+ * Get Page Number of next list query
175
+ * @returns page number or null if there's no next page
176
+ */
177
+ getNextPageNumber(): number | null;
178
+ /**
179
+ * Get the number of pages available for this list query
180
+ * @returns number of pages
181
+ */
182
+ getNumberOfPages(): number;
183
+ /**
184
+ * Get object containing all paging data
185
+ * @returns paginator data
186
+ */
187
+ getPagination(): any;
188
+ /**
189
+ * Get Page Number of previous list query
190
+ * @returns page number or null if there's no previous page
191
+ */
192
+ getPreviousPageNumber(): number | null;
193
+ /**
194
+ * Get previous record in record list
195
+ * @returns Record or null if there's no previous record
196
+ */
197
+ getPreviousRecord(): Record | null;
198
+ /**
199
+ * Get Record at given index
200
+ * @param idx record index
201
+ * @returns Record or null if index does not exist
202
+ */
203
+ getRecord(idx: number): Record | null;
204
+ /**
205
+ * Get all Records
206
+ * @returns array of records
207
+ */
208
+ getRecords(): Record[];
209
+ /**
210
+ * Get count of rows in this response
211
+ * @returns count of rows
212
+ */
213
+ getRecordsCount(): number;
214
+ /**
215
+ * Get total count of records available for the list query
216
+ * @returns total count of records or count of records for a non-list response
217
+ */
218
+ getRecordsTotalCount(): number;
219
+ /**
220
+ * Get limit(ation) setting of the current list query
221
+ * This is the count of requested rows
222
+ * @returns limit setting or count requested rows
223
+ */
224
+ getRecordsLimitation(): number;
225
+ /**
226
+ * Check if this list query has a next page
227
+ * @returns boolean result
228
+ */
229
+ hasNextPage(): boolean;
230
+ /**
231
+ * Check if this list query has a previous page
232
+ * @returns boolean result
233
+ */
234
+ hasPreviousPage(): boolean;
235
+ /**
236
+ * Reset index in record list back to zero
237
+ * @returns Current Response Instance for method chaining
238
+ */
239
+ rewindRecordList(): Response;
240
+ /**
241
+ * Check if column exists in response
242
+ * @param key column name
243
+ * @returns boolean result
244
+ */
245
+ private hasColumn;
246
+ /**
247
+ * Check if the record list contains a record for the
248
+ * current record index in use
249
+ * @returns boolean result
250
+ */
251
+ private hasCurrentRecord;
252
+ /**
253
+ * Check if the record list contains a next record for the
254
+ * current record index in use
255
+ * @returns boolean result
256
+ */
257
+ private hasNextRecord;
258
+ /**
259
+ * Check if the record list contains a previous record for the
260
+ * current record index in use
261
+ * @returns boolean result
262
+ */
263
+ private hasPreviousRecord;
264
+ }