@larose-ui/contracts 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +64 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 laRose contributors
|
|
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/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface ContractField {
|
|
2
|
+
name: string;
|
|
3
|
+
type?: string;
|
|
4
|
+
required?: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface ContractSchema {
|
|
7
|
+
name: string;
|
|
8
|
+
fields: ContractField[];
|
|
9
|
+
}
|
|
10
|
+
interface ContractMismatch {
|
|
11
|
+
field: string;
|
|
12
|
+
issue: 'missing_in_api' | 'missing_in_ui' | 'type_mismatch' | 'required_mismatch';
|
|
13
|
+
message: string;
|
|
14
|
+
severity: 'error' | 'warning';
|
|
15
|
+
}
|
|
16
|
+
interface ContractValidationResult {
|
|
17
|
+
valid: boolean;
|
|
18
|
+
mismatches: ContractMismatch[];
|
|
19
|
+
}
|
|
20
|
+
declare function validateContract(ui: ContractSchema, api: ContractSchema): ContractValidationResult;
|
|
21
|
+
declare function formatContractReport(result: ContractValidationResult): string;
|
|
22
|
+
|
|
23
|
+
export { type ContractField, type ContractMismatch, type ContractSchema, type ContractValidationResult, formatContractReport, validateContract };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function validateContract(ui, api) {
|
|
3
|
+
const mismatches = [];
|
|
4
|
+
const apiFields = new Map(api.fields.map((f) => [f.name, f]));
|
|
5
|
+
const uiFields = new Map(ui.fields.map((f) => [f.name, f]));
|
|
6
|
+
for (const uiField of ui.fields) {
|
|
7
|
+
const apiField = apiFields.get(uiField.name);
|
|
8
|
+
if (!apiField) {
|
|
9
|
+
mismatches.push({
|
|
10
|
+
field: uiField.name,
|
|
11
|
+
issue: "missing_in_api",
|
|
12
|
+
message: `UI expects "${uiField.name}" but API schema does not include it`,
|
|
13
|
+
severity: uiField.required ? "error" : "warning"
|
|
14
|
+
});
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (uiField.type && apiField.type && uiField.type !== apiField.type) {
|
|
18
|
+
mismatches.push({
|
|
19
|
+
field: uiField.name,
|
|
20
|
+
issue: "type_mismatch",
|
|
21
|
+
message: `Type mismatch for "${uiField.name}": UI=${uiField.type}, API=${apiField.type}`,
|
|
22
|
+
severity: "error"
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
if (uiField.required && !apiField.required) {
|
|
26
|
+
mismatches.push({
|
|
27
|
+
field: uiField.name,
|
|
28
|
+
issue: "required_mismatch",
|
|
29
|
+
message: `"${uiField.name}" is required in UI but optional in API`,
|
|
30
|
+
severity: "warning"
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
for (const apiField of api.fields) {
|
|
35
|
+
if (!uiFields.has(apiField.name) && apiField.required) {
|
|
36
|
+
mismatches.push({
|
|
37
|
+
field: apiField.name,
|
|
38
|
+
issue: "missing_in_ui",
|
|
39
|
+
message: `API requires "${apiField.name}" but UI schema does not include it`,
|
|
40
|
+
severity: "error"
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
valid: mismatches.filter((m) => m.severity === "error").length === 0,
|
|
46
|
+
mismatches
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function formatContractReport(result) {
|
|
50
|
+
if (result.valid && result.mismatches.length === 0) {
|
|
51
|
+
return "Contract validation passed.";
|
|
52
|
+
}
|
|
53
|
+
const lines = ["Contract validation report:", ""];
|
|
54
|
+
for (const m of result.mismatches) {
|
|
55
|
+
lines.push(`[${m.severity.toUpperCase()}] ${m.field}: ${m.message}`);
|
|
56
|
+
}
|
|
57
|
+
lines.push("");
|
|
58
|
+
lines.push(result.valid ? "Result: PASS (warnings only)" : "Result: FAIL");
|
|
59
|
+
return lines.join("\n");
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
formatContractReport,
|
|
63
|
+
validateContract
|
|
64
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@larose-ui/contracts",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "UI/API contract validation for laRose platform",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@larose-ui/core": "0.1.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"tsup": "^8.3.5",
|
|
23
|
+
"typescript": "^5.7.2",
|
|
24
|
+
"vitest": "^2.1.8"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/larose-ui/larose.git",
|
|
33
|
+
"directory": "packages/contracts"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"larose",
|
|
37
|
+
"react",
|
|
38
|
+
"ui-platform",
|
|
39
|
+
"design-system",
|
|
40
|
+
"saas"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"typecheck": "tsc --noEmit",
|
|
46
|
+
"clean": "rm -rf dist"
|
|
47
|
+
}
|
|
48
|
+
}
|