@likec4/core 0.33.0 → 0.34.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 (120) hide show
  1. package/dist/{colors.mjs → colors.cjs} +15 -3
  2. package/dist/colors.js +3 -15
  3. package/dist/compute-view/EdgeBuilder.cjs +37 -0
  4. package/dist/compute-view/EdgeBuilder.d.ts +1 -2
  5. package/dist/compute-view/EdgeBuilder.js +10 -18
  6. package/dist/compute-view/compute-ctx.cjs +35 -0
  7. package/dist/compute-view/compute-ctx.js +21 -14
  8. package/dist/compute-view/compute-element-view.cjs +135 -0
  9. package/dist/compute-view/compute-element-view.js +70 -62
  10. package/dist/compute-view/compute-predicates.cjs +363 -0
  11. package/dist/compute-view/compute-predicates.d.ts +1 -1
  12. package/dist/compute-view/compute-predicates.js +81 -115
  13. package/dist/compute-view/compute.cjs +60 -0
  14. package/dist/compute-view/compute.d.ts +13 -4
  15. package/dist/compute-view/compute.js +24 -31
  16. package/dist/compute-view/index.cjs +27 -0
  17. package/dist/compute-view/index.d.ts +2 -3
  18. package/dist/compute-view/index.js +2 -24
  19. package/dist/compute-view/utils/anyPossibleRelations.cjs +18 -0
  20. package/dist/compute-view/utils/anyPossibleRelations.js +6 -12
  21. package/dist/compute-view/utils/applyViewRuleStyles.cjs +57 -0
  22. package/dist/compute-view/utils/applyViewRuleStyles.d.ts +1 -2
  23. package/dist/compute-view/utils/applyViewRuleStyles.js +20 -29
  24. package/dist/compute-view/utils/{sortNodes.mjs → sortNodes.cjs} +19 -9
  25. package/dist/compute-view/utils/sortNodes.js +9 -19
  26. package/dist/errors/_base.cjs +62 -0
  27. package/dist/errors/_base.d.ts +20 -3
  28. package/dist/errors/_base.js +41 -14
  29. package/dist/errors/index.cjs +60 -0
  30. package/dist/errors/index.js +5 -60
  31. package/dist/errors/invariant.cjs +23 -0
  32. package/dist/errors/invariant.d.ts +5 -1
  33. package/dist/errors/invariant.js +9 -12
  34. package/dist/errors/model-index.cjs +23 -0
  35. package/dist/errors/model-index.d.ts +5 -1
  36. package/dist/errors/model-index.js +9 -12
  37. package/dist/errors/non-nullable.cjs +23 -0
  38. package/dist/errors/non-nullable.d.ts +5 -1
  39. package/dist/errors/non-nullable.js +11 -14
  40. package/dist/errors/nonexhaustive.cjs +23 -0
  41. package/dist/errors/nonexhaustive.d.ts +6 -2
  42. package/dist/errors/nonexhaustive.js +12 -13
  43. package/dist/index.cjs +71 -0
  44. package/dist/index.d.ts +2 -5
  45. package/dist/index.js +6 -71
  46. package/dist/model-index/{ModelIndex.mjs → ModelIndex.cjs} +35 -23
  47. package/dist/model-index/ModelIndex.js +23 -35
  48. package/dist/model-index/index.cjs +13 -0
  49. package/dist/model-index/index.js +1 -13
  50. package/dist/types/_common.cjs +1 -0
  51. package/dist/types/_common.js +0 -1
  52. package/dist/types/computed-view.cjs +1 -0
  53. package/dist/types/computed-view.js +0 -1
  54. package/dist/types/diagram.cjs +1 -0
  55. package/dist/types/diagram.js +0 -1
  56. package/dist/types/element.cjs +14 -0
  57. package/dist/types/element.js +3 -12
  58. package/dist/types/expression.cjs +45 -0
  59. package/dist/types/expression.js +11 -26
  60. package/dist/types/index.cjs +132 -0
  61. package/dist/types/index.d.ts +10 -12
  62. package/dist/types/index.js +11 -48
  63. package/dist/types/model.cjs +1 -0
  64. package/dist/types/model.d.ts +1 -1
  65. package/dist/types/model.js +0 -1
  66. package/dist/types/opaque.cjs +1 -0
  67. package/dist/types/opaque.d.ts +1 -1
  68. package/dist/types/opaque.js +0 -1
  69. package/dist/types/relation.cjs +1 -0
  70. package/dist/types/relation.js +0 -1
  71. package/dist/types/theme.cjs +1 -0
  72. package/dist/types/theme.js +0 -1
  73. package/dist/types/view.cjs +17 -0
  74. package/dist/types/view.js +4 -12
  75. package/dist/utils/compute-node-levels.cjs +48 -0
  76. package/dist/utils/compute-node-levels.d.ts +2 -2
  77. package/dist/utils/compute-node-levels.js +7 -24
  78. package/dist/utils/fqn.cjs +80 -0
  79. package/dist/utils/fqn.js +19 -33
  80. package/dist/utils/guards.cjs +22 -0
  81. package/dist/utils/guards.js +7 -16
  82. package/dist/utils/index.cjs +49 -0
  83. package/dist/utils/index.d.ts +1 -1
  84. package/dist/utils/index.js +4 -49
  85. package/dist/utils/relations.cjs +59 -0
  86. package/dist/utils/relations.d.ts +14 -12
  87. package/dist/utils/relations.js +28 -33
  88. package/package.json +58 -21
  89. package/dist/compute-view/EdgeBuilder.mjs +0 -31
  90. package/dist/compute-view/compute-ctx.mjs +0 -42
  91. package/dist/compute-view/compute-element-view.mjs +0 -145
  92. package/dist/compute-view/compute-predicates.mjs +0 -324
  93. package/dist/compute-view/compute.mjs +0 -39
  94. package/dist/compute-view/index.mjs +0 -1
  95. package/dist/compute-view/utils/anyPossibleRelations.mjs +0 -12
  96. package/dist/compute-view/utils/applyViewRuleStyles.mjs +0 -50
  97. package/dist/errors/_base.mjs +0 -4
  98. package/dist/errors/index.mjs +0 -5
  99. package/dist/errors/invariant.mjs +0 -8
  100. package/dist/errors/model-index.mjs +0 -8
  101. package/dist/errors/non-nullable.mjs +0 -8
  102. package/dist/errors/nonexhaustive.mjs +0 -5
  103. package/dist/index.mjs +0 -6
  104. package/dist/model-index/index.mjs +0 -1
  105. package/dist/types/_common.mjs +0 -0
  106. package/dist/types/computed-view.mjs +0 -0
  107. package/dist/types/diagram.mjs +0 -0
  108. package/dist/types/element.mjs +0 -5
  109. package/dist/types/expression.mjs +0 -30
  110. package/dist/types/index.mjs +0 -3
  111. package/dist/types/model.mjs +0 -0
  112. package/dist/types/opaque.mjs +0 -0
  113. package/dist/types/relation.mjs +0 -0
  114. package/dist/types/theme.mjs +0 -0
  115. package/dist/types/view.mjs +0 -9
  116. package/dist/utils/compute-node-levels.mjs +0 -31
  117. package/dist/utils/fqn.mjs +0 -66
  118. package/dist/utils/guards.mjs +0 -13
  119. package/dist/utils/index.mjs +0 -4
  120. package/dist/utils/relations.mjs +0 -42
@@ -1,18 +1,12 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.anyPossibleRelations = anyPossibleRelations;
7
- var _rambdax = require("rambdax");
8
- var _fqn = require("../../utils/fqn");
9
- function* anyPossibleRelations(elements) {
10
- const uniqElements = (0, _rambdax.uniqBy)((0, _rambdax.prop)("id"), elements).sort(_fqn.compareByFqnHierarchically).reverse();
1
+ import { prop, uniqBy } from "rambdax";
2
+ import { compareByFqnHierarchically, isAncestor } from "../../utils/index.js";
3
+ export function* anyPossibleRelations(elements) {
4
+ const uniqElements = uniqBy(prop("id"), elements).sort(compareByFqnHierarchically).reverse();
11
5
  for (const source of uniqElements) {
12
6
  for (const target of uniqElements) {
13
- if (source !== target && !(0, _fqn.isAncestor)(source, target) && !(0, _fqn.isAncestor)(target, source)) {
7
+ if (source !== target && !isAncestor(source, target) && !isAncestor(target, source)) {
14
8
  yield [source, target];
15
9
  }
16
10
  }
17
11
  }
18
- }
12
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.applyViewRuleStyles = applyViewRuleStyles;
7
+ var _rambdax = require("rambdax");
8
+ var _remeda = require("remeda");
9
+ var _errors = require("../../errors/index.cjs");
10
+ var _types = require("../../types/index.cjs");
11
+ function applyViewRuleStyles(rules, _nodes) {
12
+ if (rules.length === 0) {
13
+ return _nodes;
14
+ }
15
+ const nodes = (0, _rambdax.clone)(_nodes);
16
+ for (const rule of rules) {
17
+ const predicates = [];
18
+ if (!rule.style.color && !rule.style.shape) {
19
+ continue;
20
+ }
21
+ for (const target of rule.targets) {
22
+ if (_types.Expr.isWildcard(target)) {
23
+ predicates.push(() => true);
24
+ break;
25
+ }
26
+ if (_types.Expr.isElementKindExpr(target)) {
27
+ predicates.push(target.isEqual ? n => n.kind === target.elementKind : n => n.kind !== target.elementKind);
28
+ continue;
29
+ }
30
+ if (_types.Expr.isElementTagExpr(target)) {
31
+ predicates.push(target.isEqual ? ({
32
+ tags
33
+ }) => !!tags && tags.includes(target.elementTag) : ({
34
+ tags
35
+ }) => (0, _rambdax.isNil)(tags) || !tags.includes(target.elementTag));
36
+ continue;
37
+ }
38
+ if (_types.Expr.isElementRef(target)) {
39
+ const {
40
+ element,
41
+ isDescedants
42
+ } = target;
43
+ predicates.push(isDescedants ? n => n.id.startsWith(element + ".") : n => n.id === element);
44
+ continue;
45
+ }
46
+ (0, _errors.nonexhaustive)(target);
47
+ }
48
+ (0, _rambdax.filter)((0, _rambdax.anyPass)(predicates), nodes).forEach(n => {
49
+ n.shape = rule.style.shape ?? n.shape;
50
+ n.color = rule.style.color ?? n.color;
51
+ if (_remeda.isDefined.strict(rule.style.icon)) {
52
+ n.icon = rule.style.icon;
53
+ }
54
+ });
55
+ }
56
+ return nodes;
57
+ }
@@ -1,3 +1,2 @@
1
- import { type ComputedNode } from '../../types';
2
- import { type ViewRuleStyle } from '../../types/view';
1
+ import type { ComputedNode, ViewRuleStyle } from '../../types';
3
2
  export declare function applyViewRuleStyles(rules: ViewRuleStyle[], _nodes: ComputedNode[]): ComputedNode[];
@@ -1,20 +1,12 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.applyViewRuleStyles = applyViewRuleStyles;
7
- var _rambdax = require("rambdax");
8
- var _remeda = require("remeda");
9
- var Expr = _interopRequireWildcard(require("../../types/expression"));
10
- var _errors = require("../../errors");
11
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
- function applyViewRuleStyles(rules, _nodes) {
1
+ import { anyPass, clone, filter, isNil } from "rambdax";
2
+ import { isDefined } from "remeda";
3
+ import { nonexhaustive } from "../../errors/index.js";
4
+ import { Expr } from "../../types/index.js";
5
+ export function applyViewRuleStyles(rules, _nodes) {
14
6
  if (rules.length === 0) {
15
7
  return _nodes;
16
8
  }
17
- const nodes = (0, _rambdax.clone)(_nodes);
9
+ const nodes = clone(_nodes);
18
10
  for (const rule of rules) {
19
11
  const predicates = [];
20
12
  if (!rule.style.color && !rule.style.shape) {
@@ -26,34 +18,33 @@ function applyViewRuleStyles(rules, _nodes) {
26
18
  break;
27
19
  }
28
20
  if (Expr.isElementKindExpr(target)) {
29
- predicates.push(target.isEqual ? n => n.kind === target.elementKind : n => n.kind !== target.elementKind);
21
+ predicates.push(
22
+ target.isEqual ? (n) => n.kind === target.elementKind : (n) => n.kind !== target.elementKind
23
+ );
30
24
  continue;
31
25
  }
32
26
  if (Expr.isElementTagExpr(target)) {
33
- predicates.push(target.isEqual ? ({
34
- tags
35
- }) => !!tags && tags.includes(target.elementTag) : ({
36
- tags
37
- }) => (0, _rambdax.isNil)(tags) || !tags.includes(target.elementTag));
27
+ predicates.push(
28
+ target.isEqual ? ({ tags }) => !!tags && tags.includes(target.elementTag) : ({ tags }) => isNil(tags) || !tags.includes(target.elementTag)
29
+ );
38
30
  continue;
39
31
  }
40
32
  if (Expr.isElementRef(target)) {
41
- const {
42
- element,
43
- isDescedants
44
- } = target;
45
- predicates.push(isDescedants ? n => n.id.startsWith(element + ".") : n => n.id === element);
33
+ const { element, isDescedants } = target;
34
+ predicates.push(
35
+ isDescedants ? (n) => n.id.startsWith(element + ".") : (n) => n.id === element
36
+ );
46
37
  continue;
47
38
  }
48
- (0, _errors.nonexhaustive)(target);
39
+ nonexhaustive(target);
49
40
  }
50
- (0, _rambdax.filter)((0, _rambdax.anyPass)(predicates), nodes).forEach(n => {
41
+ filter(anyPass(predicates), nodes).forEach((n) => {
51
42
  n.shape = rule.style.shape ?? n.shape;
52
43
  n.color = rule.style.color ?? n.color;
53
- if (_remeda.isDefined.strict(rule.style.icon)) {
44
+ if (isDefined.strict(rule.style.icon)) {
54
45
  n.icon = rule.style.icon;
55
46
  }
56
47
  });
57
48
  }
58
49
  return nodes;
59
- }
50
+ }
@@ -1,8 +1,18 @@
1
- import { isSameHierarchy } from "../../utils/index.mjs";
2
- import pkg from "@dagrejs/graphlib";
3
- import { nonNullable } from "../../errors/index.mjs";
4
- const { Graph, alg } = pkg;
5
- export function sortNodes(_nodes, edges) {
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sortNodes = sortNodes;
7
+ var _utils = require("../../utils/index.cjs");
8
+ var _graphlib = _interopRequireDefault(require("@dagrejs/graphlib"));
9
+ var _errors = require("../../errors/index.cjs");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ const {
12
+ Graph,
13
+ alg
14
+ } = _graphlib.default;
15
+ function sortNodes(_nodes, edges) {
6
16
  const g = new Graph({
7
17
  compound: true,
8
18
  directed: true,
@@ -18,7 +28,7 @@ export function sortNodes(_nodes, edges) {
18
28
  const source = _nodes.get(edge.source);
19
29
  let target = _nodes.get(edge.target);
20
30
  while (source && target) {
21
- if (!isSameHierarchy(source, target) && !g.hasEdge(source.id, target.id)) {
31
+ if (!(0, _utils.isSameHierarchy)(source, target) && !g.hasEdge(source.id, target.id)) {
22
32
  g.setEdge(source.id, target.id);
23
33
  if (!alg.isAcyclic(g)) {
24
34
  g.removeEdge(source.id, target.id);
@@ -32,9 +42,9 @@ export function sortNodes(_nodes, edges) {
32
42
  }
33
43
  }
34
44
  const sorted = alg.topsort(g);
35
- const nodes = sorted.map((id) => nonNullable(_nodes.get(id)));
45
+ const nodes = sorted.map(id => (0, _errors.nonNullable)(_nodes.get(id)));
36
46
  for (const node of nodes) {
37
- node.children = nodes.flatMap((n) => n.parent === node.id ? n.id : []);
47
+ node.children = nodes.flatMap(n => n.parent === node.id ? n.id : []);
38
48
  }
39
49
  return nodes;
40
- }
50
+ }
@@ -1,18 +1,8 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.sortNodes = sortNodes;
7
- var _utils = require("../../utils");
8
- var _graphlib = _interopRequireDefault(require("@dagrejs/graphlib"));
9
- var _errors = require("../../errors");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- const {
12
- Graph,
13
- alg
14
- } = _graphlib.default;
15
- function sortNodes(_nodes, edges) {
1
+ import { isSameHierarchy } from "../../utils/index.js";
2
+ import pkg from "@dagrejs/graphlib";
3
+ import { nonNullable } from "../../errors/index.js";
4
+ const { Graph, alg } = pkg;
5
+ export function sortNodes(_nodes, edges) {
16
6
  const g = new Graph({
17
7
  compound: true,
18
8
  directed: true,
@@ -28,7 +18,7 @@ function sortNodes(_nodes, edges) {
28
18
  const source = _nodes.get(edge.source);
29
19
  let target = _nodes.get(edge.target);
30
20
  while (source && target) {
31
- if (!(0, _utils.isSameHierarchy)(source, target) && !g.hasEdge(source.id, target.id)) {
21
+ if (!isSameHierarchy(source, target) && !g.hasEdge(source.id, target.id)) {
32
22
  g.setEdge(source.id, target.id);
33
23
  if (!alg.isAcyclic(g)) {
34
24
  g.removeEdge(source.id, target.id);
@@ -42,9 +32,9 @@ function sortNodes(_nodes, edges) {
42
32
  }
43
33
  }
44
34
  const sorted = alg.topsort(g);
45
- const nodes = sorted.map(id => (0, _errors.nonNullable)(_nodes.get(id)));
35
+ const nodes = sorted.map((id) => nonNullable(_nodes.get(id)));
46
36
  for (const node of nodes) {
47
- node.children = nodes.flatMap(n => n.parent === node.id ? n.id : []);
37
+ node.children = nodes.flatMap((n) => n.parent === node.id ? n.id : []);
48
38
  }
49
39
  return nodes;
50
- }
40
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UnknownError = exports.RelationRefError = exports.BaseError = void 0;
7
+ exports.normalizeError = normalizeError;
8
+ exports.serializeError = serializeError;
9
+ exports.throwNormalizedError = throwNormalizedError;
10
+ var _tsCustomError = require("ts-custom-error");
11
+ var _safeStableStringify = _interopRequireDefault(require("safe-stable-stringify"));
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+ class BaseError extends _tsCustomError.CustomError {
14
+ constructor(message, options) {
15
+ super(message, options);
16
+ Object.defineProperty(this, "name", {
17
+ value: "BaseError"
18
+ });
19
+ }
20
+ }
21
+ exports.BaseError = BaseError;
22
+ class UnknownError extends BaseError {
23
+ constructor(message, options) {
24
+ super(message, options);
25
+ Object.defineProperty(this, "name", {
26
+ value: "UnknownError"
27
+ });
28
+ }
29
+ }
30
+ exports.UnknownError = UnknownError;
31
+ class RelationRefError extends BaseError {
32
+ constructor(message, options) {
33
+ super(message, options);
34
+ Object.defineProperty(this, "name", {
35
+ value: "RelationRefError"
36
+ });
37
+ }
38
+ }
39
+ exports.RelationRefError = RelationRefError;
40
+ function normalizeError(e) {
41
+ if (e instanceof BaseError) {
42
+ return e;
43
+ }
44
+ if (e instanceof Error) {
45
+ return new UnknownError(e.message, {
46
+ cause: e
47
+ });
48
+ }
49
+ const message = typeof e === "string" ? e : (0, _safeStableStringify.default)(e);
50
+ return new UnknownError(message);
51
+ }
52
+ function serializeError(e) {
53
+ const error = normalizeError(e);
54
+ return {
55
+ name: error.name,
56
+ message: error.stack ? error.stack : `${error.name}: ${error.message}`,
57
+ error
58
+ };
59
+ }
60
+ function throwNormalizedError(e) {
61
+ throw normalizeError(e);
62
+ }
@@ -1,9 +1,26 @@
1
+ import { CustomError } from 'ts-custom-error';
2
+ export interface BaseErrorOptions {
3
+ cause?: unknown;
4
+ }
1
5
  /**
2
6
  * Base class for all errors in the LikeC4 library.
3
7
  */
4
- export declare const BaseError: import("modern-errors").ErrorSubclassCore<[], {}, import("modern-errors").CustomClass>;
8
+ export declare class BaseError extends CustomError {
9
+ constructor(message: string, options?: BaseErrorOptions);
10
+ }
5
11
  /**
6
12
  * Unknown error, mosly probably a bug, unhandled case or coming from a third-party library.
7
13
  */
8
- export declare const UnknownError: import("modern-errors").ErrorSubclassCore<[], {}, import("modern-errors").CustomClass>;
9
- export declare const RelationRefError: import("modern-errors").ErrorSubclassCore<[], {}, import("modern-errors").CustomClass>;
14
+ export declare class UnknownError extends BaseError {
15
+ constructor(message: string, options?: BaseErrorOptions);
16
+ }
17
+ export declare class RelationRefError extends BaseError {
18
+ constructor(message: string, options?: BaseErrorOptions);
19
+ }
20
+ export declare function normalizeError(e: unknown): BaseError;
21
+ export declare function serializeError(e: unknown): {
22
+ name: string;
23
+ message: string;
24
+ error: BaseError;
25
+ };
26
+ export declare function throwNormalizedError(e: unknown): never;
@@ -1,14 +1,41 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.UnknownError = exports.RelationRefError = exports.BaseError = void 0;
7
- var _modernErrors = _interopRequireDefault(require("modern-errors"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- const BaseError = _modernErrors.default.subclass("BaseError");
10
- exports.BaseError = BaseError;
11
- const UnknownError = BaseError.subclass("UnknownError");
12
- exports.UnknownError = UnknownError;
13
- const RelationRefError = BaseError.subclass("RelationRefError");
14
- exports.RelationRefError = RelationRefError;
1
+ import { CustomError } from "ts-custom-error";
2
+ import stringify from "safe-stable-stringify";
3
+ export class BaseError extends CustomError {
4
+ constructor(message, options) {
5
+ super(message, options);
6
+ Object.defineProperty(this, "name", { value: "BaseError" });
7
+ }
8
+ }
9
+ export class UnknownError extends BaseError {
10
+ constructor(message, options) {
11
+ super(message, options);
12
+ Object.defineProperty(this, "name", { value: "UnknownError" });
13
+ }
14
+ }
15
+ export class RelationRefError extends BaseError {
16
+ constructor(message, options) {
17
+ super(message, options);
18
+ Object.defineProperty(this, "name", { value: "RelationRefError" });
19
+ }
20
+ }
21
+ export function normalizeError(e) {
22
+ if (e instanceof BaseError) {
23
+ return e;
24
+ }
25
+ if (e instanceof Error) {
26
+ return new UnknownError(e.message, { cause: e });
27
+ }
28
+ const message = typeof e === "string" ? e : stringify(e);
29
+ return new UnknownError(message);
30
+ }
31
+ export function serializeError(e) {
32
+ const error = normalizeError(e);
33
+ return {
34
+ name: error.name,
35
+ message: error.stack ? error.stack : `${error.name}: ${error.message}`,
36
+ error
37
+ };
38
+ }
39
+ export function throwNormalizedError(e) {
40
+ throw normalizeError(e);
41
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _base = require("./_base.cjs");
7
+ Object.keys(_base).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _base[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _base[key];
14
+ }
15
+ });
16
+ });
17
+ var _invariant = require("./invariant.cjs");
18
+ Object.keys(_invariant).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _invariant[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _invariant[key];
25
+ }
26
+ });
27
+ });
28
+ var _nonNullable = require("./non-nullable.cjs");
29
+ Object.keys(_nonNullable).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _nonNullable[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _nonNullable[key];
36
+ }
37
+ });
38
+ });
39
+ var _nonexhaustive = require("./nonexhaustive.cjs");
40
+ Object.keys(_nonexhaustive).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _nonexhaustive[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _nonexhaustive[key];
47
+ }
48
+ });
49
+ });
50
+ var _modelIndex = require("./model-index.cjs");
51
+ Object.keys(_modelIndex).forEach(function (key) {
52
+ if (key === "default" || key === "__esModule") return;
53
+ if (key in exports && exports[key] === _modelIndex[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _modelIndex[key];
58
+ }
59
+ });
60
+ });
@@ -1,60 +1,5 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _base = require("./_base");
7
- Object.keys(_base).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _base[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _base[key];
14
- }
15
- });
16
- });
17
- var _invariant = require("./invariant");
18
- Object.keys(_invariant).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _invariant[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _invariant[key];
25
- }
26
- });
27
- });
28
- var _nonNullable = require("./non-nullable");
29
- Object.keys(_nonNullable).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _nonNullable[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _nonNullable[key];
36
- }
37
- });
38
- });
39
- var _nonexhaustive = require("./nonexhaustive");
40
- Object.keys(_nonexhaustive).forEach(function (key) {
41
- if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _nonexhaustive[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function () {
46
- return _nonexhaustive[key];
47
- }
48
- });
49
- });
50
- var _modelIndex = require("./model-index");
51
- Object.keys(_modelIndex).forEach(function (key) {
52
- if (key === "default" || key === "__esModule") return;
53
- if (key in exports && exports[key] === _modelIndex[key]) return;
54
- Object.defineProperty(exports, key, {
55
- enumerable: true,
56
- get: function () {
57
- return _modelIndex[key];
58
- }
59
- });
60
- });
1
+ export * from "./_base.js";
2
+ export * from "./invariant.js";
3
+ export * from "./non-nullable.js";
4
+ export * from "./nonexhaustive.js";
5
+ export * from "./model-index.js";
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.InvariantError = void 0;
7
+ exports.invariant = invariant;
8
+ var _base = require("./_base.cjs");
9
+ class InvariantError extends _base.BaseError {
10
+ constructor(message, options) {
11
+ super(message, options);
12
+ Object.defineProperty(this, "name", {
13
+ value: "InvariantError"
14
+ });
15
+ }
16
+ }
17
+ exports.InvariantError = InvariantError;
18
+ function invariant(condition, message) {
19
+ if (condition) {
20
+ return;
21
+ }
22
+ throw new InvariantError(message ?? "Invariant failed");
23
+ }
@@ -1,2 +1,6 @@
1
- export declare const InvariantError: import("modern-errors").ErrorSubclassCore<[], {}, import("modern-errors").CustomClass>;
1
+ import type { BaseErrorOptions } from './_base';
2
+ import { BaseError } from './_base';
3
+ export declare class InvariantError extends BaseError {
4
+ constructor(message: string, options?: BaseErrorOptions);
5
+ }
2
6
  export declare function invariant(condition: any, message?: string): asserts condition;
@@ -1,16 +1,13 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.InvariantError = void 0;
7
- exports.invariant = invariant;
8
- var _base = require("./_base");
9
- const InvariantError = _base.BaseError.subclass("InvariantError");
10
- exports.InvariantError = InvariantError;
11
- function invariant(condition, message) {
1
+ import { BaseError } from "./_base.js";
2
+ export class InvariantError extends BaseError {
3
+ constructor(message, options) {
4
+ super(message, options);
5
+ Object.defineProperty(this, "name", { value: "InvariantError" });
6
+ }
7
+ }
8
+ export function invariant(condition, message) {
12
9
  if (condition) {
13
10
  return;
14
11
  }
15
12
  throw new InvariantError(message ?? "Invariant failed");
16
- }
13
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.InvalidModelError = void 0;
7
+ exports.ensureModel = ensureModel;
8
+ var _base = require("./_base.cjs");
9
+ class InvalidModelError extends _base.BaseError {
10
+ constructor(message, options) {
11
+ super(message, options);
12
+ Object.defineProperty(this, "name", {
13
+ value: "InvalidModelError"
14
+ });
15
+ }
16
+ }
17
+ exports.InvalidModelError = InvalidModelError;
18
+ function ensureModel(condition, message) {
19
+ if (condition) {
20
+ return;
21
+ }
22
+ throw new InvalidModelError(message ?? "ModelIndex Invariant failed");
23
+ }
@@ -1,2 +1,6 @@
1
- export declare const InvalidModelError: import("modern-errors").ErrorSubclassCore<[], {}, import("modern-errors").CustomClass>;
1
+ import type { BaseErrorOptions } from './_base';
2
+ import { BaseError } from './_base';
3
+ export declare class InvalidModelError extends BaseError {
4
+ constructor(message: string, options?: BaseErrorOptions);
5
+ }
2
6
  export declare function ensureModel(condition: any, message?: string): asserts condition;
@@ -1,16 +1,13 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.InvalidModelError = void 0;
7
- exports.ensureModel = ensureModel;
8
- var _base = require("./_base");
9
- const InvalidModelError = _base.BaseError.subclass("InvalidModelError");
10
- exports.InvalidModelError = InvalidModelError;
11
- function ensureModel(condition, message) {
1
+ import { BaseError } from "./_base.js";
2
+ export class InvalidModelError extends BaseError {
3
+ constructor(message, options) {
4
+ super(message, options);
5
+ Object.defineProperty(this, "name", { value: "InvalidModelError" });
6
+ }
7
+ }
8
+ export function ensureModel(condition, message) {
12
9
  if (condition) {
13
10
  return;
14
11
  }
15
12
  throw new InvalidModelError(message ?? "ModelIndex Invariant failed");
16
- }
13
+ }