@openpkg-ts/spec 0.34.1 → 0.35.1

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
@@ -414,6 +414,14 @@ type OpenPkg = {
414
414
  declare const SCHEMA_VERSION: OpenPkgVersion;
415
415
  declare const SCHEMA_URL = "https://unpkg.com/@openpkg-ts/spec/schemas/v0.4.0/openpkg.schema.json";
416
416
  declare const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
417
+ /** The 6 kinds relevant for UI display (excludes namespace, module, reference, external). */
418
+ type DisplayKind = Extract<SpecExportKind, "function" | "class" | "interface" | "type" | "enum" | "variable">;
419
+ /** Canonical display order for UI-facing kind groups. */
420
+ declare const DISPLAY_KIND_ORDER: DisplayKind[];
421
+ /** Human-readable plural labels for every kind. */
422
+ declare const KIND_LABELS: Record<SpecExportKind, string>;
423
+ /** URL-safe slug for every kind. */
424
+ declare const KIND_SLUGS: Record<SpecExportKind, string>;
417
425
  declare function dereference(spec: OpenPkg): OpenPkg;
418
426
  type BreakingSeverity = "high" | "medium" | "low";
419
427
  interface CategorizedBreaking {
@@ -510,8 +518,10 @@ declare function recommendSemverBump(diff: SpecDiff): SemverRecommendation;
510
518
  */
511
519
  declare function calculateNextVersion(currentVersion: string, bump: SemverBump): string;
512
520
  declare function normalize(spec: OpenPkg): OpenPkg;
521
+ /** Concrete schema versions (excludes 'latest' alias) */
522
+ type ConcreteSchemaVersion = "0.1.0" | "0.2.0" | "0.3.0" | "0.4.0";
513
523
  /** Supported schema versions */
514
- type SchemaVersion = "0.1.0" | "0.2.0" | "0.3.0" | "0.4.0" | "latest";
524
+ type SchemaVersion = ConcreteSchemaVersion | "latest";
515
525
  type SpecError = {
516
526
  instancePath: string;
517
527
  message: string;
@@ -550,4 +560,4 @@ declare function assertSpec(spec: unknown, version?: SchemaVersion): asserts spe
550
560
  * @returns Array of validation errors (empty if valid)
551
561
  */
552
562
  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 };
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 };
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,9 @@ 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);
67
99
  }
68
- return JSON.parse(JSON.stringify(target));
100
+ return structuredClone(target);
69
101
  }
70
102
  // src/diff.ts
71
103
  function diffSpec(oldSpec, newSpec, options) {
@@ -281,7 +313,9 @@ function calculateNextVersion(currentVersion, bump) {
281
313
  if (!match) {
282
314
  return currentVersion;
283
315
  }
284
- let [, major, minor, patch] = match.map(Number);
316
+ let major = parseInt(match[1], 10);
317
+ let minor = parseInt(match[2], 10);
318
+ let patch = parseInt(match[3], 10);
285
319
  switch (bump) {
286
320
  case "major":
287
321
  major++;
@@ -332,30 +366,9 @@ function normalizeGeneration(gen) {
332
366
  }
333
367
  return gen;
334
368
  }
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) {
369
+ function normalizeEntry(item, arrayFields) {
357
370
  const clone = structuredClone(item);
358
- for (const field of arrayFieldsByType) {
371
+ for (const field of arrayFields) {
359
372
  if (!Array.isArray(clone[field])) {
360
373
  clone[field] = [];
361
374
  }
@@ -374,6 +387,8 @@ function normalizeType(item) {
374
387
  }
375
388
  return clone;
376
389
  }
390
+ var normalizeExport = (item) => normalizeEntry(item, arrayFieldsByExport);
391
+ var normalizeType = (item) => normalizeEntry(item, arrayFieldsByType);
377
392
  function normalizeTag(tag) {
378
393
  const result = {
379
394
  name: tag.name,
@@ -2586,5 +2601,8 @@ export {
2586
2601
  assertSpec,
2587
2602
  SCHEMA_VERSION,
2588
2603
  SCHEMA_URL,
2589
- JSON_SCHEMA_DRAFT
2604
+ KIND_SLUGS,
2605
+ KIND_LABELS,
2606
+ JSON_SCHEMA_DRAFT,
2607
+ DISPLAY_KIND_ORDER
2590
2608
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/spec",
3
- "version": "0.34.1",
3
+ "version": "0.35.1",
4
4
  "description": "Shared schema, validation, and diff utilities for OpenPkg specs",
5
5
  "keywords": [
6
6
  "openpkg",