Skip to content

Commit 10d2938

Browse files
committed
Harmonize param types
1 parent f5261a8 commit 10d2938

27 files changed

+48
-344
lines changed

packages/core/src/DiagramBuilder.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Diagram } from './Diagram';
2-
import { Param, ParamValue, StringableInputValue } from './Param';
2+
import { Param, ParamInput, StringableInputValue } from './Param';
33
import { Computer } from './types/Computer';
44
import { Node } from './types/Node';
55
import { NodeDescription } from './types/NodeDescription';
@@ -9,9 +9,9 @@ import { isStringableParam } from './utils/isStringableParam';
99
// type ParamConfig = Record<string, ParamValue> | Partial<Param>
1010
type ParamConfig = {
1111
[paramName: string]: (
12-
| ParamValue
12+
| ParamInput
1313
| Partial<Param>
14-
| Record<string, ParamValue & Partial<Param>>
14+
| Record<string, ParamInput & Partial<Param>>
1515
| any // TODO ¯\_(ツ)_/¯
1616
)
1717
}
@@ -41,10 +41,10 @@ export class DiagramBuilder {
4141
id: nodeId,
4242
label: name,
4343
name: name,
44-
// The inputs have not yet been assigned ids, to it here
44+
// The inputs have not yet been assigned ids, do it here
4545
inputs: diagram.inputNodes().map(inputNode => {
46-
const param = inputNode.params.find(param => param.name === 'port_name');
47-
const inputName = isStringableParam(param?.type) ? (param?.input as StringableInputValue).rawValue : param?.input as string
46+
const param = inputNode.params.find(param => param.name === 'port_name')!;
47+
const inputName = param?.input.rawValue
4848

4949
return {
5050
name: inputName,
@@ -54,8 +54,8 @@ export class DiagramBuilder {
5454
}),
5555
// The outputs have not yet been assigned ids, to it here
5656
outputs: diagram.outputNodes().map(outputNode => {
57-
const param = outputNode.params.find(param => param.name === 'port_name');
58-
const outputName = isStringableParam(param?.type) ? (param?.input as StringableInputValue).rawValue : param?.input as string
57+
const param = outputNode.params.find(param => param.name === 'port_name')!;
58+
const outputName = param?.input.rawValue
5959

6060
return {
6161
name: outputName,

packages/core/src/ItemWithParams/ItemWithParams.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ItemValue } from '../types/ItemValue';
2-
import { Param, ParamValue } from '../Param';
2+
import { Param, EvaluatedParamValue } from '../Param';
33
import { ParamEvaluator } from './ParamEvaluator';
44

55
export const isItemWithParams = (item: ItemWithParams | unknown): item is ItemWithParams => {
@@ -21,7 +21,7 @@ export const isItemWithParams = (item: ItemWithParams | unknown): item is ItemWi
2121
export class ItemWithParams<ExpectedType extends ItemValue = ItemValue> {
2222
type = 'ItemWithParams' as const
2323
value: ExpectedType;
24-
params: Record<string, ParamValue>;
24+
params: Record<string, EvaluatedParamValue>;
2525

2626
constructor(
2727
value: ExpectedType,

packages/core/src/ItemWithParams/ParamEvaluator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class ParamEvaluator implements ParamsValueEvaluator<any>{
1212
return this.evaluators.some(e => e.canEvaluate(param));
1313
}
1414

15-
evaluate(itemValue: ItemValue, param: Param, globalParams: Param[]) {
15+
evaluate(itemValue: ItemValue, param: Param, globalParams: Param[]): any {
1616
const evaluator = this.evaluators.find(e => e.canEvaluate(param));
1717
if(!evaluator) return param.input;
1818

packages/core/src/ItemWithParams/StringableParamEvaluator.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Param, StringableParam } from '../Param';
22
import { ItemValue } from '../types/ItemValue';
3-
import { evalMath } from '../utils/evalMath';
43
import { get } from '../utils/get';
54
import { ParamsValueEvaluator } from '../types/ParamsValueEvaluator';
65
import { ParamEvaluator } from './ParamEvaluator';
@@ -63,7 +62,6 @@ export class StringableParamEvaluator implements ParamsValueEvaluator<Stringable
6362
const args = expression.split(',').map(arg => arg.trim());
6463

6564
const functions: Record<string, Function> = {
66-
evalMath: (expression: string) => evalMath(expression),
6765
env: (expression: string) => {
6866
if (typeof process === 'undefined') throw new Error('env() is not available in the browser');
6967

packages/core/src/NodeDescriptionFactory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const NodeDescriptionFactory = {
2525
.map(node => {
2626
//@ts-ignore
2727
const portParam = node.params
28-
.find(param => param.name === 'port_name')! as StringableInputValue
28+
.find(param => param.name === 'port_name')!
2929

3030
const portName = portParam.input.rawValue;
3131

@@ -39,7 +39,7 @@ export const NodeDescriptionFactory = {
3939
.map(node => {
4040
//@ts-ignore
4141
const portParam = node.params
42-
.find(param => param.name === 'port_name')! as StringableInputValue
42+
.find(param => param.name === 'port_name')!
4343

4444
const portName = portParam.input.rawValue;
4545

packages/core/src/Param/Param.ts

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { jsExpressionEvaluation } from './evaluations/jsExpressionEvaluation'
77
import { jsFunctionEvaluation } from './evaluations/jsFunctionEvaluation'
88
import { jsonEvaluation } from './evaluations/jsonEvaluation'
99

10-
export interface StringableInputValue extends Record<string, any> {
11-
rawValue: any,
10+
export interface StringableInputValue {
11+
rawValue: string,
1212
Evaluation?: string,
1313
Cast?: string,
1414
}
@@ -27,32 +27,15 @@ export type StringableParam = {
2727
input: StringableInputValue,
2828
}
2929

30-
export type PortSelectionParam = {
31-
name: string,
32-
label: string,
33-
help: string,
34-
type: 'PortSelectionParam',
35-
allowCreate: boolean,
36-
input: string
37-
}
30+
export type ParamId = string
3831

39-
/**
40-
* This type can represent ["a", "b", "c"] using 'a, b, c', which facilitates user input
41-
* */
42-
export type StringListParam = {
43-
name: string,
44-
label: string,
45-
help: string,
46-
type: 'StringListParam',
47-
input: unknown
48-
}
32+
export type Param = StringableParam;
33+
34+
export type ParamInput = Param['input']
4935

50-
export type Param =
51-
StringableParam |
52-
PortSelectionParam |
53-
StringListParam;
36+
export type EvaluatedParamValue = any
5437

55-
export type ParamValue = Param['input']
38+
export type StaticEvaluatedParamValue = any
5639

5740
export const str = ({
5841
name,
@@ -124,7 +107,7 @@ export const num = ({
124107
numberCast,
125108
],
126109
input: {
127-
rawValue: value ?? 0,
110+
rawValue: String(value ?? 0),
128111
Cast: numberCast.type,
129112
},
130113
}
@@ -167,7 +150,7 @@ export const json_ = ({
167150
stringCast,
168151
],
169152
input: {
170-
rawValue: value ?? 0,
153+
rawValue: String(value ?? 0),
171154
Evaluation: jsonEvaluation.type,
172155
},
173156
}
@@ -210,7 +193,7 @@ export const jsFn = ({
210193
stringCast,
211194
],
212195
input: {
213-
rawValue: value ?? 0,
196+
rawValue: String(value ?? 0),
214197
Evaluation: jsFunctionEvaluation.type,
215198
},
216199
}
@@ -253,7 +236,7 @@ export const jsExpression = ({
253236
stringCast,
254237
],
255238
input: {
256-
rawValue: value ?? 0,
239+
rawValue: String(value ?? 0),
257240
Evaluation: jsExpressionEvaluation.type,
258241
},
259242
}

packages/core/src/UnfoldedDiagramFactory.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export class UnfoldedDiagramFactory {
6868
if(!isInputNode) return false;
6969

7070
const param = node.params[0];
71-
const portName: string = isStringableParam(param?.type) ? (param?.input as StringableInputValue).rawValue : param?.input;
71+
const portName: string = isStringableParam(param?.type)
72+
? (param?.input as StringableInputValue).rawValue
73+
: param?.input.rawValue;
7274
if(!portName) throw new Error(`No port name found for input node "${node.id}". The node was ${JSON.stringify(node)}`)
7375

7476
const matchesPortName = portName === inputPort.name;
@@ -95,7 +97,9 @@ export class UnfoldedDiagramFactory {
9597
if(!isOutputNode) return false;
9698

9799
const param = node.params[0];
98-
const portName: string = isStringableParam(param?.type) ? (param?.input as StringableInputValue).rawValue : param?.input;
100+
const portName: string = isStringableParam(param?.type)
101+
? (param?.input as StringableInputValue).rawValue
102+
: param?.input.rawValue;
99103
if(!portName) throw new Error(`No port name found for output node "${node.id}. The node was ${JSON.stringify(node)}"`)
100104

101105
const matchesPortName = portName === outputPort.name

packages/core/src/computers/Await.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const Await: Computer = {
3737
canRun({ input, params, isAvailable }) {
3838
const haveChunk = input.haveItemsAtInput(
3939
'input',
40-
(params.number_of_items.input as StringableInputValue).rawValue as number,
40+
Number(params.number_of_items.input.rawValue),
4141
)
4242

4343
const haveRemainder = input.haveAllItemsAtInput('input')

packages/core/src/computers/MakeSet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const MakeSet: Computer = {
3030
const items = input.pull(BatchLimit);
3131

3232
for (let item of items) {
33-
const property = params.property as string;
33+
const property = params.property;
3434
const value = item.value[property];
3535

3636
if (!seen.has(value)) {

packages/core/src/computers/Throw.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ export const Throw: Computer = {
3232

3333
async *run({ input, node }) {
3434
const [item] = input.pull(1)
35+
const fuck = item.params.message
3536
throw new NodeRunError({
36-
message: item.params.message as string,
37+
message: item.params.message,
3738
node,
3839
})
3940
},

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export { createDataStoryId } from './utils/createDataStoryId'
1111
export type { NodeDescription, NodeDescriptionRequest, NodeDescriptionResponse } from './types/NodeDescription'
1212
export { NodeDescriptionResponseSchema, NodeDescriptionRequestSchema } from './types/NodeDescription';
1313
export type { Port, AbstractPort } from './types/Port'
14-
export type { Param, ParamValue } from './Param'
14+
export type { Param, ParamInput as ParamValue } from './Param'
1515
export { Application } from './Application'
1616
export type { ServiceProvider } from './types/ServiceProvider'
1717
export { DiagramBuilder } from './DiagramBuilder'
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { Param } from '../Param';
2-
3-
type ParamId = string
1+
import { ParamId, StaticEvaluatedParamValue } from '../Param';
42

53
export type ParamsDevice = {
6-
[key: ParamId]: Param['input'],
4+
[key: ParamId]: StaticEvaluatedParamValue,
75
};

packages/core/src/utils/evalMath.test.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/core/src/utils/evalMath.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/hubspot/src/crm/entity/archive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const archive = (name: string) => {
6868
}
6969

7070
const entityParam = config.params!.find((p) => p.name === 'entity')
71-
entityParam!.input = name.toLowerCase()
71+
entityParam!.input.rawValue = name.toLowerCase()
7272

7373
return config
7474
}

packages/hubspot/src/crm/entity/batchArchive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const batchArchive = (name: string) => {
6666
}
6767

6868
const entityParam = config.params!.find((p) => p.name === 'entity')
69-
entityParam!.input = name.toLowerCase()
69+
entityParam!.input.rawValue = name.toLowerCase()
7070

7171
return config
7272
}

packages/hubspot/src/crm/entity/batchCreate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const batchCreate = (name: string) => {
6666
}
6767

6868
const entityParam = config.params!.find((p) => p.name === 'entity')
69-
entityParam!.input = name.toLowerCase()
69+
entityParam!.input.rawValue = name.toLowerCase()
7070

7171
return config
7272
}

packages/hubspot/src/crm/entity/batchUpdate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const batchUpdate = (name: string) => {
6666
}
6767

6868
const entityParam = config.params!.find((p) => p.name === 'entity')
69-
entityParam!.input = name.toLowerCase()
69+
entityParam!.input.rawValue = name.toLowerCase()
7070

7171
return config
7272
}

packages/hubspot/src/crm/entity/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const create = (name: string) => {
6666
}
6767

6868
const entityParam = config.params!.find((p) => p.name === 'entity')
69-
entityParam!.input = name.toLowerCase()
69+
entityParam!.input.rawValue = name.toLowerCase()
7070

7171
return config
7272
}

packages/hubspot/src/crm/entity/getAll.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const getAll = (name: string) => {
9797
}
9898

9999
const entityParam = config.params!.find((p) => p.name === 'entity')
100-
entityParam!.input = name.toLowerCase()
100+
entityParam!.input.rawValue = name.toLowerCase()
101101

102102
return config
103103
}

packages/hubspot/src/crm/entity/update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const update = (name: string) => {
6666
}
6767

6868
const entityParam = config.params!.find((p) => p.name === 'entity')
69-
entityParam!.input = name.toLowerCase()
69+
entityParam!.input.rawValue = name.toLowerCase()
7070

7171
return config
7272
}

0 commit comments

Comments
 (0)