@codenotch/codenotch.react 1.0.81

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 (39) hide show
  1. package/README.md +145 -0
  2. package/dist/components/Auml.d.ts +46 -0
  3. package/dist/components/Auml.d.ts.map +1 -0
  4. package/dist/components/Auml.js +208 -0
  5. package/dist/components/CodeEditor.d.ts +39 -0
  6. package/dist/components/CodeEditor.d.ts.map +1 -0
  7. package/dist/components/CodeEditor.js +174 -0
  8. package/dist/core/ProcessUtils.d.ts +10 -0
  9. package/dist/core/ProcessUtils.d.ts.map +1 -0
  10. package/dist/core/ProcessUtils.js +65 -0
  11. package/dist/core/SignalR.d.ts +30 -0
  12. package/dist/core/SignalR.d.ts.map +1 -0
  13. package/dist/core/SignalR.js +245 -0
  14. package/dist/index.d.ts +60 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +370 -0
  17. package/dist/models/AppManifestModels.d.ts +46 -0
  18. package/dist/models/AppManifestModels.d.ts.map +1 -0
  19. package/dist/models/AppManifestModels.js +2 -0
  20. package/dist/models/Codenotch.d.ts +256 -0
  21. package/dist/models/Codenotch.d.ts.map +1 -0
  22. package/dist/models/Codenotch.js +2 -0
  23. package/dist/models/Misc.d.ts +28 -0
  24. package/dist/models/Misc.d.ts.map +1 -0
  25. package/dist/models/Misc.js +2 -0
  26. package/dist/models/ProjectManifestModels.d.ts +126 -0
  27. package/dist/models/ProjectManifestModels.d.ts.map +1 -0
  28. package/dist/models/ProjectManifestModels.js +158 -0
  29. package/dist/utils/I18nUtils.d.ts +7 -0
  30. package/dist/utils/I18nUtils.d.ts.map +1 -0
  31. package/dist/utils/I18nUtils.js +37 -0
  32. package/package.json +44 -0
  33. package/src/components/CodeEditor.tsx +203 -0
  34. package/src/core/ProcessUtils.ts +86 -0
  35. package/src/core/SignalR.ts +375 -0
  36. package/src/index.ts +387 -0
  37. package/src/models/AppManifestModels.ts +54 -0
  38. package/src/models/Codenotch.ts +285 -0
  39. package/src/models/Misc.ts +32 -0
@@ -0,0 +1,285 @@
1
+ import { ProjectManifest } from "@codenotch/codenotch.core";
2
+ import { ICodenotchSignal, IDisposable } from "./Misc";
3
+ import { ApplicationManifest } from "./AppManifestModels";
4
+
5
+ /**
6
+ * Runtime environment of a Codenotch application.
7
+ *
8
+ * Populated by `init()` from the environment variables injected by the Codenotch
9
+ * runtime into the hosting page, and exposed read-only through {@link ICodenotchApi.env}.
10
+ */
11
+ export interface ICodenotchEnv {
12
+ /** Name of the current application. */
13
+ appName?: string;
14
+ /** Base URL of the Codenotch cluster hosting the project, e.g. `https://cluster.example.com`. */
15
+ clusterUrl?: string;
16
+ /** Service name of the project (`serviceName` in the project's `manifest.json`). Used to build every server URL. */
17
+ serviceName?: string;
18
+ /** Name of the tenant hosting the project. Required when authenticating with an access token. */
19
+ tenantName?: string;
20
+ /** Access token used to authenticate server calls, sent as the `<tenantName>AccessToken` HTTP header. */
21
+ accessToken?: string;
22
+ /** Base URL of the current application. */
23
+ baseUrl?: string;
24
+ /** Translation dictionaries, keyed by language then by translation key: `i18n[language][key] = text`. */
25
+ i18n?: { [language: string]: { [key: string]: string } };
26
+ /** Current language code (e.g. `"en"`). Defaults to the first language found in {@link i18n}. */
27
+ language?: string;
28
+ /** Current UI theme. Resolved from the `_theme` URL parameter, or `prefers-color-scheme` as a fallback. */
29
+ theme?: 'light' | 'dark';
30
+
31
+ /** Manifest of the current application (the `<AppName>.manifest.json` file next to the app). */
32
+ appManifest?: ApplicationManifest;
33
+ /** Manifest of the Codenotch project (the project's `manifest.json` file). */
34
+ projectManifest?: ProjectManifest;
35
+
36
+ /** Any additional environment variable passed to `init()`. */
37
+ [key: string]: any; // Allow additional properties
38
+ }
39
+
40
+
41
+ /**
42
+ * Registry of the project's BPMN processes, used to type {@link ICodenotchApi.startProcess}.
43
+ *
44
+ * Empty by default: the Codenotch IDE fills it through declaration merging in the
45
+ * auto-generated `typings/process.d.ts` file of each project, with one entry per
46
+ * BPMN process. Each entry maps the process name to its start events (`nodes`,
47
+ * keyed by start node id, valued with the start event's input parameters) and to
48
+ * the `output` of its end event.
49
+ *
50
+ * When the registry has not been augmented (project built without the IDE
51
+ * typings), `startProcess` falls back to plain string names and untyped inputs,
52
+ * so the code still compiles.
53
+ *
54
+ * @example
55
+ * // typings/process.d.ts (auto-generated by the Codenotch IDE)
56
+ * import 'codenotch-react';
57
+ * declare module 'codenotch-react' {
58
+ * interface ProcessRegistry {
59
+ * 'getTodos': {
60
+ * nodes: { 'start': { UserId: string } };
61
+ * output: { todos: any[] };
62
+ * };
63
+ * }
64
+ * }
65
+ */
66
+ export interface ProcessRegistry {
67
+ // Extended by codenotch IDE
68
+ }
69
+
70
+ /**
71
+ * Registry of the project's translation keys, used to type {@link ICodenotchApi.i18n}.
72
+ *
73
+ * Empty by default: the Codenotch IDE fills it through declaration merging in the
74
+ * auto-generated `typings/i18n.d.ts` file of each project, from the project's
75
+ * `.i18n.csv` files. Each entry maps a translation key to the tuple of arguments
76
+ * expected by its `{0}`, `{1}`, … placeholders.
77
+ *
78
+ * When the registry has not been augmented (project built without the IDE
79
+ * typings), `i18n` falls back to plain string keys and untyped arguments,
80
+ * so the code still compiles.
81
+ *
82
+ * @example
83
+ * // typings/i18n.d.ts (auto-generated by the Codenotch IDE)
84
+ * import 'codenotch-react';
85
+ * declare module 'codenotch-react' {
86
+ * interface TranslationRegistry {
87
+ * 'welcome': [];
88
+ * 'greeting': [arg1: any, arg2: any];
89
+ * }
90
+ * }
91
+ */
92
+ export interface TranslationRegistry {
93
+ // Extended by codenotch IDE
94
+ }
95
+
96
+ // When the codenotch IDE has not augmented the registries, `keyof Registry` is `never`
97
+ // and every call would fail to compile. These helpers fall back to plain string keys
98
+ // and untyped arguments so the API stays usable without code generation.
99
+
100
+ /** A BPMN process name: a key of {@link ProcessRegistry}, or any string when the registry is empty. */
101
+ export type ProcessName = keyof ProcessRegistry extends never ? string : keyof ProcessRegistry;
102
+
103
+ /** The start nodes of process `P`: its `nodes` map from {@link ProcessRegistry}, or an open map when unknown. */
104
+ export type ProcessNodes<P> = P extends keyof ProcessRegistry
105
+ ? ProcessRegistry[P] extends { nodes: infer N } ? N : { [nodeId: string]: any }
106
+ : { [nodeId: string]: any };
107
+
108
+ /** The end-event output of process `P` from {@link ProcessRegistry}, or `any` when unknown. */
109
+ export type ProcessOutput<P> = P extends keyof ProcessRegistry
110
+ ? ProcessRegistry[P] extends { output: infer O } ? O : any
111
+ : any;
112
+
113
+ /** A translation key: a key of {@link TranslationRegistry}, or any string when the registry is empty. */
114
+ export type TranslationKey = keyof TranslationRegistry extends never ? string : keyof TranslationRegistry;
115
+
116
+ /** The placeholder arguments of translation key `K` from {@link TranslationRegistry}, or `any[]` when unknown. */
117
+ export type TranslationArgs<K> = K extends keyof TranslationRegistry
118
+ ? TranslationRegistry[K] extends any[] ? TranslationRegistry[K] : any[]
119
+ : any[];
120
+
121
+
122
+ /**
123
+ * Result of a BPMN process execution started with {@link ICodenotchApi.startProcess}.
124
+ */
125
+ export interface IProcessResult<T = any> {
126
+
127
+ /** Unique id of this execution of the process. */
128
+ processInstanceId: string;
129
+ /** Output parameters of the end event reached by the process. */
130
+ output: T;
131
+ /** `true` if the process ended in error; check it before reading {@link output}. */
132
+ isError: boolean;
133
+ /** Error details when {@link isError} is `true`. */
134
+ errorMessage: string;
135
+ }
136
+
137
+ /**
138
+ * The Codenotch client API, obtained by calling `useCodenotch()`.
139
+ *
140
+ * It is the bridge between a React app and the Codenotch runtime: it starts
141
+ * server-side BPMN processes, runs SioQL queries, translates i18n keys,
142
+ * listens to real-time signals and manages theme/language.
143
+ *
144
+ * @example
145
+ * import { useCodenotch } from 'codenotch-react';
146
+ *
147
+ * const cn = useCodenotch();
148
+ * const title = cn.i18n('welcome');
149
+ * const result = await cn.startProcess('getTodos', 'start', { UserId: '42' });
150
+ */
151
+ export interface ICodenotchApi {
152
+
153
+ /**
154
+ * Start a server-side BPMN process and wait for its completion.
155
+ *
156
+ * @param processName Name of the process — the `.bpmn` file name without extension (e.g. `processes/getTodos.bpmn` → `'getTodos'`).
157
+ * @param startNodeId Id of the start event to trigger (conventionally `'start'`).
158
+ * @param inputs Input parameters declared by that start event.
159
+ * @returns The process result; check `isError` before using `output` (the parameters of the end event reached).
160
+ * @example
161
+ * const result = await cn.startProcess('getTodos', 'start', { UserId: userId });
162
+ * if (!result.isError) {
163
+ * setTodos(result.output.todos);
164
+ * }
165
+ */
166
+ startProcess<P extends ProcessName, N extends keyof ProcessNodes<P>>(
167
+ processName: P,
168
+ startNodeId: N,
169
+ inputs: ProcessNodes<P>[N]
170
+ ): Promise<IProcessResult<ProcessOutput<P>>>;
171
+
172
+ /**
173
+ * Translate a key for the current language ({@link ICodenotchEnv.language}).
174
+ *
175
+ * Placeholders `{0}`, `{1}`, … in the translated text are replaced by `args`.
176
+ * Never throws: if the key or the language is missing, a warning is logged
177
+ * and the key itself is returned.
178
+ *
179
+ * @param key Translation key, as defined in the project's `.i18n.csv` files.
180
+ * @param args Values for the `{0}`, `{1}`, … placeholders of the translation.
181
+ * @example
182
+ * cn.i18n('welcome'); // "Bienvenue"
183
+ * cn.i18n('greeting', 'Fabian', 3); // "Bonjour Fabian, 3 messages" (from "Bonjour {0}, {1} messages")
184
+ */
185
+ i18n<K extends TranslationKey>(
186
+ key: K,
187
+ ...args: TranslationArgs<K>
188
+ ): string;
189
+
190
+ /** Runtime environment (cluster, service, language, theme, i18n dictionaries, manifests…). Populated by `init()`. */
191
+ readonly env: ICodenotchEnv;
192
+
193
+ /**
194
+ * Execute a SioQL query (XML, SELECT-only) against the project's SQL tables and return the parsed JSON result.
195
+ *
196
+ * The root element's `xmlns` must be the project's `serviceName`. Results are
197
+ * keyed by the `Ref` attribute of each queried table.
198
+ *
199
+ * @param sioql The SioQL XML query.
200
+ * @param verbose When `true`, asks the server for a verbose response (debugging).
201
+ * @example
202
+ * const data = await cn.requestSioql(`
203
+ * <SioQL xmlns="myproject" PageSize="10" PageIndex="0">
204
+ * <Users Ref="results">
205
+ * <Id />
206
+ * <Email />
207
+ * </Users>
208
+ * </SioQL>`);
209
+ * console.log(data.results); // [{ Id: ..., Email: ... }, ...]
210
+ */
211
+ readonly requestSioql: (sioql: string, verbose?: boolean) => Promise<any>;
212
+
213
+ /**
214
+ * Render the given React element in a fullscreen modal `<dialog>` overlay.
215
+ *
216
+ * The dialog is not closed automatically: keep the returned handle and call
217
+ * its `close()` method (typically from a button inside the dialog content).
218
+ *
219
+ * @example
220
+ * const dialog = cn.showDialog(
221
+ * <div className="bg-white p-4 rounded">
222
+ * <p>Are you sure?</p>
223
+ * <button onClick={() => dialog.close()}>Close</button>
224
+ * </div>
225
+ * );
226
+ */
227
+ readonly showDialog: (node: JSX.Element) => ICodenotchDialog;
228
+
229
+ /**
230
+ * Fetch the text content of a file of the deployed Codenotch project.
231
+ * @param relativePath Path of the file relative to the project root (e.g. `'readme.md'`).
232
+ */
233
+ readonly getProjectFile: (relativePath: string) => Promise<string | undefined>;
234
+
235
+ /**
236
+ * Build the URL serving a file of the deployed Codenotch project
237
+ * (useful as `src` for images or links).
238
+ * @param relativePath Path of the file relative to the project root.
239
+ */
240
+ readonly getProjectFileUrl: (relativePath: string) => string;
241
+
242
+ /**
243
+ * Subscribe to a real-time signal emitted by the project's BPMN processes (via SignalR).
244
+ *
245
+ * @param signalId Id of the signal, as declared in the BPMN process.
246
+ * @param callback Called each time the signal is received, with `{ signalId, data }`.
247
+ * @returns A disposable — call `dispose()` to unsubscribe (e.g. in a `useEffect` cleanup).
248
+ * @example
249
+ * useEffect(() => {
250
+ * let sub: IDisposable | undefined;
251
+ * cn.listenSignal('todosChanged', () => refresh()).then(s => sub = s);
252
+ * return () => sub?.dispose();
253
+ * }, []);
254
+ */
255
+ readonly listenSignal: (signalId: string, callback: (data: ICodenotchSignal) => void) => Promise<IDisposable>;
256
+
257
+ /** Set the UI theme. Also toggles the `light`/`dark` class on `<html>` (Tailwind `dark:` variants). */
258
+ readonly setTheme: (theme: 'light' | 'dark') => void;
259
+ /** Current UI theme, if resolved. */
260
+ readonly getTheme: () => 'light' | 'dark' | undefined;
261
+ /** Set the current language used by {@link i18n}. Must be one of the project's languages. */
262
+ readonly setLanguage: (lang: string) => void;
263
+ /** Current language code, if any. */
264
+ readonly getLanguage: () => string | undefined;
265
+ /** Languages declared in the project's `manifest.json`. */
266
+ readonly getLanguages: () => string[];
267
+ /** Query-string parameters of the current URL, as a plain object (first value wins for duplicated keys). */
268
+ readonly getUrlParams: () => { [key: string]: string };
269
+ /** Generate a random UUID v4. */
270
+ readonly uuid: () => string;
271
+ /** Manifest of the Codenotch project. Throws if not available in the environment. */
272
+ readonly getProjectManifest: () => ProjectManifest;
273
+ /** Manifest of the current application, if any. */
274
+ readonly getAppManifest: () => ApplicationManifest | undefined;
275
+ }
276
+
277
+ /**
278
+ * Handle on a dialog opened with {@link ICodenotchApi.showDialog}.
279
+ */
280
+ export interface ICodenotchDialog {
281
+ /** DOM id of the underlying `<dialog>` element. */
282
+ id: string;
283
+ /** Close the dialog and remove it from the DOM. */
284
+ close: () => void;
285
+ }
@@ -0,0 +1,32 @@
1
+ import { IProcessResult } from "./Codenotch";
2
+
3
+ /**
4
+ * Internal callbacks used while a BPMN process instance is running.
5
+ */
6
+ export interface IProcessCallbacks
7
+ {
8
+ /** Called once when the process instance completes (successfully or not). */
9
+ onOver: (processResult: IProcessResult) => void,
10
+ /** Called for each intermediate callback emitted by the process. */
11
+ onCallback:( callback: any) => void
12
+ }
13
+
14
+ /**
15
+ * A real-time signal emitted by a BPMN process,
16
+ * received through `useCodenotch().listenSignal()`.
17
+ */
18
+ export interface ICodenotchSignal
19
+ {
20
+ /** Id of the signal, as declared in the BPMN process. */
21
+ signalId: string;
22
+ /** Payload attached to the signal by the process. */
23
+ data: any;
24
+ }
25
+
26
+ /**
27
+ * A subscription that can be released.
28
+ */
29
+ export interface IDisposable {
30
+ /** Release the subscription (e.g. stop listening to a signal). */
31
+ dispose: () => void;
32
+ }