@automatons/tools 1.0.218 → 2.0.1

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 (57) hide show
  1. package/index.d.ts +334 -6
  2. package/index.js +120 -17
  3. package/index.js.map +1 -1
  4. package/package.json +38 -33
  5. package/index.d.ts.map +0 -1
  6. package/types/automaton.d.ts +0 -12
  7. package/types/automaton.d.ts.map +0 -1
  8. package/types/automaton.js +0 -3
  9. package/types/automaton.js.map +0 -1
  10. package/types/http.d.ts +0 -2
  11. package/types/http.d.ts.map +0 -1
  12. package/types/http.js +0 -3
  13. package/types/http.js.map +0 -1
  14. package/types/index.d.ts +0 -4
  15. package/types/index.d.ts.map +0 -1
  16. package/types/index.js +0 -20
  17. package/types/index.js.map +0 -1
  18. package/types/openapi.d.ts +0 -284
  19. package/types/openapi.d.ts.map +0 -1
  20. package/types/openapi.js +0 -3
  21. package/types/openapi.js.map +0 -1
  22. package/utils/fetch.d.ts +0 -3
  23. package/utils/fetch.d.ts.map +0 -1
  24. package/utils/fetch.js +0 -41
  25. package/utils/fetch.js.map +0 -1
  26. package/utils/index.d.ts +0 -7
  27. package/utils/index.d.ts.map +0 -1
  28. package/utils/index.js +0 -23
  29. package/utils/index.js.map +0 -1
  30. package/utils/openapi.d.ts +0 -3
  31. package/utils/openapi.d.ts.map +0 -1
  32. package/utils/openapi.js +0 -6
  33. package/utils/openapi.js.map +0 -1
  34. package/utils/parameter.d.ts +0 -12
  35. package/utils/parameter.d.ts.map +0 -1
  36. package/utils/parameter.js +0 -17
  37. package/utils/parameter.js.map +0 -1
  38. package/utils/reference.d.ts +0 -6
  39. package/utils/reference.d.ts.map +0 -1
  40. package/utils/reference.js +0 -39
  41. package/utils/reference.js.map +0 -1
  42. package/utils/schema.d.ts +0 -11
  43. package/utils/schema.d.ts.map +0 -1
  44. package/utils/schema.js +0 -22
  45. package/utils/schema.js.map +0 -1
  46. package/utils/url.d.ts +0 -2
  47. package/utils/url.d.ts.map +0 -1
  48. package/utils/url.js +0 -6
  49. package/utils/url.js.map +0 -1
  50. package/values/http.d.ts +0 -3
  51. package/values/http.d.ts.map +0 -1
  52. package/values/http.js +0 -5
  53. package/values/http.js.map +0 -1
  54. package/values/index.d.ts +0 -2
  55. package/values/index.d.ts.map +0 -1
  56. package/values/index.js +0 -18
  57. package/values/index.js.map +0 -1
package/index.d.ts CHANGED
@@ -1,13 +1,341 @@
1
- export * from './values';
2
- export * from './types';
3
- export * from './utils';
4
- export declare type Setting = {
1
+ type Method = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace';
2
+
3
+ interface Openapi {
4
+ openapi: string;
5
+ info: OpenapiInfo;
6
+ servers?: OpenapiServer[];
7
+ tags?: OpenapiTag[];
8
+ paths: OpenapiMap<OpenapiPath>;
9
+ components?: OpenapiComponents;
10
+ security?: OpenapiSecurity[];
11
+ externalDocs?: OpenapiExternalDocument;
12
+ }
13
+ interface OpenapiMap<T> {
14
+ [key: string]: T;
15
+ }
16
+ interface OpenapiInfo {
17
+ title: string;
18
+ version: string;
19
+ description?: string;
20
+ termsOfService?: string;
21
+ contact?: OpenapiInfoContact;
22
+ license?: OpenapiInfoLicense;
23
+ }
24
+ interface OpenapiInfoContact {
25
+ name: string;
26
+ url?: string;
27
+ }
28
+ interface OpenapiInfoLicense {
29
+ name: string;
30
+ url?: string;
31
+ }
32
+ interface OpenapiServer {
33
+ url: string;
34
+ 'x-name'?: string;
35
+ description?: string;
36
+ variables?: OpenapiMap<OpenapiServerVariable>;
37
+ }
38
+ interface OpenapiServerVariable {
39
+ default: string;
40
+ description?: string;
41
+ enum: string[];
42
+ }
43
+ interface OpenapiExternalDocument {
44
+ url: string;
45
+ description?: string;
46
+ }
47
+ interface OpenapiTag {
48
+ name: string;
49
+ description?: string;
50
+ externalDocs?: OpenapiExternalDocument;
51
+ }
52
+ interface OpenapiSecurity {
53
+ [key: string]: string[];
54
+ }
55
+ interface OpenapiPath {
56
+ '$ref'?: string;
57
+ get?: OpenapiPathOperation;
58
+ put?: OpenapiPathOperation;
59
+ post?: OpenapiPathOperation;
60
+ delete?: OpenapiPathOperation;
61
+ options?: OpenapiPathOperation;
62
+ head?: OpenapiPathOperation;
63
+ patch?: OpenapiPathOperation;
64
+ trace?: OpenapiPathOperation;
65
+ servers?: OpenapiServer[];
66
+ parameters?: OpenapiParameter[];
67
+ }
68
+ type OpenapiParameter = OpenapiParameterPath | OpenapiParameterQuery | OpenapiParameterHeader | OpenapiParameterCookie | OpenapiReference;
69
+ type OpenapiParameterCommon = {
70
+ name: string;
71
+ description?: string;
72
+ deprecated?: string;
73
+ explode?: boolean;
74
+ example?: any;
75
+ examples?: OpenapiMap<OpenapiExample>;
76
+ } & ({
77
+ content: OpenapiMap<OpenapiPathMedia>;
78
+ } | {
79
+ schema: OpenapiSchema;
80
+ });
81
+ type OpenapiParameterPath = {
82
+ in: 'path';
83
+ style: 'simple' | 'label' | 'matrix';
84
+ required: true;
85
+ } & OpenapiParameterCommon;
86
+ type OpenapiParameterQuery = {
87
+ in: 'query';
88
+ style: 'form' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject';
89
+ required?: boolean;
90
+ allowReserved?: boolean;
91
+ } & OpenapiParameterCommon;
92
+ type OpenapiParameterHeader = {
93
+ in: 'header';
94
+ style: 'simple';
95
+ required?: boolean;
96
+ } & OpenapiParameterCommon;
97
+ type OpenapiParameterCookie = {
98
+ in: 'cookie';
99
+ style: 'form';
100
+ required?: boolean;
101
+ } & OpenapiParameterCommon;
102
+ interface OpenapiPathOperation extends OpenapiPathCommon {
103
+ operationId: string;
104
+ tags?: string[];
105
+ externalDocs?: OpenapiExternalDocument;
106
+ parameters?: OpenapiParameter[];
107
+ requestBody?: OpenapiPathRequestBody | OpenapiReference;
108
+ responses: OpenapiMap<OpenapiPathResponse | OpenapiReference>;
109
+ callbacks?: OpenapiMap<OpenapiMap<OpenapiPathOperation>>;
110
+ deprecated?: boolean;
111
+ security?: OpenapiMap<string[]>[];
112
+ servers?: OpenapiServer[];
113
+ }
114
+ interface OpenapiPathRequestBody {
115
+ content: OpenapiMap<OpenapiPathMedia>;
116
+ description?: string;
117
+ required?: boolean;
118
+ }
119
+ type OpenapiPathResponse = {
120
+ description: string;
121
+ headers?: OpenapiMap<OpenapiPathResponseHeader | OpenapiReference>;
122
+ content?: OpenapiMap<OpenapiPathMedia>;
123
+ links?: OpenapiMap<OpenapiPathResponseLink | OpenapiReference>;
124
+ };
125
+ interface OpenapiPathResponseHeader {
126
+ description?: string;
127
+ schema?: OpenapiSchema;
128
+ }
129
+ type OpenapiPathMedia = {
130
+ schema?: OpenapiSchema;
131
+ encoding?: OpenapiMap<OpenapiPathResponseMediaEncoding>;
132
+ } & ({
133
+ example?: any;
134
+ } | {
135
+ examples?: OpenapiMap<OpenapiExample>;
136
+ });
137
+ type OpenapiExample = {
138
+ summary?: string;
139
+ description?: string;
140
+ value?: any;
141
+ externalValue?: string;
142
+ };
143
+ interface OpenapiPathResponseMediaEncoding {
144
+ contentType?: string;
145
+ headers?: OpenapiMap<OpenapiPathResponseHeader | OpenapiReference>;
146
+ style?: string;
147
+ explode?: boolean;
148
+ allowReserved?: boolean;
149
+ }
150
+ interface OpenapiPathResponseLink {
151
+ operationRef?: string;
152
+ operationId?: string;
153
+ parameters?: OpenapiMap<any>;
154
+ requestBody?: any;
155
+ description?: string;
156
+ server?: OpenapiServer;
157
+ }
158
+ interface OpenapiPathCommon {
159
+ summary?: string;
160
+ description?: string;
161
+ }
162
+ interface OpenapiComponents {
163
+ schemas?: OpenapiMap<OpenapiSchema>;
164
+ responses?: object;
165
+ parameters?: object;
166
+ examples?: object;
167
+ requestBodies?: object;
168
+ headers?: object;
169
+ securitySchemes?: OpenapiMap<OpenapiSecuritySchema>;
170
+ links?: object;
171
+ callbacks?: object;
172
+ }
173
+ type OpenapiSchema = OpenapiSchemaString | OpenapiSchemaBoolean | OpenapiSchemaNumber | OpenapiSchemaInteger | OpenapiSchemaObject | OpenapiSchemaArray | OpenapiSchemaAllOf | OpenapiSchemaOneOf | OpenapiSchemaReference;
174
+ type OpenapiSchemaReference = OpenapiReference & OpenapiSchemaCommon;
175
+ interface OpenapiSchemaString extends OpenapiSchemaCommon {
176
+ type: 'string';
177
+ format?: 'date' | 'date-time' | 'password' | 'byte' | 'binary' | string;
178
+ minLength?: number;
179
+ maxLength?: number;
180
+ pattern?: string;
181
+ enum?: string[];
182
+ }
183
+ interface OpenapiReference extends OpenapiSchemaCommon {
184
+ '$ref': string;
185
+ }
186
+ interface OpenapiSchemaBoolean extends OpenapiSchemaCommon {
187
+ type: 'boolean';
188
+ }
189
+ interface OpenapiSchemaNumber extends OpenapiSchemaCommon {
190
+ type: 'number';
191
+ format?: 'float' | 'double' | string;
192
+ enum?: number[];
193
+ multipleOf?: number;
194
+ minimum?: number;
195
+ exclusiveMinimum?: boolean;
196
+ maximum?: number;
197
+ exclusiveMaximum?: boolean;
198
+ }
199
+ interface OpenapiSchemaInteger extends OpenapiSchemaCommon {
200
+ type: 'integer';
201
+ format?: 'int32' | 'int64' | string;
202
+ enum?: number[];
203
+ multipleOf?: number;
204
+ minimum?: number;
205
+ exclusiveMinimum?: boolean;
206
+ maximum?: number;
207
+ exclusiveMaximum?: boolean;
208
+ }
209
+ interface OpenapiSchemaObject extends OpenapiSchemaCommon {
210
+ type: 'object';
211
+ required?: string[];
212
+ minProperties?: number;
213
+ maxProperties?: number;
214
+ properties?: OpenapiMap<OpenapiSchema>;
215
+ additionalProperties?: true | OpenapiSchema;
216
+ }
217
+ interface OpenapiSchemaArray extends OpenapiSchemaCommon {
218
+ type: 'array';
219
+ uniqueItems?: boolean;
220
+ minItems?: number;
221
+ maxItems?: number;
222
+ items?: OpenapiSchema;
223
+ }
224
+ interface OpenapiSchemaAllOf extends OpenapiSchemaCommon {
225
+ allOf: OpenapiSchema[];
226
+ }
227
+ interface OpenapiSchemaOneOf extends OpenapiSchemaCommon {
228
+ oneOf: OpenapiSchema[];
229
+ discriminator?: {
230
+ propertyName: string;
231
+ mapping?: {
232
+ [key: string]: string;
233
+ };
234
+ };
235
+ }
236
+ interface OpenapiSchemaCommon {
237
+ title?: string;
238
+ description?: string;
239
+ default?: any;
240
+ nullable?: boolean;
241
+ readOnly?: boolean;
242
+ writeOnly?: boolean;
243
+ externalDocs?: OpenapiExternalDocument;
244
+ deprecated?: boolean;
245
+ example?: any;
246
+ }
247
+ type OpenapiSecuritySchema = OpenapiSecurityApiKeySchema | OpenapiSecurityHttpSchema | OpenapiSecurityHttpBearerSchema | OpenapiSecurityOAuth2Schema | OpenapiSecurityOpenIdConnectSchema;
248
+ interface OpenapiSecurityApiKeySchema {
249
+ type: 'apiKey';
250
+ description?: string;
251
+ name: string;
252
+ in: 'query' | 'header' | 'cookie';
253
+ }
254
+ interface OpenapiSecurityHttpSchema {
255
+ type: 'http';
256
+ description?: string;
257
+ scheme: 'basic';
258
+ }
259
+ interface OpenapiSecurityHttpBearerSchema {
260
+ type: 'http';
261
+ description?: string;
262
+ scheme: 'bearer';
263
+ bearerFormat?: string;
264
+ }
265
+ interface OpenapiSecurityOAuth2Schema {
266
+ type: 'oauth2';
267
+ description?: string;
268
+ flow: {
269
+ implicit?: OpenapiSecurityOAuthFlow;
270
+ password?: OpenapiSecurityOAuthFlow;
271
+ clientCredentials?: OpenapiSecurityOAuthFlow;
272
+ authorizationCode?: OpenapiSecurityOAuthFlow;
273
+ };
274
+ }
275
+ interface OpenapiSecurityOAuthFlow {
276
+ authorizationUrl: string;
277
+ tokenUrl: string;
278
+ refreshUrl?: string;
279
+ scopes: OpenapiMap<string>;
280
+ }
281
+ interface OpenapiSecurityOpenIdConnectSchema {
282
+ type: 'openIdConnect';
283
+ description?: string;
284
+ openIdConnectUrl: string;
285
+ }
286
+
287
+ type AutomatonContext = {
288
+ openapi: Openapi;
289
+ settings: AutomatonSettings;
290
+ };
291
+ type AutomatonSettings = {
292
+ outDir: string;
293
+ path: string;
294
+ openapiPath: string;
295
+ };
296
+ type Automaton = (openapi: Openapi, settings: AutomatonSettings, options?: object) => void | Promise<unknown>;
297
+
298
+ declare const HTTP_METHODS: Method[];
299
+
300
+ declare const fetch: <T = Openapi>(url: string, openapiPath?: string) => Promise<T>;
301
+
302
+ declare const isRef: (schema: any) => schema is OpenapiReference;
303
+
304
+ declare const hasSchema: (param: OpenapiParameter) => param is OpenapiParameter & {
305
+ schema: OpenapiSchema;
306
+ };
307
+ declare const hasContent: (param: OpenapiParameter) => param is OpenapiParameter & {
308
+ content: OpenapiMap<OpenapiPathMedia>;
309
+ };
310
+ declare const isPathParam: (param: OpenapiParameter) => param is OpenapiParameterPath;
311
+ declare const isQueryParam: (param: OpenapiParameter) => param is OpenapiParameterQuery;
312
+ declare const isHeaderParam: (param: OpenapiParameter) => param is OpenapiParameterHeader;
313
+ declare const isCookieParam: (param: OpenapiParameter) => param is OpenapiParameterCookie;
314
+
315
+ declare const referenceTitle: (schema: OpenapiReference) => string;
316
+ type ReferenceSchema<T = unknown> = (T | OpenapiReference) | (T & OpenapiReference);
317
+ declare const referenceSchema: <T = unknown>(schema: ReferenceSchema<T>, { openapi, settings: { openapiPath } }: AutomatonContext) => Promise<T>;
318
+
319
+ declare const isSchemaString: (type: OpenapiSchema) => type is OpenapiSchemaString;
320
+ declare const isSchemaNumber: (type: OpenapiSchema) => type is OpenapiSchemaNumber;
321
+ declare const isSchemaInteger: (type: OpenapiSchema) => type is OpenapiSchemaInteger;
322
+ declare const isSchemaBoolean: (type: OpenapiSchema) => type is OpenapiSchemaBoolean;
323
+ declare const isSchemaObject: (type: OpenapiSchema) => type is OpenapiSchemaObject;
324
+ declare const isSchemaArray: (type: OpenapiSchema) => type is OpenapiSchemaArray;
325
+ declare const isSchemaAllOf: (type: OpenapiSchema) => type is OpenapiSchemaAllOf;
326
+ declare const isSchemaOneOf: (type: OpenapiSchema) => type is OpenapiSchemaOneOf;
327
+ declare const isSchemaRef: (type: OpenapiSchema) => type is OpenapiSchemaReference;
328
+
329
+ declare const isUrl: (url: string) => boolean;
330
+
331
+ type Setting = {
5
332
  openapi: string;
6
333
  automatons: AutomatonSetting[];
7
334
  };
8
- export declare type AutomatonSetting = {
335
+ type AutomatonSetting = {
9
336
  automaton: string;
10
337
  outDir: string;
11
338
  options?: object;
12
339
  };
13
- //# sourceMappingURL=index.d.ts.map
340
+
341
+ export { type Automaton, type AutomatonContext, type AutomatonSetting, type AutomatonSettings, HTTP_METHODS, type Method, type Openapi, type OpenapiComponents, type OpenapiExample, type OpenapiExternalDocument, type OpenapiInfo, type OpenapiInfoContact, type OpenapiInfoLicense, type OpenapiMap, type OpenapiParameter, type OpenapiParameterCommon, type OpenapiParameterCookie, type OpenapiParameterHeader, type OpenapiParameterPath, type OpenapiParameterQuery, type OpenapiPath, type OpenapiPathCommon, type OpenapiPathMedia, type OpenapiPathOperation, type OpenapiPathRequestBody, type OpenapiPathResponse, type OpenapiPathResponseHeader, type OpenapiPathResponseLink, type OpenapiPathResponseMediaEncoding, type OpenapiReference, type OpenapiSchema, type OpenapiSchemaAllOf, type OpenapiSchemaArray, type OpenapiSchemaBoolean, type OpenapiSchemaCommon, type OpenapiSchemaInteger, type OpenapiSchemaNumber, type OpenapiSchemaObject, type OpenapiSchemaOneOf, type OpenapiSchemaReference, type OpenapiSchemaString, type OpenapiSecurity, type OpenapiSecurityApiKeySchema, type OpenapiSecurityHttpBearerSchema, type OpenapiSecurityHttpSchema, type OpenapiSecurityOAuth2Schema, type OpenapiSecurityOAuthFlow, type OpenapiSecurityOpenIdConnectSchema, type OpenapiSecuritySchema, type OpenapiServer, type OpenapiServerVariable, type OpenapiTag, type Setting, fetch, hasContent, hasSchema, isCookieParam, isHeaderParam, isPathParam, isQueryParam, isRef, isSchemaAllOf, isSchemaArray, isSchemaBoolean, isSchemaInteger, isSchemaNumber, isSchemaObject, isSchemaOneOf, isSchemaRef, isSchemaString, isUrl, referenceSchema, referenceTitle };
package/index.js CHANGED
@@ -1,20 +1,123 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
1
+ // src/values/http.ts
2
+ var HTTP_METHODS = ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
3
+
4
+ // src/utils/fetch.ts
5
+ import { readFile } from "fs/promises";
6
+ import { dirname, extname, resolve } from "path";
7
+ import { load } from "js-yaml";
8
+
9
+ // src/utils/url.ts
10
+ var isUrl = (url) => url.startsWith("http://") || url.startsWith("https://");
11
+
12
+ // src/utils/fetch.ts
13
+ var fetch = async (url, openapiPath) => parse(await read(url, openapiPath), url);
14
+ var read = async (url, openapiPath) => {
15
+ if (isUrl(url)) {
16
+ return fetchText(url);
17
+ }
18
+ if (openapiPath && isUrl(openapiPath)) {
19
+ return fetchText(new URL(url, openapiPath).toString());
20
+ }
21
+ const base = openapiPath ? extname(openapiPath) ? dirname(openapiPath) : openapiPath : "";
22
+ return readFile(resolve(base, url), { encoding: "utf-8" });
23
+ };
24
+ var fetchText = async (url) => {
25
+ const response = await globalThis.fetch(url);
26
+ if (!response.ok) {
27
+ throw new Error(`Failed to fetch ${url}: ${response.status} ${response.statusText}`);
28
+ }
29
+ return response.text();
30
+ };
31
+ var parse = (data, filePath) => {
32
+ switch (extname(filePath)) {
33
+ case ".json":
34
+ return JSON.parse(data);
35
+ case ".yml":
36
+ case ".yaml": {
37
+ const yaml = load(data);
38
+ if (typeof yaml === "object") {
39
+ return yaml;
40
+ }
41
+ throw new Error("Unsupported file format");
42
+ }
43
+ default:
44
+ throw new Error("Unsupported file extension");
45
+ }
46
+ };
47
+
48
+ // src/utils/openapi.ts
49
+ var isRef = (schema) => Object.hasOwn(schema, "$ref");
50
+
51
+ // src/utils/parameter.ts
52
+ var hasSchema = (param) => Object.hasOwn(param, "schema");
53
+ var hasContent = (param) => Object.hasOwn(param, "content");
54
+ var isPathParam = (param) => !isRef(param) && param.in === "path";
55
+ var isQueryParam = (param) => !isRef(param) && param.in === "query";
56
+ var isHeaderParam = (param) => !isRef(param) && param.in === "header";
57
+ var isCookieParam = (param) => !isRef(param) && param.in === "cookie";
58
+
59
+ // src/utils/reference.ts
60
+ import { parse as parse2 } from "path";
61
+ var referenceTitle = (schema) => {
62
+ const [url = "", path = ""] = schema.$ref.split("#");
63
+ const paths = path.split("/").slice(1);
64
+ if (paths.length) {
65
+ return paths[paths.length - 1];
66
+ } else if (isUrl(url)) {
67
+ return parse2(url).name;
68
+ }
69
+ throw new Error(`Invalid ref format: ${schema.$ref}
70
+ Can not extract name.`);
71
+ };
72
+ var referenceSchema = async (schema, { openapi, settings: { openapiPath } }) => {
73
+ if (!isRef(schema)) return schema;
74
+ const [url, path] = schema.$ref.split("#");
75
+ const file = url ? await fetch(url, openapiPath) : openapi;
76
+ if (!path) {
77
+ if (!file) {
78
+ throw new Error(`Invalid ref path ${schema.$ref}`);
7
79
  }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
80
+ return file;
81
+ }
82
+ const paths = path?.split("/").slice(1);
83
+ const extractSchema = paths?.reduce((pre, cur) => pre?.[cur], file);
84
+ if (!extractSchema) {
85
+ throw new Error(`Invalid ref path ${schema.$ref}`);
86
+ }
87
+ return extractSchema;
88
+ };
89
+
90
+ // src/utils/schema.ts
91
+ var isSchemaString = (type) => type.type === "string";
92
+ var isSchemaNumber = (type) => type.type === "number";
93
+ var isSchemaInteger = (type) => type.type === "integer";
94
+ var isSchemaBoolean = (type) => type.type === "boolean";
95
+ var isSchemaObject = (type) => type.type === "object" || Object.hasOwn(type, "properties");
96
+ var isSchemaArray = (type) => type.type === "array" || Object.hasOwn(type, "items");
97
+ var isSchemaAllOf = (type) => Object.hasOwn(type, "allOf");
98
+ var isSchemaOneOf = (type) => Object.hasOwn(type, "oneOf");
99
+ var isSchemaRef = (type) => Object.hasOwn(type, "$ref");
100
+ export {
101
+ HTTP_METHODS,
102
+ fetch,
103
+ hasContent,
104
+ hasSchema,
105
+ isCookieParam,
106
+ isHeaderParam,
107
+ isPathParam,
108
+ isQueryParam,
109
+ isRef,
110
+ isSchemaAllOf,
111
+ isSchemaArray,
112
+ isSchemaBoolean,
113
+ isSchemaInteger,
114
+ isSchemaNumber,
115
+ isSchemaObject,
116
+ isSchemaOneOf,
117
+ isSchemaRef,
118
+ isSchemaString,
119
+ isUrl,
120
+ referenceSchema,
121
+ referenceTitle
15
122
  };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./values"), exports);
18
- __exportStar(require("./types"), exports);
19
- __exportStar(require("./utils"), exports);
20
123
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,0CAAwB"}
1
+ {"version":3,"sources":["../src/values/http.ts","../src/utils/fetch.ts","../src/utils/url.ts","../src/utils/openapi.ts","../src/utils/parameter.ts","../src/utils/reference.ts","../src/utils/schema.ts"],"sourcesContent":["import {Method} from '../types';\n\nexport const HTTP_METHODS: Method[] = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'];\n","import {readFile} from 'node:fs/promises';\nimport {dirname, extname, resolve} from 'node:path';\nimport {load} from 'js-yaml';\nimport {Openapi} from '../types';\nimport {isUrl} from './url';\n\nexport const fetch = async <T = Openapi>(url: string, openapiPath?: string): Promise<T> =>\n parse(await read(url, openapiPath), url);\n\nconst read = async (url: string, openapiPath?: string): Promise<string> => {\n if (isUrl(url)) {\n return fetchText(url);\n }\n if (openapiPath && isUrl(openapiPath)) {\n return fetchText(new URL(url, openapiPath).toString());\n }\n const base = openapiPath ? (extname(openapiPath) ? dirname(openapiPath) : openapiPath) : '';\n return readFile(resolve(base, url), {encoding: 'utf-8'});\n};\n\nconst fetchText = async (url: string): Promise<string> => {\n const response = await globalThis.fetch(url);\n if (!response.ok) {\n throw new Error(`Failed to fetch ${url}: ${response.status} ${response.statusText}`);\n }\n return response.text();\n};\n\nconst parse = <T = Openapi>(data: string, filePath: string): T => {\n switch (extname(filePath)) {\n case '.json':\n return JSON.parse(data);\n case '.yml':\n case '.yaml': {\n const yaml = load(data);\n if (typeof yaml === 'object') {\n return yaml as T;\n }\n throw new Error('Unsupported file format');\n }\n default:\n throw new Error('Unsupported file extension');\n }\n};\n","export const isUrl = (url: string) =>\n url.startsWith('http://') || url.startsWith('https://');\n","import {OpenapiReference} from '../types';\n\nexport const isRef = (schema: any): schema is OpenapiReference => Object.hasOwn(schema, '$ref');\n","import {\n OpenapiMap,\n OpenapiParameter,\n OpenapiParameterCookie,\n OpenapiParameterHeader,\n OpenapiParameterPath,\n OpenapiParameterQuery,\n OpenapiPathMedia,\n OpenapiSchema,\n} from '../types';\nimport {isRef} from './openapi';\n\nexport const hasSchema =\n (param: OpenapiParameter): param is OpenapiParameter & { schema: OpenapiSchema } =>\n Object.hasOwn(param, 'schema');\nexport const hasContent =\n (param: OpenapiParameter): param is OpenapiParameter & { content: OpenapiMap<OpenapiPathMedia> } =>\n Object.hasOwn(param, 'content');\nexport const isPathParam =\n (param: OpenapiParameter): param is OpenapiParameterPath => !isRef(param) && param.in === 'path';\nexport const isQueryParam =\n (param: OpenapiParameter): param is OpenapiParameterQuery => !isRef(param) && param.in === 'query';\nexport const isHeaderParam =\n (param: OpenapiParameter): param is OpenapiParameterHeader => !isRef(param) && param.in === 'header';\nexport const isCookieParam =\n (param: OpenapiParameter): param is OpenapiParameterCookie => !isRef(param) && param.in === 'cookie';\n","import {parse} from 'path';\nimport {AutomatonContext, OpenapiReference} from '../types';\nimport {fetch} from './fetch';\nimport {isRef} from './openapi';\nimport {isUrl} from './url';\n\nexport const referenceTitle = (schema: OpenapiReference): string => {\n const [url = '', path = ''] = schema.$ref.split('#');\n const paths = path.split('/').slice(1);\n if (paths.length) {\n return paths[paths.length - 1]!;\n } else if (isUrl(url)) {\n return parse(url).name;\n }\n throw new Error(`Invalid ref format: ${schema.$ref}\\n Can not extract name.`);\n};\n\ntype ReferenceSchema<T = unknown> = (T | OpenapiReference) | (T & OpenapiReference);\nexport const referenceSchema =\n async <T = unknown>(schema: ReferenceSchema<T>, {openapi, settings: {openapiPath}}: AutomatonContext): Promise<T> => {\n if (!isRef(schema)) return schema;\n const [url, path] = schema.$ref.split('#');\n const file = url ? await fetch<T>(url, openapiPath) : openapi;\n if (!path) {\n if (!file) {\n throw new Error(`Invalid ref path ${schema.$ref}`);\n }\n return file as T;\n }\n const paths = path?.split('/').slice(1);\n const extractSchema = paths?.reduce((pre: any, cur) => pre?.[cur], file) as T | undefined;\n if (!extractSchema) {\n throw new Error(`Invalid ref path ${schema.$ref}`);\n }\n return extractSchema;\n };\n","import {\n OpenapiSchema,\n OpenapiSchemaAllOf,\n OpenapiSchemaArray,\n OpenapiSchemaBoolean,\n OpenapiSchemaInteger,\n OpenapiSchemaNumber,\n OpenapiSchemaObject,\n OpenapiSchemaOneOf,\n OpenapiSchemaReference,\n OpenapiSchemaString,\n} from '../types';\n\nexport const isSchemaString =\n (type: OpenapiSchema): type is OpenapiSchemaString => (type as OpenapiSchemaString).type === 'string';\nexport const isSchemaNumber =\n (type: OpenapiSchema): type is OpenapiSchemaNumber => (type as OpenapiSchemaNumber).type === 'number';\nexport const isSchemaInteger =\n (type: OpenapiSchema): type is OpenapiSchemaInteger => (type as OpenapiSchemaInteger).type === 'integer';\nexport const isSchemaBoolean =\n (type: OpenapiSchema): type is OpenapiSchemaBoolean => (type as OpenapiSchemaBoolean).type === 'boolean';\nexport const isSchemaObject =\n (type: OpenapiSchema): type is OpenapiSchemaObject =>\n (type as OpenapiSchemaObject).type === 'object' || Object.hasOwn(type, 'properties');\nexport const isSchemaArray =\n (type: OpenapiSchema): type is OpenapiSchemaArray =>\n (type as OpenapiSchemaArray).type === 'array' || Object.hasOwn(type, 'items');\nexport const isSchemaAllOf =\n (type: OpenapiSchema): type is OpenapiSchemaAllOf => Object.hasOwn(type, 'allOf');\nexport const isSchemaOneOf =\n (type: OpenapiSchema): type is OpenapiSchemaOneOf => Object.hasOwn(type, 'oneOf');\nexport const isSchemaRef =\n (type: OpenapiSchema): type is OpenapiSchemaReference => Object.hasOwn(type, '$ref');\n"],"mappings":"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","names":["parse","parse"]}
package/package.json CHANGED
@@ -1,53 +1,58 @@
1
1
  {
2
2
  "name": "@automatons/tools",
3
- "version": "1.0.218",
4
- "repository": "git@github.com:openapi-automatons/tools.git",
3
+ "version": "2.0.1",
4
+ "repository": "https://github.com/openapi-automatons/tools.git",
5
5
  "author": "tanmen <yt.prog@gmail.com>",
6
6
  "license": "MIT",
7
+ "packageManager": "yarn@1.22.22",
8
+ "type": "module",
7
9
  "keywords": [
8
10
  "openapi",
9
11
  "openapi-automatons",
10
12
  "automatons"
11
13
  ],
12
14
  "main": "index.js",
15
+ "module": "index.js",
16
+ "types": "index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./index.d.ts",
20
+ "import": "./index.js"
21
+ }
22
+ },
23
+ "engines": {
24
+ "node": ">=22"
25
+ },
13
26
  "scripts": {
14
- "prebuild": "depcheck && node scripts/prebuild.js",
15
- "build": "tsc && cp package.json README.md LICENSE dist",
16
- "lint": "eslint src --ext .ts,.tsx",
17
- "test": "jest",
18
- "postinstall": "husky install && typesync && yarn check --integrity || yarn install --ignore-scripts && yarn-deduplicate",
19
- "postversion": "cp package.json ../package.json"
27
+ "prebuild": "depcheck",
28
+ "build": "tsup && cp package.json README.md LICENSE dist",
29
+ "lint": "eslint src",
30
+ "test": "vitest run",
31
+ "test:watch": "vitest",
32
+ "test:coverage": "vitest run --coverage",
33
+ "prepare": "husky"
20
34
  },
21
35
  "dependencies": {
22
- "fs-extra": "^10.1.0",
23
- "got": "^11.8.5",
24
36
  "js-yaml": "^4.1.0"
25
37
  },
26
38
  "devDependencies": {
27
- "@commitlint/cli": "^17.4.1",
28
- "@commitlint/config-conventional": "^17.4.0",
29
- "@semantic-release/changelog": "^6.0.2",
39
+ "@commitlint/cli": "^21.0.2",
40
+ "@commitlint/config-conventional": "^21.0.2",
41
+ "@eslint/js": "^9.39.0",
42
+ "@semantic-release/changelog": "^6.0.3",
30
43
  "@semantic-release/git": "^10.0.1",
31
- "@semantic-release/npm": "^9.0.1",
32
- "@types/eslint": "^8.4.10",
33
- "@types/fs-extra": "^9.0.13",
34
- "@types/jest": "^27.5.0",
35
- "@types/js-yaml": "^4.0.5",
36
- "@types/node": "^18.11.18",
37
- "@types/semantic-release": "^17.2.4",
38
- "@typescript-eslint/eslint-plugin": "^5.48.0",
39
- "@typescript-eslint/parser": "^5.48.0",
40
- "depcheck": "^1.4.3",
41
- "eslint": "^8.28.0",
42
- "eslint-config-google": "^0.14.0",
43
- "husky": "^8.0.3",
44
- "jest": "^26.0.1",
45
- "lint-staged": "^13.1.0",
46
- "semantic-release": "^19.0.5",
47
- "ts-jest": "^26.0.0",
48
- "typescript": "^4.7.4",
49
- "typesync": "^0.9.2",
50
- "yarn-deduplicate": "^6.0.1"
44
+ "@types/js-yaml": "^4.0.9",
45
+ "@types/node": "^24.0.0",
46
+ "@vitest/coverage-v8": "^3.2.0",
47
+ "depcheck": "^1.4.7",
48
+ "eslint": "^9.39.0",
49
+ "husky": "^9.1.7",
50
+ "lint-staged": "^17.0.7",
51
+ "semantic-release": "^25.0.3",
52
+ "tsup": "^8.5.0",
53
+ "typescript": "^6.0.3",
54
+ "typescript-eslint": "^8.46.0",
55
+ "vitest": "^3.2.0"
51
56
  },
52
57
  "publishConfig": {
53
58
  "access": "public"
package/index.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAExB,oBAAY,OAAO,GAAG;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,gBAAgB,EAAE,CAAA;CAC/B,CAAA;AAED,oBAAY,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAA"}
@@ -1,12 +0,0 @@
1
- import { Openapi } from './openapi';
2
- export declare type AutomatonContext = {
3
- openapi: Openapi;
4
- settings: AutomatonSettings;
5
- };
6
- export declare type AutomatonSettings = {
7
- outDir: string;
8
- path: string;
9
- openapiPath: string;
10
- };
11
- export declare type Automaton = (openapi: Openapi, settings: AutomatonSettings, options: object | undefined) => unknown;
12
- //# sourceMappingURL=automaton.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"automaton.d.ts","sourceRoot":"","sources":["../../src/types/automaton.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC,oBAAY,gBAAgB,GAAG;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B,CAAA;AAED,oBAAY,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB,CAAA;AAED,oBAAY,SAAS,GAAG,CAAC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,iBAAiB,EAC3B,OAAO,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAA"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=automaton.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"automaton.js","sourceRoot":"","sources":["../../src/types/automaton.ts"],"names":[],"mappings":""}
package/types/http.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare type Method = 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace';
2
- //# sourceMappingURL=http.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/types/http.ts"],"names":[],"mappings":"AAAA,oBAAY,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC"}
package/types/http.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=http.js.map
package/types/http.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/types/http.ts"],"names":[],"mappings":""}
package/types/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './http';
2
- export * from './openapi';
3
- export * from './automaton';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}