wormajs 0.3.1 → 1.0.0-beta.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 (52) hide show
  1. package/dist/bin/actions.js +162 -5
  2. package/dist/bin/cli.js +7 -1
  3. package/dist/bin/renderer.js +2 -8
  4. package/dist/checkUpdates.js +98 -0
  5. package/dist/config.js +7 -0
  6. package/dist/constant.js +1 -2
  7. package/dist/core/WorkerPool.js +14 -0
  8. package/dist/core/loader/callingCodeLoader/helper.js +2 -3
  9. package/dist/core/loader/callingCodeLoader/index.js +1 -1
  10. package/dist/core/parser/openApiParser/helper.js +32 -19
  11. package/dist/core/parser/templateParser/index.js +25 -12
  12. package/dist/core/workerPool/index.js +2 -1
  13. package/dist/functions/changeReport.js +230 -0
  14. package/dist/functions/diffApis.js +82 -0
  15. package/dist/functions/diffDocument.js +542 -0
  16. package/dist/functions/sourceSnapshot.js +107 -0
  17. package/dist/functions/wormaJson.js +306 -66
  18. package/dist/generate.js +24 -2
  19. package/dist/helper/config/ConfigHelper.js +1 -2
  20. package/dist/helper/config/ConfigManager.js +7 -0
  21. package/dist/helper/config/GeneratorHelper.js +74 -21
  22. package/dist/helper/config/zType.js +24 -1
  23. package/dist/helper/template/index.js +60 -4
  24. package/dist/index.js +17 -1
  25. package/dist/plugins/index.js +2 -2
  26. package/dist/plugins/presets/aiDoc.js +4 -0
  27. package/dist/plugins/presets/payloadModifier/dsl.js +147 -0
  28. package/dist/plugins/presets/payloadModifier/index.js +122 -135
  29. package/dist/plugins/presets/payloadModifier/patch.js +171 -0
  30. package/dist/plugins/presets/payloadModifier/scope.js +109 -0
  31. package/dist/plugins/presets/platform/index.js +1 -3
  32. package/dist/plugins/presets/postman.js +105 -0
  33. package/dist/template/presets/ai-doc/SKILL.md.handlebars +1 -1
  34. package/dist/template/presets/alova/common/services/{tag}.d.cts.handlebars +1 -1
  35. package/dist/template/presets/alova/module/services/{tag}.d.ts.handlebars +1 -1
  36. package/dist/template/presets/alova/partials/dts-fn-declare.handlebars +1 -1
  37. package/dist/template/presets/alova/partials/dts-types.handlebars +12 -0
  38. package/dist/template/presets/alova/typescript/services/{tag}.ts.handlebars +11 -6
  39. package/dist/template/presets/axios/partials/dts-types.handlebars +9 -5
  40. package/dist/template/presets/axios/typescript/services/{tag}.ts.handlebars +9 -5
  41. package/dist/template/presets/fetch/partials/dts-types.handlebars +8 -5
  42. package/dist/template/presets/fetch/typescript/services/{tag}.ts.handlebars +9 -5
  43. package/dist/template/presets/ky/partials/dts-types.handlebars +8 -5
  44. package/dist/template/presets/ky/typescript/services/{tag}.ts.handlebars +9 -5
  45. package/dist/utils/format.js +62 -15
  46. package/dist/utils/template.js +1 -1
  47. package/package.json +3 -2
  48. package/typings/index.d.ts +266 -13
  49. package/typings/plugins.d.ts +171 -80
  50. package/dist/plugins/presets/payloadModifier/hepler.js +0 -289
  51. package/dist/plugins/presets/platform/fastapi.js +0 -22
  52. package/dist/template/presets/alova/partials/dts-extra-config.handlebars +0 -8
@@ -1,289 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyModifierSchema = applyModifierSchema;
4
- // Detect a `SchemaOptional` wrapper: { required: boolean, type: Schema }.
5
- // The `required` must be a literal boolean so a plain SchemaReference whose
6
- // property happens to be named "required" (e.g. { required: 'boolean' }) is not misread.
7
- function isSchemaOptional(val) {
8
- return !!val
9
- && typeof val === 'object'
10
- && !Array.isArray(val)
11
- && typeof val.required === 'boolean'
12
- && 'type' in val;
13
- }
14
- // Collapse (possibly nested) `SchemaOptional` wrappers.
15
- // - The OUTERMOST `required` wins; inner `required` fields are ignored.
16
- // - A non-wrapped value defaults to required (required: true).
17
- function unwrapOptional(s) {
18
- if (!isSchemaOptional(s)) {
19
- return { required: true, type: s };
20
- }
21
- const required = s.required;
22
- let type = s.type;
23
- while (isSchemaOptional(type)) {
24
- type = type.type;
25
- }
26
- return { required, type };
27
- }
28
- // Remove the internal `_$ref` marker that `removeAll$ref` stamps onto dereferenced
29
- // component schemas. When a handler replaces a schema, the result must NOT inherit the
30
- // original component's `_$ref` — otherwise `mergeObject`/`removeBaseReference` downstream
31
- // treats the replacement as a reference to the original component and discards the change.
32
- function stripInternalRef(schema) {
33
- if (!schema || typeof schema !== 'object') {
34
- return schema;
35
- }
36
- if (Array.isArray(schema)) {
37
- return schema.map(stripInternalRef);
38
- }
39
- const out = {};
40
- for (const key of Object.keys(schema)) {
41
- if (key === '_$ref') {
42
- continue;
43
- }
44
- out[key] = stripInternalRef(schema[key]);
45
- }
46
- return out;
47
- }
48
- // Set of valid SchemaPrimitive values for O(1) validation lookup
49
- const VALID_PRIMITIVES = new Set([
50
- 'number',
51
- 'string',
52
- 'boolean',
53
- 'undefined',
54
- 'null',
55
- 'unknown',
56
- 'any',
57
- 'never',
58
- 'integer',
59
- ]);
60
- function validatePrimitive(val) {
61
- if (!VALID_PRIMITIVES.has(val)) {
62
- throw new Error(`[payloadModifier] Invalid schema type "${val}". Must be one of: ${[...VALID_PRIMITIVES].join(', ')}`);
63
- }
64
- }
65
- // Convert Schema (custom spec) -> OpenAPI SchemaObject
66
- function toSchemaObject(base, s) {
67
- // A `SchemaOptional` wrapper only affects requiredness (handled by the caller);
68
- // here we care about the type shape, so fully unwrap nested wrappers first.
69
- if (isSchemaOptional(s)) {
70
- s = unwrapOptional(s).type;
71
- }
72
- const result = { ...base };
73
- const cleanType = (schema) => {
74
- delete schema.type;
75
- delete schema.enum;
76
- delete schema.oneOf;
77
- delete schema.anyOf;
78
- delete schema.allOf;
79
- delete schema.items;
80
- delete schema.properties;
81
- delete schema.required;
82
- return schema;
83
- };
84
- // Native array type (elements are Schema)
85
- if (Array.isArray(s)) {
86
- const arr = s;
87
- cleanType(result);
88
- result.type = 'array';
89
- const items = arr.map(item => toSchemaObject({}, item));
90
- result.items = (items.length === 1 ? items[0] : items);
91
- return result;
92
- }
93
- // Primitive types — validate against SchemaPrimitive set during conversion
94
- if (typeof s === 'string') {
95
- validatePrimitive(s);
96
- result.type = s;
97
- return result;
98
- }
99
- // Handle union keywords: overwrite arrays but preserve unrelated fields
100
- if (s.oneOf) {
101
- const spec = s;
102
- const baseOneOf = base.oneOf || [];
103
- cleanType(result);
104
- result.oneOf = spec.oneOf.map((item, idx) => toSchemaObject(baseOneOf[idx] || {}, item));
105
- return result;
106
- }
107
- if (s.anyOf) {
108
- const spec = s;
109
- const baseAnyOf = base.anyOf || [];
110
- cleanType(result);
111
- result.anyOf = spec.anyOf.map((item, idx) => toSchemaObject(baseAnyOf[idx] || {}, item));
112
- return result;
113
- }
114
- if (s.allOf) {
115
- const spec = s;
116
- const baseAllOf = base.allOf || [];
117
- cleanType(result);
118
- result.allOf = spec.allOf.map((item, idx) => toSchemaObject(baseAllOf[idx] || {}, item));
119
- return result;
120
- }
121
- // Enum: set enum and optional type
122
- if (s.enum) {
123
- const spec = s;
124
- result.enum = spec.enum;
125
- if (spec.type) {
126
- if (typeof spec.type === 'string') {
127
- validatePrimitive(spec.type);
128
- }
129
- result.type = spec.type;
130
- }
131
- return result;
132
- }
133
- // Object (reference-like map): replace properties and required with handler's spec
134
- // (the SchemaReference returned by the handler fully replaces this field, only keeping
135
- // scalar fields like description from base)
136
- const ref = s;
137
- if (ref && typeof ref === 'object') {
138
- result.type = 'object';
139
- const properties = {};
140
- const requiredSet = new Set();
141
- for (const key in ref) {
142
- const val = ref[key];
143
- if (!val) {
144
- continue;
145
- }
146
- // SchemaOptional wrapper: optionality expressed via { required, type };
147
- // bare value defaults to required. Nested wrappers are collapsed — outermost
148
- // `required` wins, inner ones are ignored.
149
- let isOptional;
150
- let effectiveVal;
151
- if (isSchemaOptional(val)) {
152
- const { required, type } = unwrapOptional(val);
153
- isOptional = !required;
154
- effectiveVal = type;
155
- }
156
- else {
157
- isOptional = false;
158
- effectiveVal = val;
159
- }
160
- const baseProp = properties[key];
161
- properties[key] = toSchemaObject(baseProp || {}, effectiveVal);
162
- if (isOptional) {
163
- requiredSet.delete(key);
164
- }
165
- else {
166
- requiredSet.add(key);
167
- }
168
- }
169
- result.properties = properties;
170
- result.required = Array.from(requiredSet);
171
- return result;
172
- }
173
- return result;
174
- }
175
- function schemaTypeToPrimitiveType(t) {
176
- if (t === null) {
177
- return 'null';
178
- }
179
- if (t === undefined) {
180
- return 'undefined';
181
- }
182
- if (!t) {
183
- return 'unknown';
184
- }
185
- if (t === 'integer') {
186
- return 'number';
187
- }
188
- return t;
189
- }
190
- // Convert existing OpenAPI SchemaObject -> Schema (best-effort, for handler input)
191
- function toSchemaSpec(obj) {
192
- if (!obj || typeof obj !== 'object') {
193
- return 'unknown';
194
- }
195
- // Union keywords
196
- if (Array.isArray(obj.oneOf)) {
197
- const arr = obj.oneOf;
198
- return { oneOf: arr.map(item => toSchemaSpec(item)) };
199
- }
200
- if (Array.isArray(obj.anyOf)) {
201
- const arr = obj.anyOf;
202
- return { anyOf: arr.map(item => toSchemaSpec(item)) };
203
- }
204
- if (Array.isArray(obj.allOf)) {
205
- const arr = obj.allOf;
206
- return { allOf: arr.map(item => toSchemaSpec(item)) };
207
- }
208
- // Enum
209
- if (Array.isArray(obj.enum) && obj.enum.length > 0) {
210
- const type = typeof obj.type === 'string' ? obj.type : undefined;
211
- return { enum: obj.enum, type };
212
- }
213
- // Array -> native array
214
- if (obj.type === 'array' || obj.items) {
215
- const items = obj.items;
216
- if (Array.isArray(items)) {
217
- return items.map((it) => toSchemaSpec(it));
218
- }
219
- if (items) {
220
- return [toSchemaSpec(items)];
221
- }
222
- return ['unknown'];
223
- }
224
- // Object
225
- if (obj.type === 'object' || obj.properties) {
226
- const properties = obj.properties || {};
227
- const requiredSet = new Set(Array.isArray(obj.required) ? obj.required : []);
228
- const result = {};
229
- for (const key of Object.keys(properties)) {
230
- const spec = toSchemaSpec(properties[key]);
231
- // Required fields are written bare; optional fields wrapped with SchemaOptional
232
- result[key] = requiredSet.has(key) ? spec : { required: false, type: spec };
233
- }
234
- return result;
235
- }
236
- // type union as array -> oneOf
237
- if (Array.isArray(obj.type)) {
238
- const typeArr = obj.type;
239
- const mapped = typeArr.map(schemaTypeToPrimitiveType);
240
- return { oneOf: mapped };
241
- }
242
- return schemaTypeToPrimitiveType(obj.type);
243
- }
244
- // Replace whole schema based on handler result (used for params/pathParams)
245
- function applyModifierSchema(schema, config, { required, key }) {
246
- if (!schema || typeof schema !== 'object') {
247
- return { required, schema: schema };
248
- }
249
- const cloned = { ...schema };
250
- const currentSpec = toSchemaSpec(cloned);
251
- // When the field is itself optional and is a primitive, wrap it as { required, type } before passing to handler
252
- const handlerInput = (required === false && typeof currentSpec === 'string')
253
- ? { required: false, type: currentSpec }
254
- : currentSpec;
255
- const ret = config.handler(handlerInput, key);
256
- if (!ret) {
257
- return {
258
- required,
259
- schema: null,
260
- };
261
- }
262
- // A returned SchemaOptional means changing requiredness (driven by the `type` field).
263
- // Nested wrappers are collapsed: the outermost `required` wins, inner ones are ignored;
264
- // `type` may be any Schema expression (primitive, object, array, union, ...).
265
- if (isSchemaOptional(ret)) {
266
- const { required: nextRequired, type } = unwrapOptional(ret);
267
- let r = stripInternalRef(toSchemaObject(cloned, type));
268
- // When handler explicitly sets required=false, propagate to object-level required array
269
- // so all properties become nullable as semantically expected
270
- if (!nextRequired && r && typeof r === 'object' && !Array.isArray(r)) {
271
- const robj = r;
272
- if (robj.type === 'object' && Array.isArray(robj.required) && robj.required.length > 0) {
273
- r = { ...r, required: [] };
274
- }
275
- }
276
- return {
277
- required: nextRequired,
278
- schema: r,
279
- };
280
- }
281
- // Non-SchemaOptional return: handler explicitly provides a type value,
282
- // so default to required=true (the handler had the chance to wrap with
283
- // { required: false, type: ... } if it wanted to keep it optional).
284
- const r = stripInternalRef(toSchemaObject(cloned, ret));
285
- return {
286
- required: true,
287
- schema: r,
288
- };
289
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fastapi = void 0;
4
- const constant_1 = require("../../../constant");
5
- const shared_1 = require("./shared");
6
- /**
7
- * FastAPI platform plugin.
8
- *
9
- * Pass the base URL of your FastAPI app; the plugin will try `/openapi.json`
10
- * first, then fall back to the bare base URL.
11
- *
12
- * @param input - base URL string, or an array of base URLs
13
- *
14
- * @example
15
- * ```ts
16
- * plugins: [fastapi('http://fastapi-example.dokkuapp.com'), alovaGlobals()]
17
- * ```
18
- */
19
- exports.fastapi = (0, shared_1.defineUrlPlatformPlugin)(constant_1.PluginName.FASTAPI, base => [
20
- `${base}/openapi.json`,
21
- base,
22
- ]);
@@ -1,8 +0,0 @@
1
- {{#or pathParameters queryParameters requestBody}}
2
- type {{{name}}}ExtraConfig = {
3
- {{#if pathParameters}}pathParams: {{addNamespace pathParameters @root.componentNames}};
4
- {{/if}}{{#if queryParameters}}params: {{addNamespace queryParameters @root.componentNames}};
5
- {{/if}}{{#if requestBody}}data: {{addNamespace requestBody @root.componentNames}};
6
- {{/if}}
7
- };
8
- {{/or}}