vovk 3.0.0-draft.46 → 3.0.0-draft.461

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 (207) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +8 -96
  3. package/bin/index.mjs +8 -0
  4. package/cjs/JSONLinesResponse.d.ts +19 -0
  5. package/cjs/JSONLinesResponse.js +95 -0
  6. package/{VovkApp.d.ts → cjs/VovkApp.d.ts} +14 -8
  7. package/cjs/VovkApp.js +304 -0
  8. package/cjs/client/createRPC.d.ts +5 -0
  9. package/cjs/client/createRPC.js +116 -0
  10. package/cjs/client/defaultHandler.d.ts +6 -0
  11. package/{client → cjs/client}/defaultHandler.js +9 -2
  12. package/cjs/client/defaultStreamHandler.d.ts +9 -0
  13. package/{client → cjs/client}/defaultStreamHandler.js +49 -26
  14. package/cjs/client/fetcher.d.ts +18 -0
  15. package/cjs/client/fetcher.js +97 -0
  16. package/cjs/client/index.d.ts +4 -0
  17. package/cjs/client/index.js +10 -0
  18. package/cjs/client/progressive.d.ts +9 -0
  19. package/cjs/client/progressive.js +54 -0
  20. package/cjs/client/types.d.ts +120 -0
  21. package/{createVovkApp.d.ts → cjs/createVovkApp.d.ts} +19 -16
  22. package/cjs/createVovkApp.js +146 -0
  23. package/cjs/index.d.ts +69 -0
  24. package/cjs/index.js +42 -0
  25. package/cjs/openapi/error.d.ts +2 -0
  26. package/cjs/openapi/error.js +100 -0
  27. package/cjs/openapi/index.d.ts +8 -0
  28. package/cjs/openapi/index.js +21 -0
  29. package/cjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.d.ts +3 -0
  30. package/cjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.js +67 -0
  31. package/cjs/openapi/openAPIToVovkSchema/index.d.ts +4 -0
  32. package/cjs/openapi/openAPIToVovkSchema/index.js +141 -0
  33. package/cjs/openapi/openAPIToVovkSchema/inlineRefs.d.ts +10 -0
  34. package/cjs/openapi/openAPIToVovkSchema/inlineRefs.js +102 -0
  35. package/cjs/openapi/vovkSchemaToOpenAPI.d.ts +8 -0
  36. package/cjs/openapi/vovkSchemaToOpenAPI.js +238 -0
  37. package/cjs/types.d.ts +466 -0
  38. package/{types.js → cjs/types.js} +14 -2
  39. package/cjs/utils/camelCase.d.ts +6 -0
  40. package/cjs/utils/camelCase.js +37 -0
  41. package/cjs/utils/createCodeSamples.d.ts +20 -0
  42. package/cjs/utils/createCodeSamples.js +279 -0
  43. package/cjs/utils/createDecorator.d.ts +6 -0
  44. package/{createDecorator.js → cjs/utils/createDecorator.js} +24 -14
  45. package/cjs/utils/createLLMTools.d.ts +50 -0
  46. package/cjs/utils/createLLMTools.js +168 -0
  47. package/cjs/utils/createStandardValidation.d.ts +83 -0
  48. package/cjs/utils/createStandardValidation.js +35 -0
  49. package/cjs/utils/createValidateOnClient.d.ts +7 -0
  50. package/cjs/utils/createValidateOnClient.js +19 -0
  51. package/cjs/utils/deepExtend.d.ts +54 -0
  52. package/cjs/utils/deepExtend.js +134 -0
  53. package/{utils → cjs/utils}/generateStaticAPI.d.ts +2 -2
  54. package/cjs/utils/generateStaticAPI.js +30 -0
  55. package/cjs/utils/getJSONSchemaExample.d.ts +11 -0
  56. package/cjs/utils/getJSONSchemaExample.js +264 -0
  57. package/cjs/utils/getJSONSchemaSample.d.ts +2 -0
  58. package/cjs/utils/getJSONSchemaSample.js +167 -0
  59. package/cjs/utils/getSampleFromObject.d.ts +9 -0
  60. package/cjs/utils/getSampleFromObject.js +41 -0
  61. package/cjs/utils/getSchema.d.ts +21 -0
  62. package/cjs/utils/getSchema.js +38 -0
  63. package/cjs/utils/multitenant.d.ts +24 -0
  64. package/cjs/utils/multitenant.js +131 -0
  65. package/cjs/utils/parseQuery.d.ts +25 -0
  66. package/cjs/utils/parseQuery.js +156 -0
  67. package/cjs/utils/reqForm.d.ts +2 -0
  68. package/cjs/utils/reqForm.js +33 -0
  69. package/cjs/utils/reqMeta.d.ts +2 -0
  70. package/cjs/utils/reqQuery.d.ts +2 -0
  71. package/cjs/utils/reqQuery.js +10 -0
  72. package/cjs/utils/resolveGeneratorConfigValues.d.ts +18 -0
  73. package/cjs/utils/resolveGeneratorConfigValues.js +82 -0
  74. package/cjs/utils/serializeQuery.d.ts +13 -0
  75. package/cjs/utils/serializeQuery.js +65 -0
  76. package/cjs/utils/setHandlerSchema.d.ts +4 -0
  77. package/cjs/utils/setHandlerSchema.js +15 -0
  78. package/cjs/utils/upperFirst.d.ts +1 -0
  79. package/cjs/utils/upperFirst.js +6 -0
  80. package/cjs/utils/withValidationLibrary.d.ts +78 -0
  81. package/cjs/utils/withValidationLibrary.js +133 -0
  82. package/mjs/HttpException.d.ts +7 -0
  83. package/mjs/HttpException.js +15 -0
  84. package/mjs/JSONLinesResponse.d.ts +19 -0
  85. package/mjs/JSONLinesResponse.js +95 -0
  86. package/mjs/VovkApp.d.ts +34 -0
  87. package/mjs/VovkApp.js +304 -0
  88. package/mjs/client/createRPC.d.ts +5 -0
  89. package/mjs/client/createRPC.js +116 -0
  90. package/mjs/client/defaultHandler.d.ts +6 -0
  91. package/mjs/client/defaultHandler.js +29 -0
  92. package/mjs/client/defaultStreamHandler.d.ts +9 -0
  93. package/mjs/client/defaultStreamHandler.js +105 -0
  94. package/mjs/client/fetcher.d.ts +18 -0
  95. package/mjs/client/fetcher.js +97 -0
  96. package/mjs/client/index.d.ts +4 -0
  97. package/mjs/client/index.js +10 -0
  98. package/mjs/client/progressive.d.ts +9 -0
  99. package/mjs/client/progressive.js +54 -0
  100. package/mjs/client/types.d.ts +120 -0
  101. package/mjs/createVovkApp.d.ts +65 -0
  102. package/mjs/createVovkApp.js +146 -0
  103. package/mjs/index.d.ts +69 -0
  104. package/mjs/index.js +42 -0
  105. package/mjs/openapi/error.d.ts +2 -0
  106. package/mjs/openapi/error.js +100 -0
  107. package/mjs/openapi/index.d.ts +8 -0
  108. package/mjs/openapi/index.js +21 -0
  109. package/mjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.d.ts +3 -0
  110. package/mjs/openapi/openAPIToVovkSchema/applyComponentsSchemas.js +67 -0
  111. package/mjs/openapi/openAPIToVovkSchema/index.d.ts +4 -0
  112. package/mjs/openapi/openAPIToVovkSchema/index.js +141 -0
  113. package/mjs/openapi/openAPIToVovkSchema/inlineRefs.d.ts +10 -0
  114. package/mjs/openapi/openAPIToVovkSchema/inlineRefs.js +102 -0
  115. package/mjs/openapi/vovkSchemaToOpenAPI.d.ts +8 -0
  116. package/mjs/openapi/vovkSchemaToOpenAPI.js +238 -0
  117. package/mjs/types.d.ts +466 -0
  118. package/mjs/types.js +77 -0
  119. package/mjs/utils/camelCase.d.ts +6 -0
  120. package/mjs/utils/camelCase.js +37 -0
  121. package/mjs/utils/createCodeSamples.d.ts +20 -0
  122. package/mjs/utils/createCodeSamples.js +279 -0
  123. package/mjs/utils/createDecorator.d.ts +6 -0
  124. package/mjs/utils/createDecorator.js +48 -0
  125. package/mjs/utils/createLLMTools.d.ts +50 -0
  126. package/mjs/utils/createLLMTools.js +168 -0
  127. package/mjs/utils/createStandardValidation.d.ts +83 -0
  128. package/mjs/utils/createStandardValidation.js +35 -0
  129. package/mjs/utils/createValidateOnClient.d.ts +7 -0
  130. package/mjs/utils/createValidateOnClient.js +19 -0
  131. package/mjs/utils/deepExtend.d.ts +54 -0
  132. package/mjs/utils/deepExtend.js +134 -0
  133. package/mjs/utils/generateStaticAPI.d.ts +4 -0
  134. package/mjs/utils/generateStaticAPI.js +30 -0
  135. package/mjs/utils/getJSONSchemaExample.d.ts +11 -0
  136. package/mjs/utils/getJSONSchemaExample.js +264 -0
  137. package/mjs/utils/getJSONSchemaSample.d.ts +2 -0
  138. package/mjs/utils/getJSONSchemaSample.js +167 -0
  139. package/mjs/utils/getSampleFromObject.d.ts +9 -0
  140. package/mjs/utils/getSampleFromObject.js +41 -0
  141. package/mjs/utils/getSchema.d.ts +21 -0
  142. package/mjs/utils/getSchema.js +38 -0
  143. package/mjs/utils/multitenant.d.ts +24 -0
  144. package/mjs/utils/multitenant.js +131 -0
  145. package/mjs/utils/parseQuery.d.ts +25 -0
  146. package/mjs/utils/parseQuery.js +156 -0
  147. package/mjs/utils/reqForm.d.ts +2 -0
  148. package/mjs/utils/reqForm.js +33 -0
  149. package/mjs/utils/reqMeta.d.ts +2 -0
  150. package/mjs/utils/reqMeta.js +13 -0
  151. package/mjs/utils/reqQuery.d.ts +2 -0
  152. package/mjs/utils/reqQuery.js +10 -0
  153. package/mjs/utils/resolveGeneratorConfigValues.d.ts +18 -0
  154. package/mjs/utils/resolveGeneratorConfigValues.js +82 -0
  155. package/mjs/utils/serializeQuery.d.ts +13 -0
  156. package/mjs/utils/serializeQuery.js +65 -0
  157. package/mjs/utils/setHandlerSchema.d.ts +4 -0
  158. package/mjs/utils/setHandlerSchema.js +15 -0
  159. package/mjs/utils/shim.d.ts +1 -0
  160. package/mjs/utils/shim.js +18 -0
  161. package/mjs/utils/upperFirst.d.ts +1 -0
  162. package/mjs/utils/upperFirst.js +6 -0
  163. package/mjs/utils/withValidationLibrary.d.ts +78 -0
  164. package/mjs/utils/withValidationLibrary.js +133 -0
  165. package/package.json +28 -6
  166. package/.npmignore +0 -2
  167. package/StreamJSONResponse.d.ts +0 -17
  168. package/StreamJSONResponse.js +0 -54
  169. package/VovkApp.js +0 -185
  170. package/client/clientizeController.d.ts +0 -4
  171. package/client/clientizeController.js +0 -93
  172. package/client/defaultFetcher.d.ts +0 -4
  173. package/client/defaultFetcher.js +0 -49
  174. package/client/defaultHandler.d.ts +0 -2
  175. package/client/defaultStreamHandler.d.ts +0 -4
  176. package/client/index.d.ts +0 -4
  177. package/client/index.js +0 -5
  178. package/client/types.d.ts +0 -100
  179. package/createDecorator.d.ts +0 -4
  180. package/createVovkApp.js +0 -118
  181. package/index.d.ts +0 -60
  182. package/index.js +0 -20
  183. package/types.d.ts +0 -157
  184. package/utils/generateStaticAPI.js +0 -18
  185. package/utils/getSchema.d.ts +0 -8
  186. package/utils/getSchema.js +0 -38
  187. package/utils/reqForm.d.ts +0 -3
  188. package/utils/reqForm.js +0 -13
  189. package/utils/reqMeta.d.ts +0 -3
  190. package/utils/reqQuery.d.ts +0 -3
  191. package/utils/reqQuery.js +0 -25
  192. package/utils/setClientValidatorsForHandler.d.ts +0 -5
  193. package/utils/setClientValidatorsForHandler.js +0 -25
  194. package/worker/index.d.ts +0 -3
  195. package/worker/index.js +0 -7
  196. package/worker/promisifyWorker.d.ts +0 -2
  197. package/worker/promisifyWorker.js +0 -141
  198. package/worker/types.d.ts +0 -31
  199. package/worker/worker.d.ts +0 -1
  200. package/worker/worker.js +0 -43
  201. /package/{HttpException.d.ts → cjs/HttpException.d.ts} +0 -0
  202. /package/{HttpException.js → cjs/HttpException.js} +0 -0
  203. /package/{client → cjs/client}/types.js +0 -0
  204. /package/{utils → cjs/utils}/reqMeta.js +0 -0
  205. /package/{utils → cjs/utils}/shim.d.ts +0 -0
  206. /package/{utils → cjs/utils}/shim.js +0 -0
  207. /package/{worker → mjs/client}/types.js +0 -0
@@ -0,0 +1,238 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.vovkSchemaToOpenAPI = vovkSchemaToOpenAPI;
4
+ const createCodeSamples_1 = require("../utils/createCodeSamples");
5
+ const types_1 = require("../types");
6
+ const getJSONSchemaSample_1 = require("../utils/getJSONSchemaSample");
7
+ const resolveGeneratorConfigValues_1 = require("../utils/resolveGeneratorConfigValues");
8
+ function extractComponents(schema) {
9
+ if (!schema)
10
+ return [undefined, {}];
11
+ const components = {};
12
+ // Function to collect components and replace $refs recursively
13
+ const process = (obj, path = []) => {
14
+ if (!obj || typeof obj !== 'object')
15
+ return obj;
16
+ // Handle arrays
17
+ if (Array.isArray(obj)) {
18
+ return obj.map((item) => process(item, path));
19
+ }
20
+ // Create a copy to modify
21
+ const result = {};
22
+ Object.entries({ ...obj.definitions, ...obj.$defs }).forEach(([key, value]) => {
23
+ components[key] = process(value, [...path, key]);
24
+ });
25
+ // Process all properties
26
+ for (const [key, value] of Object.entries(obj ?? {})) {
27
+ // Skip already processed special properties
28
+ if (key === '$defs' || key === 'definitions')
29
+ continue;
30
+ if (key === '$ref' && typeof value === 'string') {
31
+ // Extract the component name from the reference
32
+ const refParts = value.split('/');
33
+ const refName = refParts[refParts.length - 1];
34
+ // Replace with component reference
35
+ result[key] = `#/components/schemas/${refName}`;
36
+ }
37
+ else {
38
+ // Recursively process other properties
39
+ result[key] = process(value, [...path, key]);
40
+ }
41
+ }
42
+ return result;
43
+ };
44
+ const processedSchema = process(schema);
45
+ return [processedSchema, components];
46
+ }
47
+ function vovkSchemaToOpenAPI({ rootEntry = 'api', schema: fullSchema, configs, segmentName: givenSegmentName, }) {
48
+ const paths = {};
49
+ const components = {};
50
+ const { openAPIObject, samples: samplesConfig, package: packageJson, } = (0, resolveGeneratorConfigValues_1.resolveGeneratorConfigValues)({
51
+ schema: fullSchema,
52
+ configs,
53
+ segmentName: givenSegmentName ?? null,
54
+ });
55
+ for (const [segmentName, segmentSchema] of givenSegmentName
56
+ ? [[givenSegmentName, fullSchema.segments[givenSegmentName]]]
57
+ : Object.entries(fullSchema.segments ?? {})) {
58
+ for (const c of Object.values(segmentSchema.controllers)) {
59
+ for (const [handlerName, h] of Object.entries(c.handlers ?? {})) {
60
+ if (h.operationObject) {
61
+ const [queryValidation, queryComponents] = extractComponents(h?.validation?.query);
62
+ const [bodyValidation, bodyComponents] = extractComponents(h?.validation?.body);
63
+ const [paramsValidation, paramsComponents] = extractComponents(h?.validation?.params);
64
+ const [outputValidation, outputComponents] = extractComponents(h?.validation?.output);
65
+ const [iterationValidation, iterationComponents] = extractComponents(h?.validation?.iteration);
66
+ // TODO: Handle name conflicts?
67
+ Object.assign(components, queryComponents, bodyComponents, paramsComponents, outputComponents, iterationComponents);
68
+ const { ts, rs, py } = (0, createCodeSamples_1.createCodeSamples)({
69
+ package: packageJson,
70
+ handlerName,
71
+ handlerSchema: h,
72
+ controllerSchema: c,
73
+ config: samplesConfig,
74
+ });
75
+ const queryParameters = queryValidation && 'type' in queryValidation && 'properties' in queryValidation
76
+ ? Object.entries(queryValidation.properties ?? {}).map(([propName, propSchema]) => ({
77
+ name: propName,
78
+ in: 'query',
79
+ required: queryValidation.required ? queryValidation.required.includes(propName) : false,
80
+ schema: propSchema,
81
+ }))
82
+ : null;
83
+ const pathParameters = paramsValidation && 'type' in paramsValidation && 'properties' in paramsValidation
84
+ ? Object.entries(paramsValidation.properties ?? {}).map(([propName, propSchema]) => ({
85
+ name: propName,
86
+ in: 'path',
87
+ required: paramsValidation.required ? paramsValidation.required.includes(propName) : false,
88
+ schema: propSchema,
89
+ }))
90
+ : null;
91
+ const path = h.misc?.originalPath ??
92
+ '/' + [rootEntry.replace(/^\/+|\/+$/g, ''), segmentName, c.prefix, h.path].filter(Boolean).join('/');
93
+ paths[path] = paths[path] ?? {};
94
+ const httpMethod = h.httpMethod.toLowerCase();
95
+ paths[path][httpMethod] ??= {};
96
+ paths[path][httpMethod] = {
97
+ ...h.operationObject,
98
+ ...paths[path][httpMethod],
99
+ 'x-codeSamples': [
100
+ ...(paths[path][httpMethod]['x-codeSamples'] ?? []),
101
+ ...(h.operationObject?.['x-codeSamples'] ?? []),
102
+ {
103
+ label: 'TypeScript RPC',
104
+ lang: 'typescript',
105
+ source: ts,
106
+ },
107
+ {
108
+ label: 'Python RPC',
109
+ lang: 'python',
110
+ source: py,
111
+ },
112
+ {
113
+ label: 'Rust RPC',
114
+ lang: 'rust',
115
+ source: rs,
116
+ },
117
+ ],
118
+ ...(queryParameters || pathParameters
119
+ ? {
120
+ parameters: h.operationObject?.parameters ?? [...(queryParameters || []), ...(pathParameters || [])],
121
+ }
122
+ : {}),
123
+ ...(paths[path][httpMethod].parameters
124
+ ? {
125
+ parameters: paths[path][httpMethod].parameters,
126
+ }
127
+ : {}),
128
+ ...(outputValidation && 'type' in outputValidation
129
+ ? {
130
+ responses: {
131
+ 200: {
132
+ description: 'description' in outputValidation ? outputValidation.description : 'Success',
133
+ content: {
134
+ 'application/json': {
135
+ schema: outputValidation,
136
+ },
137
+ },
138
+ },
139
+ ...h.operationObject?.responses,
140
+ },
141
+ }
142
+ : {}),
143
+ ...(iterationValidation && 'type' in iterationValidation
144
+ ? {
145
+ responses: {
146
+ 200: {
147
+ description: 'description' in iterationValidation ? iterationValidation.description : 'JSON Lines response',
148
+ content: {
149
+ 'application/jsonl': {
150
+ schema: {
151
+ ...iterationValidation,
152
+ examples: iterationValidation.examples ?? [
153
+ [
154
+ JSON.stringify((0, getJSONSchemaSample_1.getJSONSchemaSample)(iterationValidation)),
155
+ JSON.stringify((0, getJSONSchemaSample_1.getJSONSchemaSample)(iterationValidation)),
156
+ JSON.stringify((0, getJSONSchemaSample_1.getJSONSchemaSample)(iterationValidation)),
157
+ ].join('\n'),
158
+ ],
159
+ },
160
+ },
161
+ },
162
+ },
163
+ ...h.operationObject?.responses,
164
+ },
165
+ }
166
+ : {}),
167
+ ...(paths[path][httpMethod].responses
168
+ ? {
169
+ responses: paths[path][httpMethod].responses,
170
+ }
171
+ : {}),
172
+ ...(bodyValidation && 'type' in bodyValidation
173
+ ? {
174
+ requestBody: h.operationObject?.requestBody ?? {
175
+ description: 'description' in bodyValidation ? bodyValidation.description : 'Request body',
176
+ required: true,
177
+ content: {
178
+ 'application/json': {
179
+ schema: bodyValidation,
180
+ },
181
+ },
182
+ },
183
+ }
184
+ : {}),
185
+ ...(paths[path][httpMethod].requestBody
186
+ ? {
187
+ requestBody: paths[path][httpMethod].requestBody,
188
+ }
189
+ : {}),
190
+ tags: paths[path][httpMethod].tags ?? h.operationObject?.tags,
191
+ };
192
+ }
193
+ }
194
+ }
195
+ }
196
+ return {
197
+ ...openAPIObject,
198
+ components: {
199
+ ...openAPIObject?.components,
200
+ schemas: {
201
+ ...(openAPIObject?.components?.schemas ?? components),
202
+ HttpStatus: {
203
+ type: 'integer',
204
+ description: 'HTTP status code',
205
+ enum: Object.keys(types_1.HttpStatus)
206
+ .map((k) => types_1.HttpStatus[k])
207
+ .filter(Boolean)
208
+ .filter((v) => typeof v === 'number'),
209
+ },
210
+ VovkErrorResponse: {
211
+ type: 'object',
212
+ description: 'Vovk error response',
213
+ properties: {
214
+ cause: {
215
+ description: 'Error cause of any shape',
216
+ },
217
+ statusCode: {
218
+ $ref: '#/components/schemas/HttpStatus',
219
+ },
220
+ message: {
221
+ type: 'string',
222
+ description: 'Error message',
223
+ },
224
+ isError: {
225
+ type: 'boolean',
226
+ const: true,
227
+ description: 'Indicates that this object represents an error',
228
+ },
229
+ },
230
+ required: ['statusCode', 'message', 'isError'],
231
+ additionalProperties: false,
232
+ },
233
+ ...openAPIObject?.components?.schemas,
234
+ },
235
+ },
236
+ paths,
237
+ };
238
+ }