@openpkg-ts/spec 0.35.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @openpkg-ts/spec
2
2
 
3
- OpenPkg specification types, validation, normalization, and diffing utilities.
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
@@ -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 */
@@ -412,7 +414,10 @@ type OpenPkg = {
412
414
  generation?: SpecGenerationMeta | SpecGenerationInfo;
413
415
  };
414
416
  declare const SCHEMA_VERSION: OpenPkgVersion;
415
- declare const SCHEMA_URL = "https://unpkg.com/@openpkg-ts/spec/schemas/v0.4.0/openpkg.schema.json";
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";
416
421
  declare const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
417
422
  /** The 6 kinds relevant for UI display (excludes namespace, module, reference, external). */
418
423
  type DisplayKind = Extract<SpecExportKind, "function" | "class" | "interface" | "type" | "enum" | "variable">;
@@ -517,7 +522,67 @@ declare function recommendSemverBump(diff: SpecDiff): SemverRecommendation;
517
522
  * ```
518
523
  */
519
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;
520
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;
521
586
  /** Concrete schema versions (excludes 'latest' alias) */
522
587
  type ConcreteSchemaVersion = "0.1.0" | "0.2.0" | "0.3.0" | "0.4.0";
523
588
  /** Supported schema versions */
@@ -560,4 +625,4 @@ declare function assertSpec(spec: unknown, version?: SchemaVersion): asserts spe
560
625
  * @returns Array of validation errors (empty if valid)
561
626
  */
562
627
  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 };
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://unpkg.com/@openpkg-ts/spec/schemas/v0.4.0/openpkg.schema.json";
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",
@@ -333,6 +334,61 @@ function calculateNextVersion(currentVersion, bump) {
333
334
  const prefix = currentVersion.startsWith("v") ? "v" : "";
334
335
  return `${prefix}${major}.${minor}.${patch}`;
335
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
+ }
336
392
  // src/normalize.ts
337
393
  var DEFAULT_ECOSYSTEM = "js/ts";
338
394
  var arrayFieldsByExport = ["signatures", "members", "examples", "tags"];
@@ -406,13 +462,55 @@ function normalizeMember(member) {
406
462
  }
407
463
  return clone;
408
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
+ }
409
507
  // src/validate.ts
410
508
  import Ajv from "ajv/dist/2020.js";
411
509
  import addFormats from "ajv-formats";
412
510
  // schemas/v0.1.0/openpkg.schema.json
413
511
  var openpkg_schema_default = {
414
512
  $schema: "https://json-schema.org/draft/2020-12/schema",
415
- $id: "https://unpkg.com/@openpkg-ts/spec/schemas/v0.1.0/openpkg.schema.json",
513
+ $id: "https://openpkg.dev/schemas/v0.1.0/openpkg.schema.json",
416
514
  title: "OpenPkg Specification",
417
515
  description: "Schema for OpenPkg specification files",
418
516
  type: "object",
@@ -714,7 +812,7 @@ var openpkg_schema_default = {
714
812
  // schemas/v0.2.0/openpkg.schema.json
715
813
  var openpkg_schema_default2 = {
716
814
  $schema: "https://json-schema.org/draft/2020-12/schema",
717
- $id: "https://unpkg.com/@openpkg-ts/spec/schemas/v0.2.0/openpkg.schema.json",
815
+ $id: "https://openpkg.dev/schemas/v0.2.0/openpkg.schema.json",
718
816
  title: "OpenPkg Specification",
719
817
  description: "Schema for OpenPkg specification files",
720
818
  type: "object",
@@ -1140,7 +1238,7 @@ var openpkg_schema_default2 = {
1140
1238
  // schemas/v0.3.0/openpkg.schema.json
1141
1239
  var openpkg_schema_default3 = {
1142
1240
  $schema: "https://json-schema.org/draft/2020-12/schema",
1143
- $id: "https://unpkg.com/@openpkg-ts/spec/schemas/v0.3.0/openpkg.schema.json",
1241
+ $id: "https://openpkg.dev/schemas/v0.3.0/openpkg.schema.json",
1144
1242
  title: "OpenPkg Specification",
1145
1243
  description: "Schema for OpenPkg specification files",
1146
1244
  type: "object",
@@ -2137,7 +2235,7 @@ var openpkg_schema_default3 = {
2137
2235
  // schemas/v0.4.0/openpkg.schema.json
2138
2236
  var openpkg_schema_default4 = {
2139
2237
  $schema: "https://json-schema.org/draft/2020-12/schema",
2140
- $id: "https://unpkg.com/@openpkg-ts/spec/schemas/v0.4.0/openpkg.schema.json",
2238
+ $id: "https://openpkg.dev/schemas/v0.4.0/openpkg.schema.json",
2141
2239
  title: "OpenPkg Specification v0.4.0",
2142
2240
  description: "Minimal tool-agnostic TypeScript export representation",
2143
2241
  type: "object",
@@ -2590,16 +2688,36 @@ function getValidationErrors(spec, version = "latest") {
2590
2688
  }
2591
2689
  export {
2592
2690
  validateSpec,
2691
+ resolveRef,
2593
2692
  recommendSemverBump,
2594
2693
  normalize,
2694
+ isVoidSchema,
2695
+ isTupleSchema,
2696
+ isStringSchema,
2697
+ isRefSchema,
2698
+ isOneOfSchema,
2699
+ isObjectSchema,
2700
+ isNumberSchema,
2701
+ isNullSchema,
2702
+ isNeverSchema,
2703
+ isIntegerSchema,
2704
+ isFunctionSchema,
2705
+ isBooleanSchema,
2706
+ isArraySchema,
2707
+ isAnySchema,
2708
+ isAnyOfSchema,
2709
+ isAllOfSchema,
2595
2710
  getValidationErrors,
2711
+ getSchemaType,
2596
2712
  getAvailableVersions,
2713
+ flattenAnyOf,
2597
2714
  diffSpec,
2598
2715
  dereference,
2599
2716
  categorizeBreakingChanges,
2600
2717
  calculateNextVersion,
2601
2718
  assertSpec,
2602
2719
  SCHEMA_VERSION,
2720
+ SCHEMA_URL_MIRROR,
2603
2721
  SCHEMA_URL,
2604
2722
  KIND_SLUGS,
2605
2723
  KIND_LABELS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/spec",
3
- "version": "0.35.1",
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://unpkg.com/@openpkg-ts/spec/schemas/v0.1.0/openpkg.schema.json",
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://unpkg.com/@openpkg-ts/spec/schemas/v0.2.0/openpkg.schema.json",
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://unpkg.com/@openpkg-ts/spec/schemas/v0.3.0/openpkg.schema.json",
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://unpkg.com/@openpkg-ts/spec/schemas/v0.4.0/openpkg.schema.json",
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",