@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
@@ -1,165 +1,166 @@
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 { OINO_ERROR_PREFIX, OINOLog } from "./index.js"
8
-
9
-
10
-
11
- /**
12
- * Class for formatting strings and values.
13
- *
14
- */
15
- export class OINOFormatter {
16
- static OINO_FORMATTER_REGEXP = /\s?(trim(\(\))?|trimLeft(\(\))?|trimRight(\(\))?|toUpper(\(\))?|toLower(\(\))?|cropLeft\((\d+)\)|cropRight\((\d+)\)|cropToDelimiter\(([^\(\),]+),(\d+)\)|cropFromDelimiter\(([^\(\),]+),(\d+)\)|substring\((\d+),(\d+)\)|replace\(([^\(\),]+),([^\(\),]+)\))\s?$/i
17
- _types: string[]
18
- _params: any[][]
19
-
20
- /**
21
- * Constructor of `OINOFormatter`
22
- * @param types array of formatter types
23
- * @param params array of formatter parameters according to type
24
- */
25
- constructor(types: string[], params: any[][]) {
26
- this._types = types
27
- this._params = params
28
- }
29
-
30
- /**
31
- * Constructor for `OINOFormatter` as parser of http parameter.
32
- *
33
- * @param formatters string or array of strings of serialized representation of formatters with following functions
34
- * - trim()
35
- * - trimLeft()
36
- * - trimRight()
37
- * - toUpper()
38
- * - toLower()
39
- * - cropLeft(charsToCrop)
40
- * - cropRight(charsToCrop)
41
- * - cropToDelimiter(delimiter,offsetChars)
42
- * - cropFromDelimiter(delimiter,offsetChars)
43
- * - substring(start,end)
44
- * - replace(search,replace)
45
- */
46
- static parse(formatters: string|string[]): OINOFormatter {
47
- if (typeof formatters === "string") {
48
- formatters = [formatters]
49
- }
50
- if (!formatters || formatters.length === 0) {
51
- return OINO_EMPTY_FORMATTER
52
-
53
- } else {
54
- const types:string[] = []
55
- const params:any[][] = []
56
- for (let i=0; i<formatters.length; i++) {
57
- let match = formatters[i]?.match(this.OINO_FORMATTER_REGEXP)
58
- if (!match) {
59
- OINOLog.error("@oino-ts/common", "OINOFormatter", "parse", "Invalid formatter string", {formatter:formatters[i]})
60
- throw new Error(OINO_ERROR_PREFIX + "Invalid formatter: " + formatters[i])
61
- } else {
62
- const formatter_type = match[1].toLowerCase().substring(0, match[1].indexOf('('))
63
- const formatter_params: any[] = []
64
- if ((formatter_type === "trim") || (formatter_type === "trimleft") || (formatter_type === "trimright") || (formatter_type === "toupper") || (formatter_type === "tolower")) {
65
- // no parameters
66
-
67
- } else if (formatter_type=== "cropleft") {
68
- formatter_params.push(parseInt(match[7]))
69
-
70
- } else if (formatter_type === "cropright") {
71
- formatter_params.push(parseInt(match[8]))
72
-
73
- } else if (formatter_type === "croptodelimiter") {
74
- formatter_params.push(decodeURIComponent(match[9]), parseInt(match[10]))
75
-
76
- } else if (formatter_type === "cropfromdelimiter") {
77
- formatter_params.push(decodeURIComponent(match[11]), parseInt(match[12]))
78
-
79
- } else if (formatter_type === "substring") {
80
- formatter_params.push(parseInt(match[13]), parseInt(match[14]))
81
-
82
- } else if (formatter_type === "replace") {
83
- formatter_params.push(decodeURIComponent(match[15]), decodeURIComponent(match[16]))
84
- } else {
85
- OINOLog.error("@oino-ts/common", "OINOFormatter", "parse", "Unknown formatter type", {formatter:formatters[i]})
86
- throw new Error(OINO_ERROR_PREFIX + "Unsupported formatter: " + formatters[i])
87
- }
88
- types.push(formatter_type)
89
- params.push(formatter_params)
90
- }
91
- }
92
- return new OINOFormatter(types, params)
93
- }
94
- }
95
-
96
- /**
97
- * Does formatter include any operations.
98
- * @return true if formatter is empty
99
- */
100
- isEmpty():boolean {
101
- return this._types.length === 0
102
- }
103
-
104
- /**
105
- * Applies all formatters in order to given value.
106
- *
107
- * @param value string value to be formatted
108
- * @returns formatted string value
109
- */
110
- format(value: string): string {
111
- let formatted = value
112
- for (let i = 0; i < this._types.length; i++) {
113
- const formatter_type = this._types[i]
114
- const formatter_params = this._params[i]
115
- if (formatter_type === "trim") {
116
- formatted = formatted.trim()
117
-
118
- } else if (formatter_type === "trimleft") {
119
- formatted = formatted.trimStart()
120
-
121
- } else if (formatter_type === "trimright") {
122
- formatted = formatted.trimEnd()
123
-
124
- } else if (formatter_type === "toupper") {
125
- formatted = formatted.toUpperCase()
126
-
127
- } else if (formatter_type === "tolower") {
128
- formatted = formatted.toLowerCase()
129
-
130
- } else if (formatter_type === "cropleft") {
131
- formatted = formatted.slice(formatter_params[0])
132
-
133
- } else if (formatter_type === "cropright") {
134
- formatted = formatted.slice(0, formatted.length-formatter_params[0])
135
-
136
- } else if (formatter_type === "croptodelimiter") {
137
- const to_demilimiter_idx = formatted.indexOf(formatter_params[0])
138
- if (to_demilimiter_idx >= 0) {
139
- formatted = formatted.slice(Math.max(to_demilimiter_idx + formatter_params[0].length + formatter_params[1], 0))
140
- }
141
-
142
- } else if (formatter_type === "cropfromdelimiter") {
143
- const from_demilimiter_idx = formatted.indexOf(formatter_params[0])
144
- if (from_demilimiter_idx >= 0) {
145
- formatted = formatted.slice(0, Math.max(from_demilimiter_idx + formatter_params[1], 0))
146
- }
147
-
148
- } else if (formatter_type === "substring") {
149
- const start = formatter_params[0] ? parseInt(formatter_params[0]) : 0
150
- const end = formatter_params[1] ? parseInt(formatter_params[1]) : formatted.length
151
- formatted = formatted.substring(start, end)
152
-
153
- } else if (formatter_type === "replace") {
154
- const search = formatter_params[0]
155
- const replacement = formatter_params[1]
156
- formatted = formatted.replaceAll(search, replacement)
157
- }
158
- // console.log("formatter:", formatter_type, "params:", formatter_params, "formatted:", formatted)
159
- }
160
- return formatted
161
- }
162
-
163
- }
164
-
165
- export const OINO_EMPTY_FORMATTER = new OINOFormatter([], [])
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 { OINO_ERROR_PREFIX } from "./OINOConstants.js"
8
+ import { OINOLog } from "./OINOLog.js"
9
+
10
+
11
+
12
+ /**
13
+ * Class for formatting strings and values.
14
+ *
15
+ */
16
+ export class OINOFormatter {
17
+ static OINO_FORMATTER_REGEXP = /\s?(trim(\(\))?|trimLeft(\(\))?|trimRight(\(\))?|toUpper(\(\))?|toLower(\(\))?|cropLeft\((\d+)\)|cropRight\((\d+)\)|cropToDelimiter\(([^\(\),]+),(\d+)\)|cropFromDelimiter\(([^\(\),]+),(\d+)\)|substring\((\d+),(\d+)\)|replace\(([^\(\),]+),([^\(\),]+)\))\s?$/i
18
+ _types: string[]
19
+ _params: any[][]
20
+
21
+ /**
22
+ * Constructor of `OINOFormatter`
23
+ * @param types array of formatter types
24
+ * @param params array of formatter parameters according to type
25
+ */
26
+ constructor(types: string[], params: any[][]) {
27
+ this._types = types
28
+ this._params = params
29
+ }
30
+
31
+ /**
32
+ * Constructor for `OINOFormatter` as parser of http parameter.
33
+ *
34
+ * @param formatters string or array of strings of serialized representation of formatters with following functions
35
+ * - trim()
36
+ * - trimLeft()
37
+ * - trimRight()
38
+ * - toUpper()
39
+ * - toLower()
40
+ * - cropLeft(charsToCrop)
41
+ * - cropRight(charsToCrop)
42
+ * - cropToDelimiter(delimiter,offsetChars)
43
+ * - cropFromDelimiter(delimiter,offsetChars)
44
+ * - substring(start,end)
45
+ * - replace(search,replace)
46
+ */
47
+ static parse(formatters: string|string[]): OINOFormatter {
48
+ if (typeof formatters === "string") {
49
+ formatters = [formatters]
50
+ }
51
+ if (!formatters || formatters.length === 0) {
52
+ return OINO_EMPTY_FORMATTER
53
+
54
+ } else {
55
+ const types:string[] = []
56
+ const params:any[][] = []
57
+ for (let i=0; i<formatters.length; i++) {
58
+ let match = formatters[i]?.match(this.OINO_FORMATTER_REGEXP)
59
+ if (!match) {
60
+ OINOLog.error("@oino-ts/common", "OINOFormatter", "parse", "Invalid formatter string", {formatter:formatters[i]})
61
+ throw new Error(OINO_ERROR_PREFIX + "Invalid formatter: " + formatters[i])
62
+ } else {
63
+ const formatter_type = match[1].toLowerCase().substring(0, match[1].indexOf('('))
64
+ const formatter_params: any[] = []
65
+ if ((formatter_type === "trim") || (formatter_type === "trimleft") || (formatter_type === "trimright") || (formatter_type === "toupper") || (formatter_type === "tolower")) {
66
+ // no parameters
67
+
68
+ } else if (formatter_type=== "cropleft") {
69
+ formatter_params.push(parseInt(match[7]))
70
+
71
+ } else if (formatter_type === "cropright") {
72
+ formatter_params.push(parseInt(match[8]))
73
+
74
+ } else if (formatter_type === "croptodelimiter") {
75
+ formatter_params.push(decodeURIComponent(match[9]), parseInt(match[10]))
76
+
77
+ } else if (formatter_type === "cropfromdelimiter") {
78
+ formatter_params.push(decodeURIComponent(match[11]), parseInt(match[12]))
79
+
80
+ } else if (formatter_type === "substring") {
81
+ formatter_params.push(parseInt(match[13]), parseInt(match[14]))
82
+
83
+ } else if (formatter_type === "replace") {
84
+ formatter_params.push(decodeURIComponent(match[15]), decodeURIComponent(match[16]))
85
+ } else {
86
+ OINOLog.error("@oino-ts/common", "OINOFormatter", "parse", "Unknown formatter type", {formatter:formatters[i]})
87
+ throw new Error(OINO_ERROR_PREFIX + "Unsupported formatter: " + formatters[i])
88
+ }
89
+ types.push(formatter_type)
90
+ params.push(formatter_params)
91
+ }
92
+ }
93
+ return new OINOFormatter(types, params)
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Does formatter include any operations.
99
+ * @return true if formatter is empty
100
+ */
101
+ isEmpty():boolean {
102
+ return this._types.length === 0
103
+ }
104
+
105
+ /**
106
+ * Applies all formatters in order to given value.
107
+ *
108
+ * @param value string value to be formatted
109
+ * @returns formatted string value
110
+ */
111
+ format(value: string): string {
112
+ let formatted = value
113
+ for (let i = 0; i < this._types.length; i++) {
114
+ const formatter_type = this._types[i]
115
+ const formatter_params = this._params[i]
116
+ if (formatter_type === "trim") {
117
+ formatted = formatted.trim()
118
+
119
+ } else if (formatter_type === "trimleft") {
120
+ formatted = formatted.trimStart()
121
+
122
+ } else if (formatter_type === "trimright") {
123
+ formatted = formatted.trimEnd()
124
+
125
+ } else if (formatter_type === "toupper") {
126
+ formatted = formatted.toUpperCase()
127
+
128
+ } else if (formatter_type === "tolower") {
129
+ formatted = formatted.toLowerCase()
130
+
131
+ } else if (formatter_type === "cropleft") {
132
+ formatted = formatted.slice(formatter_params[0])
133
+
134
+ } else if (formatter_type === "cropright") {
135
+ formatted = formatted.slice(0, formatted.length-formatter_params[0])
136
+
137
+ } else if (formatter_type === "croptodelimiter") {
138
+ const to_demilimiter_idx = formatted.indexOf(formatter_params[0])
139
+ if (to_demilimiter_idx >= 0) {
140
+ formatted = formatted.slice(Math.max(to_demilimiter_idx + formatter_params[0].length + formatter_params[1], 0))
141
+ }
142
+
143
+ } else if (formatter_type === "cropfromdelimiter") {
144
+ const from_demilimiter_idx = formatted.indexOf(formatter_params[0])
145
+ if (from_demilimiter_idx >= 0) {
146
+ formatted = formatted.slice(0, Math.max(from_demilimiter_idx + formatter_params[1], 0))
147
+ }
148
+
149
+ } else if (formatter_type === "substring") {
150
+ const start = formatter_params[0] ? parseInt(formatter_params[0]) : 0
151
+ const end = formatter_params[1] ? parseInt(formatter_params[1]) : formatted.length
152
+ formatted = formatted.substring(start, end)
153
+
154
+ } else if (formatter_type === "replace") {
155
+ const search = formatter_params[0]
156
+ const replacement = formatter_params[1]
157
+ formatted = formatted.replaceAll(search, replacement)
158
+ }
159
+ // console.log("formatter:", formatter_type, "params:", formatter_params, "formatted:", formatted)
160
+ }
161
+ return formatted
162
+ }
163
+
164
+ }
165
+
166
+ export const OINO_EMPTY_FORMATTER = new OINOFormatter([], [])
@@ -1,51 +1,51 @@
1
- export type OINOHeadersInit = OINOHeaders | Record<string, string> | [string, string][] | Map<string, string>;
2
-
3
- /**
4
- * Type for HTTP style headers that just guarantees keys are normalized to lowercase.
5
- *
6
- */
7
-
8
- export class OINOHeaders {
9
- [key: string]: any
10
-
11
- constructor(init?: OINOHeadersInit) {
12
- this.setHeaders(init ?? {})
13
- }
14
-
15
- get(key: string): string | undefined {
16
- return this[key.toLowerCase()]
17
- }
18
-
19
- set(key: string, value: string): void {
20
- this[key.toLowerCase()] = value
21
- }
22
-
23
- setHeaders(init?: OINOHeadersInit): void {
24
- if (init instanceof OINOHeaders) {
25
- for (const key of Object.keys(init)) {
26
- this.set(key, init.get(key)!)
27
- }
28
-
29
- } else if (init instanceof Map) {
30
- for (const [key, value] of init.entries()) {
31
- this.set(key, value)
32
- }
33
-
34
- } else if (Array.isArray(init)) {
35
- for (const [key, value] of init) {
36
- this.set(key, value)
37
- }
38
-
39
- } else if (init && typeof init === "object") {
40
- for (const key in init as Record<string, string>) {
41
- this.set(key, init[key])
42
- }
43
- }
44
- }
45
-
46
- clear(): void {
47
- for (const key of Object.keys(this)) {
48
- delete this[key]
49
- }
50
- }
51
- }
1
+ export type OINOHeadersInit = OINOHeaders | Record<string, string> | [string, string][] | Map<string, string>;
2
+
3
+ /**
4
+ * Type for HTTP style headers that just guarantees keys are normalized to lowercase.
5
+ *
6
+ */
7
+
8
+ export class OINOHeaders {
9
+ [key: string]: any
10
+
11
+ constructor(init?: OINOHeadersInit) {
12
+ this.setHeaders(init ?? {})
13
+ }
14
+
15
+ get(key: string): string | undefined {
16
+ return this[key.toLowerCase()]
17
+ }
18
+
19
+ set(key: string, value: string): void {
20
+ this[key.toLowerCase()] = value
21
+ }
22
+
23
+ setHeaders(init?: OINOHeadersInit): void {
24
+ if (init instanceof OINOHeaders) {
25
+ for (const key of Object.keys(init)) {
26
+ this.set(key, init.get(key)!)
27
+ }
28
+
29
+ } else if (init instanceof Map) {
30
+ for (const [key, value] of init.entries()) {
31
+ this.set(key, value)
32
+ }
33
+
34
+ } else if (Array.isArray(init)) {
35
+ for (const [key, value] of init) {
36
+ this.set(key, value)
37
+ }
38
+
39
+ } else if (init && typeof init === "object") {
40
+ for (const key in init as Record<string, string>) {
41
+ this.set(key, init[key])
42
+ }
43
+ }
44
+ }
45
+
46
+ clear(): void {
47
+ for (const key of Object.keys(this)) {
48
+ delete this[key]
49
+ }
50
+ }
51
+ }