@wpnuxt/core 1.0.0-edge.11 → 1.0.0-edge.13

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/module.d.mts CHANGED
@@ -63,7 +63,7 @@ interface WPNuxtConfigQueries {
63
63
  outputDir?: string
64
64
  }
65
65
 
66
- declare const _default: _nuxt_schema.NuxtModule<WPNuxtConfig>;
66
+ declare const _default: _nuxt_schema.NuxtModule<WPNuxtConfig, WPNuxtConfig, false>;
67
67
 
68
68
  declare module '@nuxt/schema' {
69
69
  interface RuntimeConfig {
package/dist/module.d.ts CHANGED
@@ -63,7 +63,7 @@ interface WPNuxtConfigQueries {
63
63
  outputDir?: string
64
64
  }
65
65
 
66
- declare const _default: _nuxt_schema.NuxtModule<WPNuxtConfig>;
66
+ declare const _default: _nuxt_schema.NuxtModule<WPNuxtConfig, WPNuxtConfig, false>;
67
67
 
68
68
  declare module '@nuxt/schema' {
69
69
  interface RuntimeConfig {
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "1.0.0-edge.11",
3
+ "version": "1.0.0-edge.13",
4
4
  "configKey": "wpNuxt",
5
5
  "nuxt": ">=3.1.0",
6
6
  "builder": {
package/dist/module.mjs CHANGED
@@ -7,7 +7,7 @@ import { upperFirst } from 'scule';
7
7
  import { parse } from 'graphql';
8
8
 
9
9
  const name = "@wpnuxt/core";
10
- const version = "1.0.0-edge.11";
10
+ const version = "1.0.0-edge.13";
11
11
 
12
12
  const loggerRef = ref();
13
13
  const initLogger = (logLevel) => {
@@ -217,10 +217,6 @@ const module = defineNuxtModule({
217
217
  route: "/api/wpContent",
218
218
  handler: resolveRuntimeModule("./server/api/wpContent.post")
219
219
  });
220
- addServerHandler({
221
- route: "/api/purgeCache",
222
- handler: resolveRuntimeModule("./server/api/purgeCache.get")
223
- });
224
220
  await installModule("@vueuse/nuxt", {});
225
221
  const queryOutputPath = resolve((nuxt.options.srcDir || nuxt.options.rootDir) + "/.queries/");
226
222
  await promises.rm(queryOutputPath, { recursive: true, force: true });
@@ -232,7 +228,9 @@ const module = defineNuxtModule({
232
228
  if (m.meta.name === "@wpnuxt/blocks" && m.entryPath) {
233
229
  logger.debug("Loading queries from @wpnuxt/blocks");
234
230
  let blocksQueriesPath;
235
- if (m.entryPath.startsWith("../")) {
231
+ if (m.entryPath == "../src/module") {
232
+ blocksQueriesPath = join(nuxt.options.rootDir, "../src/runtime/queries/");
233
+ } else if (m.entryPath.startsWith("../")) {
236
234
  blocksQueriesPath = join(nuxt.options.rootDir, "../", m.entryPath, "./runtime/queries/");
237
235
  } else {
238
236
  blocksQueriesPath = join("./node_modules", m.entryPath, "dist/runtime/queries/");
@@ -331,9 +329,9 @@ const module = defineNuxtModule({
331
329
  autoimports.push(...ctx.fnImports || []);
332
330
  });
333
331
  nuxt.hook("nitro:init", async (nitro) => {
334
- const keys = await nitro.storage.getKeys("cache:content");
332
+ const keys = await nitro.storage.getKeys("cache:api:wpContent");
335
333
  keys.forEach(async (key) => {
336
- if (key.startsWith("cache:content"))
334
+ if (key.startsWith("cache:api:wpContent"))
337
335
  await nitro.storage.removeItem(key);
338
336
  });
339
337
  });
@@ -2,12 +2,12 @@
2
2
  import type { NodeWithContentEditorFragment } from '#build/graphql-operations'
3
3
 
4
4
  defineProps<{
5
- post: NodeWithContentEditorFragment
5
+ node: NodeWithContentEditorFragment
6
6
  }>()
7
7
  </script>
8
8
 
9
9
  <template>
10
10
  <div
11
- v-sanitize="post.content"
11
+ v-sanitize="node.content"
12
12
  />
13
13
  </template>
@@ -20,7 +20,7 @@ const componentToRender = await findComponentToRender()
20
20
  <template>
21
21
  <component
22
22
  :is="componentToRender"
23
- v-if="componentToRender"
23
+ v-if="componentToRender && node"
24
24
  :node="node"
25
25
  />
26
26
  </template>
@@ -1,5 +1,5 @@
1
1
  import type { FetchError } from 'ofetch';
2
2
  export declare const useWPContent: <T>(queryName: string, nodes: string[], fixImagePaths: boolean, params?: T) => Promise<{
3
- data: T;
3
+ data: unknown;
4
4
  error: import("vue").Ref<FetchError<any> | null>;
5
5
  }>;
@@ -1,7 +1,4 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
- data: any;
3
- errors: any;
4
- }>>;
1
+ declare const _default: any;
5
2
  export default _default;
6
3
  /**
7
4
  * Get the parameters for the GraphQL middleware query.
@@ -1,39 +1,33 @@
1
- import { defineEventHandler, readBody } from "h3";
2
- import { cacheStorage } from "../storage.js";
3
- import { isStaging } from "../../composables/isStaging.js";
4
- import { useRuntimeConfig } from "#imports";
5
- export default defineEventHandler(async (event) => {
6
- const config = useRuntimeConfig();
1
+ import { readBody } from "h3";
2
+ import { defineCachedEventHandler } from "#internal/nitro";
3
+ export default defineCachedEventHandler(async (event) => {
7
4
  const body = await readBody(event);
8
- const staging = await isStaging();
9
5
  if (!body || !body.queryName) {
10
6
  throw new Error(
11
7
  "The request must contain a queryName"
12
8
  );
13
9
  }
14
- const cacheKey = `wpContent-${body.queryName}-${body.params ? JSON.stringify(body.params).replaceAll('"', "").replaceAll(":", "-") : ""}`;
15
- if (config.public.wpNuxt.enableCache && !staging) {
16
- const cachedContent = await cacheStorage.getItem(cacheKey);
17
- if (cachedContent) {
18
- return {
19
- data: cachedContent,
20
- errors: []
21
- };
22
- }
23
- }
24
10
  return $fetch("/api/graphql_middleware/query/" + body.queryName, {
25
11
  params: buildRequestParams(body.params),
26
12
  headers: {
27
13
  Authorization: `Bearer ${event.context.accessToken}`
28
14
  }
29
15
  }).then((v) => {
30
- cacheStorage.setItem(cacheKey, v.data).catch(() => {
31
- });
32
16
  return {
33
17
  data: v.data,
34
18
  errors: v.errors || []
35
19
  };
36
20
  });
21
+ }, {
22
+ group: "api",
23
+ name: "wpContent",
24
+ getKey: async (event) => {
25
+ const body = await readBody(event);
26
+ return `${body.queryName}${body.params ? "_" + JSON.stringify(body.params).replaceAll('"', "").replaceAll(":", "_") : ""}`;
27
+ },
28
+ swr: true,
29
+ maxAge: 60 * 5
30
+ // 5 minutes
37
31
  });
38
32
  export function buildRequestParams(variables) {
39
33
  if (!variables) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "1.0.0-edge.11",
3
+ "version": "1.0.0-edge.13",
4
4
  "description": "WPNuxt",
5
5
  "repository": {
6
6
  "type": "git",
@@ -52,7 +52,7 @@
52
52
  "start": "pnpm run wp-env:create && pnpm run dev"
53
53
  },
54
54
  "dependencies": {
55
- "@nuxt/kit": "3.12.4",
55
+ "@nuxt/kit": "3.13.0",
56
56
  "@vueuse/nuxt": "^11.0.0",
57
57
  "defu": "^6.1.4",
58
58
  "graphql": "^16.9.0",
@@ -65,27 +65,27 @@
65
65
  "@graphql-codegen/cli": "^5.0.2",
66
66
  "@graphql-codegen/client-preset": "^4.3.3",
67
67
  "@graphql-codegen/typescript-operations": "^4.2.3",
68
- "@nuxt/devtools": "^1.3.9",
69
- "@nuxt/eslint-config": "^0.5.0",
68
+ "@nuxt/devtools": "^1.3.14",
69
+ "@nuxt/eslint-config": "^0.5.2",
70
70
  "@nuxt/module-builder": "^0.8.3",
71
- "@nuxt/schema": "3.12.4",
71
+ "@nuxt/schema": "3.13.0",
72
72
  "@nuxt/test-utils": "^3.14.1",
73
73
  "@rollup/rollup-linux-arm64-gnu": "^4.20.0",
74
74
  "@rollup/rollup-linux-arm64-musl": "^4.20.0",
75
- "@types/node": "22.4.1",
75
+ "@types/node": "22.5.0",
76
76
  "@vitest/coverage-v8": "^2.0.5",
77
77
  "@vue/test-utils": "^2.4.6",
78
- "@wordpress/env": "^10.5.0",
78
+ "@wordpress/env": "^10.6.0",
79
79
  "changelogen": "^0.5.5",
80
80
  "markdownlint-cli": "^0.41.0",
81
- "nuxt": "^3.12.4",
81
+ "nuxt": "^3.13.0",
82
82
  "nuxt-content-twoslash": "^0.1.1",
83
83
  "release-it": "^17.6.0",
84
84
  "shiki": "^1.13.0",
85
85
  "twoslash": "^0.2.9",
86
86
  "typescript": "^5.5.4",
87
87
  "untyped": "1.4.2",
88
- "vite": "^5.4.1",
88
+ "vite": "^5.4.2",
89
89
  "vitest": "^2.0.5",
90
90
  "vue-docgen-web-types": "^0.1.8",
91
91
  "vue-tsc": "2.0.29"
@@ -1,5 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
- data: string;
3
- errors: never[];
4
- }>>;
5
- export default _default;
@@ -1,9 +0,0 @@
1
- import { defineEventHandler } from "h3";
2
- import { purgeCache } from "../storage.js";
3
- export default defineEventHandler(async () => {
4
- purgeCache();
5
- return {
6
- data: "Cache purged!",
7
- errors: []
8
- };
9
- });
@@ -1,3 +0,0 @@
1
- import { type Storage } from 'unstorage';
2
- export declare const cacheStorage: Storage;
3
- export declare const purgeCache: () => Promise<void>;
@@ -1,11 +0,0 @@
1
- import { prefixStorage } from "unstorage";
2
- import { useLogger } from "../util/logger.js";
3
- import { useStorage } from "#imports";
4
- export const cacheStorage = prefixStorage(useStorage(), "cache:wpnuxt-content");
5
- export const purgeCache = async () => {
6
- const keys = await cacheStorage.getKeys("cache:wpnuxt-content");
7
- keys.forEach(async (key) => {
8
- await cacheStorage.removeItem(key);
9
- });
10
- useLogger().info("ServerSide cache purged!");
11
- };