@graph-knowledge/api 0.1.2 → 0.1.3

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.
Files changed (45) hide show
  1. package/package.json +3 -3
  2. package/src/index.js +19 -6
  3. package/src/lib/clients/firebase-auth-client.js +16 -12
  4. package/src/lib/clients/firebase-firestore-client.js +23 -19
  5. package/src/lib/config/api-config.js +2 -0
  6. package/src/lib/constants/element-defaults.js +5 -2
  7. package/src/lib/errors/api-errors.js +13 -5
  8. package/src/lib/graph-knowledge-api.js +29 -25
  9. package/src/lib/interfaces/auth-client.interface.js +2 -0
  10. package/src/lib/interfaces/batch-operations.interface.d.ts +1 -1
  11. package/src/lib/interfaces/batch-operations.interface.js +2 -0
  12. package/src/lib/interfaces/document-operations.interface.js +2 -0
  13. package/src/lib/interfaces/element-operations.interface.d.ts +1 -1
  14. package/src/lib/interfaces/element-operations.interface.js +2 -0
  15. package/src/lib/interfaces/element-validator.interface.js +2 -0
  16. package/src/lib/interfaces/firestore-client.interface.js +2 -0
  17. package/src/lib/interfaces/node-operations.interface.d.ts +1 -1
  18. package/src/lib/interfaces/node-operations.interface.js +2 -0
  19. package/src/lib/models/document.model.js +4 -1
  20. package/src/lib/models/index.js +5 -1
  21. package/src/lib/operations/batch-operations.d.ts +1 -1
  22. package/src/lib/operations/batch-operations.js +15 -11
  23. package/src/lib/operations/document-operations.js +14 -10
  24. package/src/lib/operations/element-operations.d.ts +1 -1
  25. package/src/lib/operations/element-operations.js +18 -14
  26. package/src/lib/operations/node-operations.d.ts +1 -1
  27. package/src/lib/operations/node-operations.js +10 -6
  28. package/src/lib/testing/index.js +7 -2
  29. package/src/lib/testing/mock-auth-client.js +8 -4
  30. package/src/lib/testing/mock-firestore-client.js +5 -1
  31. package/src/lib/types/api-types.d.ts +1 -1
  32. package/src/lib/types/api-types.js +2 -0
  33. package/src/lib/types/element-input-types.js +2 -0
  34. package/src/lib/utils/link-level-manager.d.ts +1 -1
  35. package/src/lib/utils/link-level-manager.js +5 -1
  36. package/src/lib/utils/uuid.js +4 -1
  37. package/src/lib/validators/document-validator.js +18 -14
  38. package/src/lib/validators/element-type-validators/base-element-validator.js +20 -16
  39. package/src/lib/validators/element-type-validators/connector-validator.js +13 -9
  40. package/src/lib/validators/element-type-validators/custom-shape-validator.js +11 -6
  41. package/src/lib/validators/element-type-validators/rectangle-validator.js +10 -6
  42. package/src/lib/validators/element-type-validators/text-validator.js +17 -13
  43. package/src/lib/validators/element-type-validators/uml-validators.js +29 -20
  44. package/src/lib/validators/element-validator-registry.js +22 -18
  45. package/src/lib/validators/node-validator.js +22 -18
@@ -1,10 +1,13 @@
1
- import { generateUuid } from "../utils/uuid";
2
- import { NotFoundError } from "../errors/api-errors";
3
- import { DEFAULT_ELEMENT_DIMENSIONS, DEFAULT_CUSTOM_SHAPE_DIMENSIONS } from "../constants/element-defaults";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ElementOperations = void 0;
4
+ const uuid_1 = require("../utils/uuid");
5
+ const api_errors_1 = require("../errors/api-errors");
6
+ const element_defaults_1 = require("../constants/element-defaults");
4
7
  /**
5
8
  * Implementation of element CRUD operations.
6
9
  */
7
- export class ElementOperations {
10
+ class ElementOperations {
8
11
  firestore;
9
12
  auth;
10
13
  validatorRegistry;
@@ -18,11 +21,11 @@ export class ElementOperations {
18
21
  const nodePath = `documents/${documentId}/nodes/${nodeId}`;
19
22
  const node = await this.firestore.getDocument(nodePath);
20
23
  if (!node) {
21
- throw new NotFoundError(`Node ${nodeId} not found`);
24
+ throw new api_errors_1.NotFoundError(`Node ${nodeId} not found`);
22
25
  }
23
26
  const element = node.elements.find((e) => e.id === elementId);
24
27
  if (!element) {
25
- throw new NotFoundError(`Element ${elementId} not found`);
28
+ throw new api_errors_1.NotFoundError(`Element ${elementId} not found`);
26
29
  }
27
30
  return element;
28
31
  }
@@ -31,7 +34,7 @@ export class ElementOperations {
31
34
  const nodePath = `documents/${documentId}/nodes/${nodeId}`;
32
35
  const node = await this.firestore.getDocument(nodePath);
33
36
  if (!node) {
34
- throw new NotFoundError(`Node ${nodeId} not found`);
37
+ throw new api_errors_1.NotFoundError(`Node ${nodeId} not found`);
35
38
  }
36
39
  return node.elements || [];
37
40
  }
@@ -45,14 +48,14 @@ export class ElementOperations {
45
48
  const nodePath = `documents/${documentId}/nodes/${nodeId}`;
46
49
  const node = await this.firestore.getDocument(nodePath);
47
50
  if (!node) {
48
- throw new NotFoundError(`Node ${nodeId} not found`);
51
+ throw new api_errors_1.NotFoundError(`Node ${nodeId} not found`);
49
52
  }
50
53
  const defaults = this.getDefaultDimensions(input.type);
51
54
  // Connectors have optional x/y since their position is derived from connected elements
52
55
  const x = input.x ?? 0;
53
56
  const y = input.y ?? 0;
54
57
  const element = {
55
- id: generateUuid(),
58
+ id: (0, uuid_1.generateUuid)(),
56
59
  elementType: input.type,
57
60
  x,
58
61
  y,
@@ -79,11 +82,11 @@ export class ElementOperations {
79
82
  const nodePath = `documents/${documentId}/nodes/${nodeId}`;
80
83
  const node = await this.firestore.getDocument(nodePath);
81
84
  if (!node) {
82
- throw new NotFoundError(`Node ${nodeId} not found`);
85
+ throw new api_errors_1.NotFoundError(`Node ${nodeId} not found`);
83
86
  }
84
87
  const elementIndex = node.elements.findIndex((e) => e.id === elementId);
85
88
  if (elementIndex === -1) {
86
- throw new NotFoundError(`Element ${elementId} not found`);
89
+ throw new api_errors_1.NotFoundError(`Element ${elementId} not found`);
87
90
  }
88
91
  const existingElement = node.elements[elementIndex];
89
92
  const updatedElement = {
@@ -120,7 +123,7 @@ export class ElementOperations {
120
123
  const nodePath = `documents/${documentId}/nodes/${nodeId}`;
121
124
  const node = await this.firestore.getDocument(nodePath);
122
125
  if (!node) {
123
- throw new NotFoundError(`Node ${nodeId} not found`);
126
+ throw new api_errors_1.NotFoundError(`Node ${nodeId} not found`);
124
127
  }
125
128
  const updatedElements = node.elements.filter((e) => e.id !== elementId);
126
129
  await this.firestore.updateDocument(nodePath, {
@@ -132,9 +135,9 @@ export class ElementOperations {
132
135
  */
133
136
  getDefaultDimensions(type) {
134
137
  if (type.startsWith("custom:")) {
135
- return DEFAULT_CUSTOM_SHAPE_DIMENSIONS;
138
+ return element_defaults_1.DEFAULT_CUSTOM_SHAPE_DIMENSIONS;
136
139
  }
137
- return (DEFAULT_ELEMENT_DIMENSIONS[type] ?? DEFAULT_CUSTOM_SHAPE_DIMENSIONS);
140
+ return (element_defaults_1.DEFAULT_ELEMENT_DIMENSIONS[type] ?? element_defaults_1.DEFAULT_CUSTOM_SHAPE_DIMENSIONS);
138
141
  }
139
142
  /**
140
143
  * Normalizes rotation to integer in range [0, 360).
@@ -173,3 +176,4 @@ export class ElementOperations {
173
176
  return props;
174
177
  }
175
178
  }
179
+ exports.ElementOperations = ElementOperations;
@@ -1,4 +1,4 @@
1
- import { GraphNode } from "@graph-knowledge/domain";
1
+ import { GraphNode } from "../models";
2
2
  import { INodeOperations } from "../interfaces/node-operations.interface";
3
3
  import { IFirestoreClient } from "../interfaces/firestore-client.interface";
4
4
  import { IAuthClient } from "../interfaces/auth-client.interface";
@@ -1,12 +1,15 @@
1
- import { generateUuid } from "../utils/uuid";
2
- import { NotFoundError } from "../errors/api-errors";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeOperations = void 0;
4
+ const uuid_1 = require("../utils/uuid");
5
+ const api_errors_1 = require("../errors/api-errors");
3
6
  // Default canvas dimensions
4
7
  const DEFAULT_CANVAS_WIDTH = 1920;
5
8
  const DEFAULT_CANVAS_HEIGHT = 1080;
6
9
  /**
7
10
  * Implementation of node CRUD operations.
8
11
  */
9
- export class NodeOperations {
12
+ class NodeOperations {
10
13
  firestore;
11
14
  auth;
12
15
  validator;
@@ -16,7 +19,7 @@ export class NodeOperations {
16
19
  this.validator = validator;
17
20
  }
18
21
  async create(documentId, input) {
19
- const nodeId = generateUuid();
22
+ const nodeId = (0, uuid_1.generateUuid)();
20
23
  return this.createNodeWithId(documentId, nodeId, input);
21
24
  }
22
25
  async createWithId(documentId, nodeId, input) {
@@ -54,7 +57,7 @@ export class NodeOperations {
54
57
  this.auth.requireAuth();
55
58
  const node = await this.firestore.getDocument(`documents/${documentId}/nodes/${nodeId}`);
56
59
  if (!node) {
57
- throw new NotFoundError(`Node ${nodeId} not found`);
60
+ throw new api_errors_1.NotFoundError(`Node ${nodeId} not found`);
58
61
  }
59
62
  return node;
60
63
  }
@@ -67,7 +70,7 @@ export class NodeOperations {
67
70
  this.validator.validateUpdate(input);
68
71
  const node = await this.firestore.getDocument(`documents/${documentId}/nodes/${nodeId}`);
69
72
  if (!node) {
70
- throw new NotFoundError(`Node ${nodeId} not found`);
73
+ throw new api_errors_1.NotFoundError(`Node ${nodeId} not found`);
71
74
  }
72
75
  const updates = {};
73
76
  if (input.title !== undefined)
@@ -87,3 +90,4 @@ export class NodeOperations {
87
90
  await this.firestore.deleteDocument(`documents/${documentId}/nodes/${nodeId}`);
88
91
  }
89
92
  }
93
+ exports.NodeOperations = NodeOperations;
@@ -1,3 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockFirestoreClient = exports.MockAuthClient = void 0;
1
4
  // Testing utilities for @graph-knowledge/api
2
- export { MockAuthClient } from "./mock-auth-client";
3
- export { MockFirestoreClient } from "./mock-firestore-client";
5
+ var mock_auth_client_1 = require("./mock-auth-client");
6
+ Object.defineProperty(exports, "MockAuthClient", { enumerable: true, get: function () { return mock_auth_client_1.MockAuthClient; } });
7
+ var mock_firestore_client_1 = require("./mock-firestore-client");
8
+ Object.defineProperty(exports, "MockFirestoreClient", { enumerable: true, get: function () { return mock_firestore_client_1.MockFirestoreClient; } });
@@ -1,8 +1,11 @@
1
- import { AuthenticationError, PermissionError } from "../errors/api-errors";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockAuthClient = void 0;
4
+ const api_errors_1 = require("../errors/api-errors");
2
5
  /**
3
6
  * Mock authentication client for testing.
4
7
  */
5
- export class MockAuthClient {
8
+ class MockAuthClient {
6
9
  _currentUserId = null;
7
10
  _isPremium = false;
8
11
  constructor(options) {
@@ -21,7 +24,7 @@ export class MockAuthClient {
21
24
  }
22
25
  requireAuth() {
23
26
  if (!this._currentUserId) {
24
- throw new AuthenticationError("Not authenticated");
27
+ throw new api_errors_1.AuthenticationError("Not authenticated");
25
28
  }
26
29
  return this._currentUserId;
27
30
  }
@@ -37,7 +40,7 @@ export class MockAuthClient {
37
40
  async requirePremium() {
38
41
  this.requireAuth();
39
42
  if (!this._isPremium) {
40
- throw new PermissionError("Premium subscription required");
43
+ throw new api_errors_1.PermissionError("Premium subscription required");
41
44
  }
42
45
  }
43
46
  /**
@@ -47,3 +50,4 @@ export class MockAuthClient {
47
50
  this._isPremium = isPremium;
48
51
  }
49
52
  }
53
+ exports.MockAuthClient = MockAuthClient;
@@ -1,3 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockFirestoreClient = void 0;
1
4
  /**
2
5
  * Mock batch writer for testing.
3
6
  */
@@ -58,7 +61,7 @@ class MockBatchWriter {
58
61
  /**
59
62
  * Mock Firestore client for testing.
60
63
  */
61
- export class MockFirestoreClient {
64
+ class MockFirestoreClient {
62
65
  store = new Map();
63
66
  async getDocument(path) {
64
67
  const data = this.store.get(path);
@@ -124,3 +127,4 @@ export class MockFirestoreClient {
124
127
  this.store.set(path, { id, ...data });
125
128
  }
126
129
  }
130
+ exports.MockFirestoreClient = MockFirestoreClient;
@@ -1,4 +1,4 @@
1
- import { Document, GraphNode } from "@graph-knowledge/domain";
1
+ import { Document, GraphNode } from "../models";
2
2
  /**
3
3
  * Input for creating a new document.
4
4
  */
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,5 @@
1
+ "use strict";
1
2
  // ============================================================================
2
3
  // Base Element Input
3
4
  // ============================================================================
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,4 @@
1
- import { GraphNode } from "@graph-knowledge/domain";
1
+ import { GraphNode } from "../models";
2
2
  /**
3
3
  * Represents a change to a node's level.
4
4
  */
@@ -1,3 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LinkLevelManager = void 0;
1
4
  /**
2
5
  * Pure utility for managing node level calculations.
3
6
  * Levels represent distance from root node in the graph.
@@ -7,7 +10,7 @@
7
10
  *
8
11
  * Extracted from web app's LinkManagerService for use in headless API.
9
12
  */
10
- export class LinkLevelManager {
13
+ class LinkLevelManager {
11
14
  /**
12
15
  * Called when a link is created (element.isLink set to true with linkTarget).
13
16
  * @param sourceNodeId The node containing the linking element
@@ -198,3 +201,4 @@ export class LinkLevelManager {
198
201
  }
199
202
  }
200
203
  }
204
+ exports.LinkLevelManager = LinkLevelManager;
@@ -1,8 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateUuid = generateUuid;
1
4
  /**
2
5
  * Generates a UUID v4.
3
6
  * Uses crypto.randomUUID() if available, otherwise falls back to a polyfill.
4
7
  */
5
- export function generateUuid() {
8
+ function generateUuid() {
6
9
  if (typeof crypto !== "undefined" &&
7
10
  typeof crypto.randomUUID === "function") {
8
11
  return crypto.randomUUID();
@@ -1,8 +1,11 @@
1
- import { ValidationError } from "../errors/api-errors";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentValidator = void 0;
4
+ const api_errors_1 = require("../errors/api-errors");
2
5
  /**
3
6
  * Validator for document operations.
4
7
  */
5
- export class DocumentValidator {
8
+ class DocumentValidator {
6
9
  /**
7
10
  * Validates input for document creation.
8
11
  * @param input The creation input to validate
@@ -10,16 +13,16 @@ export class DocumentValidator {
10
13
  */
11
14
  validateCreate(input) {
12
15
  if (!input.title || typeof input.title !== "string") {
13
- throw new ValidationError("title is required", "title");
16
+ throw new api_errors_1.ValidationError("title is required", "title");
14
17
  }
15
18
  if (input.title.trim().length === 0) {
16
- throw new ValidationError("title cannot be empty", "title");
19
+ throw new api_errors_1.ValidationError("title cannot be empty", "title");
17
20
  }
18
21
  if (input.title.length > 200) {
19
- throw new ValidationError("title must be 200 characters or less", "title");
22
+ throw new api_errors_1.ValidationError("title must be 200 characters or less", "title");
20
23
  }
21
24
  if (input.content !== undefined && typeof input.content !== "string") {
22
- throw new ValidationError("content must be a string", "content");
25
+ throw new api_errors_1.ValidationError("content must be a string", "content");
23
26
  }
24
27
  this.validateCanvasDimensions(input.canvasWidth, input.canvasHeight);
25
28
  }
@@ -31,17 +34,17 @@ export class DocumentValidator {
31
34
  validateUpdate(input) {
32
35
  if (input.title !== undefined) {
33
36
  if (typeof input.title !== "string") {
34
- throw new ValidationError("title must be a string", "title");
37
+ throw new api_errors_1.ValidationError("title must be a string", "title");
35
38
  }
36
39
  if (input.title.trim().length === 0) {
37
- throw new ValidationError("title cannot be empty", "title");
40
+ throw new api_errors_1.ValidationError("title cannot be empty", "title");
38
41
  }
39
42
  if (input.title.length > 200) {
40
- throw new ValidationError("title must be 200 characters or less", "title");
43
+ throw new api_errors_1.ValidationError("title must be 200 characters or less", "title");
41
44
  }
42
45
  }
43
46
  if (input.content !== undefined && typeof input.content !== "string") {
44
- throw new ValidationError("content must be a string", "content");
47
+ throw new api_errors_1.ValidationError("content must be a string", "content");
45
48
  }
46
49
  }
47
50
  /**
@@ -50,19 +53,20 @@ export class DocumentValidator {
50
53
  validateCanvasDimensions(width, height) {
51
54
  if (width !== undefined) {
52
55
  if (typeof width !== "number" || isNaN(width)) {
53
- throw new ValidationError("canvasWidth must be a valid number", "canvasWidth");
56
+ throw new api_errors_1.ValidationError("canvasWidth must be a valid number", "canvasWidth");
54
57
  }
55
58
  if (width < 100 || width > 10000) {
56
- throw new ValidationError("canvasWidth must be between 100 and 10000", "canvasWidth");
59
+ throw new api_errors_1.ValidationError("canvasWidth must be between 100 and 10000", "canvasWidth");
57
60
  }
58
61
  }
59
62
  if (height !== undefined) {
60
63
  if (typeof height !== "number" || isNaN(height)) {
61
- throw new ValidationError("canvasHeight must be a valid number", "canvasHeight");
64
+ throw new api_errors_1.ValidationError("canvasHeight must be a valid number", "canvasHeight");
62
65
  }
63
66
  if (height < 100 || height > 10000) {
64
- throw new ValidationError("canvasHeight must be between 100 and 10000", "canvasHeight");
67
+ throw new api_errors_1.ValidationError("canvasHeight must be between 100 and 10000", "canvasHeight");
65
68
  }
66
69
  }
67
70
  }
68
71
  }
72
+ exports.DocumentValidator = DocumentValidator;
@@ -1,9 +1,12 @@
1
- import { ValidationError } from "../../errors/api-errors";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseElementValidator = void 0;
4
+ const api_errors_1 = require("../../errors/api-errors");
2
5
  /**
3
6
  * Base class for element type validators.
4
7
  * Provides common validation logic for position, dimensions, and colors.
5
8
  */
6
- export class BaseElementValidator {
9
+ class BaseElementValidator {
7
10
  /**
8
11
  * Validates common element properties (position, dimensions, rotation).
9
12
  * @param input The element input to validate
@@ -19,16 +22,16 @@ export class BaseElementValidator {
19
22
  */
20
23
  validatePosition(input) {
21
24
  if (typeof input.x !== "number" || isNaN(input.x)) {
22
- throw new ValidationError("x must be a valid number", "x");
25
+ throw new api_errors_1.ValidationError("x must be a valid number", "x");
23
26
  }
24
27
  if (typeof input.y !== "number" || isNaN(input.y)) {
25
- throw new ValidationError("y must be a valid number", "y");
28
+ throw new api_errors_1.ValidationError("y must be a valid number", "y");
26
29
  }
27
30
  if (input.x < 0) {
28
- throw new ValidationError("x must be non-negative", "x");
31
+ throw new api_errors_1.ValidationError("x must be non-negative", "x");
29
32
  }
30
33
  if (input.y < 0) {
31
- throw new ValidationError("y must be non-negative", "y");
34
+ throw new api_errors_1.ValidationError("y must be non-negative", "y");
32
35
  }
33
36
  }
34
37
  /**
@@ -37,18 +40,18 @@ export class BaseElementValidator {
37
40
  validateDimensions(input) {
38
41
  if (input.width !== undefined) {
39
42
  if (typeof input.width !== "number" || isNaN(input.width)) {
40
- throw new ValidationError("width must be a valid number", "width");
43
+ throw new api_errors_1.ValidationError("width must be a valid number", "width");
41
44
  }
42
45
  if (input.width < 0) {
43
- throw new ValidationError("width must be non-negative", "width");
46
+ throw new api_errors_1.ValidationError("width must be non-negative", "width");
44
47
  }
45
48
  }
46
49
  if (input.height !== undefined) {
47
50
  if (typeof input.height !== "number" || isNaN(input.height)) {
48
- throw new ValidationError("height must be a valid number", "height");
51
+ throw new api_errors_1.ValidationError("height must be a valid number", "height");
49
52
  }
50
53
  if (input.height < 0) {
51
- throw new ValidationError("height must be non-negative", "height");
54
+ throw new api_errors_1.ValidationError("height must be non-negative", "height");
52
55
  }
53
56
  }
54
57
  }
@@ -58,10 +61,10 @@ export class BaseElementValidator {
58
61
  validateRotation(input) {
59
62
  if (input.rotation !== undefined) {
60
63
  if (typeof input.rotation !== "number" || isNaN(input.rotation)) {
61
- throw new ValidationError("rotation must be a valid number", "rotation");
64
+ throw new api_errors_1.ValidationError("rotation must be a valid number", "rotation");
62
65
  }
63
66
  if (input.rotation < 0 || input.rotation >= 360) {
64
- throw new ValidationError("rotation must be in range [0, 360)", "rotation");
67
+ throw new api_errors_1.ValidationError("rotation must be in range [0, 360)", "rotation");
65
68
  }
66
69
  }
67
70
  }
@@ -74,10 +77,10 @@ export class BaseElementValidator {
74
77
  if (value === undefined)
75
78
  return;
76
79
  if (typeof value !== "string") {
77
- throw new ValidationError(`${field} must be a string`, field);
80
+ throw new api_errors_1.ValidationError(`${field} must be a string`, field);
78
81
  }
79
82
  if (!value.match(/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/)) {
80
- throw new ValidationError(`${field} must be a valid hex color (e.g., #FF0000)`, field);
83
+ throw new api_errors_1.ValidationError(`${field} must be a valid hex color (e.g., #FF0000)`, field);
81
84
  }
82
85
  }
83
86
  /**
@@ -87,10 +90,11 @@ export class BaseElementValidator {
87
90
  if (value === undefined)
88
91
  return;
89
92
  if (typeof value !== "number" || isNaN(value)) {
90
- throw new ValidationError(`${field} must be a valid number`, field);
93
+ throw new api_errors_1.ValidationError(`${field} must be a valid number`, field);
91
94
  }
92
95
  if (value < 0) {
93
- throw new ValidationError(`${field} must be non-negative`, field);
96
+ throw new api_errors_1.ValidationError(`${field} must be non-negative`, field);
94
97
  }
95
98
  }
96
99
  }
100
+ exports.BaseElementValidator = BaseElementValidator;
@@ -1,5 +1,8 @@
1
- import { ValidationError } from "../../errors/api-errors";
2
- import { BaseElementValidator } from "./base-element-validator";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectorValidator = void 0;
4
+ const api_errors_1 = require("../../errors/api-errors");
5
+ const base_element_validator_1 = require("./base-element-validator");
3
6
  /**
4
7
  * Valid connector anchor points matching the graph editor's snap geometry labels.
5
8
  */
@@ -15,11 +18,11 @@ const VALID_MARKERS = ["none", "arrow", "diamond", "circle"];
15
18
  /**
16
19
  * Validator for connector elements.
17
20
  */
18
- export class ConnectorValidator extends BaseElementValidator {
21
+ class ConnectorValidator extends base_element_validator_1.BaseElementValidator {
19
22
  elementType = "connector";
20
23
  validate(input) {
21
24
  if (input.type !== "connector") {
22
- throw new ValidationError(`Expected type "connector", got "${input.type}"`, "type");
25
+ throw new api_errors_1.ValidationError(`Expected type "connector", got "${input.type}"`, "type");
23
26
  }
24
27
  const connectorInput = input;
25
28
  // Note: Connectors don't use x/y positions - they're determined by connected elements
@@ -27,11 +30,11 @@ export class ConnectorValidator extends BaseElementValidator {
27
30
  // Required fields
28
31
  if (!connectorInput.startElementId ||
29
32
  typeof connectorInput.startElementId !== "string") {
30
- throw new ValidationError("startElementId is required", "startElementId");
33
+ throw new api_errors_1.ValidationError("startElementId is required", "startElementId");
31
34
  }
32
35
  if (!connectorInput.endElementId ||
33
36
  typeof connectorInput.endElementId !== "string") {
34
- throw new ValidationError("endElementId is required", "endElementId");
37
+ throw new api_errors_1.ValidationError("endElementId is required", "endElementId");
35
38
  }
36
39
  // Validate connector-specific properties
37
40
  this.validateAnchor(connectorInput.startAnchor, "startAnchor");
@@ -46,21 +49,22 @@ export class ConnectorValidator extends BaseElementValidator {
46
49
  if (value === undefined)
47
50
  return;
48
51
  if (!VALID_ANCHORS.includes(value)) {
49
- throw new ValidationError(`${field} must be one of: ${VALID_ANCHORS.join(", ")}`, field);
52
+ throw new api_errors_1.ValidationError(`${field} must be one of: ${VALID_ANCHORS.join(", ")}`, field);
50
53
  }
51
54
  }
52
55
  validateLineStyle(value) {
53
56
  if (value === undefined)
54
57
  return;
55
58
  if (!VALID_LINE_STYLES.includes(value)) {
56
- throw new ValidationError(`lineStyle must be one of: ${VALID_LINE_STYLES.join(", ")}`, "lineStyle");
59
+ throw new api_errors_1.ValidationError(`lineStyle must be one of: ${VALID_LINE_STYLES.join(", ")}`, "lineStyle");
57
60
  }
58
61
  }
59
62
  validateMarker(value, field) {
60
63
  if (value === undefined)
61
64
  return;
62
65
  if (!VALID_MARKERS.includes(value)) {
63
- throw new ValidationError(`${field} must be one of: ${VALID_MARKERS.join(", ")}`, field);
66
+ throw new api_errors_1.ValidationError(`${field} must be one of: ${VALID_MARKERS.join(", ")}`, field);
64
67
  }
65
68
  }
66
69
  }
70
+ exports.ConnectorValidator = ConnectorValidator;
@@ -1,10 +1,14 @@
1
- import { ValidationError } from "../../errors/api-errors";
2
- import { BaseElementValidator } from "./base-element-validator";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomShapeValidator = void 0;
4
+ exports.createCustomShapeValidator = createCustomShapeValidator;
5
+ const api_errors_1 = require("../../errors/api-errors");
6
+ const base_element_validator_1 = require("./base-element-validator");
3
7
  /**
4
8
  * Validator for custom shape elements.
5
9
  * Handles elements with type "custom:{shapeId}".
6
10
  */
7
- export class CustomShapeValidator extends BaseElementValidator {
11
+ class CustomShapeValidator extends base_element_validator_1.BaseElementValidator {
8
12
  shapeId;
9
13
  /**
10
14
  * Creates a validator for a specific custom shape.
@@ -19,7 +23,7 @@ export class CustomShapeValidator extends BaseElementValidator {
19
23
  }
20
24
  validate(input) {
21
25
  if (!input.type.startsWith("custom:")) {
22
- throw new ValidationError(`Expected custom shape type, got "${input.type}"`, "type");
26
+ throw new api_errors_1.ValidationError(`Expected custom shape type, got "${input.type}"`, "type");
23
27
  }
24
28
  const customInput = input;
25
29
  // Validate common properties
@@ -27,7 +31,7 @@ export class CustomShapeValidator extends BaseElementValidator {
27
31
  // customShapeId is required
28
32
  if (!customInput.customShapeId ||
29
33
  typeof customInput.customShapeId !== "string") {
30
- throw new ValidationError("customShapeId is required for custom shapes", "customShapeId");
34
+ throw new api_errors_1.ValidationError("customShapeId is required for custom shapes", "customShapeId");
31
35
  }
32
36
  // Validate optional style properties
33
37
  this.validateColor(customInput.fillColor, "fillColor");
@@ -35,10 +39,11 @@ export class CustomShapeValidator extends BaseElementValidator {
35
39
  this.validateStrokeWidth(customInput.strokeWidth, "strokeWidth");
36
40
  }
37
41
  }
42
+ exports.CustomShapeValidator = CustomShapeValidator;
38
43
  /**
39
44
  * Factory function to create a custom shape validator.
40
45
  * @param shapeId The custom shape ID
41
46
  */
42
- export function createCustomShapeValidator(shapeId) {
47
+ function createCustomShapeValidator(shapeId) {
43
48
  return new CustomShapeValidator(shapeId);
44
49
  }
@@ -1,13 +1,16 @@
1
- import { ValidationError } from "../../errors/api-errors";
2
- import { BaseElementValidator } from "./base-element-validator";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RectangleValidator = void 0;
4
+ const api_errors_1 = require("../../errors/api-errors");
5
+ const base_element_validator_1 = require("./base-element-validator");
3
6
  /**
4
7
  * Validator for rectangle elements.
5
8
  */
6
- export class RectangleValidator extends BaseElementValidator {
9
+ class RectangleValidator extends base_element_validator_1.BaseElementValidator {
7
10
  elementType = "rectangle";
8
11
  validate(input) {
9
12
  if (input.type !== "rectangle") {
10
- throw new ValidationError(`Expected type "rectangle", got "${input.type}"`, "type");
13
+ throw new api_errors_1.ValidationError(`Expected type "rectangle", got "${input.type}"`, "type");
11
14
  }
12
15
  const rectangleInput = input;
13
16
  // Validate common properties
@@ -22,10 +25,11 @@ export class RectangleValidator extends BaseElementValidator {
22
25
  if (value === undefined)
23
26
  return;
24
27
  if (typeof value !== "number" || isNaN(value)) {
25
- throw new ValidationError("cornerRadius must be a valid number", "cornerRadius");
28
+ throw new api_errors_1.ValidationError("cornerRadius must be a valid number", "cornerRadius");
26
29
  }
27
30
  if (value < 0) {
28
- throw new ValidationError("cornerRadius must be non-negative", "cornerRadius");
31
+ throw new api_errors_1.ValidationError("cornerRadius must be non-negative", "cornerRadius");
29
32
  }
30
33
  }
31
34
  }
35
+ exports.RectangleValidator = RectangleValidator;