@codenotch/codenotch.react 2.0.5 → 2.0.7

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 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}.
@@ -69,8 +69,15 @@ declare function getCodenotch(): ICodenotchApi;
69
69
  * component or a custom hook). Outside of components — handlers defined in
70
70
  * plain modules, services, class components — use {@link getCodenotch} or
71
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.
72
78
  */
73
79
  declare function useCodenotch(): ICodenotchApi;
80
+ declare function useCodenotch<T extends ClientTables>(dbContext: T): ICodenotchApi<T>;
74
81
  /**
75
82
  * Register a listener called each time the Codenotch environment changes
76
83
  * (`setLanguage`, `setTheme`, `init`). Escape hatch for code that cannot use
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAkB,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAGjK,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAoB,aAAa,EAA2B,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE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AED,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
@@ -155,6 +155,7 @@ function init(envVariables) {
155
155
  function createApi() {
156
156
  const api = {
157
157
  env: env,
158
+ tables: {},
158
159
  uuid: () => (0, uuid_1.v4)(),
159
160
  getProjectFileUrl: (relativePath) => {
160
161
  if (env.clusterUrl === undefined)
@@ -449,22 +450,12 @@ currentApi = createApi();
449
450
  function getCodenotch() {
450
451
  return currentApi;
451
452
  }
452
- /**
453
- * React hook returning the Codenotch client API.
454
- *
455
- * The reference is stable across renders and only changes when the environment
456
- * changes (`setLanguage`, `setTheme`, `init`), in which case every component
457
- * using the hook re-renders output follows the current
458
- * language automatically, and the object is safe to use in `useMemo` /
459
- * `useEffect` dependency arrays.
460
- *
461
- * Regular hook rules apply (call it unconditionally at the top of a function
462
- * component or a custom hook). Outside of components — handlers defined in
463
- * plain modules, services, class components — use {@link getCodenotch} or
464
- * {@link withCodenotch} instead.
465
- */
466
- function useCodenotch() {
467
- 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]);
468
459
  }
469
460
  /**
470
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
  *
@@ -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 {
96
+ export interface ICodenotchApi<TTables extends ClientTables = ClientTables> {
75
97
  startProcessFromId<TInput, TOutput>(processId: string, inputs: TInput): Promise<IProcessResult<TOutput>>;
76
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;AAGpF;;;;;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,8EAA8E;IAC9E,eAAe,CAAC,EAAE,yBAAyB,CAAC;IAE5C,8DAA8D;IAC9D,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,GAAG;IAEnC,kDAAkD;IAClD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iEAAiE;IACjE,MAAM,EAAE,CAAC,CAAC;IACV,oFAAoF;IACpF,OAAO,EAAE,OAAO,CAAC;IACjB,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC;CACxB;AAID,KAAK,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GA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IACxE,QAAQ,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,qCAAqC;IACrC,QAAQ,CAAC,WAAW,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IAC/C,2DAA2D;IAC3D,QAAQ,CAAC,YAAY,EAAE,MAAM,MAAM,EAAE,CAAC;IACtC,4GAA4G;IAC5G,QAAQ,CAAC,YAAY,EAAE,MAAM;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvD,iCAAiC;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,MAAM,CAAC;IAC5B,qFAAqF;IACrF,QAAQ,CAAC,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;IAC7D,mDAAmD;IACnD,QAAQ,CAAC,cAAc,EAAE,MAAM,YAAY,GAAG,SAAS,CAAC;CAC3D;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,kBAAkB;IAC/B,4FAA4F;IAC5F,EAAE,EAAE,aAAa,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,mDAAmD;IACnD,EAAE,EAAE,MAAM,CAAC;IACX,mDAAmD;IACnD,KAAK,EAAE,MAAM,IAAI,CAAC;CACrB"}
@@ -1,2 +1,34 @@
1
1
  "use strict";
2
2
  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;
@@ -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":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAE9B,6EAA6E;IAC7E,MAAM,EAAE,CAAC,aAAa,EAAE,cAAc,KAAK,IAAI,CAAC;IAChD,oEAAoE;IACpE,UAAU,EAAC,CAAE,QAAQ,EAAE,GAAG,KAAK,IAAI,CAAA;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAE7B,yDAAyD;IACzD,QAAQ,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,IAAI,EAAE,GAAG,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,kEAAkE;IAClE,OAAO,EAAE,MAAM,IAAI,CAAC;CACvB"}
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.5",
3
+ "version": "2.0.7",
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",
@@ -25,7 +25,8 @@
25
25
  "src/**/*"
26
26
  ],
27
27
  "dependencies": {
28
- "@codenotch/codenotch.core": "1.0.23",
28
+ "@codenotch/codenotch.core": "^1.0.23",
29
+ "@codenotch/orm": "^0.1.2",
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
 
@@ -141,6 +141,7 @@ function init(envVariables: any): void {
141
141
  function createApi(): ICodenotchApi {
142
142
  const api: ICodenotchApi = {
143
143
  env: env,
144
+ tables: {},
144
145
  uuid: () => v4(),
145
146
  getProjectFileUrl: (relativePath: string): string => {
146
147
  if (env.clusterUrl === undefined) throw new Error(MISSING_CLUSTER_URL_ERROR);
@@ -465,9 +466,24 @@ function getCodenotch(): ICodenotchApi {
465
466
  * component or a custom hook). Outside of components — handlers defined in
466
467
  * plain modules, services, class components — use {@link getCodenotch} or
467
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.
468
475
  */
469
- function useCodenotch(): ICodenotchApi {
470
- return useSyncExternalStore(subscribe, getCodenotch, getCodenotch);
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
+ );
471
487
  }
472
488
 
473
489
  /**
@@ -1,6 +1,6 @@
1
1
  import type { ReactNode } from "react";
2
2
  import { IAppManifest, ICodenotchProjectManifest } from "@codenotch/codenotch.core";
3
- import { ICodenotchSignal, IDisposable } from "./Misc";
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.
@@ -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
- /// @CODENOTCH/PROCESS
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
- /// @CODENOTCH/PROCESS
124
+ /// ======================================================================================================================
73
125
 
74
126
 
75
127
  /**
@@ -83,7 +135,7 @@ 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
 
@@ -92,6 +144,12 @@ export interface ICodenotchApi {
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
  *
@@ -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.