vovk 3.0.0-draft.46 → 3.0.0-draft.460

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 +82 -0
  48. package/cjs/utils/createStandardValidation.js +34 -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 +77 -0
  81. package/cjs/utils/withValidationLibrary.js +124 -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 +82 -0
  128. package/mjs/utils/createStandardValidation.js +34 -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 +77 -0
  164. package/mjs/utils/withValidationLibrary.js +124 -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,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStandardValidation = createStandardValidation;
4
+ const types_1 = require("../types");
5
+ const withValidationLibrary_1 = require("./withValidationLibrary");
6
+ const HttpException_1 = require("../HttpException");
7
+ function createStandardValidation({ toJSONSchema, }) {
8
+ function withStandard({ isForm, body, query, params, output, iteration, handle, disableServerSideValidation, skipSchemaEmission, validateEachIteration, operationObject, }) {
9
+ return (0, withValidationLibrary_1.withValidationLibrary)({
10
+ isForm,
11
+ body,
12
+ query,
13
+ params,
14
+ output,
15
+ iteration,
16
+ disableServerSideValidation,
17
+ skipSchemaEmission,
18
+ validateEachIteration,
19
+ handle: handle,
20
+ toJSONSchema,
21
+ validate: async (data, model, { type, i }) => {
22
+ const result = await model['~standard'].validate(data);
23
+ if (result.issues?.length) {
24
+ throw new HttpException_1.HttpException(types_1.HttpStatus.BAD_REQUEST, `Validation failed. Invalid ${type === 'iteration' ? `${type} #${i}` : type} on server: ${result.issues
25
+ .map(({ message, path }) => `${message}${path ? ` at ${path.join('.')}` : ''}`)
26
+ .join(', ')}`, { [type]: data, result });
27
+ }
28
+ return result.value;
29
+ },
30
+ operationObject,
31
+ });
32
+ }
33
+ return withStandard;
34
+ }
@@ -0,0 +1,7 @@
1
+ import type { VovkValidateOnClient } from '../client';
2
+ import type { KnownAny, VovkBasicJSONSchema } from '../types';
3
+ export declare function createValidateOnClient<TFetcherOptions>({ validate, }: {
4
+ validate: (input: unknown, schema: VovkBasicJSONSchema, meta: Parameters<VovkValidateOnClient<TFetcherOptions>>[2] & {
5
+ type: 'body' | 'query' | 'params';
6
+ }) => KnownAny | Promise<KnownAny>;
7
+ }): VovkValidateOnClient<TFetcherOptions>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createValidateOnClient = createValidateOnClient;
4
+ function createValidateOnClient({ validate, }) {
5
+ const validateOnClient = async function validateOnClient(input, validation, meta) {
6
+ const newInput = { ...input };
7
+ if (input.body && validation.body) {
8
+ newInput.body = (await validate(input.body, validation.body, { ...meta, type: 'body' })) ?? input.body;
9
+ }
10
+ if (input.query && validation.query) {
11
+ newInput.query = (await validate(input.query, validation.query, { ...meta, type: 'query' })) ?? input.query;
12
+ }
13
+ if (input.params && validation.params) {
14
+ newInput.params = (await validate(input.params, validation.params, { ...meta, type: 'params' })) ?? input.params;
15
+ }
16
+ return newInput;
17
+ };
18
+ return validateOnClient;
19
+ }
@@ -0,0 +1,54 @@
1
+ /*!
2
+ * @description Recursive object extending
3
+ * @author Viacheslav Lotsmanov <lotsmanov89@gmail.com>
4
+ * @license MIT
5
+ *
6
+ * The MIT License (MIT)
7
+ *
8
+ * Copyright (c) 2013-2018 Viacheslav Lotsmanov
9
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
11
+ * this software and associated documentation files (the "Software"), to deal in
12
+ * the Software without restriction, including without limitation the rights to
13
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
14
+ * the Software, and to permit persons to whom the Software is furnished to do so,
15
+ * subject to the following conditions:
16
+ *
17
+ * The above copyright notice and this permission notice shall be included in all
18
+ * copies or substantial portions of the Software.
19
+ *
20
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ */
27
+ type DeepPartial<T> = {
28
+ [P in keyof T]?: T[P] extends (infer U)[] ? DeepPartial<U>[] : T[P] extends object ? DeepPartial<T[P]> : T[P];
29
+ };
30
+ type SpecificValue = Buffer | Date | RegExp;
31
+ declare function isSpecificValue(val: any): val is SpecificValue;
32
+ declare function cloneSpecificValue(val: SpecificValue): SpecificValue;
33
+ /**
34
+ * Recursive cloning array.
35
+ */
36
+ declare function deepCloneArray<T = any>(arr: T[]): T[];
37
+ declare function safeGetProperty<T extends object>(object: T, property: PropertyKey): any;
38
+ /**
39
+ * Extending object that entered in first argument.
40
+ *
41
+ * Returns extended object or false if have no target object or incorrect type.
42
+ *
43
+ * If you wish to clone source object (without modify it), just use empty new
44
+ * object as first argument, like this:
45
+ * deepExtend({}, yourObj_1, [yourObj_N]);
46
+ */
47
+ declare function deepExtend<T extends object>(...args: [T, ...Partial<T>[]]): T;
48
+ declare function deepExtend<T extends object, U extends object>(target: T, source: U): T & U;
49
+ declare function deepExtend<T extends object, U extends object, V extends object>(target: T, source1: U, source2: V): T & U & V;
50
+ declare function deepExtend<T extends object, U extends object, V extends object, W extends object>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
51
+ declare function deepExtend<T extends object>(target: T, ...sources: any[]): T;
52
+ export default deepExtend;
53
+ export { deepExtend, deepCloneArray, isSpecificValue, cloneSpecificValue, safeGetProperty };
54
+ export type { DeepPartial, SpecificValue };
@@ -0,0 +1,134 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /*!
3
+ * @description Recursive object extending
4
+ * @author Viacheslav Lotsmanov <lotsmanov89@gmail.com>
5
+ * @license MIT
6
+ *
7
+ * The MIT License (MIT)
8
+ *
9
+ * Copyright (c) 2013-2018 Viacheslav Lotsmanov
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
12
+ * this software and associated documentation files (the "Software"), to deal in
13
+ * the Software without restriction, including without limitation the rights to
14
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15
+ * the Software, and to permit persons to whom the Software is furnished to do so,
16
+ * subject to the following conditions:
17
+ *
18
+ * The above copyright notice and this permission notice shall be included in all
19
+ * copies or substantial portions of the Software.
20
+ *
21
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
23
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
24
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
25
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
+ */
28
+ 'use strict';
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.deepExtend = deepExtend;
31
+ exports.deepCloneArray = deepCloneArray;
32
+ exports.isSpecificValue = isSpecificValue;
33
+ exports.cloneSpecificValue = cloneSpecificValue;
34
+ exports.safeGetProperty = safeGetProperty;
35
+ function isSpecificValue(val) {
36
+ return val instanceof Buffer || val instanceof Date || val instanceof RegExp;
37
+ }
38
+ function cloneSpecificValue(val) {
39
+ if (val instanceof Buffer) {
40
+ const x = Buffer.alloc ? Buffer.alloc(val.length) : Buffer.from(val);
41
+ val.copy(x);
42
+ return x;
43
+ }
44
+ else if (val instanceof Date) {
45
+ return new Date(val.getTime());
46
+ }
47
+ else if (val instanceof RegExp) {
48
+ return new RegExp(val);
49
+ }
50
+ else {
51
+ throw new Error('Unexpected situation');
52
+ }
53
+ }
54
+ /**
55
+ * Recursive cloning array.
56
+ */
57
+ function deepCloneArray(arr) {
58
+ const clone = [];
59
+ arr.forEach((item, index) => {
60
+ if (typeof item === 'object' && item !== null) {
61
+ if (Array.isArray(item)) {
62
+ clone[index] = deepCloneArray(item);
63
+ }
64
+ else if (isSpecificValue(item)) {
65
+ clone[index] = cloneSpecificValue(item);
66
+ }
67
+ else {
68
+ clone[index] = deepExtend({}, item);
69
+ }
70
+ }
71
+ else {
72
+ clone[index] = item;
73
+ }
74
+ });
75
+ return clone;
76
+ }
77
+ function safeGetProperty(object, property) {
78
+ return property === '__proto__' ? undefined : object[property];
79
+ }
80
+ function deepExtend(...args) {
81
+ if (args.length < 1 || typeof args[0] !== 'object') {
82
+ return false;
83
+ }
84
+ if (args.length < 2) {
85
+ return args[0];
86
+ }
87
+ const target = args[0];
88
+ // convert arguments to array and cut off target object
89
+ const sources = args.slice(1);
90
+ sources.forEach((obj) => {
91
+ // skip argument if isn't an object, is null, or is an array
92
+ if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
93
+ return;
94
+ }
95
+ Object.keys(obj).forEach((key) => {
96
+ const src = safeGetProperty(target, key); // source value
97
+ const val = safeGetProperty(obj, key); // new value
98
+ // recursion prevention
99
+ if (val === target) {
100
+ return;
101
+ }
102
+ else if (typeof val !== 'object' || val === null) {
103
+ /**
104
+ * if new value isn't object then just overwrite by new value
105
+ * instead of extending.
106
+ */
107
+ target[key] = val;
108
+ return;
109
+ }
110
+ // just clone arrays (and recursive clone objects inside)
111
+ else if (Array.isArray(val)) {
112
+ target[key] = deepCloneArray(val);
113
+ return;
114
+ }
115
+ // custom cloning and overwrite for specific objects
116
+ else if (isSpecificValue(val)) {
117
+ target[key] = cloneSpecificValue(val);
118
+ return;
119
+ }
120
+ // overwrite by new value if source isn't object or array
121
+ else if (typeof src !== 'object' || src === null || Array.isArray(src)) {
122
+ target[key] = deepExtend({}, val);
123
+ return;
124
+ }
125
+ // source value and new value is objects both, extending...
126
+ else {
127
+ target[key] = deepExtend(src, val);
128
+ return;
129
+ }
130
+ });
131
+ });
132
+ return target;
133
+ }
134
+ exports.default = deepExtend;
@@ -1,4 +1,4 @@
1
- import { StaticClass as StaticClass } from '../types';
1
+ import type { StaticClass } from '../types';
2
2
  export declare function generateStaticAPI(c: Record<string, StaticClass>, slug?: string): {
3
- [x: string]: string[];
3
+ [slug]: string[];
4
4
  }[];
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateStaticAPI = generateStaticAPI;
4
+ function generateStaticAPI(c, slug = 'vovk') {
5
+ const controllers = c;
6
+ return [
7
+ { [slug]: ['_schema_'] },
8
+ ...Object.values(controllers)
9
+ .map((controller) => {
10
+ const handlers = controller._handlers;
11
+ const splitPrefix = controller._prefix?.split('/') ?? [];
12
+ return Object.entries(handlers ?? {})
13
+ .map(([name, handler]) => {
14
+ const staticParams = controller._handlersMetadata?.[name]?.staticParams;
15
+ if (staticParams?.length) {
16
+ return staticParams.map((paramsItem) => {
17
+ let path = handler.path;
18
+ for (const [key, value] of Object.entries(paramsItem ?? {})) {
19
+ path = path.replace(`{${key}}`, value);
20
+ }
21
+ return { [slug]: [...splitPrefix, ...path.split('/')].filter(Boolean) };
22
+ });
23
+ }
24
+ return [{ [slug]: [...splitPrefix, ...handler.path.split('/')].filter(Boolean) }];
25
+ })
26
+ .flat();
27
+ })
28
+ .flat(),
29
+ ];
30
+ }
@@ -0,0 +1,11 @@
1
+ import { KnownAny, VovkBasicJSONSchema } from '../types';
2
+ interface SamplerOptions {
3
+ comment?: '//' | '#';
4
+ stripQuotes?: boolean;
5
+ indent?: number;
6
+ nestingIndent?: number;
7
+ ignoreBinary?: boolean;
8
+ }
9
+ export declare function getJSONSchemaExample(schema: VovkBasicJSONSchema, options: SamplerOptions, rootSchema?: VovkBasicJSONSchema): string;
10
+ export declare function getSampleValue(schema: VovkBasicJSONSchema, rootSchema?: VovkBasicJSONSchema, ignoreBinary?: boolean): KnownAny;
11
+ export {};
@@ -0,0 +1,264 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getJSONSchemaExample = getJSONSchemaExample;
4
+ exports.getSampleValue = getSampleValue;
5
+ function getJSONSchemaExample(schema, options, rootSchema) {
6
+ const { comment = '//', stripQuotes = false, indent = 0, nestingIndent = 4, ignoreBinary = false } = options;
7
+ if (!schema || typeof schema !== 'object')
8
+ return 'null';
9
+ // Use the input schema as the root if not provided
10
+ rootSchema = rootSchema || schema;
11
+ // Get the sample value
12
+ const sampleValue = getSampleValue(schema, rootSchema, ignoreBinary);
13
+ // Format the output with descriptions
14
+ return formatWithDescriptions(sampleValue, schema, rootSchema, comment, stripQuotes, indent, nestingIndent, ignoreBinary, true // isTopLevel
15
+ );
16
+ }
17
+ function getSampleValue(schema, rootSchema, ignoreBinary) {
18
+ if (!schema || typeof schema !== 'object')
19
+ return null;
20
+ rootSchema = rootSchema || schema;
21
+ // Check if this is a binary string schema and should be ignored
22
+ if (ignoreBinary && schema.type === 'string' && schema.format === 'binary') {
23
+ return undefined;
24
+ }
25
+ // If there's an example, use it
26
+ if (schema.example !== undefined) {
27
+ return schema.example;
28
+ }
29
+ // If there are examples, use one of them
30
+ if (schema.examples && schema.examples.length > 0) {
31
+ return schema.examples[0];
32
+ }
33
+ // Handle const if present
34
+ if (schema.const !== undefined) {
35
+ return schema.const;
36
+ }
37
+ // Handle $ref if present
38
+ if (schema.$ref) {
39
+ return handleRef(schema.$ref, rootSchema, ignoreBinary);
40
+ }
41
+ // Handle enum if present
42
+ if (schema.enum && schema.enum.length > 0) {
43
+ return schema.enum[0];
44
+ }
45
+ // Handle oneOf, anyOf, allOf
46
+ if (schema.oneOf && schema.oneOf.length > 0) {
47
+ return getSampleValue(schema.oneOf[0], rootSchema, ignoreBinary);
48
+ }
49
+ if (schema.anyOf && schema.anyOf.length > 0) {
50
+ return getSampleValue(schema.anyOf[0], rootSchema, ignoreBinary);
51
+ }
52
+ if (schema.allOf && schema.allOf.length > 0) {
53
+ // Merge all schemas in allOf
54
+ const mergedSchema = schema.allOf.reduce((acc, s) => ({ ...acc, ...s }), {});
55
+ return getSampleValue(mergedSchema, rootSchema, ignoreBinary);
56
+ }
57
+ // Handle different types
58
+ if (schema.type) {
59
+ switch (schema.type) {
60
+ case 'string':
61
+ return handleString(schema);
62
+ case 'number':
63
+ case 'integer':
64
+ return handleNumber(schema);
65
+ case 'boolean':
66
+ return handleBoolean();
67
+ case 'object':
68
+ return handleObject(schema, rootSchema, ignoreBinary);
69
+ case 'array':
70
+ return handleArray(schema, rootSchema, ignoreBinary);
71
+ case 'null':
72
+ return null;
73
+ default:
74
+ return null;
75
+ }
76
+ }
77
+ // If type is not specified but properties are, treat it as an object
78
+ if (schema.properties) {
79
+ return handleObject(schema, rootSchema, ignoreBinary);
80
+ }
81
+ // Default fallback
82
+ return null;
83
+ }
84
+ function formatWithDescriptions(value, schema, rootSchema, comment, stripQuotes, indent, nestingIndent, ignoreBinary, isTopLevel) {
85
+ const indentStr = ' '.repeat(indent);
86
+ const nestIndentStr = ' '.repeat(nestingIndent); // Create nesting indent string
87
+ // Handle undefined (for ignored binary fields)
88
+ if (value === undefined) {
89
+ return '';
90
+ }
91
+ // Handle null
92
+ if (value === null) {
93
+ return 'null';
94
+ }
95
+ // Handle primitives
96
+ if (typeof value !== 'object' || value instanceof Date) {
97
+ return JSON.stringify(value);
98
+ }
99
+ // Handle arrays
100
+ if (Array.isArray(value)) {
101
+ if (value.length === 0)
102
+ return '[]';
103
+ const items = value.map((item) => {
104
+ const itemSchema = schema.items || {};
105
+ const formattedItem = formatWithDescriptions(item, itemSchema, rootSchema, comment, stripQuotes, indent + nestingIndent, // Use nestingIndent instead of hardcoded 4
106
+ nestingIndent, ignoreBinary, false);
107
+ return `${indentStr}${nestIndentStr}${formattedItem}`; // Use nestIndentStr for item indentation
108
+ });
109
+ return `[\n${items.join(',\n')}\n${indentStr}]`;
110
+ }
111
+ // Handle objects
112
+ if (typeof value === 'object') {
113
+ const entries = Object.entries(value);
114
+ if (entries.length === 0)
115
+ return '{}';
116
+ const formattedEntries = [];
117
+ // Add top-level description for objects
118
+ if (isTopLevel && schema.type === 'object' && schema.description) {
119
+ const descLines = schema.description.split('\n');
120
+ formattedEntries.push(`${indentStr}${nestIndentStr}${comment} -----`);
121
+ descLines.forEach((line) => {
122
+ formattedEntries.push(`${indentStr}${nestIndentStr}${comment} ${line.trim()}`);
123
+ });
124
+ formattedEntries.push(`${indentStr}${nestIndentStr}${comment} -----`);
125
+ }
126
+ entries.forEach(([key, val], index) => {
127
+ const propSchema = schema.properties?.[key] ?? {};
128
+ // Handle $ref in property schema
129
+ let resolvedPropSchema = propSchema;
130
+ if (propSchema.$ref) {
131
+ resolvedPropSchema = resolveRef(propSchema.$ref, rootSchema);
132
+ }
133
+ // Add property description if it exists
134
+ if (resolvedPropSchema.description) {
135
+ const descLines = resolvedPropSchema.description.split('\n');
136
+ descLines.forEach((line) => {
137
+ formattedEntries.push(`${indentStr}${nestIndentStr}${comment} ${line.trim()}`);
138
+ });
139
+ }
140
+ // Format the key
141
+ const formattedKey = stripQuotes && /^[A-Za-z_$][0-9A-Za-z_$]*$/.test(key) ? key : JSON.stringify(key);
142
+ // Format the value
143
+ const formattedValue = formatWithDescriptions(val, resolvedPropSchema, rootSchema, comment, stripQuotes, indent + nestingIndent, nestingIndent, ignoreBinary, false);
144
+ formattedEntries.push(`${indentStr}${nestIndentStr}${formattedKey}: ${formattedValue}${index < entries.length - 1 ? ',' : ''}`);
145
+ });
146
+ return `{\n${formattedEntries.join('\n')}\n${indentStr}}`;
147
+ }
148
+ return JSON.stringify(value);
149
+ }
150
+ function resolveRef(ref, rootSchema) {
151
+ const path = ref.split('/').slice(1);
152
+ let current = rootSchema;
153
+ for (const segment of path) {
154
+ current = current[segment];
155
+ if (current === undefined) {
156
+ return {};
157
+ }
158
+ }
159
+ return current;
160
+ }
161
+ function handleRef(ref, rootSchema, ignoreBinary) {
162
+ const resolved = resolveRef(ref, rootSchema);
163
+ return getSampleValue(resolved, rootSchema, ignoreBinary);
164
+ }
165
+ function handleString(schema) {
166
+ if (schema.format) {
167
+ switch (schema.format) {
168
+ case 'email':
169
+ case 'idn-email':
170
+ return 'user@example.com';
171
+ case 'uri':
172
+ case 'url':
173
+ case 'iri':
174
+ return 'https://example.com';
175
+ case 'date':
176
+ return '2023-01-01';
177
+ case 'date-time':
178
+ return '2023-01-01T00:00:00Z';
179
+ case 'time':
180
+ return '12:00:00Z';
181
+ case 'duration':
182
+ return 'PT1H';
183
+ case 'uuid':
184
+ return '00000000-0000-0000-0000-000000000000';
185
+ case 'regex':
186
+ return '^[a-zA-Z0-9]+$';
187
+ case 'relative-json-pointer':
188
+ return '/some/relative/path';
189
+ case 'color':
190
+ return '#000000';
191
+ case 'hostname':
192
+ return 'example.com';
193
+ case 'zipcode':
194
+ return '12345';
195
+ case 'phone':
196
+ return '+123-456-7890';
197
+ case 'password':
198
+ return '******';
199
+ case 'binary':
200
+ return 'binary-data';
201
+ default:
202
+ return 'string';
203
+ }
204
+ }
205
+ if (schema.pattern) {
206
+ return 'pattern-string';
207
+ }
208
+ return 'string';
209
+ }
210
+ function handleNumber(schema) {
211
+ if (schema.minimum !== undefined && schema.maximum !== undefined) {
212
+ return schema.minimum;
213
+ }
214
+ else if (schema.minimum !== undefined) {
215
+ return schema.minimum;
216
+ }
217
+ else if (schema.maximum !== undefined) {
218
+ return schema.maximum;
219
+ }
220
+ return 0;
221
+ }
222
+ function handleBoolean() {
223
+ return true;
224
+ }
225
+ function handleObject(schema, rootSchema, ignoreBinary) {
226
+ const result = {};
227
+ if (schema.properties) {
228
+ const required = schema.required || [];
229
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
230
+ if (required.includes(key) || required.length === 0) {
231
+ const value = getSampleValue(propSchema, rootSchema, ignoreBinary);
232
+ // Only add the property if it's not undefined (which happens when ignoreBinary is true and it's a binary field)
233
+ if (value !== undefined) {
234
+ result[key] = value;
235
+ }
236
+ }
237
+ }
238
+ }
239
+ if (schema.additionalProperties && typeof schema.additionalProperties === 'object') {
240
+ const value = getSampleValue(schema.additionalProperties, rootSchema, ignoreBinary);
241
+ if (value !== undefined) {
242
+ result['additionalProp'] = value;
243
+ }
244
+ }
245
+ return result;
246
+ }
247
+ function handleArray(schema, rootSchema, ignoreBinary) {
248
+ if (schema.items) {
249
+ const itemSchema = schema.items;
250
+ // Check if the items are binary strings that should be ignored
251
+ if (ignoreBinary && itemSchema.type === 'string' && itemSchema.format === 'binary') {
252
+ return undefined;
253
+ }
254
+ const minItems = schema.minItems || 1;
255
+ const numItems = Math.min(minItems, 3);
256
+ const items = Array.from({ length: numItems }, () => getSampleValue(itemSchema, rootSchema, ignoreBinary)).filter((item) => item !== undefined); // Filter out undefined values from ignored binary items
257
+ // If all items were filtered out (e.g., all were binary), return undefined instead of empty array
258
+ if (items.length === 0 && numItems > 0) {
259
+ return undefined;
260
+ }
261
+ return items;
262
+ }
263
+ return [];
264
+ }
@@ -0,0 +1,2 @@
1
+ import { KnownAny } from '../types';
2
+ export declare function getJSONSchemaSample(schema: KnownAny, rootSchema?: KnownAny): KnownAny;