@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
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import test from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
|
|
4
|
-
import * as core from "../dist/index.js";
|
|
5
|
-
|
|
6
|
-
const { normalizeUniSpec } = core;
|
|
7
|
-
|
|
8
|
-
test("normalizeUniSpec sorts object keys deterministically", () => {
|
|
9
|
-
const doc = {
|
|
10
|
-
b: 1,
|
|
11
|
-
a: {
|
|
12
|
-
d: 3,
|
|
13
|
-
c: 2,
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const normalized = normalizeUniSpec(doc);
|
|
18
|
-
|
|
19
|
-
assert.deepEqual(Object.keys(normalized), ["a", "b"]);
|
|
20
|
-
assert.deepEqual(Object.keys(normalized.a), ["c", "d"]);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test("normalizeUniSpec normalizes REST paths and HTTP methods order", () => {
|
|
24
|
-
const doc = {
|
|
25
|
-
unispecVersion: "0.1.0",
|
|
26
|
-
service: {
|
|
27
|
-
name: "test-service",
|
|
28
|
-
protocols: {
|
|
29
|
-
rest: {
|
|
30
|
-
paths: {
|
|
31
|
-
"/z": {
|
|
32
|
-
post: {},
|
|
33
|
-
get: {},
|
|
34
|
-
},
|
|
35
|
-
"/a": {
|
|
36
|
-
delete: {},
|
|
37
|
-
get: {},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const normalized = normalizeUniSpec(doc);
|
|
46
|
-
|
|
47
|
-
const paths = normalized.service.protocols.rest.paths;
|
|
48
|
-
|
|
49
|
-
assert.deepEqual(Object.keys(paths), ["/a", "/z"]);
|
|
50
|
-
assert.deepEqual(Object.keys(paths["/z"]), ["get", "post"]);
|
|
51
|
-
assert.deepEqual(Object.keys(paths["/a"]), ["get", "delete"]);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test("normalizeUniSpec normalizes GraphQL operations order", () => {
|
|
55
|
-
const doc = {
|
|
56
|
-
unispecVersion: "0.1.0",
|
|
57
|
-
service: {
|
|
58
|
-
name: "test-service",
|
|
59
|
-
protocols: {
|
|
60
|
-
graphql: {
|
|
61
|
-
operations: {
|
|
62
|
-
queries: {
|
|
63
|
-
me: {},
|
|
64
|
-
ping: {},
|
|
65
|
-
a: {},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const normalized = normalizeUniSpec(doc);
|
|
74
|
-
|
|
75
|
-
const queries = normalized.service.protocols.graphql.operations.queries;
|
|
76
|
-
assert.deepEqual(Object.keys(queries), ["a", "me", "ping"]);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("normalizeUniSpec normalizes WebSocket channels and messages order", () => {
|
|
80
|
-
const doc = {
|
|
81
|
-
unispecVersion: "0.1.0",
|
|
82
|
-
service: {
|
|
83
|
-
name: "test-service",
|
|
84
|
-
protocols: {
|
|
85
|
-
websocket: {
|
|
86
|
-
channels: {
|
|
87
|
-
zChannel: {
|
|
88
|
-
messages: [
|
|
89
|
-
{ name: "msgB" },
|
|
90
|
-
{ name: "msgA" },
|
|
91
|
-
],
|
|
92
|
-
},
|
|
93
|
-
aChannel: {
|
|
94
|
-
messages: [
|
|
95
|
-
{ name: "z" },
|
|
96
|
-
{ name: "a" },
|
|
97
|
-
],
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const normalized = normalizeUniSpec(doc);
|
|
106
|
-
|
|
107
|
-
const channels = normalized.service.protocols.websocket.channels;
|
|
108
|
-
assert.deepEqual(Object.keys(channels), ["aChannel", "zChannel"]);
|
|
109
|
-
|
|
110
|
-
const aMessages = channels.aChannel.messages;
|
|
111
|
-
const zMessages = channels.zChannel.messages;
|
|
112
|
-
|
|
113
|
-
assert.deepEqual(aMessages.map((m) => m.name), ["a", "z"]);
|
|
114
|
-
assert.deepEqual(zMessages.map((m) => m.name), ["msgA", "msgB"]);
|
|
115
|
-
});
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
|
|
4
|
+
import * as core from "../dist/index.js";
|
|
5
|
+
|
|
6
|
+
const { normalizeUniSpec } = core;
|
|
7
|
+
|
|
8
|
+
test("normalizeUniSpec sorts object keys deterministically", () => {
|
|
9
|
+
const doc = {
|
|
10
|
+
b: 1,
|
|
11
|
+
a: {
|
|
12
|
+
d: 3,
|
|
13
|
+
c: 2,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const normalized = normalizeUniSpec(doc);
|
|
18
|
+
|
|
19
|
+
assert.deepEqual(Object.keys(normalized), ["a", "b"]);
|
|
20
|
+
assert.deepEqual(Object.keys(normalized.a), ["c", "d"]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("normalizeUniSpec normalizes REST paths and HTTP methods order", () => {
|
|
24
|
+
const doc = {
|
|
25
|
+
unispecVersion: "0.1.0",
|
|
26
|
+
service: {
|
|
27
|
+
name: "test-service",
|
|
28
|
+
protocols: {
|
|
29
|
+
rest: {
|
|
30
|
+
paths: {
|
|
31
|
+
"/z": {
|
|
32
|
+
post: {},
|
|
33
|
+
get: {},
|
|
34
|
+
},
|
|
35
|
+
"/a": {
|
|
36
|
+
delete: {},
|
|
37
|
+
get: {},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const normalized = normalizeUniSpec(doc);
|
|
46
|
+
|
|
47
|
+
const paths = normalized.service.protocols.rest.paths;
|
|
48
|
+
|
|
49
|
+
assert.deepEqual(Object.keys(paths), ["/a", "/z"]);
|
|
50
|
+
assert.deepEqual(Object.keys(paths["/z"]), ["get", "post"]);
|
|
51
|
+
assert.deepEqual(Object.keys(paths["/a"]), ["get", "delete"]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("normalizeUniSpec normalizes GraphQL operations order", () => {
|
|
55
|
+
const doc = {
|
|
56
|
+
unispecVersion: "0.1.0",
|
|
57
|
+
service: {
|
|
58
|
+
name: "test-service",
|
|
59
|
+
protocols: {
|
|
60
|
+
graphql: {
|
|
61
|
+
operations: {
|
|
62
|
+
queries: {
|
|
63
|
+
me: {},
|
|
64
|
+
ping: {},
|
|
65
|
+
a: {},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const normalized = normalizeUniSpec(doc);
|
|
74
|
+
|
|
75
|
+
const queries = normalized.service.protocols.graphql.operations.queries;
|
|
76
|
+
assert.deepEqual(Object.keys(queries), ["a", "me", "ping"]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("normalizeUniSpec normalizes WebSocket channels and messages order", () => {
|
|
80
|
+
const doc = {
|
|
81
|
+
unispecVersion: "0.1.0",
|
|
82
|
+
service: {
|
|
83
|
+
name: "test-service",
|
|
84
|
+
protocols: {
|
|
85
|
+
websocket: {
|
|
86
|
+
channels: {
|
|
87
|
+
zChannel: {
|
|
88
|
+
messages: [
|
|
89
|
+
{ name: "msgB" },
|
|
90
|
+
{ name: "msgA" },
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
aChannel: {
|
|
94
|
+
messages: [
|
|
95
|
+
{ name: "z" },
|
|
96
|
+
{ name: "a" },
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const normalized = normalizeUniSpec(doc);
|
|
106
|
+
|
|
107
|
+
const channels = normalized.service.protocols.websocket.channels;
|
|
108
|
+
assert.deepEqual(Object.keys(channels), ["aChannel", "zChannel"]);
|
|
109
|
+
|
|
110
|
+
const aMessages = channels.aChannel.messages;
|
|
111
|
+
const zMessages = channels.zChannel.messages;
|
|
112
|
+
|
|
113
|
+
assert.deepEqual(aMessages.map((m) => m.name), ["a", "z"]);
|
|
114
|
+
assert.deepEqual(zMessages.map((m) => m.name), ["msgA", "msgB"]);
|
|
115
|
+
});
|
package/tsconfig.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "Node",
|
|
6
|
-
"outDir": "dist",
|
|
7
|
-
"rootDir": "src",
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"skipLibCheck": true
|
|
13
|
-
},
|
|
14
|
-
"include": ["src"]
|
|
15
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Node",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"rootDir": "src",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"skipLibCheck": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src"]
|
|
15
|
+
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { UniSpecDocument } from "../types";
|
|
2
|
-
export interface OpenAPIDocument {
|
|
3
|
-
[key: string]: unknown;
|
|
4
|
-
}
|
|
5
|
-
export interface GraphQLSDLOutput {
|
|
6
|
-
sdl: string;
|
|
7
|
-
}
|
|
8
|
-
export interface WebSocketModel {
|
|
9
|
-
[key: string]: unknown;
|
|
10
|
-
}
|
|
11
|
-
export declare function toOpenAPI(doc: UniSpecDocument): OpenAPIDocument;
|
|
12
|
-
export declare function toGraphQLSDL(doc: UniSpecDocument): GraphQLSDLOutput;
|
|
13
|
-
export declare function toWebSocketModel(doc: UniSpecDocument): WebSocketModel;
|
package/dist/converters/index.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
export function toOpenAPI(doc) {
|
|
2
|
-
const service = doc.service;
|
|
3
|
-
const rest = service.protocols?.rest;
|
|
4
|
-
const info = {
|
|
5
|
-
title: service.title ?? service.name,
|
|
6
|
-
description: service.description,
|
|
7
|
-
};
|
|
8
|
-
const servers = rest?.servers ?? [];
|
|
9
|
-
const paths = rest?.paths ?? {};
|
|
10
|
-
// Transparently forward additional REST protocol fields into the OpenAPI document.
|
|
11
|
-
// This allows users to describe components, security, tags and other structures
|
|
12
|
-
// without forcing a specific REST model at the core layer.
|
|
13
|
-
const { servers: _omitServers, paths: _omitPaths, ...restExtras } = rest ?? {};
|
|
14
|
-
return {
|
|
15
|
-
openapi: "3.1.0",
|
|
16
|
-
info,
|
|
17
|
-
servers,
|
|
18
|
-
paths,
|
|
19
|
-
...restExtras,
|
|
20
|
-
"x-unispec": doc,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export function toGraphQLSDL(doc) {
|
|
24
|
-
// Minimal implementation: generate a basic SDL that exposes service metadata
|
|
25
|
-
// via a Query field. This does not attempt to interpret the full GraphQL
|
|
26
|
-
// protocol structure yet, but provides a stable, deterministic SDL shape
|
|
27
|
-
// based on top-level UniSpec document fields.
|
|
28
|
-
const graphql = doc.service.protocols?.graphql;
|
|
29
|
-
const customSDL = graphql?.schema?.sdl;
|
|
30
|
-
if (typeof customSDL === "string" && customSDL.trim()) {
|
|
31
|
-
return { sdl: customSDL };
|
|
32
|
-
}
|
|
33
|
-
const service = doc.service;
|
|
34
|
-
const title = service.title ?? service.name;
|
|
35
|
-
const description = service.description ?? "";
|
|
36
|
-
const lines = [];
|
|
37
|
-
if (title || description) {
|
|
38
|
-
lines.push("\"\"");
|
|
39
|
-
if (title) {
|
|
40
|
-
lines.push(title);
|
|
41
|
-
}
|
|
42
|
-
if (description) {
|
|
43
|
-
lines.push("");
|
|
44
|
-
lines.push(description);
|
|
45
|
-
}
|
|
46
|
-
lines.push("\"\"");
|
|
47
|
-
}
|
|
48
|
-
lines.push("schema {");
|
|
49
|
-
lines.push(" query: Query");
|
|
50
|
-
lines.push("}");
|
|
51
|
-
lines.push("");
|
|
52
|
-
lines.push("type Query {");
|
|
53
|
-
lines.push(" _serviceInfo: String!\n");
|
|
54
|
-
lines.push("}");
|
|
55
|
-
const sdl = lines.join("\n");
|
|
56
|
-
return { sdl };
|
|
57
|
-
}
|
|
58
|
-
export function toWebSocketModel(doc) {
|
|
59
|
-
// Base WebSocket model intended for a modern, dashboard-oriented UI.
|
|
60
|
-
// It exposes service metadata, a normalized list of channels and the raw
|
|
61
|
-
// websocket protocol object, while also embedding the original UniSpec
|
|
62
|
-
// document under a technical key for debugging and introspection.
|
|
63
|
-
const service = doc.service;
|
|
64
|
-
const websocket = (service.protocols?.websocket ?? {});
|
|
65
|
-
const channelsRecord = (websocket && typeof websocket === "object" && websocket.channels && typeof websocket.channels === "object")
|
|
66
|
-
? websocket.channels
|
|
67
|
-
: {};
|
|
68
|
-
const channels = Object.keys(channelsRecord).sort().map((name) => {
|
|
69
|
-
const channel = channelsRecord[name] ?? {};
|
|
70
|
-
return {
|
|
71
|
-
name,
|
|
72
|
-
summary: channel.summary ?? channel.title,
|
|
73
|
-
description: channel.description,
|
|
74
|
-
direction: channel.direction,
|
|
75
|
-
messages: channel.messages,
|
|
76
|
-
raw: channel,
|
|
77
|
-
};
|
|
78
|
-
});
|
|
79
|
-
return {
|
|
80
|
-
service: {
|
|
81
|
-
name: service.name,
|
|
82
|
-
title: service.title,
|
|
83
|
-
description: service.description,
|
|
84
|
-
},
|
|
85
|
-
channels,
|
|
86
|
-
rawProtocol: websocket,
|
|
87
|
-
"x-unispec-ws": doc,
|
|
88
|
-
};
|
|
89
|
-
}
|
package/dist/diff/index.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { UniSpecDocument } from "../types";
|
|
2
|
-
export type ChangeSeverity = "breaking" | "non-breaking" | "unknown";
|
|
3
|
-
export interface UniSpecChange {
|
|
4
|
-
path: string;
|
|
5
|
-
description: string;
|
|
6
|
-
severity: ChangeSeverity;
|
|
7
|
-
protocol?: "rest" | "graphql" | "websocket";
|
|
8
|
-
kind?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface DiffResult {
|
|
11
|
-
changes: UniSpecChange[];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Compute a structural diff between two UniSpec documents.
|
|
15
|
-
*
|
|
16
|
-
* Current behavior:
|
|
17
|
-
* - Tracks added, removed, and changed fields and array items.
|
|
18
|
-
* - Uses JSON Pointer-like paths rooted at "" (e.g., "/info/title").
|
|
19
|
-
* - Marks all changes with severity "unknown" for now.
|
|
20
|
-
*/
|
|
21
|
-
export declare function diffUniSpec(oldDoc: UniSpecDocument, newDoc: UniSpecDocument): DiffResult;
|
package/dist/diff/index.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
function isPlainObject(value) {
|
|
2
|
-
return Object.prototype.toString.call(value) === "[object Object]";
|
|
3
|
-
}
|
|
4
|
-
function diffValues(oldVal, newVal, basePath, out) {
|
|
5
|
-
if (oldVal === newVal) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
// Both plain objects → recurse by keys
|
|
9
|
-
if (isPlainObject(oldVal) && isPlainObject(newVal)) {
|
|
10
|
-
const oldKeys = new Set(Object.keys(oldVal));
|
|
11
|
-
const newKeys = new Set(Object.keys(newVal));
|
|
12
|
-
// Removed keys
|
|
13
|
-
for (const key of oldKeys) {
|
|
14
|
-
if (!newKeys.has(key)) {
|
|
15
|
-
out.push({
|
|
16
|
-
path: `${basePath}/${key}`,
|
|
17
|
-
description: "Field removed",
|
|
18
|
-
severity: "unknown",
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
// Added / changed keys
|
|
23
|
-
for (const key of newKeys) {
|
|
24
|
-
const childPath = `${basePath}/${key}`;
|
|
25
|
-
if (!oldKeys.has(key)) {
|
|
26
|
-
out.push({
|
|
27
|
-
path: childPath,
|
|
28
|
-
description: "Field added",
|
|
29
|
-
severity: "unknown",
|
|
30
|
-
});
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
diffValues(oldVal[key], newVal[key], childPath, out);
|
|
34
|
-
}
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
// Arrays → shallow compare by index for now
|
|
38
|
-
if (Array.isArray(oldVal) && Array.isArray(newVal)) {
|
|
39
|
-
const maxLen = Math.max(oldVal.length, newVal.length);
|
|
40
|
-
for (let i = 0; i < maxLen; i++) {
|
|
41
|
-
const childPath = `${basePath}/${i}`;
|
|
42
|
-
if (i >= oldVal.length) {
|
|
43
|
-
out.push({
|
|
44
|
-
path: childPath,
|
|
45
|
-
description: "Item added",
|
|
46
|
-
severity: "unknown",
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
else if (i >= newVal.length) {
|
|
50
|
-
out.push({
|
|
51
|
-
path: childPath,
|
|
52
|
-
description: "Item removed",
|
|
53
|
-
severity: "unknown",
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
diffValues(oldVal[i], newVal[i], childPath, out);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
// Primitive or mismatched types → treat as value change
|
|
63
|
-
out.push({
|
|
64
|
-
path: basePath,
|
|
65
|
-
description: "Value changed",
|
|
66
|
-
severity: "unknown",
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
function annotateRestChange(change) {
|
|
70
|
-
if (!change.path.startsWith("/service/protocols/rest/paths/")) {
|
|
71
|
-
return change;
|
|
72
|
-
}
|
|
73
|
-
const segments = change.path.split("/").filter(Boolean);
|
|
74
|
-
// Expected shape: ["service", "protocols", "rest", "paths", pathKey?, method?]
|
|
75
|
-
if (segments[0] !== "service" || segments[1] !== "protocols" || segments[2] !== "rest" || segments[3] !== "paths") {
|
|
76
|
-
return change;
|
|
77
|
-
}
|
|
78
|
-
const pathKey = segments[4];
|
|
79
|
-
const method = segments[5];
|
|
80
|
-
const httpMethods = new Set(["get", "head", "options", "post", "put", "patch", "delete"]);
|
|
81
|
-
const annotated = {
|
|
82
|
-
...change,
|
|
83
|
-
protocol: "rest",
|
|
84
|
-
};
|
|
85
|
-
if (change.description === "Field removed") {
|
|
86
|
-
if (pathKey && !method) {
|
|
87
|
-
annotated.kind = "rest.path.removed";
|
|
88
|
-
annotated.severity = "breaking";
|
|
89
|
-
}
|
|
90
|
-
else if (pathKey && method && httpMethods.has(method)) {
|
|
91
|
-
annotated.kind = "rest.operation.removed";
|
|
92
|
-
annotated.severity = "breaking";
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
else if (change.description === "Field added") {
|
|
96
|
-
if (pathKey && !method) {
|
|
97
|
-
annotated.kind = "rest.path.added";
|
|
98
|
-
annotated.severity = "non-breaking";
|
|
99
|
-
}
|
|
100
|
-
else if (pathKey && method && httpMethods.has(method)) {
|
|
101
|
-
annotated.kind = "rest.operation.added";
|
|
102
|
-
annotated.severity = "non-breaking";
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return annotated;
|
|
106
|
-
}
|
|
107
|
-
function annotateWebSocketChange(change) {
|
|
108
|
-
if (!change.path.startsWith("/service/protocols/websocket/channels/")) {
|
|
109
|
-
return change;
|
|
110
|
-
}
|
|
111
|
-
const segments = change.path.split("/").filter(Boolean);
|
|
112
|
-
// Expected: ["service","protocols","websocket","channels", channelName, ...]
|
|
113
|
-
if (segments[0] !== "service" || segments[1] !== "protocols" || segments[2] !== "websocket" || segments[3] !== "channels") {
|
|
114
|
-
return change;
|
|
115
|
-
}
|
|
116
|
-
const channelName = segments[4];
|
|
117
|
-
const next = segments[5];
|
|
118
|
-
const annotated = {
|
|
119
|
-
...change,
|
|
120
|
-
protocol: "websocket",
|
|
121
|
-
};
|
|
122
|
-
if (!channelName) {
|
|
123
|
-
return annotated;
|
|
124
|
-
}
|
|
125
|
-
// Channel-level changes
|
|
126
|
-
if (!next) {
|
|
127
|
-
if (change.description === "Field removed") {
|
|
128
|
-
annotated.kind = "websocket.channel.removed";
|
|
129
|
-
annotated.severity = "breaking";
|
|
130
|
-
}
|
|
131
|
-
else if (change.description === "Field added") {
|
|
132
|
-
annotated.kind = "websocket.channel.added";
|
|
133
|
-
annotated.severity = "non-breaking";
|
|
134
|
-
}
|
|
135
|
-
return annotated;
|
|
136
|
-
}
|
|
137
|
-
// Message-level changes (channels/{channelName}/messages/{index})
|
|
138
|
-
if (next === "messages") {
|
|
139
|
-
const index = segments[6];
|
|
140
|
-
if (typeof index === "undefined") {
|
|
141
|
-
return annotated;
|
|
142
|
-
}
|
|
143
|
-
if (change.description === "Item removed") {
|
|
144
|
-
annotated.kind = "websocket.message.removed";
|
|
145
|
-
annotated.severity = "breaking";
|
|
146
|
-
}
|
|
147
|
-
else if (change.description === "Item added") {
|
|
148
|
-
annotated.kind = "websocket.message.added";
|
|
149
|
-
annotated.severity = "non-breaking";
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return annotated;
|
|
153
|
-
}
|
|
154
|
-
function annotateGraphQLChange(change) {
|
|
155
|
-
if (!change.path.startsWith("/service/protocols/graphql/operations/")) {
|
|
156
|
-
return change;
|
|
157
|
-
}
|
|
158
|
-
const segments = change.path.split("/").filter(Boolean);
|
|
159
|
-
// Expected: ["service","protocols","graphql","operations", kind, opName?]
|
|
160
|
-
if (segments[0] !== "service" || segments[1] !== "protocols" || segments[2] !== "graphql" || segments[3] !== "operations") {
|
|
161
|
-
return change;
|
|
162
|
-
}
|
|
163
|
-
const opKind = segments[4];
|
|
164
|
-
const opName = segments[5];
|
|
165
|
-
if (!opKind || !opName) {
|
|
166
|
-
return change;
|
|
167
|
-
}
|
|
168
|
-
const annotated = {
|
|
169
|
-
...change,
|
|
170
|
-
protocol: "graphql",
|
|
171
|
-
};
|
|
172
|
-
if (change.description === "Field removed") {
|
|
173
|
-
annotated.kind = "graphql.operation.removed";
|
|
174
|
-
annotated.severity = "breaking";
|
|
175
|
-
}
|
|
176
|
-
else if (change.description === "Field added") {
|
|
177
|
-
annotated.kind = "graphql.operation.added";
|
|
178
|
-
annotated.severity = "non-breaking";
|
|
179
|
-
}
|
|
180
|
-
return annotated;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Compute a structural diff between two UniSpec documents.
|
|
184
|
-
*
|
|
185
|
-
* Current behavior:
|
|
186
|
-
* - Tracks added, removed, and changed fields and array items.
|
|
187
|
-
* - Uses JSON Pointer-like paths rooted at "" (e.g., "/info/title").
|
|
188
|
-
* - Marks all changes with severity "unknown" for now.
|
|
189
|
-
*/
|
|
190
|
-
export function diffUniSpec(oldDoc, newDoc) {
|
|
191
|
-
const changes = [];
|
|
192
|
-
diffValues(oldDoc, newDoc, "", changes);
|
|
193
|
-
const annotated = changes.map((change) => annotateWebSocketChange(annotateGraphQLChange(annotateRestChange(change))));
|
|
194
|
-
return { changes: annotated };
|
|
195
|
-
}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
package/dist/loader/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { UniSpecDocument } from "../types";
|
|
2
|
-
export interface LoadOptions {
|
|
3
|
-
filename?: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Load a UniSpec document from a raw input value.
|
|
7
|
-
* Currently supports:
|
|
8
|
-
* - JavaScript objects (treated as already parsed UniSpec)
|
|
9
|
-
* - JSON strings
|
|
10
|
-
*
|
|
11
|
-
* YAML and filesystem helpers will be added later, keeping this API stable.
|
|
12
|
-
*/
|
|
13
|
-
export declare function loadUniSpec(input: string | object, _options?: LoadOptions): Promise<UniSpecDocument>;
|
package/dist/loader/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Load a UniSpec document from a raw input value.
|
|
3
|
-
* Currently supports:
|
|
4
|
-
* - JavaScript objects (treated as already parsed UniSpec)
|
|
5
|
-
* - JSON strings
|
|
6
|
-
*
|
|
7
|
-
* YAML and filesystem helpers will be added later, keeping this API stable.
|
|
8
|
-
*/
|
|
9
|
-
export async function loadUniSpec(input, _options = {}) {
|
|
10
|
-
if (typeof input === "string") {
|
|
11
|
-
const trimmed = input.trim();
|
|
12
|
-
if (!trimmed) {
|
|
13
|
-
throw new Error("Cannot load UniSpec: input string is empty");
|
|
14
|
-
}
|
|
15
|
-
// For now we assume JSON; YAML support will be added later.
|
|
16
|
-
return JSON.parse(trimmed);
|
|
17
|
-
}
|
|
18
|
-
return input;
|
|
19
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { UniSpecDocument } from "../types";
|
|
2
|
-
export interface NormalizeOptions {
|
|
3
|
-
}
|
|
4
|
-
/**
|
|
5
|
-
* Normalize a UniSpec document into a canonical, deterministic form.
|
|
6
|
-
*
|
|
7
|
-
* Current behavior:
|
|
8
|
-
* - Recursively sorts object keys lexicographically.
|
|
9
|
-
* - Preserves values as-is.
|
|
10
|
-
*/
|
|
11
|
-
export declare function normalizeUniSpec(doc: UniSpecDocument, _options?: NormalizeOptions): UniSpecDocument;
|