@unispechq/unispec-core 0.1.0 → 0.1.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/.github/workflows/npm-publish.yml +74 -74
- package/.windsurfrules +138 -138
- package/README.md +223 -223
- package/package.json +28 -28
- package/scripts/release.js +51 -51
- package/src/converters/index.ts +120 -120
- package/src/diff/index.ts +235 -235
- package/src/index.ts +6 -6
- package/src/loader/index.ts +25 -25
- package/src/normalizer/index.ts +156 -156
- package/src/types/index.ts +67 -67
- package/src/validator/index.ts +61 -61
- package/tests/converters.test.mjs +126 -126
- package/tests/diff.test.mjs +240 -240
- package/tests/loader-validator.test.mjs +19 -19
- package/tests/normalizer.test.mjs +115 -115
- package/tsconfig.json +15 -15
- package/dist/converters/index.d.ts +0 -13
- package/dist/converters/index.js +0 -89
- package/dist/diff/index.d.ts +0 -21
- package/dist/diff/index.js +0 -195
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -6
- package/dist/loader/index.d.ts +0 -13
- package/dist/loader/index.js +0 -19
- package/dist/normalizer/index.d.ts +0 -11
- package/dist/normalizer/index.js +0 -116
- package/dist/types/index.d.ts +0 -57
- package/dist/types/index.js +0 -1
- package/dist/validator/index.d.ts +0 -7
- package/dist/validator/index.js +0 -47
package/src/diff/index.ts
CHANGED
|
@@ -1,235 +1,235 @@
|
|
|
1
|
-
import { UniSpecDocument } from "../types";
|
|
2
|
-
|
|
3
|
-
export type ChangeSeverity = "breaking" | "non-breaking" | "unknown";
|
|
4
|
-
|
|
5
|
-
export interface UniSpecChange {
|
|
6
|
-
path: string;
|
|
7
|
-
description: string;
|
|
8
|
-
severity: ChangeSeverity;
|
|
9
|
-
protocol?: "rest" | "graphql" | "websocket";
|
|
10
|
-
kind?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface DiffResult {
|
|
14
|
-
changes: UniSpecChange[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
18
|
-
return Object.prototype.toString.call(value) === "[object Object]";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function diffValues(oldVal: unknown, newVal: unknown, basePath: string, out: UniSpecChange[]): void {
|
|
22
|
-
if (oldVal === newVal) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Both plain objects → recurse by keys
|
|
27
|
-
if (isPlainObject(oldVal) && isPlainObject(newVal)) {
|
|
28
|
-
const oldKeys = new Set(Object.keys(oldVal));
|
|
29
|
-
const newKeys = new Set(Object.keys(newVal));
|
|
30
|
-
|
|
31
|
-
// Removed keys
|
|
32
|
-
for (const key of oldKeys) {
|
|
33
|
-
if (!newKeys.has(key)) {
|
|
34
|
-
out.push({
|
|
35
|
-
path: `${basePath}/${key}`,
|
|
36
|
-
description: "Field removed",
|
|
37
|
-
severity: "unknown",
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Added / changed keys
|
|
43
|
-
for (const key of newKeys) {
|
|
44
|
-
const childPath = `${basePath}/${key}`;
|
|
45
|
-
if (!oldKeys.has(key)) {
|
|
46
|
-
out.push({
|
|
47
|
-
path: childPath,
|
|
48
|
-
description: "Field added",
|
|
49
|
-
severity: "unknown",
|
|
50
|
-
});
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
diffValues((oldVal as Record<string, unknown>)[key], (newVal as Record<string, unknown>)[key], childPath, out);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Arrays → shallow compare by index for now
|
|
61
|
-
if (Array.isArray(oldVal) && Array.isArray(newVal)) {
|
|
62
|
-
const maxLen = Math.max(oldVal.length, newVal.length);
|
|
63
|
-
for (let i = 0; i < maxLen; i++) {
|
|
64
|
-
const childPath = `${basePath}/${i}`;
|
|
65
|
-
if (i >= oldVal.length) {
|
|
66
|
-
out.push({
|
|
67
|
-
path: childPath,
|
|
68
|
-
description: "Item added",
|
|
69
|
-
severity: "unknown",
|
|
70
|
-
});
|
|
71
|
-
} else if (i >= newVal.length) {
|
|
72
|
-
out.push({
|
|
73
|
-
path: childPath,
|
|
74
|
-
description: "Item removed",
|
|
75
|
-
severity: "unknown",
|
|
76
|
-
});
|
|
77
|
-
} else {
|
|
78
|
-
diffValues(oldVal[i], newVal[i], childPath, out);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Primitive or mismatched types → treat as value change
|
|
85
|
-
out.push({
|
|
86
|
-
path: basePath,
|
|
87
|
-
description: "Value changed",
|
|
88
|
-
severity: "unknown",
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function annotateRestChange(change: UniSpecChange): UniSpecChange {
|
|
93
|
-
if (!change.path.startsWith("/service/protocols/rest/paths/")) {
|
|
94
|
-
return change;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const segments = change.path.split("/").filter(Boolean);
|
|
98
|
-
// Expected shape: ["service", "protocols", "rest", "paths", pathKey?, method?]
|
|
99
|
-
if (segments[0] !== "service" || segments[1] !== "protocols" || segments[2] !== "rest" || segments[3] !== "paths") {
|
|
100
|
-
return change;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const pathKey = segments[4];
|
|
104
|
-
const method = segments[5];
|
|
105
|
-
|
|
106
|
-
const httpMethods = new Set(["get", "head", "options", "post", "put", "patch", "delete"]);
|
|
107
|
-
|
|
108
|
-
const annotated: UniSpecChange = {
|
|
109
|
-
...change,
|
|
110
|
-
protocol: "rest",
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
if (change.description === "Field removed") {
|
|
114
|
-
if (pathKey && !method) {
|
|
115
|
-
annotated.kind = "rest.path.removed";
|
|
116
|
-
annotated.severity = "breaking";
|
|
117
|
-
} else if (pathKey && method && httpMethods.has(method)) {
|
|
118
|
-
annotated.kind = "rest.operation.removed";
|
|
119
|
-
annotated.severity = "breaking";
|
|
120
|
-
}
|
|
121
|
-
} else if (change.description === "Field added") {
|
|
122
|
-
if (pathKey && !method) {
|
|
123
|
-
annotated.kind = "rest.path.added";
|
|
124
|
-
annotated.severity = "non-breaking";
|
|
125
|
-
} else if (pathKey && method && httpMethods.has(method)) {
|
|
126
|
-
annotated.kind = "rest.operation.added";
|
|
127
|
-
annotated.severity = "non-breaking";
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return annotated;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function annotateWebSocketChange(change: UniSpecChange): UniSpecChange {
|
|
135
|
-
if (!change.path.startsWith("/service/protocols/websocket/channels/")) {
|
|
136
|
-
return change;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const segments = change.path.split("/").filter(Boolean);
|
|
140
|
-
// Expected: ["service","protocols","websocket","channels", channelName, ...]
|
|
141
|
-
if (segments[0] !== "service" || segments[1] !== "protocols" || segments[2] !== "websocket" || segments[3] !== "channels") {
|
|
142
|
-
return change;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
const channelName = segments[4];
|
|
146
|
-
const next = segments[5];
|
|
147
|
-
|
|
148
|
-
const annotated: UniSpecChange = {
|
|
149
|
-
...change,
|
|
150
|
-
protocol: "websocket",
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
if (!channelName) {
|
|
154
|
-
return annotated;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Channel-level changes
|
|
158
|
-
if (!next) {
|
|
159
|
-
if (change.description === "Field removed") {
|
|
160
|
-
annotated.kind = "websocket.channel.removed";
|
|
161
|
-
annotated.severity = "breaking";
|
|
162
|
-
} else if (change.description === "Field added") {
|
|
163
|
-
annotated.kind = "websocket.channel.added";
|
|
164
|
-
annotated.severity = "non-breaking";
|
|
165
|
-
}
|
|
166
|
-
return annotated;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Message-level changes (channels/{channelName}/messages/{index})
|
|
170
|
-
if (next === "messages") {
|
|
171
|
-
const index = segments[6];
|
|
172
|
-
if (typeof index === "undefined") {
|
|
173
|
-
return annotated;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (change.description === "Item removed") {
|
|
177
|
-
annotated.kind = "websocket.message.removed";
|
|
178
|
-
annotated.severity = "breaking";
|
|
179
|
-
} else if (change.description === "Item added") {
|
|
180
|
-
annotated.kind = "websocket.message.added";
|
|
181
|
-
annotated.severity = "non-breaking";
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return annotated;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function annotateGraphQLChange(change: UniSpecChange): UniSpecChange {
|
|
189
|
-
if (!change.path.startsWith("/service/protocols/graphql/operations/")) {
|
|
190
|
-
return change;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const segments = change.path.split("/").filter(Boolean);
|
|
194
|
-
// Expected: ["service","protocols","graphql","operations", kind, opName?]
|
|
195
|
-
if (segments[0] !== "service" || segments[1] !== "protocols" || segments[2] !== "graphql" || segments[3] !== "operations") {
|
|
196
|
-
return change;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const opKind = segments[4];
|
|
200
|
-
const opName = segments[5];
|
|
201
|
-
|
|
202
|
-
if (!opKind || !opName) {
|
|
203
|
-
return change;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const annotated: UniSpecChange = {
|
|
207
|
-
...change,
|
|
208
|
-
protocol: "graphql",
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
if (change.description === "Field removed") {
|
|
212
|
-
annotated.kind = "graphql.operation.removed";
|
|
213
|
-
annotated.severity = "breaking";
|
|
214
|
-
} else if (change.description === "Field added") {
|
|
215
|
-
annotated.kind = "graphql.operation.added";
|
|
216
|
-
annotated.severity = "non-breaking";
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return annotated;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Compute a structural diff between two UniSpec documents.
|
|
224
|
-
*
|
|
225
|
-
* Current behavior:
|
|
226
|
-
* - Tracks added, removed, and changed fields and array items.
|
|
227
|
-
* - Uses JSON Pointer-like paths rooted at "" (e.g., "/info/title").
|
|
228
|
-
* - Marks all changes with severity "unknown" for now.
|
|
229
|
-
*/
|
|
230
|
-
export function diffUniSpec(oldDoc: UniSpecDocument, newDoc: UniSpecDocument): DiffResult {
|
|
231
|
-
const changes: UniSpecChange[] = [];
|
|
232
|
-
diffValues(oldDoc, newDoc, "", changes);
|
|
233
|
-
const annotated = changes.map((change) => annotateWebSocketChange(annotateGraphQLChange(annotateRestChange(change))));
|
|
234
|
-
return { changes: annotated };
|
|
235
|
-
}
|
|
1
|
+
import { UniSpecDocument } from "../types";
|
|
2
|
+
|
|
3
|
+
export type ChangeSeverity = "breaking" | "non-breaking" | "unknown";
|
|
4
|
+
|
|
5
|
+
export interface UniSpecChange {
|
|
6
|
+
path: string;
|
|
7
|
+
description: string;
|
|
8
|
+
severity: ChangeSeverity;
|
|
9
|
+
protocol?: "rest" | "graphql" | "websocket";
|
|
10
|
+
kind?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface DiffResult {
|
|
14
|
+
changes: UniSpecChange[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
18
|
+
return Object.prototype.toString.call(value) === "[object Object]";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function diffValues(oldVal: unknown, newVal: unknown, basePath: string, out: UniSpecChange[]): void {
|
|
22
|
+
if (oldVal === newVal) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Both plain objects → recurse by keys
|
|
27
|
+
if (isPlainObject(oldVal) && isPlainObject(newVal)) {
|
|
28
|
+
const oldKeys = new Set(Object.keys(oldVal));
|
|
29
|
+
const newKeys = new Set(Object.keys(newVal));
|
|
30
|
+
|
|
31
|
+
// Removed keys
|
|
32
|
+
for (const key of oldKeys) {
|
|
33
|
+
if (!newKeys.has(key)) {
|
|
34
|
+
out.push({
|
|
35
|
+
path: `${basePath}/${key}`,
|
|
36
|
+
description: "Field removed",
|
|
37
|
+
severity: "unknown",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Added / changed keys
|
|
43
|
+
for (const key of newKeys) {
|
|
44
|
+
const childPath = `${basePath}/${key}`;
|
|
45
|
+
if (!oldKeys.has(key)) {
|
|
46
|
+
out.push({
|
|
47
|
+
path: childPath,
|
|
48
|
+
description: "Field added",
|
|
49
|
+
severity: "unknown",
|
|
50
|
+
});
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
diffValues((oldVal as Record<string, unknown>)[key], (newVal as Record<string, unknown>)[key], childPath, out);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Arrays → shallow compare by index for now
|
|
61
|
+
if (Array.isArray(oldVal) && Array.isArray(newVal)) {
|
|
62
|
+
const maxLen = Math.max(oldVal.length, newVal.length);
|
|
63
|
+
for (let i = 0; i < maxLen; i++) {
|
|
64
|
+
const childPath = `${basePath}/${i}`;
|
|
65
|
+
if (i >= oldVal.length) {
|
|
66
|
+
out.push({
|
|
67
|
+
path: childPath,
|
|
68
|
+
description: "Item added",
|
|
69
|
+
severity: "unknown",
|
|
70
|
+
});
|
|
71
|
+
} else if (i >= newVal.length) {
|
|
72
|
+
out.push({
|
|
73
|
+
path: childPath,
|
|
74
|
+
description: "Item removed",
|
|
75
|
+
severity: "unknown",
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
diffValues(oldVal[i], newVal[i], childPath, out);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Primitive or mismatched types → treat as value change
|
|
85
|
+
out.push({
|
|
86
|
+
path: basePath,
|
|
87
|
+
description: "Value changed",
|
|
88
|
+
severity: "unknown",
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function annotateRestChange(change: UniSpecChange): UniSpecChange {
|
|
93
|
+
if (!change.path.startsWith("/service/protocols/rest/paths/")) {
|
|
94
|
+
return change;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const segments = change.path.split("/").filter(Boolean);
|
|
98
|
+
// Expected shape: ["service", "protocols", "rest", "paths", pathKey?, method?]
|
|
99
|
+
if (segments[0] !== "service" || segments[1] !== "protocols" || segments[2] !== "rest" || segments[3] !== "paths") {
|
|
100
|
+
return change;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const pathKey = segments[4];
|
|
104
|
+
const method = segments[5];
|
|
105
|
+
|
|
106
|
+
const httpMethods = new Set(["get", "head", "options", "post", "put", "patch", "delete"]);
|
|
107
|
+
|
|
108
|
+
const annotated: UniSpecChange = {
|
|
109
|
+
...change,
|
|
110
|
+
protocol: "rest",
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
if (change.description === "Field removed") {
|
|
114
|
+
if (pathKey && !method) {
|
|
115
|
+
annotated.kind = "rest.path.removed";
|
|
116
|
+
annotated.severity = "breaking";
|
|
117
|
+
} else if (pathKey && method && httpMethods.has(method)) {
|
|
118
|
+
annotated.kind = "rest.operation.removed";
|
|
119
|
+
annotated.severity = "breaking";
|
|
120
|
+
}
|
|
121
|
+
} else if (change.description === "Field added") {
|
|
122
|
+
if (pathKey && !method) {
|
|
123
|
+
annotated.kind = "rest.path.added";
|
|
124
|
+
annotated.severity = "non-breaking";
|
|
125
|
+
} else if (pathKey && method && httpMethods.has(method)) {
|
|
126
|
+
annotated.kind = "rest.operation.added";
|
|
127
|
+
annotated.severity = "non-breaking";
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return annotated;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function annotateWebSocketChange(change: UniSpecChange): UniSpecChange {
|
|
135
|
+
if (!change.path.startsWith("/service/protocols/websocket/channels/")) {
|
|
136
|
+
return change;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const segments = change.path.split("/").filter(Boolean);
|
|
140
|
+
// Expected: ["service","protocols","websocket","channels", channelName, ...]
|
|
141
|
+
if (segments[0] !== "service" || segments[1] !== "protocols" || segments[2] !== "websocket" || segments[3] !== "channels") {
|
|
142
|
+
return change;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const channelName = segments[4];
|
|
146
|
+
const next = segments[5];
|
|
147
|
+
|
|
148
|
+
const annotated: UniSpecChange = {
|
|
149
|
+
...change,
|
|
150
|
+
protocol: "websocket",
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
if (!channelName) {
|
|
154
|
+
return annotated;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Channel-level changes
|
|
158
|
+
if (!next) {
|
|
159
|
+
if (change.description === "Field removed") {
|
|
160
|
+
annotated.kind = "websocket.channel.removed";
|
|
161
|
+
annotated.severity = "breaking";
|
|
162
|
+
} else if (change.description === "Field added") {
|
|
163
|
+
annotated.kind = "websocket.channel.added";
|
|
164
|
+
annotated.severity = "non-breaking";
|
|
165
|
+
}
|
|
166
|
+
return annotated;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Message-level changes (channels/{channelName}/messages/{index})
|
|
170
|
+
if (next === "messages") {
|
|
171
|
+
const index = segments[6];
|
|
172
|
+
if (typeof index === "undefined") {
|
|
173
|
+
return annotated;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (change.description === "Item removed") {
|
|
177
|
+
annotated.kind = "websocket.message.removed";
|
|
178
|
+
annotated.severity = "breaking";
|
|
179
|
+
} else if (change.description === "Item added") {
|
|
180
|
+
annotated.kind = "websocket.message.added";
|
|
181
|
+
annotated.severity = "non-breaking";
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return annotated;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function annotateGraphQLChange(change: UniSpecChange): UniSpecChange {
|
|
189
|
+
if (!change.path.startsWith("/service/protocols/graphql/operations/")) {
|
|
190
|
+
return change;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const segments = change.path.split("/").filter(Boolean);
|
|
194
|
+
// Expected: ["service","protocols","graphql","operations", kind, opName?]
|
|
195
|
+
if (segments[0] !== "service" || segments[1] !== "protocols" || segments[2] !== "graphql" || segments[3] !== "operations") {
|
|
196
|
+
return change;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const opKind = segments[4];
|
|
200
|
+
const opName = segments[5];
|
|
201
|
+
|
|
202
|
+
if (!opKind || !opName) {
|
|
203
|
+
return change;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const annotated: UniSpecChange = {
|
|
207
|
+
...change,
|
|
208
|
+
protocol: "graphql",
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
if (change.description === "Field removed") {
|
|
212
|
+
annotated.kind = "graphql.operation.removed";
|
|
213
|
+
annotated.severity = "breaking";
|
|
214
|
+
} else if (change.description === "Field added") {
|
|
215
|
+
annotated.kind = "graphql.operation.added";
|
|
216
|
+
annotated.severity = "non-breaking";
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return annotated;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Compute a structural diff between two UniSpec documents.
|
|
224
|
+
*
|
|
225
|
+
* Current behavior:
|
|
226
|
+
* - Tracks added, removed, and changed fields and array items.
|
|
227
|
+
* - Uses JSON Pointer-like paths rooted at "" (e.g., "/info/title").
|
|
228
|
+
* - Marks all changes with severity "unknown" for now.
|
|
229
|
+
*/
|
|
230
|
+
export function diffUniSpec(oldDoc: UniSpecDocument, newDoc: UniSpecDocument): DiffResult {
|
|
231
|
+
const changes: UniSpecChange[] = [];
|
|
232
|
+
diffValues(oldDoc, newDoc, "", changes);
|
|
233
|
+
const annotated = changes.map((change) => annotateWebSocketChange(annotateGraphQLChange(annotateRestChange(change))));
|
|
234
|
+
return { changes: annotated };
|
|
235
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./types/index.js";
|
|
2
|
-
export * from "./loader/index.js";
|
|
3
|
-
export * from "./validator/index.js";
|
|
4
|
-
export * from "./normalizer/index.js";
|
|
5
|
-
export * from "./diff/index.js";
|
|
6
|
-
export * from "./converters/index.js";
|
|
1
|
+
export * from "./types/index.js";
|
|
2
|
+
export * from "./loader/index.js";
|
|
3
|
+
export * from "./validator/index.js";
|
|
4
|
+
export * from "./normalizer/index.js";
|
|
5
|
+
export * from "./diff/index.js";
|
|
6
|
+
export * from "./converters/index.js";
|
package/src/loader/index.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { UniSpecDocument } from "../types";
|
|
2
|
-
|
|
3
|
-
export interface LoadOptions {
|
|
4
|
-
filename?: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Load a UniSpec document from a raw input value.
|
|
9
|
-
* Currently supports:
|
|
10
|
-
* - JavaScript objects (treated as already parsed UniSpec)
|
|
11
|
-
* - JSON strings
|
|
12
|
-
*
|
|
13
|
-
* YAML and filesystem helpers will be added later, keeping this API stable.
|
|
14
|
-
*/
|
|
15
|
-
export async function loadUniSpec(input: string | object, _options: LoadOptions = {}): Promise<UniSpecDocument> {
|
|
16
|
-
if (typeof input === "string") {
|
|
17
|
-
const trimmed = input.trim();
|
|
18
|
-
if (!trimmed) {
|
|
19
|
-
throw new Error("Cannot load UniSpec: input string is empty");
|
|
20
|
-
}
|
|
21
|
-
// For now we assume JSON; YAML support will be added later.
|
|
22
|
-
return JSON.parse(trimmed) as UniSpecDocument;
|
|
23
|
-
}
|
|
24
|
-
return input as UniSpecDocument;
|
|
25
|
-
}
|
|
1
|
+
import { UniSpecDocument } from "../types";
|
|
2
|
+
|
|
3
|
+
export interface LoadOptions {
|
|
4
|
+
filename?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Load a UniSpec document from a raw input value.
|
|
9
|
+
* Currently supports:
|
|
10
|
+
* - JavaScript objects (treated as already parsed UniSpec)
|
|
11
|
+
* - JSON strings
|
|
12
|
+
*
|
|
13
|
+
* YAML and filesystem helpers will be added later, keeping this API stable.
|
|
14
|
+
*/
|
|
15
|
+
export async function loadUniSpec(input: string | object, _options: LoadOptions = {}): Promise<UniSpecDocument> {
|
|
16
|
+
if (typeof input === "string") {
|
|
17
|
+
const trimmed = input.trim();
|
|
18
|
+
if (!trimmed) {
|
|
19
|
+
throw new Error("Cannot load UniSpec: input string is empty");
|
|
20
|
+
}
|
|
21
|
+
// For now we assume JSON; YAML support will be added later.
|
|
22
|
+
return JSON.parse(trimmed) as UniSpecDocument;
|
|
23
|
+
}
|
|
24
|
+
return input as UniSpecDocument;
|
|
25
|
+
}
|