windmill-components 1.138.4 → 1.138.6
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/package/components/FlowGraphViewer.svelte +1 -1
- package/package/components/InputTransformForm.svelte +2 -2
- package/package/components/InputTransformsViewer.svelte +2 -2
- package/package/components/LightweightArgInput.svelte +8 -6
- package/package/components/LightweightObjectResourceInput.svelte +38 -0
- package/package/components/LightweightObjectResourceInput.svelte.d.ts +18 -0
- package/package/components/LightweightResourcePicker.svelte +78 -0
- package/package/components/LightweightResourcePicker.svelte.d.ts +21 -0
- package/package/components/apps/components/display/AppText.svelte +2 -3
- package/package/components/apps/components/helpers/InputValue.svelte +2 -2
- package/package/components/flows/utils.d.ts +0 -2
- package/package/components/flows/utils.js +4 -17
- package/package/infer.d.ts +1 -0
- package/package/infer.js +39 -1
- package/package/scripts.d.ts +0 -1
- package/package/scripts.js +2 -41
- package/package/utils.d.ts +2 -0
- package/package/utils.js +13 -0
- package/package.json +1 -1
|
@@ -6,10 +6,10 @@ import { Badge, Button, Drawer, DrawerContent } from './common';
|
|
|
6
6
|
import { Highlight } from 'svelte-highlight';
|
|
7
7
|
import ObjectViewer from './propertyPicker/ObjectViewer.svelte';
|
|
8
8
|
import typescript from 'svelte-highlight/languages/typescript';
|
|
9
|
-
import { cleanExpr } from './flows/utils';
|
|
10
9
|
import FlowPathViewer from './flows/content/FlowPathViewer.svelte';
|
|
11
10
|
import SchemaViewer from './SchemaViewer.svelte';
|
|
12
11
|
import { scriptPathToHref } from '../scripts';
|
|
12
|
+
import { cleanExpr } from '../utils';
|
|
13
13
|
export let flow;
|
|
14
14
|
export let overflowAuto = false;
|
|
15
15
|
export let noSide = false;
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import ArgInput from './ArgInput.svelte';
|
|
3
3
|
import FieldHeader from './FieldHeader.svelte';
|
|
4
4
|
import DynamicInputHelpBox from './flows/content/DynamicInputHelpBox.svelte';
|
|
5
|
-
import { codeToStaticTemplate, getDefaultExpr
|
|
5
|
+
import { codeToStaticTemplate, getDefaultExpr } from './flows/utils';
|
|
6
6
|
import SimpleEditor from './SimpleEditor.svelte';
|
|
7
7
|
import { Button } from './common';
|
|
8
8
|
import ToggleButtonGroup from './common/toggleButton-v2/ToggleButtonGroup.svelte';
|
|
9
9
|
import ToggleButton from './common/toggleButton-v2/ToggleButton.svelte';
|
|
10
10
|
import { ResourceService } from '../gen';
|
|
11
11
|
import TemplateEditor from './TemplateEditor.svelte';
|
|
12
|
-
import { setInputCat as computeInputCat } from '../utils';
|
|
12
|
+
import { setInputCat as computeInputCat, isCodeInjection } from '../utils';
|
|
13
13
|
import { Code, Plug } from 'lucide-svelte';
|
|
14
14
|
import { workspaceStore } from '../stores';
|
|
15
15
|
export let schema;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
<script>import
|
|
2
|
-
import
|
|
1
|
+
<script>import { cleanExpr } from '../utils';
|
|
2
|
+
import ObjectViewer from './propertyPicker/ObjectViewer.svelte';
|
|
3
3
|
export let inputTransforms;
|
|
4
4
|
$: entries = Object.entries(inputTransforms);
|
|
5
5
|
</script>
|
|
@@ -299,12 +299,14 @@ $: inputCat = computeInputCat(type, format, itemsType?.type, enum_, contentEncod
|
|
|
299
299
|
multiple={false}
|
|
300
300
|
/>
|
|
301
301
|
{:else if inputCat == 'resource-string'}
|
|
302
|
-
<
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
302
|
+
<div class="flex flex-row gap-x-1 w-full">
|
|
303
|
+
<ResourcePicker
|
|
304
|
+
bind:value
|
|
305
|
+
resourceType={format.split('-').length > 1
|
|
306
|
+
? format.substring('resource-'.length)
|
|
307
|
+
: undefined}
|
|
308
|
+
/>
|
|
309
|
+
</div>
|
|
308
310
|
{:else if inputCat == 'string'}
|
|
309
311
|
<div class="flex flex-col w-full">
|
|
310
312
|
<div class="flex flex-row w-full items-center justify-between">
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script>import LightweightResourcePicker from './LightweightResourcePicker.svelte';
|
|
2
|
+
export let format;
|
|
3
|
+
export let value;
|
|
4
|
+
export let disablePortal = false;
|
|
5
|
+
function isString(value) {
|
|
6
|
+
return typeof value === 'string' || value instanceof String;
|
|
7
|
+
}
|
|
8
|
+
let path = '';
|
|
9
|
+
function resourceToValue() {
|
|
10
|
+
if (path) {
|
|
11
|
+
value = `$res:${path}`;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
value = undefined;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function isResource() {
|
|
18
|
+
return isString(value) && value.length >= '$res:'.length;
|
|
19
|
+
}
|
|
20
|
+
function valueToPath() {
|
|
21
|
+
if (isResource()) {
|
|
22
|
+
path = value.substr('$res:'.length);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
$: value && valueToPath();
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<div class="flex flex-row w-full flex-wrap gap-x-2 gap-y-0.5">
|
|
29
|
+
<LightweightResourcePicker
|
|
30
|
+
{disablePortal}
|
|
31
|
+
on:change={(e) => {
|
|
32
|
+
path = e.detail
|
|
33
|
+
resourceToValue()
|
|
34
|
+
}}
|
|
35
|
+
bind:value={path}
|
|
36
|
+
resourceType={format.split('-').length > 1 ? format.substring('resource-'.length) : undefined}
|
|
37
|
+
/>
|
|
38
|
+
</div>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
format: string;
|
|
5
|
+
value: any;
|
|
6
|
+
disablePortal?: boolean | undefined;
|
|
7
|
+
};
|
|
8
|
+
events: {
|
|
9
|
+
[evt: string]: CustomEvent<any>;
|
|
10
|
+
};
|
|
11
|
+
slots: {};
|
|
12
|
+
};
|
|
13
|
+
export type LightweightObjectResourceInputProps = typeof __propDef.props;
|
|
14
|
+
export type LightweightObjectResourceInputEvents = typeof __propDef.events;
|
|
15
|
+
export type LightweightObjectResourceInputSlots = typeof __propDef.slots;
|
|
16
|
+
export default class LightweightObjectResourceInput extends SvelteComponentTyped<LightweightObjectResourceInputProps, LightweightObjectResourceInputEvents, LightweightObjectResourceInputSlots> {
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<script>import { ResourceService } from '../gen';
|
|
2
|
+
import { workspaceStore } from '../stores';
|
|
3
|
+
import { createEventDispatcher, onMount } from 'svelte';
|
|
4
|
+
import Select from './apps/svelte-select/lib/index';
|
|
5
|
+
import { SELECT_INPUT_DEFAULT_STYLE } from '../defaults';
|
|
6
|
+
import DarkModeObserver from './DarkModeObserver.svelte';
|
|
7
|
+
const dispatch = createEventDispatcher();
|
|
8
|
+
export let initialValue = undefined;
|
|
9
|
+
export let value = initialValue;
|
|
10
|
+
export let resourceType = undefined;
|
|
11
|
+
export let disablePortal = false;
|
|
12
|
+
let valueSelect = initialValue || value
|
|
13
|
+
? {
|
|
14
|
+
value: value ?? initialValue,
|
|
15
|
+
label: value ?? initialValue
|
|
16
|
+
}
|
|
17
|
+
: undefined;
|
|
18
|
+
let collection = [valueSelect];
|
|
19
|
+
async function loadResources(resourceType) {
|
|
20
|
+
const nc = (await ResourceService.listResource({
|
|
21
|
+
workspace: $workspaceStore,
|
|
22
|
+
resourceType
|
|
23
|
+
})).map((x) => ({
|
|
24
|
+
value: x.path,
|
|
25
|
+
label: x.path
|
|
26
|
+
}));
|
|
27
|
+
// TODO check if this is needed
|
|
28
|
+
if (!nc.find((x) => x.value == value) && (initialValue || value)) {
|
|
29
|
+
nc.push({ value: value ?? initialValue, label: value ?? initialValue });
|
|
30
|
+
}
|
|
31
|
+
collection = nc;
|
|
32
|
+
}
|
|
33
|
+
$: {
|
|
34
|
+
if ($workspaceStore) {
|
|
35
|
+
loadResources(resourceType);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
$: dispatch('change', value);
|
|
39
|
+
let darkMode = false;
|
|
40
|
+
function onThemeChange() {
|
|
41
|
+
if (document.documentElement.classList.contains('dark')) {
|
|
42
|
+
darkMode = true;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
darkMode = false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
onMount(() => {
|
|
49
|
+
onThemeChange();
|
|
50
|
+
});
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<DarkModeObserver on:change={onThemeChange} />
|
|
54
|
+
|
|
55
|
+
<Select
|
|
56
|
+
portal={!disablePortal}
|
|
57
|
+
value={valueSelect}
|
|
58
|
+
on:change={(e) => {
|
|
59
|
+
value = e.detail.value
|
|
60
|
+
valueSelect = e.detail
|
|
61
|
+
}}
|
|
62
|
+
on:clear={() => {
|
|
63
|
+
value = undefined
|
|
64
|
+
valueSelect = undefined
|
|
65
|
+
}}
|
|
66
|
+
items={collection}
|
|
67
|
+
class="text-clip grow min-w-0"
|
|
68
|
+
placeholder="{resourceType ?? 'any'} resource"
|
|
69
|
+
inputStyles={SELECT_INPUT_DEFAULT_STYLE.inputStyles}
|
|
70
|
+
containerStyles={darkMode
|
|
71
|
+
? SELECT_INPUT_DEFAULT_STYLE.containerStylesDark
|
|
72
|
+
: SELECT_INPUT_DEFAULT_STYLE.containerStyles}
|
|
73
|
+
/>
|
|
74
|
+
|
|
75
|
+
<style>
|
|
76
|
+
:global(.svelte-select-list) {
|
|
77
|
+
font-size: small !important;
|
|
78
|
+
}</style>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
initialValue?: string | undefined;
|
|
5
|
+
value?: string | undefined;
|
|
6
|
+
resourceType?: string | undefined;
|
|
7
|
+
disablePortal?: boolean | undefined;
|
|
8
|
+
};
|
|
9
|
+
events: {
|
|
10
|
+
change: CustomEvent<any>;
|
|
11
|
+
} & {
|
|
12
|
+
[evt: string]: CustomEvent<any>;
|
|
13
|
+
};
|
|
14
|
+
slots: {};
|
|
15
|
+
};
|
|
16
|
+
export type LightweightResourcePickerProps = typeof __propDef.props;
|
|
17
|
+
export type LightweightResourcePickerEvents = typeof __propDef.events;
|
|
18
|
+
export type LightweightResourcePickerSlots = typeof __propDef.slots;
|
|
19
|
+
export default class LightweightResourcePicker extends SvelteComponentTyped<LightweightResourcePickerProps, LightweightResourcePickerEvents, LightweightResourcePickerSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
<script>import
|
|
2
|
-
import Tooltip from '../../../Tooltip.svelte';
|
|
1
|
+
<script>import Tooltip from '../../../Tooltip.svelte';
|
|
3
2
|
import { Clipboard } from 'lucide-svelte';
|
|
4
3
|
import { getContext } from 'svelte';
|
|
5
4
|
import { twMerge } from 'tailwind-merge';
|
|
6
|
-
import { copyToClipboard } from '../../../../utils';
|
|
5
|
+
import { copyToClipboard, isCodeInjection } from '../../../../utils';
|
|
7
6
|
import Button from '../../../common/button/Button.svelte';
|
|
8
7
|
import { initConfig, initOutput } from '../../editor/appUtils';
|
|
9
8
|
import { components } from '../../editor/component';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
import { createEventDispatcher, getContext, onDestroy, tick } from 'svelte';
|
|
1
|
+
<script>import { createEventDispatcher, getContext, onDestroy, tick } from 'svelte';
|
|
3
2
|
import { accessPropertyByPath } from '../../utils';
|
|
4
3
|
import { computeGlobalContext, eval_like } from './eval';
|
|
5
4
|
import deepEqualWithOrderedArray from './deepEqualWithOrderedArray';
|
|
6
5
|
import { deepEqual } from 'fast-equals';
|
|
6
|
+
import { isCodeInjection } from '../../../../utils';
|
|
7
7
|
export let input;
|
|
8
8
|
export let value;
|
|
9
9
|
export let id = undefined;
|
|
@@ -4,12 +4,10 @@ import type { FlowModuleState } from './flowState';
|
|
|
4
4
|
import type { PickableProperties } from './previousResults';
|
|
5
5
|
export declare function evalValue(k: string, mod: FlowModule, testStepStore: Record<string, any>, pickableProperties: PickableProperties | undefined, showError: boolean): any;
|
|
6
6
|
export declare function cleanInputs(flow: Flow | any): Flow;
|
|
7
|
-
export declare function cleanExpr(expr: string): string;
|
|
8
7
|
export declare function loadSchemaFromModule(module: FlowModule): Promise<{
|
|
9
8
|
input_transforms: Record<string, InputTransform>;
|
|
10
9
|
schema: Schema;
|
|
11
10
|
}>;
|
|
12
|
-
export declare function isCodeInjection(expr: string | undefined): boolean;
|
|
13
11
|
export declare function getDefaultExpr(key: string | undefined, previousModuleId: string | undefined, previousExpr?: string): string;
|
|
14
12
|
export declare function jobsToResults(jobs: Job[]): any;
|
|
15
13
|
export declare function runFlowPreview(args: Record<string, any>, flow: Flow): Promise<string>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { JobService, ScriptService } from '../../gen';
|
|
2
|
-
import { inferArgs } from '../../infer';
|
|
3
|
-
import {
|
|
2
|
+
import { inferArgs, loadSchemaFromPath } from '../../infer';
|
|
3
|
+
import { loadSchemaFlow } from '../../scripts';
|
|
4
4
|
import { workspaceStore } from '../../stores';
|
|
5
|
-
import { emptySchema } from '../../utils';
|
|
5
|
+
import { cleanExpr, emptySchema } from '../../utils';
|
|
6
6
|
import { get } from 'svelte/store';
|
|
7
7
|
import { NEVER_TESTED_THIS_FAR } from './models';
|
|
8
8
|
import { sendUserToast } from '../../toast';
|
|
@@ -70,12 +70,6 @@ export function cleanInputs(flow) {
|
|
|
70
70
|
});
|
|
71
71
|
return newFlow;
|
|
72
72
|
}
|
|
73
|
-
export function cleanExpr(expr) {
|
|
74
|
-
return expr
|
|
75
|
-
.split('\n')
|
|
76
|
-
.filter((x) => x != '' && !x.startsWith(`import `))
|
|
77
|
-
.join('\n');
|
|
78
|
-
}
|
|
79
73
|
export async function loadSchemaFromModule(module) {
|
|
80
74
|
const mod = module.value;
|
|
81
75
|
if (mod.type == 'rawscript' || mod.type === 'script' || mod.type === 'flow') {
|
|
@@ -85,7 +79,7 @@ export async function loadSchemaFromModule(module) {
|
|
|
85
79
|
await inferArgs(mod.language, mod.content ?? '', schema);
|
|
86
80
|
}
|
|
87
81
|
else if (mod.type == 'script' && mod.path && mod.path != '') {
|
|
88
|
-
schema = await
|
|
82
|
+
schema = await loadSchemaFromPath(mod.path, mod.hash);
|
|
89
83
|
}
|
|
90
84
|
else if (mod.type == 'flow' && mod.path && mod.path != '') {
|
|
91
85
|
schema = await loadSchemaFlow(mod.path);
|
|
@@ -121,13 +115,6 @@ export async function loadSchemaFromModule(module) {
|
|
|
121
115
|
schema: emptySchema()
|
|
122
116
|
};
|
|
123
117
|
}
|
|
124
|
-
const dynamicTemplateRegex = new RegExp(/\$\{(.*)\}/);
|
|
125
|
-
export function isCodeInjection(expr) {
|
|
126
|
-
if (!expr) {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
return dynamicTemplateRegex.test(expr);
|
|
130
|
-
}
|
|
131
118
|
export function getDefaultExpr(key = 'myfield', previousModuleId, previousExpr) {
|
|
132
119
|
return (previousExpr ?? (previousModuleId ? `results.${previousModuleId}.${key}` : `flow_input.${key}`));
|
|
133
120
|
}
|
package/package/infer.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Schema, SupportedLanguage } from './common.js';
|
|
2
2
|
export declare function inferArgs(language: SupportedLanguage, code: string, schema: Schema): Promise<void>;
|
|
3
|
+
export declare function loadSchemaFromPath(path: string, hash?: string): Promise<Schema>;
|
|
3
4
|
export declare function loadSchema(workspace: string, path: string, runType: 'script' | 'flow' | 'hubscript'): Promise<{
|
|
4
5
|
schema: Schema;
|
|
5
6
|
summary: string | undefined;
|
package/package/infer.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ScriptService, FlowService } from './gen';
|
|
1
|
+
import { ScriptService, FlowService, Script } from './gen';
|
|
2
2
|
import { get, writable } from 'svelte/store';
|
|
3
3
|
import { emptySchema, sortObject } from './utils.js';
|
|
4
4
|
import { tick } from 'svelte';
|
|
5
5
|
import init, { parse_deno, parse_bash, parse_go, parse_python, parse_sql, parse_mysql, parse_bigquery } from 'windmill-parser-wasm';
|
|
6
6
|
import wasmUrl from 'windmill-parser-wasm/windmill_parser_wasm_bg.wasm?url';
|
|
7
|
+
import { workspaceStore } from './stores.js';
|
|
7
8
|
init(wasmUrl);
|
|
8
9
|
const loadSchemaLastRun = writable(undefined);
|
|
9
10
|
export async function inferArgs(language, code, schema) {
|
|
@@ -179,6 +180,43 @@ function argSigToJsonSchemaType(t, oldS) {
|
|
|
179
180
|
oldS.format = undefined;
|
|
180
181
|
}
|
|
181
182
|
}
|
|
183
|
+
export async function loadSchemaFromPath(path, hash) {
|
|
184
|
+
if (path.startsWith('hub/')) {
|
|
185
|
+
const { content, language, schema } = await ScriptService.getHubScriptByPath({ path });
|
|
186
|
+
if (language == 'deno') {
|
|
187
|
+
const newSchema = emptySchema();
|
|
188
|
+
await inferArgs('deno', content ?? '', newSchema);
|
|
189
|
+
return newSchema;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
return schema ?? emptySchema();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else if (hash) {
|
|
196
|
+
const script = await ScriptService.getScriptByHash({
|
|
197
|
+
workspace: get(workspaceStore),
|
|
198
|
+
hash
|
|
199
|
+
});
|
|
200
|
+
return inferSchemaIfNecessary(script);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
const script = await ScriptService.getScriptByPath({
|
|
204
|
+
workspace: get(workspaceStore),
|
|
205
|
+
path: path ?? ''
|
|
206
|
+
});
|
|
207
|
+
return inferSchemaIfNecessary(script);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async function inferSchemaIfNecessary(script) {
|
|
211
|
+
if (script.schema) {
|
|
212
|
+
return script.schema;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
const newSchema = emptySchema();
|
|
216
|
+
await inferArgs(script.language, script.content ?? '', newSchema);
|
|
217
|
+
return newSchema;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
182
220
|
export async function loadSchema(workspace, path, runType) {
|
|
183
221
|
if (runType === 'script') {
|
|
184
222
|
const script = await ScriptService.getScriptByPath({
|
package/package/scripts.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Schema, SupportedLanguage } from './common';
|
|
2
2
|
import { Script } from './gen';
|
|
3
3
|
export declare function scriptLangToEditorLang(lang: Script.language): "graphql" | "sql" | Script.language.GO | "typescript" | "python" | "shell";
|
|
4
|
-
export declare function loadSchema(path: string, hash?: string): Promise<Schema>;
|
|
5
4
|
export declare function loadSchemaFlow(path: string): Promise<Schema>;
|
|
6
5
|
export declare function scriptPathToHref(path: string): string;
|
|
7
6
|
export declare function getScriptByPath(path: string): Promise<{
|
package/package/scripts.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { get } from 'svelte/store';
|
|
2
2
|
import { FlowService, Script, ScriptService } from './gen';
|
|
3
|
-
import { inferArgs } from './infer';
|
|
4
3
|
import { workspaceStore, hubScripts } from './stores';
|
|
5
|
-
import { emptySchema } from './utils';
|
|
6
4
|
export function scriptLangToEditorLang(lang) {
|
|
7
5
|
if (lang == 'deno') {
|
|
8
6
|
return 'typescript';
|
|
@@ -37,43 +35,6 @@ export function scriptLangToEditorLang(lang) {
|
|
|
37
35
|
return lang;
|
|
38
36
|
}
|
|
39
37
|
}
|
|
40
|
-
export async function loadSchema(path, hash) {
|
|
41
|
-
if (path.startsWith('hub/')) {
|
|
42
|
-
const { content, language, schema } = await ScriptService.getHubScriptByPath({ path });
|
|
43
|
-
if (language == 'deno') {
|
|
44
|
-
const newSchema = emptySchema();
|
|
45
|
-
await inferArgs('deno', content ?? '', newSchema);
|
|
46
|
-
return newSchema;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
return schema ?? emptySchema();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else if (hash) {
|
|
53
|
-
const script = await ScriptService.getScriptByHash({
|
|
54
|
-
workspace: get(workspaceStore),
|
|
55
|
-
hash
|
|
56
|
-
});
|
|
57
|
-
return inferSchemaIfNecessary(script);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
const script = await ScriptService.getScriptByPath({
|
|
61
|
-
workspace: get(workspaceStore),
|
|
62
|
-
path: path ?? ''
|
|
63
|
-
});
|
|
64
|
-
return inferSchemaIfNecessary(script);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
async function inferSchemaIfNecessary(script) {
|
|
68
|
-
if (script.schema) {
|
|
69
|
-
return script.schema;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
const newSchema = emptySchema();
|
|
73
|
-
await inferArgs(script.language, script.content ?? '', newSchema);
|
|
74
|
-
return newSchema;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
38
|
export async function loadSchemaFlow(path) {
|
|
78
39
|
const flow = await FlowService.getFlowByPath({
|
|
79
40
|
workspace: get(workspaceStore),
|
|
@@ -99,7 +60,7 @@ export async function getScriptByPath(path) {
|
|
|
99
60
|
description: '',
|
|
100
61
|
tag: undefined,
|
|
101
62
|
concurrent_limit: undefined,
|
|
102
|
-
concurrency_time_window_s: undefined
|
|
63
|
+
concurrency_time_window_s: undefined
|
|
103
64
|
};
|
|
104
65
|
}
|
|
105
66
|
else {
|
|
@@ -114,7 +75,7 @@ export async function getScriptByPath(path) {
|
|
|
114
75
|
description: script.description,
|
|
115
76
|
tag: script.tag,
|
|
116
77
|
concurrent_limit: script.concurrent_limit,
|
|
117
|
-
concurrency_time_window_s: script.concurrency_time_window_s
|
|
78
|
+
concurrency_time_window_s: script.concurrency_time_window_s
|
|
118
79
|
};
|
|
119
80
|
}
|
|
120
81
|
}
|
package/package/utils.d.ts
CHANGED
|
@@ -89,3 +89,5 @@ export declare function isOwner(path: string, user: UserExt | undefined, workspa
|
|
|
89
89
|
export declare function isObviousOwner(path: string, user?: UserExt): boolean;
|
|
90
90
|
export declare function extractCustomProperties(styleStr: string): string;
|
|
91
91
|
export declare function toCamel(s: string): string;
|
|
92
|
+
export declare function cleanExpr(expr: string): string;
|
|
93
|
+
export declare function isCodeInjection(expr: string | undefined): boolean;
|
package/package/utils.js
CHANGED
|
@@ -499,3 +499,16 @@ export function toCamel(s) {
|
|
|
499
499
|
return $1.toUpperCase().replace('-', '').replace('_', '');
|
|
500
500
|
});
|
|
501
501
|
}
|
|
502
|
+
export function cleanExpr(expr) {
|
|
503
|
+
return expr
|
|
504
|
+
.split('\n')
|
|
505
|
+
.filter((x) => x != '' && !x.startsWith(`import `))
|
|
506
|
+
.join('\n');
|
|
507
|
+
}
|
|
508
|
+
const dynamicTemplateRegex = new RegExp(/\$\{(.*)\}/);
|
|
509
|
+
export function isCodeInjection(expr) {
|
|
510
|
+
if (!expr) {
|
|
511
|
+
return false;
|
|
512
|
+
}
|
|
513
|
+
return dynamicTemplateRegex.test(expr);
|
|
514
|
+
}
|