@openpkg-ts/spec 0.37.0 → 0.41.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/README.md +1 -1
- package/dist/index.d.ts +65 -62
- package/dist/index.js +104 -102
- package/package.json +3 -2
- package/schemas/v0.1.0/openpkg.schema.json +1 -1
- package/schemas/v0.2.0/openpkg.schema.json +1 -1
- package/schemas/v0.3.0/openpkg.schema.json +1 -1
- package/schemas/v0.4.0/openpkg.schema.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @openpkg-ts/spec
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Types, validation, normalization, and diffing for [OpenPkg](https://openpkg.dev) documents. Part of [openpkg-ts](https://github.com/ryanwaits/openpkg-ts), the TypeScript reference implementation of the OpenPkg standard.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
package/dist/index.d.ts
CHANGED
|
@@ -414,7 +414,10 @@ type OpenPkg = {
|
|
|
414
414
|
generation?: SpecGenerationMeta | SpecGenerationInfo;
|
|
415
415
|
};
|
|
416
416
|
declare const SCHEMA_VERSION: OpenPkgVersion;
|
|
417
|
-
|
|
417
|
+
/** Canonical schema URL — hosted by the OpenPkg standard, independent of any implementation's packaging. */
|
|
418
|
+
declare const SCHEMA_URL = "https://openpkg.dev/schemas/v0.4.0/openpkg.schema.json";
|
|
419
|
+
/** Mirror of the canonical schema, served from the published @openpkg-ts/spec npm package. */
|
|
420
|
+
declare const SCHEMA_URL_MIRROR = "https://unpkg.com/@openpkg-ts/spec/schemas/v0.4.0/openpkg.schema.json";
|
|
418
421
|
declare const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
|
|
419
422
|
/** The 6 kinds relevant for UI display (excludes namespace, module, reference, external). */
|
|
420
423
|
type DisplayKind = Extract<SpecExportKind, "function" | "class" | "interface" | "type" | "enum" | "variable">;
|
|
@@ -425,66 +428,6 @@ declare const KIND_LABELS: Record<SpecExportKind, string>;
|
|
|
425
428
|
/** URL-safe slug for every kind. */
|
|
426
429
|
declare const KIND_SLUGS: Record<SpecExportKind, string>;
|
|
427
430
|
declare function dereference(spec: OpenPkg): OpenPkg;
|
|
428
|
-
declare function isStringSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
429
|
-
type: "string";
|
|
430
|
-
}>;
|
|
431
|
-
declare function isNumberSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
432
|
-
type: "number";
|
|
433
|
-
}>;
|
|
434
|
-
declare function isBooleanSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
435
|
-
type: "boolean";
|
|
436
|
-
}>;
|
|
437
|
-
declare function isIntegerSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
438
|
-
type: "integer";
|
|
439
|
-
}>;
|
|
440
|
-
declare function isNullSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
441
|
-
type: "null";
|
|
442
|
-
}>;
|
|
443
|
-
declare function isVoidSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
444
|
-
type: "void";
|
|
445
|
-
}>;
|
|
446
|
-
declare function isNeverSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
447
|
-
type: "never";
|
|
448
|
-
}>;
|
|
449
|
-
declare function isAnySchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
450
|
-
type: "any";
|
|
451
|
-
}>;
|
|
452
|
-
declare function isObjectSchema(s: SpecSchema): s is Extract<SpecSchemaComposite, {
|
|
453
|
-
type: "object";
|
|
454
|
-
}>;
|
|
455
|
-
declare function isArraySchema(s: SpecSchema): s is Extract<SpecSchemaComposite, {
|
|
456
|
-
type: "array";
|
|
457
|
-
}>;
|
|
458
|
-
declare function isTupleSchema(s: SpecSchema): s is Extract<SpecSchemaComposite, {
|
|
459
|
-
type: "tuple";
|
|
460
|
-
}>;
|
|
461
|
-
declare function isFunctionSchema(s: SpecSchema): s is Extract<SpecSchemaComposite, {
|
|
462
|
-
type: "function";
|
|
463
|
-
}>;
|
|
464
|
-
declare function isAnyOfSchema(s: SpecSchema): s is Extract<SpecSchemaCombinator, {
|
|
465
|
-
anyOf: SpecSchema[];
|
|
466
|
-
}>;
|
|
467
|
-
declare function isAllOfSchema(s: SpecSchema): s is Extract<SpecSchemaCombinator, {
|
|
468
|
-
allOf: SpecSchema[];
|
|
469
|
-
}>;
|
|
470
|
-
declare function isOneOfSchema(s: SpecSchema): s is Extract<SpecSchemaCombinator, {
|
|
471
|
-
oneOf: SpecSchema[];
|
|
472
|
-
}>;
|
|
473
|
-
declare function isRefSchema(s: SpecSchema): s is SpecSchemaRef;
|
|
474
|
-
/**
|
|
475
|
-
* Resolve a $ref schema to the referenced SpecType.
|
|
476
|
-
* Returns null if the ref can't be resolved.
|
|
477
|
-
*/
|
|
478
|
-
declare function resolveRef(schema: SpecSchema, spec: OpenPkg): SpecType | null;
|
|
479
|
-
/**
|
|
480
|
-
* Flatten nested anyOf into a single array of schemas.
|
|
481
|
-
* Non-anyOf schemas return as a single-element array.
|
|
482
|
-
*/
|
|
483
|
-
declare function flattenAnyOf(schema: SpecSchema): SpecSchema[];
|
|
484
|
-
/**
|
|
485
|
-
* Get a human-readable type string from a schema.
|
|
486
|
-
*/
|
|
487
|
-
declare function getSchemaType(schema: SpecSchema): string;
|
|
488
431
|
type BreakingSeverity = "high" | "medium" | "low";
|
|
489
432
|
interface CategorizedBreaking {
|
|
490
433
|
id: string;
|
|
@@ -579,7 +522,67 @@ declare function recommendSemverBump(diff: SpecDiff): SemverRecommendation;
|
|
|
579
522
|
* ```
|
|
580
523
|
*/
|
|
581
524
|
declare function calculateNextVersion(currentVersion: string, bump: SemverBump): string;
|
|
525
|
+
declare function isStringSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
526
|
+
type: "string";
|
|
527
|
+
}>;
|
|
528
|
+
declare function isNumberSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
529
|
+
type: "number";
|
|
530
|
+
}>;
|
|
531
|
+
declare function isBooleanSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
532
|
+
type: "boolean";
|
|
533
|
+
}>;
|
|
534
|
+
declare function isIntegerSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
535
|
+
type: "integer";
|
|
536
|
+
}>;
|
|
537
|
+
declare function isNullSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
538
|
+
type: "null";
|
|
539
|
+
}>;
|
|
540
|
+
declare function isVoidSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
541
|
+
type: "void";
|
|
542
|
+
}>;
|
|
543
|
+
declare function isNeverSchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
544
|
+
type: "never";
|
|
545
|
+
}>;
|
|
546
|
+
declare function isAnySchema(s: SpecSchema): s is Extract<SpecSchemaPrimitive, {
|
|
547
|
+
type: "any";
|
|
548
|
+
}>;
|
|
549
|
+
declare function isObjectSchema(s: SpecSchema): s is Extract<SpecSchemaComposite, {
|
|
550
|
+
type: "object";
|
|
551
|
+
}>;
|
|
552
|
+
declare function isArraySchema(s: SpecSchema): s is Extract<SpecSchemaComposite, {
|
|
553
|
+
type: "array";
|
|
554
|
+
}>;
|
|
555
|
+
declare function isTupleSchema(s: SpecSchema): s is Extract<SpecSchemaComposite, {
|
|
556
|
+
type: "tuple";
|
|
557
|
+
}>;
|
|
558
|
+
declare function isFunctionSchema(s: SpecSchema): s is Extract<SpecSchemaComposite, {
|
|
559
|
+
type: "function";
|
|
560
|
+
}>;
|
|
561
|
+
declare function isAnyOfSchema(s: SpecSchema): s is Extract<SpecSchemaCombinator, {
|
|
562
|
+
anyOf: SpecSchema[];
|
|
563
|
+
}>;
|
|
564
|
+
declare function isAllOfSchema(s: SpecSchema): s is Extract<SpecSchemaCombinator, {
|
|
565
|
+
allOf: SpecSchema[];
|
|
566
|
+
}>;
|
|
567
|
+
declare function isOneOfSchema(s: SpecSchema): s is Extract<SpecSchemaCombinator, {
|
|
568
|
+
oneOf: SpecSchema[];
|
|
569
|
+
}>;
|
|
570
|
+
declare function isRefSchema(s: SpecSchema): s is SpecSchemaRef;
|
|
582
571
|
declare function normalize(spec: OpenPkg): OpenPkg;
|
|
572
|
+
/**
|
|
573
|
+
* Resolve a $ref schema to the referenced SpecType.
|
|
574
|
+
* Returns null if the ref can't be resolved.
|
|
575
|
+
*/
|
|
576
|
+
declare function resolveRef(schema: SpecSchema, spec: OpenPkg): SpecType | null;
|
|
577
|
+
/**
|
|
578
|
+
* Flatten nested anyOf into a single array of schemas.
|
|
579
|
+
* Non-anyOf schemas return as a single-element array.
|
|
580
|
+
*/
|
|
581
|
+
declare function flattenAnyOf(schema: SpecSchema): SpecSchema[];
|
|
582
|
+
/**
|
|
583
|
+
* Get a human-readable type string from a schema.
|
|
584
|
+
*/
|
|
585
|
+
declare function getSchemaType(schema: SpecSchema): string;
|
|
583
586
|
/** Concrete schema versions (excludes 'latest' alias) */
|
|
584
587
|
type ConcreteSchemaVersion = "0.1.0" | "0.2.0" | "0.3.0" | "0.4.0";
|
|
585
588
|
/** Supported schema versions */
|
|
@@ -622,4 +625,4 @@ declare function assertSpec(spec: unknown, version?: SchemaVersion): asserts spe
|
|
|
622
625
|
* @returns Array of validation errors (empty if valid)
|
|
623
626
|
*/
|
|
624
627
|
declare function getValidationErrors(spec: unknown, version?: SchemaVersion): SpecError[];
|
|
625
|
-
export { validateSpec, resolveRef, recommendSemverBump, normalize, isVoidSchema, isTupleSchema, isStringSchema, isRefSchema, isOneOfSchema, isObjectSchema, isNumberSchema, isNullSchema, isNeverSchema, isIntegerSchema, isFunctionSchema, isBooleanSchema, isArraySchema, isAnySchema, isAnyOfSchema, isAllOfSchema, getValidationErrors, getSchemaType, getAvailableVersions, flattenAnyOf, diffSpec, dereference, categorizeBreakingChanges, calculateNextVersion, assertSpec, SpecVisibility, SpecTypePredicate, SpecTypeParameter, SpecTypeKind, SpecTypeAliasKind, SpecType, SpecThrows, SpecTagParam, SpecTag, SpecSource, SpecSkippedExport, SpecSignatureReturn, SpecSignatureParameter, SpecSignature, SpecSchemaRef, SpecSchemaPrimitive, SpecSchemaGeneric, SpecSchemaFallback, SpecSchemaComposite, SpecSchemaCombinator, SpecSchema, SpecPresentationMeta, SpecMember, SpecMappedType, SpecInheritedMember, SpecGenerationMeta, SpecGenerationInfo, SpecExtractionMode, SpecExtractionLimitation, SpecExtensions, SpecExtension, SpecExportKind, SpecExport, SpecExampleLanguage, SpecExample, SpecDiff, SpecDecorator, SpecConditionalType, SemverRecommendation, SemverBump, SCHEMA_VERSION, SCHEMA_URL, OpenPkgVersion, OpenPkgMeta, OpenPkg, MemberChangeInfo, KIND_SLUGS, KIND_LABELS, JSON_SCHEMA_DRAFT, JSONSchemaExtensions, GenerationIssueSeverity, GenerationIssue, EntryPointDetectionMethod, DisplayKind, DiffOptions, DISPLAY_KIND_ORDER, CategorizedBreaking, BreakingSeverity };
|
|
628
|
+
export { validateSpec, resolveRef, recommendSemverBump, normalize, isVoidSchema, isTupleSchema, isStringSchema, isRefSchema, isOneOfSchema, isObjectSchema, isNumberSchema, isNullSchema, isNeverSchema, isIntegerSchema, isFunctionSchema, isBooleanSchema, isArraySchema, isAnySchema, isAnyOfSchema, isAllOfSchema, getValidationErrors, getSchemaType, getAvailableVersions, flattenAnyOf, diffSpec, dereference, categorizeBreakingChanges, calculateNextVersion, assertSpec, SpecVisibility, SpecTypePredicate, SpecTypeParameter, SpecTypeKind, SpecTypeAliasKind, SpecType, SpecThrows, SpecTagParam, SpecTag, SpecSource, SpecSkippedExport, SpecSignatureReturn, SpecSignatureParameter, SpecSignature, SpecSchemaRef, SpecSchemaPrimitive, SpecSchemaGeneric, SpecSchemaFallback, SpecSchemaComposite, SpecSchemaCombinator, SpecSchema, SpecPresentationMeta, SpecMember, SpecMappedType, SpecInheritedMember, SpecGenerationMeta, SpecGenerationInfo, SpecExtractionMode, SpecExtractionLimitation, SpecExtensions, SpecExtension, SpecExportKind, SpecExport, SpecExampleLanguage, SpecExample, SpecDiff, SpecDecorator, SpecConditionalType, SemverRecommendation, SemverBump, SCHEMA_VERSION, SCHEMA_URL_MIRROR, SCHEMA_URL, OpenPkgVersion, OpenPkgMeta, OpenPkg, MemberChangeInfo, KIND_SLUGS, KIND_LABELS, JSON_SCHEMA_DRAFT, JSONSchemaExtensions, GenerationIssueSeverity, GenerationIssue, EntryPointDetectionMethod, DisplayKind, DiffOptions, DISPLAY_KIND_ORDER, CategorizedBreaking, BreakingSeverity };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/constants.ts
|
|
2
2
|
var SCHEMA_VERSION = "0.4.0";
|
|
3
|
-
var SCHEMA_URL = "https://
|
|
3
|
+
var SCHEMA_URL = "https://openpkg.dev/schemas/v0.4.0/openpkg.schema.json";
|
|
4
|
+
var SCHEMA_URL_MIRROR = "https://unpkg.com/@openpkg-ts/spec/schemas/v0.4.0/openpkg.schema.json";
|
|
4
5
|
var JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
|
|
5
6
|
var DISPLAY_KIND_ORDER = [
|
|
6
7
|
"function",
|
|
@@ -99,103 +100,6 @@ function resolveTypeRef(id, lookup, seen) {
|
|
|
99
100
|
}
|
|
100
101
|
return structuredClone(target);
|
|
101
102
|
}
|
|
102
|
-
// src/guards.ts
|
|
103
|
-
function isObj(s) {
|
|
104
|
-
return typeof s === "object" && s !== null;
|
|
105
|
-
}
|
|
106
|
-
function hasType(s, t) {
|
|
107
|
-
return isObj(s) && "type" in s && s.type === t;
|
|
108
|
-
}
|
|
109
|
-
function isStringSchema(s) {
|
|
110
|
-
return hasType(s, "string");
|
|
111
|
-
}
|
|
112
|
-
function isNumberSchema(s) {
|
|
113
|
-
return hasType(s, "number");
|
|
114
|
-
}
|
|
115
|
-
function isBooleanSchema(s) {
|
|
116
|
-
return hasType(s, "boolean");
|
|
117
|
-
}
|
|
118
|
-
function isIntegerSchema(s) {
|
|
119
|
-
return hasType(s, "integer");
|
|
120
|
-
}
|
|
121
|
-
function isNullSchema(s) {
|
|
122
|
-
return hasType(s, "null");
|
|
123
|
-
}
|
|
124
|
-
function isVoidSchema(s) {
|
|
125
|
-
return hasType(s, "void");
|
|
126
|
-
}
|
|
127
|
-
function isNeverSchema(s) {
|
|
128
|
-
return hasType(s, "never");
|
|
129
|
-
}
|
|
130
|
-
function isAnySchema(s) {
|
|
131
|
-
return hasType(s, "any");
|
|
132
|
-
}
|
|
133
|
-
function isObjectSchema(s) {
|
|
134
|
-
return hasType(s, "object");
|
|
135
|
-
}
|
|
136
|
-
function isArraySchema(s) {
|
|
137
|
-
return hasType(s, "array");
|
|
138
|
-
}
|
|
139
|
-
function isTupleSchema(s) {
|
|
140
|
-
return hasType(s, "tuple");
|
|
141
|
-
}
|
|
142
|
-
function isFunctionSchema(s) {
|
|
143
|
-
return hasType(s, "function");
|
|
144
|
-
}
|
|
145
|
-
function isAnyOfSchema(s) {
|
|
146
|
-
return isObj(s) && "anyOf" in s && Array.isArray(s.anyOf);
|
|
147
|
-
}
|
|
148
|
-
function isAllOfSchema(s) {
|
|
149
|
-
return isObj(s) && "allOf" in s && Array.isArray(s.allOf);
|
|
150
|
-
}
|
|
151
|
-
function isOneOfSchema(s) {
|
|
152
|
-
return isObj(s) && "oneOf" in s && Array.isArray(s.oneOf);
|
|
153
|
-
}
|
|
154
|
-
function isRefSchema(s) {
|
|
155
|
-
return isObj(s) && "$ref" in s && typeof s.$ref === "string";
|
|
156
|
-
}
|
|
157
|
-
// src/schema-utils.ts
|
|
158
|
-
function resolveRef(schema, spec) {
|
|
159
|
-
if (!isRefSchema(schema))
|
|
160
|
-
return null;
|
|
161
|
-
const prefix = "#/types/";
|
|
162
|
-
if (!schema.$ref.startsWith(prefix))
|
|
163
|
-
return null;
|
|
164
|
-
const name = schema.$ref.slice(prefix.length);
|
|
165
|
-
return spec.types?.find((t) => t.name === name) ?? null;
|
|
166
|
-
}
|
|
167
|
-
function flattenAnyOf(schema) {
|
|
168
|
-
if (!isAnyOfSchema(schema))
|
|
169
|
-
return [schema];
|
|
170
|
-
const result = [];
|
|
171
|
-
for (const s of schema.anyOf) {
|
|
172
|
-
if (isAnyOfSchema(s)) {
|
|
173
|
-
result.push(...flattenAnyOf(s));
|
|
174
|
-
} else {
|
|
175
|
-
result.push(s);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return result;
|
|
179
|
-
}
|
|
180
|
-
function getSchemaType(schema) {
|
|
181
|
-
if (typeof schema === "string")
|
|
182
|
-
return schema;
|
|
183
|
-
if ("$ref" in schema && typeof schema.$ref === "string") {
|
|
184
|
-
const ref = schema.$ref;
|
|
185
|
-
const prefix = "#/types/";
|
|
186
|
-
return ref.startsWith(prefix) ? ref.slice(prefix.length) : ref;
|
|
187
|
-
}
|
|
188
|
-
if ("anyOf" in schema)
|
|
189
|
-
return "union";
|
|
190
|
-
if ("allOf" in schema)
|
|
191
|
-
return "intersection";
|
|
192
|
-
if ("oneOf" in schema)
|
|
193
|
-
return "oneOf";
|
|
194
|
-
if ("type" in schema && typeof schema.type === "string") {
|
|
195
|
-
return schema.type;
|
|
196
|
-
}
|
|
197
|
-
return "unknown";
|
|
198
|
-
}
|
|
199
103
|
// src/diff.ts
|
|
200
104
|
function diffSpec(oldSpec, newSpec, options) {
|
|
201
105
|
const { includeDocsOnly = true, kinds } = options ?? {};
|
|
@@ -430,6 +334,61 @@ function calculateNextVersion(currentVersion, bump) {
|
|
|
430
334
|
const prefix = currentVersion.startsWith("v") ? "v" : "";
|
|
431
335
|
return `${prefix}${major}.${minor}.${patch}`;
|
|
432
336
|
}
|
|
337
|
+
// src/guards.ts
|
|
338
|
+
function isObj(s) {
|
|
339
|
+
return typeof s === "object" && s !== null;
|
|
340
|
+
}
|
|
341
|
+
function hasType(s, t) {
|
|
342
|
+
return isObj(s) && "type" in s && s.type === t;
|
|
343
|
+
}
|
|
344
|
+
function isStringSchema(s) {
|
|
345
|
+
return hasType(s, "string");
|
|
346
|
+
}
|
|
347
|
+
function isNumberSchema(s) {
|
|
348
|
+
return hasType(s, "number");
|
|
349
|
+
}
|
|
350
|
+
function isBooleanSchema(s) {
|
|
351
|
+
return hasType(s, "boolean");
|
|
352
|
+
}
|
|
353
|
+
function isIntegerSchema(s) {
|
|
354
|
+
return hasType(s, "integer");
|
|
355
|
+
}
|
|
356
|
+
function isNullSchema(s) {
|
|
357
|
+
return hasType(s, "null");
|
|
358
|
+
}
|
|
359
|
+
function isVoidSchema(s) {
|
|
360
|
+
return hasType(s, "void");
|
|
361
|
+
}
|
|
362
|
+
function isNeverSchema(s) {
|
|
363
|
+
return hasType(s, "never");
|
|
364
|
+
}
|
|
365
|
+
function isAnySchema(s) {
|
|
366
|
+
return hasType(s, "any");
|
|
367
|
+
}
|
|
368
|
+
function isObjectSchema(s) {
|
|
369
|
+
return hasType(s, "object");
|
|
370
|
+
}
|
|
371
|
+
function isArraySchema(s) {
|
|
372
|
+
return hasType(s, "array");
|
|
373
|
+
}
|
|
374
|
+
function isTupleSchema(s) {
|
|
375
|
+
return hasType(s, "tuple");
|
|
376
|
+
}
|
|
377
|
+
function isFunctionSchema(s) {
|
|
378
|
+
return hasType(s, "function");
|
|
379
|
+
}
|
|
380
|
+
function isAnyOfSchema(s) {
|
|
381
|
+
return isObj(s) && "anyOf" in s && Array.isArray(s.anyOf);
|
|
382
|
+
}
|
|
383
|
+
function isAllOfSchema(s) {
|
|
384
|
+
return isObj(s) && "allOf" in s && Array.isArray(s.allOf);
|
|
385
|
+
}
|
|
386
|
+
function isOneOfSchema(s) {
|
|
387
|
+
return isObj(s) && "oneOf" in s && Array.isArray(s.oneOf);
|
|
388
|
+
}
|
|
389
|
+
function isRefSchema(s) {
|
|
390
|
+
return isObj(s) && "$ref" in s && typeof s.$ref === "string";
|
|
391
|
+
}
|
|
433
392
|
// src/normalize.ts
|
|
434
393
|
var DEFAULT_ECOSYSTEM = "js/ts";
|
|
435
394
|
var arrayFieldsByExport = ["signatures", "members", "examples", "tags"];
|
|
@@ -503,13 +462,55 @@ function normalizeMember(member) {
|
|
|
503
462
|
}
|
|
504
463
|
return clone;
|
|
505
464
|
}
|
|
465
|
+
// src/schema-utils.ts
|
|
466
|
+
function resolveRef(schema, spec) {
|
|
467
|
+
if (!isRefSchema(schema))
|
|
468
|
+
return null;
|
|
469
|
+
const prefix = "#/types/";
|
|
470
|
+
if (!schema.$ref.startsWith(prefix))
|
|
471
|
+
return null;
|
|
472
|
+
const name = schema.$ref.slice(prefix.length);
|
|
473
|
+
return spec.types?.find((t) => t.name === name) ?? null;
|
|
474
|
+
}
|
|
475
|
+
function flattenAnyOf(schema) {
|
|
476
|
+
if (!isAnyOfSchema(schema))
|
|
477
|
+
return [schema];
|
|
478
|
+
const result = [];
|
|
479
|
+
for (const s of schema.anyOf) {
|
|
480
|
+
if (isAnyOfSchema(s)) {
|
|
481
|
+
result.push(...flattenAnyOf(s));
|
|
482
|
+
} else {
|
|
483
|
+
result.push(s);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return result;
|
|
487
|
+
}
|
|
488
|
+
function getSchemaType(schema) {
|
|
489
|
+
if (typeof schema === "string")
|
|
490
|
+
return schema;
|
|
491
|
+
if ("$ref" in schema && typeof schema.$ref === "string") {
|
|
492
|
+
const ref = schema.$ref;
|
|
493
|
+
const prefix = "#/types/";
|
|
494
|
+
return ref.startsWith(prefix) ? ref.slice(prefix.length) : ref;
|
|
495
|
+
}
|
|
496
|
+
if ("anyOf" in schema)
|
|
497
|
+
return "union";
|
|
498
|
+
if ("allOf" in schema)
|
|
499
|
+
return "intersection";
|
|
500
|
+
if ("oneOf" in schema)
|
|
501
|
+
return "oneOf";
|
|
502
|
+
if ("type" in schema && typeof schema.type === "string") {
|
|
503
|
+
return schema.type;
|
|
504
|
+
}
|
|
505
|
+
return "unknown";
|
|
506
|
+
}
|
|
506
507
|
// src/validate.ts
|
|
507
508
|
import Ajv from "ajv/dist/2020.js";
|
|
508
509
|
import addFormats from "ajv-formats";
|
|
509
510
|
// schemas/v0.1.0/openpkg.schema.json
|
|
510
511
|
var openpkg_schema_default = {
|
|
511
512
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
512
|
-
$id: "https://
|
|
513
|
+
$id: "https://openpkg.dev/schemas/v0.1.0/openpkg.schema.json",
|
|
513
514
|
title: "OpenPkg Specification",
|
|
514
515
|
description: "Schema for OpenPkg specification files",
|
|
515
516
|
type: "object",
|
|
@@ -811,7 +812,7 @@ var openpkg_schema_default = {
|
|
|
811
812
|
// schemas/v0.2.0/openpkg.schema.json
|
|
812
813
|
var openpkg_schema_default2 = {
|
|
813
814
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
814
|
-
$id: "https://
|
|
815
|
+
$id: "https://openpkg.dev/schemas/v0.2.0/openpkg.schema.json",
|
|
815
816
|
title: "OpenPkg Specification",
|
|
816
817
|
description: "Schema for OpenPkg specification files",
|
|
817
818
|
type: "object",
|
|
@@ -1237,7 +1238,7 @@ var openpkg_schema_default2 = {
|
|
|
1237
1238
|
// schemas/v0.3.0/openpkg.schema.json
|
|
1238
1239
|
var openpkg_schema_default3 = {
|
|
1239
1240
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
1240
|
-
$id: "https://
|
|
1241
|
+
$id: "https://openpkg.dev/schemas/v0.3.0/openpkg.schema.json",
|
|
1241
1242
|
title: "OpenPkg Specification",
|
|
1242
1243
|
description: "Schema for OpenPkg specification files",
|
|
1243
1244
|
type: "object",
|
|
@@ -2234,7 +2235,7 @@ var openpkg_schema_default3 = {
|
|
|
2234
2235
|
// schemas/v0.4.0/openpkg.schema.json
|
|
2235
2236
|
var openpkg_schema_default4 = {
|
|
2236
2237
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
2237
|
-
$id: "https://
|
|
2238
|
+
$id: "https://openpkg.dev/schemas/v0.4.0/openpkg.schema.json",
|
|
2238
2239
|
title: "OpenPkg Specification v0.4.0",
|
|
2239
2240
|
description: "Minimal tool-agnostic TypeScript export representation",
|
|
2240
2241
|
type: "object",
|
|
@@ -2716,6 +2717,7 @@ export {
|
|
|
2716
2717
|
calculateNextVersion,
|
|
2717
2718
|
assertSpec,
|
|
2718
2719
|
SCHEMA_VERSION,
|
|
2720
|
+
SCHEMA_URL_MIRROR,
|
|
2719
2721
|
SCHEMA_URL,
|
|
2720
2722
|
KIND_SLUGS,
|
|
2721
2723
|
KIND_LABELS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/spec",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "Shared schema, validation, and diff utilities for OpenPkg specs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openpkg",
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"test": "bun test",
|
|
37
37
|
"lint": "biome check src/",
|
|
38
38
|
"lint:fix": "biome check --write src/",
|
|
39
|
-
"format": "biome format --write src/"
|
|
39
|
+
"format": "biome format --write src/",
|
|
40
|
+
"typecheck": "tsc --noEmit -p ."
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
43
|
"ajv": "^8.17.1",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://
|
|
3
|
+
"$id": "https://openpkg.dev/schemas/v0.1.0/openpkg.schema.json",
|
|
4
4
|
"title": "OpenPkg Specification",
|
|
5
5
|
"description": "Schema for OpenPkg specification files",
|
|
6
6
|
"type": "object",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://
|
|
3
|
+
"$id": "https://openpkg.dev/schemas/v0.2.0/openpkg.schema.json",
|
|
4
4
|
"title": "OpenPkg Specification",
|
|
5
5
|
"description": "Schema for OpenPkg specification files",
|
|
6
6
|
"type": "object",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://
|
|
3
|
+
"$id": "https://openpkg.dev/schemas/v0.3.0/openpkg.schema.json",
|
|
4
4
|
"title": "OpenPkg Specification",
|
|
5
5
|
"description": "Schema for OpenPkg specification files",
|
|
6
6
|
"type": "object",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://
|
|
3
|
+
"$id": "https://openpkg.dev/schemas/v0.4.0/openpkg.schema.json",
|
|
4
4
|
"title": "OpenPkg Specification v0.4.0",
|
|
5
5
|
"description": "Minimal tool-agnostic TypeScript export representation",
|
|
6
6
|
"type": "object",
|