@graph-knowledge/api 0.1.5 → 0.1.6
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/package.json +1 -1
- package/src/index.d.ts +1 -1
- package/src/lib/constants/element-defaults.js +7 -1
- package/src/lib/types/element-input-types.d.ts +79 -1
- package/src/lib/validators/element-type-validators/basic-shape-validators.d.ts +36 -0
- package/src/lib/validators/element-type-validators/basic-shape-validators.js +51 -0
- package/src/lib/validators/element-type-validators/block-arrow-validator.d.ts +11 -0
- package/src/lib/validators/element-type-validators/block-arrow-validator.js +36 -0
- package/src/lib/validators/element-type-validators/line-validator.d.ts +11 -0
- package/src/lib/validators/element-type-validators/line-validator.js +35 -0
- package/src/lib/validators/element-validator-registry.js +9 -0
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type { IBatchOperations, BatchUpdateElementInput } from "./lib/interfaces
|
|
|
9
9
|
export type { ITemplateOperations } from "./lib/interfaces/template-operations.interface";
|
|
10
10
|
export type { IElementTypeValidator, IElementValidatorRegistry } from "./lib/interfaces/element-validator.interface";
|
|
11
11
|
export type { CreateDocumentInput, UpdateDocumentInput, DocumentResult, CreateNodeInput, UpdateNodeInput, NodeResult } from "./lib/types/api-types";
|
|
12
|
-
export type { BaseElementInput, RectangleInput, TextInput, ConnectorInput, ConnectorAnchor, LineStyle, MarkerType, UmlClassInput, UmlInterfaceInput, UmlComponentInput, UmlPackageInput, UmlArtifactInput, UmlNoteInput, CustomShapeInput, AnyElementInput, UpdateElementInput } from "./lib/types/element-input-types";
|
|
12
|
+
export type { BaseElementInput, RectangleInput, TextInput, ConnectorInput, ConnectorAnchor, LineStyle, MarkerType, UmlClassInput, UmlInterfaceInput, UmlComponentInput, UmlPackageInput, UmlArtifactInput, UmlNoteInput, TriangleInput, DiamondInput, HexagonInput, EllipseInput, LineInput, BlockArrowInput, BlockArrowDirection, CustomShapeInput, AnyElementInput, UpdateElementInput } from "./lib/types/element-input-types";
|
|
13
13
|
export { GraphKnowledgeAPIError, AuthenticationError, NotFoundError, ValidationError, PermissionError } from "./lib/errors/api-errors";
|
|
14
14
|
export type { Document, GraphNode, GraphElement } from "./lib/models";
|
|
15
15
|
export { CURRENT_DOCUMENT_SCHEMA_VERSION } from "./lib/models";
|
|
@@ -14,7 +14,13 @@ exports.DEFAULT_ELEMENT_DIMENSIONS = {
|
|
|
14
14
|
"uml-component": { width: 150, height: 100 },
|
|
15
15
|
"uml-package": { width: 200, height: 150 },
|
|
16
16
|
"uml-artifact": { width: 100, height: 80 },
|
|
17
|
-
"uml-note": { width: 150, height: 100 }
|
|
17
|
+
"uml-note": { width: 150, height: 100 },
|
|
18
|
+
triangle: { width: 120, height: 100 },
|
|
19
|
+
diamond: { width: 100, height: 100 },
|
|
20
|
+
hexagon: { width: 120, height: 104 },
|
|
21
|
+
ellipse: { width: 150, height: 100 },
|
|
22
|
+
line: { width: 150, height: 0 },
|
|
23
|
+
"block-arrow": { width: 150, height: 80 }
|
|
18
24
|
};
|
|
19
25
|
/**
|
|
20
26
|
* Default dimensions for custom shapes.
|
|
@@ -201,6 +201,84 @@ export interface UmlNoteInput extends BaseElementInput {
|
|
|
201
201
|
/** Stroke width in pixels */
|
|
202
202
|
strokeWidth?: number;
|
|
203
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Input for creating a triangle element.
|
|
206
|
+
*/
|
|
207
|
+
export interface TriangleInput extends BaseElementInput {
|
|
208
|
+
type: "triangle";
|
|
209
|
+
/** Fill color (hex, e.g., "#FF5733") */
|
|
210
|
+
fillColor?: string;
|
|
211
|
+
/** Stroke color (hex) */
|
|
212
|
+
strokeColor?: string;
|
|
213
|
+
/** Stroke width in pixels */
|
|
214
|
+
strokeWidth?: number;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Input for creating a diamond element.
|
|
218
|
+
*/
|
|
219
|
+
export interface DiamondInput extends BaseElementInput {
|
|
220
|
+
type: "diamond";
|
|
221
|
+
/** Fill color (hex, e.g., "#FF5733") */
|
|
222
|
+
fillColor?: string;
|
|
223
|
+
/** Stroke color (hex) */
|
|
224
|
+
strokeColor?: string;
|
|
225
|
+
/** Stroke width in pixels */
|
|
226
|
+
strokeWidth?: number;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Input for creating a hexagon element.
|
|
230
|
+
*/
|
|
231
|
+
export interface HexagonInput extends BaseElementInput {
|
|
232
|
+
type: "hexagon";
|
|
233
|
+
/** Fill color (hex, e.g., "#FF5733") */
|
|
234
|
+
fillColor?: string;
|
|
235
|
+
/** Stroke color (hex) */
|
|
236
|
+
strokeColor?: string;
|
|
237
|
+
/** Stroke width in pixels */
|
|
238
|
+
strokeWidth?: number;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Input for creating an ellipse element.
|
|
242
|
+
*/
|
|
243
|
+
export interface EllipseInput extends BaseElementInput {
|
|
244
|
+
type: "ellipse";
|
|
245
|
+
/** Fill color (hex, e.g., "#FF5733") */
|
|
246
|
+
fillColor?: string;
|
|
247
|
+
/** Stroke color (hex) */
|
|
248
|
+
strokeColor?: string;
|
|
249
|
+
/** Stroke width in pixels */
|
|
250
|
+
strokeWidth?: number;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Input for creating a line element.
|
|
254
|
+
*/
|
|
255
|
+
export interface LineInput extends BaseElementInput {
|
|
256
|
+
type: "line";
|
|
257
|
+
/** Stroke color (hex) */
|
|
258
|
+
strokeColor?: string;
|
|
259
|
+
/** Stroke width in pixels */
|
|
260
|
+
strokeWidth?: number;
|
|
261
|
+
/** Line style (reuses LineStyle from connectors) */
|
|
262
|
+
lineStyle?: LineStyle;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Direction for block arrow elements.
|
|
266
|
+
*/
|
|
267
|
+
export type BlockArrowDirection = "right" | "left" | "up" | "down";
|
|
268
|
+
/**
|
|
269
|
+
* Input for creating a block arrow element.
|
|
270
|
+
*/
|
|
271
|
+
export interface BlockArrowInput extends BaseElementInput {
|
|
272
|
+
type: "block-arrow";
|
|
273
|
+
/** Fill color (hex, e.g., "#FF5733") */
|
|
274
|
+
fillColor?: string;
|
|
275
|
+
/** Stroke color (hex) */
|
|
276
|
+
strokeColor?: string;
|
|
277
|
+
/** Stroke width in pixels */
|
|
278
|
+
strokeWidth?: number;
|
|
279
|
+
/** Arrow direction */
|
|
280
|
+
direction?: BlockArrowDirection;
|
|
281
|
+
}
|
|
204
282
|
/**
|
|
205
283
|
* Input for creating a custom shape element.
|
|
206
284
|
*/
|
|
@@ -220,7 +298,7 @@ export interface CustomShapeInput extends BaseElementInput {
|
|
|
220
298
|
/**
|
|
221
299
|
* Union of all element input types.
|
|
222
300
|
*/
|
|
223
|
-
export type AnyElementInput = RectangleInput | TextInput | ConnectorInput | UmlClassInput | UmlInterfaceInput | UmlComponentInput | UmlPackageInput | UmlArtifactInput | UmlNoteInput | CustomShapeInput;
|
|
301
|
+
export type AnyElementInput = RectangleInput | TextInput | ConnectorInput | UmlClassInput | UmlInterfaceInput | UmlComponentInput | UmlPackageInput | UmlArtifactInput | UmlNoteInput | TriangleInput | DiamondInput | HexagonInput | EllipseInput | LineInput | BlockArrowInput | CustomShapeInput;
|
|
224
302
|
/**
|
|
225
303
|
* Input for updating an existing element.
|
|
226
304
|
*/
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { IElementTypeValidator } from "../../interfaces/element-validator.interface";
|
|
2
|
+
import { AnyElementInput } from "../../types/element-input-types";
|
|
3
|
+
import { BaseElementValidator } from "./base-element-validator";
|
|
4
|
+
/**
|
|
5
|
+
* Base validator for basic shapes (triangle, diamond, hexagon, ellipse).
|
|
6
|
+
* All these shapes share the same properties: fillColor, strokeColor, strokeWidth.
|
|
7
|
+
*/
|
|
8
|
+
declare abstract class BasicShapeValidator extends BaseElementValidator implements IElementTypeValidator {
|
|
9
|
+
abstract readonly elementType: string;
|
|
10
|
+
validate(input: AnyElementInput): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Validator for triangle elements.
|
|
14
|
+
*/
|
|
15
|
+
export declare class TriangleValidator extends BasicShapeValidator {
|
|
16
|
+
readonly elementType = "triangle";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Validator for diamond elements.
|
|
20
|
+
*/
|
|
21
|
+
export declare class DiamondValidator extends BasicShapeValidator {
|
|
22
|
+
readonly elementType = "diamond";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validator for hexagon elements.
|
|
26
|
+
*/
|
|
27
|
+
export declare class HexagonValidator extends BasicShapeValidator {
|
|
28
|
+
readonly elementType = "hexagon";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Validator for ellipse elements.
|
|
32
|
+
*/
|
|
33
|
+
export declare class EllipseValidator extends BasicShapeValidator {
|
|
34
|
+
readonly elementType = "ellipse";
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EllipseValidator = exports.HexagonValidator = exports.DiamondValidator = exports.TriangleValidator = void 0;
|
|
4
|
+
const api_errors_1 = require("../../errors/api-errors");
|
|
5
|
+
const base_element_validator_1 = require("./base-element-validator");
|
|
6
|
+
/**
|
|
7
|
+
* Base validator for basic shapes (triangle, diamond, hexagon, ellipse).
|
|
8
|
+
* All these shapes share the same properties: fillColor, strokeColor, strokeWidth.
|
|
9
|
+
*/
|
|
10
|
+
class BasicShapeValidator extends base_element_validator_1.BaseElementValidator {
|
|
11
|
+
validate(input) {
|
|
12
|
+
if (input.type !== this.elementType) {
|
|
13
|
+
throw new api_errors_1.ValidationError(`Expected type "${this.elementType}", got "${input.type}"`, "type");
|
|
14
|
+
}
|
|
15
|
+
const shapeInput = input;
|
|
16
|
+
// Validate common properties
|
|
17
|
+
this.validateCommon(shapeInput);
|
|
18
|
+
// Validate shape-specific properties
|
|
19
|
+
this.validateColor(shapeInput.fillColor, "fillColor");
|
|
20
|
+
this.validateColor(shapeInput.strokeColor, "strokeColor");
|
|
21
|
+
this.validateStrokeWidth(shapeInput.strokeWidth, "strokeWidth");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validator for triangle elements.
|
|
26
|
+
*/
|
|
27
|
+
class TriangleValidator extends BasicShapeValidator {
|
|
28
|
+
elementType = "triangle";
|
|
29
|
+
}
|
|
30
|
+
exports.TriangleValidator = TriangleValidator;
|
|
31
|
+
/**
|
|
32
|
+
* Validator for diamond elements.
|
|
33
|
+
*/
|
|
34
|
+
class DiamondValidator extends BasicShapeValidator {
|
|
35
|
+
elementType = "diamond";
|
|
36
|
+
}
|
|
37
|
+
exports.DiamondValidator = DiamondValidator;
|
|
38
|
+
/**
|
|
39
|
+
* Validator for hexagon elements.
|
|
40
|
+
*/
|
|
41
|
+
class HexagonValidator extends BasicShapeValidator {
|
|
42
|
+
elementType = "hexagon";
|
|
43
|
+
}
|
|
44
|
+
exports.HexagonValidator = HexagonValidator;
|
|
45
|
+
/**
|
|
46
|
+
* Validator for ellipse elements.
|
|
47
|
+
*/
|
|
48
|
+
class EllipseValidator extends BasicShapeValidator {
|
|
49
|
+
elementType = "ellipse";
|
|
50
|
+
}
|
|
51
|
+
exports.EllipseValidator = EllipseValidator;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IElementTypeValidator } from "../../interfaces/element-validator.interface";
|
|
2
|
+
import { AnyElementInput } from "../../types/element-input-types";
|
|
3
|
+
import { BaseElementValidator } from "./base-element-validator";
|
|
4
|
+
/**
|
|
5
|
+
* Validator for block arrow elements.
|
|
6
|
+
*/
|
|
7
|
+
export declare class BlockArrowValidator extends BaseElementValidator implements IElementTypeValidator {
|
|
8
|
+
readonly elementType = "block-arrow";
|
|
9
|
+
validate(input: AnyElementInput): void;
|
|
10
|
+
private validateDirection;
|
|
11
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlockArrowValidator = void 0;
|
|
4
|
+
const api_errors_1 = require("../../errors/api-errors");
|
|
5
|
+
const base_element_validator_1 = require("./base-element-validator");
|
|
6
|
+
/**
|
|
7
|
+
* Validator for block arrow elements.
|
|
8
|
+
*/
|
|
9
|
+
class BlockArrowValidator extends base_element_validator_1.BaseElementValidator {
|
|
10
|
+
elementType = "block-arrow";
|
|
11
|
+
validate(input) {
|
|
12
|
+
if (input.type !== "block-arrow") {
|
|
13
|
+
throw new api_errors_1.ValidationError(`Expected type "block-arrow", got "${input.type}"`, "type");
|
|
14
|
+
}
|
|
15
|
+
const blockArrowInput = input;
|
|
16
|
+
// Validate common properties
|
|
17
|
+
this.validateCommon(blockArrowInput);
|
|
18
|
+
// Validate block-arrow-specific properties
|
|
19
|
+
this.validateColor(blockArrowInput.fillColor, "fillColor");
|
|
20
|
+
this.validateColor(blockArrowInput.strokeColor, "strokeColor");
|
|
21
|
+
this.validateStrokeWidth(blockArrowInput.strokeWidth, "strokeWidth");
|
|
22
|
+
this.validateDirection(blockArrowInput.direction);
|
|
23
|
+
}
|
|
24
|
+
validateDirection(value) {
|
|
25
|
+
if (value === undefined)
|
|
26
|
+
return;
|
|
27
|
+
if (typeof value !== "string") {
|
|
28
|
+
throw new api_errors_1.ValidationError("direction must be a string", "direction");
|
|
29
|
+
}
|
|
30
|
+
const validDirections = ["right", "left", "up", "down"];
|
|
31
|
+
if (!validDirections.includes(value)) {
|
|
32
|
+
throw new api_errors_1.ValidationError(`direction must be one of: ${validDirections.join(", ")}`, "direction");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.BlockArrowValidator = BlockArrowValidator;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IElementTypeValidator } from "../../interfaces/element-validator.interface";
|
|
2
|
+
import { AnyElementInput } from "../../types/element-input-types";
|
|
3
|
+
import { BaseElementValidator } from "./base-element-validator";
|
|
4
|
+
/**
|
|
5
|
+
* Validator for line elements.
|
|
6
|
+
*/
|
|
7
|
+
export declare class LineValidator extends BaseElementValidator implements IElementTypeValidator {
|
|
8
|
+
readonly elementType = "line";
|
|
9
|
+
validate(input: AnyElementInput): void;
|
|
10
|
+
private validateLineStyle;
|
|
11
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LineValidator = void 0;
|
|
4
|
+
const api_errors_1 = require("../../errors/api-errors");
|
|
5
|
+
const base_element_validator_1 = require("./base-element-validator");
|
|
6
|
+
/**
|
|
7
|
+
* Validator for line elements.
|
|
8
|
+
*/
|
|
9
|
+
class LineValidator extends base_element_validator_1.BaseElementValidator {
|
|
10
|
+
elementType = "line";
|
|
11
|
+
validate(input) {
|
|
12
|
+
if (input.type !== "line") {
|
|
13
|
+
throw new api_errors_1.ValidationError(`Expected type "line", got "${input.type}"`, "type");
|
|
14
|
+
}
|
|
15
|
+
const lineInput = input;
|
|
16
|
+
// Validate common properties
|
|
17
|
+
this.validateCommon(lineInput);
|
|
18
|
+
// Validate line-specific properties
|
|
19
|
+
this.validateColor(lineInput.strokeColor, "strokeColor");
|
|
20
|
+
this.validateStrokeWidth(lineInput.strokeWidth, "strokeWidth");
|
|
21
|
+
this.validateLineStyle(lineInput.lineStyle);
|
|
22
|
+
}
|
|
23
|
+
validateLineStyle(value) {
|
|
24
|
+
if (value === undefined)
|
|
25
|
+
return;
|
|
26
|
+
if (typeof value !== "string") {
|
|
27
|
+
throw new api_errors_1.ValidationError("lineStyle must be a string", "lineStyle");
|
|
28
|
+
}
|
|
29
|
+
const validStyles = ["solid", "dashed", "dotted"];
|
|
30
|
+
if (!validStyles.includes(value)) {
|
|
31
|
+
throw new api_errors_1.ValidationError(`lineStyle must be one of: ${validStyles.join(", ")}`, "lineStyle");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.LineValidator = LineValidator;
|
|
@@ -6,6 +6,9 @@ const rectangle_validator_1 = require("./element-type-validators/rectangle-valid
|
|
|
6
6
|
const text_validator_1 = require("./element-type-validators/text-validator");
|
|
7
7
|
const connector_validator_1 = require("./element-type-validators/connector-validator");
|
|
8
8
|
const uml_validators_1 = require("./element-type-validators/uml-validators");
|
|
9
|
+
const basic_shape_validators_1 = require("./element-type-validators/basic-shape-validators");
|
|
10
|
+
const line_validator_1 = require("./element-type-validators/line-validator");
|
|
11
|
+
const block_arrow_validator_1 = require("./element-type-validators/block-arrow-validator");
|
|
9
12
|
const custom_shape_validator_1 = require("./element-type-validators/custom-shape-validator");
|
|
10
13
|
/**
|
|
11
14
|
* Registry for element type validators.
|
|
@@ -31,6 +34,12 @@ class ElementValidatorRegistry {
|
|
|
31
34
|
this.register(new uml_validators_1.UmlPackageValidator());
|
|
32
35
|
this.register(new uml_validators_1.UmlArtifactValidator());
|
|
33
36
|
this.register(new uml_validators_1.UmlNoteValidator());
|
|
37
|
+
this.register(new basic_shape_validators_1.TriangleValidator());
|
|
38
|
+
this.register(new basic_shape_validators_1.DiamondValidator());
|
|
39
|
+
this.register(new basic_shape_validators_1.HexagonValidator());
|
|
40
|
+
this.register(new basic_shape_validators_1.EllipseValidator());
|
|
41
|
+
this.register(new line_validator_1.LineValidator());
|
|
42
|
+
this.register(new block_arrow_validator_1.BlockArrowValidator());
|
|
34
43
|
}
|
|
35
44
|
register(validator) {
|
|
36
45
|
this.validators.set(validator.elementType, validator);
|