@codemation/core-nodes 0.2.0 → 0.3.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/dist/index.d.cts CHANGED
@@ -1695,12 +1695,13 @@ interface WorkflowAgentOptions<TCurrentJson, TOutputSchema extends z.ZodTypeAny
1695
1695
  }
1696
1696
  //#endregion
1697
1697
  //#region src/workflowAuthoring/WorkflowBranchBuilder.types.d.ts
1698
+ type WorkflowMapCallback$1<TCurrentJson, TNextJson$1> = (item: Item<TCurrentJson>, ctx: NodeExecutionContext<MapData<TCurrentJson, TNextJson$1>>) => TNextJson$1;
1698
1699
  declare class WorkflowBranchBuilder<TCurrentJson> {
1699
1700
  private readonly steps;
1700
1701
  constructor(steps?: ReadonlyArray<AnyRunnableNodeConfig>);
1701
1702
  then<TOutputJson$1, TConfig extends RunnableNodeConfig<TCurrentJson, TOutputJson$1>>(config: TConfig): WorkflowBranchBuilder<RunnableNodeOutputJson<TConfig>>;
1702
- map<TNextJson$1>(mapper: (item: TCurrentJson) => TNextJson$1): WorkflowBranchBuilder<TNextJson$1>;
1703
- map<TNextJson$1>(name: string, mapper: (item: TCurrentJson) => TNextJson$1, options?: MapDataOptions): WorkflowBranchBuilder<TNextJson$1>;
1703
+ map<TNextJson$1>(mapper: WorkflowMapCallback$1<TCurrentJson, TNextJson$1>): WorkflowBranchBuilder<TNextJson$1>;
1704
+ map<TNextJson$1>(name: string, mapper: WorkflowMapCallback$1<TCurrentJson, TNextJson$1>, options?: MapDataOptions): WorkflowBranchBuilder<TNextJson$1>;
1704
1705
  wait(duration: number | string): WorkflowBranchBuilder<TCurrentJson>;
1705
1706
  wait(name: string, duration: number | string, id?: string): WorkflowBranchBuilder<TCurrentJson>;
1706
1707
  split<TElem>(getElements: (item: Item<TCurrentJson>, ctx: NodeExecutionContext<Split<TCurrentJson, TElem>>) => readonly TElem[]): WorkflowBranchBuilder<TElem>;
@@ -1719,12 +1720,15 @@ declare class WorkflowBranchBuilder<TCurrentJson> {
1719
1720
  //#region src/workflowAuthoring/WorkflowChain.types.d.ts
1720
1721
  type BranchCallback<TCurrentJson, TNextJson$1> = (branch: WorkflowBranchBuilder<TCurrentJson>) => WorkflowBranchBuilder<TNextJson$1>;
1721
1722
  type RouteBranchCallback<TCurrentJson, TNextJson$1> = (branch: WorkflowChain<TCurrentJson>) => WorkflowChain<TNextJson$1>;
1723
+ type WorkflowMapCallback<TCurrentJson, TNextJson$1> = (item: Item<TCurrentJson>, ctx: NodeExecutionContext<MapData<TCurrentJson, TNextJson$1>>) => TNextJson$1;
1724
+ type WorkflowIfPredicate<TCurrentJson> = (item: Item<TCurrentJson>, ctx: NodeExecutionContext<If<TCurrentJson>>) => boolean;
1725
+ type WorkflowSwitchCaseKeyResolver<TCurrentJson> = (item: Item<TCurrentJson>, ctx: NodeExecutionContext<Switch<TCurrentJson>>) => string | Promise<string>;
1722
1726
  declare class WorkflowChain<TCurrentJson> {
1723
1727
  private readonly chain;
1724
1728
  constructor(chain: ChainCursor<TCurrentJson>);
1725
1729
  then<TOutputJson$1, TConfig extends RunnableNodeConfig<TCurrentJson, TOutputJson$1>>(config: TConfig): WorkflowChain<RunnableNodeOutputJson<TConfig>>;
1726
- map<TNextJson$1>(mapper: (item: TCurrentJson) => TNextJson$1): WorkflowChain<TNextJson$1>;
1727
- map<TNextJson$1>(name: string, mapper: (item: TCurrentJson) => TNextJson$1, options?: MapDataOptions): WorkflowChain<TNextJson$1>;
1730
+ map<TNextJson$1>(mapper: WorkflowMapCallback<TCurrentJson, TNextJson$1>): WorkflowChain<TNextJson$1>;
1731
+ map<TNextJson$1>(name: string, mapper: WorkflowMapCallback<TCurrentJson, TNextJson$1>, options?: MapDataOptions): WorkflowChain<TNextJson$1>;
1728
1732
  wait(duration: number | string): WorkflowChain<TCurrentJson>;
1729
1733
  wait(name: string, duration: number | string, id?: string): WorkflowChain<TCurrentJson>;
1730
1734
  split<TElem>(getElements: (item: Item<TCurrentJson>, ctx: NodeExecutionContext<Split<TCurrentJson, TElem>>) => readonly TElem[]): WorkflowChain<TElem>;
@@ -1742,11 +1746,11 @@ declare class WorkflowChain<TCurrentJson> {
1742
1746
  mode: MergeMode;
1743
1747
  prefer?: ReadonlyArray<string>;
1744
1748
  }>, id?: string): WorkflowChain<TCurrentJson>;
1745
- if<TBranchJson>(predicate: (item: TCurrentJson) => boolean, branches: Readonly<{
1749
+ if<TBranchJson>(predicate: WorkflowIfPredicate<TCurrentJson>, branches: Readonly<{
1746
1750
  true?: BranchCallback<TCurrentJson, TBranchJson>;
1747
1751
  false?: BranchCallback<TCurrentJson, TBranchJson>;
1748
1752
  }>): WorkflowChain<TBranchJson>;
1749
- if<TBranchJson>(name: string, predicate: (item: TCurrentJson) => boolean, branches: Readonly<{
1753
+ if<TBranchJson>(name: string, predicate: WorkflowIfPredicate<TCurrentJson>, branches: Readonly<{
1750
1754
  true?: BranchCallback<TCurrentJson, TBranchJson>;
1751
1755
  false?: BranchCallback<TCurrentJson, TBranchJson>;
1752
1756
  }>): WorkflowChain<TBranchJson>;
@@ -1754,13 +1758,13 @@ declare class WorkflowChain<TCurrentJson> {
1754
1758
  switch<TBranchJson>(cfg: Readonly<{
1755
1759
  cases: readonly string[];
1756
1760
  defaultCase: string;
1757
- resolveCaseKey: (item: TCurrentJson) => string | Promise<string>;
1761
+ resolveCaseKey: WorkflowSwitchCaseKeyResolver<TCurrentJson>;
1758
1762
  branches: Readonly<Record<string, RouteBranchCallback<TCurrentJson, TBranchJson> | undefined>>;
1759
1763
  }>): WorkflowChain<TBranchJson>;
1760
1764
  switch<TBranchJson>(name: string, cfg: Readonly<{
1761
1765
  cases: readonly string[];
1762
1766
  defaultCase: string;
1763
- resolveCaseKey: (item: TCurrentJson) => string | Promise<string>;
1767
+ resolveCaseKey: WorkflowSwitchCaseKeyResolver<TCurrentJson>;
1764
1768
  branches: Readonly<Record<string, RouteBranchCallback<TCurrentJson, TBranchJson> | undefined>>;
1765
1769
  }>, id?: string): WorkflowChain<TBranchJson>;
1766
1770
  agent<TOutputSchema extends z.ZodTypeAny>(options: WorkflowAgentOptions<TCurrentJson, TOutputSchema>): WorkflowChain<z.output<TOutputSchema>>;
package/dist/index.d.ts CHANGED
@@ -1695,12 +1695,13 @@ interface WorkflowAgentOptions<TCurrentJson, TOutputSchema extends z.ZodTypeAny
1695
1695
  }
1696
1696
  //#endregion
1697
1697
  //#region src/workflowAuthoring/WorkflowBranchBuilder.types.d.ts
1698
+ type WorkflowMapCallback$1<TCurrentJson, TNextJson$1> = (item: Item<TCurrentJson>, ctx: NodeExecutionContext<MapData<TCurrentJson, TNextJson$1>>) => TNextJson$1;
1698
1699
  declare class WorkflowBranchBuilder<TCurrentJson> {
1699
1700
  private readonly steps;
1700
1701
  constructor(steps?: ReadonlyArray<AnyRunnableNodeConfig>);
1701
1702
  then<TOutputJson$1, TConfig extends RunnableNodeConfig<TCurrentJson, TOutputJson$1>>(config: TConfig): WorkflowBranchBuilder<RunnableNodeOutputJson<TConfig>>;
1702
- map<TNextJson$1>(mapper: (item: TCurrentJson) => TNextJson$1): WorkflowBranchBuilder<TNextJson$1>;
1703
- map<TNextJson$1>(name: string, mapper: (item: TCurrentJson) => TNextJson$1, options?: MapDataOptions): WorkflowBranchBuilder<TNextJson$1>;
1703
+ map<TNextJson$1>(mapper: WorkflowMapCallback$1<TCurrentJson, TNextJson$1>): WorkflowBranchBuilder<TNextJson$1>;
1704
+ map<TNextJson$1>(name: string, mapper: WorkflowMapCallback$1<TCurrentJson, TNextJson$1>, options?: MapDataOptions): WorkflowBranchBuilder<TNextJson$1>;
1704
1705
  wait(duration: number | string): WorkflowBranchBuilder<TCurrentJson>;
1705
1706
  wait(name: string, duration: number | string, id?: string): WorkflowBranchBuilder<TCurrentJson>;
1706
1707
  split<TElem>(getElements: (item: Item<TCurrentJson>, ctx: NodeExecutionContext<Split<TCurrentJson, TElem>>) => readonly TElem[]): WorkflowBranchBuilder<TElem>;
@@ -1719,12 +1720,15 @@ declare class WorkflowBranchBuilder<TCurrentJson> {
1719
1720
  //#region src/workflowAuthoring/WorkflowChain.types.d.ts
1720
1721
  type BranchCallback<TCurrentJson, TNextJson$1> = (branch: WorkflowBranchBuilder<TCurrentJson>) => WorkflowBranchBuilder<TNextJson$1>;
1721
1722
  type RouteBranchCallback<TCurrentJson, TNextJson$1> = (branch: WorkflowChain<TCurrentJson>) => WorkflowChain<TNextJson$1>;
1723
+ type WorkflowMapCallback<TCurrentJson, TNextJson$1> = (item: Item<TCurrentJson>, ctx: NodeExecutionContext<MapData<TCurrentJson, TNextJson$1>>) => TNextJson$1;
1724
+ type WorkflowIfPredicate<TCurrentJson> = (item: Item<TCurrentJson>, ctx: NodeExecutionContext<If<TCurrentJson>>) => boolean;
1725
+ type WorkflowSwitchCaseKeyResolver<TCurrentJson> = (item: Item<TCurrentJson>, ctx: NodeExecutionContext<Switch<TCurrentJson>>) => string | Promise<string>;
1722
1726
  declare class WorkflowChain<TCurrentJson> {
1723
1727
  private readonly chain;
1724
1728
  constructor(chain: ChainCursor<TCurrentJson>);
1725
1729
  then<TOutputJson$1, TConfig extends RunnableNodeConfig<TCurrentJson, TOutputJson$1>>(config: TConfig): WorkflowChain<RunnableNodeOutputJson<TConfig>>;
1726
- map<TNextJson$1>(mapper: (item: TCurrentJson) => TNextJson$1): WorkflowChain<TNextJson$1>;
1727
- map<TNextJson$1>(name: string, mapper: (item: TCurrentJson) => TNextJson$1, options?: MapDataOptions): WorkflowChain<TNextJson$1>;
1730
+ map<TNextJson$1>(mapper: WorkflowMapCallback<TCurrentJson, TNextJson$1>): WorkflowChain<TNextJson$1>;
1731
+ map<TNextJson$1>(name: string, mapper: WorkflowMapCallback<TCurrentJson, TNextJson$1>, options?: MapDataOptions): WorkflowChain<TNextJson$1>;
1728
1732
  wait(duration: number | string): WorkflowChain<TCurrentJson>;
1729
1733
  wait(name: string, duration: number | string, id?: string): WorkflowChain<TCurrentJson>;
1730
1734
  split<TElem>(getElements: (item: Item<TCurrentJson>, ctx: NodeExecutionContext<Split<TCurrentJson, TElem>>) => readonly TElem[]): WorkflowChain<TElem>;
@@ -1742,11 +1746,11 @@ declare class WorkflowChain<TCurrentJson> {
1742
1746
  mode: MergeMode;
1743
1747
  prefer?: ReadonlyArray<string>;
1744
1748
  }>, id?: string): WorkflowChain<TCurrentJson>;
1745
- if<TBranchJson>(predicate: (item: TCurrentJson) => boolean, branches: Readonly<{
1749
+ if<TBranchJson>(predicate: WorkflowIfPredicate<TCurrentJson>, branches: Readonly<{
1746
1750
  true?: BranchCallback<TCurrentJson, TBranchJson>;
1747
1751
  false?: BranchCallback<TCurrentJson, TBranchJson>;
1748
1752
  }>): WorkflowChain<TBranchJson>;
1749
- if<TBranchJson>(name: string, predicate: (item: TCurrentJson) => boolean, branches: Readonly<{
1753
+ if<TBranchJson>(name: string, predicate: WorkflowIfPredicate<TCurrentJson>, branches: Readonly<{
1750
1754
  true?: BranchCallback<TCurrentJson, TBranchJson>;
1751
1755
  false?: BranchCallback<TCurrentJson, TBranchJson>;
1752
1756
  }>): WorkflowChain<TBranchJson>;
@@ -1754,13 +1758,13 @@ declare class WorkflowChain<TCurrentJson> {
1754
1758
  switch<TBranchJson>(cfg: Readonly<{
1755
1759
  cases: readonly string[];
1756
1760
  defaultCase: string;
1757
- resolveCaseKey: (item: TCurrentJson) => string | Promise<string>;
1761
+ resolveCaseKey: WorkflowSwitchCaseKeyResolver<TCurrentJson>;
1758
1762
  branches: Readonly<Record<string, RouteBranchCallback<TCurrentJson, TBranchJson> | undefined>>;
1759
1763
  }>): WorkflowChain<TBranchJson>;
1760
1764
  switch<TBranchJson>(name: string, cfg: Readonly<{
1761
1765
  cases: readonly string[];
1762
1766
  defaultCase: string;
1763
- resolveCaseKey: (item: TCurrentJson) => string | Promise<string>;
1767
+ resolveCaseKey: WorkflowSwitchCaseKeyResolver<TCurrentJson>;
1764
1768
  branches: Readonly<Record<string, RouteBranchCallback<TCurrentJson, TBranchJson> | undefined>>;
1765
1769
  }>, id?: string): WorkflowChain<TBranchJson>;
1766
1770
  agent<TOutputSchema extends z.ZodTypeAny>(options: WorkflowAgentOptions<TCurrentJson, TOutputSchema>): WorkflowChain<z.output<TOutputSchema>>;
package/dist/index.js CHANGED
@@ -4028,7 +4028,7 @@ var WorkflowBranchBuilder = class WorkflowBranchBuilder {
4028
4028
  map(nameOrMapper, mapperOrUndefined, options) {
4029
4029
  const name = typeof nameOrMapper === "string" ? nameOrMapper : "Map data";
4030
4030
  const mapper = typeof nameOrMapper === "string" ? mapperOrUndefined : nameOrMapper;
4031
- return this.then(new MapData(name, (item) => mapper(item.json), options));
4031
+ return this.then(new MapData(name, mapper, options));
4032
4032
  }
4033
4033
  wait(nameOrDuration, durationOrUndefined, id) {
4034
4034
  const name = typeof nameOrDuration === "string" && durationOrUndefined !== void 0 ? nameOrDuration : "Wait";
@@ -4074,7 +4074,7 @@ var WorkflowChain = class WorkflowChain {
4074
4074
  map(nameOrMapper, mapperOrUndefined, options) {
4075
4075
  const name = typeof nameOrMapper === "string" ? nameOrMapper : "Map data";
4076
4076
  const mapper = typeof nameOrMapper === "string" ? mapperOrUndefined : nameOrMapper;
4077
- return this.then(new MapData(name, (item) => mapper(item.json), options));
4077
+ return this.then(new MapData(name, mapper, options));
4078
4078
  }
4079
4079
  wait(nameOrDuration, durationOrUndefined, id) {
4080
4080
  const name = typeof nameOrDuration === "string" && durationOrUndefined !== void 0 ? nameOrDuration : "Wait";
@@ -4106,7 +4106,7 @@ var WorkflowChain = class WorkflowChain {
4106
4106
  const name = typeof nameOrPredicate === "string" ? nameOrPredicate : "If";
4107
4107
  const predicate = typeof nameOrPredicate === "string" ? predicateOrBranches : nameOrPredicate;
4108
4108
  const branches = typeof nameOrPredicate === "string" ? branchesOrUndefined : predicateOrBranches;
4109
- const cursor = this.chain.then(new If(name, (item) => predicate(item.json)));
4109
+ const cursor = this.chain.then(new If(name, (item, _index, _items, ctx) => predicate(item, ctx)));
4110
4110
  const trueSteps = branches.true?.(new WorkflowBranchBuilder()).getSteps();
4111
4111
  const falseSteps = branches.false?.(new WorkflowBranchBuilder()).getSteps();
4112
4112
  return new WorkflowChain(cursor.when({
@@ -4124,7 +4124,7 @@ var WorkflowChain = class WorkflowChain {
4124
4124
  return this.then(new Switch(name, {
4125
4125
  cases: cfg.cases,
4126
4126
  defaultCase: cfg.defaultCase,
4127
- resolveCaseKey: (item) => cfg.resolveCaseKey(item.json)
4127
+ resolveCaseKey: (item, _index, _items, ctx) => cfg.resolveCaseKey(item, ctx)
4128
4128
  }, id)).route(cfg.branches);
4129
4129
  }
4130
4130
  agent(nameOrOptions, optionsOrUndefined) {