@oino-ts/common 0.21.2 → 1.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 (69) hide show
  1. package/README.md +183 -0
  2. package/dist/cjs/OINOApi.js +322 -0
  3. package/dist/cjs/OINOConfig.js +104 -0
  4. package/dist/cjs/OINOConstants.js +42 -0
  5. package/dist/cjs/OINODataField.js +346 -0
  6. package/dist/cjs/OINODataModel.js +182 -0
  7. package/dist/cjs/OINODataSource.js +165 -0
  8. package/dist/cjs/OINOFormatter.js +6 -5
  9. package/dist/cjs/OINOHtmlTemplate.js +21 -18
  10. package/dist/cjs/OINOModelSet.js +333 -0
  11. package/dist/cjs/OINOParser.js +448 -0
  12. package/dist/cjs/OINOQueryParams.js +434 -0
  13. package/dist/cjs/OINORequest.js +21 -13
  14. package/dist/cjs/OINOResult.js +13 -12
  15. package/dist/cjs/OINOStr.js +11 -11
  16. package/dist/cjs/OINOSwagger.js +205 -0
  17. package/dist/cjs/index.js +57 -39
  18. package/dist/esm/OINOApi.js +315 -0
  19. package/dist/esm/OINOConfig.js +100 -0
  20. package/dist/esm/OINOConstants.js +39 -0
  21. package/dist/esm/OINODataField.js +337 -0
  22. package/dist/esm/OINODataModel.js +178 -0
  23. package/dist/esm/OINODataSource.js +159 -0
  24. package/dist/esm/OINOFormatter.js +2 -1
  25. package/dist/esm/OINOHtmlTemplate.js +4 -1
  26. package/dist/esm/OINOModelSet.js +329 -0
  27. package/dist/esm/OINOParser.js +444 -0
  28. package/dist/esm/OINOQueryParams.js +426 -0
  29. package/dist/esm/OINORequest.js +9 -1
  30. package/dist/esm/OINOResult.js +2 -1
  31. package/dist/esm/OINOStr.js +1 -1
  32. package/dist/esm/OINOSwagger.js +201 -0
  33. package/dist/esm/index.js +14 -32
  34. package/dist/types/OINOApi.d.ts +191 -0
  35. package/dist/types/OINOConfig.d.ts +63 -0
  36. package/dist/types/OINOConstants.d.ts +51 -0
  37. package/dist/types/OINODataField.d.ts +209 -0
  38. package/dist/types/OINODataModel.d.ts +78 -0
  39. package/dist/types/OINODataSource.d.ts +184 -0
  40. package/dist/types/OINOHtmlTemplate.d.ts +1 -1
  41. package/dist/types/OINOModelSet.d.ts +64 -0
  42. package/dist/types/OINOParser.d.ts +42 -0
  43. package/dist/types/OINOQueryParams.d.ts +270 -0
  44. package/dist/types/OINORequest.d.ts +4 -1
  45. package/dist/types/OINOResult.d.ts +1 -1
  46. package/dist/types/OINOStr.d.ts +1 -1
  47. package/dist/types/OINOSwagger.d.ts +25 -0
  48. package/dist/types/index.d.ts +14 -31
  49. package/package.json +32 -32
  50. package/src/OINOApi.ts +429 -0
  51. package/src/OINOBenchmark.ts +323 -323
  52. package/src/OINOConfig.ts +113 -0
  53. package/src/OINOConstants.ts +59 -0
  54. package/src/OINODataField.ts +371 -0
  55. package/src/OINODataModel.ts +187 -0
  56. package/src/OINODataSource.ts +280 -0
  57. package/src/OINOFormatter.ts +166 -165
  58. package/src/OINOHeaders.ts +51 -51
  59. package/src/OINOHtmlTemplate.test.ts +114 -114
  60. package/src/OINOHtmlTemplate.ts +225 -222
  61. package/src/OINOLog.ts +292 -292
  62. package/src/OINOModelSet.ts +359 -0
  63. package/src/OINOParser.ts +441 -0
  64. package/src/OINOQueryParams.ts +449 -0
  65. package/src/OINORequest.ts +204 -196
  66. package/src/OINOResult.ts +331 -330
  67. package/src/OINOStr.ts +254 -254
  68. package/src/OINOSwagger.ts +213 -0
  69. package/src/index.ts +18 -38
@@ -0,0 +1,213 @@
1
+ /*
2
+ * This Source Code Form is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
+ */
6
+
7
+ import { OINOApi } from "./OINOApi.js"
8
+ import { OINODataField } from "./OINODataField.js"
9
+
10
+ /**
11
+ * Static class for Swagger utilities
12
+ *
13
+ */
14
+ export class OINOSwagger {
15
+
16
+ private static _getSchemaApiMethodParamsQueryId(): any {
17
+ return {
18
+ "schema": {
19
+ "type": "string"
20
+ },
21
+ "in": "path",
22
+ "name": "id",
23
+ "required": true
24
+ }
25
+ }
26
+
27
+ private static _getSchemaApiMethodParamsBody(tableName:string): any {
28
+ return {
29
+ "required": true,
30
+ "content": {
31
+ "application/json": {
32
+ "schema": {
33
+ "$ref": "#/components/schemas/" + tableName
34
+ }
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ private static _getSchemaApiMethodDescription(method:string, tableName:string, hasQueryIdParam:boolean): any {
41
+ if (hasQueryIdParam) {
42
+ return method.toUpperCase() + " " + tableName + " object"
43
+ } else {
44
+ return method.toUpperCase() + " " +tableName + " object array"
45
+ }
46
+ }
47
+
48
+ private static _getSchemaApiMethodOperationId(method:string, tableName:string, hasQueryIdParam:boolean): any {
49
+ if (hasQueryIdParam) {
50
+ return method+tableName
51
+ } else {
52
+ return method+tableName+"All"
53
+ }
54
+ }
55
+
56
+ private static _getSchemaOinoResponse(): any {
57
+ return {
58
+ "type": "object",
59
+ "properties": {
60
+ "success": {
61
+ "type": "boolean"
62
+ },
63
+ "status": {
64
+ "type": "number"
65
+ },
66
+ "statusText": {
67
+ "type": "string"
68
+ },
69
+ "messages": {
70
+ "type": "array",
71
+ "items": {
72
+ "type": "string"
73
+ }
74
+ }
75
+ },
76
+ "required": [
77
+ "success",
78
+ "status",
79
+ "statusText",
80
+ "messages"
81
+ ]
82
+ }
83
+ }
84
+
85
+ private static _getSchemaFieldType(field:OINODataField): any {
86
+ let type_string:string
87
+ if (field.type == "boolean") {
88
+ type_string = "boolean"
89
+ } else if (field.type == "integer" || field.type == "number") {
90
+ type_string = "number"
91
+ } else {
92
+ type_string = "string"
93
+ }
94
+ if (!field.fieldParams.isNotNull) {
95
+ return {
96
+ "anyOf": [
97
+ {
98
+ "type": type_string
99
+ },
100
+ {
101
+ "type": "null"
102
+ }
103
+ ]
104
+ }
105
+ } else {
106
+ return { type: type_string }
107
+ }
108
+ }
109
+
110
+ private static _getSwaggerApiType(api:OINOApi):any {
111
+ let result:any = {
112
+ type: "object",
113
+ properties: {},
114
+ required: []
115
+ }
116
+ let field:OINODataField
117
+ for (field of api.datamodel!.fields) {
118
+ result.properties[field.name] = this._getSchemaFieldType(field)
119
+ if (field.fieldParams.isPrimaryKey) {
120
+ result.required.push(field.name)
121
+ }
122
+ }
123
+ return result
124
+ }
125
+
126
+ private static _getSchemaType(tableName:string, hasQueryIdParam:boolean, hasResultData:boolean) {
127
+ if (hasResultData && hasQueryIdParam) {
128
+ return { "$ref": "#/components/schemas/" + tableName }
129
+
130
+ } else if (hasResultData) {
131
+ return { type : "array", items : { "$ref": "#/components/schemas/" + tableName } }
132
+
133
+ } else if (hasQueryIdParam) {
134
+ return { "$ref": "#/components/schemas/OINOResponse" }
135
+
136
+ } else {
137
+ return { "$ref": "#/components/schemas/OINOResponse" }
138
+ }
139
+ }
140
+
141
+ private static _getSchemaApiMethodParams(hasQueryIdParam:boolean) {
142
+ if (hasQueryIdParam) {
143
+ return [ this._getSchemaApiMethodParamsQueryId() ]
144
+ } else {
145
+ return [ ]
146
+ }
147
+ }
148
+
149
+ private static _getSchemaApiMethod(method:string, tableName:string, hasQueryIdParam:boolean, hasBody:boolean, hasResultData:boolean) {
150
+ const result:any = {
151
+ responses: {
152
+ 200: { description: this._getSchemaApiMethodDescription(method, tableName, hasQueryIdParam), content: { "application/json": { schema: this._getSchemaType(tableName, hasQueryIdParam, hasResultData) } } }
153
+ },
154
+ "operationId": this._getSchemaApiMethodOperationId(method, tableName, hasQueryIdParam),
155
+ "parameters": this._getSchemaApiMethodParams(hasQueryIdParam)
156
+ }
157
+ if (hasBody) {
158
+ result["requestBody"] = this._getSchemaApiMethodParamsBody(tableName)
159
+ }
160
+ return result
161
+ }
162
+
163
+ private static _getSwaggerApiPath(tableName:string, hasQueryIdParam:boolean):any {
164
+
165
+ if (hasQueryIdParam) {
166
+ return {
167
+ get: this._getSchemaApiMethod("get", tableName, hasQueryIdParam, false, true),
168
+ put: this._getSchemaApiMethod("put", tableName, hasQueryIdParam, true, false),
169
+ delete: this._getSchemaApiMethod("delete", tableName, hasQueryIdParam, false, false)
170
+ }
171
+ } else {
172
+ return {
173
+ get: this._getSchemaApiMethod("get", tableName, hasQueryIdParam, false, true),
174
+ post: this._getSchemaApiMethod("post", tableName, hasQueryIdParam, true, false)
175
+ }
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Returns swagger.json as object of the given API's.
181
+ *
182
+ * @param apis array of API's use for Swagger definition
183
+ *
184
+ */
185
+ static getApiDefinition(apis:OINOApi[]): any {
186
+ let result:any = {
187
+ "openapi": "3.1.0",
188
+ "info": {
189
+ "title": "",
190
+ "description": "",
191
+ "version": ""
192
+ },
193
+ "paths": {
194
+
195
+ },
196
+ "components": {
197
+ "schemas": {
198
+ OINOResponse: this._getSchemaOinoResponse()
199
+ }
200
+ }
201
+ }
202
+ for (let i=0; i<apis.length; i++) {
203
+ if (!apis[i].initialized) {
204
+ throw new Error("API " + apis[i].params.tableName + " is not initialized, cannot create Swagger definition")
205
+ }
206
+ const table_name = apis[i].params.tableName
207
+ result.paths["/" + table_name] = this._getSwaggerApiPath(table_name, false)
208
+ result.paths["/" + table_name + "/{id}"] = this._getSwaggerApiPath(table_name, true)
209
+ result.components.schemas[table_name] = this._getSwaggerApiType(apis[i])
210
+ }
211
+ return result
212
+ }
213
+ }
package/src/index.ts CHANGED
@@ -1,38 +1,18 @@
1
- export { OINOBenchmark, OINOMemoryBenchmark } from "./OINOBenchmark.js"
2
- export { OINOLog, OINOLogLevel, OINOConsoleLog } from "./OINOLog.js"
3
- export { OINOResult, OINOHttpResult, type OINOResultInit, type OINOHttpResultInit } from "./OINOResult.js"
4
- export { OINORequest, OINOHttpRequest, type OINOHttpData, type OINORequestInit, type OINOHttpRequestInit } from "./OINORequest.js"
5
- export { OINOStr } from "./OINOStr.js"
6
- export { OINOHtmlTemplate } from "./OINOHtmlTemplate.js"
7
- export { OINOFormatter, OINO_EMPTY_FORMATTER } from "./OINOFormatter.js"
8
- export { OINOHeaders, type OINOHeadersInit } from "./OINOHeaders.js"
9
-
10
- /** OINO error message prefix */
11
- export const OINO_ERROR_PREFIX = "OINO ERROR"
12
- /** OINO warning message prefix */
13
- export const OINO_WARNING_PREFIX = "OINO WARNING"
14
- /** OINO info message prefix */
15
- export const OINO_INFO_PREFIX = "OINO INFO"
16
- /** OINO debug message prefix */
17
- export const OINO_DEBUG_PREFIX = "OINO DEBUG"
18
- /** Name of the OINOContentType-parameter request */
19
- export const OINO_REQUEST_TYPE_PARAM = "oinorequesttype"
20
- /** Name of the OINOContentType-parameter request */
21
- export const OINO_RESPONSE_TYPE_PARAM = "oinoresponsetype"
22
-
23
- /**
24
- * Supported content format mime-types
25
- */
26
- export enum OINOContentType {
27
- /** JSON encoded data */
28
- json='application/json',
29
- /** CSV encoded data */
30
- csv='text/csv',
31
- /** Multipart encoded form data */
32
- formdata='multipart/form-data',
33
- /** URL encoded form data */
34
- urlencode='application/x-www-form-urlencoded',
35
- /** HTML encoded data (output only) */
36
- html='text/html'
37
- }
38
-
1
+ export { OINOApi, OINOApiRequest, OINOApiResult, OINOApiHtmlTemplate, type OINOApiParams, type OINOApiData, type OINOApiRequestInit } from "./OINOApi.js"
2
+ export { OINOBenchmark, OINOMemoryBenchmark } from "./OINOBenchmark.js"
3
+ export { OINOConfig } from "./OINOConfig.js"
4
+ export { OINO_ERROR_PREFIX, OINO_WARNING_PREFIX, OINO_INFO_PREFIX, OINO_DEBUG_PREFIX, OINO_REQUEST_TYPE_PARAM, OINO_RESPONSE_TYPE_PARAM, OINOContentType, type OINODataFieldParams, type OINODataCell, type OINODataRow, OINO_EMPTY_ROW, OINO_EMPTY_ROWS } from "./OINOConstants.js"
5
+ export { OINODataModel } from "./OINODataModel.js"
6
+ export { OINODataSource, OINODataSet, OINOMemoryDataset } from "./OINODataSource.js"
7
+ export { OINODataField, OINOStringDataField, OINONumberDataField, OINOBooleanDataField, OINODatetimeDataField, OINOBlobDataField, type OINODataFieldFilter } from "./OINODataField.js"
8
+ export { OINOFormatter, OINO_EMPTY_FORMATTER } from "./OINOFormatter.js"
9
+ export { OINOHeaders, type OINOHeadersInit } from "./OINOHeaders.js"
10
+ export { OINOHtmlTemplate } from "./OINOHtmlTemplate.js"
11
+ export { OINOLog, OINOLogLevel, OINOConsoleLog } from "./OINOLog.js"
12
+ export { OINOModelSet } from "./OINOModelSet.js"
13
+ export { OINOParser } from "./OINOParser.js"
14
+ export { OINOQueryBooleanOperation, OINOQueryComparison, OINOQueryNullCheck, OINOQueryAggregateFunctions, OINOQuerySelect, OINOQueryFilter, OINOQueryOrder, OINOQueryLimit, OINOQueryAggregate, type OINOQueryParams } from "./OINOQueryParams.js"
15
+ export { OINORequest, OINOHttpRequest, type OINOHttpData, type OINORequestInit, type OINOHttpRequestInit } from "./OINORequest.js"
16
+ export { OINOResult, OINOHttpResult, type OINOResultInit, type OINOHttpResultInit } from "./OINOResult.js"
17
+ export { OINOStr } from "./OINOStr.js"
18
+ export { OINOSwagger } from "./OINOSwagger.js"