@lobb-js/studio 0.1.31 → 0.1.33
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.json +24 -14
- package/src/{Studio.svelte → lib/components/Studio.svelte} +8 -8
- package/src/lib/components/dataTable/childRecords.svelte +1 -1
- package/src/lib/components/detailView/create/children.svelte +1 -1
- package/src/lib/components/detailView/create/createDetailView.svelte +1 -1
- package/src/lib/components/detailView/fieldInput.svelte +1 -1
- package/src/lib/components/detailView/update/children.svelte +1 -1
- package/src/lib/components/detailView/update/updateDetailView.svelte +1 -1
- package/src/lib/components/extensionsComponents.svelte +1 -2
- package/src/lib/components/miniSidebar.svelte +1 -1
- package/{vite-plugin-contextual-lib.js → vite-plugins/contextual-lib-alias.js} +2 -7
- package/vite-plugins/index.js +21 -0
- package/vite-plugins/studio-source-resolver.js +41 -0
- package/.env.example +0 -1
- package/.storybook/main.ts +0 -31
- package/.storybook/preview.ts +0 -21
- package/.storybook/vitest.setup.ts +0 -7
- package/components.json +0 -16
- package/docker-entrypoint.sh +0 -7
- package/dockerfile +0 -27
- package/index.html +0 -13
- package/public/lobb.svg +0 -15
- package/src/app.css +0 -121
- package/src/components-export.ts +0 -21
- package/src/extensions/extension.types.ts +0 -93
- package/src/extensions/extensionUtils.ts +0 -192
- package/src/lib/Lobb.ts +0 -241
- package/src/lib/eventSystem.ts +0 -38
- package/src/lib/index.ts +0 -40
- package/src/lib/store.svelte.ts +0 -21
- package/src/lib/store.types.ts +0 -28
- package/src/lib/utils.ts +0 -84
- package/src/main.ts +0 -18
- package/src/routes/collections/collection.svelte +0 -46
- package/src/routes/collections/collections.svelte +0 -43
- package/src/routes/data_model/dataModel.svelte +0 -40
- package/src/routes/data_model/flow.css +0 -22
- package/src/routes/data_model/flow.svelte +0 -82
- package/src/routes/data_model/syncManager.svelte +0 -93
- package/src/routes/data_model/utils.ts +0 -35
- package/src/routes/extensions/extension.svelte +0 -16
- package/src/routes/home.svelte +0 -36
- package/src/routes/workflows/workflows.svelte +0 -135
- package/src/stories/Configure.mdx +0 -364
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +0 -1
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +0 -1
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +0 -1
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +0 -1
- package/src/stories/assets/youtube.svg +0 -1
- package/src/stories/detailView/detailViewForm.stories.svelte +0 -79
- package/src/stories/examples/Button.stories.svelte +0 -31
- package/src/stories/examples/Button.svelte +0 -30
- package/src/stories/examples/Header.stories.svelte +0 -26
- package/src/stories/examples/Header.svelte +0 -45
- package/src/stories/examples/Page.stories.svelte +0 -29
- package/src/stories/examples/Page.svelte +0 -70
- package/src/stories/examples/button.css +0 -30
- package/src/stories/examples/header.css +0 -32
- package/src/stories/examples/page.css +0 -68
- package/src/vite-env.d.ts +0 -2
- package/svelte.config.js +0 -7
- package/todo.md +0 -24
- package/tsconfig.app.json +0 -25
- package/tsconfig.json +0 -14
- package/tsconfig.node.json +0 -24
- package/vite.build.svelte.config.ts +0 -18
- package/vite.config.ts +0 -84
- package/vite.extension.config.ts +0 -81
- package/vite_utils.ts +0 -28
- package/vitest.shims.d.ts +0 -1
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type { Lobb } from "$lib/Lobb";
|
|
2
|
-
import type { CTX } from "../lib/store.types";
|
|
3
|
-
import type { Button } from "$lib/components/ui/button";
|
|
4
|
-
import type { Input } from "$lib/components/ui/input";
|
|
5
|
-
import type { Separator } from "$lib/components/ui/separator";
|
|
6
|
-
import type { Skeleton } from "$lib/components/ui/skeleton";
|
|
7
|
-
import type LlmButton from "$lib/components/LlmButton.svelte";
|
|
8
|
-
import type Sidebar from "$lib/components/sidebar/sidebar.svelte";
|
|
9
|
-
import type SidebarTrigger from "$lib/components/sidebar/sidebarTrigger.svelte";
|
|
10
|
-
import type CreateDetailViewButton from "$lib/components/detailView/create/createDetailViewButton.svelte";
|
|
11
|
-
import type UpdateDetailViewButton from "$lib/components/detailView/update/updateDetailViewButton.svelte";
|
|
12
|
-
import type { getFileFromUser, mediaQueries } from "$lib/utils";
|
|
13
|
-
import type Table from "$lib/components/dataTable/table.svelte";
|
|
14
|
-
import type { Location } from "@wjfe/n-savant";
|
|
15
|
-
import type RangeCalendarButton from "$lib/components/rangeCalendarButton.svelte";
|
|
16
|
-
import type DataTable from "$lib/components/dataTable/dataTable.svelte";
|
|
17
|
-
import type Drawer from "$lib/components/drawer.svelte";
|
|
18
|
-
import type SelectRecord from "$lib/components/selectRecord.svelte";
|
|
19
|
-
import * as Popover from "$lib/components/ui/popover";
|
|
20
|
-
import * as intlDate from "@internationalized/date";
|
|
21
|
-
import * as Icons from "lucide-svelte"
|
|
22
|
-
import { ContextMenu } from "bits-ui";
|
|
23
|
-
import * as Tooltip from "$lib/components/ui/tooltip";
|
|
24
|
-
import * as Breadcrumb from "$lib/components/ui/breadcrumb";
|
|
25
|
-
import { showDialog } from "$lib/components/confirmationDialog/store.svelte";
|
|
26
|
-
import { toast } from "svelte-sonner";
|
|
27
|
-
import type Drawer from "$lib/components/drawer.svelte";
|
|
28
|
-
import { Switch } from "$lib/components/ui/switch";
|
|
29
|
-
|
|
30
|
-
// extensions utils
|
|
31
|
-
export interface Components {
|
|
32
|
-
Button: typeof Button;
|
|
33
|
-
Input: typeof Input;
|
|
34
|
-
Separator: typeof Separator;
|
|
35
|
-
Skeleton: typeof Skeleton;
|
|
36
|
-
LlmButton: typeof LlmButton;
|
|
37
|
-
Sidebar: typeof Sidebar;
|
|
38
|
-
SidebarTrigger: typeof SidebarTrigger;
|
|
39
|
-
CreateDetailViewButton: typeof CreateDetailViewButton;
|
|
40
|
-
UpdateDetailViewButton: typeof UpdateDetailViewButton;
|
|
41
|
-
Tooltip: typeof Tooltip;
|
|
42
|
-
Breadcrumb: typeof Breadcrumb;
|
|
43
|
-
ContextMenu: typeof ContextMenu;
|
|
44
|
-
Popover: typeof Popover;
|
|
45
|
-
Icons: typeof Icons;
|
|
46
|
-
Table: typeof Table;
|
|
47
|
-
RangeCalendarButton: typeof RangeCalendarButton;
|
|
48
|
-
DataTable: typeof DataTable;
|
|
49
|
-
Drawer: typeof Drawer;
|
|
50
|
-
SelectRecord: typeof SelectRecord,
|
|
51
|
-
Switch: typeof Switch,
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface ExtensionUtils {
|
|
55
|
-
ctx: CTX;
|
|
56
|
-
lobb: Lobb;
|
|
57
|
-
location: Location;
|
|
58
|
-
toast: typeof toast;
|
|
59
|
-
showDialog: typeof showDialog;
|
|
60
|
-
getFileFromUser: typeof getFileFromUser;
|
|
61
|
-
components: Components;
|
|
62
|
-
mediaQueries: typeof mediaQueries;
|
|
63
|
-
intlDate: typeof intlDate;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// dashboard nav
|
|
67
|
-
interface DashboardNav {
|
|
68
|
-
label: string;
|
|
69
|
-
icon: any;
|
|
70
|
-
href?: string;
|
|
71
|
-
onclick?: () => void;
|
|
72
|
-
navs?: DashboardNav[];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface DashboardNavs {
|
|
76
|
-
top?: DashboardNav[];
|
|
77
|
-
middle?: DashboardNav[];
|
|
78
|
-
bottom?: DashboardNav[];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// extension components base Props
|
|
82
|
-
export interface ExtensionProps {
|
|
83
|
-
utils: ExtensionUtils;
|
|
84
|
-
[key: string]: any;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// extension exported object
|
|
88
|
-
export interface Extension {
|
|
89
|
-
name: string;
|
|
90
|
-
onStartup?: (utils: ExtensionUtils) => Promise<void>;
|
|
91
|
-
components?: Record<string, any>;
|
|
92
|
-
dashboardNavs?: DashboardNavs;
|
|
93
|
-
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Components,
|
|
3
|
-
DashboardNavs,
|
|
4
|
-
Extension,
|
|
5
|
-
ExtensionUtils,
|
|
6
|
-
} from "./extension.types";
|
|
7
|
-
import { lobb } from "$lib";
|
|
8
|
-
import { ctx } from "$lib/store.svelte";
|
|
9
|
-
import { toast } from "svelte-sonner";
|
|
10
|
-
import { showDialog } from "$lib/components/confirmationDialog/store.svelte";
|
|
11
|
-
import { Button } from "$lib/components/ui/button";
|
|
12
|
-
import { Input } from "$lib/components/ui/input";
|
|
13
|
-
import { Separator } from "$lib/components/ui/separator";
|
|
14
|
-
import { Skeleton } from "$lib/components/ui/skeleton";
|
|
15
|
-
import Table from "$lib/components/dataTable/table.svelte";
|
|
16
|
-
import { getFileFromUser, mediaQueries } from "$lib/utils";
|
|
17
|
-
import LlmButton from "$lib/components/LlmButton.svelte";
|
|
18
|
-
import Sidebar from "$lib/components/sidebar/sidebar.svelte";
|
|
19
|
-
import SidebarTrigger from "$lib/components/sidebar/sidebarTrigger.svelte";
|
|
20
|
-
import CreateDetailViewButton from "$lib/components/detailView/create/createDetailViewButton.svelte";
|
|
21
|
-
import UpdateDetailViewButton from "$lib/components/detailView/update/updateDetailViewButton.svelte";
|
|
22
|
-
import * as intlDate from "@internationalized/date";
|
|
23
|
-
import * as Tooltip from "$lib/components/ui/tooltip";
|
|
24
|
-
import * as Breadcrumb from "$lib/components/ui/breadcrumb";
|
|
25
|
-
import { ContextMenu } from "bits-ui";
|
|
26
|
-
import * as Popover from "$lib/components/ui/popover";
|
|
27
|
-
import * as Icons from "lucide-svelte";
|
|
28
|
-
import { location } from "@wjfe/n-savant";
|
|
29
|
-
import RangeCalendarButton from "$lib/components/rangeCalendarButton.svelte";
|
|
30
|
-
import DataTable from "$lib/components/dataTable/dataTable.svelte";
|
|
31
|
-
import Drawer from "$lib/components/drawer.svelte";
|
|
32
|
-
import SelectRecord from "$lib/components/selectRecord.svelte";
|
|
33
|
-
import { Switch } from "$lib/components/ui/switch";
|
|
34
|
-
|
|
35
|
-
export function getComponents(): Components {
|
|
36
|
-
return {
|
|
37
|
-
Button: Button,
|
|
38
|
-
Input: Input,
|
|
39
|
-
Separator: Separator,
|
|
40
|
-
Skeleton: Skeleton,
|
|
41
|
-
LlmButton: LlmButton,
|
|
42
|
-
Sidebar: Sidebar,
|
|
43
|
-
SidebarTrigger: SidebarTrigger,
|
|
44
|
-
CreateDetailViewButton: CreateDetailViewButton,
|
|
45
|
-
UpdateDetailViewButton: UpdateDetailViewButton,
|
|
46
|
-
Tooltip: Tooltip,
|
|
47
|
-
Breadcrumb: Breadcrumb,
|
|
48
|
-
ContextMenu: ContextMenu,
|
|
49
|
-
Popover: Popover,
|
|
50
|
-
Icons: Icons,
|
|
51
|
-
Table: Table,
|
|
52
|
-
RangeCalendarButton: RangeCalendarButton,
|
|
53
|
-
DataTable: DataTable,
|
|
54
|
-
Drawer: Drawer,
|
|
55
|
-
SelectRecord: SelectRecord,
|
|
56
|
-
Switch: Switch,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function getExtensionUtils(): ExtensionUtils {
|
|
61
|
-
return {
|
|
62
|
-
ctx: ctx,
|
|
63
|
-
lobb: lobb,
|
|
64
|
-
location: location,
|
|
65
|
-
toast: toast,
|
|
66
|
-
showDialog: showDialog,
|
|
67
|
-
getFileFromUser: getFileFromUser,
|
|
68
|
-
components: getComponents(),
|
|
69
|
-
mediaQueries: mediaQueries,
|
|
70
|
-
intlDate: intlDate,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function getExtensionsThatHasDash(): string[] {
|
|
75
|
-
const extensionNames = Object.keys(ctx.meta.extensions);
|
|
76
|
-
|
|
77
|
-
const extensionsWithDashExt = [];
|
|
78
|
-
for (let index = 0; index < extensionNames.length; index++) {
|
|
79
|
-
const extensionName = extensionNames[index];
|
|
80
|
-
const extensionMeta = ctx.meta.extensions[extensionName];
|
|
81
|
-
if (extensionMeta.hasDashboardExtension) {
|
|
82
|
-
extensionsWithDashExt.push(extensionName);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return extensionsWithDashExt;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export async function loadExtensions(studioExtensions?: any[]): Promise<Record<string, Extension>> {
|
|
90
|
-
const extensions: Record<string, Extension> = {};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (studioExtensions) {
|
|
94
|
-
for (let index = 0; index < studioExtensions.length; index++) {
|
|
95
|
-
const studioExtension = studioExtensions[index](getExtensionUtils());
|
|
96
|
-
extensions[studioExtension.name] = studioExtension;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const extensionsThatHasDash = getExtensionsThatHasDash();
|
|
101
|
-
for (let index = 0; index < extensionsThatHasDash.length; index++) {
|
|
102
|
-
const extensionName = extensionsThatHasDash[index];
|
|
103
|
-
|
|
104
|
-
// Try to import locally-installed extension by name first
|
|
105
|
-
if (extensionName && extensions[extensionName]) {
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Fall back to remote import
|
|
110
|
-
try {
|
|
111
|
-
extensions[extensionName] = (
|
|
112
|
-
await import(
|
|
113
|
-
/* @vite-ignore */ `${ctx.lobbUrl}/api/extensions/${extensionName}/dashboard?v=${ctx.meta.extensions[extensionName]?.version}`
|
|
114
|
-
)
|
|
115
|
-
).extension(getExtensionUtils());
|
|
116
|
-
} catch (error) {
|
|
117
|
-
console.warn(`Failed to load remote extension ${extensionName}`, error);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return extensions;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function loadExtensionComponents(
|
|
125
|
-
name: string,
|
|
126
|
-
filterByExtensions?: string[],
|
|
127
|
-
): any[] {
|
|
128
|
-
const components = [];
|
|
129
|
-
for (const [extensionName, extensionValue] of Object.entries(
|
|
130
|
-
ctx.extensions,
|
|
131
|
-
)) {
|
|
132
|
-
if (filterByExtensions && !filterByExtensions.includes(extensionName)) {
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
if (extensionValue.components) {
|
|
136
|
-
for (const [componentName, componentValue] of Object.entries(
|
|
137
|
-
extensionValue.components,
|
|
138
|
-
)) {
|
|
139
|
-
if (name.startsWith(componentName)) {
|
|
140
|
-
components.push(componentValue);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return components;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export async function executeExtensionsOnStartup() {
|
|
149
|
-
const extensionNames: string[] = Object.keys(ctx.extensions);
|
|
150
|
-
for (let index = 0; index < extensionNames.length; index++) {
|
|
151
|
-
const extensionName = extensionNames[index];
|
|
152
|
-
const extension = ctx.extensions[extensionName];
|
|
153
|
-
if (extension) {
|
|
154
|
-
if (extension.onStartup) {
|
|
155
|
-
await extension.onStartup(getExtensionUtils());
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function getDashboardNavs(): DashboardNavs {
|
|
162
|
-
let navs: DashboardNavs = {
|
|
163
|
-
top: [],
|
|
164
|
-
middle: [],
|
|
165
|
-
bottom: [],
|
|
166
|
-
};
|
|
167
|
-
const extensionNames: string[] = Object.keys(ctx.extensions);
|
|
168
|
-
for (let index = 0; index < extensionNames.length; index++) {
|
|
169
|
-
const extensionName = extensionNames[index];
|
|
170
|
-
const extension = ctx.extensions[extensionName];
|
|
171
|
-
if (extension) {
|
|
172
|
-
if (extension.dashboardNavs && extension.dashboardNavs.top && navs.top) {
|
|
173
|
-
navs.top = [...navs.top, ...extension.dashboardNavs.top];
|
|
174
|
-
}
|
|
175
|
-
if (
|
|
176
|
-
extension.dashboardNavs &&
|
|
177
|
-
extension.dashboardNavs.middle &&
|
|
178
|
-
navs.middle
|
|
179
|
-
) {
|
|
180
|
-
navs.middle = [...navs.middle, ...extension.dashboardNavs.middle];
|
|
181
|
-
}
|
|
182
|
-
if (
|
|
183
|
-
extension.dashboardNavs &&
|
|
184
|
-
extension.dashboardNavs.bottom &&
|
|
185
|
-
navs.bottom
|
|
186
|
-
) {
|
|
187
|
-
navs.bottom = [...navs.bottom, ...extension.dashboardNavs.bottom];
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return navs;
|
|
192
|
-
}
|
package/src/lib/Lobb.ts
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import qs from "qs";
|
|
2
|
-
import { parseFunction } from "./utils";
|
|
3
|
-
|
|
4
|
-
interface RouteParams {
|
|
5
|
-
method: string;
|
|
6
|
-
route: string;
|
|
7
|
-
payload?: any;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
type OnResponseHandlers = (reponse: Response) => void;
|
|
11
|
-
|
|
12
|
-
export class Lobb {
|
|
13
|
-
public lobbUrl: string;
|
|
14
|
-
private headers: HeadersInit = [];
|
|
15
|
-
private onResponseHandlers: Array<OnResponseHandlers> = [];
|
|
16
|
-
|
|
17
|
-
constructor(lobbUrl: string) {
|
|
18
|
-
this.lobbUrl = lobbUrl;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public async onResponse(callback: OnResponseHandlers) {
|
|
22
|
-
this.onResponseHandlers.push(callback);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public setHeaders(headers: HeadersInit) {
|
|
26
|
-
this.headers = headers;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public getHeaders() {
|
|
30
|
-
return this.headers;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public async getMeta() {
|
|
34
|
-
const response = await fetch(`${this.lobbUrl}/api/meta`, {
|
|
35
|
-
headers: this.headers,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const metaResponse = await this.handleResponse(response);
|
|
39
|
-
const meta = await metaResponse.json();
|
|
40
|
-
|
|
41
|
-
meta.studio_workflows = meta.studio_workflows.map((workflow: any) => {
|
|
42
|
-
return {
|
|
43
|
-
...workflow,
|
|
44
|
-
handler: parseFunction(workflow.handler),
|
|
45
|
-
};
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
return meta;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// CRUD methods
|
|
52
|
-
public async findAll(collectionName: string, params: any) {
|
|
53
|
-
const response = await fetch(
|
|
54
|
-
`${this.lobbUrl}/api/collections/${collectionName}/search`,
|
|
55
|
-
{
|
|
56
|
-
method: "POST",
|
|
57
|
-
headers: this.headers,
|
|
58
|
-
body: JSON.stringify(params),
|
|
59
|
-
},
|
|
60
|
-
);
|
|
61
|
-
return await this.handleResponse(response);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public async findOne(
|
|
65
|
-
collectionName: string,
|
|
66
|
-
id: string,
|
|
67
|
-
queryParams?: any,
|
|
68
|
-
) {
|
|
69
|
-
queryParams = queryParams ? `?${qs.stringify(queryParams)}` : "";
|
|
70
|
-
const response = await fetch(
|
|
71
|
-
`${this.lobbUrl}/api/collections/${collectionName}/${id}${queryParams}`,
|
|
72
|
-
{
|
|
73
|
-
method: "GET",
|
|
74
|
-
headers: this.headers,
|
|
75
|
-
},
|
|
76
|
-
);
|
|
77
|
-
return await this.handleResponse(response);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public async createOne(collectionName: string, body: any, file?: File) {
|
|
81
|
-
if (file) {
|
|
82
|
-
const formData = new FormData();
|
|
83
|
-
Object.keys(body).forEach((key) => {
|
|
84
|
-
formData.append(key, body[key]);
|
|
85
|
-
});
|
|
86
|
-
formData.append("file", file, file.name);
|
|
87
|
-
formData.append(
|
|
88
|
-
"payload",
|
|
89
|
-
JSON.stringify({
|
|
90
|
-
data: body,
|
|
91
|
-
}),
|
|
92
|
-
);
|
|
93
|
-
body = formData;
|
|
94
|
-
} else {
|
|
95
|
-
body = JSON.stringify({
|
|
96
|
-
data: body,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
const response = await fetch(
|
|
100
|
-
`${this.lobbUrl}/api/collections/${collectionName}`,
|
|
101
|
-
{
|
|
102
|
-
method: "POST",
|
|
103
|
-
headers: this.headers,
|
|
104
|
-
body,
|
|
105
|
-
},
|
|
106
|
-
);
|
|
107
|
-
return await this.handleResponse(response);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
public async updateOne(collectionName: string, id: string, body: any) {
|
|
111
|
-
const response = await fetch(
|
|
112
|
-
`${this.lobbUrl}/api/collections/${collectionName}/${id}`,
|
|
113
|
-
{
|
|
114
|
-
method: "PATCH",
|
|
115
|
-
headers: this.headers,
|
|
116
|
-
body: JSON.stringify({
|
|
117
|
-
data: body,
|
|
118
|
-
}),
|
|
119
|
-
},
|
|
120
|
-
);
|
|
121
|
-
return await this.handleResponse(response);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
public async readSingleton(
|
|
125
|
-
collectionName: string,
|
|
126
|
-
) {
|
|
127
|
-
const response = await fetch(
|
|
128
|
-
`${this.lobbUrl}/api/collections/${collectionName}/singleton`,
|
|
129
|
-
{
|
|
130
|
-
method: "GET",
|
|
131
|
-
headers: this.headers,
|
|
132
|
-
},
|
|
133
|
-
);
|
|
134
|
-
return await this.handleResponse(response);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public async updateSingleton(
|
|
138
|
-
collectionName: string,
|
|
139
|
-
body: Record<string, any>
|
|
140
|
-
) {
|
|
141
|
-
const response = await fetch(
|
|
142
|
-
`${this.lobbUrl}/api/collections/${collectionName}/singleton`,
|
|
143
|
-
{
|
|
144
|
-
method: "PATCH",
|
|
145
|
-
headers: this.headers,
|
|
146
|
-
body: JSON.stringify({
|
|
147
|
-
data: body,
|
|
148
|
-
}),
|
|
149
|
-
},
|
|
150
|
-
);
|
|
151
|
-
return await this.handleResponse(response);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
public async deleteOne(collectionName: string, id: string, force = false) {
|
|
155
|
-
const response = await fetch(
|
|
156
|
-
`${this.lobbUrl}/api/collections/${collectionName}/${id}${force ? "?force" : ""}`,
|
|
157
|
-
{
|
|
158
|
-
method: "DELETE",
|
|
159
|
-
headers: this.headers,
|
|
160
|
-
},
|
|
161
|
-
);
|
|
162
|
-
return await this.handleResponse(response);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
public async deleteMany(collectionName: string, filter: any, force = false) {
|
|
166
|
-
const response = await fetch(
|
|
167
|
-
`${this.lobbUrl}/api/collections/${collectionName}${force ? "?force" : ""}`,
|
|
168
|
-
{
|
|
169
|
-
method: "DELETE",
|
|
170
|
-
headers: this.headers,
|
|
171
|
-
body: JSON.stringify({
|
|
172
|
-
filter,
|
|
173
|
-
}),
|
|
174
|
-
},
|
|
175
|
-
);
|
|
176
|
-
return await this.handleResponse(response);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
public async createMany(collectionName: string, body: any) {
|
|
180
|
-
body = JSON.stringify({
|
|
181
|
-
data: body,
|
|
182
|
-
});
|
|
183
|
-
const response = await fetch(
|
|
184
|
-
`${this.lobbUrl}/api/collections/${collectionName}`,
|
|
185
|
-
{
|
|
186
|
-
method: "POST",
|
|
187
|
-
headers: this.headers,
|
|
188
|
-
body,
|
|
189
|
-
},
|
|
190
|
-
);
|
|
191
|
-
return await this.handleResponse(response);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
public async updateMany(collectionName: string, body: any, filter: any) {
|
|
195
|
-
const response = await fetch(
|
|
196
|
-
`${this.lobbUrl}/api/collections/${collectionName}`,
|
|
197
|
-
{
|
|
198
|
-
method: "PATCH",
|
|
199
|
-
headers: this.headers,
|
|
200
|
-
body: JSON.stringify({
|
|
201
|
-
filter,
|
|
202
|
-
data: body,
|
|
203
|
-
}),
|
|
204
|
-
},
|
|
205
|
-
);
|
|
206
|
-
return await this.handleResponse(response);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
public async transactions(body: any[], rollback?: boolean) {
|
|
210
|
-
const response = await fetch(
|
|
211
|
-
`${this.lobbUrl}/api/collections/transactions${
|
|
212
|
-
rollback ? "?rollback" : ""
|
|
213
|
-
}`,
|
|
214
|
-
{
|
|
215
|
-
method: "POST",
|
|
216
|
-
headers: this.headers,
|
|
217
|
-
body: JSON.stringify(body),
|
|
218
|
-
},
|
|
219
|
-
);
|
|
220
|
-
return await this.handleResponse(response);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// CUSTOM REQUEST methods
|
|
224
|
-
public async request(params: RouteParams) {
|
|
225
|
-
const response = await fetch(`${this.lobbUrl}${params.route}`, {
|
|
226
|
-
method: params.method,
|
|
227
|
-
headers: this.headers,
|
|
228
|
-
body: JSON.stringify(params.payload),
|
|
229
|
-
});
|
|
230
|
-
return await this.handleResponse(response);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// HELPER methods
|
|
234
|
-
private async handleResponse(response: Response): Promise<Response> {
|
|
235
|
-
for (let index = 0; index < this.onResponseHandlers.length; index++) {
|
|
236
|
-
const handler = this.onResponseHandlers[index];
|
|
237
|
-
handler(response.clone());
|
|
238
|
-
}
|
|
239
|
-
return response;
|
|
240
|
-
}
|
|
241
|
-
}
|
package/src/lib/eventSystem.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { toast } from "svelte-sonner";
|
|
2
|
-
import { ctx } from "./store.svelte";
|
|
3
|
-
import { openCreateDetailView, openUpdateDetailView } from "./components/detailView/store.svelte";
|
|
4
|
-
|
|
5
|
-
export async function emitEvent(eventName: string, input: Record<string, any>) {
|
|
6
|
-
const workflows = ctx.meta.studio_workflows.filter(
|
|
7
|
-
(workflow) => {
|
|
8
|
-
return eventName.startsWith(workflow.eventName);
|
|
9
|
-
},
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
for (let index = 0; index < workflows.length; index++) {
|
|
13
|
-
const workflow = workflows[index];
|
|
14
|
-
try {
|
|
15
|
-
const localOutput = await workflow.handler(
|
|
16
|
-
input,
|
|
17
|
-
await getEventContext(),
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
if (localOutput) {
|
|
21
|
-
input = localOutput;
|
|
22
|
-
}
|
|
23
|
-
} catch (error) {
|
|
24
|
-
toast.error((error as any).message);
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return input;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async function getEventContext() {
|
|
33
|
-
return {
|
|
34
|
-
toast,
|
|
35
|
-
openCreateDetailView,
|
|
36
|
-
openUpdateDetailView,
|
|
37
|
-
};
|
|
38
|
-
}
|
package/src/lib/index.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Lobb } from "./Lobb";
|
|
2
|
-
import { ctx } from "$lib/store.svelte";
|
|
3
|
-
import { toast } from "svelte-sonner";
|
|
4
|
-
|
|
5
|
-
export const lobb = new Lobb(ctx.lobbUrl);
|
|
6
|
-
|
|
7
|
-
// logging the message if got any bad responses
|
|
8
|
-
lobb.onResponse(async (response) => {
|
|
9
|
-
if (response.status >= 400) {
|
|
10
|
-
const body = await response.json();
|
|
11
|
-
toast.error(body.message);
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export function createSet(lastNumber: number): Set<number> {
|
|
16
|
-
const set = new Set() as Set<number>;
|
|
17
|
-
for (let i = 0; i <= lastNumber; i++) {
|
|
18
|
-
set.add(i);
|
|
19
|
-
}
|
|
20
|
-
return set;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function moveElement<T>(array: T[], fromIndex: number, toIndex: number) {
|
|
24
|
-
if (
|
|
25
|
-
fromIndex < 0 || fromIndex >= array.length || toIndex < 0 ||
|
|
26
|
-
toIndex >= array.length
|
|
27
|
-
) {
|
|
28
|
-
throw new Error("Index out of bounds");
|
|
29
|
-
}
|
|
30
|
-
const [element] = array.splice(fromIndex, 1);
|
|
31
|
-
array.splice(toIndex, 0, element);
|
|
32
|
-
return array;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function pxToRem(px: number) {
|
|
36
|
-
const rootFontSize = parseFloat(
|
|
37
|
-
getComputedStyle(document.documentElement).fontSize,
|
|
38
|
-
);
|
|
39
|
-
return px / rootFontSize;
|
|
40
|
-
}
|
package/src/lib/store.svelte.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { CTX } from './store.types';
|
|
2
|
-
import pkg from '../../package.json';
|
|
3
|
-
|
|
4
|
-
if (!window.APP_ENV) {
|
|
5
|
-
window.APP_ENV = {};
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (window.APP_ENV.LOBB_URL === '%LOBB_URL%') {
|
|
9
|
-
window.APP_ENV.LOBB_URL = null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const ctx: CTX = $state.raw({
|
|
13
|
-
studioVersion: pkg.version,
|
|
14
|
-
lobbUrl: window.APP_ENV.LOBB_URL || localStorage.getItem("lobb_url"),
|
|
15
|
-
extensions: {},
|
|
16
|
-
meta: {
|
|
17
|
-
collections: null,
|
|
18
|
-
extensions: null,
|
|
19
|
-
filter: null
|
|
20
|
-
},
|
|
21
|
-
});
|
package/src/lib/store.types.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Extension } from "../extensions/extension.types";
|
|
2
|
-
|
|
3
|
-
interface Collection {
|
|
4
|
-
category: string;
|
|
5
|
-
owner: string;
|
|
6
|
-
fields: Record<string, any>;
|
|
7
|
-
singleton: boolean;
|
|
8
|
-
}
|
|
9
|
-
type Collections = Record<string, Collection>;
|
|
10
|
-
|
|
11
|
-
interface Meta {
|
|
12
|
-
version: string;
|
|
13
|
-
relations: Array<any>;
|
|
14
|
-
collections: Collections;
|
|
15
|
-
extensions: Record<string, any>;
|
|
16
|
-
filter: any;
|
|
17
|
-
events: any[];
|
|
18
|
-
event_context_type: string;
|
|
19
|
-
studio_workflows: any[];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface CTX {
|
|
23
|
-
studioVersion: string;
|
|
24
|
-
lobbUrl: string | null;
|
|
25
|
-
extensions: Record<string, Extension>;
|
|
26
|
-
meta: Meta;
|
|
27
|
-
currentUrl: URL;
|
|
28
|
-
}
|