@justanarthur/payload-www 0.3.2 → 0.3.4
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/access.js +13 -3
- package/dist/blocks.js +21 -7
- package/dist/collections.js +72 -19
- package/dist/components.js +1 -0
- package/dist/config.js +108 -26
- package/dist/core-access.js +13 -3
- package/dist/core-blocks.js +21 -7
- package/dist/core-fields.js +21 -7
- package/dist/core-utils.js +20 -6
- package/dist/data-collections.js +72 -19
- package/dist/data-test.js +108 -26
- package/dist/fields.js +21 -7
- package/dist/globals.js +18 -1
- package/dist/hooks.js +47 -15
- package/dist/index.js +1 -0
- package/dist/metadata.js +68 -22
- package/dist/pages.js +133 -39
- package/dist/render-components.js +13 -3
- package/dist/render-metadata.js +68 -22
- package/dist/render-pages.js +223 -59
- package/dist/render-utils.js +62 -16
- package/dist/server.js +245 -69
- package/dist/test.js +108 -26
- package/dist/utils.js +20 -6
- package/dist/with-www-config.js +108 -26
- package/package.json +1 -1
package/dist/access.js
CHANGED
|
@@ -16,11 +16,21 @@ var __export = (target, all) => {
|
|
|
16
16
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
17
|
|
|
18
18
|
// src/core/access/index.ts
|
|
19
|
-
var anyone = () =>
|
|
20
|
-
|
|
19
|
+
var anyone = () => {
|
|
20
|
+
console.log("[WWW] core/access:anyone -> true");
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
var authenticated = ({ req: { user } }) => {
|
|
24
|
+
const result = Boolean(user);
|
|
25
|
+
console.log("[WWW] core/access:authenticated ->", result);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
21
28
|
var authenticatedOrPublished = ({ req: { user } }) => {
|
|
22
|
-
if (user)
|
|
29
|
+
if (user) {
|
|
30
|
+
console.log("[WWW] core/access:authenticatedOrPublished -> true (authenticated)");
|
|
23
31
|
return true;
|
|
32
|
+
}
|
|
33
|
+
console.log('[WWW] core/access:authenticatedOrPublished -> { _status: { equals: "published" } }');
|
|
24
34
|
return { _status: { equals: "published" } };
|
|
25
35
|
};
|
|
26
36
|
|
package/dist/blocks.js
CHANGED
|
@@ -17,17 +17,27 @@ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
|
17
17
|
|
|
18
18
|
// src/core/utils/getFromImportMap.ts
|
|
19
19
|
function getFromImportMap(key, importMap) {
|
|
20
|
-
|
|
20
|
+
const resolvedKey = key.includes("#") ? key : key + "#default";
|
|
21
|
+
const value = importMap[resolvedKey];
|
|
22
|
+
console.log("[WWW] core/utils:getFromImportMap key=", key, "resolved=", resolvedKey, "hit=", Boolean(value));
|
|
23
|
+
return value;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
// src/core/utils/generateImportName.ts
|
|
24
27
|
function generateImportName(type, slug) {
|
|
25
28
|
switch (type) {
|
|
26
|
-
case "block":
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return
|
|
29
|
+
case "block": {
|
|
30
|
+
const name = `Block${slug.replace(/(^\w|-\w)/g, (m) => m.replace("-", "").toUpperCase())}#default`;
|
|
31
|
+
console.log("[WWW] core/utils:generateImportName type=block slug=", slug, "->", name);
|
|
32
|
+
return name;
|
|
33
|
+
}
|
|
34
|
+
case "page": {
|
|
35
|
+
const name = `Page${slug.replace(/(^\w|-\w)/g, (m) => m.replace("-", "").toUpperCase())}#default`;
|
|
36
|
+
console.log("[WWW] core/utils:generateImportName type=page slug=", slug, "->", name);
|
|
37
|
+
return name;
|
|
38
|
+
}
|
|
30
39
|
default:
|
|
40
|
+
console.error("[WWW] core/utils:generateImportName unknown type:", type);
|
|
31
41
|
throw new Error(`Unknown type: ${type}`);
|
|
32
42
|
}
|
|
33
43
|
}
|
|
@@ -42,8 +52,11 @@ var RenderBlocks = ({
|
|
|
42
52
|
locale,
|
|
43
53
|
searchParams
|
|
44
54
|
}) => {
|
|
45
|
-
if (!blocks || !Array.isArray(blocks) || blocks.length === 0)
|
|
55
|
+
if (!blocks || !Array.isArray(blocks) || blocks.length === 0) {
|
|
56
|
+
console.log("[WWW] render/blocks:RenderBlocks no blocks (locale=", locale, ")");
|
|
46
57
|
return null;
|
|
58
|
+
}
|
|
59
|
+
console.log("[WWW] render/blocks:RenderBlocks rendering count=", blocks.length, "locale=", locale);
|
|
47
60
|
const rendered = [];
|
|
48
61
|
for (let i = 0;i < blocks.length; i++) {
|
|
49
62
|
const block = blocks[i];
|
|
@@ -51,9 +64,10 @@ var RenderBlocks = ({
|
|
|
51
64
|
const importMapPath = config.admin?.dependencies?.[blockType]?.path ?? generateImportName("block", blockType);
|
|
52
65
|
const Block = getFromImportMap(importMapPath, importMap);
|
|
53
66
|
if (!Block) {
|
|
54
|
-
console.warn(`
|
|
67
|
+
console.warn(`[WWW] render/blocks:RenderBlocks no block for type=${blockType} importMapPath=${importMapPath} (locale=${locale})`);
|
|
55
68
|
continue;
|
|
56
69
|
}
|
|
70
|
+
console.log("[WWW] render/blocks:RenderBlocks [", i, "] blockType=", blockType, "importMapPath=", importMapPath);
|
|
57
71
|
rendered.push(/* @__PURE__ */ jsx(Block, {
|
|
58
72
|
index: i,
|
|
59
73
|
...blockProps,
|
package/dist/collections.js
CHANGED
|
@@ -16,11 +16,21 @@ var __export = (target, all) => {
|
|
|
16
16
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
17
|
|
|
18
18
|
// src/core/access/index.ts
|
|
19
|
-
var anyone = () =>
|
|
20
|
-
|
|
19
|
+
var anyone = () => {
|
|
20
|
+
console.log("[WWW] core/access:anyone -> true");
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
var authenticated = ({ req: { user } }) => {
|
|
24
|
+
const result = Boolean(user);
|
|
25
|
+
console.log("[WWW] core/access:authenticated ->", result);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
21
28
|
var authenticatedOrPublished = ({ req: { user } }) => {
|
|
22
|
-
if (user)
|
|
29
|
+
if (user) {
|
|
30
|
+
console.log("[WWW] core/access:authenticatedOrPublished -> true (authenticated)");
|
|
23
31
|
return true;
|
|
32
|
+
}
|
|
33
|
+
console.log('[WWW] core/access:authenticatedOrPublished -> { _status: { equals: "published" } }');
|
|
24
34
|
return { _status: { equals: "published" } };
|
|
25
35
|
};
|
|
26
36
|
|
|
@@ -31,6 +41,7 @@ var slugField = (options = {}) => {
|
|
|
31
41
|
const { name = "slug", nested = false, localized = true } = options;
|
|
32
42
|
const pattern = nested ? NESTED_PATTERN : FLAT_PATTERN;
|
|
33
43
|
const invalidMessage = nested ? "Slug must be lowercase, with hyphens or the `_` nesting divider (no spaces or other special characters)" : "Slug must be lowercase, with hyphens (no spaces or special characters)";
|
|
44
|
+
console.log("[WWW] core/fields:slugField options=", JSON.stringify({ name, nested, localized }));
|
|
34
45
|
return {
|
|
35
46
|
name,
|
|
36
47
|
type: "text",
|
|
@@ -45,8 +56,10 @@ var slugField = (options = {}) => {
|
|
|
45
56
|
validate: (value) => {
|
|
46
57
|
if (typeof value !== "string")
|
|
47
58
|
return "Slug must be a string";
|
|
48
|
-
if (value !== "" && !pattern.test(value))
|
|
59
|
+
if (value !== "" && !pattern.test(value)) {
|
|
60
|
+
console.warn("[WWW] core/fields:slugField invalid slug value=", JSON.stringify(value));
|
|
49
61
|
return invalidMessage;
|
|
62
|
+
}
|
|
50
63
|
return true;
|
|
51
64
|
}
|
|
52
65
|
};
|
|
@@ -54,30 +67,45 @@ var slugField = (options = {}) => {
|
|
|
54
67
|
|
|
55
68
|
// src/render/_locale.ts
|
|
56
69
|
function prefixFor(locale, defaultLocale, mode) {
|
|
70
|
+
let result;
|
|
57
71
|
if (mode === "never")
|
|
58
|
-
|
|
59
|
-
if (mode === "as-needed" && locale === defaultLocale)
|
|
60
|
-
|
|
61
|
-
|
|
72
|
+
result = "";
|
|
73
|
+
else if (mode === "as-needed" && locale === defaultLocale)
|
|
74
|
+
result = "";
|
|
75
|
+
else
|
|
76
|
+
result = `/${locale}`;
|
|
77
|
+
console.log("[WWW] render/_locale:prefixFor locale=", locale, "default=", defaultLocale, "mode=", mode, "->", JSON.stringify(result));
|
|
78
|
+
return result;
|
|
62
79
|
}
|
|
63
80
|
function resolveLocale(req) {
|
|
64
|
-
if (!req || typeof req !== "object")
|
|
81
|
+
if (!req || typeof req !== "object") {
|
|
82
|
+
console.log('[WWW] render/_locale:resolveLocale -> "" (no req)');
|
|
65
83
|
return "";
|
|
84
|
+
}
|
|
66
85
|
const r = req;
|
|
67
|
-
if (typeof r.locale === "string" && r.locale.length > 0)
|
|
86
|
+
if (typeof r.locale === "string" && r.locale.length > 0) {
|
|
87
|
+
console.log("[WWW] render/_locale:resolveLocale ->", r.locale, "(from req.locale)");
|
|
68
88
|
return r.locale;
|
|
89
|
+
}
|
|
69
90
|
const fallback = r.payload?.config?.localization?.defaultLocale;
|
|
70
|
-
if (typeof fallback === "string" && fallback.length > 0)
|
|
91
|
+
if (typeof fallback === "string" && fallback.length > 0) {
|
|
92
|
+
console.log("[WWW] render/_locale:resolveLocale ->", fallback, "(from config.localization.defaultLocale)");
|
|
71
93
|
return fallback;
|
|
94
|
+
}
|
|
95
|
+
console.log('[WWW] render/_locale:resolveLocale -> "" (no locale anywhere)');
|
|
72
96
|
return "";
|
|
73
97
|
}
|
|
74
98
|
function allLocales(req) {
|
|
75
|
-
if (!req || typeof req !== "object")
|
|
99
|
+
if (!req || typeof req !== "object") {
|
|
100
|
+
console.log("[WWW] render/_locale:allLocales -> [] (no req)");
|
|
76
101
|
return [];
|
|
102
|
+
}
|
|
77
103
|
const r = req;
|
|
78
104
|
const list = r.payload?.config?.localization?.locales;
|
|
79
|
-
if (!Array.isArray(list) || list.length === 0)
|
|
105
|
+
if (!Array.isArray(list) || list.length === 0) {
|
|
106
|
+
console.log("[WWW] render/_locale:allLocales -> [] (no locales declared)");
|
|
80
107
|
return [];
|
|
108
|
+
}
|
|
81
109
|
const out = [];
|
|
82
110
|
for (const entry of list) {
|
|
83
111
|
if (typeof entry === "string" && entry.length > 0) {
|
|
@@ -88,6 +116,7 @@ function allLocales(req) {
|
|
|
88
116
|
out.push(code);
|
|
89
117
|
}
|
|
90
118
|
}
|
|
119
|
+
console.log("[WWW] render/_locale:allLocales ->", JSON.stringify(out));
|
|
91
120
|
return out;
|
|
92
121
|
}
|
|
93
122
|
|
|
@@ -97,21 +126,28 @@ function nextCacheImport() {
|
|
|
97
126
|
return cachePromise ??= import("next/cache");
|
|
98
127
|
}
|
|
99
128
|
function shouldSkipRevalidate(context) {
|
|
100
|
-
|
|
129
|
+
const skip = Boolean(context?.disableRevalidate);
|
|
130
|
+
if (skip)
|
|
131
|
+
console.log("[WWW] render/hooks:_shared:shouldSkipRevalidate -> skip");
|
|
132
|
+
return skip;
|
|
101
133
|
}
|
|
102
134
|
async function safeRevalidatePath(payload, path) {
|
|
135
|
+
console.log("[WWW] render/hooks:_shared:safeRevalidatePath path=", path);
|
|
103
136
|
try {
|
|
104
137
|
const { revalidatePath } = await nextCacheImport();
|
|
105
138
|
revalidatePath(path);
|
|
106
139
|
} catch (error) {
|
|
140
|
+
console.error("[WWW] render/hooks:_shared:safeRevalidatePath failed path=", path, "err=", String(error));
|
|
107
141
|
payload.logger.error(`revalidatePath("${path}") failed: ${String(error)}`);
|
|
108
142
|
}
|
|
109
143
|
}
|
|
110
144
|
async function safeRevalidateTag(payload, tag, profile = "max") {
|
|
145
|
+
console.log("[WWW] render/hooks:_shared:safeRevalidateTag tag=", tag, "profile=", profile);
|
|
111
146
|
try {
|
|
112
147
|
const { revalidateTag } = await nextCacheImport();
|
|
113
148
|
revalidateTag(tag, profile);
|
|
114
149
|
} catch (error) {
|
|
150
|
+
console.error("[WWW] render/hooks:_shared:safeRevalidateTag failed tag=", tag, "err=", String(error));
|
|
115
151
|
payload.logger.error(`revalidateTag("${tag}") failed: ${String(error)}`);
|
|
116
152
|
}
|
|
117
153
|
}
|
|
@@ -127,6 +163,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
127
163
|
pathMode = "url"
|
|
128
164
|
} = options;
|
|
129
165
|
const resolvedSitemapTag = sitemapTag === false ? false : sitemapTag ?? `${collectionSlug}-sitemap`;
|
|
166
|
+
console.log("[WWW] render/hooks:createRevalidateCollectionHook collectionSlug=", collectionSlug, "urlPathPrefix=", urlPathPrefix, "sitemapTag=", resolvedSitemapTag, "pathMode=", pathMode);
|
|
130
167
|
const resolveDefaults = (req) => {
|
|
131
168
|
const mode = modeOption ?? "always";
|
|
132
169
|
const defaultLocale = defaultLocaleOption ?? req?.payload?.config?.localization?.defaultLocale ?? "";
|
|
@@ -155,6 +192,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
155
192
|
}
|
|
156
193
|
};
|
|
157
194
|
const fireCollectionTags = async (payload, docId, req) => {
|
|
195
|
+
console.log("[WWW] render/hooks:fireCollectionTags collectionSlug=", collectionSlug, "docId=", docId);
|
|
158
196
|
if (typeof docId === "string" || typeof docId === "number") {
|
|
159
197
|
await safeRevalidateTag(payload, `collection_${collectionSlug}_${docId}`);
|
|
160
198
|
}
|
|
@@ -168,6 +206,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
168
206
|
const { payload } = req;
|
|
169
207
|
const typed = doc;
|
|
170
208
|
const prev = previousDoc;
|
|
209
|
+
console.log("[WWW] render/hooks:afterChange collectionSlug=", collectionSlug, "id=", typed.id, "slug=", typed.slug, "prevSlug=", prev?.slug);
|
|
171
210
|
const isPublished = typed._status === "published";
|
|
172
211
|
const wasPublished = prev?._status === "published";
|
|
173
212
|
const prevSlugIsString = typeof prev?.slug === "string";
|
|
@@ -191,6 +230,7 @@ function createRevalidateCollectionHook(options) {
|
|
|
191
230
|
return doc ?? null;
|
|
192
231
|
const { payload } = req;
|
|
193
232
|
const typed = doc;
|
|
233
|
+
console.log("[WWW] render/hooks:afterDelete collectionSlug=", collectionSlug, "id=", typed?.id, "slug=", typed?.slug);
|
|
194
234
|
if (pathMode !== "tag-only") {
|
|
195
235
|
await fanOutPaths(payload, req, typed?.slug, `Revalidating deleted ${collectionSlug} at path:`);
|
|
196
236
|
}
|
|
@@ -199,11 +239,14 @@ function createRevalidateCollectionHook(options) {
|
|
|
199
239
|
};
|
|
200
240
|
return { afterChange, afterDelete };
|
|
201
241
|
}
|
|
202
|
-
var createRevalidatePageHooks = (opts = {}) =>
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
242
|
+
var createRevalidatePageHooks = (opts = {}) => {
|
|
243
|
+
console.log("[WWW] render/hooks:createRevalidatePageHooks (deprecated alias) opts=", JSON.stringify(opts));
|
|
244
|
+
return createRevalidateCollectionHook({
|
|
245
|
+
collectionSlug: "pages",
|
|
246
|
+
urlPathPrefix: "",
|
|
247
|
+
...opts
|
|
248
|
+
});
|
|
249
|
+
};
|
|
207
250
|
|
|
208
251
|
// src/config/constants.ts
|
|
209
252
|
var PAGES_RENDER_PATH = "@justanarthur/payload-www/render-pages#PagesPage";
|
|
@@ -428,6 +471,13 @@ var link = (options = {}) => {
|
|
|
428
471
|
overrides = {},
|
|
429
472
|
extraFields = []
|
|
430
473
|
} = options;
|
|
474
|
+
console.log("[WWW] core/fields:link options=", JSON.stringify({
|
|
475
|
+
appearances: appearances === false ? false : appearances ?? "default-set",
|
|
476
|
+
disableLabel,
|
|
477
|
+
relationTo,
|
|
478
|
+
localized,
|
|
479
|
+
extraFieldsCount: extraFields.length
|
|
480
|
+
}));
|
|
431
481
|
const result = {
|
|
432
482
|
name: "link",
|
|
433
483
|
type: "group",
|
|
@@ -506,15 +556,18 @@ var link = (options = {}) => {
|
|
|
506
556
|
if (extraFields.length) {
|
|
507
557
|
result.fields.push(...extraFields);
|
|
508
558
|
}
|
|
559
|
+
console.log("[WWW] core/fields:link built fieldsCount=", result.fields.length);
|
|
509
560
|
return { ...result, ...overrides };
|
|
510
561
|
};
|
|
511
562
|
|
|
512
563
|
// src/render/hooks/revalidateGlobal.ts
|
|
513
564
|
function createRevalidateGlobalHook(slug) {
|
|
565
|
+
console.log("[WWW] render/hooks:createRevalidateGlobalHook slug=", slug);
|
|
514
566
|
return async ({ doc, req: { payload, context, locale } }) => {
|
|
515
567
|
if (shouldSkipRevalidate(context))
|
|
516
568
|
return doc;
|
|
517
569
|
const tags = [`global_${slug}`, `global_${slug}_${locale}`];
|
|
570
|
+
console.log("[WWW] render/hooks:revalidateGlobal slug=", slug, "locale=", locale, "tags=", JSON.stringify(tags));
|
|
518
571
|
payload.logger.info?.(`Revalidating global: ${tags.join(", ")}`);
|
|
519
572
|
for (const tag of tags) {
|
|
520
573
|
await safeRevalidateTag(payload, tag);
|
package/dist/components.js
CHANGED
|
@@ -24,6 +24,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
24
24
|
var LivePreviewListener = ({ serverURL }) => {
|
|
25
25
|
const router = useRouter();
|
|
26
26
|
const url = serverURL ?? process.env.NEXT_PUBLIC_SERVER_URL ?? (typeof window !== "undefined" ? window.location.origin : "");
|
|
27
|
+
console.log("[WWW] render/components:LivePreviewListener serverURL=", url);
|
|
27
28
|
return /* @__PURE__ */ jsx(PayloadLivePreview, {
|
|
28
29
|
refresh: router.refresh,
|
|
29
30
|
serverURL: url
|