@reeve-iot/workflow-adapters 0.0.0-stage → 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Reeve Workflow Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,170 @@
1
- # Temporary Holding Version
1
+ # @reeve-iot/workflow-adapters
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The data sources [`@reeve-iot/workflow-core`](https://github.com/reeve-iot/reeve-workflow/tree/main/packages/core) declares, implemented against
4
+ [`@reeve-iot/workflow-client`](https://github.com/reeve-iot/reeve-workflow/tree/main/packages/client). Wire these and the editor loads and saves over HTTP, with
5
+ no fetch layer, cache keys or mapping from the server's shapes to the editor's. Part of [Reeve Workflow](https://github.com/reeve-iot/reeve-workflow).
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @reeve-iot/workflow-adapters
11
+ ```
12
+
13
+ Requires React 18 or 19. This is the only package that depends on both `core` and `client`, and it is optional: a host
14
+ with its own data layer (auth interceptors, React Query keys, an offline cache) implements the same seams itself.
15
+
16
+ ## Usage
17
+
18
+ Build the sources once, outside render. Each holds a cache, and one rebuilt per render drops it every time.
19
+
20
+ ```tsx
21
+ import {
22
+ createBlockCatalogueSource,
23
+ createWorkflowDocumentSource,
24
+ createWorkflowOptionsSource,
25
+ createWorkflowReferenceSource,
26
+ } from '@reeve-iot/workflow-adapters'
27
+ import { createWorkflowClient } from '@reeve-iot/workflow-client'
28
+
29
+ const client = createWorkflowClient({ baseUrl: 'https://workflows.example.com' })
30
+
31
+ const catalogue = createBlockCatalogueSource(client)
32
+ const document = createWorkflowDocumentSource(client)
33
+ const options = createWorkflowOptionsSource(client)
34
+ const reference = createWorkflowReferenceSource(client)
35
+ ```
36
+
37
+ Then read them inside the editor:
38
+
39
+ ```tsx
40
+ function EditorBody({ workflowId }: { workflowId: string | null }) {
41
+ const blockTypes = catalogue.useBlockTypes()
42
+ const workflow = document.useWorkflow(workflowId)
43
+
44
+ const setBlockTypes = useWorkflowEditorStore((s) => s.setBlockTypes)
45
+ const loadStoredWorkflow = useWorkflowEditorStore((s) => s.loadStoredWorkflow)
46
+ const setWorkflowParams = useWorkflowEditorStore((s) => s.setWorkflowParams)
47
+ const syncSpecialNodes = useWorkflowEditorStore((s) => s.syncSpecialNodes)
48
+
49
+ useEffect(() => { setBlockTypes([...blockTypes]) }, [blockTypes, setBlockTypes])
50
+ useEffect(() => {
51
+ if (workflow === null) return
52
+ setWorkflowParams(workflow.inputParams, workflow.outputParams)
53
+ loadStoredWorkflow(workflow.definition)
54
+ syncSpecialNodes()
55
+ }, [workflow, loadStoredWorkflow, setWorkflowParams, syncSpecialNodes])
56
+
57
+ return <WorkflowCanvas onCanvasClick={() => undefined} />
58
+ }
59
+ ```
60
+
61
+ `workflow.definition` is the stored-document reader's answer (`StoredDefinitionRead`): `{ ok: true, definition, sites }`,
62
+ or `{ ok: false, fault }` for a definition or parameter list it refuses. Pass it to `loadStoredWorkflow`. A refused
63
+ answer loads an empty canvas that cannot be saved, with the fault on `loadedDocumentFault`, so a save never overwrites
64
+ the stored workflow with an empty canvas. Do not pass it to `loadWorkflow`, which takes a graph.
65
+
66
+ `reference.resolver` goes into `WorkflowReferenceResolverContext`. It is a hook, so its identity must stay stable for
67
+ the editor's lifetime.
68
+
69
+ [`examples/adopter`](https://github.com/reeve-iot/reeve-workflow/tree/main/examples/adopter) is a complete host (palette, canvas, configuration panel,
70
+ workflow picker); its test renders it against a fake server.
71
+
72
+ ## What each source reads
73
+
74
+ | Source | Reads | Gives |
75
+ |---|---|---|
76
+ | `createBlockCatalogueSource` | `GET /api/workflow-blocks` | `BlockTypeDescriptor[]` for `setBlockTypes` |
77
+ | `createWorkflowDocumentSource` | `GET /api/workflows/{id}`, and `GET /api/workflows/{id}/versions/{n}` while the workflow has a draft | the draft's graph where there is one, else the current one, as `StoredDefinitionRead`, and its declared parameters |
78
+ | `createWorkflowOptionsSource` | `GET /api/workflows` | `{ id, name }` for a picker |
79
+ | `createWorkflowReferenceSource` | `GET /api/workflows/{id}` | the ports a referenced child workflow declares |
80
+
81
+ Port types arrive as whatever string the server spelled them with, so each is normalised through the registry of the
82
+ surrounding `WorkflowEditorStoreProvider`; call these hooks inside the provider.
83
+
84
+ The catalogue carries `runsWorkflowFrom` and each block's `typeParameters` as the server declares them.
85
+ `readBlockType` refuses a port that declares a `typeFrom` relation, which the catalogue format does not define;
86
+ `createBlockCatalogueSource` then leaves that block type out of the palette, reports it to `onError` once per load and
87
+ loads the rest. `outputSatisfyingBranchSets` is absent because nothing on the wire declares it; a host that knows its
88
+ own catalogue says so through the store's `adaptBlockType`.
89
+
90
+ ## The port-type vocabulary
91
+
92
+ The server's compiler checks every wire against one widening table: the built-ins plus whatever the host registered
93
+ through `Seams.PortTypes`. `getPortTypes()` on the editor client publishes it, and `readPortTypeVocabulary` turns it
94
+ into definitions for `createPortTypeRegistry`, so the editor answers as the compiler does:
95
+
96
+ ```ts
97
+ import { readPortTypeConstructors, readPortTypeVocabulary } from '@reeve-iot/workflow-adapters'
98
+ import { createWorkflowEditorClient } from '@reeve-iot/workflow-client'
99
+ import { createPortTypeRegistry } from '@reeve-iot/workflow-core'
100
+
101
+ const editor = createWorkflowEditorClient({ baseUrl: 'https://workflows.example.com' })
102
+
103
+ async function loadPortTypes() {
104
+ const vocabulary = await editor.getPortTypes()
105
+ return createPortTypeRegistry(readPortTypeVocabulary(vocabulary), readPortTypeConstructors(vocabulary), {
106
+ secretCodec: vocabulary.secretCodec,
107
+ })
108
+ }
109
+ ```
110
+
111
+ Load it before the editor mounts: a registry is immutable and the editor reads it once, so a type registered later is
112
+ offered after a page reload. `getPortTypes` throws `WorkflowApiError` for an error status (and what `fetch` throws when
113
+ there is no answer), and `readPortTypeVocabulary` throws, naming the row, for a table it cannot hold, such as a
114
+ `Collection<…>` row that widens. Until a load succeeds, show the editor as unavailable with a way to retry rather than
115
+ mounting it over `BUILTIN_PORT_TYPES`, which would pass wires the server refuses and refuse ones it passes.
116
+
117
+ The endpoint sits in the editor group, behind the policy the host states on `MapWorkflowEditorApi`'s group, so a caller
118
+ that policy refuses cannot seed from it. A host that shows such a caller the canvas serves
119
+ `PortTypeVocabularyResponse.From(options.Vocabulary, services)` from a route of its own. The vocabulary carries no
120
+ display names; map the definitions to add one. A type the editor offers must be registered on the server
121
+ (`Seams.PortTypes.Add(new WorkflowTypeRecord(…))`), not only in TypeScript. A record cannot express an alias onto a
122
+ `Collection<…>` name, so a server built on records publishes none.
123
+
124
+ ## The server's types for a draft
125
+
126
+ The editor does not bind type parameters or type expressions itself: the compiler does. `POST {root}/analysis` answers
127
+ for a draft nobody saved, with the declared and effective term of every port, and `createDraftAnalysisSource` wires it
128
+ into the store:
129
+
130
+ ```ts
131
+ import { createDraftAnalysisSource } from '@reeve-iot/workflow-adapters'
132
+ import { createWorkflowEditorClient } from '@reeve-iot/workflow-client'
133
+ import { createWorkflowEditorStore } from '@reeve-iot/workflow-core'
134
+
135
+ const editor = createWorkflowEditorClient({ baseUrl: 'https://workflows.example.com' })
136
+ const store = createWorkflowEditorStore({
137
+ portTypes: await loadPortTypes(),
138
+ draftAnalysis: createDraftAnalysisSource(editor, { workflowId: () => openWorkflowId }),
139
+ })
140
+ ```
141
+
142
+ The store asks for an analysis after each edit, once it has been quiet for `draftAnalysisDelayMs`, and aborts a request
143
+ an edit overtakes. An answer is shown as current only for the revision it was asked at. A failed request leaves the
144
+ last answer in place and reaches `onDraftAnalysisError` and the store's `analysisError`. `readDraftAnalysis(response,
145
+ definition)` refuses an answer with a port state it does not know, a bound port without an effective term, or a port
146
+ with no declared term that no `passthrough` entry of the draft names. Without the analysis seam a port shows its
147
+ declared term and the editor grades only a literal against a closed one.
148
+
149
+ ## Loading, failure and refresh
150
+
151
+ Every source is read-through and safe to call during render: an unknown key returns the empty value and starts one
152
+ load, and the same key asked again while that load is in flight starts nothing. The first render is therefore empty;
153
+ there is no suspense boundary and no thrown promise.
154
+
155
+ A failed load is remembered as empty rather than retried, so one unreachable workflow cannot turn into an unbounded
156
+ stream of requests. Pass `onError` to see it; without one it is silent, which matches the editor's contract that an
157
+ unresolvable reference draws no ports rather than breaking the canvas.
158
+
159
+ `refresh()` drops everything a source holds, so the next render loads again. Every source has one, including the
160
+ reference resolver: a child workflow that has just gained a parameter is stale on its parent until the resolver is
161
+ refreshed, and a child that failed once is otherwise never asked for again. A load in flight when `refresh()` is called
162
+ is discarded rather than written.
163
+
164
+ ## Documentation
165
+
166
+ See the [main README](https://github.com/reeve-iot/reeve-workflow#readme) and [docs](https://github.com/reeve-iot/reeve-workflow/tree/main/docs).
167
+
168
+ ## Licence
169
+
170
+ MIT.
@@ -0,0 +1,23 @@
1
+ import type { WorkflowBlockTypeResponse, WorkflowClient } from '@reeve-iot/workflow-client';
2
+ import type { BlockTypeDescriptor, PortTypeRegistry } from '@reeve-iot/workflow-core';
3
+ /**
4
+ * One block type as the editor reads it, with the input it runs a workflow from and the type parameters its
5
+ * ports name. `outputSatisfyingBranchSets` is absent on purpose: nothing on the
6
+ * wire declares it, and the store's own `adaptBlockType` is where a host says so.
7
+ */
8
+ export declare function readBlockType(response: WorkflowBlockTypeResponse, portTypes: PortTypeRegistry): BlockTypeDescriptor;
9
+ export interface BlockCatalogueSource {
10
+ /** The block types the editor draws with. Empty on the first render and while the list is loading. A block type
11
+ * this editor cannot read is left out and its validation finding is reported to `onError` once per load. */
12
+ useBlockTypes: () => readonly BlockTypeDescriptor[];
13
+ /** Drops the catalogue, so the next render loads it again — call it after a plugin is installed. */
14
+ refresh: () => void;
15
+ }
16
+ /**
17
+ * The palette's contents, fetched once and shared. Feed the result to the store's `setBlockTypes`: an
18
+ * editor whose catalogue is empty draws nothing at all, which is why this is the first seam to wire.
19
+ */
20
+ export declare function createBlockCatalogueSource(client: WorkflowClient, options?: {
21
+ readonly onError?: (error: unknown) => void;
22
+ }): BlockCatalogueSource;
23
+ //# sourceMappingURL=blockCatalogue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blockCatalogue.d.ts","sourceRoot":"","sources":["../src/blockCatalogue.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,yBAAyB,EACzB,cAAc,EACf,MAAM,4BAA4B,CAAA;AASnC,OAAO,KAAK,EAAa,mBAAmB,EAAE,gBAAgB,EAAqB,MAAM,0BAA0B,CAAA;AAgEnH;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,yBAAyB,EACnC,SAAS,EAAE,gBAAgB,GAC1B,mBAAmB,CAIrB;AA2DD,MAAM,WAAW,oBAAoB;IACnC;gHAC4G;IAC5G,aAAa,EAAE,MAAM,SAAS,mBAAmB,EAAE,CAAA;IACnD,oGAAoG;IACpG,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CAAO,GAC5D,oBAAoB,CAwBtB"}
@@ -0,0 +1,148 @@
1
+ import { useEffect, useMemo, useSyncExternalStore } from 'react';
2
+ import { BLOCK_PORT_DECLARATION_INVALID, BlockPortDeclarationInvalidError, describePortTypeSyntaxError, parsePortTerm, usePortTypes, validationMessage, } from '@reeve-iot/workflow-core';
3
+ import { createReadCache } from './cache.js';
4
+ const NONE = [];
5
+ const ALL = 'all';
6
+ function assertNoRelation(port, owner) {
7
+ if ('typeFrom' in port && port.typeFrom != null) {
8
+ throw new Error(`Port '${owner}' declares a type relation, which this editor's block-catalogue format does not define: the server publishes a block catalogue this editor cannot type`);
9
+ }
10
+ }
11
+ function assertNoTextPolicy(entry, owner) {
12
+ if ('textPolicy' in entry) {
13
+ throw new Error(`'${owner}' declares a text policy, which this editor's block-catalogue format does not define: the server publishes a block catalogue this editor cannot grade literals for`);
14
+ }
15
+ }
16
+ function assertDeclaredTermsParse(response) {
17
+ const parse = (where, type) => {
18
+ const parsed = parsePortTerm(type, 'declaration');
19
+ if (!parsed.ok) {
20
+ throw new BlockPortDeclarationInvalidError(response.blockTypeId, where, `has the type '${type}', which is not a declaration term: ${describePortTypeSyntaxError(type, parsed)}`);
21
+ }
22
+ };
23
+ const ports = (list, prefix) => {
24
+ for (const port of list) {
25
+ const where = `${prefix}port '${port.name}'`;
26
+ parse(where, port.type);
27
+ for (const variable of port.scopeVariables)
28
+ parse(`${where} scope variable '${variable.name}'`, variable.type);
29
+ }
30
+ };
31
+ ports(response.inputs, '');
32
+ ports(response.outputs, '');
33
+ for (const [branch, list] of Object.entries(response.subCanvasInputs))
34
+ ports(list, `sub-canvas '${branch}' `);
35
+ for (const [branch, list] of Object.entries(response.subCanvasOutputs))
36
+ ports(list, `sub-canvas '${branch}' `);
37
+ }
38
+ function readPorts(ports, normalize) {
39
+ return ports.map((p) => {
40
+ if (p.name.includes('.'))
41
+ throw new Error(`Port name '${p.name}' contains a dot (rule dotted-name).`);
42
+ assertNoTextPolicy(p, p.name);
43
+ assertNoRelation(p, p.name);
44
+ return {
45
+ name: p.name,
46
+ displayName: p.displayName,
47
+ type: normalize(p.type),
48
+ isRequired: p.isRequired,
49
+ allowedValues: p.allowedValues === null ? null : [...p.allowedValues],
50
+ ...(p.scopeVariables.length === 0 ? {} : { scopeVariables: p.scopeVariables.map((v) => ({ name: v.name, type: normalize(v.type) })) }),
51
+ ...(p.secretValues ? { secretValues: true } : {}),
52
+ };
53
+ });
54
+ }
55
+ function readSubCanvases(ports, normalize) {
56
+ return Object.fromEntries(Object.entries(ports).map(([name, p]) => [name, readPorts(p, normalize)]));
57
+ }
58
+ /**
59
+ * One block type as the editor reads it, with the input it runs a workflow from and the type parameters its
60
+ * ports name. `outputSatisfyingBranchSets` is absent on purpose: nothing on the
61
+ * wire declares it, and the store's own `adaptBlockType` is where a host says so.
62
+ */
63
+ export function readBlockType(response, portTypes) {
64
+ const descriptor = describe(response, (type) => portTypes.normalize(type));
65
+ assertDeclaredTermsParse(response);
66
+ return descriptor;
67
+ }
68
+ function describe(response, normalize) {
69
+ return {
70
+ blockTypeId: response.blockTypeId,
71
+ displayName: response.displayName,
72
+ description: response.description,
73
+ category: response.category,
74
+ inputs: readPorts(response.inputs, normalize),
75
+ outputs: readPorts(response.outputs, normalize),
76
+ hasDynamicPorts: response.hasDynamicPorts,
77
+ supportsDeclaredOutputs: response.supportsDeclaredOutputs,
78
+ ...(response.declaredOutputsCollect === true ? { declaredOutputsCollect: true } : {}),
79
+ configurationSchema: response.configurationSchema.map((f) => {
80
+ assertNoTextPolicy(f, f.name);
81
+ return {
82
+ ...f,
83
+ allowedValues: f.allowedValues ? [...f.allowedValues] : null,
84
+ };
85
+ }),
86
+ subCanvasNames: [...response.subCanvasNames],
87
+ subCanvasInputs: readSubCanvases(response.subCanvasInputs, normalize),
88
+ subCanvasOutputs: readSubCanvases(response.subCanvasOutputs, normalize),
89
+ ...(response.runsWorkflowFrom === null ? {} : { runsWorkflowFrom: response.runsWorkflowFrom }),
90
+ ...(response.typeParameters.length === 0
91
+ ? {}
92
+ : { typeParameters: response.typeParameters.map((p) => ({ name: p.name, constraints: [...p.constraints] })) }),
93
+ };
94
+ }
95
+ function readCatalogue(responses, portTypes) {
96
+ if (responses.length === 0)
97
+ return { blockTypes: NONE, refused: [] };
98
+ const blockTypes = [];
99
+ const refused = [];
100
+ for (const response of responses) {
101
+ try {
102
+ blockTypes.push(readBlockType(response, portTypes));
103
+ }
104
+ catch (error) {
105
+ const why = error instanceof Error ? error.message : String(error);
106
+ if (error instanceof BlockPortDeclarationInvalidError) {
107
+ const finding = {
108
+ nodeId: null,
109
+ code: BLOCK_PORT_DECLARATION_INVALID,
110
+ params: { blockTypeId: error.blockTypeId, where: error.where, reason: error.reason },
111
+ message: why,
112
+ };
113
+ finding.message = validationMessage(finding);
114
+ refused.push(finding);
115
+ }
116
+ else {
117
+ refused.push(new Error(`Block type '${response.blockTypeId}' is left out of the palette: ${why}`, { cause: error }));
118
+ }
119
+ }
120
+ }
121
+ return { blockTypes, refused };
122
+ }
123
+ /**
124
+ * The palette's contents, fetched once and shared. Feed the result to the store's `setBlockTypes`: an
125
+ * editor whose catalogue is empty draws nothing at all, which is why this is the first seam to wire.
126
+ */
127
+ export function createBlockCatalogueSource(client, options = {}) {
128
+ const cache = createReadCache(async () => client.getBlockTypes(), [], (_, error) => { options.onError?.(error); });
129
+ const snapshot = () => cache.read(ALL);
130
+ const reported = new WeakSet();
131
+ return {
132
+ useBlockTypes() {
133
+ const portTypes = usePortTypes();
134
+ const responses = useSyncExternalStore(cache.subscribe, snapshot, snapshot);
135
+ const read = useMemo(() => readCatalogue(responses, portTypes), [responses, portTypes]);
136
+ useEffect(() => {
137
+ if (read.refused.length === 0 || reported.has(responses))
138
+ return;
139
+ reported.add(responses);
140
+ for (const finding of read.refused)
141
+ options.onError?.(finding);
142
+ }, [read, responses]);
143
+ return read.blockTypes;
144
+ },
145
+ refresh: cache.invalidate,
146
+ };
147
+ }
148
+ //# sourceMappingURL=blockCatalogue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blockCatalogue.js","sourceRoot":"","sources":["../src/blockCatalogue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAMhE,OAAO,EACL,8BAA8B,EAC9B,gCAAgC,EAChC,2BAA2B,EAC3B,aAAa,EACb,YAAY,EACZ,iBAAiB,GAClB,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE5C,MAAM,IAAI,GAAmC,EAAE,CAAA;AAC/C,MAAM,GAAG,GAAG,KAAK,CAAA;AAEjB,SAAS,gBAAgB,CAAC,IAAY,EAAE,KAAa;IACnD,IAAI,UAAU,IAAI,IAAI,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,SAAS,KAAK,wJAAwJ,CAAC,CAAA;IACzL,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa,EAAE,KAAa;IACtD,IAAI,YAAY,IAAI,KAAK,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,oKAAoK,CAAC,CAAA;IAChM,CAAC;AACH,CAAC;AAED,SAAS,wBAAwB,CAAC,QAAmC;IACnE,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,IAAY,EAAQ,EAAE;QAClD,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;QACjD,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,gCAAgC,CACxC,QAAQ,CAAC,WAAW,EAAE,KAA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CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAA;YACvF,SAAS,CAAC,GAAG,EAAE;gBACb,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC;oBAAE,OAAM;gBAChE,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;gBACvB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,OAAO;oBAAE,OAAO,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAA;YAChE,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAA;YACrB,OAAO,IAAI,CAAC,UAAU,CAAA;QACxB,CAAC;QACD,OAAO,EAAE,KAAK,CAAC,UAAU;KAC1B,CAAA;AACH,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A read-through cache whose reads are safe to make during render: an unknown key returns the empty
3
+ * value and starts one load, and the same key asked again while that load is in flight starts nothing.
4
+ */
5
+ export interface ReadCache<T> {
6
+ /** The value for a key, and the load that fills it if nobody has asked yet. */
7
+ read: (key: string) => T;
8
+ /** Notified whenever a load settles. */
9
+ subscribe: (listener: () => void) => () => void;
10
+ /** Forgets everything, so the next read loads again. */
11
+ invalidate: () => void;
12
+ }
13
+ /**
14
+ * `empty` is returned for a key that is not loaded yet and for one whose load failed, and it must be a
15
+ * stable value: a caller reading during render compares identities to decide whether to re-render.
16
+ */
17
+ export declare function createReadCache<T>(load: (key: string) => Promise<T>, empty: T, onError?: (key: string, error: unknown) => void): ReadCache<T>;
18
+ //# sourceMappingURL=cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC;IAC1B,+EAA+E;IAC/E,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,CAAA;IACxB,wCAAwC;IACxC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAA;IAC/C,wDAAwD;IACxD,UAAU,EAAE,MAAM,IAAI,CAAA;CACvB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EACjC,KAAK,EAAE,CAAC,EACR,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,GAC9C,SAAS,CAAC,CAAC,CAAC,CAsCd"}
package/dist/cache.js ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * `empty` is returned for a key that is not loaded yet and for one whose load failed, and it must be a
3
+ * stable value: a caller reading during render compares identities to decide whether to re-render.
4
+ */
5
+ export function createReadCache(load, empty, onError) {
6
+ let values = new Map();
7
+ let inFlight = new Set();
8
+ const listeners = new Set();
9
+ let generation = 0;
10
+ const settle = (key, value, startedAt) => {
11
+ if (startedAt !== generation)
12
+ return;
13
+ values.set(key, value);
14
+ inFlight.delete(key);
15
+ for (const listener of [...listeners])
16
+ listener();
17
+ };
18
+ return {
19
+ read(key) {
20
+ const known = values.get(key);
21
+ if (known !== undefined)
22
+ return known;
23
+ if (!inFlight.has(key)) {
24
+ inFlight.add(key);
25
+ const startedAt = generation;
26
+ void load(key).then((value) => { settle(key, value, startedAt); }, (error) => { onError?.(key, error); settle(key, empty, startedAt); });
27
+ }
28
+ return empty;
29
+ },
30
+ subscribe(listener) {
31
+ listeners.add(listener);
32
+ return () => { listeners.delete(listener); };
33
+ },
34
+ invalidate() {
35
+ generation += 1;
36
+ values = new Map();
37
+ inFlight = new Set();
38
+ for (const listener of [...listeners])
39
+ listener();
40
+ },
41
+ };
42
+ }
43
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../src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C7E,CAAA;YACH,CAAC;YACD,OAAO,KAAK,CAAA;QACd,CAAC;QACD,SAAS,CAAC,QAAQ;YAChB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACvB,OAAO,GAAG,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA,CAAC,CAAC,CAAA;QAC7C,CAAC;QACD,UAAU;YACR,UAAU,IAAI,CAAC,CAAA;YACf,MAAM,GAAG,IAAI,GAAG,EAAE,CAAA;YAClB,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAA;YACpB,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,SAAS,CAAC;gBAAE,QAAQ,EAAE,CAAA;QACnD,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { DraftAnalysisResponse, WorkflowEditorClient } from '@reeve-iot/workflow-client';
2
+ import type { DraftAnalysis, DraftAnalysisSource, SavedWorkflowDefinition } from '@reeve-iot/workflow-core';
3
+ /** Reads the server's draft analysis as the editor holds it, against the `definition` it was asked for. Throws, naming the
4
+ * place, for an unknown state, a bound port with no term, or a null `declared` that no `passthrough` entry of the definition names. */
5
+ export declare function readDraftAnalysis(response: DraftAnalysisResponse, definition: SavedWorkflowDefinition): DraftAnalysis;
6
+ export interface DraftAnalysisSourceOptions {
7
+ /** The workflow the draft belongs to, read when each request is sent, or null for one not yet created. The server
8
+ * checks that the caller owns it; the compile is the one a save runs. */
9
+ workflowId?: () => string | null;
10
+ }
11
+ /** A {@link DraftAnalysisSource} over the Editor client: posts the draft to `analyzeDraft` and reads the answer. A request the
12
+ * editor supersedes is aborted through the signal. */
13
+ export declare function createDraftAnalysisSource(client: Pick<WorkflowEditorClient, 'analyzeDraft'>, options?: DraftAnalysisSourceOptions): DraftAnalysisSource;
14
+ //# sourceMappingURL=draftAnalysis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draftAnalysis.d.ts","sourceRoot":"","sources":["../src/draftAnalysis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAC7F,OAAO,KAAK,EACS,aAAa,EAAyB,mBAAmB,EAAqC,uBAAuB,EACzI,MAAM,0BAA0B,CAAA;AAuDjC;uIACuI;AACvI,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,qBAAqB,EAAE,UAAU,EAAE,uBAAuB,GAAG,aAAa,CAyBrH;AAED,MAAM,WAAW,0BAA0B;IACzC;6EACyE;IACzE,UAAU,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,CAAA;CACjC;AAED;sDACsD;AACtD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,IAAI,CAAC,oBAAoB,EAAE,cAAc,CAAC,EAAE,OAAO,GAAE,0BAA+B,GAC3F,mBAAmB,CAerB"}
@@ -0,0 +1,96 @@
1
+ import { WORKFLOW_INPUT_BLOCK_TYPE_ID } from '@reeve-iot/workflow-core';
2
+ const STATES = ['bound', 'unbound', 'refused'];
3
+ function readState(state, where) {
4
+ const found = STATES.find((candidate) => candidate === state);
5
+ if (found === undefined)
6
+ throw new Error(`The server answered a draft analysis with port state '${state}' at ${where}, which this editor does not know.`);
7
+ return found;
8
+ }
9
+ function readPath(path) {
10
+ return path.map((segment) => ({ nodeId: segment.nodeId, branchName: segment.branchName }));
11
+ }
12
+ const pathKey = (path) => path.map((s) => `${s.nodeId}\u0001${s.branchName}`).join('\u0002');
13
+ function passthroughNames(canvas, path, owner, into) {
14
+ if (!Array.isArray(canvas.nodes))
15
+ return;
16
+ for (const node of canvas.nodes) {
17
+ const own = new Set(Array.isArray(node.passthrough) ? node.passthrough : []);
18
+ into.set(`${path}\u0000${node.id}`, node.blockTypeId === WORKFLOW_INPUT_BLOCK_TYPE_ID && owner !== undefined ? owner : own);
19
+ if (node.subCanvases === null || typeof node.subCanvases !== 'object')
20
+ continue;
21
+ for (const [branch, sub] of Object.entries(node.subCanvases)) {
22
+ const segment = `${node.id}\u0001${branch}`;
23
+ passthroughNames(sub, path === '' ? segment : `${path}\u0002${segment}`, own, into);
24
+ }
25
+ }
26
+ }
27
+ function readPort(port, where, given) {
28
+ if (port.declared === null && given?.has(port.name) !== true) {
29
+ throw new Error(`The server answered a draft analysis with no declared term for ${where}.${port.name}, which no passthrough entry names.`);
30
+ }
31
+ const read = {
32
+ name: port.name,
33
+ declared: port.declared,
34
+ effective: port.effective,
35
+ state: readState(port.state, `${where}.${port.name}`),
36
+ unbound: [...port.unbound],
37
+ };
38
+ if (port.expression !== undefined && port.expression !== null)
39
+ read.expression = port.expression;
40
+ if (port.projection !== undefined && port.projection !== null)
41
+ read.projection = port.projection;
42
+ if (read.state === 'bound' && read.effective === null) {
43
+ throw new Error(`The server answered a draft analysis with a bound port with no effective term at ${where}.${port.name}.`);
44
+ }
45
+ if (read.state === 'unbound' && read.declared === null) {
46
+ throw new Error(`The server answered a draft analysis with an unbound port with no declared term at ${where}.${port.name}.`);
47
+ }
48
+ return read;
49
+ }
50
+ /** Reads the server's draft analysis as the editor holds it, against the `definition` it was asked for. Throws, naming the
51
+ * place, for an unknown state, a bound port with no term, or a null `declared` that no `passthrough` entry of the definition names. */
52
+ export function readDraftAnalysis(response, definition) {
53
+ const names = new Map();
54
+ passthroughNames(definition, '', undefined, names);
55
+ return {
56
+ revision: response.revision,
57
+ registryGeneration: response.registryGeneration,
58
+ diagnostics: response.diagnostics.map((d) => ({
59
+ ruleId: d.ruleId,
60
+ message: d.message,
61
+ nodeId: d.nodeId,
62
+ portName: d.portName,
63
+ canvasPath: readPath(d.canvasPath),
64
+ })),
65
+ nodes: response.nodes.map((node) => {
66
+ const where = `node '${node.nodeId}'`;
67
+ const given = names.get(`${pathKey(node.canvasPath)}\u0000${node.nodeId}`);
68
+ return {
69
+ canvasPath: readPath(node.canvasPath),
70
+ nodeId: node.nodeId,
71
+ typeArguments: { ...node.typeArguments },
72
+ inputs: node.inputs.map((port) => readPort(port, `${where} input`, given)),
73
+ outputs: node.outputs.map((port) => readPort(port, `${where} output`, given)),
74
+ };
75
+ }),
76
+ };
77
+ }
78
+ /** A {@link DraftAnalysisSource} over the Editor client: posts the draft to `analyzeDraft` and reads the answer. A request the
79
+ * editor supersedes is aborted through the signal. */
80
+ export function createDraftAnalysisSource(client, options = {}) {
81
+ return {
82
+ analyze: async (document, revision, signal) => {
83
+ const response = await client.analyzeDraft({
84
+ body: {
85
+ workflowId: options.workflowId?.() ?? null,
86
+ revision,
87
+ definitionJson: JSON.stringify(document.definition),
88
+ inputParametersJson: JSON.stringify(document.inputParameters),
89
+ outputParametersJson: JSON.stringify(document.outputParameters),
90
+ },
91
+ }, { signal });
92
+ return readDraftAnalysis(response, document.definition);
93
+ },
94
+ };
95
+ }
96
+ //# sourceMappingURL=draftAnalysis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draftAnalysis.js","sourceRoot":"","sources":["../src/draftAnalysis.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAA;AAEvE,MAAM,MAAM,GAA8B,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;AAEzE,SAAS,SAAS,CAAC,KAAa,EAAE,KAAa;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,KAAK,KAAK,CAAC,CAAA;IAC7D,IAAI,KAAK,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,yDAAyD,KAAK,QAAQ,KAAK,oCAAoC,CAAC,CAAA;IACzJ,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,QAAQ,CAAC,IAA6E;IAC7F,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA;AAC5F,CA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CAAC,CAAC;gBAC1E,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,KAAK,SAAS,EAAE,KAAK,CAAC,CAAC;aAC9E,CAAA;QACH,CAAC,CAAC;KACH,CAAA;AACH,CAAC;AAQD;sDACsD;AACtD,MAAM,UAAU,yBAAyB,CACvC,MAAkD,EAAE,UAAsC,EAAE;IAE5F,OAAO;QACL,OAAO,EAAE,KAAK,EAAE,QAA+B,EAAE,QAAgB,EAAE,MAAmB,EAA0B,EAAE;YAChH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC;gBACzC,IAAI,EAAE;oBACJ,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,EAAE,IAAI,IAAI;oBAC1C,QAAQ;oBACR,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;oBACnD,mBAAmB,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,eAAe,CAAC;oBAC7D,oBAAoB,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC;iBAChE;aACF,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;YACd,OAAO,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAA;QACzD,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ export { createReadCache } from './cache.js';
2
+ export type { ReadCache } from './cache.js';
3
+ export { WorkflowReferenceUnreadableError, createWorkflowReferenceSource, readDeclaredPorts } from './workflowReference.js';
4
+ export type { DeclaredPortsRead, WorkflowReferenceResolverOptions, WorkflowReferenceSource } from './workflowReference.js';
5
+ export { createWorkflowOptionsSource } from './workflowOptions.js';
6
+ export type { WorkflowOption, WorkflowOptionsSource } from './workflowOptions.js';
7
+ export { createBlockCatalogueSource, readBlockType } from './blockCatalogue.js';
8
+ export type { BlockCatalogueSource } from './blockCatalogue.js';
9
+ export { createWorkflowDocumentSource, readWorkflowDefinition, readWorkflowDocument } from './workflowDocument.js';
10
+ export type { WorkflowDocument, WorkflowDocumentSource } from './workflowDocument.js';
11
+ export { readPortTypeConstructors, readPortTypeVocabulary } from './portTypeVocabulary.js';
12
+ export { createDraftAnalysisSource, readDraftAnalysis } from './draftAnalysis.js';
13
+ export type { DraftAnalysisSourceOptions } from './draftAnalysis.js';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3C,OAAO,EAAE,gCAAgC,EAAE,6BAA6B,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC3H,YAAY,EAAE,iBAAiB,EAAE,gCAAgC,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAE1H,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAA;AAClE,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAEjF,OAAO,EAAE,0BAA0B,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAC/E,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE/D,OAAO,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAClH,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAErF,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAE1F,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACjF,YAAY,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ export { createReadCache } from './cache.js';
2
+ export { WorkflowReferenceUnreadableError, createWorkflowReferenceSource, readDeclaredPorts } from './workflowReference.js';
3
+ export { createWorkflowOptionsSource } from './workflowOptions.js';
4
+ export { createBlockCatalogueSource, readBlockType } from './blockCatalogue.js';
5
+ export { createWorkflowDocumentSource, readWorkflowDefinition, readWorkflowDocument } from './workflowDocument.js';
6
+ export { readPortTypeConstructors, readPortTypeVocabulary } from './portTypeVocabulary.js';
7
+ export { createDraftAnalysisSource, readDraftAnalysis } from './draftAnalysis.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAG5C,OAAO,EAAE,gCAAgC,EAAE,6BAA6B,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAG3H,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAA;AAGlE,OAAO,EAAE,0BAA0B,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAG/E,OAAO,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAGlH,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAE1F,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA"}
@@ -0,0 +1,10 @@
1
+ import type { PortTypeVocabularyResponse } from '@reeve-iot/workflow-client';
2
+ import type { PortTypeConstructorDefinition, PortTypeDefinition } from '@reeve-iot/workflow-core';
3
+ /** The server's vocabulary (`getPortTypes`) as `createPortTypeRegistry`'s definitions, `implements` included; throws,
4
+ * naming it, for a name that does not parse, a capability this editor does not know or a literal form outside the
5
+ * closed set. */
6
+ export declare function readPortTypeVocabulary(response: PortTypeVocabularyResponse): PortTypeDefinition[];
7
+ /** The host constructors as `createPortTypeRegistry`'s second argument, built-in `Collection` and `Map` left out. Throws for one
8
+ * that lists no argument, and for a `Map` published with an arity or key this editor's grammar does not read. */
9
+ export declare function readPortTypeConstructors(response: PortTypeVocabularyResponse): PortTypeConstructorDefinition[];
10
+ //# sourceMappingURL=portTypeVocabulary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portTypeVocabulary.d.ts","sourceRoot":"","sources":["../src/portTypeVocabulary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAA;AAE5E,OAAO,KAAK,EAAuC,6BAA6B,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAoBtI;;iBAEiB;AACjB,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,0BAA0B,GAAG,kBAAkB,EAAE,CAkBjG;AAMD;iHACiH;AACjH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,0BAA0B,GAAG,6BAA6B,EAAE,CAqB9G"}
@@ -0,0 +1,71 @@
1
+ import { describePortTypeSyntaxError, isPortCapabilityName, literalFormRefusal, parsePortTypeName } from '@reeve-iot/workflow-core';
2
+ function implementsOf(response, name, listed) {
3
+ const published = new Set(response.capabilities.map((c) => c.name));
4
+ return listed.map((capability) => {
5
+ if (!published.has(capability) || !isPortCapabilityName(capability)) {
6
+ throw new Error(`The server published '${name}' as implementing '${capability}', which is not a capability of its vocabulary this editor knows.`);
7
+ }
8
+ return capability;
9
+ });
10
+ }
11
+ function literalOf(name, published) {
12
+ if (published === null)
13
+ return null;
14
+ const form = { gradedAs: published.gradedAs, format: published.format };
15
+ const why = literalFormRefusal(form);
16
+ if (why !== undefined)
17
+ throw new Error(`The server published '${name}' with a literal form this editor cannot grade: ${why}.`);
18
+ return form.format === null ? { gradedAs: form.gradedAs } : form;
19
+ }
20
+ /** The server's vocabulary (`getPortTypes`) as `createPortTypeRegistry`'s definitions, `implements` included; throws,
21
+ * naming it, for a name that does not parse, a capability this editor does not know or a literal form outside the
22
+ * closed set. */
23
+ export function readPortTypeVocabulary(response) {
24
+ const definitions = [];
25
+ for (const type of response.types) {
26
+ const parsed = parsePortTypeName(type.name);
27
+ if (!parsed.ok)
28
+ throw new Error(`The server published port type '${type.name}', which does not parse: ${describePortTypeSyntaxError(type.name, parsed)}`);
29
+ if (parsed.depth > 0) {
30
+ if (type.aliases.length > 0)
31
+ definitions.push({ name: type.name, aliases: [...type.aliases] });
32
+ continue;
33
+ }
34
+ definitions.push({
35
+ name: type.name,
36
+ aliases: [...type.aliases],
37
+ widensTo: [...type.widensTo],
38
+ implements: implementsOf(response, type.name, type.implements),
39
+ literal: literalOf(type.name, type.literal),
40
+ });
41
+ }
42
+ return definitions;
43
+ }
44
+ const BUILT_IN_CONSTRUCTORS = new Set(['Collection', 'Map']);
45
+ const MAP_ARITY = 2;
46
+ const MAP_KEY = 'String';
47
+ /** The host constructors as `createPortTypeRegistry`'s second argument, built-in `Collection` and `Map` left out. Throws for one
48
+ * that lists no argument, and for a `Map` published with an arity or key this editor's grammar does not read. */
49
+ export function readPortTypeConstructors(response) {
50
+ for (const constructor of response.constructors) {
51
+ const published = constructor;
52
+ if (constructor.name === 'Map' && (published.arity !== undefined || published.key !== undefined) && (published.arity !== MAP_ARITY || published.key !== MAP_KEY)) {
53
+ throw new Error(`The server published built-in constructor 'Map' with arity ${String(published.arity)} and key ${String(published.key)}, which this editor cannot read.`);
54
+ }
55
+ }
56
+ return response.constructors
57
+ .filter((constructor) => !BUILT_IN_CONSTRUCTORS.has(constructor.name))
58
+ .map((constructor) => {
59
+ const allowed = constructor.allowedArguments;
60
+ if (allowed === null || allowed.length === 0) {
61
+ throw new Error(`The server published port type constructor '${constructor.name}' with no allowed argument.`);
62
+ }
63
+ return {
64
+ name: constructor.name,
65
+ allowedArguments: [...allowed],
66
+ implements: implementsOf(response, constructor.name, constructor.implements),
67
+ literal: literalOf(constructor.name, constructor.literal),
68
+ };
69
+ });
70
+ }
71
+ //# sourceMappingURL=portTypeVocabulary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"portTypeVocabulary.js","sourceRoot":"","sources":["../src/portTypeVocabulary.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAGnI,SAAS,YAAY,CAAC,QAAoC,EAAE,IAAY,EAAE,MAAyB;IACjG,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;IACnE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QAC/B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,EAAE,CAAC;YACpE,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,sBAAsB,UAAU,mEAAmE,CAAC,CAAA;QACnJ,CAAC;QACD,OAAO,UAAU,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,IAAY,EAAE,SAA+E;IAC9G,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IACnC,MAAM,IAAI,GAAG,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAqB,CAAA;IAC1F,MAAM,GAAG,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAA;IACpC,IAAI,GAAG,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,mDAAmD,GAAG,GAAG,CAAC,CAAA;IAC9H,OAAO,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,EA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C,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC;SAC1D,CAAA;IACH,CAAC,CAAC,CAAA;AACN,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { WorkflowClient, WorkflowResponse } from '@reeve-iot/workflow-client';
2
+ import type { PortTypeRegistry, StoredDefinitionRead, WorkflowParameter } from '@reeve-iot/workflow-core';
3
+ /** One workflow as the editor loads it: the graph as the stored-document reader read it, and the parameters its
4
+ * entry and exit nodes carry, the draft's while there is one. Pass `definition` to the store's `loadStoredWorkflow`. */
5
+ export interface WorkflowDocument {
6
+ readonly id: string;
7
+ readonly name: string;
8
+ /** The definition and both parameter lists as read: a fault in any of them is the fault here, so a store
9
+ * loading it holds an empty canvas that cannot be saved over the stored workflow. */
10
+ readonly definition: StoredDefinitionRead;
11
+ readonly inputParams: WorkflowParameter[];
12
+ readonly outputParams: WorkflowParameter[];
13
+ }
14
+ /** The stored graph through the stored-document reader, every rule L1 to L9 over the text: a graph it
15
+ * refuses is a fault, never an empty canvas or the half that happened to parse; an absent text is the fault no document. */
16
+ export declare function readWorkflowDefinition(json: string | null | undefined): StoredDefinitionRead;
17
+ export declare function readWorkflowDocument(response: WorkflowResponse, portTypes: PortTypeRegistry): WorkflowDocument;
18
+ export interface WorkflowDocumentSource {
19
+ /** The workflow to edit, or null while it loads and for one that could not be read. */
20
+ useWorkflow: (workflowId: string | null) => WorkflowDocument | null;
21
+ /** Drops every loaded workflow, so the next render fetches again — call it after a save. */
22
+ refresh: () => void;
23
+ }
24
+ /**
25
+ * What the editor is editing, refreshed on save; the draft's documents while there is a draft, read with
26
+ * `getVersion`. A draft that cannot be read goes to `onError` and loads as null, never as the current documents.
27
+ */
28
+ export declare function createWorkflowDocumentSource(client: WorkflowClient, options?: {
29
+ readonly onError?: (workflowId: string, error: unknown) => void;
30
+ }): WorkflowDocumentSource;
31
+ //# sourceMappingURL=workflowDocument.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflowDocument.d.ts","sourceRoot":"","sources":["../src/workflowDocument.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAElF,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAuB,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAI9H;wHACwH;AACxH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB;yFACqF;IACrF,QAAQ,CAAC,UAAU,EAAE,oBAAoB,CAAA;IACzC,QAAQ,CAAC,WAAW,EAAE,iBAAiB,EAAE,CAAA;IACzC,QAAQ,CAAC,YAAY,EAAE,iBAAiB,EAAE,CAAA;CAC3C;AAED;4HAC4H;AAC5H,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,oBAAoB,CAE5F;AAMD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAE,gBAAgB,GAAG,gBAAgB,CAc9G;AAiBD,MAAM,WAAW,sBAAsB;IACrC,uFAAuF;IACvF,WAAW,EAAE,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,KAAK,gBAAgB,GAAG,IAAI,CAAA;IACnE,4FAA4F;IAC5F,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CAAO,GAChF,sBAAsB,CAmBxB"}
@@ -0,0 +1,59 @@
1
+ import { useCallback, useMemo, useSyncExternalStore } from 'react';
2
+ import { readStoredDefinitionText, usePortTypes } from '@reeve-iot/workflow-core';
3
+ import { createReadCache } from './cache.js';
4
+ import { readDeclaredPorts } from './workflowReference.js';
5
+ /** The stored graph through the stored-document reader, every rule L1 to L9 over the text: a graph it
6
+ * refuses is a fault, never an empty canvas or the half that happened to parse; an absent text is the fault no document. */
7
+ export function readWorkflowDefinition(json) {
8
+ return readStoredDefinitionText(json);
9
+ }
10
+ function listFault(fault, side) {
11
+ return { ok: false, fault: { ...fault, detail: `the declared ${side} parameters: ${fault.detail}` } };
12
+ }
13
+ export function readWorkflowDocument(response, portTypes) {
14
+ const inputs = readDeclaredPorts(response.inputParametersJson, portTypes);
15
+ const outputs = readDeclaredPorts(response.outputParametersJson, portTypes);
16
+ return {
17
+ id: response.id,
18
+ name: response.name,
19
+ definition: !inputs.ok
20
+ ? listFault(inputs.fault, 'input')
21
+ : !outputs.ok
22
+ ? listFault(outputs.fault, 'output')
23
+ : readWorkflowDefinition(response.definitionJson),
24
+ inputParams: inputs.ok ? inputs.ports : [],
25
+ outputParams: outputs.ok ? outputs.ports : [],
26
+ };
27
+ }
28
+ async function withDraftDocuments(client, response) {
29
+ if (!response.draftVersionId || response.documentsFrom === 'Draft')
30
+ return response;
31
+ if (typeof response.draftVersionNumber !== 'number') {
32
+ throw new Error(`The workflow '${response.id}' has the draft '${response.draftVersionId}' and no draft version number to read it by.`);
33
+ }
34
+ const draft = await client.getVersion({ id: response.id, versionNumber: response.draftVersionNumber });
35
+ return {
36
+ ...response,
37
+ definitionJson: draft.definitionJson,
38
+ inputParametersJson: draft.inputParametersJson,
39
+ outputParametersJson: draft.outputParametersJson,
40
+ documentsFrom: 'Draft',
41
+ };
42
+ }
43
+ /**
44
+ * What the editor is editing, refreshed on save; the draft's documents while there is a draft, read with
45
+ * `getVersion`. A draft that cannot be read goes to `onError` and loads as null, never as the current documents.
46
+ */
47
+ export function createWorkflowDocumentSource(client, options = {}) {
48
+ const cache = createReadCache(async (id) => withDraftDocuments(client, await client.getWorkflow({ id })), null, options.onError);
49
+ return {
50
+ useWorkflow(workflowId) {
51
+ const portTypes = usePortTypes();
52
+ const getSnapshot = useCallback(() => (workflowId === null || workflowId === '' ? null : cache.read(workflowId)), [workflowId]);
53
+ const response = useSyncExternalStore(cache.subscribe, getSnapshot, getSnapshot);
54
+ return useMemo(() => (response === null ? null : readWorkflowDocument(response, portTypes)), [response, portTypes]);
55
+ },
56
+ refresh: cache.invalidate,
57
+ };
58
+ }
59
+ //# sourceMappingURL=workflowDocument.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflowDocument.js","sourceRoot":"","sources":["../src/workflowDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAElE,OAAO,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEjF,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAc1D;4HAC4H;AAC5H,MAAM,UAAU,sBAAsB,CAAC,IAA+B;IACpE,OAAO,wBAAwB,CAAC,IAAI,CAAC,CAAA;AACvC,CAAC;AAED,SAAS,SAAS,CAAC,KAA0B,EAAE,IAAY;IACzD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,gBAAgB,IAAI,gBAAgB,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,CAAA;AACvG,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,QAA0B,EAAE,SAA2B;IAC1F,MAAM,MAAM,GAAG,iBAAiB,CAAC,QAAQ,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAA;IACzE,MAAM,OAAO,GAAG,iBAAiB,CAAC,QAAQ,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAA;IAC3E,OAAO;QACL,EAAE,EAAE,QAAQ,CAAC,EAAE;QACf,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,UA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AE;IAEjF,MAAM,KAAK,GAAG,eAAe,CAC3B,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAC1E,IAAI,EACJ,OAAO,CAAC,OAAO,CAChB,CAAA;IAED,OAAO;QACL,WAAW,CAAC,UAAU;YACpB,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;YAChC,MAAM,WAAW,GAAG,WAAW,CAC7B,GAAG,EAAE,CAAC,CAAC,UAAU,KAAK,IAAI,IAAI,UAAU,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAChF,CAAC,UAAU,CAAC,CACb,CAAA;YACD,MAAM,QAAQ,GAAG,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,WAAW,EAAE,WAAW,CAAC,CAAA;YAChF,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAA;QACrH,CAAC;QACD,OAAO,EAAE,KAAK,CAAC,UAAU;KAC1B,CAAA;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { WorkflowClient } from '@reeve-iot/workflow-client';
2
+ /** What a picker needs to offer a workflow, and nothing more. */
3
+ export interface WorkflowOption {
4
+ readonly id: string;
5
+ readonly name: string;
6
+ }
7
+ export interface WorkflowOptionsSource {
8
+ /** The workflows a picker can offer. Empty on the first render and while the list is loading. */
9
+ useWorkflowOptions: () => readonly WorkflowOption[];
10
+ /** Drops the list, so the next render loads it again — call it after the host creates a workflow. */
11
+ refresh: () => void;
12
+ }
13
+ /**
14
+ * The list behind a picker for a `Workflow` port, fetched once and shared. It returns data rather than a
15
+ * control on purpose: what a workflow choice looks like is the host's decision, not this package's.
16
+ */
17
+ export declare function createWorkflowOptionsSource(client: WorkflowClient, options?: {
18
+ readonly onError?: (error: unknown) => void;
19
+ }): WorkflowOptionsSource;
20
+ //# sourceMappingURL=workflowOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflowOptions.d.ts","sourceRoot":"","sources":["../src/workflowOptions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAGhE,iEAAiE;AACjE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAKD,MAAM,WAAW,qBAAqB;IACpC,iGAAiG;IACjG,kBAAkB,EAAE,MAAM,SAAS,cAAc,EAAE,CAAA;IACnD,qGAAqG;IACrG,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CAAO,GAC5D,qBAAqB,CAgBvB"}
@@ -0,0 +1,20 @@
1
+ import { useSyncExternalStore } from 'react';
2
+ import { createReadCache } from './cache.js';
3
+ const NONE = [];
4
+ const ALL = 'all';
5
+ /**
6
+ * The list behind a picker for a `Workflow` port, fetched once and shared. It returns data rather than a
7
+ * control on purpose: what a workflow choice looks like is the host's decision, not this package's.
8
+ */
9
+ export function createWorkflowOptionsSource(client, options = {}) {
10
+ const cache = createReadCache(async () => {
11
+ const workflows = await client.getWorkflows();
12
+ return workflows.map((w) => ({ id: w.id, name: w.name }));
13
+ }, NONE, (_, error) => { options.onError?.(error); });
14
+ const snapshot = () => cache.read(ALL);
15
+ return {
16
+ useWorkflowOptions: () => useSyncExternalStore(cache.subscribe, snapshot, snapshot),
17
+ refresh: cache.invalidate,
18
+ };
19
+ }
20
+ //# sourceMappingURL=workflowOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflowOptions.js","sourceRoot":"","sources":["../src/workflowOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAQ5C,MAAM,IAAI,GAA8B,EAAE,CAAA;AAC1C,MAAM,GAAG,GAAG,KAAK,CAAA;AASjB;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CACzC,MAAsB,EACtB,UAA2D,EAAE;IAE7D,MAAM,KAAK,GAAG,eAAe,CAC3B,KAAK,IAAI,EAAE;QACT,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,YAAY,EAAE,CAAA;QAC7C,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IAC3D,CAAC,EACD,IAAI,EACJ,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAA,CAAC,CAAC,CAC3C,CAAA;IAED,MAAM,QAAQ,GAAG,GAA8B,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAEjE,OAAO;QACL,kBAAkB,EAAE,GAAG,EAAE,CAAC,oBAAoB,CAAC,KAAK,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC;QACnF,OAAO,EAAE,KAAK,CAAC,UAAU;KAC1B,CAAA;AACH,CAAC"}
@@ -0,0 +1,44 @@
1
+ import type { WorkflowClient } from '@reeve-iot/workflow-client';
2
+ import type { PortInfo, PortTypeRegistry, StoredDocumentFault, WorkflowReferenceResolver } from '@reeve-iot/workflow-core';
3
+ /** A parameter list read as ports, or the first rule its stored text breaks. */
4
+ export type DeclaredPortsRead = {
5
+ ok: true;
6
+ ports: PortInfo[];
7
+ } | {
8
+ ok: false;
9
+ fault: StoredDocumentFault;
10
+ };
11
+ /**
12
+ * Reads one of the two parameter fields through the stored-document reader: an absent list and `[]` are no
13
+ * parameters, blank text and `null` are refused, and so is a list the reader refuses, whole, never read as
14
+ * the entries that happen to parse.
15
+ * A type is normalised into the host's vocabulary; an absent one is blank, never Any.
16
+ */
17
+ export declare function readDeclaredPorts(json: string | null, portTypes: PortTypeRegistry): DeclaredPortsRead;
18
+ /** Thrown into `onError` for a referenced workflow whose parameter list cannot be read; it then draws no ports. */
19
+ export declare class WorkflowReferenceUnreadableError extends Error {
20
+ readonly workflowId: string;
21
+ readonly fault: StoredDocumentFault;
22
+ constructor(workflowId: string, fault: StoredDocumentFault);
23
+ }
24
+ export interface WorkflowReferenceResolverOptions {
25
+ /** Called when a workflow cannot be read. Without it a failure is silent, which is the editor's own
26
+ * contract: an unresolvable reference draws no ports rather than breaking the canvas. */
27
+ readonly onError?: (workflowId: string, error: unknown) => void;
28
+ }
29
+ export interface WorkflowReferenceSource {
30
+ /** The seam `core` declares. Pass it to `WorkflowReferenceResolverContext`. */
31
+ resolver: WorkflowReferenceResolver;
32
+ /** Forgets every referenced workflow, so the next render reads them again. */
33
+ refresh: () => void;
34
+ }
35
+ /**
36
+ * The seam `core` declares, implemented once. Call it outside render — the resolver's identity has to
37
+ * stay stable for the editor's lifetime — and pass `resolver` to `WorkflowReferenceResolverContext`.
38
+ *
39
+ * Each referenced workflow is fetched once and shared by every node that references it. A workflow that
40
+ * cannot be read resolves to no ports and is not asked for again until `refresh()`, which is also what
41
+ * makes a child's newly declared parameter appear on the parent that runs it.
42
+ */
43
+ export declare function createWorkflowReferenceSource(client: WorkflowClient, options?: WorkflowReferenceResolverOptions): WorkflowReferenceSource;
44
+ //# sourceMappingURL=workflowReference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflowReference.d.ts","sourceRoot":"","sources":["../src/workflowReference.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAEhE,OAAO,KAAK,EACV,QAAQ,EAAE,gBAAgB,EAAE,mBAAmB,EAA0B,yBAAyB,EACnG,MAAM,0BAA0B,CAAA;AAKjC,gFAAgF;AAChF,MAAM,MAAM,iBAAiB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,QAAQ,EAAE,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,mBAAmB,CAAA;CAAE,CAAA;AAE3G;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,SAAS,EAAE,gBAAgB,GAAG,iBAAiB,CAerG;AAED,mHAAmH;AACnH,qBAAa,gCAAiC,SAAQ,KAAK;IAC7C,QAAQ,CAAC,UAAU,EAAE,MAAM;IAAE,QAAQ,CAAC,KAAK,EAAE,mBAAmB;gBAAvD,UAAU,EAAE,MAAM,EAAW,KAAK,EAAE,mBAAmB;CAI7E;AAED,MAAM,WAAW,gCAAgC;IAC/C;6FACyF;IACzF,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CAChE;AAED,MAAM,WAAW,uBAAuB;IACtC,+EAA+E;IAC/E,QAAQ,EAAE,yBAAyB,CAAA;IACnC,8EAA8E;IAC9E,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB;AAED;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,cAAc,EACtB,OAAO,GAAE,gCAAqC,GAC7C,uBAAuB,CA+BzB"}
@@ -0,0 +1,71 @@
1
+ import { useCallback, useMemo, useSyncExternalStore } from 'react';
2
+ import { describeStoredDocumentFault, readParameterListText, usePortTypes } from '@reeve-iot/workflow-core';
3
+ import { createReadCache } from './cache.js';
4
+ const EMPTY = { inputs: [], outputs: [] };
5
+ /**
6
+ * Reads one of the two parameter fields through the stored-document reader: an absent list and `[]` are no
7
+ * parameters, blank text and `null` are refused, and so is a list the reader refuses, whole, never read as
8
+ * the entries that happen to parse.
9
+ * A type is normalised into the host's vocabulary; an absent one is blank, never Any.
10
+ */
11
+ export function readDeclaredPorts(json, portTypes) {
12
+ const read = readParameterListText(json, 'input');
13
+ if (!read.ok)
14
+ return read;
15
+ return {
16
+ ok: true,
17
+ ports: read.sites.map((site, i) => {
18
+ const displayName = read.entries[i]?.['displayName'];
19
+ return {
20
+ name: site.portName,
21
+ displayName: typeof displayName === 'string' && displayName !== '' ? displayName : site.portName,
22
+ isRequired: site.isRequired,
23
+ type: site.rawType === null ? '' : portTypes.normalize(site.rawType),
24
+ };
25
+ }),
26
+ };
27
+ }
28
+ /** Thrown into `onError` for a referenced workflow whose parameter list cannot be read; it then draws no ports. */
29
+ export class WorkflowReferenceUnreadableError extends Error {
30
+ workflowId;
31
+ fault;
32
+ constructor(workflowId, fault) {
33
+ super(`The declared parameters of workflow '${workflowId}' cannot be read: ${describeStoredDocumentFault(fault)}.`);
34
+ this.workflowId = workflowId;
35
+ this.fault = fault;
36
+ this.name = 'WorkflowReferenceUnreadableError';
37
+ }
38
+ }
39
+ /**
40
+ * The seam `core` declares, implemented once. Call it outside render — the resolver's identity has to
41
+ * stay stable for the editor's lifetime — and pass `resolver` to `WorkflowReferenceResolverContext`.
42
+ *
43
+ * Each referenced workflow is fetched once and shared by every node that references it. A workflow that
44
+ * cannot be read resolves to no ports and is not asked for again until `refresh()`, which is also what
45
+ * makes a child's newly declared parameter appear on the parent that runs it.
46
+ */
47
+ export function createWorkflowReferenceSource(client, options = {}) {
48
+ const cache = createReadCache(async (id) => {
49
+ const workflow = await client.getWorkflow({ id });
50
+ for (const json of [workflow.inputParametersJson, workflow.outputParametersJson]) {
51
+ const read = readParameterListText(json, 'input');
52
+ if (!read.ok)
53
+ throw new WorkflowReferenceUnreadableError(id, read.fault);
54
+ }
55
+ return workflow;
56
+ }, null, options.onError);
57
+ function useWorkflowReference(workflowId) {
58
+ const portTypes = usePortTypes();
59
+ const getSnapshot = useCallback(() => (workflowId === null || workflowId === '' ? null : cache.read(workflowId)), [workflowId]);
60
+ const workflow = useSyncExternalStore(cache.subscribe, getSnapshot, getSnapshot);
61
+ return useMemo(() => {
62
+ if (workflow === null)
63
+ return EMPTY;
64
+ const inputs = readDeclaredPorts(workflow.inputParametersJson, portTypes);
65
+ const outputs = readDeclaredPorts(workflow.outputParametersJson, portTypes);
66
+ return inputs.ok && outputs.ok ? { inputs: inputs.ports, outputs: outputs.ports } : EMPTY;
67
+ }, [workflow, portTypes]);
68
+ }
69
+ return { resolver: useWorkflowReference, refresh: cache.invalidate };
70
+ }
71
+ //# sourceMappingURL=workflowReference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflowReference.js","sourceRoot":"","sources":["../src/workflowReference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAElE,OAAO,EAAE,2BAA2B,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAI3G,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE5C,MAAM,KAAK,GAA2B,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;AAKjE;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAmB,EAAE,SAA2B;IAChF,MAAM,IAAI,GAAG,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACjD,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAA;IACzB,OAAO;QACL,EAAE,EAAE,IAAI;QACR,KAAK,EAAE,IAAI,CAAC,KA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EAAE,CAAA;AACtE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@reeve-iot/workflow-adapters",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Ready-made implementations of the seams @reeve-iot/workflow-core declares, over @reeve-iot/workflow-client. Wire these and the editor works without writing a fetch layer.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/reeve-iot/reeve-workflow.git",
25
+ "directory": "packages/adapters"
26
+ },
27
+ "keywords": [
28
+ "workflow",
29
+ "editor",
30
+ "react",
31
+ "adapter",
32
+ "client"
33
+ ],
34
+ "scripts": {
35
+ "build": "tsc -b",
36
+ "typecheck": "tsc -b"
37
+ },
38
+ "dependencies": {
39
+ "@reeve-iot/workflow-client": "1.0.0",
40
+ "@reeve-iot/workflow-core": "1.0.0"
41
+ },
42
+ "peerDependencies": {
43
+ "react": "^18.0.0 || ^19.0.0"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ }
48
+ }