@graph-knowledge/api 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/README.md +396 -0
- package/package.json +44 -0
- package/src/index.d.ts +18 -0
- package/src/index.js +19 -0
- package/src/lib/clients/firebase-auth-client.d.ts +24 -0
- package/src/lib/clients/firebase-auth-client.js +76 -0
- package/src/lib/clients/firebase-firestore-client.d.ts +22 -0
- package/src/lib/clients/firebase-firestore-client.js +79 -0
- package/src/lib/config/api-config.d.ts +20 -0
- package/src/lib/config/api-config.js +0 -0
- package/src/lib/constants/element-defaults.d.ts +15 -0
- package/src/lib/constants/element-defaults.js +19 -0
- package/src/lib/errors/api-errors.d.ts +33 -0
- package/src/lib/errors/api-errors.js +51 -0
- package/src/lib/graph-knowledge-api.d.ts +106 -0
- package/src/lib/graph-knowledge-api.js +154 -0
- package/src/lib/interfaces/auth-client.interface.d.ts +35 -0
- package/src/lib/interfaces/auth-client.interface.js +0 -0
- package/src/lib/interfaces/batch-operations.interface.d.ts +46 -0
- package/src/lib/interfaces/batch-operations.interface.js +0 -0
- package/src/lib/interfaces/document-operations.interface.d.ts +51 -0
- package/src/lib/interfaces/document-operations.interface.js +0 -0
- package/src/lib/interfaces/element-operations.interface.d.ts +57 -0
- package/src/lib/interfaces/element-operations.interface.js +0 -0
- package/src/lib/interfaces/element-validator.interface.d.ts +42 -0
- package/src/lib/interfaces/element-validator.interface.js +0 -0
- package/src/lib/interfaces/firestore-client.interface.d.ts +62 -0
- package/src/lib/interfaces/firestore-client.interface.js +0 -0
- package/src/lib/interfaces/node-operations.interface.d.ts +62 -0
- package/src/lib/interfaces/node-operations.interface.js +0 -0
- package/src/lib/models/document.model.d.ts +73 -0
- package/src/lib/models/document.model.js +13 -0
- package/src/lib/models/index.d.ts +6 -0
- package/src/lib/models/index.js +5 -0
- package/src/lib/operations/batch-operations.d.ts +30 -0
- package/src/lib/operations/batch-operations.js +181 -0
- package/src/lib/operations/document-operations.d.ts +20 -0
- package/src/lib/operations/document-operations.js +108 -0
- package/src/lib/operations/element-operations.d.ts +33 -0
- package/src/lib/operations/element-operations.js +175 -0
- package/src/lib/operations/node-operations.d.ts +22 -0
- package/src/lib/operations/node-operations.js +89 -0
- package/src/lib/testing/index.d.ts +2 -0
- package/src/lib/testing/index.js +3 -0
- package/src/lib/testing/mock-auth-client.d.ts +26 -0
- package/src/lib/testing/mock-auth-client.js +49 -0
- package/src/lib/testing/mock-firestore-client.d.ts +32 -0
- package/src/lib/testing/mock-firestore-client.js +126 -0
- package/src/lib/types/api-types.d.ts +61 -0
- package/src/lib/types/api-types.js +0 -0
- package/src/lib/types/element-input-types.d.ts +237 -0
- package/src/lib/types/element-input-types.js +3 -0
- package/src/lib/utils/link-level-manager.d.ts +66 -0
- package/src/lib/utils/link-level-manager.js +200 -0
- package/src/lib/utils/uuid.d.ts +5 -0
- package/src/lib/utils/uuid.js +16 -0
- package/src/lib/validators/document-validator.d.ts +22 -0
- package/src/lib/validators/document-validator.js +68 -0
- package/src/lib/validators/element-type-validators/base-element-validator.d.ts +35 -0
- package/src/lib/validators/element-type-validators/base-element-validator.js +96 -0
- package/src/lib/validators/element-type-validators/connector-validator.d.ts +13 -0
- package/src/lib/validators/element-type-validators/connector-validator.js +66 -0
- package/src/lib/validators/element-type-validators/custom-shape-validator.d.ts +22 -0
- package/src/lib/validators/element-type-validators/custom-shape-validator.js +44 -0
- package/src/lib/validators/element-type-validators/rectangle-validator.d.ts +11 -0
- package/src/lib/validators/element-type-validators/rectangle-validator.js +31 -0
- package/src/lib/validators/element-type-validators/text-validator.d.ts +14 -0
- package/src/lib/validators/element-type-validators/text-validator.js +66 -0
- package/src/lib/validators/element-type-validators/uml-validators.d.ts +58 -0
- package/src/lib/validators/element-type-validators/uml-validators.js +123 -0
- package/src/lib/validators/element-validator-registry.d.ts +18 -0
- package/src/lib/validators/element-validator-registry.js +58 -0
- package/src/lib/validators/node-validator.d.ts +26 -0
- package/src/lib/validators/node-validator.js +90 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ValidationError } from "../errors/api-errors";
|
|
2
|
+
/**
|
|
3
|
+
* Validator for node operations.
|
|
4
|
+
*/
|
|
5
|
+
export class NodeValidator {
|
|
6
|
+
/**
|
|
7
|
+
* Validates input for node creation.
|
|
8
|
+
* @param input The creation input to validate
|
|
9
|
+
* @throws ValidationError if validation fails
|
|
10
|
+
*/
|
|
11
|
+
validateCreate(input) {
|
|
12
|
+
if (!input.title || typeof input.title !== "string") {
|
|
13
|
+
throw new ValidationError("title is required", "title");
|
|
14
|
+
}
|
|
15
|
+
if (input.title.trim().length === 0) {
|
|
16
|
+
throw new ValidationError("title cannot be empty", "title");
|
|
17
|
+
}
|
|
18
|
+
if (input.title.length > 200) {
|
|
19
|
+
throw new ValidationError("title must be 200 characters or less", "title");
|
|
20
|
+
}
|
|
21
|
+
if (input.content !== undefined && typeof input.content !== "string") {
|
|
22
|
+
throw new ValidationError("content must be a string", "content");
|
|
23
|
+
}
|
|
24
|
+
if (input.parentNodeId !== undefined &&
|
|
25
|
+
typeof input.parentNodeId !== "string") {
|
|
26
|
+
throw new ValidationError("parentNodeId must be a string", "parentNodeId");
|
|
27
|
+
}
|
|
28
|
+
this.validateCanvasDimensions(input.canvasWidth, input.canvasHeight);
|
|
29
|
+
this.validateLevel(input.level);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Validates input for node update.
|
|
33
|
+
* @param input The update input to validate
|
|
34
|
+
* @throws ValidationError if validation fails
|
|
35
|
+
*/
|
|
36
|
+
validateUpdate(input) {
|
|
37
|
+
if (input.title !== undefined) {
|
|
38
|
+
if (typeof input.title !== "string") {
|
|
39
|
+
throw new ValidationError("title must be a string", "title");
|
|
40
|
+
}
|
|
41
|
+
if (input.title.trim().length === 0) {
|
|
42
|
+
throw new ValidationError("title cannot be empty", "title");
|
|
43
|
+
}
|
|
44
|
+
if (input.title.length > 200) {
|
|
45
|
+
throw new ValidationError("title must be 200 characters or less", "title");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (input.content !== undefined && typeof input.content !== "string") {
|
|
49
|
+
throw new ValidationError("content must be a string", "content");
|
|
50
|
+
}
|
|
51
|
+
this.validateCanvasDimensions(input.canvasWidth, input.canvasHeight);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Validates canvas dimensions.
|
|
55
|
+
*/
|
|
56
|
+
validateCanvasDimensions(width, height) {
|
|
57
|
+
if (width !== undefined) {
|
|
58
|
+
if (typeof width !== "number" || isNaN(width)) {
|
|
59
|
+
throw new ValidationError("canvasWidth must be a valid number", "canvasWidth");
|
|
60
|
+
}
|
|
61
|
+
if (width < 100 || width > 10000) {
|
|
62
|
+
throw new ValidationError("canvasWidth must be between 100 and 10000", "canvasWidth");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (height !== undefined) {
|
|
66
|
+
if (typeof height !== "number" || isNaN(height)) {
|
|
67
|
+
throw new ValidationError("canvasHeight must be a valid number", "canvasHeight");
|
|
68
|
+
}
|
|
69
|
+
if (height < 100 || height > 10000) {
|
|
70
|
+
throw new ValidationError("canvasHeight must be between 100 and 10000", "canvasHeight");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Validates node level.
|
|
76
|
+
*/
|
|
77
|
+
validateLevel(level) {
|
|
78
|
+
if (level === undefined)
|
|
79
|
+
return;
|
|
80
|
+
if (typeof level !== "number" || isNaN(level)) {
|
|
81
|
+
throw new ValidationError("level must be a valid number", "level");
|
|
82
|
+
}
|
|
83
|
+
if (level < 0) {
|
|
84
|
+
throw new ValidationError("level must be non-negative", "level");
|
|
85
|
+
}
|
|
86
|
+
if (!Number.isInteger(level)) {
|
|
87
|
+
throw new ValidationError("level must be an integer", "level");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|