@justanarthur/payload-www 0.1.1
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 +381 -0
- package/dist/access.d.ts +11 -0
- package/dist/access.js +34 -0
- package/dist/blocks.d.ts +24 -0
- package/dist/blocks.js +75 -0
- package/dist/collections.d.ts +200 -0
- package/dist/collections.js +625 -0
- package/dist/components.d.ts +6 -0
- package/dist/components.js +38 -0
- package/dist/config.d.ts +100 -0
- package/dist/config.js +914 -0
- package/dist/core-access.d.ts +11 -0
- package/dist/core-access.js +34 -0
- package/dist/core-blocks.d.ts +24 -0
- package/dist/core-blocks.js +75 -0
- package/dist/core-fields.d.ts +36 -0
- package/dist/core-fields.js +134 -0
- package/dist/core-utils.d.ts +16 -0
- package/dist/core-utils.js +59 -0
- package/dist/data-collections.d.ts +200 -0
- package/dist/data-collections.js +625 -0
- package/dist/data-seed.d.ts +76 -0
- package/dist/data-seed.js +212 -0
- package/dist/data-test.d.ts +30 -0
- package/dist/data-test.js +1018 -0
- package/dist/fields.d.ts +36 -0
- package/dist/fields.js +134 -0
- package/dist/globals.d.ts +48 -0
- package/dist/globals.js +228 -0
- package/dist/hooks.d.ts +108 -0
- package/dist/hooks.js +196 -0
- package/dist/imagehash.d.ts +3 -0
- package/dist/imagehash.js +24 -0
- package/dist/import-map-provider.d.ts +20 -0
- package/dist/import-map-provider.js +26 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +38 -0
- package/dist/metadata.d.ts +122 -0
- package/dist/metadata.js +335 -0
- package/dist/pages.d.ts +323 -0
- package/dist/pages.js +1016 -0
- package/dist/render-components.d.ts +42 -0
- package/dist/render-components.js +144 -0
- package/dist/render-metadata.d.ts +122 -0
- package/dist/render-metadata.js +335 -0
- package/dist/render-pages.d.ts +574 -0
- package/dist/render-pages.js +1450 -0
- package/dist/render-utils.d.ts +158 -0
- package/dist/render-utils.js +341 -0
- package/dist/seed.d.ts +76 -0
- package/dist/seed.js +212 -0
- package/dist/server.d.ts +922 -0
- package/dist/server.js +2055 -0
- package/dist/test.d.ts +30 -0
- package/dist/test.js +1018 -0
- package/dist/translator.d.ts +2 -0
- package/dist/translator.js +24 -0
- package/dist/utils.d.ts +16 -0
- package/dist/utils.js +59 -0
- package/dist/with-www-config.d.ts +100 -0
- package/dist/with-www-config.js +914 -0
- package/package.json +246 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
17
|
+
|
|
18
|
+
// src/data/seed/createBaseSeed.ts
|
|
19
|
+
var simpleRichText = (text) => ({
|
|
20
|
+
root: {
|
|
21
|
+
type: "root",
|
|
22
|
+
format: "",
|
|
23
|
+
indent: 0,
|
|
24
|
+
version: 1,
|
|
25
|
+
direction: "ltr",
|
|
26
|
+
children: [
|
|
27
|
+
{
|
|
28
|
+
type: "paragraph",
|
|
29
|
+
format: "",
|
|
30
|
+
indent: 0,
|
|
31
|
+
version: 1,
|
|
32
|
+
direction: "ltr",
|
|
33
|
+
textFormat: 0,
|
|
34
|
+
children: [
|
|
35
|
+
{ mode: "normal", text, type: "text", style: "", detail: 0, format: 0, version: 1 }
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
async function createBaseSeed(payload, options = {}) {
|
|
42
|
+
const localization = payload.config.localization;
|
|
43
|
+
const defaultLocale = options.defaultLocale ?? (typeof localization === "object" && localization ? typeof localization.defaultLocale === "string" ? localization.defaultLocale : "en" : "en");
|
|
44
|
+
const configLocales = typeof localization === "object" && localization ? (localization.locales ?? []).map((l) => typeof l === "string" ? l : l.code) : [];
|
|
45
|
+
const locales = options.locales ?? (configLocales.length > 0 ? configLocales : [defaultLocale]);
|
|
46
|
+
const result = { users: [], categories: [], pages: [], posts: [] };
|
|
47
|
+
const pagesCollection = payload.collections["pages"];
|
|
48
|
+
if (!pagesCollection) {
|
|
49
|
+
throw new Error("createBaseSeed: no `pages` collection registered with this payload instance");
|
|
50
|
+
}
|
|
51
|
+
const findBlocksField = (fields) => {
|
|
52
|
+
for (const f of fields) {
|
|
53
|
+
if (f.name === "blocks" && Array.isArray(f.blocks))
|
|
54
|
+
return f;
|
|
55
|
+
if (Array.isArray(f.fields)) {
|
|
56
|
+
const found = findBlocksField(f.fields);
|
|
57
|
+
if (found)
|
|
58
|
+
return found;
|
|
59
|
+
}
|
|
60
|
+
if (Array.isArray(f.tabs)) {
|
|
61
|
+
for (const t of f.tabs) {
|
|
62
|
+
if (Array.isArray(t.fields)) {
|
|
63
|
+
const found = findBlocksField(t.fields);
|
|
64
|
+
if (found)
|
|
65
|
+
return found;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
};
|
|
72
|
+
const layoutField = findBlocksField(pagesCollection.config.fields);
|
|
73
|
+
const validBlockSlugs = new Set((layoutField?.blocks ?? []).map((b) => b.slug));
|
|
74
|
+
for (const page of options.pages ?? []) {
|
|
75
|
+
for (const block of page.blocks ?? []) {
|
|
76
|
+
const slug = block.blockType;
|
|
77
|
+
if (!slug) {
|
|
78
|
+
throw new Error(`createBaseSeed: page "${page.slug}" has a block without blockType`);
|
|
79
|
+
}
|
|
80
|
+
if (!validBlockSlugs.has(slug)) {
|
|
81
|
+
throw new Error(`createBaseSeed: page "${page.slug}" references unknown block slug "${slug}". Allowed: ${[...validBlockSlugs].join(", ")}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (options.dryRun)
|
|
86
|
+
return result;
|
|
87
|
+
for (const user of options.users ?? [{ email: "dev@payloadcms.com", password: "test", name: "Dev User" }]) {
|
|
88
|
+
const existing = await payload.find({
|
|
89
|
+
collection: "users",
|
|
90
|
+
where: { email: { equals: user.email } },
|
|
91
|
+
limit: 1,
|
|
92
|
+
overrideAccess: true
|
|
93
|
+
});
|
|
94
|
+
let id;
|
|
95
|
+
if (existing.docs.length > 0) {
|
|
96
|
+
id = existing.docs[0].id;
|
|
97
|
+
} else {
|
|
98
|
+
const created = await payload.create({
|
|
99
|
+
collection: "users",
|
|
100
|
+
data: { email: user.email, password: user.password ?? "test", name: user.name ?? "" },
|
|
101
|
+
overrideAccess: true
|
|
102
|
+
});
|
|
103
|
+
id = created.id;
|
|
104
|
+
}
|
|
105
|
+
result.users.push({ id, email: user.email });
|
|
106
|
+
}
|
|
107
|
+
for (const cat of options.categories ?? []) {
|
|
108
|
+
const slug = cat.slug ?? cat.title.toLowerCase().replace(/\s+/g, "-");
|
|
109
|
+
const existing = await payload.find({
|
|
110
|
+
collection: "categories",
|
|
111
|
+
where: { title: { equals: cat.title } },
|
|
112
|
+
limit: 1,
|
|
113
|
+
overrideAccess: true
|
|
114
|
+
});
|
|
115
|
+
let id;
|
|
116
|
+
if (existing.docs.length > 0) {
|
|
117
|
+
id = existing.docs[0].id;
|
|
118
|
+
} else {
|
|
119
|
+
const created = await payload.create({
|
|
120
|
+
collection: "categories",
|
|
121
|
+
data: { title: cat.title, slug },
|
|
122
|
+
overrideAccess: true
|
|
123
|
+
});
|
|
124
|
+
id = created.id;
|
|
125
|
+
}
|
|
126
|
+
result.categories.push({ id, title: cat.title, slug });
|
|
127
|
+
}
|
|
128
|
+
for (const page of options.pages ?? []) {
|
|
129
|
+
const existing = await payload.find({
|
|
130
|
+
collection: "pages",
|
|
131
|
+
where: { slug: { equals: page.slug } },
|
|
132
|
+
limit: 1,
|
|
133
|
+
overrideAccess: true
|
|
134
|
+
});
|
|
135
|
+
const data = {
|
|
136
|
+
slug: page.slug,
|
|
137
|
+
title: { ...page.title },
|
|
138
|
+
blocks: page.blocks ?? [],
|
|
139
|
+
publishedAt: page.publishedAt ?? new Date().toISOString(),
|
|
140
|
+
_status: page.status === "draft" ? "draft" : "published"
|
|
141
|
+
};
|
|
142
|
+
if (page.meta)
|
|
143
|
+
data.meta = { ...page.meta };
|
|
144
|
+
let id;
|
|
145
|
+
if (existing.docs.length === 0) {
|
|
146
|
+
const created = await payload.create({
|
|
147
|
+
collection: "pages",
|
|
148
|
+
data,
|
|
149
|
+
overrideAccess: true,
|
|
150
|
+
draft: page.status === "draft"
|
|
151
|
+
});
|
|
152
|
+
id = created.id;
|
|
153
|
+
} else {
|
|
154
|
+
id = existing.docs[0].id;
|
|
155
|
+
await payload.update({
|
|
156
|
+
collection: "pages",
|
|
157
|
+
id,
|
|
158
|
+
data,
|
|
159
|
+
overrideAccess: true,
|
|
160
|
+
draft: page.status === "draft"
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
for (const locale of locales)
|
|
164
|
+
result.pages.push({ id, slug: page.slug, locale });
|
|
165
|
+
}
|
|
166
|
+
for (const post of options.posts ?? []) {
|
|
167
|
+
const existing = await payload.find({
|
|
168
|
+
collection: "posts",
|
|
169
|
+
where: { slug: { equals: post.slug } },
|
|
170
|
+
limit: 1,
|
|
171
|
+
overrideAccess: true
|
|
172
|
+
});
|
|
173
|
+
const data = {
|
|
174
|
+
slug: post.slug,
|
|
175
|
+
title: { ...post.title },
|
|
176
|
+
...post.excerpt ? { excerpt: { ...post.excerpt } } : {},
|
|
177
|
+
content: post.content ?? simpleRichText("Hello world"),
|
|
178
|
+
publishedAt: post.publishedAt ?? new Date().toISOString(),
|
|
179
|
+
authors: result.users.length > 0 ? [result.users[0].id] : [],
|
|
180
|
+
_status: post.status === "draft" ? "draft" : "published"
|
|
181
|
+
};
|
|
182
|
+
let id;
|
|
183
|
+
if (existing.docs.length === 0) {
|
|
184
|
+
const created = await payload.create({
|
|
185
|
+
collection: "posts",
|
|
186
|
+
data,
|
|
187
|
+
overrideAccess: true,
|
|
188
|
+
draft: post.status === "draft"
|
|
189
|
+
});
|
|
190
|
+
id = created.id;
|
|
191
|
+
} else {
|
|
192
|
+
id = existing.docs[0].id;
|
|
193
|
+
await payload.update({
|
|
194
|
+
collection: "posts",
|
|
195
|
+
id,
|
|
196
|
+
data,
|
|
197
|
+
overrideAccess: true,
|
|
198
|
+
draft: post.status === "draft"
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
for (const locale of locales)
|
|
202
|
+
result.posts.push({ id, slug: post.slug, locale });
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// src/exports/data-seed.ts
|
|
208
|
+
var data_seed_default = createBaseSeed;
|
|
209
|
+
export {
|
|
210
|
+
data_seed_default as default,
|
|
211
|
+
createBaseSeed
|
|
212
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Payload } from "payload";
|
|
2
|
+
type CreateTestPayloadOptions = {
|
|
3
|
+
/** Default blocks for the Pages collection. */
|
|
4
|
+
blocks?: any[];
|
|
5
|
+
/** Locale list. First entry is the default locale. */
|
|
6
|
+
locales?: readonly string[];
|
|
7
|
+
/** Database file path. Default: temp file. */
|
|
8
|
+
databaseFile?: string;
|
|
9
|
+
/** Run payload auto-migration before returning. Default: `true`. */
|
|
10
|
+
migrate?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Strip `versions` from the Pages collection. Default: `false`.
|
|
13
|
+
* Set to `true` for integration tests that don't need versioning
|
|
14
|
+
* (avoids a payload@3.85 drizzle version-table build quirk).
|
|
15
|
+
*/
|
|
16
|
+
overridePagesVersions?: boolean;
|
|
17
|
+
};
|
|
18
|
+
type CreateTestPayloadResult = {
|
|
19
|
+
payload: Payload;
|
|
20
|
+
databaseFile: string;
|
|
21
|
+
destroy: () => Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Build a Payload instance backed by a temp SQLite database for
|
|
25
|
+
* vitest integration tests. The lib's `createWWWConfig` is wired
|
|
26
|
+
* with a single empty-block Pages collection; tests add more
|
|
27
|
+
* collections via `configOverrides` if needed.
|
|
28
|
+
*/
|
|
29
|
+
declare function createTestPayload(options?: CreateTestPayloadOptions): Promise<CreateTestPayloadResult>;
|
|
30
|
+
export { createTestPayload as default, createTestPayload, CreateTestPayloadResult, CreateTestPayloadOptions };
|