windmill-components 1.138.3 → 1.138.5

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.
@@ -6,16 +6,12 @@ import { Button, Drawer, DrawerContent } from './common';
6
6
  import { ClipboardCopy, Download, Expand } from 'lucide-svelte';
7
7
  import Portal from 'svelte-portal';
8
8
  import ObjectViewer from './propertyPicker/ObjectViewer.svelte';
9
- import ScriptFix from './codeGen/ScriptFix.svelte';
10
9
  export let result;
11
10
  export let requireHtmlApproval = false;
12
11
  export let filename = undefined;
13
12
  export let disableExpand = false;
14
13
  export let jobId = undefined;
15
14
  export let workspaceId = undefined;
16
- export let editor = undefined;
17
- export let diffEditor = undefined;
18
- export let lang = undefined;
19
15
  let resultKind;
20
16
  $: resultKind = inferResultKind(result);
21
17
  let forceJson = false;
@@ -207,9 +203,7 @@ $: jsonStr = JSON.stringify(result, null, 4);
207
203
  .message}{:else}{JSON.stringify(result.error, null, 4)}{/if}</span
208
204
  >
209
205
  <pre class="text-sm whitespace-pre-wrap text-primary">{result.error.stack ?? ''}</pre>
210
- {#if lang && editor && diffEditor}
211
- <ScriptFix error={JSON.stringify(result.error)} {lang} {editor} {diffEditor} />
212
- {/if}
206
+ <slot />
213
207
  </div>
214
208
  {:else if !forceJson && resultKind == 'approval'}<div class="flex flex-col gap-3 mt-8 mx-4">
215
209
  <Button
@@ -1,7 +1,4 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { Preview } from '../gen';
3
- import type Editor from './Editor.svelte';
4
- import type DiffEditor from './DiffEditor.svelte';
5
2
  declare const __propDef: {
6
3
  props: {
7
4
  result: any;
@@ -10,14 +7,13 @@ declare const __propDef: {
10
7
  disableExpand?: boolean | undefined;
11
8
  jobId?: string | undefined;
12
9
  workspaceId?: string | undefined;
13
- editor?: Editor | undefined;
14
- diffEditor?: DiffEditor | undefined;
15
- lang?: Preview.language | undefined;
16
10
  };
17
11
  events: {
18
12
  [evt: string]: CustomEvent<any>;
19
13
  };
20
- slots: {};
14
+ slots: {
15
+ default: {};
16
+ };
21
17
  };
22
18
  export type DisplayResultProps = typeof __propDef.props;
23
19
  export type DisplayResultEvents = typeof __propDef.events;
@@ -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
- <ResourcePicker
303
- bind:value
304
- resourceType={format.split('-').length > 1
305
- ? format.substring('resource-'.length)
306
- : undefined}
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 {};
@@ -12,6 +12,7 @@ import TestJobLoader from './TestJobLoader.svelte';
12
12
  import ModulePreviewForm from './ModulePreviewForm.svelte';
13
13
  import { Kbd } from './common';
14
14
  import { evalValue } from './flows/utils';
15
+ import ScriptFix from './codeGen/ScriptFix.svelte';
15
16
  export let mod;
16
17
  export let schema;
17
18
  export let pickableProperties;
@@ -101,14 +102,16 @@ function jobDone() {
101
102
  <Pane size={50} minSize={10} class="text-sm text-tertiary">
102
103
  {#if testJob != undefined && 'result' in testJob && testJob.result != undefined}
103
104
  <pre class="overflow-x-auto break-words relative h-full px-2">
104
- <DisplayResult
105
- workspaceId={testJob?.workspace_id}
106
- jobId={testJob?.id}
107
- result={testJob.result}
108
- {editor}
109
- {diffEditor}
110
- {lang}
111
- />
105
+ <DisplayResult workspaceId={testJob?.workspace_id} jobId={testJob?.id} result={testJob.result}>
106
+ {#if lang && editor && diffEditor && testJob?.result?.error}
107
+ <ScriptFix
108
+ error={JSON.stringify(testJob.result.error)}
109
+ {lang}
110
+ {editor}
111
+ {diffEditor}
112
+ />
113
+ {/if}
114
+ </DisplayResult>
112
115
  </pre>
113
116
  {:else}
114
117
  <div class="p-2">
@@ -1,6 +1,6 @@
1
1
  import { JobService, ScriptService } from '../../gen';
2
- import { inferArgs } from '../../infer';
3
- import { loadSchema, loadSchemaFlow } from '../../scripts';
2
+ import { inferArgs, loadSchemaFromPath } from '../../infer';
3
+ import { loadSchemaFlow } from '../../scripts';
4
4
  import { workspaceStore } from '../../stores';
5
5
  import { emptySchema } from '../../utils';
6
6
  import { get } from 'svelte/store';
@@ -85,7 +85,7 @@ export async function loadSchemaFromModule(module) {
85
85
  await inferArgs(mod.language, mod.content ?? '', schema);
86
86
  }
87
87
  else if (mod.type == 'script' && mod.path && mod.path != '') {
88
- schema = await loadSchema(mod.path, mod.hash);
88
+ schema = await loadSchemaFromPath(mod.path, mod.hash);
89
89
  }
90
90
  else if (mod.type == 'flow' && mod.path && mod.path != '') {
91
91
  schema = await loadSchemaFlow(mod.path);
@@ -18,6 +18,7 @@ import LogViewer from '../LogViewer.svelte';
18
18
  import { Pane, Splitpanes } from 'svelte-splitpanes';
19
19
  import SplitPanesWrapper from '../splitPanes/SplitPanesWrapper.svelte';
20
20
  import { Loader2 } from 'lucide-svelte';
21
+ import ScriptFix from '../codeGen/ScriptFix.svelte';
21
22
  export let lang;
22
23
  export let previewIsLoading = false;
23
24
  export let previewJob;
@@ -82,10 +83,16 @@ function closeDrawer() {
82
83
  workspaceId={previewJob?.workspace_id}
83
84
  jobId={previewJob?.id}
84
85
  result={previewJob.result}
85
- {editor}
86
- {diffEditor}
87
- {lang}
88
- />
86
+ >
87
+ {#if lang && editor && diffEditor && previewJob?.result?.error}
88
+ <ScriptFix
89
+ error={JSON.stringify(previewJob.result.error)}
90
+ {lang}
91
+ {editor}
92
+ {diffEditor}
93
+ />
94
+ {/if}
95
+ </DisplayResult>
89
96
  </div>
90
97
  {:else}
91
98
  <div class="text-sm text-tertiary p-2">
@@ -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({
@@ -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<{
@@ -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.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "windmill-components",
3
- "version": "1.138.3",
3
+ "version": "1.138.5",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build",