@oino-ts/db 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 (39) hide show
  1. package/dist/cjs/OINODb.js +6 -144
  2. package/dist/cjs/OINODbApi.js +50 -318
  3. package/dist/cjs/OINODbConfig.js +10 -10
  4. package/dist/cjs/OINODbConstants.js +10 -0
  5. package/dist/cjs/OINODbDataField.js +28 -70
  6. package/dist/cjs/OINODbDataModel.js +29 -143
  7. package/dist/cjs/OINODbFactory.js +2 -2
  8. package/dist/cjs/OINODbModelSet.js +23 -23
  9. package/dist/cjs/OINODbQueryParams.js +201 -0
  10. package/dist/cjs/index.js +12 -41
  11. package/dist/esm/OINODb.js +6 -142
  12. package/dist/esm/OINODbApi.js +49 -314
  13. package/dist/esm/OINODbConstants.js +7 -0
  14. package/dist/esm/OINODbDataModel.js +29 -143
  15. package/dist/esm/OINODbFactory.js +1 -1
  16. package/dist/esm/OINODbQueryParams.js +194 -0
  17. package/dist/esm/index.js +4 -14
  18. package/dist/types/OINODb.d.ts +6 -173
  19. package/dist/types/OINODbApi.d.ts +18 -104
  20. package/dist/types/OINODbConstants.d.ts +23 -0
  21. package/dist/types/OINODbDataModel.d.ts +7 -61
  22. package/dist/types/OINODbFactory.d.ts +5 -2
  23. package/dist/types/OINODbQueryParams.d.ts +72 -0
  24. package/dist/types/index.d.ts +4 -108
  25. package/package.json +37 -37
  26. package/src/OINODb.ts +99 -348
  27. package/src/OINODbApi.test.ts +507 -498
  28. package/src/OINODbApi.ts +389 -667
  29. package/src/OINODbConstants.ts +32 -0
  30. package/src/OINODbDataModel.ts +191 -307
  31. package/src/OINODbFactory.ts +73 -68
  32. package/src/OINODbQueryParams.ts +203 -0
  33. package/src/index.ts +6 -118
  34. package/src/OINODbConfig.ts +0 -98
  35. package/src/OINODbDataField.ts +0 -405
  36. package/src/OINODbModelSet.ts +0 -353
  37. package/src/OINODbParser.ts +0 -438
  38. package/src/OINODbSqlParams.ts +0 -593
  39. package/src/OINODbSwagger.ts +0 -209
@@ -1,209 +0,0 @@
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 { OINODbApi, OINODbDataField } from "./index.js";
8
-
9
- /**
10
- * Static class for Swagger utilities
11
- *
12
- */
13
- export class OINODbSwagger {
14
-
15
- private static _getSchemaApiMethodParamsQueryId(): any {
16
- return {
17
- "schema": {
18
- "type": "string"
19
- },
20
- "in": "path",
21
- "name": "id",
22
- "required": true
23
- }
24
- }
25
-
26
- private static _getSchemaApiMethodParamsBody(tableName:string): any {
27
- return {
28
- "required": true,
29
- "content": {
30
- "application/json": {
31
- "schema": {
32
- "$ref": "#/components/schemas/" + tableName
33
- }
34
- }
35
- }
36
- }
37
- }
38
-
39
- private static _getSchemaApiMethodDescription(method:string, tableName:string, hasQueryIdParam:boolean): any {
40
- if (hasQueryIdParam) {
41
- return method.toUpperCase() + " " + tableName + " object"
42
- } else {
43
- return method.toUpperCase() + " " +tableName + " object array"
44
- }
45
- }
46
-
47
- private static _getSchemaApiMethodOperationId(method:string, tableName:string, hasQueryIdParam:boolean): any {
48
- if (hasQueryIdParam) {
49
- return method+tableName
50
- } else {
51
- return method+tableName+"All"
52
- }
53
- }
54
-
55
- private static _getSchemaOinoResponse(): any {
56
- return {
57
- "type": "object",
58
- "properties": {
59
- "success": {
60
- "type": "boolean"
61
- },
62
- "status": {
63
- "type": "number"
64
- },
65
- "statusText": {
66
- "type": "string"
67
- },
68
- "messages": {
69
- "type": "array",
70
- "items": {
71
- "type": "string"
72
- }
73
- }
74
- },
75
- "required": [
76
- "success",
77
- "status",
78
- "statusText",
79
- "messages"
80
- ]
81
- }
82
- }
83
-
84
- private static _getSchemaFieldType(field:OINODbDataField): any {
85
- let type_string:string
86
- if (field.type == "boolean") {
87
- type_string = "boolean"
88
- } else if (field.type == "integer" || field.type == "number") {
89
- type_string = "number"
90
- } else {
91
- type_string = "string"
92
- }
93
- if (!field.fieldParams.isNotNull) {
94
- return {
95
- "anyOf": [
96
- {
97
- "type": type_string
98
- },
99
- {
100
- "type": "null"
101
- }
102
- ]
103
- }
104
- } else {
105
- return { type: type_string }
106
- }
107
- }
108
-
109
- private static _getSwaggerApiType(api:OINODbApi):any {
110
- let result:any = {
111
- type: "object",
112
- properties: {},
113
- required: []
114
- }
115
- let field:OINODbDataField
116
- for (field of api.datamodel.fields) {
117
- result.properties[field.name] = this._getSchemaFieldType(field)
118
- if (field.fieldParams.isPrimaryKey) {
119
- result.required.push(field.name)
120
- }
121
- }
122
- return result
123
- }
124
-
125
- private static _getSchemaType(tableName:string, hasQueryIdParam:boolean, hasResultData:boolean) {
126
- if (hasResultData && hasQueryIdParam) {
127
- return { "$ref": "#/components/schemas/" + tableName }
128
-
129
- } else if (hasResultData) {
130
- return { type : "array", items : { "$ref": "#/components/schemas/" + tableName } }
131
-
132
- } else if (hasQueryIdParam) {
133
- return { "$ref": "#/components/schemas/OINOResponse" }
134
-
135
- } else {
136
- return { "$ref": "#/components/schemas/OINOResponse" }
137
- }
138
- }
139
-
140
- private static _getSchemaApiMethodParams(hasQueryIdParam:boolean) {
141
- if (hasQueryIdParam) {
142
- return [ this._getSchemaApiMethodParamsQueryId() ]
143
- } else {
144
- return [ ]
145
- }
146
- }
147
-
148
- private static _getSchemaApiMethod(method:string, tableName:string, hasQueryIdParam:boolean, hasBody:boolean, hasResultData:boolean) {
149
- const result:any = {
150
- responses: {
151
- 200: { description: this._getSchemaApiMethodDescription(method, tableName, hasQueryIdParam), content: { "application/json": { schema: this._getSchemaType(tableName, hasQueryIdParam, hasResultData) } } }
152
- },
153
- "operationId": this._getSchemaApiMethodOperationId(method, tableName, hasQueryIdParam),
154
- "parameters": this._getSchemaApiMethodParams(hasQueryIdParam)
155
- }
156
- if (hasBody) {
157
- result["requestBody"] = this._getSchemaApiMethodParamsBody(tableName)
158
- }
159
- return result
160
- }
161
-
162
- private static _getSwaggerApiPath(tableName:string, hasQueryIdParam:boolean):any {
163
-
164
- if (hasQueryIdParam) {
165
- return {
166
- get: this._getSchemaApiMethod("get", tableName, hasQueryIdParam, false, true),
167
- put: this._getSchemaApiMethod("put", tableName, hasQueryIdParam, true, false),
168
- delete: this._getSchemaApiMethod("delete", tableName, hasQueryIdParam, false, false)
169
- }
170
- } else {
171
- return {
172
- get: this._getSchemaApiMethod("get", tableName, hasQueryIdParam, false, true),
173
- post: this._getSchemaApiMethod("post", tableName, hasQueryIdParam, true, false)
174
- }
175
- }
176
- }
177
-
178
- /**
179
- * Returns swagger.json as object of the given API's.
180
- *
181
- * @param apis array of API's use for Swagger definition
182
- *
183
- */
184
- static getApiDefinition(apis:OINODbApi[]): any {
185
- let result:any = {
186
- "openapi": "3.1.0",
187
- "info": {
188
- "title": "",
189
- "description": "",
190
- "version": ""
191
- },
192
- "paths": {
193
-
194
- },
195
- "components": {
196
- "schemas": {
197
- OINOResponse: this._getSchemaOinoResponse()
198
- }
199
- }
200
- }
201
- for (let i=0; i<apis.length; i++) {
202
- const table_name = apis[i].params.tableName
203
- result.paths["/" + table_name] = this._getSwaggerApiPath(table_name, false)
204
- result.paths["/" + table_name + "/{id}"] = this._getSwaggerApiPath(table_name, true)
205
- result.components.schemas[table_name] = this._getSwaggerApiType(apis[i])
206
- }
207
- return result
208
- }
209
- }