@kemu-io/edge-runtime 1.5.0 → 1.7.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.
Files changed (3) hide show
  1. package/package.json +2 -1
  2. package/runner.d.ts +113 -84
  3. package/runner.js +4 -4
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kemu-io/edge-runtime",
3
3
  "type": "module",
4
- "version": "1.5.0",
4
+ "version": "1.7.0",
5
5
  "description": "Kemu Edge runtime for running Kemu recipes",
6
6
  "author": "Kemu Pty Ltd",
7
7
  "main": "runner.js",
@@ -31,6 +31,7 @@
31
31
  "axios": "^1.7.2",
32
32
  "compare-versions": "^6.1.0",
33
33
  "crypto-js": "^4.2.0",
34
+ "expr-eval": "^2.0.2",
34
35
  "jsonp": "^0.2.1",
35
36
  "jszip": "^3.10.1",
36
37
  "microseconds": "^0.2.0",
package/runner.d.ts CHANGED
@@ -72,84 +72,64 @@ export type Data = {
72
72
  timestamp: number;
73
73
  };
74
74
  export type PartialData = Omit<Data, "timestamp">;
75
- declare enum WidgetType {
76
- input = "input",
77
- counter = "counter",
78
- play = "play",
79
- elapsed = "elapsed",
80
- ifGate = "ifGate",
81
- skipEvent = "skipEvent",
82
- between = "between",
83
- map = "map",
84
- parser = "parser",
85
- slider = "slider",
86
- suspend = "suspend",
87
- display = "display",
88
- json = "json",
89
- arrayItem = "arrayItem",
90
- extractImage = "extractImage",
91
- imageConvolution = "imageConvolution",
92
- firstEvent = "firstEvent",
93
- pixelDraw = "pixelDraw",
94
- randomBetween = "randomBetween",
95
- arrayCombine = "arrayCombine",
96
- clock = "clock",
97
- multiplication = "multiplication",
98
- object = "object",
99
- widgetGroup = "widgetGroup",
100
- script = "script",
101
- base64ToImageData = "base64ToImageData",
102
- jsonParse = "jsonParse",
103
- text = "text",
104
- imageCrop = "imageCrop",
105
- imageResize = "imageResize",
106
- value = "value",
107
- imageWarp = "imageWarp",
108
- sequence = "sequence",
109
- variable = "variable",
110
- hubService = "hubService",
111
- imageFilter = "imageFilter",
112
- recipeLoad = "recipeLoad",
113
- note = "note",
114
- stringify = "stringify",
115
- templateString = "templateString",
116
- expressionEval = "expressionEval",
117
- rescue = "rescue",
118
- objectCombine = "objectCombine",
119
- loop = "loop",
120
- status = "status",
121
- secret = "secret",
122
- output = "output"
123
- }
124
- export type VariableDefinition = {
125
- /**
126
- * the type of widget that created the variable, this in
127
- * order to speed up scope resolution of the variable when accessed.
128
- **/
129
- ownerType: WidgetType;
130
- /**
131
- * The data type held by the variable.
132
- */
133
- type: DataType;
134
- /**
135
- * indicates if its value should be stored as part of the recipe
136
- * when the recipe is saved
137
- **/
138
- storeValueInRecipe: boolean;
139
- /** the id of the widget that registered the variable */
140
- createdByWidgetId: string;
141
- /** indicates if the variable is a reference to a widget's UI element */
142
- isUIElement: boolean;
143
- /** the current value of the variable */
144
- value?: SupportedTypes;
75
+ export type ExecutionContext = {
76
+ currentPath: string[];
77
+ eventId: number;
78
+ };
79
+ export type GlobalVariableControlType = "number" | "slider" | "text" | "multilineText" | "dropdown" | "image" | "binaryFile" | "checkbox" | "multiSelect" | "anything";
80
+ export type GlobalVariable<T = any> = {
81
+ name: string;
82
+ controlType: GlobalVariableControlType;
83
+ lastDataType: DataType | null;
84
+ lastValue: SupportedTypes | null;
85
+ lastChangedByWidgetId: string | null;
86
+ lastExecutionContext: ExecutionContext | null;
87
+ controlSettings: T;
88
+ /** help text in plain text or markdown format */
89
+ helpText?: string;
90
+ order?: number;
91
+ };
92
+ /**
93
+ * Handler function type for edge function callbacks
94
+ * @param functionParams - Custom configuration parameters for the function
95
+ * @param eventId - Unique event identifier
96
+ * @returns Promise resolving to a SupportedType value
97
+ */
98
+ export type EdgeFunctionHandler = (functionParams: any, eventId: number) => Promise<SupportedTypes>;
99
+ declare const _default: {
100
+ registerFunctionHandler: (functionName: string, handler: EdgeFunctionHandler) => void;
101
+ invokeFunction: (config: {
102
+ eventId: number;
103
+ functionName: string;
104
+ functionParams: any;
105
+ }) => Promise<SupportedTypes | null | void>;
106
+ unregisterFunctionHandler: (functionName: string) => void;
107
+ clearAllHandlers: () => void;
145
108
  };
146
- export type VarValueChangeEvt = Readonly<Pick<VariableDefinition, "type" | "value" | "isUIElement"> & {
147
- varName: string;
148
- setByWidgetType: WidgetType;
149
- setByWidgetId: string;
150
- }>;
151
109
  export type SendToInputWidgetFn = (inputName: string, data: PartialData | number | string | boolean | Array<any>) => Promise<void>;
152
110
  export type SendToInputWidgetAndWaitForOutputFn = <T = any>(inputName: string, data: PartialData | number | string | boolean | Array<any>) => Promise<T>;
111
+ declare const onGlobalVariableChange: (varName: string | "*", cb: (config: GlobalVariable) => void) => import("emittery").UnsubscribeFunction;
112
+ declare const setGlobalVariable: (varName: string, value: SupportedTypes, config?: {
113
+ /** whether to disable change notifications for this variable */
114
+ disableChangeNotifications?: boolean;
115
+ /** whether to disable define notifications for this variable */
116
+ disableDefineNotifications?: boolean;
117
+ /** whether to not override an existing variable with the same name */
118
+ doNotOverrideExisting?: boolean;
119
+ }) => Promise<void>;
120
+ declare const deleteGlobalVariable: (varName: string) => void;
121
+ declare const getAllGlobalVariables: () => GlobalVariable<any>[];
122
+ declare const getGlobalVariable: (varName: string) => GlobalVariable | null;
123
+ declare const onStatusValueChange: (cb: (config: {
124
+ /** the name of the status */
125
+ name: string;
126
+ /** the value of the status */
127
+ value: PartialData;
128
+ /** the id of the parent widget setting the status value */
129
+ sourceWidget: string;
130
+ /** the id of the status widget being set */
131
+ statusWidgetId: string;
132
+ }) => void) => import("emittery").UnsubscribeFunction;
153
133
  export declare const utils: {
154
134
  /**
155
135
  * Builds an object that represents an ImageData type. This is useful when services
@@ -171,7 +151,7 @@ export declare const utils: {
171
151
  */
172
152
  encodeImageData: (imageData: ImageData$1, format?: "png" | "jpeg" | "webp", quality?: number) => Promise<Buffer>;
173
153
  };
174
- declare const _default: {
154
+ declare const _default$1: {
175
155
  start: (config?: {
176
156
  /**
177
157
  * path to the recipe file or containing directory.
@@ -209,19 +189,68 @@ declare const _default: {
209
189
  * @returns the response from the input widget.
210
190
  */
211
191
  sendToInputWidgetAndWaitForOutput: SendToInputWidgetAndWaitForOutputFn;
192
+ /**
193
+ * Manage global variables in your recipe.
194
+ */
195
+ globalVariables: {
196
+ /**
197
+ * Sets a listener to changes in the value of a variable.
198
+ * @param varName the name of the variable to listen to.
199
+ * @param cb the callback function to be invoked.
200
+ * @returns a function to remove the listener.
201
+ */
202
+ onChange: typeof onGlobalVariableChange;
203
+ /**
204
+ * Sets the value of a global variable.
205
+ * @param varName the name of the variable to set.
206
+ * @param value the value to set.
207
+ */
208
+ setValue: typeof setGlobalVariable;
209
+ /**
210
+ * Retrieves a global variable.
211
+ * @param varName the name of the variable to retrieve.
212
+ * @returns the global variable or null if it does not exist.
213
+ */
214
+ getValue: typeof getGlobalVariable;
215
+ /**
216
+ * Removes a global variable.
217
+ * @param varName the name of the variable to delete.
218
+ */
219
+ delete: typeof deleteGlobalVariable;
220
+ /**
221
+ * Retrieves all global variables.
222
+ * @returns all global variables.
223
+ */
224
+ getAll: typeof getAllGlobalVariables;
225
+ };
226
+ /**
227
+ * Access status set by Status widgets.
228
+ */
229
+ status: {
230
+ /**
231
+ * Sets a listener to changes in the value of a status.
232
+ * @param cb the callback function to be invoked.
233
+ * @returns a function to remove the listener.
234
+ */
235
+ onChange: typeof onStatusValueChange;
236
+ };
237
+ /**
238
+ * Manage edge functions in your recipe.
239
+ */
240
+ edgeFunctions: {
241
+ /** Registers a function handler for an edge function */
242
+ register: (typeof _default)["registerFunctionHandler"];
243
+ /** Unregisters a function handler for an edge function */
244
+ unregister: (typeof _default)["unregisterFunctionHandler"];
245
+ /** Clears all registered function handlers */
246
+ clearAll: (typeof _default)["clearAllHandlers"];
247
+ };
212
248
  }>;
213
249
  terminate: () => Promise<void>;
214
- /**
215
- * Sets a listener to changes in the value of a variable.
216
- * @param varName the name of the variable to listen to.
217
- * @param cb the callback function to be invoked.
218
- * @returns a function to remove the listener.
219
- */
220
- onVariableChange: (varName: string, cb: (evt: Omit<VarValueChangeEvt, "isUIElement">) => void | Promise<void>) => () => void;
221
250
  };
222
251
 
223
252
  export {
224
- _default as default,
253
+ _default$1 as default,
225
254
  };
226
255
 
227
256
  export {};