@openpkg-ts/spec 0.19.0 → 0.24.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.
Files changed (2) hide show
  1. package/dist/index.d.ts +76 -2
  2. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -112,7 +112,7 @@ type SpecSchemaRef = {
112
112
  type SpecSchemaFallback = {
113
113
  type: string;
114
114
  };
115
- type SpecSchemaGeneric = Record<string, unknown>;
115
+ type SpecSchemaGeneric = Record<string, unknown> & Partial<JSONSchemaExtensions>;
116
116
  type SpecSchema = string | SpecSchemaPrimitive | SpecSchemaComposite | SpecSchemaCombinator | SpecSchemaRef | SpecSchemaFallback | SpecSchemaGeneric;
117
117
  type SpecExampleLanguage = "ts" | "js" | "tsx" | "jsx" | "shell" | "json";
118
118
  type SpecExample = {
@@ -140,6 +140,8 @@ type SpecTypeParameter = {
140
140
  name: string;
141
141
  constraint?: string;
142
142
  default?: string;
143
+ variance?: "in" | "out" | "inout";
144
+ const?: boolean;
143
145
  };
144
146
  type SpecSignatureParameter = {
145
147
  name: string;
@@ -158,11 +160,79 @@ type SpecSignature = {
158
160
  parameters?: SpecSignatureParameter[];
159
161
  returns?: SpecSignatureReturn;
160
162
  description?: string;
163
+ tags?: SpecTag[];
164
+ examples?: SpecExample[];
161
165
  typeParameters?: SpecTypeParameter[];
162
166
  overloadIndex?: number;
163
167
  isImplementation?: boolean;
164
168
  throws?: SpecThrows[];
165
169
  };
170
+ /**
171
+ * Type predicate information for type guard functions.
172
+ * Preserved in x-ts-type-predicate extension.
173
+ */
174
+ type SpecTypePredicate = {
175
+ /** The parameter name that the type guard narrows */
176
+ parameterName: string;
177
+ /** The type that the parameter is narrowed to */
178
+ type: SpecSchema;
179
+ };
180
+ /**
181
+ * JSON Schema extension fields for TypeScript-specific type information.
182
+ *
183
+ * These extensions use the `x-` prefix which is valid JSON Schema for vendor extensions.
184
+ * They allow consumers to preserve TypeScript-specific information while still having
185
+ * valid JSON Schema. The extensions are optional - a consumer can ignore them for pure
186
+ * JSON Schema usage.
187
+ *
188
+ * Extension semantics:
189
+ * | Extension | Purpose |
190
+ * |----------------------|----------------------------------------------------------------------|
191
+ * | `x-ts-type` | Preserves original TS type for types that map to JSON Schema but |
192
+ * | | lose fidelity (bigint → integer, symbol → string) |
193
+ * | `x-ts-function` | Marks a schema as representing a function type |
194
+ * | `x-ts-signatures` | Contains function/method signatures for callable types |
195
+ * | `x-ts-type-arguments`| Preserves generic type arguments for parameterized types |
196
+ * | `x-ts-type-predicate`| Preserves type guard narrowing information |
197
+ * | `x-ts-package` | Package name for external type references |
198
+ */
199
+ type JSONSchemaExtensions = {
200
+ /**
201
+ * Preserves the original TypeScript type when mapping to JSON Schema loses fidelity.
202
+ * Examples:
203
+ * - bigint → { type: "integer", "x-ts-type": "bigint" }
204
+ * - symbol → { type: "string", "x-ts-type": "symbol" }
205
+ * - void → { type: "null", "x-ts-type": "void" } (optionally)
206
+ * - never, any, unknown, undefined also supported
207
+ */
208
+ "x-ts-type"?: "bigint" | "symbol" | "void" | "never" | "any" | "unknown" | "undefined" | string;
209
+ /**
210
+ * Marks a schema as representing a function type.
211
+ * When true, the schema represents a callable TypeScript function.
212
+ */
213
+ "x-ts-function"?: boolean;
214
+ /**
215
+ * Contains function/method signatures for callable types.
216
+ * Used in conjunction with `x-ts-function` to preserve full signature information.
217
+ */
218
+ "x-ts-signatures"?: SpecSignature[];
219
+ /**
220
+ * Preserves generic type arguments for parameterized types.
221
+ * Used with $ref to maintain generic instantiation information.
222
+ * Example: Map<string, number> → { "$ref": "#/$defs/Map", "x-ts-type-arguments": [...] }
223
+ */
224
+ "x-ts-type-arguments"?: SpecSchema[];
225
+ /**
226
+ * Preserves type guard narrowing information for type predicate functions.
227
+ * Example: (value: unknown) => value is string → { "x-ts-type-predicate": { parameterName: "value", type: { type: "string" } } }
228
+ */
229
+ "x-ts-type-predicate"?: SpecTypePredicate;
230
+ /**
231
+ * Package name for external type references from node_modules.
232
+ * Example: AnyRouter from @trpc/server → { "$ref": "#/types/AnyRouter", "x-ts-package": "@trpc/server" }
233
+ */
234
+ "x-ts-package"?: string;
235
+ };
166
236
  type SpecMember = {
167
237
  id?: string;
168
238
  name?: string;
@@ -175,6 +245,10 @@ type SpecMember = {
175
245
  signatures?: SpecSignature[];
176
246
  decorators?: SpecDecorator[];
177
247
  };
248
+ type SpecInheritedMember = SpecMember & {
249
+ /** Name of the class this member was inherited from */
250
+ inheritedFrom: string;
251
+ };
178
252
  type SpecExportKind = "function" | "class" | "variable" | "interface" | "type" | "enum" | "module" | "namespace" | "reference" | "external";
179
253
  type SpecTypeKind = "class" | "interface" | "type" | "enum" | "external";
180
254
  type SpecExport = {
@@ -447,4 +521,4 @@ declare function assertSpec(spec: unknown, version?: SchemaVersion): asserts spe
447
521
  * @returns Array of validation errors (empty if valid)
448
522
  */
449
523
  declare function getValidationErrors(spec: unknown, version?: SchemaVersion): SpecError[];
450
- export { validateSpec, recommendSemverBump, normalize, getValidationErrors, getAvailableVersions, diffSpec, dereference, categorizeBreakingChanges, calculateNextVersion, assertSpec, SpecVisibility, SpecTypeParameter, SpecTypeKind, SpecTypeAliasKind, SpecType, SpecThrows, SpecTagParam, SpecTag, SpecSource, SpecSignatureReturn, SpecSignatureParameter, SpecSignature, SpecSchemaRef, SpecSchemaPrimitive, SpecSchemaGeneric, SpecSchemaFallback, SpecSchemaComposite, SpecSchemaCombinator, SpecSchema, SpecPresentationMeta, SpecMember, SpecMappedType, SpecGenerationMeta, SpecGenerationInfo, SpecExtensions, SpecExtension, SpecExportKind, SpecExport, SpecExampleLanguage, SpecExample, SpecDiff, SpecDecorator, SpecConditionalType, SemverRecommendation, SemverBump, SCHEMA_VERSION, SCHEMA_URL, OpenPkgVersion, OpenPkgMeta, OpenPkg, MemberChangeInfo, JSON_SCHEMA_DRAFT, GenerationIssueSeverity, GenerationIssue, EntryPointDetectionMethod, CategorizedBreaking, BreakingSeverity };
524
+ export { validateSpec, recommendSemverBump, normalize, getValidationErrors, getAvailableVersions, diffSpec, dereference, categorizeBreakingChanges, calculateNextVersion, assertSpec, SpecVisibility, SpecTypePredicate, SpecTypeParameter, SpecTypeKind, SpecTypeAliasKind, SpecType, SpecThrows, SpecTagParam, SpecTag, SpecSource, SpecSignatureReturn, SpecSignatureParameter, SpecSignature, SpecSchemaRef, SpecSchemaPrimitive, SpecSchemaGeneric, SpecSchemaFallback, SpecSchemaComposite, SpecSchemaCombinator, SpecSchema, SpecPresentationMeta, SpecMember, SpecMappedType, SpecInheritedMember, SpecGenerationMeta, SpecGenerationInfo, 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, CategorizedBreaking, BreakingSeverity };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/spec",
3
- "version": "0.19.0",
3
+ "version": "0.24.0",
4
4
  "description": "Shared schema, validation, and diff utilities for OpenPkg specs",
5
5
  "keywords": [
6
6
  "openpkg",