graphwise-reactodia 0.0.1-TR16 → 0.0.1-TR17

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 (42) hide show
  1. package/README.md +35 -0
  2. package/dist/cjs/error-code-NpXlqCEN.js +28 -0
  3. package/dist/cjs/graphwise-reactodia.cjs.entry.js +232 -37
  4. package/dist/cjs/graphwise-reactodia.cjs.js +1 -1
  5. package/dist/cjs/{index-CII9aUQC.js → index-DtzCybH4.js} +16 -0
  6. package/dist/cjs/index.cjs.js +10 -4
  7. package/dist/cjs/loader.cjs.js +1 -1
  8. package/dist/collection/components/graphwise-reactodia/graphwise-reactodia.js +44 -4
  9. package/dist/collection/components/graphwise-reactodia/menu/graphwise-menu.js +4 -1
  10. package/dist/collection/components/graphwise-reactodia/models/error/error-callback.js +1 -0
  11. package/dist/collection/components/graphwise-reactodia/models/error/error-cause.js +1 -0
  12. package/dist/collection/components/graphwise-reactodia/models/error/error-code.js +18 -0
  13. package/dist/collection/components/graphwise-reactodia/models/error/error-report.js +4 -0
  14. package/dist/collection/components/graphwise-reactodia/reactodia-app.js +53 -19
  15. package/dist/collection/components/graphwise-reactodia/services/diagram-storage/diagram-storage.service.js +20 -4
  16. package/dist/collection/components/graphwise-reactodia/services/error/error.service.js +89 -0
  17. package/dist/collection/index.js +2 -0
  18. package/dist/collection/pages/graphwise-reactodia/main.js +37 -0
  19. package/dist/esm/error-code-7lGYbTwb.js +26 -0
  20. package/dist/esm/graphwise-reactodia.entry.js +228 -33
  21. package/dist/esm/graphwise-reactodia.js +2 -2
  22. package/dist/esm/{index-Cypw7ydc.js → index-DpCR6zMg.js} +16 -1
  23. package/dist/esm/index.js +5 -4
  24. package/dist/esm/loader.js +2 -2
  25. package/dist/graphwise-reactodia/graphwise-reactodia.esm.js +1 -1
  26. package/dist/graphwise-reactodia/index.esm.js +1 -1
  27. package/dist/graphwise-reactodia/p-7lGYbTwb.js +1 -0
  28. package/dist/graphwise-reactodia/p-DpCR6zMg.js +2 -0
  29. package/dist/graphwise-reactodia/p-ec30185a.entry.js +1 -0
  30. package/dist/types/components/graphwise-reactodia/graphwise-reactodia.d.ts +9 -0
  31. package/dist/types/components/graphwise-reactodia/models/error/error-callback.d.ts +5 -0
  32. package/dist/types/components/graphwise-reactodia/models/error/error-cause.d.ts +10 -0
  33. package/dist/types/components/graphwise-reactodia/models/error/error-code.d.ts +17 -0
  34. package/dist/types/components/graphwise-reactodia/models/error/error-report.d.ts +17 -0
  35. package/dist/types/components/graphwise-reactodia/reactodia-app.d.ts +1 -1
  36. package/dist/types/components/graphwise-reactodia/services/diagram-storage/diagram-storage.service.d.ts +1 -0
  37. package/dist/types/components/graphwise-reactodia/services/error/error.service.d.ts +50 -0
  38. package/dist/types/components.d.ts +21 -0
  39. package/dist/types/index.d.ts +3 -0
  40. package/package.json +1 -1
  41. package/dist/graphwise-reactodia/p-20637a6f.entry.js +0 -1
  42. package/dist/graphwise-reactodia/p-Cypw7ydc.js +0 -2
@@ -1,6 +1,8 @@
1
+ import { EventEmitter } from '../../stencil-public-runtime';
1
2
  import { SparqlDataProviderSettings } from '@reactodia/workspace';
2
3
  import { LanguageKey } from './i18n/language-key';
3
4
  import { ReactodiaConfig } from './models/reactodia-config';
5
+ import { ErrorReport } from './models/error/error-report';
4
6
  /**
5
7
  * A web component that renders a graph with the Reactodia workspace.
6
8
  *
@@ -14,6 +16,7 @@ import { ReactodiaConfig } from './models/reactodia-config';
14
16
  */
15
17
  export declare class GraphwiseReactodia {
16
18
  private readonly hostElement?;
19
+ private readonly subscriptions;
17
20
  /**
18
21
  * The active repository id. Appended to {@link queryFunction} as the request `url`;
19
22
  * changing it re-points the graph at the new repository (and resets the canvas),
@@ -43,6 +46,10 @@ export declare class GraphwiseReactodia {
43
46
  * The reactodia theme to use
44
47
  */
45
48
  theme?: 'light' | 'dark';
49
+ /**
50
+ * Fires, when an error has occurred. The host decides how to handle it.
51
+ */
52
+ errorEmitter: EventEmitter<ErrorReport>;
46
53
  private reactRoot?;
47
54
  /**
48
55
  * `connectedCallback` and the watchers can run before all props are set: when the component's
@@ -59,5 +66,7 @@ export declare class GraphwiseReactodia {
59
66
  componentDidLoad(): void;
60
67
  disconnectedCallback(): void;
61
68
  render(): any;
69
+ private subscribeToErrors;
62
70
  private renderGraph;
71
+ private reportMissingPropError;
63
72
  }
@@ -0,0 +1,5 @@
1
+ import { ErrorReport } from './error-report';
2
+ /**
3
+ * Callback invoked with every reported error.
4
+ */
5
+ export type ErrorCallback = (report: ErrorReport) => void;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * A link in the `cause` chain of a thrown value: the value itself, its `cause`, the cause of that, and so on.
3
+ * Anything can be thrown, so a link is not necessarily an `Error` and neither field is guaranteed.
4
+ */
5
+ export interface ErrorCause {
6
+ /** The error name, e.g. `AbortError`. */
7
+ name?: unknown;
8
+ /** The next link in the chain. */
9
+ cause?: unknown;
10
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The stable category of a reported error. The host uses it to choose its own message.
3
+ */
4
+ export declare enum ErrorCode {
5
+ /** A required prop is missing. */
6
+ MISSING_REQUIRED_PROP = "missing-required-prop",
7
+ /** A SPARQL data provider call failed. */
8
+ DATA_FETCH = "data-fetch",
9
+ /** The startup load, a reload or a repository switch failed. */
10
+ DIAGRAM_LOAD = "diagram-load",
11
+ /** The uploaded file was rejected or its import failed. */
12
+ DIAGRAM_IMPORT = "diagram-import",
13
+ /** Reading the diagram from local storage failed. */
14
+ LOCAL_DIAGRAM_READ = "local-diagram-read",
15
+ /** Saving the diagram in local storage failed. */
16
+ LOCAL_DIAGRAM_SAVE = "local-diagram-save"
17
+ }
@@ -0,0 +1,17 @@
1
+ import { ErrorCode } from './error-code';
2
+ /**
3
+ * Name of the DOM event the `graphwise-reactodia` element dispatches for every reported error.
4
+ */
5
+ export declare const GRAPHWISE_REACTODIA_ERROR_EVENT = "graphwiseReactodiaError";
6
+ /**
7
+ * A failure the wrapper announces to the host.
8
+ */
9
+ export interface ErrorReport {
10
+ code: ErrorCode;
11
+ /**
12
+ * The thrown value, passed on unchanged. The wrapper and the fork throw `Error`s with an untranslated `message`, but
13
+ * a failure of the host's `config.queryFunction` arrives as whatever it rejected with (e.g. an HTTP error response),
14
+ * so narrow it before use.
15
+ */
16
+ error: unknown;
17
+ }
@@ -8,7 +8,7 @@ export declare function mountReactodia(container: HTMLElement, props: ReactodiaA
8
8
  /**
9
9
  * Re-points the diagram at a new SPARQL endpoint by recreating it with a fresh data provider.
10
10
  * The canvas is reset to empty, matching the initial mount, since the data of another repository
11
- * has nothing to do with the current graph.
11
+ * has nothing to do with the current graph. A failure is reported, not thrown.
12
12
  */
13
13
  export declare function updateReactodia(props: ReactodiaAppProps): Promise<void>;
14
14
  /**
@@ -5,6 +5,7 @@ import type { SerializedDiagram } from '@reactodia/workspace';
5
5
  export declare class DiagramStorageService {
6
6
  static readonly ID = "DiagramStorageService";
7
7
  private static readonly STORAGE_KEY;
8
+ private readonly errorService;
8
9
  /**
9
10
  * Load the persisted diagram from the local store, or `undefined` when nothing is stored (or the stored value
10
11
  * is unreadable).
@@ -0,0 +1,50 @@
1
+ import { Subscription } from '../../models/subscription';
2
+ import { ErrorCallback } from '../../models/error/error-callback';
3
+ import { ErrorCode } from '../../models/error/error-code';
4
+ /**
5
+ * Service that collects the failures of the wrapper and the fork, so they can be announced to the host.
6
+ */
7
+ export declare class ErrorService {
8
+ static readonly ID = "ErrorService";
9
+ private static readonly ABORT_ERROR_NAME;
10
+ private callback?;
11
+ private readonly reported;
12
+ /**
13
+ * Reports a failure to the host, unless it's an abort, or this exact error object is already reported
14
+ * from another place.
15
+ *
16
+ * The same error object may be reported from different places. E.g. a query that fails while a diagram loads is
17
+ * reported by the data provider decorator as `data-fetch`, and then reaches the `catch` around the load, which
18
+ * reports it as `diagram-load`. Only the first one is announced.
19
+ *
20
+ * The `cause` is checked because the fork wraps whatever fails during a diagram import in a new error:
21
+ *
22
+ * ```ts
23
+ * // reactodia-workspace/src/editor/dataDiagramModel.ts, importLayout
24
+ * } catch (error) {
25
+ * throw new Error('Reactodia: failed to import a layout', {cause: error});
26
+ * }
27
+ * ```
28
+ *
29
+ * We need to check the cause to make sure we don't report the same error/abort more than once.
30
+ *
31
+ * @param code The category of the failure.
32
+ * @param thrown The thrown value.
33
+ */
34
+ report(code: ErrorCode, thrown: unknown): void;
35
+ /**
36
+ * Subscribes to the reported errors, replacing the previous subscriber.
37
+ *
38
+ * @param callback Called with every reported error.
39
+ * @returns A {@link Subscription} that, when called, removes the callback, unless it has already been replaced.
40
+ */
41
+ subscribe(callback: ErrorCallback): Subscription;
42
+ /**
43
+ * Whether any link of the given cause chain is an abort or is already reported.
44
+ */
45
+ private isAbortedOrAlreadyReported;
46
+ /**
47
+ * The thrown value followed by its `cause`, the cause of that, and so on, for as long as they are objects.
48
+ */
49
+ private causeChain;
50
+ }
@@ -8,9 +8,11 @@ import { HTMLStencilElement, JSXBase } from "./stencil-public-runtime";
8
8
  import { ReactodiaConfig } from "./components/graphwise-reactodia/models/reactodia-config";
9
9
  import { LanguageKey } from "./components/graphwise-reactodia/i18n/language-key";
10
10
  import { SparqlDataProviderSettings } from "@reactodia/workspace";
11
+ import { ErrorReport } from "./components/graphwise-reactodia/models/error/error-report";
11
12
  export { ReactodiaConfig } from "./components/graphwise-reactodia/models/reactodia-config";
12
13
  export { LanguageKey } from "./components/graphwise-reactodia/i18n/language-key";
13
14
  export { SparqlDataProviderSettings } from "@reactodia/workspace";
15
+ export { ErrorReport } from "./components/graphwise-reactodia/models/error/error-report";
14
16
  export namespace Components {
15
17
  /**
16
18
  * A web component that renders a graph with the Reactodia workspace.
@@ -45,7 +47,14 @@ export namespace Components {
45
47
  "theme"?: 'light' | 'dark';
46
48
  }
47
49
  }
50
+ export interface GraphwiseReactodiaCustomEvent<T> extends CustomEvent<T> {
51
+ detail: T;
52
+ target: HTMLGraphwiseReactodiaElement;
53
+ }
48
54
  declare global {
55
+ interface HTMLGraphwiseReactodiaElementEventMap {
56
+ "graphwiseReactodiaError": ErrorReport;
57
+ }
49
58
  /**
50
59
  * A web component that renders a graph with the Reactodia workspace.
51
60
  * The component is backed by a SPARQL endpoint but is endpoint-agnostic: the host passes
@@ -56,6 +65,14 @@ declare global {
56
65
  * wrapper and is supplied through the `providerSettings` prop.
57
66
  */
58
67
  interface HTMLGraphwiseReactodiaElement extends Components.GraphwiseReactodia, HTMLStencilElement {
68
+ addEventListener<K extends keyof HTMLGraphwiseReactodiaElementEventMap>(type: K, listener: (this: HTMLGraphwiseReactodiaElement, ev: GraphwiseReactodiaCustomEvent<HTMLGraphwiseReactodiaElementEventMap[K]>) => any, options?: boolean | AddEventListenerOptions): void;
69
+ addEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
70
+ addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
71
+ addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
72
+ removeEventListener<K extends keyof HTMLGraphwiseReactodiaElementEventMap>(type: K, listener: (this: HTMLGraphwiseReactodiaElement, ev: GraphwiseReactodiaCustomEvent<HTMLGraphwiseReactodiaElementEventMap[K]>) => any, options?: boolean | EventListenerOptions): void;
73
+ removeEventListener<K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
74
+ removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
75
+ removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
59
76
  }
60
77
  var HTMLGraphwiseReactodiaElement: {
61
78
  prototype: HTMLGraphwiseReactodiaElement;
@@ -89,6 +106,10 @@ declare namespace LocalJSX {
89
106
  * @default LanguageKey.EN
90
107
  */
91
108
  "language"?: LanguageKey;
109
+ /**
110
+ * Fires, when an error has occurred. The host decides how to handle it.
111
+ */
112
+ "onGraphwiseReactodiaError"?: (event: GraphwiseReactodiaCustomEvent<ErrorReport>) => void;
92
113
  /**
93
114
  * Query preset for the SPARQL data provider, owned and configured by the host. A DOM property (an object, not an attribute) passed in from outside the wrapper. Required: the wrapper has no default preset and throws when it is missing. Changing it rebuilds the data provider and reloads the graph with it, keeping the current diagram.
94
115
  */
@@ -1 +1,4 @@
1
1
  export { CLEAR_DIAGRAM_STORAGE_EVENT } from './components/graphwise-reactodia/models/clear-diagram-storage-event';
2
+ export { GRAPHWISE_REACTODIA_ERROR_EVENT } from './components/graphwise-reactodia/models/error/error-report';
3
+ export { ErrorCode } from './components/graphwise-reactodia/models/error/error-code';
4
+ export type { ErrorReport } from './components/graphwise-reactodia/models/error/error-report';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphwise-reactodia",
3
- "version": "0.0.1-TR16",
3
+ "version": "0.0.1-TR17",
4
4
  "description": "Graphwise wrapper around the Reactodia graph explorer.",
5
5
  "license": "LGPL-3.0-or-later",
6
6
  "author": "Ontotext AD",