@graph-knowledge/api 0.1.2 → 0.1.4

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 (46) hide show
  1. package/README.md +12 -1
  2. package/package.json +3 -3
  3. package/src/index.js +19 -6
  4. package/src/lib/clients/firebase-auth-client.js +16 -12
  5. package/src/lib/clients/firebase-firestore-client.js +23 -19
  6. package/src/lib/config/api-config.js +2 -0
  7. package/src/lib/constants/element-defaults.js +5 -2
  8. package/src/lib/errors/api-errors.js +13 -5
  9. package/src/lib/graph-knowledge-api.js +29 -25
  10. package/src/lib/interfaces/auth-client.interface.js +2 -0
  11. package/src/lib/interfaces/batch-operations.interface.d.ts +1 -1
  12. package/src/lib/interfaces/batch-operations.interface.js +2 -0
  13. package/src/lib/interfaces/document-operations.interface.js +2 -0
  14. package/src/lib/interfaces/element-operations.interface.d.ts +1 -1
  15. package/src/lib/interfaces/element-operations.interface.js +2 -0
  16. package/src/lib/interfaces/element-validator.interface.js +2 -0
  17. package/src/lib/interfaces/firestore-client.interface.js +2 -0
  18. package/src/lib/interfaces/node-operations.interface.d.ts +1 -1
  19. package/src/lib/interfaces/node-operations.interface.js +2 -0
  20. package/src/lib/models/document.model.js +4 -1
  21. package/src/lib/models/index.js +5 -1
  22. package/src/lib/operations/batch-operations.d.ts +1 -1
  23. package/src/lib/operations/batch-operations.js +15 -11
  24. package/src/lib/operations/document-operations.js +14 -10
  25. package/src/lib/operations/element-operations.d.ts +1 -1
  26. package/src/lib/operations/element-operations.js +18 -14
  27. package/src/lib/operations/node-operations.d.ts +1 -1
  28. package/src/lib/operations/node-operations.js +10 -6
  29. package/src/lib/testing/index.js +7 -2
  30. package/src/lib/testing/mock-auth-client.js +8 -4
  31. package/src/lib/testing/mock-firestore-client.js +5 -1
  32. package/src/lib/types/api-types.d.ts +1 -1
  33. package/src/lib/types/api-types.js +2 -0
  34. package/src/lib/types/element-input-types.js +2 -0
  35. package/src/lib/utils/link-level-manager.d.ts +1 -1
  36. package/src/lib/utils/link-level-manager.js +5 -1
  37. package/src/lib/utils/uuid.js +4 -1
  38. package/src/lib/validators/document-validator.js +18 -14
  39. package/src/lib/validators/element-type-validators/base-element-validator.js +20 -16
  40. package/src/lib/validators/element-type-validators/connector-validator.js +13 -9
  41. package/src/lib/validators/element-type-validators/custom-shape-validator.js +11 -6
  42. package/src/lib/validators/element-type-validators/rectangle-validator.js +10 -6
  43. package/src/lib/validators/element-type-validators/text-validator.js +17 -13
  44. package/src/lib/validators/element-type-validators/uml-validators.js +29 -20
  45. package/src/lib/validators/element-validator-registry.js +22 -18
  46. package/src/lib/validators/node-validator.js +22 -18
@@ -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;
@@ -1,23 +1,26 @@
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.TextValidator = 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 text elements.
5
8
  */
6
- export class TextValidator extends BaseElementValidator {
9
+ class TextValidator extends base_element_validator_1.BaseElementValidator {
7
10
  elementType = "text";
8
11
  validate(input) {
9
12
  if (input.type !== "text") {
10
- throw new ValidationError(`Expected type "text", got "${input.type}"`, "type");
13
+ throw new api_errors_1.ValidationError(`Expected type "text", got "${input.type}"`, "type");
11
14
  }
12
15
  const textInput = input;
13
16
  // Validate common properties
14
17
  this.validateCommon(textInput);
15
18
  // Text content is required
16
19
  if (textInput.text === undefined || textInput.text === null) {
17
- throw new ValidationError("text is required for text elements", "text");
20
+ throw new api_errors_1.ValidationError("text is required for text elements", "text");
18
21
  }
19
22
  if (typeof textInput.text !== "string") {
20
- throw new ValidationError("text must be a string", "text");
23
+ throw new api_errors_1.ValidationError("text must be a string", "text");
21
24
  }
22
25
  // Validate text-specific properties
23
26
  this.validateColor(textInput.fillColor, "fillColor");
@@ -30,37 +33,38 @@ export class TextValidator extends BaseElementValidator {
30
33
  if (value === undefined)
31
34
  return;
32
35
  if (typeof value !== "number" || isNaN(value)) {
33
- throw new ValidationError("fontSize must be a valid number", "fontSize");
36
+ throw new api_errors_1.ValidationError("fontSize must be a valid number", "fontSize");
34
37
  }
35
38
  if (value <= 0) {
36
- throw new ValidationError("fontSize must be positive", "fontSize");
39
+ throw new api_errors_1.ValidationError("fontSize must be positive", "fontSize");
37
40
  }
38
41
  }
39
42
  validateFontWeight(value) {
40
43
  if (value === undefined)
41
44
  return;
42
45
  if (typeof value !== "number" || isNaN(value)) {
43
- throw new ValidationError("fontWeight must be a valid number", "fontWeight");
46
+ throw new api_errors_1.ValidationError("fontWeight must be a valid number", "fontWeight");
44
47
  }
45
48
  if (value < 100 || value > 900) {
46
- throw new ValidationError("fontWeight must be between 100 and 900", "fontWeight");
49
+ throw new api_errors_1.ValidationError("fontWeight must be between 100 and 900", "fontWeight");
47
50
  }
48
51
  }
49
52
  validateTextAlign(value) {
50
53
  if (value === undefined)
51
54
  return;
52
55
  if (!["left", "center", "right"].includes(value)) {
53
- throw new ValidationError('textAlign must be "left", "center", or "right"', "textAlign");
56
+ throw new api_errors_1.ValidationError('textAlign must be "left", "center", or "right"', "textAlign");
54
57
  }
55
58
  }
56
59
  validateLineHeight(value) {
57
60
  if (value === undefined)
58
61
  return;
59
62
  if (typeof value !== "number" || isNaN(value)) {
60
- throw new ValidationError("lineHeight must be a valid number", "lineHeight");
63
+ throw new api_errors_1.ValidationError("lineHeight must be a valid number", "lineHeight");
61
64
  }
62
65
  if (value <= 0) {
63
- throw new ValidationError("lineHeight must be positive", "lineHeight");
66
+ throw new api_errors_1.ValidationError("lineHeight must be positive", "lineHeight");
64
67
  }
65
68
  }
66
69
  }
70
+ exports.TextValidator = TextValidator;
@@ -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.UmlNoteValidator = exports.UmlArtifactValidator = exports.UmlPackageValidator = exports.UmlComponentValidator = exports.UmlInterfaceValidator = exports.UmlClassValidator = 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
  * Base validator for UML elements.
5
8
  * Provides common validation for UML-specific properties.
6
9
  */
7
- class BaseUmlValidator extends BaseElementValidator {
10
+ class BaseUmlValidator extends base_element_validator_1.BaseElementValidator {
8
11
  validate(input) {
9
12
  if (input.type !== this.elementType) {
10
- throw new ValidationError(`Expected type "${this.elementType}", got "${input.type}"`, "type");
13
+ throw new api_errors_1.ValidationError(`Expected type "${this.elementType}", got "${input.type}"`, "type");
11
14
  }
12
15
  // Validate common properties - cast is safe since we've verified the type
13
16
  // and UML elements always have required x/y
@@ -30,94 +33,100 @@ class BaseUmlValidator extends BaseElementValidator {
30
33
  /**
31
34
  * Validator for UML class elements.
32
35
  */
33
- export class UmlClassValidator extends BaseUmlValidator {
36
+ class UmlClassValidator extends BaseUmlValidator {
34
37
  elementType = "uml-class";
35
38
  validateSpecific(input) {
36
39
  const classInput = input;
37
40
  if (classInput["name"] !== undefined &&
38
41
  typeof classInput["name"] !== "string") {
39
- throw new ValidationError("name must be a string", "name");
42
+ throw new api_errors_1.ValidationError("name must be a string", "name");
40
43
  }
41
44
  if (classInput["attributes"] !== undefined &&
42
45
  typeof classInput["attributes"] !== "string") {
43
- throw new ValidationError("attributes must be a string", "attributes");
46
+ throw new api_errors_1.ValidationError("attributes must be a string", "attributes");
44
47
  }
45
48
  if (classInput["methods"] !== undefined &&
46
49
  typeof classInput["methods"] !== "string") {
47
- throw new ValidationError("methods must be a string", "methods");
50
+ throw new api_errors_1.ValidationError("methods must be a string", "methods");
48
51
  }
49
52
  if (classInput["stereotype"] !== undefined &&
50
53
  typeof classInput["stereotype"] !== "string") {
51
- throw new ValidationError("stereotype must be a string", "stereotype");
54
+ throw new api_errors_1.ValidationError("stereotype must be a string", "stereotype");
52
55
  }
53
56
  }
54
57
  }
58
+ exports.UmlClassValidator = UmlClassValidator;
55
59
  /**
56
60
  * Validator for UML interface elements.
57
61
  */
58
- export class UmlInterfaceValidator extends BaseUmlValidator {
62
+ class UmlInterfaceValidator extends BaseUmlValidator {
59
63
  elementType = "uml-interface";
60
64
  validateSpecific(input) {
61
65
  const interfaceInput = input;
62
66
  if (interfaceInput["name"] !== undefined &&
63
67
  typeof interfaceInput["name"] !== "string") {
64
- throw new ValidationError("name must be a string", "name");
68
+ throw new api_errors_1.ValidationError("name must be a string", "name");
65
69
  }
66
70
  if (interfaceInput["methods"] !== undefined &&
67
71
  typeof interfaceInput["methods"] !== "string") {
68
- throw new ValidationError("methods must be a string", "methods");
72
+ throw new api_errors_1.ValidationError("methods must be a string", "methods");
69
73
  }
70
74
  }
71
75
  }
76
+ exports.UmlInterfaceValidator = UmlInterfaceValidator;
72
77
  /**
73
78
  * Validator for UML component elements.
74
79
  */
75
- export class UmlComponentValidator extends BaseUmlValidator {
80
+ class UmlComponentValidator extends BaseUmlValidator {
76
81
  elementType = "uml-component";
77
82
  validateSpecific(input) {
78
83
  const componentInput = input;
79
84
  if (componentInput["name"] !== undefined &&
80
85
  typeof componentInput["name"] !== "string") {
81
- throw new ValidationError("name must be a string", "name");
86
+ throw new api_errors_1.ValidationError("name must be a string", "name");
82
87
  }
83
88
  }
84
89
  }
90
+ exports.UmlComponentValidator = UmlComponentValidator;
85
91
  /**
86
92
  * Validator for UML package elements.
87
93
  */
88
- export class UmlPackageValidator extends BaseUmlValidator {
94
+ class UmlPackageValidator extends BaseUmlValidator {
89
95
  elementType = "uml-package";
90
96
  validateSpecific(input) {
91
97
  const packageInput = input;
92
98
  if (packageInput["name"] !== undefined &&
93
99
  typeof packageInput["name"] !== "string") {
94
- throw new ValidationError("name must be a string", "name");
100
+ throw new api_errors_1.ValidationError("name must be a string", "name");
95
101
  }
96
102
  }
97
103
  }
104
+ exports.UmlPackageValidator = UmlPackageValidator;
98
105
  /**
99
106
  * Validator for UML artifact elements.
100
107
  */
101
- export class UmlArtifactValidator extends BaseUmlValidator {
108
+ class UmlArtifactValidator extends BaseUmlValidator {
102
109
  elementType = "uml-artifact";
103
110
  validateSpecific(input) {
104
111
  const artifactInput = input;
105
112
  if (artifactInput["name"] !== undefined &&
106
113
  typeof artifactInput["name"] !== "string") {
107
- throw new ValidationError("name must be a string", "name");
114
+ throw new api_errors_1.ValidationError("name must be a string", "name");
108
115
  }
109
116
  }
110
117
  }
118
+ exports.UmlArtifactValidator = UmlArtifactValidator;
111
119
  /**
112
120
  * Validator for UML note elements.
113
121
  */
114
- export class UmlNoteValidator extends BaseUmlValidator {
122
+ class UmlNoteValidator extends BaseUmlValidator {
115
123
  elementType = "uml-note";
116
124
  validateSpecific(input) {
117
125
  const noteInput = input;
118
126
  if (noteInput["text"] !== undefined &&
119
127
  typeof noteInput["text"] !== "string") {
120
- throw new ValidationError("text must be a string", "text");
128
+ throw new api_errors_1.ValidationError("text must be a string", "text");
121
129
  }
122
130
  }
123
131
  }
132
+ exports.UmlNoteValidator = UmlNoteValidator;
@@ -1,15 +1,18 @@
1
- import { ValidationError } from "../errors/api-errors";
2
- import { RectangleValidator } from "./element-type-validators/rectangle-validator";
3
- import { TextValidator } from "./element-type-validators/text-validator";
4
- import { ConnectorValidator } from "./element-type-validators/connector-validator";
5
- import { UmlClassValidator, UmlInterfaceValidator, UmlComponentValidator, UmlPackageValidator, UmlArtifactValidator, UmlNoteValidator } from "./element-type-validators/uml-validators";
6
- import { CustomShapeValidator } from "./element-type-validators/custom-shape-validator";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ElementValidatorRegistry = void 0;
4
+ const api_errors_1 = require("../errors/api-errors");
5
+ const rectangle_validator_1 = require("./element-type-validators/rectangle-validator");
6
+ const text_validator_1 = require("./element-type-validators/text-validator");
7
+ const connector_validator_1 = require("./element-type-validators/connector-validator");
8
+ const uml_validators_1 = require("./element-type-validators/uml-validators");
9
+ const custom_shape_validator_1 = require("./element-type-validators/custom-shape-validator");
7
10
  /**
8
11
  * Registry for element type validators.
9
12
  * Implements Open/Closed principle - new validators can be registered
10
13
  * without modifying this class.
11
14
  */
12
- export class ElementValidatorRegistry {
15
+ class ElementValidatorRegistry {
13
16
  validators = new Map();
14
17
  constructor() {
15
18
  // Register built-in validators
@@ -19,15 +22,15 @@ export class ElementValidatorRegistry {
19
22
  * Registers built-in validators for standard element types.
20
23
  */
21
24
  registerBuiltInValidators() {
22
- this.register(new RectangleValidator());
23
- this.register(new TextValidator());
24
- this.register(new ConnectorValidator());
25
- this.register(new UmlClassValidator());
26
- this.register(new UmlInterfaceValidator());
27
- this.register(new UmlComponentValidator());
28
- this.register(new UmlPackageValidator());
29
- this.register(new UmlArtifactValidator());
30
- this.register(new UmlNoteValidator());
25
+ this.register(new rectangle_validator_1.RectangleValidator());
26
+ this.register(new text_validator_1.TextValidator());
27
+ this.register(new connector_validator_1.ConnectorValidator());
28
+ this.register(new uml_validators_1.UmlClassValidator());
29
+ this.register(new uml_validators_1.UmlInterfaceValidator());
30
+ this.register(new uml_validators_1.UmlComponentValidator());
31
+ this.register(new uml_validators_1.UmlPackageValidator());
32
+ this.register(new uml_validators_1.UmlArtifactValidator());
33
+ this.register(new uml_validators_1.UmlNoteValidator());
31
34
  }
32
35
  register(validator) {
33
36
  this.validators.set(validator.elementType, validator);
@@ -41,7 +44,7 @@ export class ElementValidatorRegistry {
41
44
  // Handle custom shapes - create validator on demand
42
45
  if (elementType.startsWith("custom:")) {
43
46
  const shapeId = elementType.substring(7); // Remove "custom:" prefix
44
- const customValidator = new CustomShapeValidator(shapeId);
47
+ const customValidator = new custom_shape_validator_1.CustomShapeValidator(shapeId);
45
48
  // Cache for future use
46
49
  this.validators.set(elementType, customValidator);
47
50
  return customValidator;
@@ -51,8 +54,9 @@ export class ElementValidatorRegistry {
51
54
  validate(input) {
52
55
  const validator = this.getValidator(input.type);
53
56
  if (!validator) {
54
- throw new ValidationError(`Unknown element type: ${input.type}`, "type");
57
+ throw new api_errors_1.ValidationError(`Unknown element type: ${input.type}`, "type");
55
58
  }
56
59
  validator.validate(input);
57
60
  }
58
61
  }
62
+ exports.ElementValidatorRegistry = ElementValidatorRegistry;
@@ -1,8 +1,11 @@
1
- import { ValidationError } from "../errors/api-errors";
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodeValidator = void 0;
4
+ const api_errors_1 = require("../errors/api-errors");
2
5
  /**
3
6
  * Validator for node operations.
4
7
  */
5
- export class NodeValidator {
8
+ class NodeValidator {
6
9
  /**
7
10
  * Validates input for node creation.
8
11
  * @param input The creation input to validate
@@ -10,20 +13,20 @@ export class NodeValidator {
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
  if (input.parentNodeId !== undefined &&
25
28
  typeof input.parentNodeId !== "string") {
26
- throw new ValidationError("parentNodeId must be a string", "parentNodeId");
29
+ throw new api_errors_1.ValidationError("parentNodeId must be a string", "parentNodeId");
27
30
  }
28
31
  this.validateCanvasDimensions(input.canvasWidth, input.canvasHeight);
29
32
  this.validateLevel(input.level);
@@ -36,17 +39,17 @@ export class NodeValidator {
36
39
  validateUpdate(input) {
37
40
  if (input.title !== undefined) {
38
41
  if (typeof input.title !== "string") {
39
- throw new ValidationError("title must be a string", "title");
42
+ throw new api_errors_1.ValidationError("title must be a string", "title");
40
43
  }
41
44
  if (input.title.trim().length === 0) {
42
- throw new ValidationError("title cannot be empty", "title");
45
+ throw new api_errors_1.ValidationError("title cannot be empty", "title");
43
46
  }
44
47
  if (input.title.length > 200) {
45
- throw new ValidationError("title must be 200 characters or less", "title");
48
+ throw new api_errors_1.ValidationError("title must be 200 characters or less", "title");
46
49
  }
47
50
  }
48
51
  if (input.content !== undefined && typeof input.content !== "string") {
49
- throw new ValidationError("content must be a string", "content");
52
+ throw new api_errors_1.ValidationError("content must be a string", "content");
50
53
  }
51
54
  this.validateCanvasDimensions(input.canvasWidth, input.canvasHeight);
52
55
  }
@@ -56,18 +59,18 @@ export class NodeValidator {
56
59
  validateCanvasDimensions(width, height) {
57
60
  if (width !== undefined) {
58
61
  if (typeof width !== "number" || isNaN(width)) {
59
- throw new ValidationError("canvasWidth must be a valid number", "canvasWidth");
62
+ throw new api_errors_1.ValidationError("canvasWidth must be a valid number", "canvasWidth");
60
63
  }
61
64
  if (width < 100 || width > 10000) {
62
- throw new ValidationError("canvasWidth must be between 100 and 10000", "canvasWidth");
65
+ throw new api_errors_1.ValidationError("canvasWidth must be between 100 and 10000", "canvasWidth");
63
66
  }
64
67
  }
65
68
  if (height !== undefined) {
66
69
  if (typeof height !== "number" || isNaN(height)) {
67
- throw new ValidationError("canvasHeight must be a valid number", "canvasHeight");
70
+ throw new api_errors_1.ValidationError("canvasHeight must be a valid number", "canvasHeight");
68
71
  }
69
72
  if (height < 100 || height > 10000) {
70
- throw new ValidationError("canvasHeight must be between 100 and 10000", "canvasHeight");
73
+ throw new api_errors_1.ValidationError("canvasHeight must be between 100 and 10000", "canvasHeight");
71
74
  }
72
75
  }
73
76
  }
@@ -78,13 +81,14 @@ export class NodeValidator {
78
81
  if (level === undefined)
79
82
  return;
80
83
  if (typeof level !== "number" || isNaN(level)) {
81
- throw new ValidationError("level must be a valid number", "level");
84
+ throw new api_errors_1.ValidationError("level must be a valid number", "level");
82
85
  }
83
86
  if (level < 0) {
84
- throw new ValidationError("level must be non-negative", "level");
87
+ throw new api_errors_1.ValidationError("level must be non-negative", "level");
85
88
  }
86
89
  if (!Number.isInteger(level)) {
87
- throw new ValidationError("level must be an integer", "level");
90
+ throw new api_errors_1.ValidationError("level must be an integer", "level");
88
91
  }
89
92
  }
90
93
  }
94
+ exports.NodeValidator = NodeValidator;