@studiocms/devapps 0.1.0-beta.29 → 0.1.0-beta.31

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/README.md CHANGED
@@ -52,28 +52,6 @@ export default defineConfig({
52
52
 
53
53
  All tools will only be available during `astro dev` and will not be available during production deployments!
54
54
 
55
- ### libSQL Viewer
56
-
57
- #### Requires
58
-
59
- The following env variables set (`@astrojs/db`):
60
- - **`ASTRO_DB_REMOTE_URL`**
61
- - **`ASTRO_DB_APP_TOKEN`**
62
-
63
- #### Preview
64
-
65
- - Toolbar app
66
-
67
- ![toolbar](./assets/preview-toolbar.png)
68
-
69
- - Toolbar app Embedded
70
-
71
- ![toolbar-embedded](./assets/preview-embeddedapp.png)
72
-
73
- - Full page View
74
-
75
- ![pageview](./assets/preview-page.png)
76
-
77
55
  ### WordPress Importer
78
56
 
79
57
  #### Requires
@@ -6,50 +6,50 @@ declare const WordPressAPIConverters_base: Effect.Service.Class<WordPressAPIConv
6
6
  readonly dependencies: readonly [import("effect/Layer").Layer<WordPressAPIUtils, never, never>];
7
7
  readonly effect: Effect.Effect<{
8
8
  convertToPageData: Effect.Effect<{
9
- title: string;
10
- slug: string;
11
- description: string;
12
- draft?: boolean | null | undefined;
13
- id?: string | undefined;
14
- categories?: unknown;
15
- tags?: unknown;
16
- package?: string | undefined;
17
- showOnNav?: boolean | undefined;
18
- publishedAt?: Date | undefined;
19
- updatedAt?: Date | null | undefined;
20
- contentLang?: string | undefined;
21
- heroImage?: string | undefined;
22
- authorId?: string | null | undefined;
23
- contributorIds?: unknown;
24
- showAuthor?: boolean | null | undefined;
25
- showContributors?: boolean | null | undefined;
26
- parentFolder?: string | null | undefined;
27
- augments?: unknown;
28
- }, boolean | Error | import("effect/ParseResult").ParseError, ImportEndpointConfig | RawPageData>;
29
- convertToPageContent: Effect.Effect<CombinedInsertContent, boolean | Error | import("effect/ParseResult").ParseError, RawPageData | FullPageData>;
9
+ readonly title: string;
10
+ readonly draft: boolean;
11
+ readonly id: string;
12
+ readonly slug: string;
13
+ readonly categories: string;
14
+ readonly tags: string;
15
+ readonly description: string;
16
+ readonly package: string;
17
+ readonly showOnNav: boolean;
18
+ readonly publishedAt: string;
19
+ readonly updatedAt: string;
20
+ readonly contentLang: string;
21
+ readonly heroImage: string | null | undefined;
22
+ readonly authorId: string;
23
+ readonly contributorIds: string;
24
+ readonly showAuthor: boolean;
25
+ readonly showContributors: boolean;
26
+ readonly parentFolder: string | null | undefined;
27
+ readonly augments: string;
28
+ }, boolean | Error | import("effect/ConfigError").ConfigError | import("effect/ParseResult").ParseError, ImportEndpointConfig | RawPageData>;
29
+ convertToPageContent: Effect.Effect<CombinedInsertContent, boolean | Error | import("effect/ConfigError").ConfigError | import("effect/ParseResult").ParseError, RawPageData | FullPageData>;
30
30
  convertToPostData: Effect.Effect<{
31
- title: string;
32
- slug: string;
33
- description: string;
34
- draft?: boolean | null | undefined;
35
- id?: string | undefined;
36
- categories?: unknown;
37
- tags?: unknown;
38
- package?: string | undefined;
39
- showOnNav?: boolean | undefined;
40
- publishedAt?: Date | undefined;
41
- updatedAt?: Date | null | undefined;
42
- contentLang?: string | undefined;
43
- heroImage?: string | undefined;
44
- authorId?: string | null | undefined;
45
- contributorIds?: unknown;
46
- showAuthor?: boolean | null | undefined;
47
- showContributors?: boolean | null | undefined;
48
- parentFolder?: string | null | undefined;
49
- augments?: unknown;
50
- }, boolean | import("astro/errors").AstroError | import("effect/Cause").UnknownException | import("effect/ParseResult").ParseError | import("@withstudiocms/effect/drizzle").LibSQLClientError, ImportEndpointConfig | RawPageData | UseBlogPkgConfig>;
51
- convertToPostContent: Effect.Effect<CombinedInsertContent, boolean | Error | import("effect/ParseResult").ParseError, RawPageData | FullPageData>;
52
- }, never, WordPressAPIUtils>;
31
+ readonly title: string;
32
+ readonly draft: boolean;
33
+ readonly id: string;
34
+ readonly slug: string;
35
+ readonly categories: string;
36
+ readonly tags: string;
37
+ readonly description: string;
38
+ readonly package: string;
39
+ readonly showOnNav: boolean;
40
+ readonly publishedAt: string;
41
+ readonly updatedAt: string;
42
+ readonly contentLang: string;
43
+ readonly heroImage: string | null | undefined;
44
+ readonly authorId: string;
45
+ readonly contributorIds: string;
46
+ readonly showAuthor: boolean;
47
+ readonly showContributors: boolean;
48
+ readonly parentFolder: string | null | undefined;
49
+ readonly augments: string;
50
+ }, boolean | import("effect/ConfigError").ConfigError | import("astro/errors").AstroError | import("effect/Cause").UnknownException | import("effect/ParseResult").ParseError | import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, ImportEndpointConfig | RawPageData | UseBlogPkgConfig>;
51
+ convertToPostContent: Effect.Effect<CombinedInsertContent, boolean | Error | import("effect/ConfigError").ConfigError | import("effect/ParseResult").ParseError, RawPageData | FullPageData>;
52
+ }, import("effect/ConfigError").ConfigError | import("studiocms/sdk/base").DBClientInitializationError | import("studiocms/sdk/base").SDKInitializationError, WordPressAPIUtils>;
53
53
  }>;
54
54
  export declare class WordPressAPIConverters extends WordPressAPIConverters_base {
55
55
  }
@@ -1,10 +1,9 @@
1
- import { eq } from "astro:db";
2
1
  import path from "node:path";
3
2
  import { SDKCore } from "studiocms:sdk";
4
3
  import { userProjectRoot } from "virtual:studiocms-devapps/config";
4
+ import { StudioCMSPageDataCategories, StudioCMSPageDataTags } from "@withstudiocms/kysely";
5
5
  import { Console, Effect, genLogger, Schema } from "studiocms/effect";
6
6
  import { decode } from "studiocms/runtime";
7
- import { tsPageDataCategories, tsPageDataTags } from "studiocms/sdk/tables";
8
7
  import {
9
8
  APIEndpointConfig,
10
9
  CategoryOrTagConfig,
@@ -21,6 +20,18 @@ const ASTRO_PUBLIC_FOLDER = path.resolve(userProjectRoot, "public");
21
20
  const WPImportFolder = path.resolve(ASTRO_PUBLIC_FOLDER, "wp-import");
22
21
  const pagesImagesFolder = path.resolve(WPImportFolder, "pages");
23
22
  const postsImagesFolder = path.resolve(WPImportFolder, "posts");
23
+ const sharedMeta = (data) => ({
24
+ augments: "[]",
25
+ authorId: "",
26
+ categories: "[]",
27
+ tags: "[]",
28
+ contributorIds: "[]",
29
+ draft: data.status !== "publish",
30
+ heroImage: void 0,
31
+ parentFolder: void 0,
32
+ showAuthor: false,
33
+ showContributors: false
34
+ });
24
35
  class WordPressAPIConverters extends Effect.Service()(
25
36
  "WordPressAPIConverters",
26
37
  {
@@ -35,6 +46,34 @@ class WordPressAPIConverters extends Effect.Service()(
35
46
  stripHtml,
36
47
  turndown
37
48
  } = yield* WordPressAPIUtils;
49
+ const _getCategoryById = sdk.dbService.withCodec({
50
+ decoder: Schema.UndefinedOr(StudioCMSPageDataCategories.Select),
51
+ encoder: Schema.Number,
52
+ callbackFn: (client, id) => client(
53
+ (db) => db.selectFrom("StudioCMSPageDataCategories").selectAll().where("id", "=", id).executeTakeFirst()
54
+ )
55
+ });
56
+ const _insertCategory = sdk.dbService.withEncoder({
57
+ encoder: Schema.Union(
58
+ Schema.Array(StudioCMSPageDataCategories.Insert),
59
+ StudioCMSPageDataCategories.Insert
60
+ ),
61
+ callbackFn: (client, data) => client((db) => db.insertInto("StudioCMSPageDataCategories").values(data).execute())
62
+ });
63
+ const _getTagById = sdk.dbService.withCodec({
64
+ decoder: Schema.UndefinedOr(StudioCMSPageDataTags.Select),
65
+ encoder: Schema.Number,
66
+ callbackFn: (client, id) => client(
67
+ (db) => db.selectFrom("StudioCMSPageDataTags").selectAll().where("id", "=", id).executeTakeFirst()
68
+ )
69
+ });
70
+ const _insertTag = sdk.dbService.withEncoder({
71
+ encoder: Schema.Union(
72
+ Schema.Array(StudioCMSPageDataTags.Insert),
73
+ StudioCMSPageDataTags.Insert
74
+ ),
75
+ callbackFn: (client, data) => client((db) => db.insertInto("StudioCMSPageDataTags").values(data).execute())
76
+ });
38
77
  const convertToPageData = genLogger(
39
78
  "@studiocms/devapps/effects/WordPressAPI/converters.effect.convertToPageData"
40
79
  )(function* () {
@@ -51,12 +90,13 @@ class WordPressAPIConverters extends Effect.Service()(
51
90
  if (!titleImageId || titleImageId === 0) {
52
91
  yield* Console.log("No featured media for:", data.title.rendered);
53
92
  const pageData2 = {
93
+ ...sharedMeta(data),
54
94
  id: crypto.randomUUID(),
55
95
  title: data.title.rendered,
56
96
  description: decode(cleanHTML),
57
97
  slug: data.slug,
58
- publishedAt: new Date(data.date_gmt),
59
- updatedAt: new Date(data.modified_gmt),
98
+ publishedAt: new Date(data.date_gmt).toISOString(),
99
+ updatedAt: new Date(data.modified_gmt).toISOString(),
60
100
  showOnNav: false,
61
101
  contentLang: "default",
62
102
  package: "studiocms"
@@ -72,12 +112,13 @@ class WordPressAPIConverters extends Effect.Service()(
72
112
  DownloadPostImageConfig.makeProvide(titleImageJson.source_url, pagesImagesFolder)
73
113
  );
74
114
  const pageData = {
115
+ ...sharedMeta(data),
75
116
  id: crypto.randomUUID(),
76
117
  title: data.title.rendered,
77
118
  description: decode(cleanHTML),
78
119
  slug: data.slug,
79
- publishedAt: new Date(data.date_gmt),
80
- updatedAt: new Date(data.modified_gmt),
120
+ publishedAt: new Date(data.date_gmt).toISOString(),
121
+ updatedAt: new Date(data.modified_gmt).toISOString(),
81
122
  showOnNav: false,
82
123
  contentLang: "default",
83
124
  package: "studiocms",
@@ -118,15 +159,15 @@ class WordPressAPIConverters extends Effect.Service()(
118
159
  ImportEndpointConfig,
119
160
  CategoryOrTagConfig
120
161
  ]);
121
- const TableMap = {
122
- categories: tsPageDataCategories,
123
- tags: tsPageDataTags
162
+ const TableFnMap = {
163
+ categories: _getCategoryById,
164
+ tags: _getTagById
124
165
  };
125
- const table = TableMap[type];
166
+ const tableFn = TableFnMap[type];
126
167
  const newItems = [];
127
168
  const idChecks = yield* Effect.all(
128
169
  value.map(
129
- (val) => sdk.dbService.execute((client) => client.select().from(table).where(eq(table.id, val)).get()).pipe(Effect.map((exists) => ({ val, exists: !!exists })))
170
+ (val) => tableFn(val).pipe(Effect.map((exists) => ({ val, exists: !!exists })))
130
171
  ),
131
172
  { concurrency: 10 }
132
173
  );
@@ -146,47 +187,39 @@ class WordPressAPIConverters extends Effect.Service()(
146
187
  if (newItems.length > 0) {
147
188
  switch (type) {
148
189
  case "categories": {
149
- const data = newItems.map((category) => {
150
- const data2 = {
190
+ const data = newItems.map(
191
+ (category) => ({
151
192
  id: category.id,
152
193
  name: category.name,
153
194
  slug: category.slug,
154
195
  description: category.description,
155
- meta: JSON.stringify(category.meta)
156
- };
157
- if (category.parent) {
158
- data2.parent = category.parent;
159
- }
160
- return data2;
161
- });
196
+ meta: JSON.stringify(category.meta),
197
+ parent: category.parent || null
198
+ })
199
+ );
162
200
  yield* Console.log(
163
201
  "Inserting new Categories into the database:",
164
202
  data.map((d) => `${d.id}: ${d.name}`).join(", ")
165
203
  );
166
- yield* sdk.dbService.execute(
167
- (client) => client.insert(tsPageDataCategories).values(data)
168
- );
204
+ yield* _insertCategory(data);
169
205
  yield* Console.log("Categories inserted!");
170
206
  break;
171
207
  }
172
208
  case "tags": {
173
- const tagData = newItems.map((tag) => {
174
- const data = {
209
+ const tagData = newItems.map(
210
+ (tag) => ({
175
211
  id: tag.id,
176
212
  name: tag.name,
177
213
  slug: tag.slug,
178
214
  description: tag.description,
179
215
  meta: JSON.stringify(tag.meta)
180
- };
181
- return data;
182
- });
216
+ })
217
+ );
183
218
  yield* Console.log(
184
219
  "Inserting new Tags into the database:",
185
220
  tagData.map((data) => `${data.id}: ${data.name}`).join(", ")
186
221
  );
187
- yield* sdk.dbService.execute(
188
- (client) => client.insert(tsPageDataTags).values(tagData)
189
- );
222
+ yield* _insertTag(tagData);
190
223
  yield* Console.log("Tags inserted!");
191
224
  break;
192
225
  }
@@ -208,12 +241,13 @@ class WordPressAPIConverters extends Effect.Service()(
208
241
  if (!titleImageId || titleImageId === 0) {
209
242
  yield* Console.log("No featured media for:", data.title.rendered);
210
243
  const pageData2 = {
244
+ ...sharedMeta(data),
211
245
  id: crypto.randomUUID(),
212
246
  title: data.title.rendered,
213
247
  description: decode(cleanedHTML),
214
248
  slug: data.slug,
215
- publishedAt: new Date(data.date_gmt),
216
- updatedAt: new Date(data.modified_gmt),
249
+ publishedAt: new Date(data.date_gmt).toISOString(),
250
+ updatedAt: new Date(data.modified_gmt).toISOString(),
217
251
  showOnNav: false,
218
252
  contentLang: "default",
219
253
  package: pkg,
@@ -239,12 +273,13 @@ class WordPressAPIConverters extends Effect.Service()(
239
273
  CategoryOrTagConfig.makeProvide(data.tags)
240
274
  );
241
275
  const pageData = {
276
+ ...sharedMeta(data),
242
277
  id: crypto.randomUUID(),
243
278
  title: data.title.rendered,
244
279
  description: decode(cleanedHTML),
245
280
  slug: data.slug,
246
- publishedAt: new Date(data.date_gmt),
247
- updatedAt: new Date(data.modified_gmt),
281
+ publishedAt: new Date(data.date_gmt).toISOString(),
282
+ updatedAt: new Date(data.modified_gmt).toISOString(),
248
283
  showOnNav: false,
249
284
  contentLang: "default",
250
285
  package: pkg,
@@ -1,19 +1,19 @@
1
+ import type { StudioCMSPageContent, StudioCMSPageData } from '@withstudiocms/kysely';
1
2
  import { Effect } from 'studiocms/effect';
2
- import type { tsPageContent, tsPageData } from 'studiocms/sdk/tables';
3
3
  import { ImportEndpointConfig, ImportPostsEndpointConfig } from './configs.js';
4
4
  import { WordPressAPIConverters } from './converters.js';
5
5
  import { WordPressAPIUtils } from './utils.js';
6
- export type PageData = typeof tsPageData.$inferInsert;
7
- export type PageContent = typeof tsPageContent.$inferInsert;
6
+ export type PageData = (typeof StudioCMSPageData)['Insert']['Type'];
7
+ export type PageContent = (typeof StudioCMSPageContent)['Insert']['Type'];
8
8
  declare const WordPressAPI_base: Effect.Service.Class<WordPressAPI, "WordPressAPI", {
9
- readonly dependencies: readonly [import("effect/Layer").Layer<WordPressAPIUtils, never, never>, import("effect/Layer").Layer<WordPressAPIConverters, never, never>];
9
+ readonly dependencies: readonly [import("effect/Layer").Layer<WordPressAPIUtils, never, never>, import("effect/Layer").Layer<WordPressAPIConverters, import("effect/ConfigError").ConfigError | import("studiocms/sdk/base").DBClientInitializationError | import("studiocms/sdk/base").SDKInitializationError, never>];
10
10
  readonly effect: Effect.Effect<{
11
- importSettingsFromWPAPI: Effect.Effect<void, boolean | Error | import("effect/ParseResult").ParseError, ImportEndpointConfig>;
12
- importPagesFromWPAPI: Effect.Effect<void, boolean | Error | import("effect/ParseResult").ParseError | import("studiocms/sdk/errors").SDKCoreError, ImportEndpointConfig>;
13
- importPostsFromWPAPI: Effect.Effect<void, boolean | Error | import("effect/ParseResult").ParseError | import("studiocms/sdk/errors").SDKCoreError, ImportPostsEndpointConfig>;
14
- }, never, WordPressAPIUtils | WordPressAPIConverters>;
11
+ importSettingsFromWPAPI: Effect.Effect<void, boolean | import("effect/ConfigError").ConfigError | import("astro/errors").AstroError | import("effect/Cause").UnknownException | import("effect/ParseResult").ParseError | import("@withstudiocms/kysely").DBCallbackFailure | import("@withstudiocms/kysely/core/errors").DatabaseError, ImportEndpointConfig>;
12
+ importPagesFromWPAPI: Effect.Effect<void, boolean | Error | import("effect/ConfigError").ConfigError | import("effect/ParseResult").ParseError, ImportEndpointConfig>;
13
+ importPostsFromWPAPI: Effect.Effect<void, boolean | Error | import("effect/ConfigError").ConfigError | import("effect/ParseResult").ParseError, ImportPostsEndpointConfig>;
14
+ }, import("effect/ConfigError").ConfigError | import("studiocms/sdk/base").DBClientInitializationError | import("studiocms/sdk/base").SDKInitializationError, WordPressAPIUtils | WordPressAPIConverters>;
15
15
  }>;
16
16
  export declare class WordPressAPI extends WordPressAPI_base {
17
- static Provide: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, WordPressAPI>>;
17
+ static Provide: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, import("effect/ConfigError").ConfigError | import("studiocms/sdk/base").DBClientInitializationError | import("studiocms/sdk/base").SDKInitializationError | E, Exclude<R, WordPressAPI>>;
18
18
  }
19
19
  export {};
@@ -1,15 +1,15 @@
1
1
  import { AstroError } from 'astro/errors';
2
- import { Effect } from 'studiocms/effect';
2
+ import { type ConfigError, Effect } from 'studiocms/effect';
3
3
  import { APIEndpointConfig, DownloadPostImageConfig, StringConfig } from './configs.js';
4
4
  declare const WordPressAPIUtils_base: Effect.Service.Class<WordPressAPIUtils, "WordPressAPIUtils", {
5
5
  readonly effect: Effect.Effect<{
6
- turndown: Effect.Effect<string, AstroError, StringConfig>;
7
- stripHtml: Effect.Effect<string, import("effect/Cause").UnknownException, StringConfig>;
8
- cleanUpHtml: Effect.Effect<string, AstroError, StringConfig>;
9
- fetchAll: (url: URL, page?: number, results?: any[]) => Effect.Effect<any[], AstroError, never>;
10
- apiEndpoint: Effect.Effect<URL, AstroError, APIEndpointConfig>;
11
- downloadPostImage: Effect.Effect<string | undefined, boolean | import("effect/Cause").UnknownException, DownloadPostImageConfig>;
12
- downloadAndUpdateImages: Effect.Effect<string, boolean | AstroError | import("effect/Cause").UnknownException, DownloadPostImageConfig>;
6
+ turndown: Effect.Effect<string, ConfigError.ConfigError | AstroError, StringConfig>;
7
+ stripHtml: Effect.Effect<string, ConfigError.ConfigError | import("effect/Cause").UnknownException, StringConfig>;
8
+ cleanUpHtml: Effect.Effect<string, ConfigError.ConfigError | AstroError, StringConfig>;
9
+ fetchAll: (url: URL, page?: number, results?: any[]) => Effect.Effect<any[], ConfigError.ConfigError | AstroError, never>;
10
+ apiEndpoint: Effect.Effect<URL, ConfigError.ConfigError | AstroError, APIEndpointConfig>;
11
+ downloadPostImage: Effect.Effect<string | undefined, boolean | ConfigError.ConfigError | import("effect/Cause").UnknownException, DownloadPostImageConfig>;
12
+ downloadAndUpdateImages: Effect.Effect<string, boolean | ConfigError.ConfigError | AstroError | import("effect/Cause").UnknownException, DownloadPostImageConfig>;
13
13
  }, never, never>;
14
14
  }>;
15
15
  export declare class WordPressAPIUtils extends WordPressAPIUtils_base {
@@ -2,12 +2,12 @@ import { Effect } from 'studiocms/effect';
2
2
  import { AstroAPIContextProvider } from './WordPressAPI/configs.js';
3
3
  import { WordPressAPI } from './WordPressAPI/importers.js';
4
4
  declare const WPImporter_base: Effect.Service.Class<WPImporter, "WPImporter", {
5
- readonly dependencies: readonly [import("effect/Layer").Layer<WordPressAPI, never, never>];
5
+ readonly dependencies: readonly [import("effect/Layer").Layer<WordPressAPI, import("effect/ConfigError").ConfigError | import("studiocms/sdk/base").DBClientInitializationError | import("studiocms/sdk/base").SDKInitializationError, never>];
6
6
  readonly effect: Effect.Effect<{
7
- runPostEvent: Effect.Effect<Response, boolean | Error | import("effect/ParseResult").ParseError | import("studiocms/sdk/errors").SDKCoreError, AstroAPIContextProvider>;
8
- }, never, WordPressAPI>;
7
+ runPostEvent: Effect.Effect<Response, boolean | Error | import("effect/ConfigError").ConfigError | import("effect/ParseResult").ParseError, AstroAPIContextProvider>;
8
+ }, import("effect/ConfigError").ConfigError, WordPressAPI>;
9
9
  }>;
10
10
  export declare class WPImporter extends WPImporter_base {
11
- static Provide: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, Exclude<R, WPImporter>>;
11
+ static Provide: <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, import("effect/ConfigError").ConfigError | import("studiocms/sdk/base").DBClientInitializationError | import("studiocms/sdk/base").SDKInitializationError | E, Exclude<R, WPImporter>>;
12
12
  }
13
13
  export {};
package/dist/index.d.ts CHANGED
@@ -26,9 +26,6 @@ import { type StudioCMSDevAppsOptions } from './schema/index.js';
26
26
  * enabled: true,
27
27
  * endpoint: '/wp-import',
28
28
  * },
29
- * libSQLViewer: {
30
- * enabled: true,
31
- * },
32
29
  * },
33
30
  * verbose: true,
34
31
  * }),
package/dist/index.js CHANGED
@@ -1,12 +1,10 @@
1
1
  import { addVirtualImports, createResolver, injectDevRoute } from "astro-integration-kit";
2
- import { loadEnv } from "vite";
3
2
  import { StudioCMSDevAppsSchema } from "./schema/index.js";
4
3
  import { pathGenerator } from "./utils/pathGenerator.js";
5
4
  function studioCMSDevApps(opts) {
6
5
  const options = StudioCMSDevAppsSchema.parse(opts);
7
6
  const { resolve } = createResolver(import.meta.url);
8
7
  let makeEndpointPath;
9
- const astroDbEnv = loadEnv("all", process.cwd(), "ASTRO_DB");
10
8
  return {
11
9
  name: "@studiocms/devapps",
12
10
  hooks: {
@@ -16,37 +14,17 @@ function studioCMSDevApps(opts) {
16
14
  options.verbose && logger.info("Setting up StudioCMS DevApps");
17
15
  if (command === "dev") {
18
16
  const wpAPIPath = makeEndpointPath(options.appsConfig.wpImporter.endpoint);
19
- const libsqlIFrame = makeEndpointPath(options.appsConfig.libSQLViewer.endpoint);
20
17
  addVirtualImports(params, {
21
18
  name: "@studiocms/devapps",
22
19
  imports: {
23
20
  "virtual:studiocms-devapps/endpoints": `
24
21
  export const wpAPIEndpoint = "${wpAPIPath}";
25
- export const libsqlEndpoint = "${libsqlIFrame}";
26
22
  `,
27
23
  "virtual:studiocms-devapps/config": `
28
24
  export const userProjectRoot = "${config.root.pathname}";
29
-
30
- export const dbEnv = {
31
- remoteUrl: "${astroDbEnv.ASTRO_DB_REMOTE_URL}",
32
- token: "${astroDbEnv.ASTRO_DB_APP_TOKEN}",
33
- };
34
25
  `
35
26
  }
36
27
  });
37
- if (options.appsConfig.libSQLViewer.enabled) {
38
- options.verbose && logger.info("Adding Dev Toolbar App: LibSQL Viewer");
39
- injectDevRoute(params, {
40
- entrypoint: resolve("./routes/outerbase.astro"),
41
- pattern: libsqlIFrame
42
- });
43
- addDevToolbarApp({
44
- name: "Outerbase Studio Embedded",
45
- id: "studiocms-devapps-libsql-viewer",
46
- entrypoint: resolve("./apps/libsql-viewer.js"),
47
- icon: '<svg width="40" height="40" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg" class="mb-4 hidden size-4 md:block"><path fill-rule="evenodd" clip-rule="evenodd" d="M20 0C8.97048 0 0 8.96666 0 19.9999C0 31.0227 8.97048 40 20 40C31.0294 40 40 31.0333 40 19.9999C40 8.96666 31.0294 0 20 0ZM27.4346 33.7676L27.3343 33.8966C26.2881 35.1776 25.0082 35.5974 24.1178 35.7158C23.8841 35.748 23.6504 35.759 23.4056 35.759C20.9794 35.759 18.5308 34.112 16.3272 30.9795C14.5353 28.4284 12.9771 25.027 11.9421 21.3992C10.1057 14.9299 10.3172 9.03117 12.4763 6.36169C13.5225 5.08067 14.8024 4.66086 15.6928 4.5425C18.2192 4.19787 20.8013 5.67267 23.1385 8.79421C25.0749 11.3779 26.7445 14.9408 27.8576 18.8481C29.6716 25.2207 29.4935 31.0549 27.4346 33.7676Z" fill="currentColor"></path></svg>'
48
- });
49
- }
50
28
  if (options.appsConfig.wpImporter.enabled) {
51
29
  options.verbose && logger.info("Adding Dev Toolbar App: WP API Importer");
52
30
  injectDevRoute(params, {
@@ -23,16 +23,6 @@ import { z } from 'astro/zod';
23
23
  * - `wpImporter` - An object with `enabled` and `endpoint` properties for the app's configuration.
24
24
  */
25
25
  export declare const AppsConfigSchema: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodObject<{
26
- /**
27
- * Astro DB LibSQL Viewer App Config
28
- */
29
- libSQLViewer: z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
30
- endpoint: z.ZodDefault<z.ZodOptional<z.ZodString>>;
31
- }, "strip", z.ZodTypeAny, {
32
- endpoint: string;
33
- }, {
34
- endpoint?: string | undefined;
35
- }>]>;
36
26
  /**
37
27
  * StudioCMS WP API Importer App Config
38
28
  */
@@ -44,32 +34,19 @@ export declare const AppsConfigSchema: z.ZodEffects<z.ZodDefault<z.ZodOptional<z
44
34
  endpoint?: string | undefined;
45
35
  }>]>;
46
36
  }, "strip", z.ZodTypeAny, {
47
- libSQLViewer: boolean | {
48
- endpoint: string;
49
- };
50
37
  wpImporter: boolean | {
51
38
  endpoint: string;
52
39
  };
53
40
  }, {
54
- libSQLViewer: boolean | {
55
- endpoint?: string | undefined;
56
- };
57
41
  wpImporter: boolean | {
58
42
  endpoint?: string | undefined;
59
43
  };
60
44
  }>>>, {
61
- libSQLViewer: {
62
- enabled: boolean;
63
- endpoint: string;
64
- };
65
45
  wpImporter: {
66
46
  enabled: boolean;
67
47
  endpoint: string;
68
48
  };
69
49
  }, {
70
- libSQLViewer: boolean | {
71
- endpoint?: string | undefined;
72
- };
73
50
  wpImporter: boolean | {
74
51
  endpoint?: string | undefined;
75
52
  };
@@ -92,16 +69,6 @@ export declare const StudioCMSDevAppsSchema: z.ZodDefault<z.ZodOptional<z.ZodObj
92
69
  endpoint: z.ZodDefault<z.ZodOptional<z.ZodString>>;
93
70
  verbose: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
94
71
  appsConfig: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodObject<{
95
- /**
96
- * Astro DB LibSQL Viewer App Config
97
- */
98
- libSQLViewer: z.ZodUnion<[z.ZodBoolean, z.ZodObject<{
99
- endpoint: z.ZodDefault<z.ZodOptional<z.ZodString>>;
100
- }, "strip", z.ZodTypeAny, {
101
- endpoint: string;
102
- }, {
103
- endpoint?: string | undefined;
104
- }>]>;
105
72
  /**
106
73
  * StudioCMS WP API Importer App Config
107
74
  */
@@ -113,32 +80,19 @@ export declare const StudioCMSDevAppsSchema: z.ZodDefault<z.ZodOptional<z.ZodObj
113
80
  endpoint?: string | undefined;
114
81
  }>]>;
115
82
  }, "strip", z.ZodTypeAny, {
116
- libSQLViewer: boolean | {
117
- endpoint: string;
118
- };
119
83
  wpImporter: boolean | {
120
84
  endpoint: string;
121
85
  };
122
86
  }, {
123
- libSQLViewer: boolean | {
124
- endpoint?: string | undefined;
125
- };
126
87
  wpImporter: boolean | {
127
88
  endpoint?: string | undefined;
128
89
  };
129
90
  }>>>, {
130
- libSQLViewer: {
131
- enabled: boolean;
132
- endpoint: string;
133
- };
134
91
  wpImporter: {
135
92
  enabled: boolean;
136
93
  endpoint: string;
137
94
  };
138
95
  }, {
139
- libSQLViewer: boolean | {
140
- endpoint?: string | undefined;
141
- };
142
96
  wpImporter: boolean | {
143
97
  endpoint?: string | undefined;
144
98
  };
@@ -147,10 +101,6 @@ export declare const StudioCMSDevAppsSchema: z.ZodDefault<z.ZodOptional<z.ZodObj
147
101
  endpoint: string;
148
102
  verbose: boolean;
149
103
  appsConfig: {
150
- libSQLViewer: {
151
- enabled: boolean;
152
- endpoint: string;
153
- };
154
104
  wpImporter: {
155
105
  enabled: boolean;
156
106
  endpoint: string;
@@ -160,9 +110,6 @@ export declare const StudioCMSDevAppsSchema: z.ZodDefault<z.ZodOptional<z.ZodObj
160
110
  endpoint?: string | undefined;
161
111
  verbose?: boolean | undefined;
162
112
  appsConfig?: {
163
- libSQLViewer: boolean | {
164
- endpoint?: string | undefined;
165
- };
166
113
  wpImporter: boolean | {
167
114
  endpoint?: string | undefined;
168
115
  };
@@ -1,14 +1,5 @@
1
1
  import { z } from "astro/zod";
2
2
  const AppsConfigSchema = z.object({
3
- /**
4
- * Astro DB LibSQL Viewer App Config
5
- */
6
- libSQLViewer: z.union([
7
- z.boolean(),
8
- z.object({
9
- endpoint: z.string().optional().default("outerbase")
10
- })
11
- ]),
12
3
  /**
13
4
  * StudioCMS WP API Importer App Config
14
5
  */
@@ -19,23 +10,15 @@ const AppsConfigSchema = z.object({
19
10
  })
20
11
  ])
21
12
  }).optional().default({
22
- wpImporter: { endpoint: "wp-api-importer" },
23
- libSQLViewer: { endpoint: "outerbase" }
13
+ wpImporter: { endpoint: "wp-api-importer" }
24
14
  }).transform((val) => {
25
- let libSQL;
26
15
  let wpAPI;
27
- if (typeof val.libSQLViewer === "boolean") {
28
- libSQL = { enabled: val.libSQLViewer, endpoint: "outerbase" };
29
- } else {
30
- libSQL = { enabled: true, endpoint: val.libSQLViewer.endpoint };
31
- }
32
16
  if (typeof val.wpImporter === "boolean") {
33
17
  wpAPI = { enabled: val.wpImporter, endpoint: "wp-api-importer" };
34
18
  } else {
35
19
  wpAPI = { enabled: true, endpoint: val.wpImporter.endpoint };
36
20
  }
37
21
  return {
38
- libSQLViewer: libSQL,
39
22
  wpImporter: wpAPI
40
23
  };
41
24
  });
package/dist/virt.d.ts CHANGED
@@ -1,15 +1,9 @@
1
- /// <reference types="@astrojs/db" />
2
1
  /// <reference types="studiocms/v/types" />
3
2
 
4
3
  declare module 'virtual:studiocms-devapps/endpoints' {
5
4
  export const wpAPIEndpoint: string;
6
- export const libsqlEndpoint: string;
7
5
  }
8
6
 
9
7
  declare module 'virtual:studiocms-devapps/config' {
10
8
  export const userProjectRoot: string;
11
- export const dbEnv: {
12
- remoteUrl: string;
13
- token: string;
14
- };
15
9
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@studiocms/devapps",
3
- "version": "0.1.0-beta.29",
4
- "description": "A dedicated CMS for Astro DB. Built from the ground up by the Astro community.",
3
+ "version": "0.1.0-beta.31",
4
+ "description": "Devapps for StudioCMS Astro projects, including a WordPress importer.",
5
5
  "author": {
6
6
  "name": "withstudiocms",
7
7
  "url": "https://studiocms.dev"
@@ -20,18 +20,12 @@
20
20
  "license": "MIT",
21
21
  "keywords": [
22
22
  "astro",
23
- "astrodb",
24
- "astrolicious",
25
23
  "astro-integration",
26
24
  "studiocms",
27
25
  "withastro",
28
26
  "wordpress",
29
27
  "wordpress-import",
30
28
  "wordpress-importer",
31
- "libsql",
32
- "libsql-viewer",
33
- "libsql-client",
34
- "libsqlstudio",
35
29
  "devapp",
36
30
  "astro-devapp",
37
31
  "astro-devtoolbarapp"
@@ -65,16 +59,11 @@
65
59
  "typescript": "^5.9.3"
66
60
  },
67
61
  "peerDependencies": {
68
- "@astrojs/db": ">=0.17.2",
69
62
  "astro": "^5.12.9",
70
- "effect": "^3.19.0",
63
+ "effect": "^3.19.9",
71
64
  "vite": "^6.3.4",
72
- "studiocms": "0.1.0-beta.29"
73
- },
74
- "peerDependenciesMeta": {
75
- "studiocms": {
76
- "optional": true
77
- }
65
+ "@withstudiocms/kysely": "0.1.0-beta.1",
66
+ "studiocms": "0.1.0-beta.31"
78
67
  },
79
68
  "scripts": {
80
69
  "build": "buildkit build 'src/**/*.{ts,astro,css,json,png,d.ts}'",
@@ -1,2 +0,0 @@
1
- declare const _default: import("astro").DevToolbarApp;
2
- export default _default;
@@ -1,32 +0,0 @@
1
- import { libsqlEndpoint } from "virtual:studiocms-devapps/endpoints";
2
- import { defineToolbarApp } from "astro/toolbar";
3
- import { closeOnOutsideClick } from "../utils/app-utils.js";
4
- var libsql_viewer_default = defineToolbarApp({
5
- init(canvas, eventTarget) {
6
- const appWindow = document.createElement("astro-dev-toolbar-window");
7
- appWindow.style.width = "90%";
8
- appWindow.style.height = "100%";
9
- appWindow.style.marginLeft = "1rem";
10
- appWindow.style.marginRight = "1rem";
11
- appWindow.style.padding = "0";
12
- appWindow.style.border = "none";
13
- appWindow.style.overflow = "hidden";
14
- appWindow.style.borderRadius = "0.5rem";
15
- appWindow.style.boxShadow = "0 0 1rem rgba(0, 0, 0, 0.1)";
16
- closeOnOutsideClick(eventTarget);
17
- const viewerIframe = document.createElement("iframe");
18
- viewerIframe.src = libsqlEndpoint;
19
- viewerIframe.id = "sqlIframe";
20
- viewerIframe.title = "libSQL Database Viewer";
21
- Object.assign(viewerIframe.style, {
22
- height: "100%",
23
- width: "100%",
24
- border: "1px solid rgba(27, 30, 36, 1)"
25
- });
26
- appWindow.appendChild(viewerIframe);
27
- canvas.appendChild(appWindow);
28
- }
29
- });
30
- export {
31
- libsql_viewer_default as default
32
- };
@@ -1,118 +0,0 @@
1
- ---
2
- import { dbEnv } from 'virtual:studiocms-devapps/config';
3
-
4
- /**
5
- * Generates the source URL for an iframe based on the provided database URL.
6
- *
7
- * @param dbUrl - The URL of the database.
8
- * @returns The source URL for the iframe. If the database URL contains 'turso.io',
9
- * it returns `tursoURL`. Otherwise, it returns `sqlLiteUrl`.
10
- */
11
- function getIFrameSrc(dbUrl: string) {
12
- if (dbUrl.includes('turso.io')) {
13
- return 'https://studio.outerbase.com/embed/turso?theme=dark';
14
- }
15
- return 'https://studio.outerbase.com/embed/turso?theme=dark';
16
- }
17
- ---
18
- <html>
19
- <head>
20
- <style is:global>
21
- astro-dev-toolbar {
22
- display: none;
23
- }
24
- </style>
25
- </head>
26
- <body style="margin: 0; padding: 0; overflow: hidden;">
27
- <iframe id="sqlIframe"
28
- style="width: 100%; height: 100vh; border: none;"
29
- src={getIFrameSrc(dbEnv.remoteUrl)}
30
- title="Outerbase Studio"
31
- allow="clipboard-read; clipboard-write"
32
- data-dburl={dbEnv.remoteUrl}
33
- data-dbtoken={dbEnv.token}
34
- />
35
-
36
- <script>
37
- // @ts-ignore
38
- import { createClient } from 'https://esm.sh/@libsql/client@0.14.0/web';
39
- // @ts-ignore
40
- import { transformTursoResult } from 'https://esm.sh/@outerbase/sdk-transform@1.0.7';
41
-
42
- interface ClientRequest {
43
- type: 'query' | 'transaction';
44
- id: number;
45
- statement?: string;
46
- statements?: string[];
47
- }
48
-
49
- const iframe = document.querySelector('#sqlIframe') as HTMLIFrameElement;
50
-
51
- const dbUrl = iframe.dataset.dburl;
52
- const dbToken = iframe.dataset.dbtoken;
53
-
54
- const client = createClient({
55
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
56
- url: dbUrl!,
57
- // biome-ignore lint/style/noNonNullAssertion: <explanation>
58
- authToken: dbToken!,
59
- intMode: 'bigint',
60
- });
61
-
62
- // Event listener to handle postMessage events
63
- window.addEventListener('message', async (e: MessageEvent<ClientRequest>) => {
64
- const contentWindow = iframe.contentWindow;
65
-
66
- if (contentWindow && e.data) {
67
- const { type, id, statement, statements } = e.data;
68
-
69
- if (type === 'query' && statement) {
70
- // Execute a single SQL query
71
- try {
72
- const result = await client.execute(statement);
73
- contentWindow.postMessage(
74
- {
75
- type,
76
- id,
77
- data: transformTursoResult(result),
78
- },
79
- '*'
80
- );
81
- } catch (err) {
82
- contentWindow.postMessage(
83
- {
84
- type,
85
- id,
86
- error: (err as Error).message,
87
- },
88
- '*'
89
- );
90
- }
91
- } else if (type === 'transaction' && statements) {
92
- // Execute a batch of SQL statements in a transaction
93
- try {
94
- const result = await client.batch(statements, 'write');
95
- contentWindow.postMessage(
96
- {
97
- type,
98
- id,
99
- data: result.map(transformTursoResult),
100
- },
101
- '*'
102
- );
103
- } catch (err) {
104
- contentWindow.postMessage(
105
- {
106
- type,
107
- id,
108
- error: (err as Error).message,
109
- },
110
- '*'
111
- );
112
- }
113
- }
114
- }
115
- });
116
- </script>
117
- </body>
118
- </html>