From ad48a1e1e71903cf08912a2b979227078ab535ce Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Mon, 30 Nov 2026 23:52:41 -0800 Subject: [PATCH] chore(workflow-sdk): drop unused codegen exports and alias indirection - codegen barrel: drop GenerateSdkTypesFn, GenerateWorkspaceTypesFn, BuilderLookup, BuilderReference and WorkspaceManifestColumn; generateSdkTypes and generateWorkspaceTypes become plain function declarations - knip: check workflow-sdk entry exports (exempting only the authoring .d.ts surface and fixtures), so an unused ./codegen export now fails check:unused-exports - compile-source.ts and stored-edges.ts import CompileInput instead of re-deriving it - refusals.ts reads blockRenames directly instead of inverting it twice --- .../source-pipeline/evaluate/refusals.ts | 3 +-- apps/sim/lib/workflows/code/compile-source.ts | 3 +-- knip.jsonc | 18 +++++++++++------- .../src/commands/protocol/stored-edges.ts | 3 +-- packages/workflow-sdk/src/codegen/generate.ts | 7 ++++--- packages/workflow-sdk/src/codegen/index.ts | 5 ----- packages/workflow-sdk/src/codegen/reference.ts | 4 ++-- packages/workflow-sdk/src/codegen/workspace.ts | 6 ++---- 8 files changed, 22 insertions(+), 27 deletions(-) diff --git a/apps/sim/lib/workflows/application/source-pipeline/evaluate/refusals.ts b/apps/sim/lib/workflows/application/source-pipeline/evaluate/refusals.ts index e0873fe2c43..018cb33421c 100644 --- a/apps/sim/lib/workflows/application/source-pipeline/evaluate/refusals.ts +++ b/apps/sim/lib/workflows/application/source-pipeline/evaluate/refusals.ts @@ -261,11 +261,10 @@ export async function sourceRefusals( replacedKeys ) const renamedKeys = new Map([...blockRenames].map(([key, storedKey]) => [storedKey, key])) - const storedKeyOf = new Map([...renamedKeys].map(([storedKey, key]) => [key, storedKey])) const storedCode = (key: string) => { const storedBlock = getOwn(compiled.stored.blocks, key) ?? - getOwn(compiled.stored.blocks, storedKeyOf.get(key) ?? key) + getOwn(compiled.stored.blocks, blockRenames.get(key) ?? key) return storedBlock && getOwn(storedBlock.params, 'code') } const compileFindings = withoutRenameSettledFindings(compiled, renamedKeys, () => diff --git a/apps/sim/lib/workflows/code/compile-source.ts b/apps/sim/lib/workflows/code/compile-source.ts index 4bba3732d24..54e9ccff3fb 100644 --- a/apps/sim/lib/workflows/code/compile-source.ts +++ b/apps/sim/lib/workflows/code/compile-source.ts @@ -1,6 +1,7 @@ import { type BlockKey, type CanonicalWorkflow, + type CompileInput, type CompileResult, compileWorkflow, lockIdentRenames, @@ -8,8 +9,6 @@ import { type WorkflowLockV1, } from '@sim/workflow-code' -type CompileInput = Parameters[0] - /** `stored` with each renamed block under its new key, its children and edges following it. */ function rekeyStored( stored: CanonicalWorkflow, diff --git a/knip.jsonc b/knip.jsonc index 6a2883159ae..3eac2e454e4 100644 --- a/knip.jsonc +++ b/knip.jsonc @@ -173,26 +173,30 @@ "entry": ["src/index.ts", "src/runtime.ts", "scripts/*.ts"] }, "packages/sim-setup": { "includeEntryExports": false }, - // The SDK's main entry is `core.d.ts`, the authoring surface workflow files outside this - // monorepo import (the CLI writes it next to them as `CORE_DTS`), so no workspace imports its - // exports. `test/examples`, `test/negative` and `test/core` are type-check fixtures whose + // Entry exports stay checked, so a `./codegen` export nothing in the monorepo imports fails. + // Exempt: `core.d.ts` and `workspace/*.d.ts`, the authoring surface workflow files outside + // this monorepo import (the CLI writes them next to those files as `CORE_DTS` and + // `WORKSPACE_SDK_DTS`), so no workspace imports them. `test/examples`, `test/negative` and `test/core` are type-check fixtures whose // default export is the workflow: nothing imports them, because `test/typecheck-project.ts` // globs them into a tsconfig that a test runs tsgo against. `cookbook/examples/*.ts` are // the examples the CLI writes as text (`COOKBOOK_EXAMPLES`), type-checked by apps/sim's real-catalog test; // `cookbook/workspace/**` is the example workspace directory it writes as `WORKSPACE_COOKBOOK` // (its `tools/*.js` is custom tool code, which runs in a sandbox, not as a module). "packages/workflow-sdk": { - "includeEntryExports": false, "entry": [ - "src/runtime.ts", - "src/codegen/index.ts", "scripts/*.ts", "cookbook/examples/*.ts", "cookbook/workspace/**/*.{ts,js}", "test/core/*.ts", "test/examples/*.ts", "test/negative/*.ts" - ] + ], + "ignoreIssues": { + "src/core.d.ts": ["exports", "types"], + "src/workspace/*.d.ts": ["exports", "types"], + "cookbook/**": ["exports"], + "test/{core,examples,negative}/*.ts": ["exports"] + } }, // This shared config is consumed by apps that own the Next dependency. "packages/tsconfig": { "ignoreUnresolved": ["next"] } diff --git a/packages/sim-cli/src/commands/protocol/stored-edges.ts b/packages/sim-cli/src/commands/protocol/stored-edges.ts index b7bab5a0591..4c37a7a5145 100644 --- a/packages/sim-cli/src/commands/protocol/stored-edges.ts +++ b/packages/sim-cli/src/commands/protocol/stored-edges.ts @@ -4,6 +4,7 @@ import { type CanonicalBlock, type ChildResultNode, type ChildResults, + type CompileInput, type CompileResult, calledWorkflowKeys, compiledResultNode, @@ -35,8 +36,6 @@ export function blockDigest(block: CanonicalBlock): string { return digest(stableStringify(block)) } -type CompileInput = Parameters[0] - /** * `compiled`, the compile of `input`, as `childResults` type it: the same compile when none types * a call it makes, else `input` compiled again with them. diff --git a/packages/workflow-sdk/src/codegen/generate.ts b/packages/workflow-sdk/src/codegen/generate.ts index 55f5308f086..eb1060573c3 100644 --- a/packages/workflow-sdk/src/codegen/generate.ts +++ b/packages/workflow-sdk/src/codegen/generate.ts @@ -68,8 +68,6 @@ interface SdkTypesOptions { blockTypes?: ReadonlySet } -export type GenerateSdkTypesFn = (catalog: BlockCatalog, options?: SdkTypesOptions) => SdkTypeFile[] - /** Names `core.d.ts` exports that generated files may reference; imported only when used. */ const CORE_TYPE_NAMES = [ 'AnyRef', @@ -798,7 +796,10 @@ function generateSdkIndex( * Generates the declaration files and `INDEX.md` for a catalog, sorted by path: every block, or * only `options.blockTypes` (a directory's own copy, whose `index.d.ts` imports just those). */ -export const generateSdkTypes: GenerateSdkTypesFn = (catalog, options = {}) => { +export function generateSdkTypes( + catalog: BlockCatalog, + options: SdkTypesOptions = {} +): SdkTypeFile[] { const byType = new Map() for (const entry of builderEntries(catalog)) { if (options.blockTypes && !options.blockTypes.has(entry.builder.type)) continue diff --git a/packages/workflow-sdk/src/codegen/index.ts b/packages/workflow-sdk/src/codegen/index.ts index 6b76de6386a..ee0884b6124 100644 --- a/packages/workflow-sdk/src/codegen/index.ts +++ b/packages/workflow-sdk/src/codegen/index.ts @@ -1,7 +1,6 @@ export { COOKBOOK_EXAMPLES } from './cookbook-text.generated' export { CORE_DTS } from './core-text.generated' export { - type GenerateSdkTypesFn, generateSdkTypes, type SdkTypeFile, sdkIndexHeader, @@ -17,8 +16,6 @@ export { SDK_MODELS_FILE, } from './layout' export { - type BuilderLookup, - type BuilderReference, builderSnippet, compactBuilder, describeBuilder, @@ -28,10 +25,8 @@ export { } from './reference' export { SOURCE_COMPILER_OPTIONS, SOURCE_TYPESCRIPT_VERSION } from './tsconfig' export { - type GenerateWorkspaceTypesFn, generateWorkspaceTypes, type WorkspaceManifest, - type WorkspaceManifestColumn, } from './workspace' export { WORKSPACE_COOKBOOK } from './workspace-cookbook-text.generated' export { WORKSPACE_SDK_DTS } from './workspace-text.generated' diff --git a/packages/workflow-sdk/src/codegen/reference.ts b/packages/workflow-sdk/src/codegen/reference.ts index 04518ccc1c9..cc09a1738d5 100644 --- a/packages/workflow-sdk/src/codegen/reference.ts +++ b/packages/workflow-sdk/src/codegen/reference.ts @@ -27,7 +27,7 @@ import { isLegacyBuilder } from './layout' import { builderEntry, TOOL_NAMESPACE } from './names' /** A builder as `sim workflows source params` reports it. */ -export interface BuilderReference { +interface BuilderReference { /** The dotted builder path (`slack.sendMessage`). */ key: string blockType: string @@ -71,7 +71,7 @@ interface BuilderSummary { } /** What a builder lookup found. */ -export type BuilderLookup = +type BuilderLookup = | { kind: 'builder'; reference: BuilderReference } | { kind: 'namespace'; namespace: string; builders: BuilderSummary[] } | { kind: 'core'; name: string; declaration: string } diff --git a/packages/workflow-sdk/src/codegen/workspace.ts b/packages/workflow-sdk/src/codegen/workspace.ts index 2a1582e8b5e..0f4497c8189 100644 --- a/packages/workflow-sdk/src/codegen/workspace.ts +++ b/packages/workflow-sdk/src/codegen/workspace.ts @@ -13,7 +13,7 @@ import { arrayOf, union } from './emit' import type { SdkTypeFile } from './generate' /** A table column, as the table's schema declares it (apps/sim/lib/table/column-types). */ -export interface WorkspaceManifestColumn { +interface WorkspaceManifestColumn { /** The column type id: `string`, `number`, `currency`, `boolean`, `date`, `json`, `select`, ... */ type: string /** Option names of a `select` column, as table blocks read and write them. */ @@ -88,8 +88,6 @@ export interface WorkspaceManifest { env?: string[] } -export type GenerateWorkspaceTypesFn = (manifest: WorkspaceManifest) => SdkTypeFile - /** The `@sim/workflow-sdk` types `workspace.d.ts` may name, in import order. */ const SDK_TYPES = ['Json', 'SimFile'] as const /** The `@sim/workflow-sdk/workspace` helpers `workspace.d.ts` may name, in import order. */ @@ -192,7 +190,7 @@ function declarationModules(manifest: WorkspaceManifest): WorkspaceDeclarationMo } /** Generates `workspace.d.ts`. Deterministic: keys are sorted. */ -export const generateWorkspaceTypes: GenerateWorkspaceTypesFn = (manifest) => { +export function generateWorkspaceTypes(manifest: WorkspaceManifest): SdkTypeFile { const used: UsedNames = { sdk: new Set(), workspace: new Set() } const declared = [...new Set(manifest.tableDeclarations ?? [])].sort(compareStrings) const declaredTables = declared.map(