@openpkg-ts/spec 0.35.1 → 0.37.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/dist/index.d.ts CHANGED
@@ -244,6 +244,8 @@ type SpecMember = {
244
244
  schema?: SpecSchema;
245
245
  signatures?: SpecSignature[];
246
246
  decorators?: SpecDecorator[];
247
+ deprecated?: boolean;
248
+ deprecationReason?: string;
247
249
  };
248
250
  type SpecInheritedMember = SpecMember & {
249
251
  /** Name of the class this member was inherited from */
@@ -423,6 +425,66 @@ declare const KIND_LABELS: Record<SpecExportKind, string>;
423
425
  /** URL-safe slug for every kind. */
424
426
  declare const KIND_SLUGS: Record<SpecExportKind, string>;
425
427
  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;
426
488
  type BreakingSeverity = "high" | "medium" | "low";
427
489
  interface CategorizedBreaking {
428
490
  id: string;
@@ -560,4 +622,4 @@ declare function assertSpec(spec: unknown, version?: SchemaVersion): asserts spe
560
622
  * @returns Array of validation errors (empty if valid)
561
623
  */
562
624
  declare function getValidationErrors(spec: unknown, version?: SchemaVersion): SpecError[];
563
- export { validateSpec, recommendSemverBump, normalize, getValidationErrors, getAvailableVersions, 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 };
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 };
package/dist/index.js CHANGED
@@ -99,6 +99,103 @@ function resolveTypeRef(id, lookup, seen) {
99
99
  }
100
100
  return structuredClone(target);
101
101
  }
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
+ }
102
199
  // src/diff.ts
103
200
  function diffSpec(oldSpec, newSpec, options) {
104
201
  const { includeDocsOnly = true, kinds } = options ?? {};
@@ -2590,10 +2687,29 @@ function getValidationErrors(spec, version = "latest") {
2590
2687
  }
2591
2688
  export {
2592
2689
  validateSpec,
2690
+ resolveRef,
2593
2691
  recommendSemverBump,
2594
2692
  normalize,
2693
+ isVoidSchema,
2694
+ isTupleSchema,
2695
+ isStringSchema,
2696
+ isRefSchema,
2697
+ isOneOfSchema,
2698
+ isObjectSchema,
2699
+ isNumberSchema,
2700
+ isNullSchema,
2701
+ isNeverSchema,
2702
+ isIntegerSchema,
2703
+ isFunctionSchema,
2704
+ isBooleanSchema,
2705
+ isArraySchema,
2706
+ isAnySchema,
2707
+ isAnyOfSchema,
2708
+ isAllOfSchema,
2595
2709
  getValidationErrors,
2710
+ getSchemaType,
2596
2711
  getAvailableVersions,
2712
+ flattenAnyOf,
2597
2713
  diffSpec,
2598
2714
  dereference,
2599
2715
  categorizeBreakingChanges,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/spec",
3
- "version": "0.35.1",
3
+ "version": "0.37.0",
4
4
  "description": "Shared schema, validation, and diff utilities for OpenPkg specs",
5
5
  "keywords": [
6
6
  "openpkg",