@skmtc/core 0.49.0 → 0.50.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/esm/context/CoreContext.js +80 -3
- package/esm/context/GenerateContext.d.ts +6 -1
- package/esm/context/GenerateContext.js +149 -81
- package/esm/context/LogLinesHandler.d.ts +1 -1
- package/esm/context/LogLinesHandler.js +3 -0
- package/esm/context/ParseContext.d.ts +3 -0
- package/esm/context/ParseContext.js +36 -14
- package/esm/helpers/ResultsLog.js +7 -1
- package/esm/helpers/refFns.js +11 -0
- package/esm/helpers/toCountPhrase.d.ts +11 -0
- package/esm/helpers/toCountPhrase.js +11 -0
- package/esm/parse/toCyclicRefs.js +27 -16
- package/esm/types/JsonPointer.js +2 -2
- package/esm/types/LogLine.d.ts +40 -1
- package/esm/types/LogLine.js +25 -0
- package/package.json +1 -1
- package/script/context/CoreContext.js +80 -3
- package/script/context/GenerateContext.d.ts +6 -1
- package/script/context/GenerateContext.js +149 -81
- package/script/context/LogLinesHandler.d.ts +1 -1
- package/script/context/LogLinesHandler.js +3 -0
- package/script/context/ParseContext.d.ts +3 -0
- package/script/context/ParseContext.js +36 -14
- package/script/helpers/ResultsLog.js +7 -1
- package/script/helpers/refFns.js +11 -0
- package/script/helpers/toCountPhrase.d.ts +11 -0
- package/script/helpers/toCountPhrase.js +15 -0
- package/script/parse/toCyclicRefs.js +27 -16
- package/script/types/JsonPointer.js +2 -2
- package/script/types/LogLine.d.ts +40 -1
- package/script/types/LogLine.js +27 -1
package/script/helpers/refFns.js
CHANGED
|
@@ -78,6 +78,7 @@ const toRefPathSegments = (refPath) => {
|
|
|
78
78
|
return body === '' ? [] : body.split('/').map(JsonPointer_js_1.unescapeSegment);
|
|
79
79
|
};
|
|
80
80
|
exports.toRefPathSegments = toRefPathSegments;
|
|
81
|
+
const COMPONENTS_PATH = '#/components/';
|
|
81
82
|
/**
|
|
82
83
|
* The `components` bucket a `refPath` is, such as `schemas` for
|
|
83
84
|
* `#/components/schemas`, or `undefined` for any other path. A ref whose path
|
|
@@ -90,6 +91,13 @@ const toRefPathBucket = (refPath) => {
|
|
|
90
91
|
if ((0, exports.isRemoteRefPath)(refPath)) {
|
|
91
92
|
return undefined;
|
|
92
93
|
}
|
|
94
|
+
// The usual path, `#/components/<bucket>`, with nothing to split or unescape.
|
|
95
|
+
if (refPath.startsWith(COMPONENTS_PATH)) {
|
|
96
|
+
const bucket = refPath.slice(COMPONENTS_PATH.length);
|
|
97
|
+
if (!bucket.includes('/') && !bucket.includes('~')) {
|
|
98
|
+
return isBucket(bucket) ? bucket : undefined;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
93
101
|
const [first, bucket, ...rest] = (0, exports.toRefPathSegments)(refPath);
|
|
94
102
|
return first === 'components' && rest.length === 0 && isBucket(bucket) ? bucket : undefined;
|
|
95
103
|
};
|
|
@@ -169,6 +177,9 @@ const toRawRefTarget = (document, { refName, refPath }) => (0, exports.isRemoteR
|
|
|
169
177
|
}, document);
|
|
170
178
|
exports.toRawRefTarget = toRawRefTarget;
|
|
171
179
|
const toPercentDecoded = (segment) => {
|
|
180
|
+
if (!segment.includes('%')) {
|
|
181
|
+
return segment;
|
|
182
|
+
}
|
|
172
183
|
try {
|
|
173
184
|
return decodeURIComponent(segment);
|
|
174
185
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `count` and the noun for it, for a log line: `1 file`, `2 files`.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* toCountPhrase(1, 'warning') // '1 warning'
|
|
7
|
+
* toCountPhrase(0, 'error') // '0 errors'
|
|
8
|
+
* toCountPhrase(2, 'debug', 'debug') // '2 debug'
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare const toCountPhrase: (count: number, singular: string, plural?: string) => string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toCountPhrase = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `count` and the noun for it, for a log line: `1 file`, `2 files`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* toCountPhrase(1, 'warning') // '1 warning'
|
|
10
|
+
* toCountPhrase(0, 'error') // '0 errors'
|
|
11
|
+
* toCountPhrase(2, 'debug', 'debug') // '2 debug'
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
const toCountPhrase = (count, singular, plural = `${singular}s`) => `${count} ${count === 1 ? singular : plural}`;
|
|
15
|
+
exports.toCountPhrase = toCountPhrase;
|
|
@@ -7,34 +7,45 @@ const refFns_js_1 = require("../helpers/refFns.js");
|
|
|
7
7
|
const DATA_KEYWORDS = ['default', 'example', 'examples', 'enum', 'const'];
|
|
8
8
|
/** Keywords whose value is a map of names to schemas: a name in it is not a keyword. */
|
|
9
9
|
const SCHEMA_MAP_KEYWORDS = ['properties', 'patternProperties', '$defs', 'definitions', 'dependentSchemas'];
|
|
10
|
-
/** Every `$ref` object anywhere inside a raw schema. */
|
|
11
|
-
const toSchemaRefs = (value) => {
|
|
10
|
+
/** Every `$ref` object anywhere inside a raw schema, added to `found` in document order. */
|
|
11
|
+
const toSchemaRefs = (value, found = []) => {
|
|
12
12
|
if (Array.isArray(value)) {
|
|
13
|
-
|
|
13
|
+
value.forEach(item => toSchemaRefs(item, found));
|
|
14
|
+
return found;
|
|
14
15
|
}
|
|
15
16
|
if (!(0, isPlainObject_js_1.isPlainObject)(value)) {
|
|
16
|
-
return
|
|
17
|
+
return found;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
if ((0, refFns_js_1.isRef)(value)) {
|
|
20
|
+
found.push(value);
|
|
21
|
+
}
|
|
22
|
+
Object.entries(value).forEach(([key, child]) => {
|
|
19
23
|
if (DATA_KEYWORDS.includes(key) || key.startsWith('x-')) {
|
|
20
|
-
return
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (SCHEMA_MAP_KEYWORDS.includes(key) && (0, isPlainObject_js_1.isPlainObject)(child)) {
|
|
27
|
+
Object.values(child).forEach(member => toSchemaRefs(member, found));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
toSchemaRefs(child, found);
|
|
21
31
|
}
|
|
22
|
-
return SCHEMA_MAP_KEYWORDS.includes(key) && (0, isPlainObject_js_1.isPlainObject)(child)
|
|
23
|
-
? Object.values(child).flatMap(toSchemaRefs)
|
|
24
|
-
: toSchemaRefs(child);
|
|
25
32
|
});
|
|
26
|
-
return
|
|
33
|
+
return found;
|
|
27
34
|
};
|
|
28
|
-
/** Every `$ref` object anywhere in a raw document. */
|
|
29
|
-
const toDocumentRefs = (value) => {
|
|
35
|
+
/** Every `$ref` object anywhere in a raw document, added to `found` in document order. */
|
|
36
|
+
const toDocumentRefs = (value, found = []) => {
|
|
30
37
|
if (Array.isArray(value)) {
|
|
31
|
-
|
|
38
|
+
value.forEach(item => toDocumentRefs(item, found));
|
|
39
|
+
return found;
|
|
32
40
|
}
|
|
33
41
|
if (!(0, isPlainObject_js_1.isPlainObject)(value)) {
|
|
34
|
-
return
|
|
42
|
+
return found;
|
|
43
|
+
}
|
|
44
|
+
if ((0, refFns_js_1.isRef)(value)) {
|
|
45
|
+
found.push(value);
|
|
35
46
|
}
|
|
36
|
-
|
|
37
|
-
return
|
|
47
|
+
Object.values(value).forEach(child => toDocumentRefs(child, found));
|
|
48
|
+
return found;
|
|
38
49
|
};
|
|
39
50
|
/** Whether a ref can point at a schema: not a remote one, and not one to another kind of component. */
|
|
40
51
|
const canNameSchema = ({ refName, refPath }) => {
|
|
@@ -17,7 +17,7 @@ exports.isJsonPointer = exports.append = exports.fromJsonPointer = exports.toJso
|
|
|
17
17
|
* `~` → `~0` (must be replaced first to avoid double-escaping)
|
|
18
18
|
* `/` → `~1`
|
|
19
19
|
*/
|
|
20
|
-
const escapeSegment = (segment) => segment.replaceAll('~', '~0').replaceAll('/', '~1');
|
|
20
|
+
const escapeSegment = (segment) => segment.includes('~') || segment.includes('/') ? segment.replaceAll('~', '~0').replaceAll('/', '~1') : segment;
|
|
21
21
|
exports.escapeSegment = escapeSegment;
|
|
22
22
|
/**
|
|
23
23
|
* Unescape a single segment per RFC 6901 §4.
|
|
@@ -25,7 +25,7 @@ exports.escapeSegment = escapeSegment;
|
|
|
25
25
|
* `~1` → `/` (must be replaced first)
|
|
26
26
|
* `~0` → `~`
|
|
27
27
|
*/
|
|
28
|
-
const unescapeSegment = (segment) => segment.replaceAll('~1', '/').replaceAll('~0', '~');
|
|
28
|
+
const unescapeSegment = (segment) => segment.includes('~') ? segment.replaceAll('~1', '/').replaceAll('~0', '~') : segment;
|
|
29
29
|
exports.unescapeSegment = unescapeSegment;
|
|
30
30
|
/**
|
|
31
31
|
* Build a JSON Pointer from an array of unescaped segments.
|
|
@@ -13,15 +13,48 @@ import { type SerializedError } from './SerializedError.js';
|
|
|
13
13
|
export type LogLineLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
|
|
14
14
|
/** Valibot schema for {@link LogLineLevel}. */
|
|
15
15
|
export declare const logLineLevel: v.PicklistSchema<["DEBUG", "INFO", "WARN", "ERROR"], undefined>;
|
|
16
|
+
/** The fields of the parse issue a {@link LogLine} reports. */
|
|
17
|
+
export type LogLineIssue = {
|
|
18
|
+
/**
|
|
19
|
+
* The issue's type. A string, not the closed list of types: a reader on
|
|
20
|
+
* an older core must still read a line with a type added since.
|
|
21
|
+
*/
|
|
22
|
+
type: string;
|
|
23
|
+
level: 'error' | 'warning' | 'debug';
|
|
24
|
+
/** The issue's `location`, as `manifest.parseIssues` has it. */
|
|
25
|
+
location: string;
|
|
26
|
+
/** The object around the issue, as JSON. */
|
|
27
|
+
parent?: string;
|
|
28
|
+
};
|
|
29
|
+
/** Valibot schema for {@link LogLineIssue}. */
|
|
30
|
+
export declare const logLineIssue: v.ObjectSchema<{
|
|
31
|
+
readonly type: v.StringSchema<undefined>;
|
|
32
|
+
readonly level: v.PicklistSchema<["error", "warning", "debug"], undefined>;
|
|
33
|
+
readonly location: v.StringSchema<undefined>;
|
|
34
|
+
readonly parent: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
35
|
+
}, undefined>;
|
|
36
|
+
/**
|
|
37
|
+
* A log argument that gives its line an `issue` field. Parse logs one with
|
|
38
|
+
* each issue it records.
|
|
39
|
+
*/
|
|
40
|
+
export declare class LogLineIssueArg {
|
|
41
|
+
issue: LogLineIssue;
|
|
42
|
+
constructor(issue: LogLineIssue);
|
|
43
|
+
}
|
|
16
44
|
export type LogLine = {
|
|
17
45
|
/** Position of the line in the run, from 0. */
|
|
18
46
|
seq: number;
|
|
19
47
|
level: LogLineLevel;
|
|
20
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* The subject's stack trail, or the generator's on the line a generator
|
|
50
|
+
* logs after it ran. Absent outside a generator (parse, render).
|
|
51
|
+
*/
|
|
21
52
|
trail?: string;
|
|
22
53
|
message: string;
|
|
23
54
|
/** The first `Error` the line was logged with. */
|
|
24
55
|
error?: SerializedError;
|
|
56
|
+
/** The parse issue the line reports. */
|
|
57
|
+
issue?: LogLineIssue;
|
|
25
58
|
/** When the line was logged, in milliseconds since the epoch. */
|
|
26
59
|
time: number;
|
|
27
60
|
};
|
|
@@ -32,5 +65,11 @@ export declare const logLine: v.ObjectSchema<{
|
|
|
32
65
|
readonly trail: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
33
66
|
readonly message: v.StringSchema<undefined>;
|
|
34
67
|
readonly error: v.OptionalSchema<v.GenericSchema<SerializedError>, undefined>;
|
|
68
|
+
readonly issue: v.OptionalSchema<v.ObjectSchema<{
|
|
69
|
+
readonly type: v.StringSchema<undefined>;
|
|
70
|
+
readonly level: v.PicklistSchema<["error", "warning", "debug"], undefined>;
|
|
71
|
+
readonly location: v.StringSchema<undefined>;
|
|
72
|
+
readonly parent: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
73
|
+
}, undefined>, undefined>;
|
|
35
74
|
readonly time: v.NumberSchema<undefined>;
|
|
36
75
|
}, undefined>;
|
package/script/types/LogLine.js
CHANGED
|
@@ -42,13 +42,38 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
42
42
|
};
|
|
43
43
|
})();
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.logLine = exports.logLineLevel = void 0;
|
|
45
|
+
exports.logLine = exports.LogLineIssueArg = exports.logLineIssue = exports.logLineLevel = void 0;
|
|
46
46
|
const v = __importStar(require("valibot"));
|
|
47
47
|
const SerializedError_js_1 = require("./SerializedError.js");
|
|
48
48
|
/** Valibot schema for {@link LogLineLevel}. */
|
|
49
49
|
exports.logLineLevel = v.picklist(['DEBUG', 'INFO', 'WARN', 'ERROR']);
|
|
50
50
|
const _logLineLevelDriftCheck = exports.logLineLevel;
|
|
51
51
|
void _logLineLevelDriftCheck;
|
|
52
|
+
/** Valibot schema for {@link LogLineIssue}. */
|
|
53
|
+
exports.logLineIssue = v.object({
|
|
54
|
+
type: v.string(),
|
|
55
|
+
level: v.picklist(['error', 'warning', 'debug']),
|
|
56
|
+
location: v.string(),
|
|
57
|
+
parent: v.optional(v.string())
|
|
58
|
+
});
|
|
59
|
+
const _logLineIssueDriftCheck = exports.logLineIssue;
|
|
60
|
+
void _logLineIssueDriftCheck;
|
|
61
|
+
/**
|
|
62
|
+
* A log argument that gives its line an `issue` field. Parse logs one with
|
|
63
|
+
* each issue it records.
|
|
64
|
+
*/
|
|
65
|
+
class LogLineIssueArg {
|
|
66
|
+
constructor(issue) {
|
|
67
|
+
Object.defineProperty(this, "issue", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
configurable: true,
|
|
70
|
+
writable: true,
|
|
71
|
+
value: void 0
|
|
72
|
+
});
|
|
73
|
+
this.issue = issue;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.LogLineIssueArg = LogLineIssueArg;
|
|
52
77
|
/** Valibot schema for {@link LogLine}. */
|
|
53
78
|
exports.logLine = v.object({
|
|
54
79
|
seq: v.number(),
|
|
@@ -56,6 +81,7 @@ exports.logLine = v.object({
|
|
|
56
81
|
trail: v.optional(v.string()),
|
|
57
82
|
message: v.string(),
|
|
58
83
|
error: v.optional(SerializedError_js_1.serializedError),
|
|
84
|
+
issue: v.optional(exports.logLineIssue),
|
|
59
85
|
time: v.number()
|
|
60
86
|
});
|
|
61
87
|
const _logLineDriftCheck = exports.logLine;
|