windmill-components 1.13.0 → 1.13.1
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/common.js +23 -0
- package/components/ArgInfo.svelte +2 -2
- package/components/Dropdown.svelte +1 -1
- package/components/FlowBuilder.svelte +2 -2
- package/components/FlowEditor.svelte +2 -2
- package/components/FlowPreview.svelte +2 -2
- package/components/FlowStatusViewer.svelte +2 -2
- package/components/GroupModal.svelte +2 -2
- package/components/InviteGlobalUser.svelte +1 -1
- package/components/InviteUser.svelte +2 -2
- package/components/JobStatus.svelte +1 -1
- package/components/ModuleStep.svelte +1 -1
- package/components/ObjectResourceInput.svelte +1 -1
- package/components/Path.svelte +3 -3
- package/components/ResourceEditor.svelte +2 -2
- package/components/ResourcePicker.svelte +1 -1
- package/components/ResourceTypePicker.svelte +1 -1
- package/components/RunForm.svelte +1 -1
- package/components/SchemaEditor.svelte +1 -1
- package/components/SchemaForm.svelte +1 -1
- package/components/SchemaViewer.svelte +1 -1
- package/components/ScriptBuilder.svelte +3 -3
- package/components/ScriptEditor.svelte +3 -3
- package/components/ScriptPicker.svelte +2 -2
- package/components/ShareModal.svelte +2 -2
- package/components/SharedBadge.svelte +1 -1
- package/components/VariableEditor.svelte +2 -2
- package/infer.js +81 -0
- package/{common.d.ts → lib/common.d.ts} +0 -0
- package/lib/components/ArgInput.svelte.d.ts +2 -2
- package/lib/components/FieldHeader.svelte.d.ts +2 -1
- package/{infer.d.ts → lib/infer.d.ts} +0 -0
- package/{stores.d.ts → lib/stores.d.ts} +1 -2
- package/{utils.d.ts → lib/utils.d.ts} +1 -1
- package/package.json +7 -3
- package/stores.js +26 -0
- package/utils.js +258 -0
package/common.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function pathToMeta(path) {
|
|
2
|
+
const splitted = path.split('/');
|
|
3
|
+
let ownerKind;
|
|
4
|
+
if (splitted[0] == 'g') {
|
|
5
|
+
ownerKind = 'group';
|
|
6
|
+
}
|
|
7
|
+
else if (splitted[0] == 'u') {
|
|
8
|
+
ownerKind = 'user';
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
console.error('Not recognized owner:' + splitted[0]);
|
|
12
|
+
return {
|
|
13
|
+
ownerKind: 'user',
|
|
14
|
+
owner: '',
|
|
15
|
+
name: ''
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
ownerKind,
|
|
20
|
+
owner: splitted[1],
|
|
21
|
+
name: splitted.slice(2).join('/')
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
<script>import { truncate } from '
|
|
1
|
+
<script>import { truncate } from '../utils';
|
|
2
2
|
import Modal from './Modal.svelte';
|
|
3
3
|
import Tooltip from './Tooltip.svelte';
|
|
4
4
|
import json from 'svelte-highlight/languages/json';
|
|
5
5
|
import github from 'svelte-highlight/styles/github';
|
|
6
6
|
import { Highlight } from 'svelte-highlight';
|
|
7
7
|
import { ResourceService } from '../../gen';
|
|
8
|
-
import { workspaceStore } from '
|
|
8
|
+
import { workspaceStore } from '../stores';
|
|
9
9
|
export let value;
|
|
10
10
|
let resourceViewer;
|
|
11
11
|
let resource;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<script>import { FlowService } from '../../gen';
|
|
2
|
-
import { sendUserToast } from '
|
|
2
|
+
import { sendUserToast } from '../utils';
|
|
3
3
|
import { page } from '$app/stores';
|
|
4
4
|
import { goto } from '$app/navigation';
|
|
5
5
|
import Path from './Path.svelte';
|
|
6
6
|
import SvelteMarkdown from 'svelte-markdown';
|
|
7
|
-
import { workspaceStore } from '
|
|
7
|
+
import { workspaceStore } from '../stores';
|
|
8
8
|
import ScriptSchema from './ScriptSchema.svelte';
|
|
9
9
|
import Required from './Required.svelte';
|
|
10
10
|
import FlowEditor from './FlowEditor.svelte';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<script>import { faPlus } from '@fortawesome/free-solid-svg-icons';
|
|
2
|
-
import { emptySchema, loadSchema } from '
|
|
2
|
+
import { emptySchema, loadSchema } from '../utils';
|
|
3
3
|
import Icon from 'svelte-awesome';
|
|
4
4
|
import { FlowModuleValue, ScriptService } from '../../gen';
|
|
5
5
|
import SchemaEditor from './SchemaEditor.svelte';
|
|
6
|
-
import { workspaceStore } from '
|
|
6
|
+
import { workspaceStore } from '../stores';
|
|
7
7
|
import ModuleStep from './ModuleStep.svelte';
|
|
8
8
|
import FlowPreview from './FlowPreview.svelte';
|
|
9
9
|
export let flow;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script>import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons';
|
|
2
|
-
import { sendUserToast, truncateRev } from '
|
|
2
|
+
import { sendUserToast, truncateRev } from '../utils';
|
|
3
3
|
import Icon from 'svelte-awesome';
|
|
4
4
|
import { Job, JobService, InputTransform } from '../../gen';
|
|
5
|
-
import { workspaceStore } from '
|
|
5
|
+
import { workspaceStore } from '../stores';
|
|
6
6
|
import RunForm from './RunForm.svelte';
|
|
7
7
|
import FlowStatusViewer from './FlowStatusViewer.svelte';
|
|
8
8
|
import { onDestroy } from 'svelte';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<script>import { faHourglassHalf, faSpinner, faTimes } from '@fortawesome/free-solid-svg-icons';
|
|
2
|
-
import { truncateRev } from '
|
|
2
|
+
import { truncateRev } from '../utils';
|
|
3
3
|
import Icon from 'svelte-awesome';
|
|
4
4
|
import { check } from 'svelte-awesome/icons';
|
|
5
5
|
import { CompletedJob, FlowModuleValue, FlowStatusModule, JobService, QueuedJob } from '../../gen';
|
|
6
|
-
import { workspaceStore } from '
|
|
6
|
+
import { workspaceStore } from '../stores';
|
|
7
7
|
import DisplayResult from './DisplayResult.svelte';
|
|
8
8
|
import ChevronButton from './ChevronButton.svelte';
|
|
9
9
|
import JobStatus from './JobStatus.svelte';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
<script>import { userStore, workspaceStore } from '
|
|
1
|
+
<script>import { userStore, workspaceStore } from '../stores';
|
|
2
2
|
import Modal from './Modal.svelte';
|
|
3
3
|
import { GroupService, UserService } from '../../gen';
|
|
4
4
|
import AutoComplete from 'simple-svelte-autocomplete';
|
|
5
5
|
import PageHeader from './PageHeader.svelte';
|
|
6
6
|
import TableCustom from './TableCustom.svelte';
|
|
7
|
-
import { canWrite } from '
|
|
7
|
+
import { canWrite } from '../utils';
|
|
8
8
|
let name = '';
|
|
9
9
|
let modal;
|
|
10
10
|
let can_write = false;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
<script>import { sendUserToast } from '
|
|
1
|
+
<script>import { sendUserToast } from '../utils';
|
|
2
2
|
import Switch from './Switch.svelte';
|
|
3
3
|
import { createEventDispatcher } from 'svelte';
|
|
4
|
-
import { workspaceStore } from '
|
|
4
|
+
import { workspaceStore } from '../stores';
|
|
5
5
|
import { WorkspaceService } from '../../gen';
|
|
6
6
|
const dispatch = createEventDispatcher();
|
|
7
7
|
let valid = true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>import { faCalendar, faCircle, faClock, faHourglassHalf, faTimes } from '@fortawesome/free-solid-svg-icons';
|
|
2
|
-
import { displayDate, forLater } from '
|
|
2
|
+
import { displayDate, forLater } from '../utils';
|
|
3
3
|
import Icon from 'svelte-awesome';
|
|
4
4
|
import { check } from 'svelte-awesome/icons';
|
|
5
5
|
const SMALL_ICON_SCALE = 0.7;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>import SchemaForm from './SchemaForm.svelte';
|
|
2
2
|
import ScriptPicker from './ScriptPicker.svelte';
|
|
3
|
-
import { emptySchema, loadSchema as UloadSchema } from '
|
|
3
|
+
import { emptySchema, loadSchema as UloadSchema } from '../utils';
|
|
4
4
|
import FlowPreview from './FlowPreview.svelte';
|
|
5
5
|
export let flow;
|
|
6
6
|
export let i;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>import { ResourceService } from '../../gen';
|
|
2
2
|
import ResourcePicker from './ResourcePicker.svelte';
|
|
3
|
-
import { workspaceStore } from '
|
|
3
|
+
import { workspaceStore } from '../stores';
|
|
4
4
|
import SchemaForm from './SchemaForm.svelte';
|
|
5
5
|
import RadioButton from './RadioButton.svelte';
|
|
6
6
|
export let format;
|
package/components/Path.svelte
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
<script>import { pathToMeta } from '
|
|
1
|
+
<script>import { pathToMeta } from '../common';
|
|
2
2
|
import { GroupService } from '../../gen';
|
|
3
3
|
import Tooltip from './Tooltip.svelte';
|
|
4
|
-
import { userStore, workspaceStore } from '
|
|
5
|
-
import { sleep } from '
|
|
4
|
+
import { userStore, workspaceStore } from '../stores';
|
|
5
|
+
import { sleep } from '../utils';
|
|
6
6
|
export let meta = {
|
|
7
7
|
ownerKind: 'user',
|
|
8
8
|
owner: '',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>import { ResourceService, VariableService } from '../../gen';
|
|
2
|
-
import { allTrue, emptySchema, sendUserToast } from '
|
|
2
|
+
import { allTrue, emptySchema, sendUserToast } from '../utils';
|
|
3
3
|
import { createEventDispatcher } from 'svelte';
|
|
4
4
|
import Modal from './Modal.svelte';
|
|
5
5
|
import Path from './Path.svelte';
|
|
@@ -8,7 +8,7 @@ import AutosizedTextarea from './AutosizedTextarea.svelte';
|
|
|
8
8
|
import ItemPicker from './ItemPicker.svelte';
|
|
9
9
|
import VariableEditor from './VariableEditor.svelte';
|
|
10
10
|
import Required from './Required.svelte';
|
|
11
|
-
import { workspaceStore } from '
|
|
11
|
+
import { workspaceStore } from '../stores';
|
|
12
12
|
import ResourceTypePicker from './ResourceTypePicker.svelte';
|
|
13
13
|
let path = '';
|
|
14
14
|
let initialPath = '';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>import { createEventDispatcher } from 'svelte';
|
|
2
2
|
import { ResourceService } from '../../gen';
|
|
3
|
-
import { workspaceStore } from '
|
|
3
|
+
import { workspaceStore } from '../stores';
|
|
4
4
|
import IconedResourceType from './IconedResourceType.svelte';
|
|
5
5
|
let resources = [];
|
|
6
6
|
export let value;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script>import { page } from '$app/stores';
|
|
2
|
-
import { getToday } from '
|
|
2
|
+
import { getToday } from '../utils';
|
|
3
3
|
import { slide } from 'svelte/transition';
|
|
4
4
|
import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons';
|
|
5
5
|
import Icon from 'svelte-awesome';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>import SchemaModal, { DEFAULT_PROPERTY, modalToSchema, schemaToModal } from './SchemaModal.svelte';
|
|
2
2
|
import Editor from './Editor.svelte';
|
|
3
|
-
import { emptySchema, sendUserToast } from '
|
|
3
|
+
import { emptySchema, sendUserToast } from '../utils';
|
|
4
4
|
import Tooltip from './Tooltip.svelte';
|
|
5
5
|
import TableCustom from './TableCustom.svelte';
|
|
6
6
|
export let schema = emptySchema();
|
|
@@ -47,16 +47,16 @@ export async function main(x: string, y: string = 'default arg') {
|
|
|
47
47
|
</script>
|
|
48
48
|
|
|
49
49
|
<script>import { ScriptService } from '../../gen';
|
|
50
|
-
import { emptySchema, sendUserToast } from '
|
|
50
|
+
import { emptySchema, sendUserToast } from '../utils';
|
|
51
51
|
import { onDestroy } from 'svelte';
|
|
52
52
|
import ScriptEditor from './ScriptEditor.svelte';
|
|
53
53
|
import { page } from '$app/stores';
|
|
54
54
|
import { goto } from '$app/navigation';
|
|
55
55
|
import Path from './Path.svelte';
|
|
56
56
|
import SvelteMarkdown from 'svelte-markdown';
|
|
57
|
-
import { workspaceStore } from '
|
|
57
|
+
import { workspaceStore } from '../stores';
|
|
58
58
|
import ScriptSchema from './ScriptSchema.svelte';
|
|
59
|
-
import { inferArgs } from '
|
|
59
|
+
import { inferArgs } from '../infer';
|
|
60
60
|
import Required from './Required.svelte';
|
|
61
61
|
import RadioButton from './RadioButton.svelte';
|
|
62
62
|
let editor;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<script>import { JobService, Job, CompletedJob, VariableService, ResourceService, ScriptService } from '../../gen';
|
|
2
|
-
import { sendUserToast, emptySchema, displayDate } from '
|
|
2
|
+
import { sendUserToast, emptySchema, displayDate } from '../utils';
|
|
3
3
|
import { fade } from 'svelte/transition';
|
|
4
4
|
import Icon from 'svelte-awesome';
|
|
5
5
|
import { faCheck, faChevronDown, faChevronUp, faExclamationTriangle, faMagic, faSearch, faSpinner, faTimes } from '@fortawesome/free-solid-svg-icons';
|
|
6
6
|
import Editor from './Editor.svelte';
|
|
7
7
|
import Tooltip from './Tooltip.svelte';
|
|
8
8
|
import { onDestroy, onMount } from 'svelte';
|
|
9
|
-
import { userStore, workspaceStore } from '
|
|
9
|
+
import { userStore, workspaceStore } from '../stores';
|
|
10
10
|
import TableCustom from './TableCustom.svelte';
|
|
11
11
|
import { check } from 'svelte-awesome/icons';
|
|
12
12
|
import Modal from './Modal.svelte';
|
|
@@ -16,7 +16,7 @@ import github from 'svelte-highlight/styles/github';
|
|
|
16
16
|
import ItemPicker from './ItemPicker.svelte';
|
|
17
17
|
import VariableEditor from './VariableEditor.svelte';
|
|
18
18
|
import ResourceEditor from './ResourceEditor.svelte';
|
|
19
|
-
import { inferArgs } from '
|
|
19
|
+
import { inferArgs } from '../infer';
|
|
20
20
|
// @ts-ignore
|
|
21
21
|
import { VSplitPane } from 'svelte-split-pane';
|
|
22
22
|
import SchemaForm from './SchemaForm.svelte';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
<script>import { sendUserToast } from '
|
|
1
|
+
<script>import { sendUserToast } from '../utils';
|
|
2
2
|
import { ScriptService, FlowService, Script } from '../../gen';
|
|
3
3
|
import Icon from 'svelte-awesome';
|
|
4
4
|
import { faSearch } from '@fortawesome/free-solid-svg-icons';
|
|
5
|
-
import { hubScripts, workspaceStore } from '
|
|
5
|
+
import { hubScripts, workspaceStore } from '../stores';
|
|
6
6
|
import { createEventDispatcher } from 'svelte';
|
|
7
7
|
import ItemPicker from './ItemPicker.svelte';
|
|
8
8
|
import RadioButton from './RadioButton.svelte';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<script>import Modal from './Modal.svelte';
|
|
2
2
|
import TableCustom from './TableCustom.svelte';
|
|
3
3
|
import { GranularAclService } from '../../gen/services/GranularAclService';
|
|
4
|
-
import { sendUserToast } from '
|
|
4
|
+
import { sendUserToast } from '../utils';
|
|
5
5
|
import { GroupService, UserService } from '../../gen';
|
|
6
6
|
import { createEventDispatcher } from 'svelte';
|
|
7
7
|
import AutoComplete from 'simple-svelte-autocomplete';
|
|
8
|
-
import { workspaceStore } from '
|
|
8
|
+
import { workspaceStore } from '../stores';
|
|
9
9
|
const dispatch = createEventDispatcher();
|
|
10
10
|
export let kind;
|
|
11
11
|
export let path = '';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<script>import Password from './Password.svelte';
|
|
2
|
-
import { sendUserToast } from '
|
|
2
|
+
import { sendUserToast } from '../utils';
|
|
3
3
|
import { VariableService } from '../../gen';
|
|
4
4
|
import AutosizedTextarea from './AutosizedTextarea.svelte';
|
|
5
5
|
import Path from './Path.svelte';
|
|
6
6
|
import Modal from './Modal.svelte';
|
|
7
7
|
import { createEventDispatcher } from 'svelte';
|
|
8
|
-
import { workspaceStore } from '
|
|
8
|
+
import { workspaceStore } from '../stores';
|
|
9
9
|
import Required from './Required.svelte';
|
|
10
10
|
const dispatch = createEventDispatcher();
|
|
11
11
|
let path = '';
|
package/infer.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ScriptService } from '../gen';
|
|
2
|
+
import { sendUserToast } from './utils';
|
|
3
|
+
export async function inferArgs(language, code, schema) {
|
|
4
|
+
try {
|
|
5
|
+
let inferedSchema;
|
|
6
|
+
if (language == 'python3') {
|
|
7
|
+
inferedSchema = await ScriptService.pythonToJsonschema({
|
|
8
|
+
requestBody: code
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
else if (language == 'deno') {
|
|
12
|
+
inferedSchema = await ScriptService.denoToJsonschema({
|
|
13
|
+
requestBody: code
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
schema.required = [];
|
|
20
|
+
const oldProperties = Object.assign({}, schema.properties);
|
|
21
|
+
schema.properties = {};
|
|
22
|
+
for (const arg of inferedSchema.args) {
|
|
23
|
+
if (!(arg.name in oldProperties)) {
|
|
24
|
+
schema.properties[arg.name] = { description: '', type: '' };
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
schema.properties[arg.name] = oldProperties[arg.name];
|
|
28
|
+
}
|
|
29
|
+
argSigToJsonSchemaType(arg.typ, schema.properties[arg.name]);
|
|
30
|
+
schema.properties[arg.name].default = arg.default;
|
|
31
|
+
if (!arg.has_default) {
|
|
32
|
+
schema.required.push(arg.name);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
console.error(err);
|
|
38
|
+
sendUserToast(`Could not infer schema: ${err.body ?? err}`, true);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function argSigToJsonSchemaType(t, s) {
|
|
42
|
+
if (t === 'int') {
|
|
43
|
+
s.type = 'integer';
|
|
44
|
+
}
|
|
45
|
+
else if (t === 'float') {
|
|
46
|
+
s.type = 'number';
|
|
47
|
+
}
|
|
48
|
+
else if (t === 'bool') {
|
|
49
|
+
s.type = 'boolean';
|
|
50
|
+
}
|
|
51
|
+
else if (t === 'str') {
|
|
52
|
+
s.type = 'string';
|
|
53
|
+
}
|
|
54
|
+
else if (t === 'dict') {
|
|
55
|
+
s.type = 'object';
|
|
56
|
+
}
|
|
57
|
+
else if (t === 'bytes') {
|
|
58
|
+
s.type = 'string';
|
|
59
|
+
s.contentEncoding = 'base64';
|
|
60
|
+
}
|
|
61
|
+
else if (t === 'datetime') {
|
|
62
|
+
s.type = 'string';
|
|
63
|
+
s.format = 'date-time';
|
|
64
|
+
}
|
|
65
|
+
else if (typeof t !== 'string' && `resource` in t) {
|
|
66
|
+
s.type = 'object';
|
|
67
|
+
s.format = `resource-${t.resource}`;
|
|
68
|
+
}
|
|
69
|
+
else if (typeof t !== 'string' && `list` in t) {
|
|
70
|
+
s.type = 'array';
|
|
71
|
+
if (t.list === 'int' || t.list === 'float') {
|
|
72
|
+
s.items = { type: 'number' };
|
|
73
|
+
}
|
|
74
|
+
else if (t.list === 'bytes') {
|
|
75
|
+
s.items = { type: 'string', contentEncoding: 'base64' };
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
s.items = { type: 'string' };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
File without changes
|
|
@@ -17,8 +17,8 @@ declare const __propDef: {
|
|
|
17
17
|
disabled?: boolean | undefined;
|
|
18
18
|
editableSchema?: boolean | undefined;
|
|
19
19
|
itemsType?: {
|
|
20
|
-
type?: "string" | "number" | undefined;
|
|
21
|
-
contentEncoding?:
|
|
20
|
+
type?: "string" | "number" | "bytes" | undefined;
|
|
21
|
+
contentEncoding?: "base64" | undefined;
|
|
22
22
|
} | undefined;
|
|
23
23
|
displayHeader?: boolean | undefined;
|
|
24
24
|
evalValueToRaw?: (() => void) | undefined;
|
|
@@ -7,7 +7,8 @@ declare const __propDef: {
|
|
|
7
7
|
type?: string | undefined;
|
|
8
8
|
required?: boolean | undefined;
|
|
9
9
|
itemsType?: {
|
|
10
|
-
type?: "string" | "number" | undefined;
|
|
10
|
+
type?: "string" | "number" | "bytes" | undefined;
|
|
11
|
+
contentEncoding?: "base64" | undefined;
|
|
11
12
|
} | undefined;
|
|
12
13
|
};
|
|
13
14
|
events: {
|
|
File without changes
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { UserWorkspaceList } from './gen';
|
|
2
1
|
export interface UserExt {
|
|
3
2
|
email: string;
|
|
4
3
|
username: string;
|
|
@@ -9,7 +8,7 @@ export interface UserExt {
|
|
|
9
8
|
}
|
|
10
9
|
export declare const userStore: import("svelte/store").Writable<UserExt | undefined>;
|
|
11
10
|
export declare const workspaceStore: import("svelte/store").Writable<string | undefined>;
|
|
12
|
-
export declare const usersWorkspaceStore: import("svelte/store").Writable<
|
|
11
|
+
export declare const usersWorkspaceStore: import("svelte/store").Writable<any>;
|
|
13
12
|
export declare const superadmin: import("svelte/store").Writable<false | String | undefined>;
|
|
14
13
|
export declare const hubScripts: import("svelte/store").Writable<{
|
|
15
14
|
path: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "windmill-components",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.1",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@sveltejs/adapter-node": "^1.0.0-next.78",
|
|
6
6
|
"@sveltejs/adapter-static": "^1.0.0-next.34",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"exports": {
|
|
50
50
|
"./package.json": "./package.json",
|
|
51
|
+
"./common": "./common.js",
|
|
51
52
|
"./components/ArgInfo.svelte": "./components/ArgInfo.svelte",
|
|
52
53
|
"./components/ArgInput.svelte": "./components/ArgInput.svelte",
|
|
53
54
|
"./components/AutosizedTextarea.svelte": "./components/AutosizedTextarea.svelte",
|
|
@@ -105,6 +106,9 @@
|
|
|
105
106
|
"./components/icons/Mail.svelte": "./components/icons/Mail.svelte",
|
|
106
107
|
"./components/icons/Mysql.svelte": "./components/icons/Mysql.svelte",
|
|
107
108
|
"./components/icons/PostgresIcon.svelte": "./components/icons/PostgresIcon.svelte",
|
|
108
|
-
"./components/icons/Slack.svelte": "./components/icons/Slack.svelte"
|
|
109
|
+
"./components/icons/Slack.svelte": "./components/icons/Slack.svelte",
|
|
110
|
+
"./infer": "./infer.js",
|
|
111
|
+
"./stores": "./stores.js",
|
|
112
|
+
"./utils": "./utils.js"
|
|
109
113
|
}
|
|
110
|
-
}
|
|
114
|
+
}
|
package/stores.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { browser } from '$app/env';
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
import { getUserExt } from './utils';
|
|
4
|
+
let persistedWorkspace = browser && localStorage.getItem('workspace');
|
|
5
|
+
export const userStore = writable(undefined);
|
|
6
|
+
export const workspaceStore = writable(persistedWorkspace ? String(persistedWorkspace) : undefined);
|
|
7
|
+
export const usersWorkspaceStore = writable(undefined);
|
|
8
|
+
export const superadmin = writable(undefined);
|
|
9
|
+
export const hubScripts = writable(undefined);
|
|
10
|
+
if (browser) {
|
|
11
|
+
workspaceStore.subscribe(async (workspace) => {
|
|
12
|
+
if (workspace) {
|
|
13
|
+
localStorage.setItem('workspace', String(workspace));
|
|
14
|
+
userStore.set(await getUserExt(workspace));
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
userStore.set(undefined);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export function clearStores() {
|
|
22
|
+
userStore.set(undefined);
|
|
23
|
+
workspaceStore.set(undefined);
|
|
24
|
+
usersWorkspaceStore.set(undefined);
|
|
25
|
+
superadmin.set(undefined);
|
|
26
|
+
}
|
package/utils.js
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
|
+
import { goto } from '$app/navigation';
|
|
3
|
+
import { toast } from '@zerodevx/svelte-toast';
|
|
4
|
+
import { get } from 'svelte/store';
|
|
5
|
+
import { ScriptService, UserService } from '../gen';
|
|
6
|
+
import { inferArgs } from './infer';
|
|
7
|
+
import { clearStores, superadmin, workspaceStore } from './stores';
|
|
8
|
+
export function isToday(someDate) {
|
|
9
|
+
const today = new Date();
|
|
10
|
+
return (someDate.getDate() == today.getDate() &&
|
|
11
|
+
someDate.getMonth() == today.getMonth() &&
|
|
12
|
+
someDate.getFullYear() == today.getFullYear());
|
|
13
|
+
}
|
|
14
|
+
export function daysAgo(someDate) {
|
|
15
|
+
const today = new Date();
|
|
16
|
+
return Math.floor((today.getTime() - someDate.getTime()) / 86400000);
|
|
17
|
+
}
|
|
18
|
+
export function secondsAgo(date) {
|
|
19
|
+
return Math.floor((new Date().getTime() - date.getTime()) / 1000);
|
|
20
|
+
}
|
|
21
|
+
export function displayDaysAgo(dateString) {
|
|
22
|
+
const date = new Date(dateString);
|
|
23
|
+
const nbSecondsAgo = secondsAgo(date);
|
|
24
|
+
if (nbSecondsAgo < 600) {
|
|
25
|
+
return `${nbSecondsAgo}s ago`;
|
|
26
|
+
}
|
|
27
|
+
else if (isToday(date)) {
|
|
28
|
+
return `today at ${date.toLocaleTimeString()}`;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return `${daysAgo(date) + 1} days ago`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function displayDate(dateString) {
|
|
35
|
+
const date = new Date(dateString ?? '');
|
|
36
|
+
if (date.toString() === 'Invalid Date') {
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()} at ${date.toLocaleTimeString()}`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function getToday() {
|
|
44
|
+
var today = new Date();
|
|
45
|
+
return today;
|
|
46
|
+
}
|
|
47
|
+
export function sendUserToast(message, error = false) {
|
|
48
|
+
if (error) {
|
|
49
|
+
toast.push(message, {
|
|
50
|
+
theme: {
|
|
51
|
+
'--toastBackground': '#FEE2E2',
|
|
52
|
+
'--toastBarBackground': '#FEE2E2'
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else
|
|
57
|
+
toast.push(message);
|
|
58
|
+
}
|
|
59
|
+
export function truncateHash(hash) {
|
|
60
|
+
if (hash.length >= 6) {
|
|
61
|
+
return hash.substr(hash.length - 6);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return hash;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export async function getUserExt(workspace) {
|
|
68
|
+
try {
|
|
69
|
+
const user = await UserService.whoami({ workspace });
|
|
70
|
+
return mapUserToUserExt(user);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export function logoutWithRedirect(rd) {
|
|
77
|
+
const error = encodeURIComponent('You have been logged out because your session has expired.');
|
|
78
|
+
goto(`/user/login?error=${error}${rd ? '&rd=' + encodeURIComponent(rd) : ''}`);
|
|
79
|
+
}
|
|
80
|
+
export function sleep(ms) {
|
|
81
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
82
|
+
}
|
|
83
|
+
export function validatePassword(password) {
|
|
84
|
+
const re = /^(?=.*[\d])(?=.*[!@#$%^&*])[\w!@#$%^&*]{8,30}$/;
|
|
85
|
+
return re.test(password);
|
|
86
|
+
}
|
|
87
|
+
export async function refreshSuperadmin() {
|
|
88
|
+
if (get(superadmin) == undefined) {
|
|
89
|
+
UserService.globalWhoami().then((x) => {
|
|
90
|
+
if (x.super_admin) {
|
|
91
|
+
superadmin.set(x.email);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
superadmin.set(false);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export async function logout(logoutMessage) {
|
|
100
|
+
try {
|
|
101
|
+
clearStores();
|
|
102
|
+
await UserService.logout();
|
|
103
|
+
goto(`/user/login${logoutMessage ? '?error=' + encodeURIComponent(logoutMessage) : ''}`);
|
|
104
|
+
sendUserToast('you have been logged out');
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
goto(`/user/login?error=${encodeURIComponent('There was a problem logging you out, check the logs')}`);
|
|
108
|
+
console.error(error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
112
|
+
export function clickOutside(node) {
|
|
113
|
+
const handleClick = (event) => {
|
|
114
|
+
if (node && !node.contains(event.target) && !event.defaultPrevented) {
|
|
115
|
+
node.dispatchEvent(new CustomEvent('click_outside', node));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
document.addEventListener('click', handleClick, true);
|
|
119
|
+
return {
|
|
120
|
+
destroy() {
|
|
121
|
+
document.removeEventListener('click', handleClick, true);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export async function loadSchema(path) {
|
|
126
|
+
if (path.startsWith('hub/')) {
|
|
127
|
+
const code = await ScriptService.getHubScriptContentByPath({ path });
|
|
128
|
+
const schema = emptySchema();
|
|
129
|
+
await inferArgs('deno', code, schema);
|
|
130
|
+
return schema;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const script = await ScriptService.getScriptByPath({
|
|
134
|
+
workspace: get(workspaceStore),
|
|
135
|
+
path: path ?? ''
|
|
136
|
+
});
|
|
137
|
+
return script.schema;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export function emptySchema() {
|
|
141
|
+
return {
|
|
142
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
143
|
+
properties: {},
|
|
144
|
+
required: [],
|
|
145
|
+
type: 'object'
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export function simpleSchema() {
|
|
149
|
+
return {
|
|
150
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
151
|
+
type: 'object',
|
|
152
|
+
properties: {
|
|
153
|
+
name: {
|
|
154
|
+
description: 'The name to hello world to',
|
|
155
|
+
type: 'string'
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
required: []
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
export function removeItemAll(arr, value) {
|
|
162
|
+
var i = 0;
|
|
163
|
+
while (i < arr.length) {
|
|
164
|
+
if (arr[i] === value) {
|
|
165
|
+
arr.splice(i, 1);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
++i;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return arr;
|
|
172
|
+
}
|
|
173
|
+
export function canWrite(path, extra_perms, user) {
|
|
174
|
+
let keys = Object.keys(extra_perms);
|
|
175
|
+
if (!user) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
if (user.is_admin) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
let userOwner = `u/${user.username}`;
|
|
182
|
+
if (path.startsWith(userOwner)) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
if (keys.includes(userOwner) && extra_perms[userOwner]) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
if (user.pgroups.findIndex((x) => path.startsWith(x) || (keys.includes(x) && extra_perms[x])) != -1) {
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
export function removeKeysWithEmptyValues(obj) {
|
|
194
|
+
Object.keys(obj).forEach((key) => (obj[key] === undefined ? delete obj[key] : {}));
|
|
195
|
+
}
|
|
196
|
+
export function allTrue(dict) {
|
|
197
|
+
return Object.values(dict).every(Boolean);
|
|
198
|
+
}
|
|
199
|
+
export function forLater(scheduledString) {
|
|
200
|
+
return new Date() < new Date(scheduledString);
|
|
201
|
+
}
|
|
202
|
+
export function elapsedSinceSecs(date) {
|
|
203
|
+
return Math.round((new Date().getTime() - new Date(date).getTime()) / 1000);
|
|
204
|
+
}
|
|
205
|
+
export function groupBy(scripts, toGroup, dflts = []) {
|
|
206
|
+
let r = {};
|
|
207
|
+
for (const dflt of dflts) {
|
|
208
|
+
r[dflt] = [];
|
|
209
|
+
}
|
|
210
|
+
scripts.forEach((sc) => {
|
|
211
|
+
let section = toGroup(sc);
|
|
212
|
+
if (section in r) {
|
|
213
|
+
r[section].push(sc);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
r[section] = [sc];
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
return Object.entries(r).sort((s1, s2) => {
|
|
220
|
+
let n1 = s1[0];
|
|
221
|
+
let n2 = s2[0];
|
|
222
|
+
if (n1 > n2) {
|
|
223
|
+
return 1;
|
|
224
|
+
}
|
|
225
|
+
else if (n1 < n2) {
|
|
226
|
+
return -1;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
return 0;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
export function truncate(s, n, suffix = '...') {
|
|
234
|
+
if (s.length <= n) {
|
|
235
|
+
return s;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
return s.substring(0, n) + suffix;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
export function truncateRev(s, n, prefix = '...') {
|
|
242
|
+
if (s.length <= n) {
|
|
243
|
+
return s;
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
return prefix + s.substring(s.length - n, s.length);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
export function isString(value) {
|
|
250
|
+
return typeof value === 'string' || value instanceof String;
|
|
251
|
+
}
|
|
252
|
+
export function mapUserToUserExt(user) {
|
|
253
|
+
return {
|
|
254
|
+
...user,
|
|
255
|
+
groups: user.groups,
|
|
256
|
+
pgroups: user.groups.map((x) => `g/${x}`)
|
|
257
|
+
};
|
|
258
|
+
}
|