@openpkg-ts/spec 0.1.0 → 0.2.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ryan Waits
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,66 +1,33 @@
1
1
  # @openpkg-ts/spec
2
2
 
3
- Shared contract for the OpenPkg specification, including versioned JSON Schema files, TypeScript types, validation helpers, and diff utilities. The package is still under construction; functionality will be filled in as the spec is extracted from the CLI and SDK.
4
-
5
- ## Development
3
+ Canonical schema, TypeScript types, validation, normalization, deref, diff, and migration helpers for OpenPkg specs.
6
4
 
5
+ ## Install
7
6
  ```bash
8
- bun install
9
- bun run build
7
+ npm install @openpkg-ts/spec
10
8
  ```
11
9
 
12
- The build compiles ESM output and type declarations under `dist/`. Schemas are published verbatim from the `schemas/` directory.
13
-
14
-
15
- ## Usage Examples
16
-
17
- ### Validate & Normalize a Generated Spec
10
+ ## Quick Helpers
18
11
  ```ts
19
- import { readFile } from 'node:fs/promises';
20
12
  import { normalize, validateSpec } from '@openpkg-ts/spec';
21
13
 
22
- const raw = await readFile('openpkg.json', 'utf8');
23
- const spec = JSON.parse(raw);
24
14
  const normalized = normalize(spec);
25
-
26
15
  const result = validateSpec(normalized);
27
16
  if (!result.ok) {
28
- for (const err of result.errors) {
29
- console.error(`schema: ${err.instancePath || '/'} ${err.message}`);
30
- }
31
- process.exit(1);
17
+ throw new Error(result.errors.map((e) => `${e.instancePath || '/'} ${e.message}`).join('\n'));
32
18
  }
33
-
34
- console.log('✅ spec is valid and normalized');
35
19
  ```
36
20
 
37
- ### Diff Two Spec Snapshots
38
21
  ```ts
39
- import { readFile } from 'node:fs/promises';
40
- import { dereference, diffSpec, normalize } from '@openpkg-ts/spec';
22
+ import { dereference, diffSpec } from '@openpkg-ts/spec';
41
23
 
42
- const [currentPath, nextPath] = process.argv.slice(2);
43
- const load = async (file: string) =>
44
- dereference(normalize(JSON.parse(await readFile(file, 'utf8'))));
45
-
46
- const current = await load(currentPath);
47
- const next = await load(nextPath);
48
- const diff = diffSpec(current, next);
49
-
50
- console.log('Breaking changes:', diff.breaking);
51
- console.log('Non-breaking changes:', diff.nonBreaking);
52
- console.log('Docs-only changes:', diff.docsOnly);
24
+ const left = dereference(specA);
25
+ const right = dereference(specB);
26
+ const diff = diffSpec(left, right);
53
27
  ```
54
28
 
55
- ### Assert Valid Specs in Tests
56
- ```ts
57
- import { expect, test } from 'bun:test';
58
- import { normalize, validateSpec } from '@openpkg-ts/spec';
59
- import spec from '../openpkg.json' assert { type: 'json' };
29
+ ## See Also
30
+ - [SDK generator](../sdk/README.md)
31
+ - [CLI usage](../cli/README.md)
60
32
 
61
- test('generated spec stays schema-valid', () => {
62
- const normalized = normalize(spec);
63
- const result = validateSpec(normalized);
64
- expect(result.ok).toBe(true);
65
- });
66
- ```
33
+ MIT License
package/dist/index.d.ts CHANGED
@@ -1,99 +1,148 @@
1
- declare const SCHEMA_VERSION = "0.1.0";
2
- declare const SCHEMA_URL = "https://unpkg.com/@openpkg-ts/spec/schemas/v0.1.0/openpkg.schema.json";
1
+ declare const SCHEMA_VERSION = "0.2.0";
2
+ declare const SCHEMA_URL = "https://unpkg.com/@openpkg-ts/spec/schemas/v0.2.0/openpkg.schema.json";
3
3
  declare const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
4
4
  type SpecTag = {
5
- name: string
6
- text: string
5
+ name: string;
6
+ text: string;
7
7
  };
8
8
  type SpecSource = {
9
- file?: string
10
- line?: number
11
- url?: string
9
+ file?: string;
10
+ line?: number;
11
+ url?: string;
12
12
  };
13
13
  type SpecSchema = unknown;
14
14
  type SpecExample = Record<string, unknown>;
15
15
  type SpecExtension = Record<string, unknown>;
16
+ type SpecDocSignal = "description" | "params" | "returns" | "examples";
17
+ type SpecDocDrift = {
18
+ type: "param-mismatch" | "param-type-mismatch" | "return-type-mismatch" | "generic-constraint-mismatch" | "optionality-mismatch" | "deprecated-mismatch" | "visibility-mismatch" | "example-drift" | "broken-link";
19
+ target?: string;
20
+ issue: string;
21
+ suggestion?: string;
22
+ };
23
+ type SpecVisibility = "public" | "protected" | "private";
24
+ type SpecDocsMetadata = {
25
+ coverageScore?: number;
26
+ missing?: SpecDocSignal[];
27
+ drift?: SpecDocDrift[];
28
+ };
29
+ type SpecTypeParameter = {
30
+ name: string;
31
+ constraint?: string;
32
+ default?: string;
33
+ };
16
34
  type SpecSignatureParameter = {
17
- name: string
18
- required?: boolean
19
- description?: string
20
- schema: SpecSchema
35
+ name: string;
36
+ required?: boolean;
37
+ description?: string;
38
+ schema: SpecSchema;
21
39
  };
22
40
  type SpecSignatureReturn = {
23
- schema: SpecSchema
24
- description?: string
41
+ schema: SpecSchema;
42
+ description?: string;
43
+ tsType?: string;
25
44
  };
26
45
  type SpecSignature = {
27
- parameters?: SpecSignatureParameter[]
28
- returns?: SpecSignatureReturn
29
- description?: string
46
+ parameters?: SpecSignatureParameter[];
47
+ returns?: SpecSignatureReturn;
48
+ description?: string;
49
+ typeParameters?: SpecTypeParameter[];
50
+ };
51
+ type SpecMember = {
52
+ id?: string;
53
+ name?: string;
54
+ kind?: string;
55
+ description?: string;
56
+ tags?: SpecTag[];
57
+ visibility?: SpecVisibility;
58
+ flags?: Record<string, unknown>;
59
+ schema?: SpecSchema;
60
+ signatures?: SpecSignature[];
30
61
  };
31
- type SpecMember = unknown;
32
62
  type SpecExportKind = "function" | "class" | "variable" | "interface" | "type" | "enum" | "module" | "namespace" | "reference";
33
63
  type SpecTypeKind = "class" | "interface" | "type" | "enum";
34
64
  type SpecExport = {
35
- id: string
36
- name: string
37
- kind: SpecExportKind
38
- signatures?: SpecSignature[]
39
- members?: SpecMember[]
40
- type?: string | SpecSchema
41
- schema?: SpecSchema
42
- description?: string
43
- examples?: string[]
44
- source?: SpecSource
45
- flags?: Record<string, unknown>
46
- tags?: SpecTag[]
65
+ id: string;
66
+ name: string;
67
+ slug?: string;
68
+ displayName?: string;
69
+ category?: string;
70
+ importPath?: string;
71
+ kind: SpecExportKind;
72
+ signatures?: SpecSignature[];
73
+ typeParameters?: SpecTypeParameter[];
74
+ members?: SpecMember[];
75
+ type?: string | SpecSchema;
76
+ schema?: SpecSchema;
77
+ description?: string;
78
+ examples?: string[];
79
+ docs?: SpecDocsMetadata;
80
+ source?: SpecSource;
81
+ deprecated?: boolean;
82
+ flags?: Record<string, unknown>;
83
+ tags?: SpecTag[];
47
84
  };
48
85
  type SpecType = {
49
- id: string
50
- name: string
51
- kind: SpecTypeKind
52
- description?: string
53
- schema?: SpecSchema
54
- type?: string | SpecSchema
55
- members?: SpecMember[]
56
- source?: SpecSource
57
- tags?: SpecTag[]
58
- rawComments?: string
86
+ id: string;
87
+ name: string;
88
+ slug?: string;
89
+ displayName?: string;
90
+ category?: string;
91
+ importPath?: string;
92
+ kind: SpecTypeKind;
93
+ description?: string;
94
+ schema?: SpecSchema;
95
+ type?: string | SpecSchema;
96
+ members?: SpecMember[];
97
+ source?: SpecSource;
98
+ tags?: SpecTag[];
99
+ rawComments?: string;
59
100
  };
60
101
  type OpenPkgMeta = {
61
- name: string
62
- version?: string
63
- description?: string
64
- license?: string
65
- repository?: string
66
- ecosystem?: string
102
+ name: string;
103
+ version?: string;
104
+ description?: string;
105
+ license?: string;
106
+ repository?: string;
107
+ ecosystem?: string;
67
108
  };
68
109
  type OpenPkg = {
69
- $schema?: string
70
- openpkg: "0.1.0"
71
- meta: OpenPkgMeta
72
- exports: SpecExport[]
73
- types?: SpecType[]
74
- examples?: SpecExample[]
75
- extensions?: SpecExtension
110
+ $schema?: string;
111
+ openpkg: "0.2.0";
112
+ meta: OpenPkgMeta;
113
+ exports: SpecExport[];
114
+ types?: SpecType[];
115
+ examples?: SpecExample[];
116
+ docs?: SpecDocsMetadata;
117
+ extensions?: SpecExtension;
118
+ };
119
+ declare function dereference(spec: OpenPkg): OpenPkg;
120
+ type SpecDiff = {
121
+ breaking: string[];
122
+ nonBreaking: string[];
123
+ docsOnly: string[];
124
+ coverageDelta: number;
125
+ oldCoverage: number;
126
+ newCoverage: number;
127
+ newUndocumented: string[];
128
+ improvedExports: string[];
129
+ regressedExports: string[];
130
+ driftIntroduced: number;
131
+ driftResolved: number;
76
132
  };
133
+ declare function diffSpec(oldSpec: OpenPkg, newSpec: OpenPkg): SpecDiff;
134
+ declare function normalize(spec: OpenPkg): OpenPkg;
77
135
  type SpecError = {
78
- instancePath: string
79
- message: string
80
- keyword: string
136
+ instancePath: string;
137
+ message: string;
138
+ keyword: string;
81
139
  };
82
140
  declare function validateSpec(spec: unknown): {
83
- ok: true
141
+ ok: true;
84
142
  } | {
85
- ok: false
86
- errors: SpecError[]
143
+ ok: false;
144
+ errors: SpecError[];
87
145
  };
88
146
  declare function assertSpec(spec: unknown): asserts spec is OpenPkg;
89
147
  declare function getValidationErrors(spec: unknown): SpecError[];
90
- declare function normalize(spec: OpenPkg): OpenPkg;
91
- declare function dereference(spec: OpenPkg): OpenPkg;
92
- declare function migrate_0_1_0__to__0_2_0(spec: OpenPkg): OpenPkg;
93
- type SpecDiff = {
94
- breaking: string[]
95
- nonBreaking: string[]
96
- docsOnly: string[]
97
- };
98
- declare function diffSpec(a: OpenPkg, b: OpenPkg): SpecDiff;
99
- export { validateSpec, normalize, migrate_0_1_0__to__0_2_0 as migrate, getValidationErrors, diffSpec, dereference, assertSpec, SpecTypeKind, SpecType, SpecTag, SpecSource, SpecSignatureReturn, SpecSignatureParameter, SpecSignature, SpecSchema, SpecMember, SpecExtension, SpecExportKind, SpecExport, SpecExample, SCHEMA_VERSION, SCHEMA_URL, OpenPkgMeta, OpenPkg, JSON_SCHEMA_DRAFT };
148
+ export { validateSpec, normalize, getValidationErrors, diffSpec, dereference, assertSpec, SpecVisibility, SpecTypeParameter, SpecTypeKind, SpecType, SpecTag, SpecSource, SpecSignatureReturn, SpecSignatureParameter, SpecSignature, SpecSchema, SpecMember, SpecExtension, SpecExportKind, SpecExport, SpecExample, SpecDocsMetadata, SpecDocSignal, SpecDocDrift, SCHEMA_VERSION, SCHEMA_URL, OpenPkgMeta, OpenPkg, JSON_SCHEMA_DRAFT };