@sanity/workbench 0.1.0-alpha.1 → 0.1.0-alpha.10
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/dist/_chunks-es/index.js +34 -0
- package/dist/_chunks-es/index.js.map +1 -0
- package/dist/_internal.d.ts +38 -4
- package/dist/_internal.js +42 -26
- package/dist/_internal.js.map +1 -1
- package/dist/core.d.ts +1617 -0
- package/dist/core.js +779 -0
- package/dist/core.js.map +1 -0
- package/package.json +23 -8
- package/src/_exports/_internal.ts +1 -0
- package/src/_exports/core.ts +1 -0
- package/src/_internal/env.ts +32 -0
- package/src/_internal/index.ts +3 -1
- package/src/_internal/render.ts +82 -38
- package/src/core/applications/application-list.ts +104 -0
- package/src/core/applications/application.ts +95 -0
- package/src/core/canvases.ts +91 -0
- package/src/core/config.ts +34 -0
- package/src/core/index.ts +12 -0
- package/src/core/log/index.ts +92 -0
- package/src/core/media-libraries.ts +92 -0
- package/src/core/organizations.ts +115 -0
- package/src/core/projects.ts +114 -0
- package/src/core/shared/urls.ts +129 -0
- package/src/core/user-applications/core-app.ts +131 -0
- package/src/core/user-applications/studios/index.ts +3 -0
- package/src/core/user-applications/studios/schemas.ts +111 -0
- package/src/core/user-applications/studios/studio.ts +504 -0
- package/src/core/user-applications/studios/workspace.ts +147 -0
- package/src/core/user-applications/user-application.ts +181 -0
- package/src/vite-env.d.ts +8 -0
- package/dist/_internal.cjs +0 -38
- package/dist/_internal.cjs.map +0 -1
- package/dist/_internal.d.cts +0 -30
- package/src/env.d.ts +0 -7
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// eslint-disable-next-line no-restricted-imports
|
|
2
|
+
import type { ApplicationResource as ProtocolApplicationResource } from "@sanity/message-protocol";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
import { OrganizationId } from "../organizations";
|
|
6
|
+
import {
|
|
7
|
+
UserApplication,
|
|
8
|
+
UserApplicationBase,
|
|
9
|
+
ActiveDeployment,
|
|
10
|
+
} from "./user-application";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export const CoreAppUserApplicationManifest = z.object({
|
|
16
|
+
version: z.string(),
|
|
17
|
+
icon: z.string().optional(),
|
|
18
|
+
title: z.string().optional(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export type CoreAppUserApplicationManifest = z.output<
|
|
25
|
+
typeof CoreAppUserApplicationManifest
|
|
26
|
+
>;
|
|
27
|
+
|
|
28
|
+
const CoreAppUserApplicationBase = UserApplicationBase.extend({
|
|
29
|
+
title: z.string(),
|
|
30
|
+
organizationId: OrganizationId,
|
|
31
|
+
type: z.literal("coreApp"),
|
|
32
|
+
manifest: CoreAppUserApplicationManifest.nullable().optional(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const InternalCoreAppUserApplication = CoreAppUserApplicationBase.extend({
|
|
36
|
+
urlType: z.literal("internal"),
|
|
37
|
+
activeDeployment: ActiveDeployment.extend({
|
|
38
|
+
manifest: CoreAppUserApplicationManifest.nullable().optional(),
|
|
39
|
+
}),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const ExternalCoreAppUserApplication = CoreAppUserApplicationBase.extend({
|
|
43
|
+
urlType: z.literal("external"),
|
|
44
|
+
activeDeployment: z.null(),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Core application schema — validates and brands API
|
|
49
|
+
* responses from the `/user-applications?appType=coreApp`
|
|
50
|
+
* endpoint. Uses a discriminated union on `urlType`.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
const CoreAppUserApplication = z.discriminatedUnion("urlType", [
|
|
54
|
+
InternalCoreAppUserApplication,
|
|
55
|
+
ExternalCoreAppUserApplication,
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
export type CoreAppUserApplication = z.output<typeof CoreAppUserApplication>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Validates and parses a raw API response into a branded
|
|
65
|
+
* CoreAppUserApplicationData.
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
export function parseCoreApplication(data: unknown): CoreAppUserApplication {
|
|
69
|
+
return CoreAppUserApplication.parse(data);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
export class CoreAppApplication extends UserApplication<
|
|
76
|
+
CoreAppUserApplication,
|
|
77
|
+
"coreApp",
|
|
78
|
+
ProtocolApplicationResource
|
|
79
|
+
> {
|
|
80
|
+
readonly activeDeployment: CoreAppUserApplication["activeDeployment"];
|
|
81
|
+
|
|
82
|
+
constructor(
|
|
83
|
+
application: CoreAppUserApplication,
|
|
84
|
+
options: {
|
|
85
|
+
isLocal?: boolean;
|
|
86
|
+
remoteApplication?: CoreAppApplication | null;
|
|
87
|
+
} = {},
|
|
88
|
+
) {
|
|
89
|
+
super(application, "coreApp", options);
|
|
90
|
+
|
|
91
|
+
this.activeDeployment = application.activeDeployment;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get href() {
|
|
95
|
+
return this.isLocal
|
|
96
|
+
? `/local/${this.id}`
|
|
97
|
+
: `/application/${this.application.id}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
get title() {
|
|
101
|
+
return this.activeDeployment?.manifest?.title ?? this.application.title;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
get subtitle() {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
get updatedAt() {
|
|
109
|
+
return this.application.updatedAt;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
get<TKey extends keyof CoreAppUserApplication>(
|
|
113
|
+
attr: TKey,
|
|
114
|
+
): CoreAppUserApplication[TKey] {
|
|
115
|
+
if (!(attr in this.application)) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
`Attribute ${attr.toString()} does not exist on application ${this.application.id}`,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return this.application[attr];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
toProtocolResource(): ProtocolApplicationResource {
|
|
125
|
+
return {
|
|
126
|
+
...this.application,
|
|
127
|
+
type: "application",
|
|
128
|
+
url: this.url.toString(),
|
|
129
|
+
} as ProtocolApplicationResource;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
import { ProjectId } from "../../projects";
|
|
4
|
+
import { ActiveDeployment, UserApplicationBase } from "../user-application";
|
|
5
|
+
|
|
6
|
+
const Workspace = z.object({
|
|
7
|
+
name: z.string(),
|
|
8
|
+
title: z.string(),
|
|
9
|
+
subtitle: z.string().optional(),
|
|
10
|
+
basePath: z.string(),
|
|
11
|
+
projectId: ProjectId,
|
|
12
|
+
dataset: z.string().optional(),
|
|
13
|
+
icon: z.string().nullable().optional(),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export type Workspace = z.output<typeof Workspace>;
|
|
20
|
+
|
|
21
|
+
const ServerManifest = z.object({
|
|
22
|
+
buildId: z.string().optional(),
|
|
23
|
+
bundleVersion: z.string().optional(),
|
|
24
|
+
version: z.string().optional(),
|
|
25
|
+
workspaces: z
|
|
26
|
+
.array(
|
|
27
|
+
Workspace.extend({
|
|
28
|
+
dataset: z.string(),
|
|
29
|
+
schemaDescriptorId: z.string(),
|
|
30
|
+
}),
|
|
31
|
+
)
|
|
32
|
+
.optional(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
export const ClientManifest = z.object({
|
|
39
|
+
version: z.number(),
|
|
40
|
+
createdAt: z.string(),
|
|
41
|
+
studioVersion: z.string().optional(),
|
|
42
|
+
workspaces: z.array(
|
|
43
|
+
Workspace.extend({
|
|
44
|
+
schema: z.string(),
|
|
45
|
+
tools: z.string().optional(),
|
|
46
|
+
}),
|
|
47
|
+
),
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export type ClientManifest = z.output<typeof ClientManifest>;
|
|
54
|
+
|
|
55
|
+
const StudioUserApplicationBase = UserApplicationBase.extend({
|
|
56
|
+
title: z.string().nullable(),
|
|
57
|
+
projectId: ProjectId,
|
|
58
|
+
type: z.literal("studio"),
|
|
59
|
+
manifest: ClientManifest.nullable(),
|
|
60
|
+
manifestData: z.object({ value: ClientManifest }).nullable(),
|
|
61
|
+
autoUpdatingVersion: z.string().nullable(),
|
|
62
|
+
config: z.object({
|
|
63
|
+
"live-manifest": z
|
|
64
|
+
.object({
|
|
65
|
+
createdAt: z.string(),
|
|
66
|
+
updatedAt: z.string(),
|
|
67
|
+
updatedBy: z.string(),
|
|
68
|
+
value: ServerManifest,
|
|
69
|
+
})
|
|
70
|
+
.optional(),
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const InternalStudioUserApplication = StudioUserApplicationBase.extend({
|
|
75
|
+
urlType: z.literal("internal"),
|
|
76
|
+
activeDeployment: ActiveDeployment.extend({
|
|
77
|
+
manifest: ServerManifest.nullable(),
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const ExternalStudioUserApplication = StudioUserApplicationBase.extend({
|
|
82
|
+
urlType: z.literal("external"),
|
|
83
|
+
activeDeployment: z.null(),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Studio user application schema — validates and brands API
|
|
88
|
+
* responses from the `/user-applications?appType=studio`
|
|
89
|
+
* endpoint. Uses a discriminated union on `urlType`.
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
export const StudioUserApplication = z.discriminatedUnion("urlType", [
|
|
93
|
+
InternalStudioUserApplication,
|
|
94
|
+
ExternalStudioUserApplication,
|
|
95
|
+
]);
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
export type StudioUserApplication = z.output<typeof StudioUserApplication>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Validates and parses a raw API response into a branded
|
|
104
|
+
* StudioUserApplication.
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
107
|
+
export function parseStudioUserApplication(
|
|
108
|
+
data: unknown,
|
|
109
|
+
): StudioUserApplication {
|
|
110
|
+
return StudioUserApplication.parse(data);
|
|
111
|
+
}
|