@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.
Files changed (74) hide show
  1. package/README.md +396 -0
  2. package/package.json +44 -0
  3. package/src/index.d.ts +18 -0
  4. package/src/index.js +19 -0
  5. package/src/lib/clients/firebase-auth-client.d.ts +24 -0
  6. package/src/lib/clients/firebase-auth-client.js +76 -0
  7. package/src/lib/clients/firebase-firestore-client.d.ts +22 -0
  8. package/src/lib/clients/firebase-firestore-client.js +79 -0
  9. package/src/lib/config/api-config.d.ts +20 -0
  10. package/src/lib/config/api-config.js +0 -0
  11. package/src/lib/constants/element-defaults.d.ts +15 -0
  12. package/src/lib/constants/element-defaults.js +19 -0
  13. package/src/lib/errors/api-errors.d.ts +33 -0
  14. package/src/lib/errors/api-errors.js +51 -0
  15. package/src/lib/graph-knowledge-api.d.ts +106 -0
  16. package/src/lib/graph-knowledge-api.js +154 -0
  17. package/src/lib/interfaces/auth-client.interface.d.ts +35 -0
  18. package/src/lib/interfaces/auth-client.interface.js +0 -0
  19. package/src/lib/interfaces/batch-operations.interface.d.ts +46 -0
  20. package/src/lib/interfaces/batch-operations.interface.js +0 -0
  21. package/src/lib/interfaces/document-operations.interface.d.ts +51 -0
  22. package/src/lib/interfaces/document-operations.interface.js +0 -0
  23. package/src/lib/interfaces/element-operations.interface.d.ts +57 -0
  24. package/src/lib/interfaces/element-operations.interface.js +0 -0
  25. package/src/lib/interfaces/element-validator.interface.d.ts +42 -0
  26. package/src/lib/interfaces/element-validator.interface.js +0 -0
  27. package/src/lib/interfaces/firestore-client.interface.d.ts +62 -0
  28. package/src/lib/interfaces/firestore-client.interface.js +0 -0
  29. package/src/lib/interfaces/node-operations.interface.d.ts +62 -0
  30. package/src/lib/interfaces/node-operations.interface.js +0 -0
  31. package/src/lib/models/document.model.d.ts +73 -0
  32. package/src/lib/models/document.model.js +13 -0
  33. package/src/lib/models/index.d.ts +6 -0
  34. package/src/lib/models/index.js +5 -0
  35. package/src/lib/operations/batch-operations.d.ts +30 -0
  36. package/src/lib/operations/batch-operations.js +181 -0
  37. package/src/lib/operations/document-operations.d.ts +20 -0
  38. package/src/lib/operations/document-operations.js +108 -0
  39. package/src/lib/operations/element-operations.d.ts +33 -0
  40. package/src/lib/operations/element-operations.js +175 -0
  41. package/src/lib/operations/node-operations.d.ts +22 -0
  42. package/src/lib/operations/node-operations.js +89 -0
  43. package/src/lib/testing/index.d.ts +2 -0
  44. package/src/lib/testing/index.js +3 -0
  45. package/src/lib/testing/mock-auth-client.d.ts +26 -0
  46. package/src/lib/testing/mock-auth-client.js +49 -0
  47. package/src/lib/testing/mock-firestore-client.d.ts +32 -0
  48. package/src/lib/testing/mock-firestore-client.js +126 -0
  49. package/src/lib/types/api-types.d.ts +61 -0
  50. package/src/lib/types/api-types.js +0 -0
  51. package/src/lib/types/element-input-types.d.ts +237 -0
  52. package/src/lib/types/element-input-types.js +3 -0
  53. package/src/lib/utils/link-level-manager.d.ts +66 -0
  54. package/src/lib/utils/link-level-manager.js +200 -0
  55. package/src/lib/utils/uuid.d.ts +5 -0
  56. package/src/lib/utils/uuid.js +16 -0
  57. package/src/lib/validators/document-validator.d.ts +22 -0
  58. package/src/lib/validators/document-validator.js +68 -0
  59. package/src/lib/validators/element-type-validators/base-element-validator.d.ts +35 -0
  60. package/src/lib/validators/element-type-validators/base-element-validator.js +96 -0
  61. package/src/lib/validators/element-type-validators/connector-validator.d.ts +13 -0
  62. package/src/lib/validators/element-type-validators/connector-validator.js +66 -0
  63. package/src/lib/validators/element-type-validators/custom-shape-validator.d.ts +22 -0
  64. package/src/lib/validators/element-type-validators/custom-shape-validator.js +44 -0
  65. package/src/lib/validators/element-type-validators/rectangle-validator.d.ts +11 -0
  66. package/src/lib/validators/element-type-validators/rectangle-validator.js +31 -0
  67. package/src/lib/validators/element-type-validators/text-validator.d.ts +14 -0
  68. package/src/lib/validators/element-type-validators/text-validator.js +66 -0
  69. package/src/lib/validators/element-type-validators/uml-validators.d.ts +58 -0
  70. package/src/lib/validators/element-type-validators/uml-validators.js +123 -0
  71. package/src/lib/validators/element-validator-registry.d.ts +18 -0
  72. package/src/lib/validators/element-validator-registry.js +58 -0
  73. package/src/lib/validators/node-validator.d.ts +26 -0
  74. package/src/lib/validators/node-validator.js +90 -0
File without changes
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Default dimensions per element type.
3
+ * Shared between ElementOperations and BatchOperations.
4
+ */
5
+ export declare const DEFAULT_ELEMENT_DIMENSIONS: Record<string, {
6
+ width: number;
7
+ height: number;
8
+ }>;
9
+ /**
10
+ * Default dimensions for custom shapes.
11
+ */
12
+ export declare const DEFAULT_CUSTOM_SHAPE_DIMENSIONS: {
13
+ width: number;
14
+ height: number;
15
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Default dimensions per element type.
3
+ * Shared between ElementOperations and BatchOperations.
4
+ */
5
+ export const DEFAULT_ELEMENT_DIMENSIONS = {
6
+ rectangle: { width: 150, height: 120 },
7
+ text: { width: 100, height: 30 },
8
+ connector: { width: 0, height: 0 },
9
+ "uml-class": { width: 150, height: 120 },
10
+ "uml-interface": { width: 150, height: 100 },
11
+ "uml-component": { width: 150, height: 100 },
12
+ "uml-package": { width: 200, height: 150 },
13
+ "uml-artifact": { width: 100, height: 80 },
14
+ "uml-note": { width: 150, height: 100 }
15
+ };
16
+ /**
17
+ * Default dimensions for custom shapes.
18
+ */
19
+ export const DEFAULT_CUSTOM_SHAPE_DIMENSIONS = { width: 100, height: 100 };
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Base error class for all API errors.
3
+ */
4
+ export declare class GraphKnowledgeAPIError extends Error {
5
+ readonly code: string;
6
+ constructor(message: string, code: string);
7
+ }
8
+ /**
9
+ * Thrown when authentication fails or user is not authenticated.
10
+ */
11
+ export declare class AuthenticationError extends GraphKnowledgeAPIError {
12
+ constructor(message: string);
13
+ }
14
+ /**
15
+ * Thrown when a requested resource is not found.
16
+ */
17
+ export declare class NotFoundError extends GraphKnowledgeAPIError {
18
+ constructor(message: string);
19
+ }
20
+ /**
21
+ * Thrown when input validation fails.
22
+ */
23
+ export declare class ValidationError extends GraphKnowledgeAPIError {
24
+ readonly field?: string | undefined;
25
+ readonly details?: Record<string, string> | undefined;
26
+ constructor(message: string, field?: string | undefined, details?: Record<string, string> | undefined);
27
+ }
28
+ /**
29
+ * Thrown when the user lacks permission to perform an operation.
30
+ */
31
+ export declare class PermissionError extends GraphKnowledgeAPIError {
32
+ constructor(message: string);
33
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Base error class for all API errors.
3
+ */
4
+ export class GraphKnowledgeAPIError extends Error {
5
+ code;
6
+ constructor(message, code) {
7
+ super(message);
8
+ this.code = code;
9
+ this.name = "GraphKnowledgeAPIError";
10
+ }
11
+ }
12
+ /**
13
+ * Thrown when authentication fails or user is not authenticated.
14
+ */
15
+ export class AuthenticationError extends GraphKnowledgeAPIError {
16
+ constructor(message) {
17
+ super(message, "AUTH_ERROR");
18
+ this.name = "AuthenticationError";
19
+ }
20
+ }
21
+ /**
22
+ * Thrown when a requested resource is not found.
23
+ */
24
+ export class NotFoundError extends GraphKnowledgeAPIError {
25
+ constructor(message) {
26
+ super(message, "NOT_FOUND");
27
+ this.name = "NotFoundError";
28
+ }
29
+ }
30
+ /**
31
+ * Thrown when input validation fails.
32
+ */
33
+ export class ValidationError extends GraphKnowledgeAPIError {
34
+ field;
35
+ details;
36
+ constructor(message, field, details) {
37
+ super(message, "VALIDATION_ERROR");
38
+ this.field = field;
39
+ this.details = details;
40
+ this.name = "ValidationError";
41
+ }
42
+ }
43
+ /**
44
+ * Thrown when the user lacks permission to perform an operation.
45
+ */
46
+ export class PermissionError extends GraphKnowledgeAPIError {
47
+ constructor(message) {
48
+ super(message, "PERMISSION_DENIED");
49
+ this.name = "PermissionError";
50
+ }
51
+ }
@@ -0,0 +1,106 @@
1
+ import { ApiConfig } from "./config/api-config";
2
+ import { IAuthClient } from "./interfaces/auth-client.interface";
3
+ import { IDocumentOperations } from "./interfaces/document-operations.interface";
4
+ import { INodeOperations } from "./interfaces/node-operations.interface";
5
+ import { IElementOperations } from "./interfaces/element-operations.interface";
6
+ import { IBatchOperations } from "./interfaces/batch-operations.interface";
7
+ /**
8
+ * Main entry point for the Graph Knowledge Headless API.
9
+ *
10
+ * Provides programmatic access to Graph Knowledge documents, nodes, and elements
11
+ * without requiring the Angular UI.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { GraphKnowledgeAPI } from '@graph-knowledge/api';
16
+ *
17
+ * const api = new GraphKnowledgeAPI({
18
+ * firebaseConfig: {
19
+ * apiKey: "...",
20
+ * authDomain: "...",
21
+ * projectId: "...",
22
+ * storageBucket: "...",
23
+ * messagingSenderId: "...",
24
+ * appId: "..."
25
+ * }
26
+ * });
27
+ *
28
+ * await api.signIn("user@example.com", "password");
29
+ *
30
+ * const doc = await api.documents.create({ title: "My Document" });
31
+ * const node = await api.nodes.create(doc.id, { title: "My Node" });
32
+ * await api.elements.create(doc.id, node.id, {
33
+ * type: "rectangle",
34
+ * x: 100,
35
+ * y: 100,
36
+ * width: 200,
37
+ * height: 100,
38
+ * fillColor: "#FF5733"
39
+ * });
40
+ * ```
41
+ */
42
+ export declare class GraphKnowledgeAPI {
43
+ private readonly app;
44
+ private readonly auth;
45
+ private readonly db;
46
+ private readonly _authClient;
47
+ private readonly _documents;
48
+ private readonly _nodes;
49
+ private readonly _elements;
50
+ private readonly _batch;
51
+ /**
52
+ * Creates a new GraphKnowledgeAPI instance.
53
+ * @param config Configuration including Firebase credentials
54
+ */
55
+ constructor(config: ApiConfig);
56
+ /**
57
+ * Authentication client for sign-in/sign-out operations.
58
+ */
59
+ get authClient(): IAuthClient;
60
+ /**
61
+ * Document operations (create, get, list, update, delete, share).
62
+ */
63
+ get documents(): IDocumentOperations;
64
+ /**
65
+ * Node operations (create, get, list, update, delete).
66
+ */
67
+ get nodes(): INodeOperations;
68
+ /**
69
+ * Element operations (create, get, list, update, delete).
70
+ */
71
+ get elements(): IElementOperations;
72
+ /**
73
+ * Batch element operations (createElements, updateElements, deleteElements).
74
+ */
75
+ get batch(): IBatchOperations;
76
+ /**
77
+ * Signs in with email and password.
78
+ * @param email User email
79
+ * @param password User password
80
+ */
81
+ signIn(email: string, password: string): Promise<void>;
82
+ /**
83
+ * Signs out the current user.
84
+ */
85
+ signOut(): Promise<void>;
86
+ /**
87
+ * Gets the current user's ID, or null if not authenticated.
88
+ */
89
+ get currentUserId(): string | null;
90
+ /**
91
+ * Waits for Firebase Auth to initialize.
92
+ * Call this before checking auth state if the API was just created.
93
+ */
94
+ waitForAuthInit(): Promise<void>;
95
+ /**
96
+ * Checks if the current user has premium status.
97
+ * @returns Promise resolving to true if user is premium
98
+ */
99
+ isPremium(): Promise<boolean>;
100
+ /**
101
+ * Requires the current user to have premium status.
102
+ * @throws AuthenticationError if not authenticated
103
+ * @throws PermissionError if not premium
104
+ */
105
+ requirePremium(): Promise<void>;
106
+ }
@@ -0,0 +1,154 @@
1
+ import { initializeApp } from "firebase/app";
2
+ import { getAuth } from "firebase/auth";
3
+ import { getFirestore } from "firebase/firestore";
4
+ import { FirebaseAuthClient } from "./clients/firebase-auth-client";
5
+ import { FirebaseFirestoreClient } from "./clients/firebase-firestore-client";
6
+ import { DocumentOperations } from "./operations/document-operations";
7
+ import { NodeOperations } from "./operations/node-operations";
8
+ import { ElementOperations } from "./operations/element-operations";
9
+ import { BatchOperations } from "./operations/batch-operations";
10
+ import { DocumentValidator } from "./validators/document-validator";
11
+ import { NodeValidator } from "./validators/node-validator";
12
+ import { ElementValidatorRegistry } from "./validators/element-validator-registry";
13
+ /**
14
+ * Main entry point for the Graph Knowledge Headless API.
15
+ *
16
+ * Provides programmatic access to Graph Knowledge documents, nodes, and elements
17
+ * without requiring the Angular UI.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { GraphKnowledgeAPI } from '@graph-knowledge/api';
22
+ *
23
+ * const api = new GraphKnowledgeAPI({
24
+ * firebaseConfig: {
25
+ * apiKey: "...",
26
+ * authDomain: "...",
27
+ * projectId: "...",
28
+ * storageBucket: "...",
29
+ * messagingSenderId: "...",
30
+ * appId: "..."
31
+ * }
32
+ * });
33
+ *
34
+ * await api.signIn("user@example.com", "password");
35
+ *
36
+ * const doc = await api.documents.create({ title: "My Document" });
37
+ * const node = await api.nodes.create(doc.id, { title: "My Node" });
38
+ * await api.elements.create(doc.id, node.id, {
39
+ * type: "rectangle",
40
+ * x: 100,
41
+ * y: 100,
42
+ * width: 200,
43
+ * height: 100,
44
+ * fillColor: "#FF5733"
45
+ * });
46
+ * ```
47
+ */
48
+ export class GraphKnowledgeAPI {
49
+ app;
50
+ auth;
51
+ db;
52
+ _authClient;
53
+ _documents;
54
+ _nodes;
55
+ _elements;
56
+ _batch;
57
+ /**
58
+ * Creates a new GraphKnowledgeAPI instance.
59
+ * @param config Configuration including Firebase credentials
60
+ */
61
+ constructor(config) {
62
+ // Initialize Firebase
63
+ this.app = initializeApp(config.firebaseConfig, config.appName ?? `graph-knowledge-api-${Date.now()}`);
64
+ this.auth = getAuth(this.app);
65
+ this.db = getFirestore(this.app);
66
+ // Create clients
67
+ const firestoreClient = new FirebaseFirestoreClient(this.db);
68
+ this._authClient = new FirebaseAuthClient(this.auth, this.db);
69
+ // Create validators
70
+ const documentValidator = new DocumentValidator();
71
+ const nodeValidator = new NodeValidator();
72
+ const elementValidatorRegistry = new ElementValidatorRegistry();
73
+ // Create operations (dependency injection)
74
+ this._documents = new DocumentOperations(firestoreClient, this._authClient, documentValidator);
75
+ this._nodes = new NodeOperations(firestoreClient, this._authClient, nodeValidator);
76
+ this._elements = new ElementOperations(firestoreClient, this._authClient, elementValidatorRegistry);
77
+ this._batch = new BatchOperations(firestoreClient, this._authClient, elementValidatorRegistry);
78
+ }
79
+ /**
80
+ * Authentication client for sign-in/sign-out operations.
81
+ */
82
+ get authClient() {
83
+ return this._authClient;
84
+ }
85
+ /**
86
+ * Document operations (create, get, list, update, delete, share).
87
+ */
88
+ get documents() {
89
+ return this._documents;
90
+ }
91
+ /**
92
+ * Node operations (create, get, list, update, delete).
93
+ */
94
+ get nodes() {
95
+ return this._nodes;
96
+ }
97
+ /**
98
+ * Element operations (create, get, list, update, delete).
99
+ */
100
+ get elements() {
101
+ return this._elements;
102
+ }
103
+ /**
104
+ * Batch element operations (createElements, updateElements, deleteElements).
105
+ */
106
+ get batch() {
107
+ return this._batch;
108
+ }
109
+ // =========================================================================
110
+ // Convenience methods delegating to authClient
111
+ // =========================================================================
112
+ /**
113
+ * Signs in with email and password.
114
+ * @param email User email
115
+ * @param password User password
116
+ */
117
+ async signIn(email, password) {
118
+ return this._authClient.signIn(email, password);
119
+ }
120
+ /**
121
+ * Signs out the current user.
122
+ */
123
+ async signOut() {
124
+ return this._authClient.signOut();
125
+ }
126
+ /**
127
+ * Gets the current user's ID, or null if not authenticated.
128
+ */
129
+ get currentUserId() {
130
+ return this._authClient.currentUserId;
131
+ }
132
+ /**
133
+ * Waits for Firebase Auth to initialize.
134
+ * Call this before checking auth state if the API was just created.
135
+ */
136
+ async waitForAuthInit() {
137
+ return this._authClient.waitForInit();
138
+ }
139
+ /**
140
+ * Checks if the current user has premium status.
141
+ * @returns Promise resolving to true if user is premium
142
+ */
143
+ async isPremium() {
144
+ return this._authClient.isPremium();
145
+ }
146
+ /**
147
+ * Requires the current user to have premium status.
148
+ * @throws AuthenticationError if not authenticated
149
+ * @throws PermissionError if not premium
150
+ */
151
+ async requirePremium() {
152
+ return this._authClient.requirePremium();
153
+ }
154
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Interface for authentication operations.
3
+ * Abstracts Firebase Auth for dependency inversion.
4
+ */
5
+ export interface IAuthClient {
6
+ /**
7
+ * Signs in with email and password.
8
+ * @throws AuthenticationError if sign in fails
9
+ */
10
+ signIn(email: string, password: string): Promise<void>;
11
+ /**
12
+ * Signs out the current user.
13
+ */
14
+ signOut(): Promise<void>;
15
+ /**
16
+ * Gets the current user's ID, or null if not authenticated.
17
+ */
18
+ get currentUserId(): string | null;
19
+ /**
20
+ * Gets the current user's ID, throwing if not authenticated.
21
+ * @throws AuthenticationError if not authenticated
22
+ */
23
+ requireAuth(): string;
24
+ /**
25
+ * Checks if the current user has premium status.
26
+ * @returns Promise resolving to true if user is premium
27
+ */
28
+ isPremium(): Promise<boolean>;
29
+ /**
30
+ * Requires the current user to have premium status.
31
+ * @throws AuthenticationError if not authenticated
32
+ * @throws PermissionError if not premium
33
+ */
34
+ requirePremium(): Promise<void>;
35
+ }
File without changes
@@ -0,0 +1,46 @@
1
+ import { GraphElement } from "@graph-knowledge/domain";
2
+ import { AnyElementInput, UpdateElementInput } from "../types/element-input-types";
3
+ /**
4
+ * Update input for batch element updates.
5
+ * Includes elementId to identify which element to update.
6
+ */
7
+ export interface BatchUpdateElementInput extends UpdateElementInput {
8
+ elementId: string;
9
+ }
10
+ /**
11
+ * Interface for batch element operations.
12
+ * Enables efficient bulk operations for AI agents and automation.
13
+ */
14
+ export interface IBatchOperations {
15
+ /**
16
+ * Creates multiple elements atomically.
17
+ * All elements are validated before any are created.
18
+ * @param documentId The parent document ID
19
+ * @param nodeId The parent node ID
20
+ * @param inputs Array of element creation parameters
21
+ * @returns Array of created elements
22
+ * @throws AuthenticationError if not authenticated
23
+ * @throws NotFoundError if node doesn't exist
24
+ * @throws ValidationError if any input is invalid (none created)
25
+ */
26
+ createElements(documentId: string, nodeId: string, inputs: AnyElementInput[]): Promise<GraphElement[]>;
27
+ /**
28
+ * Updates multiple elements atomically.
29
+ * @param documentId The parent document ID
30
+ * @param nodeId The parent node ID
31
+ * @param updates Array of element updates (with elementId)
32
+ * @throws AuthenticationError if not authenticated
33
+ * @throws NotFoundError if node or any element doesn't exist
34
+ */
35
+ updateElements(documentId: string, nodeId: string, updates: BatchUpdateElementInput[]): Promise<void>;
36
+ /**
37
+ * Deletes multiple elements atomically.
38
+ * Non-existent element IDs are silently skipped.
39
+ * @param documentId The parent document ID
40
+ * @param nodeId The parent node ID
41
+ * @param elementIds Array of element IDs to delete
42
+ * @throws AuthenticationError if not authenticated
43
+ * @throws NotFoundError if node doesn't exist
44
+ */
45
+ deleteElements(documentId: string, nodeId: string, elementIds: string[]): Promise<void>;
46
+ }
@@ -0,0 +1,51 @@
1
+ import { CreateDocumentInput, UpdateDocumentInput, DocumentResult } from "../types/api-types";
2
+ /**
3
+ * Interface for document CRUD operations.
4
+ */
5
+ export interface IDocumentOperations {
6
+ /**
7
+ * Creates a new document with a root node.
8
+ * @param input Document creation parameters
9
+ * @returns The created document with its ID
10
+ * @throws AuthenticationError if not authenticated
11
+ * @throws ValidationError if input is invalid
12
+ */
13
+ create(input: CreateDocumentInput): Promise<DocumentResult>;
14
+ /**
15
+ * Gets a document by ID, including all its nodes.
16
+ * @param documentId The document ID
17
+ * @returns The document with all nodes
18
+ * @throws AuthenticationError if not authenticated
19
+ * @throws NotFoundError if document doesn't exist
20
+ */
21
+ get(documentId: string): Promise<DocumentResult>;
22
+ /**
23
+ * Lists all documents owned by the current user.
24
+ * @returns Array of documents (shallow, without nodes)
25
+ * @throws AuthenticationError if not authenticated
26
+ */
27
+ list(): Promise<DocumentResult[]>;
28
+ /**
29
+ * Updates a document's metadata.
30
+ * @param documentId The document ID
31
+ * @param input Fields to update
32
+ * @throws AuthenticationError if not authenticated
33
+ * @throws NotFoundError if document doesn't exist
34
+ * @throws ValidationError if input is invalid
35
+ */
36
+ update(documentId: string, input: UpdateDocumentInput): Promise<void>;
37
+ /**
38
+ * Deletes a document.
39
+ * @param documentId The document ID
40
+ * @throws AuthenticationError if not authenticated
41
+ */
42
+ delete(documentId: string): Promise<void>;
43
+ /**
44
+ * Shares a document with other users.
45
+ * @param documentId The document ID
46
+ * @param userIds Array of user IDs to share with
47
+ * @throws AuthenticationError if not authenticated
48
+ * @throws NotFoundError if document doesn't exist
49
+ */
50
+ share(documentId: string, userIds: string[]): Promise<void>;
51
+ }
@@ -0,0 +1,57 @@
1
+ import { GraphElement } from "@graph-knowledge/domain";
2
+ import { AnyElementInput, UpdateElementInput } from "../types/element-input-types";
3
+ /**
4
+ * Interface for element CRUD operations.
5
+ */
6
+ export interface IElementOperations {
7
+ /**
8
+ * Creates a new element within a node.
9
+ * @param documentId The parent document ID
10
+ * @param nodeId The parent node ID
11
+ * @param input Element creation parameters (type-specific)
12
+ * @returns The created element
13
+ * @throws AuthenticationError if not authenticated
14
+ * @throws NotFoundError if node doesn't exist
15
+ * @throws ValidationError if input is invalid
16
+ */
17
+ create(documentId: string, nodeId: string, input: AnyElementInput): Promise<GraphElement>;
18
+ /**
19
+ * Gets an element by ID.
20
+ * @param documentId The parent document ID
21
+ * @param nodeId The parent node ID
22
+ * @param elementId The element ID
23
+ * @returns The element
24
+ * @throws AuthenticationError if not authenticated
25
+ * @throws NotFoundError if node or element doesn't exist
26
+ */
27
+ get(documentId: string, nodeId: string, elementId: string): Promise<GraphElement>;
28
+ /**
29
+ * Lists all elements in a node.
30
+ * @param documentId The parent document ID
31
+ * @param nodeId The parent node ID
32
+ * @returns Array of elements
33
+ * @throws AuthenticationError if not authenticated
34
+ * @throws NotFoundError if node doesn't exist
35
+ */
36
+ list(documentId: string, nodeId: string): Promise<GraphElement[]>;
37
+ /**
38
+ * Updates an element's properties.
39
+ * @param documentId The parent document ID
40
+ * @param nodeId The parent node ID
41
+ * @param elementId The element ID
42
+ * @param input Fields to update
43
+ * @throws AuthenticationError if not authenticated
44
+ * @throws NotFoundError if element doesn't exist
45
+ * @throws ValidationError if input is invalid
46
+ */
47
+ update(documentId: string, nodeId: string, elementId: string, input: UpdateElementInput): Promise<void>;
48
+ /**
49
+ * Deletes an element.
50
+ * @param documentId The parent document ID
51
+ * @param nodeId The parent node ID
52
+ * @param elementId The element ID
53
+ * @throws AuthenticationError if not authenticated
54
+ * @throws NotFoundError if element doesn't exist
55
+ */
56
+ delete(documentId: string, nodeId: string, elementId: string): Promise<void>;
57
+ }
@@ -0,0 +1,42 @@
1
+ import { AnyElementInput } from "../types/element-input-types";
2
+ /**
3
+ * Interface for element type validators.
4
+ * Each element type (rectangle, text, etc.) has its own validator.
5
+ * Implements the Strategy pattern for extensibility.
6
+ */
7
+ export interface IElementTypeValidator {
8
+ /**
9
+ * The element type this validator handles (e.g., "rectangle", "text").
10
+ */
11
+ readonly elementType: string;
12
+ /**
13
+ * Validates element input.
14
+ * @param input The element input to validate
15
+ * @throws ValidationError if input is invalid
16
+ */
17
+ validate(input: AnyElementInput): void;
18
+ }
19
+ /**
20
+ * Interface for the element validator registry.
21
+ * Implements Open/Closed principle - new validators can be registered
22
+ * without modifying existing code.
23
+ */
24
+ export interface IElementValidatorRegistry {
25
+ /**
26
+ * Registers a validator for an element type.
27
+ * @param validator The validator to register
28
+ */
29
+ register(validator: IElementTypeValidator): void;
30
+ /**
31
+ * Gets the validator for an element type.
32
+ * @param elementType The element type
33
+ * @returns The validator or undefined if not found
34
+ */
35
+ getValidator(elementType: string): IElementTypeValidator | undefined;
36
+ /**
37
+ * Validates an element input using the appropriate validator.
38
+ * @param input The element input to validate
39
+ * @throws ValidationError if input is invalid or no validator found
40
+ */
41
+ validate(input: AnyElementInput): void;
42
+ }