@openpkg-ts/spec 0.34.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 */
@@ -414,7 +416,75 @@ type OpenPkg = {
414
416
  declare const SCHEMA_VERSION: OpenPkgVersion;
415
417
  declare const SCHEMA_URL = "https://unpkg.com/@openpkg-ts/spec/schemas/v0.4.0/openpkg.schema.json";
416
418
  declare const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
419
+ /** The 6 kinds relevant for UI display (excludes namespace, module, reference, external). */
420
+ type DisplayKind = Extract<SpecExportKind, "function" | "class" | "interface" | "type" | "enum" | "variable">;
421
+ /** Canonical display order for UI-facing kind groups. */
422
+ declare const DISPLAY_KIND_ORDER: DisplayKind[];
423
+ /** Human-readable plural labels for every kind. */
424
+ declare const KIND_LABELS: Record<SpecExportKind, string>;
425
+ /** URL-safe slug for every kind. */
426
+ declare const KIND_SLUGS: Record<SpecExportKind, string>;
417
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;
418
488
  type BreakingSeverity = "high" | "medium" | "low";
419
489
  interface CategorizedBreaking {
420
490
  id: string;
@@ -510,8 +580,10 @@ declare function recommendSemverBump(diff: SpecDiff): SemverRecommendation;
510
580
  */
511
581
  declare function calculateNextVersion(currentVersion: string, bump: SemverBump): string;
512
582
  declare function normalize(spec: OpenPkg): OpenPkg;
583
+ /** Concrete schema versions (excludes 'latest' alias) */
584
+ type ConcreteSchemaVersion = "0.1.0" | "0.2.0" | "0.3.0" | "0.4.0";
513
585
  /** Supported schema versions */
514
- type SchemaVersion = "0.1.0" | "0.2.0" | "0.3.0" | "0.4.0" | "latest";
586
+ type SchemaVersion = ConcreteSchemaVersion | "latest";
515
587
  type SpecError = {
516
588
  instancePath: string;
517
589
  message: string;
@@ -550,4 +622,4 @@ declare function assertSpec(spec: unknown, version?: SchemaVersion): asserts spe
550
622
  * @returns Array of validation errors (empty if valid)
551
623
  */
552
624
  declare function getValidationErrors(spec: unknown, version?: SchemaVersion): SpecError[];
553
- 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, JSON_SCHEMA_DRAFT, JSONSchemaExtensions, GenerationIssueSeverity, GenerationIssue, EntryPointDetectionMethod, DiffOptions, 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
@@ -2,9 +2,41 @@
2
2
  var SCHEMA_VERSION = "0.4.0";
3
3
  var SCHEMA_URL = "https://unpkg.com/@openpkg-ts/spec/schemas/v0.4.0/openpkg.schema.json";
4
4
  var JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
5
+ var DISPLAY_KIND_ORDER = [
6
+ "function",
7
+ "class",
8
+ "interface",
9
+ "type",
10
+ "enum",
11
+ "variable"
12
+ ];
13
+ var KIND_LABELS = {
14
+ function: "Functions",
15
+ class: "Classes",
16
+ interface: "Interfaces",
17
+ type: "Types",
18
+ enum: "Enums",
19
+ variable: "Variables",
20
+ namespace: "Namespaces",
21
+ module: "Modules",
22
+ reference: "References",
23
+ external: "External"
24
+ };
25
+ var KIND_SLUGS = {
26
+ function: "functions",
27
+ class: "classes",
28
+ interface: "interfaces",
29
+ type: "types",
30
+ enum: "enums",
31
+ variable: "variables",
32
+ namespace: "namespaces",
33
+ module: "modules",
34
+ reference: "references",
35
+ external: "externals"
36
+ };
5
37
  // src/deref.ts
6
38
  function dereference(spec) {
7
- const clone = JSON.parse(JSON.stringify(spec));
39
+ const clone = structuredClone(spec);
8
40
  const typeLookup = buildTypeLookup(clone.types);
9
41
  const visit = (value, seen) => {
10
42
  if (Array.isArray(value)) {
@@ -63,9 +95,106 @@ function resolveTypeRef(id, lookup, seen) {
63
95
  }
64
96
  seen.add(id);
65
97
  if (target.schema) {
66
- return JSON.parse(JSON.stringify(target.schema));
98
+ return structuredClone(target.schema);
99
+ }
100
+ return structuredClone(target);
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
+ }
67
177
  }
68
- return JSON.parse(JSON.stringify(target));
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";
69
198
  }
70
199
  // src/diff.ts
71
200
  function diffSpec(oldSpec, newSpec, options) {
@@ -281,7 +410,9 @@ function calculateNextVersion(currentVersion, bump) {
281
410
  if (!match) {
282
411
  return currentVersion;
283
412
  }
284
- let [, major, minor, patch] = match.map(Number);
413
+ let major = parseInt(match[1], 10);
414
+ let minor = parseInt(match[2], 10);
415
+ let patch = parseInt(match[3], 10);
285
416
  switch (bump) {
286
417
  case "major":
287
418
  major++;
@@ -332,30 +463,9 @@ function normalizeGeneration(gen) {
332
463
  }
333
464
  return gen;
334
465
  }
335
- function normalizeExport(item) {
336
- const clone = structuredClone(item);
337
- for (const field of arrayFieldsByExport) {
338
- if (!Array.isArray(clone[field])) {
339
- clone[field] = [];
340
- }
341
- }
342
- if (clone.type !== undefined && typeof clone.type !== "string") {
343
- if (!clone.schema) {
344
- clone.schema = clone.type;
345
- }
346
- delete clone.type;
347
- }
348
- if (clone.tags && clone.tags.length > 0) {
349
- clone.tags = clone.tags.map(normalizeTag);
350
- }
351
- if (clone.members && clone.members.length > 0) {
352
- clone.members = clone.members.map(normalizeMember);
353
- }
354
- return clone;
355
- }
356
- function normalizeType(item) {
466
+ function normalizeEntry(item, arrayFields) {
357
467
  const clone = structuredClone(item);
358
- for (const field of arrayFieldsByType) {
468
+ for (const field of arrayFields) {
359
469
  if (!Array.isArray(clone[field])) {
360
470
  clone[field] = [];
361
471
  }
@@ -374,6 +484,8 @@ function normalizeType(item) {
374
484
  }
375
485
  return clone;
376
486
  }
487
+ var normalizeExport = (item) => normalizeEntry(item, arrayFieldsByExport);
488
+ var normalizeType = (item) => normalizeEntry(item, arrayFieldsByType);
377
489
  function normalizeTag(tag) {
378
490
  const result = {
379
491
  name: tag.name,
@@ -2575,10 +2687,29 @@ function getValidationErrors(spec, version = "latest") {
2575
2687
  }
2576
2688
  export {
2577
2689
  validateSpec,
2690
+ resolveRef,
2578
2691
  recommendSemverBump,
2579
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,
2580
2709
  getValidationErrors,
2710
+ getSchemaType,
2581
2711
  getAvailableVersions,
2712
+ flattenAnyOf,
2582
2713
  diffSpec,
2583
2714
  dereference,
2584
2715
  categorizeBreakingChanges,
@@ -2586,5 +2717,8 @@ export {
2586
2717
  assertSpec,
2587
2718
  SCHEMA_VERSION,
2588
2719
  SCHEMA_URL,
2589
- JSON_SCHEMA_DRAFT
2720
+ KIND_SLUGS,
2721
+ KIND_LABELS,
2722
+ JSON_SCHEMA_DRAFT,
2723
+ DISPLAY_KIND_ORDER
2590
2724
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/spec",
3
- "version": "0.34.1",
3
+ "version": "0.37.0",
4
4
  "description": "Shared schema, validation, and diff utilities for OpenPkg specs",
5
5
  "keywords": [
6
6
  "openpkg",