@pikku/inspector 0.12.43 → 0.12.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.md +168 -0
  2. package/dist/add/add-credential.js +2 -0
  3. package/dist/add/add-keyed-wiring.js +2 -0
  4. package/dist/add/add-workflow.js +9 -4
  5. package/dist/utils/schema-generator.js +19 -4
  6. package/dist/utils/workflow/dsl/deserialize-dsl-workflow.js +373 -91
  7. package/dist/utils/workflow/dsl/extract-dsl-workflow.js +218 -99
  8. package/dist/utils/workflow/graph/convert-dsl-to-graph.js +62 -5
  9. package/dist/utils/workflow/graph/workflow-graph.types.d.ts +3 -3
  10. package/package.json +3 -3
  11. package/run-tests.sh +1 -1
  12. package/src/add/add-credential.ts +2 -0
  13. package/src/add/add-keyed-wiring.ts +2 -0
  14. package/src/add/add-workflow-edge-cases.test.ts +201 -0
  15. package/src/add/add-workflow-fanout.test.ts +60 -0
  16. package/src/add/add-workflow-on-error.test.ts +118 -0
  17. package/src/add/add-workflow-return-switch.test.ts +121 -0
  18. package/src/add/add-workflow-silent-drops.test.ts +163 -0
  19. package/src/add/add-workflow-sleep-expression.test.ts +97 -0
  20. package/src/add/add-workflow.ts +9 -4
  21. package/src/add/config-value-metadata.test.ts +169 -0
  22. package/src/utils/schema-generator.test.ts +164 -0
  23. package/src/utils/schema-generator.ts +26 -3
  24. package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +480 -119
  25. package/src/utils/workflow/dsl/deserialize-fanout-body.test.ts +71 -0
  26. package/src/utils/workflow/dsl/deserialize-fanout-fidelity.test.ts +99 -0
  27. package/src/utils/workflow/dsl/deserialize-graph-next.test.ts +161 -0
  28. package/src/utils/workflow/dsl/deserialize-roundtrip-bindings.test.ts +121 -0
  29. package/src/utils/workflow/dsl/deserialize-roundtrip-values.test.ts +116 -0
  30. package/src/utils/workflow/dsl/deserialize-roundtrip.test.ts +145 -0
  31. package/src/utils/workflow/dsl/extract-dsl-workflow.ts +245 -105
  32. package/src/utils/workflow/graph/convert-dsl-to-graph.ts +67 -10
  33. package/src/utils/workflow/graph/fanout-node-identity.test.ts +105 -0
  34. package/src/utils/workflow/graph/workflow-graph.types.ts +3 -2
  35. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,171 @@
1
+ ## 0.12.44
2
+
3
+ ### Patch Changes
4
+
5
+ - 1a86d3f: Stop silently dropping DSL workflow constructs during extraction.
6
+
7
+ Four constructs produced a wrong workflow graph with no diagnostic:
8
+ - A property access on the fanout item (`users.map((u) => workflow.do(..., { userId: u.id }))`)
9
+ was dropped from the step's inputs — `extractInputSource` resolved property
10
+ access against the input param and output variables but not loop variables.
11
+ - `const [org, user] = await Promise.all([...])` dropped **both** steps, because
12
+ extraction bailed on any non-identifier binding name before reaching the
13
+ `Promise.all` branch. Array destructuring now binds each name to its matching
14
+ child step's output.
15
+ - A brace-less `for (const x of xs) await workflow.do(...)` dropped the entire
16
+ loop, since only block bodies were walked.
17
+ - Object destructuring of a step result and multi-declarator statements now
18
+ report a diagnostic instead of vanishing.
19
+
20
+ - 1a86d3f: Fix a fanout collapsing into a single step, and preserve graph node config.
21
+ - A fanout took its `stepName` from the first step of its body. Node ids _are_
22
+ step names, so the loop and that step got the same id and the step overwrote
23
+ the loop: `await Promise.all(users.map(...))` rendered as one plain call, and
24
+ everything after the loop became unreachable. A fanout is not itself a cached
25
+ step, so it no longer borrows a name.
26
+ - A `workflow.sleep` or `workflow.suspend` inside a fanout body was dropped at
27
+ extraction — `FanoutStepMeta.body` was typed RPC-only. It now admits sleep and
28
+ suspend, and the regenerated body emits them.
29
+ - Regenerating a `pikkuWorkflowGraph` dropped `onError`, `retries` and
30
+ `retryDelay` from every node, and graph-level `notes`. All four are honoured
31
+ at runtime, so the round trip silently changed behaviour.
32
+
33
+ - 1a86d3f: Support multi-step fanout bodies in DSL workflows.
34
+
35
+ A `Promise.all(array.map(...))` (or `for...of`) body containing more than one
36
+ `workflow.do` call previously extracted only a single step: `const`-captured
37
+ steps were skipped entirely by the parallel extractor, so a body like
38
+
39
+ ```ts
40
+ await Promise.all(
41
+ users.map(async (u) => {
42
+ const digestData = await workflow.do('Get pipeline', 'getDigestData', {
43
+ userId: u.id,
44
+ })
45
+ await workflow.do('Send digest', 'sendDigestEmail', { ...digestData })
46
+ })
47
+ )
48
+ ```
49
+
50
+ produced a graph with `getDigestData` missing and `sendDigestEmail` referencing
51
+ an unregistered variable. `FanoutStepMeta.child` is replaced by
52
+ `FanoutStepMeta.body: RpcStepMeta[]`, holding the per-iteration steps inline in
53
+ the same workflow — no sub-workflow boundary. Per-iteration `const` bindings are
54
+ now registered so later steps in the same iteration can reference them, and the
55
+ sequential path no longer hard-errors on bodies with more than one step.
56
+
57
+ - 1a86d3f: Add `onError` compensation to DSL workflows.
58
+
59
+ A DSL workflow had no way to express error handling at all — `try/catch` is not
60
+ an allowed statement, and step options carried only `retries`/`retryDelay`. A
61
+ step can now name a compensation RPC:
62
+
63
+ ```ts
64
+ await workflow.do(
65
+ 'Charge',
66
+ 'chargeCard',
67
+ { id },
68
+ {
69
+ retries: 3,
70
+ onError: 'refundOrder',
71
+ }
72
+ )
73
+ ```
74
+
75
+ Semantics mirror a graph node's `onError` exactly: once the step's retries are
76
+ exhausted the handler is invoked with `{ error: { message } }` and the original
77
+ error is still thrown. This is compensation, not recovery — the workflow fails
78
+ either way. The handler runs as its own durable step, so a replay cannot
79
+ compensate twice, and it does not inherit `onError` itself.
80
+
81
+ The handler is materialised as a real graph node, so it is wired like any other
82
+ RPC and the console draws a dashed red "on error" edge to it rather than the
83
+ route being invisible.
84
+
85
+ - 1a86d3f: Keep a numeric `retryDelay` numeric through the graph round-trip. The serialized
86
+ graph typed it as `string` and the DSL→graph conversion called `.toString()`, so
87
+ `retryDelay: 500` regenerated as `retryDelay: '500'` — a different value to the
88
+ runtime, which parses strings as durations.
89
+ - 1a86d3f: Stop silently dropping switch cases and spread returns from workflow graphs.
90
+ - A fall-through case (`case 'a': case 'b': ...`) recorded only the last value.
91
+ A run entering on `'a'` therefore appeared to match no case at all. Empty
92
+ clauses now carry through to the entry they fall into — the next non-empty
93
+ case, otherwise `default`, otherwise the switch exit.
94
+ - `return { ...r, extra: 1 }` produced a return node listing only `extra`, so
95
+ the graph claimed an output shape the workflow does not have, with no
96
+ diagnostic. `return r` produced no return node at all. `ReturnStepMeta` now
97
+ records a `spread` list, and the regenerated code emits it.
98
+
99
+ - 1a86d3f: Stop deleting code when regenerating a DSL workflow from its graph.
100
+
101
+ Regenerating a workflow (as the console's graph editor does) silently dropped
102
+ steps:
103
+ - Only the **first** step of an `if` arm survived. The walk stopped via a
104
+ heuristic that tested whether the next node id contained `_then_`/`_else_`,
105
+ but node ids are step names, so it never matched. Branch and switch bodies now
106
+ walk the `next` chain up to an explicit exit boundary — the enclosing flow
107
+ node's own `next`.
108
+ - Switch cases emitted only their entry node, never walking `next` at all.
109
+ - Every step was renamed to `Call <rpcName>`, because the graph conversion never
110
+ wrote `stepName` onto the node. Step names are the durable replay cache key,
111
+ so a round-trip silently invalidated in-flight runs.
112
+ - `workflow.suspend()` had no graph node, yet the preceding step's `next` still
113
+ pointed at its id — traversal dead-ended there and every following step was
114
+ deleted. `suspend` is now a real flow node, and both `suspend` and `approval`
115
+ have deserializer cases.
116
+ - Numeric and boolean `switch` case values were emitted quoted (`case '1':`),
117
+ so the case could never match. Step names and reasons containing a quote are
118
+ now escaped.
119
+
120
+ Also fixed in the same pass:
121
+ - `const [org, user] = await Promise.all([...])` regenerated as a bare
122
+ `await Promise.all([...])`, leaving both names unbound.
123
+ - A step result assigned inside a branch was re-declared with `const` inside
124
+ that branch, so any later reference was out of scope. Hoisting analysis was
125
+ keyed off the same dead node-id heuristic and never fired.
126
+ - A top-level step whose _name_ contained `_case`, `_item_`, `_then_`,
127
+ `_else_`, `_child_` or `_default_` was silently deleted, because node ids are
128
+ step names and were matched against those structural substrings. Ownership is
129
+ now read from the parent constructs themselves.
130
+
131
+ - 1a86d3f: Stop corrupting values when regenerating a workflow from its graph.
132
+ - A numeric `workflow.sleep('Wait', 5000)` came back as `'5000'`, and a numeric
133
+ `retryDelay` likewise. Durations are `string | number`; only strings are
134
+ quoted now.
135
+ - An assignment to a context variable was stored as an opaque `value`, so
136
+ `count = count + 1` regenerated as `count = 'count + 1'` — an expression
137
+ turned into a string literal. `SetStepMeta` now carries a separate
138
+ `expression` field (mirroring `SwitchCaseMeta`), so a string literal and a
139
+ code expression are no longer indistinguishable in the meta.
140
+ - A `next` that was not a single node id was coerced with a string cast: an
141
+ array became the bogus id `'a,b'` and a branch-key record became
142
+ `'[object Object]'`, severing every downstream node. Arrays, key-based
143
+ routing tables and condition lists now each render in their own shape.
144
+ - A `filter`/`some`/`every` node with no `outputVar` emitted
145
+ `const undefined = ...`, which does not parse.
146
+
147
+ - 1a86d3f: Keep a `workflow.sleep` whose duration is only known at runtime (a loop
148
+ variable, a field off the input). The closure evaluates it, so it is legal DSL;
149
+ its source text is recorded as an `expression` and emitted raw when regenerating
150
+ code, as a set step already does.
151
+ - 314ace3: Cut the schema generator's ts.Program cost — the dominant contributor to `pikku all` memory and time.
152
+
153
+ Two independent fixes: the program is now scoped to the virtual file's import
154
+ closure (870 source files instead of the whole tsconfig's 2572), and it is
155
+ released once schemas are generated instead of being pinned at module scope for
156
+ the life of the process. On a 279-function tree this cuts cold codegen ~20% and
157
+ in-pass live heap ~21%, with byte-identical schema output.
158
+
159
+ - 3d76f51: Add an optional `docsUrl` to `wireSecret`, `wireVariable`, and `wireCredential`, so a console or deploy UI reporting a missing value can link the user to where they obtain it instead of showing a bare identifier.
160
+ - Updated dependencies [1a86d3f]
161
+ - Updated dependencies [1a86d3f]
162
+ - Updated dependencies [1a86d3f]
163
+ - Updated dependencies [1a86d3f]
164
+ - Updated dependencies [1a86d3f]
165
+ - Updated dependencies [1a86d3f]
166
+ - Updated dependencies [3d76f51]
167
+ - @pikku/core@0.12.65
168
+
1
169
  ## 0.12.43
2
170
 
3
171
  ### Patch Changes
@@ -22,6 +22,7 @@ export const addCredential = (logger, node, checker, state, _options) => {
22
22
  const displayNameValue = getPropertyValue(obj, 'displayName');
23
23
  const descriptionValue = getPropertyValue(obj, 'description');
24
24
  const typeValue = getPropertyValue(obj, 'type');
25
+ const docsUrlValue = getPropertyValue(obj, 'docsUrl');
25
26
  if (!nameValue) {
26
27
  logger.critical(ErrorCode.MISSING_NAME, "Credential is missing the required 'name' property.");
27
28
  return;
@@ -113,6 +114,7 @@ export const addCredential = (logger, node, checker, state, _options) => {
113
114
  displayName: displayNameValue,
114
115
  description: descriptionValue || undefined,
115
116
  type: typeValue,
117
+ docsUrl: docsUrlValue || undefined,
116
118
  schema: schemaLookupName,
117
119
  oauth2,
118
120
  sourceFile,
@@ -26,6 +26,7 @@ export const createAddKeyedWiring = (config) => {
26
26
  const displayNameValue = getPropertyValue(obj, 'displayName');
27
27
  const descriptionValue = getPropertyValue(obj, 'description');
28
28
  const rotationPeriodValue = getPropertyValue(obj, 'rotationPeriod');
29
+ const docsUrlValue = getPropertyValue(obj, 'docsUrl');
29
30
  const idValue = getPropertyValue(obj, config.idField);
30
31
  let schemaVariableName = null;
31
32
  let schemaSourceFile = null;
@@ -102,6 +103,7 @@ export const createAddKeyedWiring = (config) => {
102
103
  displayName: displayNameValue,
103
104
  description: descriptionValue || undefined,
104
105
  rotationPeriod: rotationPeriodValue || undefined,
106
+ docsUrl: docsUrlValue || undefined,
105
107
  [config.idField]: idValue,
106
108
  schema: schemaLookupName,
107
109
  sourceFile,
@@ -62,8 +62,8 @@ function hasInlineSteps(steps) {
62
62
  if (step.defaultSteps && hasInlineSteps(step.defaultSteps))
63
63
  return true;
64
64
  }
65
- else if (step.type === 'fanout' && step.child) {
66
- if (hasInlineSteps([step.child]))
65
+ else if (step.type === 'fanout' && step.body) {
66
+ if (hasInlineSteps(step.body))
67
67
  return true;
68
68
  }
69
69
  else if (step.type === 'parallel' && step.children) {
@@ -80,6 +80,11 @@ export function collectInvokedRPCs(steps, rpcs) {
80
80
  for (const step of steps) {
81
81
  if (step.type === 'rpc' && step.rpcName) {
82
82
  rpcs.add(step.rpcName);
83
+ // The compensation handler is invoked at runtime too, so it has to be
84
+ // wired like any other step.
85
+ if (step.options?.onError) {
86
+ rpcs.add(step.options.onError);
87
+ }
83
88
  }
84
89
  else if (step.type === 'branch') {
85
90
  for (const branch of step.branches) {
@@ -96,8 +101,8 @@ export function collectInvokedRPCs(steps, rpcs) {
96
101
  if (step.defaultSteps)
97
102
  collectInvokedRPCs(step.defaultSteps, rpcs);
98
103
  }
99
- else if (step.type === 'fanout' && step.child) {
100
- collectInvokedRPCs([step.child], rpcs);
104
+ else if (step.type === 'fanout' && step.body) {
105
+ collectInvokedRPCs(step.body, rpcs);
101
106
  }
102
107
  else if (step.type === 'parallel' && step.children) {
103
108
  collectInvokedRPCs(step.children, rpcs);
@@ -67,7 +67,9 @@ const inspectorVersion = (() => {
67
67
  try {
68
68
  const pkgUrl = new URL('../../package.json', import.meta.url);
69
69
  const pkg = JSON.parse(readFileSync(pkgUrl, 'utf-8'));
70
- return typeof pkg.version === 'string' ? pkg.version : `v${SCHEMA_CACHE_VERSION}`;
70
+ return typeof pkg.version === 'string'
71
+ ? pkg.version
72
+ : `v${SCHEMA_CACHE_VERSION}`;
71
73
  }
72
74
  catch {
73
75
  return `v${SCHEMA_CACHE_VERSION}`;
@@ -112,7 +114,7 @@ function writeDiskTSSchemas(logger, cacheDir, key, schemas) {
112
114
  logger.debug(`Failed to persist TS-schema cache: ${e.message}`);
113
115
  }
114
116
  }
115
- function createProgramWithVirtualFile(tsconfig, virtualFilePath, virtualFileContent) {
117
+ function createProgramWithVirtualFile(logger, tsconfig, virtualFilePath, virtualFileContent) {
116
118
  const configPath = resolve(tsconfig);
117
119
  // Cache the parsed tsconfig — it doesn't change between runs
118
120
  if (!cachedParsedConfig || cachedTsconfigPath !== configPath) {
@@ -123,7 +125,11 @@ function createProgramWithVirtualFile(tsconfig, virtualFilePath, virtualFileCont
123
125
  cachedSchemaProgram = undefined;
124
126
  }
125
127
  const resolvedVirtualPath = resolve(virtualFilePath);
126
- const fileNames = [...cachedParsedConfig.fileNames, resolvedVirtualPath];
128
+ // The virtual file imports every type it references, so it is a complete root
129
+ // on its own and TypeScript pulls in exactly the transitive closure it needs.
130
+ // Rooting at cachedParsedConfig.fileNames instead loaded the whole project
131
+ // (2572 files vs 870 on a real tree) without widening what could be resolved.
132
+ const fileNames = [resolvedVirtualPath];
127
133
  const defaultHost = ts.createCompilerHost(cachedParsedConfig.options);
128
134
  const customHost = {
129
135
  ...defaultHost,
@@ -144,9 +150,11 @@ function createProgramWithVirtualFile(tsconfig, virtualFilePath, virtualFileCont
144
150
  return defaultHost.readFile(fileName);
145
151
  },
146
152
  };
153
+ const startProgram = performance.now();
147
154
  const program = ts.createProgram(fileNames, cachedParsedConfig.options, customHost, cachedSchemaProgram // reuse previous program for incremental compilation
148
155
  );
149
156
  cachedSchemaProgram = program;
157
+ logger.debug(`Created schema program in ${(performance.now() - startProgram).toFixed(0)}ms (${program.getSourceFiles().length} files)`);
150
158
  return program;
151
159
  }
152
160
  function generateTSSchemas(logger, tsconfig, customTypesContent, typesMap, functionMeta, httpWiringsMeta, additionalTypes, additionalProperties = false, generatedZodSchemas) {
@@ -192,7 +200,7 @@ function generateTSSchemas(logger, tsconfig, customTypesContent, typesMap, funct
192
200
  }
193
201
  logger.debug(`generateTSSchemas needed for ${uncoveredSchemas.length} types: ${uncoveredSchemas.slice(0, 3).join(', ')}${uncoveredSchemas.length > 3 ? '...' : ''}`);
194
202
  const virtualFilePath = join(dirname(resolve(tsconfig)), '__pikku_virtual_types__.ts');
195
- const program = createProgramWithVirtualFile(tsconfig, virtualFilePath, customTypesContent);
203
+ const program = createProgramWithVirtualFile(logger, tsconfig, virtualFilePath, customTypesContent);
196
204
  const generator = createGenerator({
197
205
  tsProgram: program,
198
206
  skipTypeCheck: true,
@@ -408,6 +416,13 @@ export async function generateAllSchemas(logger, config, state) {
408
416
  }
409
417
  }
410
418
  const tsSchemas = generateTSSchemas(logger, config.tsconfig, customTypesContent, state.functions.typesMap, state.functions.meta, state.http.meta, config.schemasFromTypes, config.schema?.additionalProperties, zodSchemas);
419
+ // Release the program once the schemas are out of it. It spans the whole
420
+ // tsconfig (~2.5k files, ~600MB on a large tree) and was previously pinned at
421
+ // module scope for the life of the process, so it stacked on top of the main
422
+ // inspector program and pushed `pikku all` past a 2GB heap (#982). The result
423
+ // cache below is what the same-process fast path actually needs; the program
424
+ // only bought incremental reuse on a rebuild, at a cost that dwarfs it.
425
+ cachedSchemaProgram = undefined;
411
426
  cachedCustomTypesContent = customTypesContent;
412
427
  cachedTSSchemas = tsSchemas;
413
428
  if (config.cacheDir && cacheKey) {