@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.
- package/README.md +183 -0
- package/dist/cjs/OINOApi.js +322 -0
- package/dist/cjs/OINOConfig.js +104 -0
- package/dist/cjs/OINOConstants.js +42 -0
- package/dist/cjs/OINODataField.js +346 -0
- package/dist/cjs/OINODataModel.js +182 -0
- package/dist/cjs/OINODataSource.js +165 -0
- package/dist/cjs/OINOFormatter.js +6 -5
- package/dist/cjs/OINOHtmlTemplate.js +21 -18
- package/dist/cjs/OINOModelSet.js +333 -0
- package/dist/cjs/OINOParser.js +448 -0
- package/dist/cjs/OINOQueryParams.js +434 -0
- package/dist/cjs/OINORequest.js +21 -13
- package/dist/cjs/OINOResult.js +13 -12
- package/dist/cjs/OINOStr.js +11 -11
- package/dist/cjs/OINOSwagger.js +205 -0
- package/dist/cjs/index.js +57 -39
- package/dist/esm/OINOApi.js +315 -0
- package/dist/esm/OINOConfig.js +100 -0
- package/dist/esm/OINOConstants.js +39 -0
- package/dist/esm/OINODataField.js +337 -0
- package/dist/esm/OINODataModel.js +178 -0
- package/dist/esm/OINODataSource.js +159 -0
- package/dist/esm/OINOFormatter.js +2 -1
- package/dist/esm/OINOHtmlTemplate.js +4 -1
- package/dist/esm/OINOModelSet.js +329 -0
- package/dist/esm/OINOParser.js +444 -0
- package/dist/esm/OINOQueryParams.js +426 -0
- package/dist/esm/OINORequest.js +9 -1
- package/dist/esm/OINOResult.js +2 -1
- package/dist/esm/OINOStr.js +1 -1
- package/dist/esm/OINOSwagger.js +201 -0
- package/dist/esm/index.js +14 -32
- package/dist/types/OINOApi.d.ts +191 -0
- package/dist/types/OINOConfig.d.ts +63 -0
- package/dist/types/OINOConstants.d.ts +51 -0
- package/dist/types/OINODataField.d.ts +209 -0
- package/dist/types/OINODataModel.d.ts +78 -0
- package/dist/types/OINODataSource.d.ts +184 -0
- package/dist/types/OINOHtmlTemplate.d.ts +1 -1
- package/dist/types/OINOModelSet.d.ts +64 -0
- package/dist/types/OINOParser.d.ts +42 -0
- package/dist/types/OINOQueryParams.d.ts +270 -0
- package/dist/types/OINORequest.d.ts +4 -1
- package/dist/types/OINOResult.d.ts +1 -1
- package/dist/types/OINOStr.d.ts +1 -1
- package/dist/types/OINOSwagger.d.ts +25 -0
- package/dist/types/index.d.ts +14 -31
- package/package.json +32 -32
- package/src/OINOApi.ts +429 -0
- package/src/OINOBenchmark.ts +323 -323
- package/src/OINOConfig.ts +113 -0
- package/src/OINOConstants.ts +59 -0
- package/src/OINODataField.ts +371 -0
- package/src/OINODataModel.ts +187 -0
- package/src/OINODataSource.ts +280 -0
- package/src/OINOFormatter.ts +166 -165
- package/src/OINOHeaders.ts +51 -51
- package/src/OINOHtmlTemplate.test.ts +114 -114
- package/src/OINOHtmlTemplate.ts +225 -222
- package/src/OINOLog.ts +292 -292
- package/src/OINOModelSet.ts +359 -0
- package/src/OINOParser.ts +441 -0
- package/src/OINOQueryParams.ts +449 -0
- package/src/OINORequest.ts +204 -196
- package/src/OINOResult.ts +331 -330
- package/src/OINOStr.ts +254 -254
- package/src/OINOSwagger.ts +213 -0
- 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 {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
export
|
|
18
|
-
|
|
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"
|