@adecore/intelligent-ui 0.55.1 → 0.55.3

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
@@ -6,6 +6,7 @@ export { parseUiSyntax, uiDiagnostic, type UiDiagnostic, type UiSyntax, type UiS
6
6
  export { UI_FENCE_LANGUAGE, UI_HOST_LIMITS, UI_REPLY_LIMITS, UiCompiler, compileUi, compileUiBlock, uiHasFence, uiMayReferenceHost, type UiCompilerOptions, type UiCompileUpdate, type UiBlock, type UiCompileOptions, type UiNode, type UiQuery } from './compiler.ts';
7
7
  export { evaluateUiBlock, UiState, uiInputValues, resolveUiChoice, uiChoiceLabel, type UiChoiceSelection, type UiBinding, type UiEvaluation, type UiViewNode } from './runtime.ts';
8
8
  export { uiValidatedState, uiQueryArguments, uiQueryFallback } from './query.ts';
9
+ export { uiNodeQueries } from './node-queries.ts';
9
10
  export { UiNodeSchema, UiDiagnosticSchema, UiBlockSchema, UiBlocksSchema } from './protocol.ts';
10
11
  export { uiCompactCatalog, uiSessionNote, uiGroupReference, uiReferenceText, uiFallbackText, type UiTextOptions } from './text.ts';
11
12
  export { UI_STREAM_INTERVAL_MS, UiStream, type UiStreamClock, type UiStreamOptions, type UiStreamPreview } from './stream.ts';
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ export { parseUiSyntax, uiDiagnostic } from './syntax.js';
6
6
  export { UI_FENCE_LANGUAGE, UI_HOST_LIMITS, UI_REPLY_LIMITS, UiCompiler, compileUi, compileUiBlock, uiHasFence, uiMayReferenceHost } from './compiler.js';
7
7
  export { evaluateUiBlock, UiState, uiInputValues, resolveUiChoice, uiChoiceLabel } from './runtime.js';
8
8
  export { uiValidatedState, uiQueryArguments, uiQueryFallback } from './query.js';
9
+ export { uiNodeQueries } from './node-queries.js';
9
10
  export { UiNodeSchema, UiDiagnosticSchema, UiBlockSchema, UiBlocksSchema } from './protocol.js';
10
11
  export { uiCompactCatalog, uiSessionNote, uiGroupReference, uiReferenceText, uiFallbackText } from './text.js';
11
12
  export { UI_STREAM_INTERVAL_MS, UiStream } from './stream.js';
@@ -0,0 +1,2 @@
1
+ import type { UiBlock } from './compiler.ts';
2
+ export declare function uiNodeQueries(block: UiBlock): Record<string, readonly string[]>;
@@ -0,0 +1,41 @@
1
+ /*
2
+ * The queries each written node of a block reads, by node id: the ones its own expressions name, and the ones
3
+ * of an `Each` it stands in, whose items come from them. A node that reads none is left out. An evaluated node
4
+ * finds its entry under its `sourceId`, or its own id when it has none.
5
+ */
6
+ export function uiNodeQueries(block) {
7
+ const names = new Set(Object.keys(block.queries));
8
+ const queries = Object.create(null);
9
+ if (names.size === 0) {
10
+ return queries;
11
+ }
12
+ const references = (value, into) => {
13
+ if (!value || typeof value !== 'object') {
14
+ return;
15
+ }
16
+ const expression = value;
17
+ if (expression.kind === 'reference' && names.has(String(expression.name))) {
18
+ into.add(String(expression.name));
19
+ }
20
+ for (const child of Object.values(expression)) {
21
+ if (Array.isArray(child)) {
22
+ child.forEach((item) => references(item, into));
23
+ }
24
+ else if (typeof child === 'object') {
25
+ references(child, into);
26
+ }
27
+ }
28
+ };
29
+ const walk = (nodes, inherited) => {
30
+ for (const node of nodes) {
31
+ const related = new Set(inherited);
32
+ references(node.expressions, related);
33
+ if (related.size > 0) {
34
+ queries[node.id] = [...related].sort();
35
+ }
36
+ walk(node.children, node.type === 'Each' ? related : inherited);
37
+ }
38
+ };
39
+ walk(block.nodes, new Set());
40
+ return queries;
41
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/intelligent-ui",
3
- "version": "0.55.1",
3
+ "version": "0.55.3",
4
4
  "description": "A streaming UI catalog, compiler and bounded expression interpreter without a framework or DOM.",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "author": "Bas Milius",
package/src/index.ts CHANGED
@@ -42,6 +42,7 @@ export {
42
42
  type UiViewNode
43
43
  } from './runtime.ts';
44
44
  export { uiValidatedState, uiQueryArguments, uiQueryFallback } from './query.ts';
45
+ export { uiNodeQueries } from './node-queries.ts';
45
46
  export { UiNodeSchema, UiDiagnosticSchema, UiBlockSchema, UiBlocksSchema } from './protocol.ts';
46
47
  export { uiCompactCatalog, uiSessionNote, uiGroupReference, uiReferenceText, uiFallbackText, type UiTextOptions } from './text.ts';
47
48
  export { UI_STREAM_INTERVAL_MS, UiStream, type UiStreamClock, type UiStreamOptions, type UiStreamPreview } from './stream.ts';
@@ -0,0 +1,52 @@
1
+ import type { UiBlock, UiNode } from './compiler.ts';
2
+
3
+ /*
4
+ * The queries each written node of a block reads, by node id: the ones its own expressions name, and the ones
5
+ * of an `Each` it stands in, whose items come from them. A node that reads none is left out. An evaluated node
6
+ * finds its entry under its `sourceId`, or its own id when it has none.
7
+ */
8
+ export function uiNodeQueries(block: UiBlock): Record<string, readonly string[]> {
9
+ const names = new Set(Object.keys(block.queries));
10
+ const queries: Record<string, readonly string[]> = Object.create(null);
11
+
12
+ if (names.size === 0) {
13
+ return queries;
14
+ }
15
+
16
+ const references = (value: unknown, into: Set<string>): void => {
17
+ if (!value || typeof value !== 'object') {
18
+ return;
19
+ }
20
+
21
+ const expression = value as Record<string, unknown>;
22
+
23
+ if (expression.kind === 'reference' && names.has(String(expression.name))) {
24
+ into.add(String(expression.name));
25
+ }
26
+
27
+ for (const child of Object.values(expression)) {
28
+ if (Array.isArray(child)) {
29
+ child.forEach((item) => references(item, into));
30
+ } else if (typeof child === 'object') {
31
+ references(child, into);
32
+ }
33
+ }
34
+ };
35
+
36
+ const walk = (nodes: readonly UiNode[], inherited: ReadonlySet<string>): void => {
37
+ for (const node of nodes) {
38
+ const related = new Set(inherited);
39
+ references(node.expressions, related);
40
+
41
+ if (related.size > 0) {
42
+ queries[node.id] = [...related].sort();
43
+ }
44
+
45
+ walk(node.children, node.type === 'Each' ? related : inherited);
46
+ }
47
+ };
48
+
49
+ walk(block.nodes, new Set());
50
+
51
+ return queries;
52
+ }