@workbench-kit/adapters 0.0.2-prototype.0.2.5 → 0.0.2-prototype.0.2.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.
@@ -1,65 +1,65 @@
1
- import type { WorkspaceFile } from '@workbench-kit/workspace';
2
-
3
- export const WIDGET_STUDIO_ASSETS_DIR = 'src/widgets/assets';
4
- export const WIDGET_STUDIO_CUSTOM_ASSETS_DIR = 'src/widgets/assets/custom';
5
-
6
- const MANIFEST_MIME = 'application/vnd.workbench-kit.widget-asset-manifest+json';
7
- const CONTENT_MIME = 'application/vnd.workbench-kit.widget-asset-content+json';
8
- const SCHEMA_MIME = 'application/vnd.workbench-kit.widget-asset-schema+json';
9
-
10
- export interface WidgetStudioAssetPackageDefinition {
11
- readonly slug: string;
12
- readonly baseDir?: string | undefined;
13
- readonly updatedAt: string;
14
- readonly manifest: Record<string, unknown>;
15
- readonly content: Record<string, unknown>;
16
- readonly schema?: Record<string, unknown> | undefined;
17
- }
18
-
19
- function json(value: unknown): string {
20
- return `${JSON.stringify(value, null, 2)}\n`;
21
- }
22
-
23
- export function createWidgetStudioAssetPackageFiles(
24
- definition: WidgetStudioAssetPackageDefinition,
25
- ): WorkspaceFile[] {
26
- const baseDir = definition.baseDir ?? WIDGET_STUDIO_ASSETS_DIR;
27
- const root = `${baseDir}/${definition.slug}`;
28
- const files: WorkspaceFile[] = [
29
- {
30
- path: `${root}/manifest.json`,
31
- mimeType: MANIFEST_MIME,
32
- updatedAt: definition.updatedAt,
33
- source: 'user',
34
- content: json({
35
- $schema: 'https://workbench-kit.dev/schemas/widget-asset-manifest.v1.jdw.schema.json',
36
- ...definition.manifest,
37
- }),
38
- },
39
- {
40
- path: `${root}/content.json`,
41
- mimeType: CONTENT_MIME,
42
- updatedAt: definition.updatedAt,
43
- source: 'user',
44
- content: json(definition.content),
45
- },
46
- ];
47
-
48
- if (definition.schema) {
49
- files.push({
50
- path: `${root}/schema.json`,
51
- mimeType: SCHEMA_MIME,
52
- updatedAt: definition.updatedAt,
53
- source: 'user',
54
- content: json(definition.schema),
55
- });
56
- }
57
-
58
- return files;
59
- }
60
-
61
- export function flattenWidgetStudioAssetPackages(
62
- packages: readonly WidgetStudioAssetPackageDefinition[],
63
- ): WorkspaceFile[] {
64
- return packages.flatMap((definition) => createWidgetStudioAssetPackageFiles(definition));
65
- }
1
+ import type { WorkspaceFile } from '@workbench-kit/workspace';
2
+
3
+ export const WIDGET_STUDIO_ASSETS_DIR = 'src/widgets/assets';
4
+ export const WIDGET_STUDIO_CUSTOM_ASSETS_DIR = 'src/widgets/assets/custom';
5
+
6
+ const MANIFEST_MIME = 'application/vnd.workbench-kit.widget-asset-manifest+json';
7
+ const CONTENT_MIME = 'application/vnd.workbench-kit.widget-asset-content+json';
8
+ const SCHEMA_MIME = 'application/vnd.workbench-kit.widget-asset-schema+json';
9
+
10
+ export interface WidgetStudioAssetPackageDefinition {
11
+ readonly slug: string;
12
+ readonly baseDir?: string | undefined;
13
+ readonly updatedAt: string;
14
+ readonly manifest: Record<string, unknown>;
15
+ readonly content: Record<string, unknown>;
16
+ readonly schema?: Record<string, unknown> | undefined;
17
+ }
18
+
19
+ function json(value: unknown): string {
20
+ return `${JSON.stringify(value, null, 2)}\n`;
21
+ }
22
+
23
+ export function createWidgetStudioAssetPackageFiles(
24
+ definition: WidgetStudioAssetPackageDefinition,
25
+ ): WorkspaceFile[] {
26
+ const baseDir = definition.baseDir ?? WIDGET_STUDIO_ASSETS_DIR;
27
+ const root = `${baseDir}/${definition.slug}`;
28
+ const files: WorkspaceFile[] = [
29
+ {
30
+ path: `${root}/manifest.json`,
31
+ mimeType: MANIFEST_MIME,
32
+ updatedAt: definition.updatedAt,
33
+ source: 'user',
34
+ content: json({
35
+ $schema: 'https://workbench-kit.dev/schemas/widget-asset-manifest.v1.jdw.schema.json',
36
+ ...definition.manifest,
37
+ }),
38
+ },
39
+ {
40
+ path: `${root}/content.json`,
41
+ mimeType: CONTENT_MIME,
42
+ updatedAt: definition.updatedAt,
43
+ source: 'user',
44
+ content: json(definition.content),
45
+ },
46
+ ];
47
+
48
+ if (definition.schema) {
49
+ files.push({
50
+ path: `${root}/schema.json`,
51
+ mimeType: SCHEMA_MIME,
52
+ updatedAt: definition.updatedAt,
53
+ source: 'user',
54
+ content: json(definition.schema),
55
+ });
56
+ }
57
+
58
+ return files;
59
+ }
60
+
61
+ export function flattenWidgetStudioAssetPackages(
62
+ packages: readonly WidgetStudioAssetPackageDefinition[],
63
+ ): WorkspaceFile[] {
64
+ return packages.flatMap((definition) => createWidgetStudioAssetPackageFiles(definition));
65
+ }