@justanarthur/payload-www 0.3.4 → 1.0.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.
Files changed (62) hide show
  1. package/README.md +317 -307
  2. package/dist/access.d.ts +2 -2
  3. package/dist/access.js +6 -30
  4. package/dist/blocks.d.ts +0 -10
  5. package/dist/blocks.js +8 -33
  6. package/dist/collections.d.ts +33 -225
  7. package/dist/collections.js +186 -661
  8. package/dist/config.d.ts +19 -105
  9. package/dist/config.js +263 -868
  10. package/dist/fields.d.ts +4 -46
  11. package/dist/fields.js +183 -73
  12. package/dist/imagehash.js +0 -15
  13. package/dist/import-map-provider.d.ts +0 -16
  14. package/dist/import-map-provider.js +0 -15
  15. package/dist/metadata.d.ts +24 -89
  16. package/dist/metadata.js +123 -258
  17. package/dist/pages.d.ts +37 -319
  18. package/dist/pages.js +355 -973
  19. package/dist/render-pages.d.ts +69 -564
  20. package/dist/render-pages.js +476 -1502
  21. package/dist/sitemap.d.ts +10 -0
  22. package/dist/sitemap.js +324 -0
  23. package/dist/translator.js +0 -15
  24. package/dist/utils.d.ts +4 -12
  25. package/dist/utils.js +10 -56
  26. package/package.json +75 -178
  27. package/dist/components.d.ts +0 -6
  28. package/dist/components.js +0 -39
  29. package/dist/core-access.d.ts +0 -11
  30. package/dist/core-access.js +0 -44
  31. package/dist/core-blocks.d.ts +0 -24
  32. package/dist/core-blocks.js +0 -89
  33. package/dist/core-fields.d.ts +0 -73
  34. package/dist/core-fields.js +0 -181
  35. package/dist/core-utils.d.ts +0 -16
  36. package/dist/core-utils.js +0 -73
  37. package/dist/data-collections.d.ts +0 -229
  38. package/dist/data-collections.js +0 -697
  39. package/dist/data-seed.d.ts +0 -76
  40. package/dist/data-seed.js +0 -212
  41. package/dist/data-test.d.ts +0 -30
  42. package/dist/data-test.js +0 -1134
  43. package/dist/globals.d.ts +0 -69
  44. package/dist/globals.js +0 -259
  45. package/dist/hooks.d.ts +0 -108
  46. package/dist/hooks.js +0 -228
  47. package/dist/index.d.ts +0 -6
  48. package/dist/index.js +0 -39
  49. package/dist/render-components.d.ts +0 -42
  50. package/dist/render-components.js +0 -154
  51. package/dist/render-metadata.d.ts +0 -122
  52. package/dist/render-metadata.js +0 -393
  53. package/dist/render-utils.d.ts +0 -166
  54. package/dist/render-utils.js +0 -401
  55. package/dist/seed.d.ts +0 -76
  56. package/dist/seed.js +0 -212
  57. package/dist/server.d.ts +0 -980
  58. package/dist/server.js +0 -2265
  59. package/dist/test.d.ts +0 -30
  60. package/dist/test.js +0 -1134
  61. package/dist/with-www-config.d.ts +0 -108
  62. package/dist/with-www-config.js +0 -1030
@@ -1,76 +0,0 @@
1
- import { Payload } from "payload";
2
- type SeedPageInput = {
3
- slug: string;
4
- title: Record<string, string>;
5
- meta?: Record<string, {
6
- title?: string;
7
- description?: string;
8
- }>;
9
- blocks?: Array<Record<string, unknown>>;
10
- status?: "draft" | "published";
11
- publishedAt?: string;
12
- };
13
- type SeedPostInput = {
14
- slug: string;
15
- title: Record<string, string>;
16
- excerpt?: Record<string, string>;
17
- content?: Record<string, unknown>;
18
- status?: "draft" | "published";
19
- publishedAt?: string;
20
- };
21
- type SeedUserInput = {
22
- email: string;
23
- password?: string;
24
- name?: string;
25
- };
26
- type SeedCategoryInput = {
27
- title: string;
28
- slug?: string;
29
- };
30
- type CreateBaseSeedOptions = {
31
- defaultLocale?: string;
32
- locales?: string[];
33
- users?: SeedUserInput[];
34
- categories?: SeedCategoryInput[];
35
- pages?: SeedPageInput[];
36
- posts?: SeedPostInput[];
37
- dryRun?: boolean;
38
- };
39
- type CreateBaseSeedResult = {
40
- users: Array<{
41
- id: string | number;
42
- email: string;
43
- }>;
44
- categories: Array<{
45
- id: string | number;
46
- title: string;
47
- slug: string;
48
- }>;
49
- pages: Array<{
50
- id: string | number;
51
- slug: string;
52
- locale: string;
53
- }>;
54
- posts: Array<{
55
- id: string | number;
56
- slug: string;
57
- locale: string;
58
- }>;
59
- };
60
- /**
61
- * Idempotent seeder for the lib's collections. Re-running on the
62
- * same database is a no-op for users (matched by email) and
63
- * categories (matched by title); pages and posts are matched by
64
- * slug and re-created if missing.
65
- *
66
- * Pages and posts are created once per slug — localized values are
67
- * stored in a single doc per slug. Tests assert the alternate
68
- * resolution by querying `locale: 'all'`.
69
- *
70
- * Throws on:
71
- * - any block slug in a Page's `layout` that doesn't exist on the
72
- * Pages collection's `blocks` field
73
- * - a block without a `blockType`
74
- */
75
- declare function createBaseSeed(payload: Payload, options?: CreateBaseSeedOptions): Promise<CreateBaseSeedResult>;
76
- export { createBaseSeed as default, createBaseSeed, SeedUserInput, SeedPostInput, SeedPageInput, SeedCategoryInput, CreateBaseSeedResult, CreateBaseSeedOptions };
package/dist/data-seed.js DELETED
@@ -1,212 +0,0 @@
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
- };
@@ -1,30 +0,0 @@
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 };