@codenotch/codenotch.react 2.0.4 → 2.0.6
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.
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -20
- package/dist/models/Codenotch.d.ts +32 -4
- package/dist/models/Codenotch.d.ts.map +1 -1
- package/dist/models/Codenotch.js +32 -0
- package/dist/models/Misc.d.ts +0 -20
- package/dist/models/Misc.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/index.ts +33 -8
- package/src/models/Codenotch.ts +65 -7
- package/src/models/Misc.ts +0 -24
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ComponentType, type ComponentProps, type FunctionComponent, type RefAttributes } from "react";
|
|
2
2
|
import { IDisposable } from "./models/Misc";
|
|
3
|
-
import { ICodenotchApi, ICodenotchEnv, WithCodenotchProps } from "./models/Codenotch";
|
|
3
|
+
import { ClientTables, ICodenotchApi, ICodenotchEnv, WithCodenotchProps } from "./models/Codenotch";
|
|
4
4
|
import CodeEditor from "./components/CodeEditor";
|
|
5
5
|
/**
|
|
6
6
|
* The Codenotch runtime environment, populated by {@link init}.
|
|
@@ -21,7 +21,8 @@ declare const env: ICodenotchEnv;
|
|
|
21
21
|
* - anything else — copied as-is onto {@link env}.
|
|
22
22
|
*
|
|
23
23
|
* The UI theme is resolved from the `_theme` URL parameter, or from
|
|
24
|
-
* `prefers-color-scheme` as a fallback
|
|
24
|
+
* `prefers-color-scheme` as a fallback, and applied as the `light`/`dark`
|
|
25
|
+
* class on `<html>`.
|
|
25
26
|
*
|
|
26
27
|
* @param envVariables An object containing the Codenotch environment variables as key-value pairs.
|
|
27
28
|
* @example
|
|
@@ -68,8 +69,15 @@ declare function getCodenotch(): ICodenotchApi;
|
|
|
68
69
|
* component or a custom hook). Outside of components — handlers defined in
|
|
69
70
|
* plain modules, services, class components — use {@link getCodenotch} or
|
|
70
71
|
* {@link withCodenotch} instead.
|
|
72
|
+
*
|
|
73
|
+
* @param dbContext The project's tables (typically the object exported by the
|
|
74
|
+
* generated db-schema module), exposed as `tables` on the returned API. Its
|
|
75
|
+
* type is inferred, so `cn.tables.<name>` autocompletes. Pass a module-level
|
|
76
|
+
* reference, not an object built during render, otherwise the returned API
|
|
77
|
+
* changes on every render.
|
|
71
78
|
*/
|
|
72
79
|
declare function useCodenotch(): ICodenotchApi;
|
|
80
|
+
declare function useCodenotch<T extends ClientTables>(dbContext: T): ICodenotchApi<T>;
|
|
73
81
|
/**
|
|
74
82
|
* Register a listener called each time the Codenotch environment changes
|
|
75
83
|
* (`setLanguage`, `setTheme`, `init`). Escape hatch for code that cannot use
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgD,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAkB,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAG1K,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAwB,YAAY,EAAE,aAAa,EAAoB,aAAa,EAA2B,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAErK,OAAO,UAAU,MAAM,yBAAyB,CAAC;AAEjD;;;GAGG;AACH,QAAA,MAAM,GAAG,EAAE,aAAkB,CAAC;AA6B9B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,iBAAS,IAAI,CAAC,YAAY,EAAE,GAAG,GAAG,IAAI,CAkErC;AAySD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,iBAAS,YAAY,IAAI,aAAa,CAErC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iBAAS,YAAY,IAAI,aAAa,CAAC;AACvC,iBAAS,YAAY,CAAC,CAAC,SAAS,YAAY,EAAE,SAAS,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAY9E;;;;;;;;;;;;;;GAcG;AACH,iBAAS,iBAAiB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,WAAW,CAG5D;AAED,wFAAwF;AACxF,KAAK,qBAAqB,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,MAAM,kBAAkB,CAAC,CAAC;AAElE,8FAA8F;AAC9F,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAElF;;;;;;;;;;GAUG;AACH,iBAAS,aAAa,CAAC,CAAC,SAAS,aAAa,CAAC,GAAG,CAAC,EAC/C,SAAS,EAAE,CAAC,GACb,iBAAiB,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAQnG;AAED,OAAO,EACH,GAAG,EACH,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,IAAI,EACJ,UAAU,EACb,CAAC;AAEF,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -76,7 +76,8 @@ function subscribe(listener) {
|
|
|
76
76
|
* - anything else — copied as-is onto {@link env}.
|
|
77
77
|
*
|
|
78
78
|
* The UI theme is resolved from the `_theme` URL parameter, or from
|
|
79
|
-
* `prefers-color-scheme` as a fallback
|
|
79
|
+
* `prefers-color-scheme` as a fallback, and applied as the `light`/`dark`
|
|
80
|
+
* class on `<html>`.
|
|
80
81
|
*
|
|
81
82
|
* @param envVariables An object containing the Codenotch environment variables as key-value pairs.
|
|
82
83
|
* @example
|
|
@@ -134,6 +135,13 @@ function init(envVariables) {
|
|
|
134
135
|
else {
|
|
135
136
|
env.theme = 'light';
|
|
136
137
|
}
|
|
138
|
+
// Apply the resolved theme to <html> like setTheme does. Without this, getTheme()
|
|
139
|
+
// and the DOM disagree until the first setTheme call, which can then be a visual
|
|
140
|
+
// no-op (early return when env.theme already equals the requested theme).
|
|
141
|
+
if (env.theme) {
|
|
142
|
+
document.documentElement.classList.remove(env.theme === 'dark' ? 'light' : 'dark');
|
|
143
|
+
document.documentElement.classList.add(env.theme);
|
|
144
|
+
}
|
|
137
145
|
}
|
|
138
146
|
catch {
|
|
139
147
|
}
|
|
@@ -147,6 +155,7 @@ function init(envVariables) {
|
|
|
147
155
|
function createApi() {
|
|
148
156
|
const api = {
|
|
149
157
|
env: env,
|
|
158
|
+
tables: {},
|
|
150
159
|
uuid: () => (0, uuid_1.v4)(),
|
|
151
160
|
getProjectFileUrl: (relativePath) => {
|
|
152
161
|
if (env.clusterUrl === undefined)
|
|
@@ -194,10 +203,10 @@ function createApi() {
|
|
|
194
203
|
}
|
|
195
204
|
return await response.json();
|
|
196
205
|
},
|
|
197
|
-
|
|
198
|
-
return api.
|
|
206
|
+
startProcess: async (p, inputs) => {
|
|
207
|
+
return api.startProcessFromId(p.id, inputs);
|
|
199
208
|
},
|
|
200
|
-
|
|
209
|
+
startProcessFromId: async (processId, inputs) => {
|
|
201
210
|
if (env.clusterUrl === undefined)
|
|
202
211
|
throw new Error(MISSING_CLUSTER_URL_ERROR);
|
|
203
212
|
if (env.serviceName === undefined)
|
|
@@ -441,22 +450,12 @@ currentApi = createApi();
|
|
|
441
450
|
function getCodenotch() {
|
|
442
451
|
return currentApi;
|
|
443
452
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
* language automatically, and the object is safe to use in `useMemo` /
|
|
451
|
-
* `useEffect` dependency arrays.
|
|
452
|
-
*
|
|
453
|
-
* Regular hook rules apply (call it unconditionally at the top of a function
|
|
454
|
-
* component or a custom hook). Outside of components — handlers defined in
|
|
455
|
-
* plain modules, services, class components — use {@link getCodenotch} or
|
|
456
|
-
* {@link withCodenotch} instead.
|
|
457
|
-
*/
|
|
458
|
-
function useCodenotch() {
|
|
459
|
-
return (0, react_1.useSyncExternalStore)(subscribe, getCodenotch, getCodenotch);
|
|
453
|
+
function useCodenotch(dbContext) {
|
|
454
|
+
const api = (0, react_1.useSyncExternalStore)(subscribe, getCodenotch, getCodenotch);
|
|
455
|
+
// The shared API object is a module-level singleton: expose the caller's
|
|
456
|
+
// tables on a derived copy rather than mutating it. The copy is memoized so
|
|
457
|
+
// the reference stays stable as long as `api` and `dbContext` do.
|
|
458
|
+
return (0, react_1.useMemo)(() => (dbContext ? { ...api, tables: dbContext } : api), [api, dbContext]);
|
|
460
459
|
}
|
|
461
460
|
/**
|
|
462
461
|
* Register a listener called each time the Codenotch environment changes
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import { IAppManifest, ICodenotchProjectManifest } from "@codenotch/codenotch.core";
|
|
3
|
+
import { EntityMetadata, Query, Row, Predicate, Scope } from "@codenotch/orm";
|
|
3
4
|
/**
|
|
4
5
|
* Runtime environment of a Codenotch application.
|
|
5
6
|
*
|
|
@@ -31,7 +32,7 @@ export interface ICodenotchEnv {
|
|
|
31
32
|
[key: string]: any;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
|
-
* Result of a
|
|
35
|
+
* Result of a process execution
|
|
35
36
|
*/
|
|
36
37
|
export interface IProcessResult<T = any> {
|
|
37
38
|
/** Unique id of this execution of the process. */
|
|
@@ -43,6 +44,27 @@ export interface IProcessResult<T = any> {
|
|
|
43
44
|
/** Error details when {@link isError} is `true`. */
|
|
44
45
|
errorMessage: string;
|
|
45
46
|
}
|
|
47
|
+
export declare class ClientTableQueryable<T extends EntityMetadata> {
|
|
48
|
+
private readonly _query;
|
|
49
|
+
constructor(entity: T, serviceName: string);
|
|
50
|
+
/** Wrap an existing query; used internally by the builder methods. */
|
|
51
|
+
constructor(query: Query<T, Row<T>>);
|
|
52
|
+
/**
|
|
53
|
+
* Add a predicate (AND-combined with the previous ones). Returns a new
|
|
54
|
+
* queryable and leaves this one untouched, so a shared `tables.xxx`
|
|
55
|
+
* instance can be reused for independent queries.
|
|
56
|
+
*/
|
|
57
|
+
filter(predicate: (scope: Scope<T>) => Predicate): ClientTableQueryable<T>;
|
|
58
|
+
run(): Promise<T[]>;
|
|
59
|
+
first(): Promise<T | undefined>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The project's tables, keyed by name — augmented via declaration merging by the
|
|
63
|
+
* generated db-schema.d.ts so every table and row type autocompletes.
|
|
64
|
+
*/
|
|
65
|
+
export interface ClientTables {
|
|
66
|
+
[name: string]: ClientTableQueryable<EntityMetadata>;
|
|
67
|
+
}
|
|
46
68
|
type Json = string | number | boolean | null | Json[] | {
|
|
47
69
|
[key: string]: Json;
|
|
48
70
|
};
|
|
@@ -71,11 +93,17 @@ export interface Process<In = unknown, Out = unknown, E extends EventMap = {}> {
|
|
|
71
93
|
* server-side BPMN processes, runs CNQL queries,
|
|
72
94
|
* listens to real-time signals and manages theme/language.
|
|
73
95
|
*/
|
|
74
|
-
export interface ICodenotchApi {
|
|
75
|
-
|
|
76
|
-
|
|
96
|
+
export interface ICodenotchApi<TTables extends ClientTables = ClientTables> {
|
|
97
|
+
startProcessFromId<TInput, TOutput>(processId: string, inputs: TInput): Promise<IProcessResult<TOutput>>;
|
|
98
|
+
startProcess<In, Out>(p: Process<In, Out, any>, inputs: In): Promise<IProcessResult<Out>>;
|
|
77
99
|
/** Runtime environment (cluster, service, language, theme dictionaries, manifests…). Populated by `init()`. */
|
|
78
100
|
readonly env: ICodenotchEnv;
|
|
101
|
+
/**
|
|
102
|
+
* The project's tables, as passed to `useCodenotch(tables)`. The type
|
|
103
|
+
* parameter is inferred from that argument so every table name and row
|
|
104
|
+
* type autocompletes; without an argument it falls back to {@link ClientTables}.
|
|
105
|
+
*/
|
|
106
|
+
readonly tables: TTables;
|
|
79
107
|
/**
|
|
80
108
|
* Execute a CNQL query (XML, SELECT-only) against the project's SQL tables and return the parsed JSON result.
|
|
81
109
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Codenotch.d.ts","sourceRoot":"","sources":["../../src/models/Codenotch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"Codenotch.d.ts","sourceRoot":"","sources":["../../src/models/Codenotch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAA8C,MAAM,gBAAgB,CAAC;AAE1H;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC1B,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iGAAiG;IACjG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oHAAoH;IACpH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iGAAiG;IACjG,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yGAAyG;IACzG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2GAA2G;IAC3G,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAEzB,gGAAgG;IAChG,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B,8EA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
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientTableQueryable = void 0;
|
|
4
|
+
const orm_1 = require("@codenotch/orm");
|
|
5
|
+
/// ======================================================================================================================
|
|
6
|
+
/// consomme @codenotch/orm
|
|
7
|
+
class ClientTableQueryable {
|
|
8
|
+
constructor(entityOrQuery, serviceName) {
|
|
9
|
+
this._query = serviceName === undefined
|
|
10
|
+
? entityOrQuery
|
|
11
|
+
: (0, orm_1.createReadContext)({ source: serviceName, now: () => orm_1.Instant.fromDate(new Date()) }).query(entityOrQuery);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Add a predicate (AND-combined with the previous ones). Returns a new
|
|
15
|
+
* queryable and leaves this one untouched, so a shared `tables.xxx`
|
|
16
|
+
* instance can be reused for independent queries.
|
|
17
|
+
*/
|
|
18
|
+
filter(predicate) {
|
|
19
|
+
return new ClientTableQueryable(this._query.filter(predicate));
|
|
20
|
+
}
|
|
21
|
+
async run() {
|
|
22
|
+
const cnql = this._query.toXml();
|
|
23
|
+
// TODO
|
|
24
|
+
console.log('this._query.toXml():', cnql);
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
async first() {
|
|
28
|
+
const cnql = this._query.toXml();
|
|
29
|
+
// TODO
|
|
30
|
+
console.log('this._query.toXml():', cnql);
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.ClientTableQueryable = ClientTableQueryable;
|
package/dist/models/Misc.d.ts
CHANGED
|
@@ -1,23 +1,3 @@
|
|
|
1
|
-
import { IProcessResult } from "./Codenotch";
|
|
2
|
-
/**
|
|
3
|
-
* Internal callbacks used while a BPMN process instance is running.
|
|
4
|
-
*/
|
|
5
|
-
export interface IProcessCallbacks {
|
|
6
|
-
/** Called once when the process instance completes (successfully or not). */
|
|
7
|
-
onOver: (processResult: IProcessResult) => void;
|
|
8
|
-
/** Called for each intermediate callback emitted by the process. */
|
|
9
|
-
onCallback: (callback: any) => void;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* A real-time signal emitted by a BPMN process,
|
|
13
|
-
* received through `useCodenotch().listenSignal()`.
|
|
14
|
-
*/
|
|
15
|
-
export interface ICodenotchSignal {
|
|
16
|
-
/** Id of the signal, as declared in the BPMN process. */
|
|
17
|
-
signalId: string;
|
|
18
|
-
/** Payload attached to the signal by the process. */
|
|
19
|
-
data: any;
|
|
20
|
-
}
|
|
21
1
|
/**
|
|
22
2
|
* A subscription that can be released.
|
|
23
3
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Misc.d.ts","sourceRoot":"","sources":["../../src/models/Misc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Misc.d.ts","sourceRoot":"","sources":["../../src/models/Misc.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,kEAAkE;IAClE,OAAO,EAAE,MAAM,IAAI,CAAC;CACvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codenotch/codenotch.react",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "React bindings for Codenotch applications: start BPMN processes, run cnql queries, listen to real-time signals, manage theme and language.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codenotch",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@codenotch/codenotch.core": "1.0.23",
|
|
29
|
+
"@codenotch/orm": "0.1.1",
|
|
29
30
|
"uuid": "^8.2.0"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { createElement, useSyncExternalStore, type ComponentType, type ComponentProps, type FunctionComponent, type ReactNode, type RefAttributes } from "react";
|
|
1
|
+
import { createElement, useMemo, useSyncExternalStore, type ComponentType, type ComponentProps, type FunctionComponent, type ReactNode, type RefAttributes } from "react";
|
|
2
2
|
import { flushSync } from "react-dom";
|
|
3
3
|
import { createRoot, Root } from "react-dom/client";
|
|
4
4
|
import { IDisposable } from "./models/Misc";
|
|
5
|
-
import { ICodenotchApi, ICodenotchDialog, ICodenotchEnv, IProcessResult, Process, WithCodenotchProps } from "./models/Codenotch";
|
|
5
|
+
import { ClientTableQueryable, ClientTables, ICodenotchApi, ICodenotchDialog, ICodenotchEnv, IProcessResult, Process, WithCodenotchProps } from "./models/Codenotch";
|
|
6
6
|
import { v4 } from "uuid";
|
|
7
7
|
import CodeEditor from "./components/CodeEditor";
|
|
8
8
|
|
|
@@ -53,7 +53,8 @@ function subscribe(listener: () => void): () => void {
|
|
|
53
53
|
* - anything else — copied as-is onto {@link env}.
|
|
54
54
|
*
|
|
55
55
|
* The UI theme is resolved from the `_theme` URL parameter, or from
|
|
56
|
-
* `prefers-color-scheme` as a fallback
|
|
56
|
+
* `prefers-color-scheme` as a fallback, and applied as the `light`/`dark`
|
|
57
|
+
* class on `<html>`.
|
|
57
58
|
*
|
|
58
59
|
* @param envVariables An object containing the Codenotch environment variables as key-value pairs.
|
|
59
60
|
* @example
|
|
@@ -117,6 +118,14 @@ function init(envVariables: any): void {
|
|
|
117
118
|
else {
|
|
118
119
|
env.theme = 'light';
|
|
119
120
|
}
|
|
121
|
+
|
|
122
|
+
// Apply the resolved theme to <html> like setTheme does. Without this, getTheme()
|
|
123
|
+
// and the DOM disagree until the first setTheme call, which can then be a visual
|
|
124
|
+
// no-op (early return when env.theme already equals the requested theme).
|
|
125
|
+
if (env.theme) {
|
|
126
|
+
document.documentElement.classList.remove(env.theme === 'dark' ? 'light' : 'dark');
|
|
127
|
+
document.documentElement.classList.add(env.theme);
|
|
128
|
+
}
|
|
120
129
|
}
|
|
121
130
|
catch {
|
|
122
131
|
}
|
|
@@ -132,6 +141,7 @@ function init(envVariables: any): void {
|
|
|
132
141
|
function createApi(): ICodenotchApi {
|
|
133
142
|
const api: ICodenotchApi = {
|
|
134
143
|
env: env,
|
|
144
|
+
tables: {},
|
|
135
145
|
uuid: () => v4(),
|
|
136
146
|
getProjectFileUrl: (relativePath: string): string => {
|
|
137
147
|
if (env.clusterUrl === undefined) throw new Error(MISSING_CLUSTER_URL_ERROR);
|
|
@@ -177,10 +187,10 @@ function createApi(): ICodenotchApi {
|
|
|
177
187
|
|
|
178
188
|
return await response.json();
|
|
179
189
|
},
|
|
180
|
-
|
|
181
|
-
return api.
|
|
190
|
+
startProcess: async <In, Out>(p: Process<In, Out, any>, inputs: In): Promise<IProcessResult<Out>> => {
|
|
191
|
+
return api.startProcessFromId<In, Out>(p.id, inputs);
|
|
182
192
|
},
|
|
183
|
-
|
|
193
|
+
startProcessFromId: async <TInput, TOutput>(processId: string, inputs: TInput): Promise<IProcessResult<TOutput>> => {
|
|
184
194
|
if (env.clusterUrl === undefined) throw new Error(MISSING_CLUSTER_URL_ERROR);
|
|
185
195
|
if (env.serviceName === undefined) throw new Error(MISSING_SERVICE_NAME_ERROR);
|
|
186
196
|
|
|
@@ -456,9 +466,24 @@ function getCodenotch(): ICodenotchApi {
|
|
|
456
466
|
* component or a custom hook). Outside of components — handlers defined in
|
|
457
467
|
* plain modules, services, class components — use {@link getCodenotch} or
|
|
458
468
|
* {@link withCodenotch} instead.
|
|
469
|
+
*
|
|
470
|
+
* @param dbContext The project's tables (typically the object exported by the
|
|
471
|
+
* generated db-schema module), exposed as `tables` on the returned API. Its
|
|
472
|
+
* type is inferred, so `cn.tables.<name>` autocompletes. Pass a module-level
|
|
473
|
+
* reference, not an object built during render, otherwise the returned API
|
|
474
|
+
* changes on every render.
|
|
459
475
|
*/
|
|
460
|
-
function useCodenotch(): ICodenotchApi
|
|
461
|
-
|
|
476
|
+
function useCodenotch(): ICodenotchApi;
|
|
477
|
+
function useCodenotch<T extends ClientTables>(dbContext: T): ICodenotchApi<T>;
|
|
478
|
+
function useCodenotch(dbContext?: ClientTables): ICodenotchApi {
|
|
479
|
+
const api = useSyncExternalStore(subscribe, getCodenotch, getCodenotch);
|
|
480
|
+
// The shared API object is a module-level singleton: expose the caller's
|
|
481
|
+
// tables on a derived copy rather than mutating it. The copy is memoized so
|
|
482
|
+
// the reference stays stable as long as `api` and `dbContext` do.
|
|
483
|
+
return useMemo(
|
|
484
|
+
() => (dbContext ? { ...api, tables: dbContext } : api),
|
|
485
|
+
[api, dbContext]
|
|
486
|
+
);
|
|
462
487
|
}
|
|
463
488
|
|
|
464
489
|
/**
|
package/src/models/Codenotch.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import { IAppManifest, ICodenotchProjectManifest } from "@codenotch/codenotch.core";
|
|
3
|
-
import {
|
|
3
|
+
import { EntityMetadata, Query, Row, Predicate, Scope, defineEntity, p, createReadContext, Instant} from "@codenotch/orm";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Runtime environment of a Codenotch application.
|
|
@@ -36,7 +36,7 @@ export interface ICodenotchEnv {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* Result of a
|
|
39
|
+
* Result of a process execution
|
|
40
40
|
*/
|
|
41
41
|
export interface IProcessResult<T = any> {
|
|
42
42
|
|
|
@@ -50,8 +50,60 @@ export interface IProcessResult<T = any> {
|
|
|
50
50
|
errorMessage: string;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/// ======================================================================================================================
|
|
54
|
+
/// consomme @codenotch/orm
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
export class ClientTableQueryable<T extends EntityMetadata> {
|
|
57
|
+
|
|
58
|
+
private readonly _query: Query<T, Row<T>>;
|
|
59
|
+
|
|
60
|
+
constructor(entity: T, serviceName: string);
|
|
61
|
+
/** Wrap an existing query; used internally by the builder methods. */
|
|
62
|
+
constructor(query: Query<T, Row<T>>);
|
|
63
|
+
constructor(entityOrQuery: T | Query<T, Row<T>>, serviceName?: string) {
|
|
64
|
+
this._query = serviceName === undefined
|
|
65
|
+
? entityOrQuery as Query<T, Row<T>>
|
|
66
|
+
: createReadContext({ source: serviceName, now: () => Instant.fromDate(new Date()) }).query(entityOrQuery as T);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Add a predicate (AND-combined with the previous ones). Returns a new
|
|
71
|
+
* queryable and leaves this one untouched, so a shared `tables.xxx`
|
|
72
|
+
* instance can be reused for independent queries.
|
|
73
|
+
*/
|
|
74
|
+
filter(predicate: (scope: Scope<T>) => Predicate): ClientTableQueryable<T> {
|
|
75
|
+
return new ClientTableQueryable<T>(this._query.filter(predicate));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async run(): Promise<T[]>{
|
|
79
|
+
const cnql = this._query.toXml();
|
|
80
|
+
// TODO
|
|
81
|
+
console.log('this._query.toXml():', cnql);
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async first(): Promise<T | undefined> {
|
|
86
|
+
const cnql = this._query.toXml();
|
|
87
|
+
// TODO
|
|
88
|
+
console.log('this._query.toXml():', cnql);
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The project's tables, keyed by name — augmented via declaration merging by the
|
|
95
|
+
* generated db-schema.d.ts so every table and row type autocompletes.
|
|
96
|
+
*/
|
|
97
|
+
export interface ClientTables {
|
|
98
|
+
[name: string]: ClientTableQueryable<EntityMetadata>;
|
|
99
|
+
}
|
|
100
|
+
/// ======================================================================================================================
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
/// ======================================================================================================================
|
|
104
|
+
/// Duplicate of the `Process` interface in @codenotch/process, to avoid a hard dependency on that package in this module.
|
|
105
|
+
/// It is used only for typing the `startProcess()` method of {@link ICodenotchApi}.
|
|
106
|
+
/// @codenotch/process
|
|
55
107
|
type Json = string | number | boolean | null | Json[] | {
|
|
56
108
|
[key: string]: Json;
|
|
57
109
|
};
|
|
@@ -69,7 +121,7 @@ export interface Process<In = unknown, Out = unknown, E extends EventMap = {}> {
|
|
|
69
121
|
events: E;
|
|
70
122
|
};
|
|
71
123
|
}
|
|
72
|
-
///
|
|
124
|
+
/// ======================================================================================================================
|
|
73
125
|
|
|
74
126
|
|
|
75
127
|
/**
|
|
@@ -83,15 +135,21 @@ export interface Process<In = unknown, Out = unknown, E extends EventMap = {}> {
|
|
|
83
135
|
* server-side BPMN processes, runs CNQL queries,
|
|
84
136
|
* listens to real-time signals and manages theme/language.
|
|
85
137
|
*/
|
|
86
|
-
export interface ICodenotchApi {
|
|
138
|
+
export interface ICodenotchApi<TTables extends ClientTables = ClientTables> {
|
|
87
139
|
|
|
88
|
-
|
|
140
|
+
startProcessFromId<TInput, TOutput>(processId: string, inputs: TInput): Promise<IProcessResult<TOutput>>;
|
|
89
141
|
|
|
90
|
-
|
|
142
|
+
startProcess<In, Out>(p: Process<In, Out, any>, inputs: In): Promise<IProcessResult<Out>>;
|
|
91
143
|
|
|
92
144
|
/** Runtime environment (cluster, service, language, theme dictionaries, manifests…). Populated by `init()`. */
|
|
93
145
|
readonly env: ICodenotchEnv;
|
|
94
146
|
|
|
147
|
+
/**
|
|
148
|
+
* The project's tables, as passed to `useCodenotch(tables)`. The type
|
|
149
|
+
* parameter is inferred from that argument so every table name and row
|
|
150
|
+
* type autocompletes; without an argument it falls back to {@link ClientTables}.
|
|
151
|
+
*/
|
|
152
|
+
readonly tables: TTables;
|
|
95
153
|
/**
|
|
96
154
|
* Execute a CNQL query (XML, SELECT-only) against the project's SQL tables and return the parsed JSON result.
|
|
97
155
|
*
|
package/src/models/Misc.ts
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
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
1
|
|
|
26
2
|
/**
|
|
27
3
|
* A subscription that can be released.
|