@appweaver/client 1.1.6 → 1.2.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.
- package/cjs/commands/generate-command.d.ts +1 -0
- package/cjs/commands/generate-command.js +2 -7
- package/cjs/utils/schema-util.d.ts +10 -0
- package/cjs/utils/schema-util.js +25 -3
- package/esm/commands/generate-command.d.ts +1 -0
- package/esm/commands/generate-command.js +3 -9
- package/esm/utils/schema-util.d.ts +10 -0
- package/esm/utils/schema-util.js +24 -3
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.generateCommand = generateCommand;
|
|
7
7
|
exports.relativePathFrom = relativePathFrom;
|
|
8
|
+
exports.parseSchema = parseSchema;
|
|
8
9
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
10
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
10
11
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -102,13 +103,7 @@ function relativePathFrom(firstPath, otherPath) {
|
|
|
102
103
|
return rel.replace(/\\/g, '/');
|
|
103
104
|
}
|
|
104
105
|
function parseSchema(value) {
|
|
105
|
-
|
|
106
|
-
try {
|
|
107
|
-
schemaUrl = new URL(value);
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
// Schema path is not in URL format
|
|
111
|
-
}
|
|
106
|
+
const schemaUrl = (0, utils_1.parseSchemaUrl)(value);
|
|
112
107
|
if (schemaUrl) {
|
|
113
108
|
if (!['http:', 'https:', 'file:'].includes(schemaUrl.protocol)) {
|
|
114
109
|
throw new commander_1.InvalidArgumentError(`Unsupported schema URL protocol: ${schemaUrl.protocol}`);
|
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import { OpenAPI3 } from 'openapi-typescript';
|
|
2
|
+
/**
|
|
3
|
+
* Parses a schema location into a URL, treating the locations that are
|
|
4
|
+
* filesystem paths as such rather than as URLs.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} schemaPath The schema location given on the command line,
|
|
7
|
+
* either a URL or a filesystem path.
|
|
8
|
+
* @returns {URL | undefined} The parsed URL, or undefined when the location is
|
|
9
|
+
* a filesystem path, including a Windows path starting with a drive letter.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseSchemaUrl(schemaPath: string): URL | undefined;
|
|
2
12
|
export declare function readSchemaContent(schemaPath: string): Promise<string>;
|
|
3
13
|
export declare function toSchemaObject(schemaContent: string): Promise<OpenAPI3>;
|
package/cjs/utils/schema-util.js
CHANGED
|
@@ -3,16 +3,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseSchemaUrl = parseSchemaUrl;
|
|
6
7
|
exports.readSchemaContent = readSchemaContent;
|
|
7
8
|
exports.toSchemaObject = toSchemaObject;
|
|
8
9
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
9
10
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
// A Windows path starting with a drive letter (i.e. `C:\schema.json`) parses
|
|
12
|
+
// as a URL whose protocol is a single letter, no real protocol is one letter.
|
|
13
|
+
const WINDOWS_DRIVE_PATH = /^[a-zA-Z]:[\\/]/;
|
|
14
|
+
/**
|
|
15
|
+
* Parses a schema location into a URL, treating the locations that are
|
|
16
|
+
* filesystem paths as such rather than as URLs.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} schemaPath The schema location given on the command line,
|
|
19
|
+
* either a URL or a filesystem path.
|
|
20
|
+
* @returns {URL | undefined} The parsed URL, or undefined when the location is
|
|
21
|
+
* a filesystem path, including a Windows path starting with a drive letter.
|
|
22
|
+
*/
|
|
23
|
+
function parseSchemaUrl(schemaPath) {
|
|
24
|
+
if (WINDOWS_DRIVE_PATH.test(schemaPath)) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
12
27
|
try {
|
|
13
|
-
|
|
28
|
+
return new URL(schemaPath);
|
|
14
29
|
}
|
|
15
30
|
catch {
|
|
31
|
+
// Schema path is not in URL format
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function readSchemaContent(schemaPath) {
|
|
36
|
+
const schemaUrl = parseSchemaUrl(schemaPath);
|
|
37
|
+
if (!schemaUrl) {
|
|
16
38
|
return await promises_1.default.readFile(schemaPath, 'utf8');
|
|
17
39
|
}
|
|
18
40
|
if (schemaUrl.protocol === 'http:' || schemaUrl.protocol === 'https:') {
|
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import prettier from 'prettier';
|
|
5
5
|
import { InvalidArgumentError, InvalidOptionArgumentError } from 'commander';
|
|
6
6
|
import { generateClient, generateTypes } from '../generators/index.js';
|
|
7
|
-
import { readSchemaContent, toSchemaObject } from '../utils/index.js';
|
|
7
|
+
import { parseSchemaUrl, readSchemaContent, toSchemaObject } from '../utils/index.js';
|
|
8
8
|
import { FRAMEWORKS } from '../constants.js';
|
|
9
9
|
export function generateCommand(program) {
|
|
10
10
|
program
|
|
@@ -94,14 +94,8 @@ export function relativePathFrom(firstPath, otherPath) {
|
|
|
94
94
|
}
|
|
95
95
|
return rel.replace(/\\/g, '/');
|
|
96
96
|
}
|
|
97
|
-
function parseSchema(value) {
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
schemaUrl = new URL(value);
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
// Schema path is not in URL format
|
|
104
|
-
}
|
|
97
|
+
export function parseSchema(value) {
|
|
98
|
+
const schemaUrl = parseSchemaUrl(value);
|
|
105
99
|
if (schemaUrl) {
|
|
106
100
|
if (!['http:', 'https:', 'file:'].includes(schemaUrl.protocol)) {
|
|
107
101
|
throw new InvalidArgumentError(`Unsupported schema URL protocol: ${schemaUrl.protocol}`);
|
|
@@ -1,3 +1,13 @@
|
|
|
1
1
|
import { OpenAPI3 } from 'openapi-typescript';
|
|
2
|
+
/**
|
|
3
|
+
* Parses a schema location into a URL, treating the locations that are
|
|
4
|
+
* filesystem paths as such rather than as URLs.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} schemaPath The schema location given on the command line,
|
|
7
|
+
* either a URL or a filesystem path.
|
|
8
|
+
* @returns {URL | undefined} The parsed URL, or undefined when the location is
|
|
9
|
+
* a filesystem path, including a Windows path starting with a drive letter.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseSchemaUrl(schemaPath: string): URL | undefined;
|
|
2
12
|
export declare function readSchemaContent(schemaPath: string): Promise<string>;
|
|
3
13
|
export declare function toSchemaObject(schemaContent: string): Promise<OpenAPI3>;
|
package/esm/utils/schema-util.js
CHANGED
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
import fsp from 'node:fs/promises';
|
|
2
2
|
import yaml from 'js-yaml';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
// A Windows path starting with a drive letter (i.e. `C:\schema.json`) parses
|
|
4
|
+
// as a URL whose protocol is a single letter, no real protocol is one letter.
|
|
5
|
+
const WINDOWS_DRIVE_PATH = /^[a-zA-Z]:[\\/]/;
|
|
6
|
+
/**
|
|
7
|
+
* Parses a schema location into a URL, treating the locations that are
|
|
8
|
+
* filesystem paths as such rather than as URLs.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} schemaPath The schema location given on the command line,
|
|
11
|
+
* either a URL or a filesystem path.
|
|
12
|
+
* @returns {URL | undefined} The parsed URL, or undefined when the location is
|
|
13
|
+
* a filesystem path, including a Windows path starting with a drive letter.
|
|
14
|
+
*/
|
|
15
|
+
export function parseSchemaUrl(schemaPath) {
|
|
16
|
+
if (WINDOWS_DRIVE_PATH.test(schemaPath)) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
5
19
|
try {
|
|
6
|
-
|
|
20
|
+
return new URL(schemaPath);
|
|
7
21
|
}
|
|
8
22
|
catch {
|
|
23
|
+
// Schema path is not in URL format
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export async function readSchemaContent(schemaPath) {
|
|
28
|
+
const schemaUrl = parseSchemaUrl(schemaPath);
|
|
29
|
+
if (!schemaUrl) {
|
|
9
30
|
return await fsp.readFile(schemaPath, 'utf8');
|
|
10
31
|
}
|
|
11
32
|
if (schemaUrl.protocol === 'http:' || schemaUrl.protocol === 'https:') {
|