@vitrine-kit/payload-blueprint 0.2.4 → 0.3.0
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/index.d.ts +4 -2
- package/dist/index.js +26 -8
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BlueprintFieldDef, Extend } from '@vitrine-kit/contracts';
|
|
2
2
|
|
|
3
|
-
declare const PAYLOAD_BLUEPRINT_VERSION: "0.
|
|
3
|
+
declare const PAYLOAD_BLUEPRINT_VERSION: "0.3.0";
|
|
4
4
|
|
|
5
5
|
interface BlueprintCollectionConfig {
|
|
6
6
|
slug: string;
|
|
@@ -20,7 +20,9 @@ declare const baseCollections: BlueprintCollectionConfig[];
|
|
|
20
20
|
|
|
21
21
|
interface Blueprint {
|
|
22
22
|
extend: Extend;
|
|
23
|
-
/**
|
|
23
|
+
/** Add a collection that is not in the base set (e.g. storefront customers). */
|
|
24
|
+
addCollection(config: BlueprintCollectionConfig): void;
|
|
25
|
+
/** Assembles the base collections + additive extensions + extras. */
|
|
24
26
|
build(): BlueprintCollectionConfig[];
|
|
25
27
|
}
|
|
26
28
|
declare function createBlueprint(): Blueprint;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.generated.ts
|
|
2
|
-
var PAYLOAD_BLUEPRINT_VERSION = "0.
|
|
2
|
+
var PAYLOAD_BLUEPRINT_VERSION = "0.3.0";
|
|
3
3
|
|
|
4
4
|
// src/collections.ts
|
|
5
5
|
var f = (name, type, extra = {}) => ({ name, type, ...extra });
|
|
@@ -11,9 +11,9 @@ var categoriesCollection = {
|
|
|
11
11
|
admin: { useAsTitle: "title" },
|
|
12
12
|
access: publicRead,
|
|
13
13
|
fields: [
|
|
14
|
-
f("title", "text", { required: true }),
|
|
14
|
+
f("title", "text", { required: true, localized: true }),
|
|
15
15
|
f("slug", "text", { required: true, unique: true, index: true }),
|
|
16
|
-
f("description", "textarea"),
|
|
16
|
+
f("description", "textarea", { localized: true }),
|
|
17
17
|
f("parent", "relationship", { relationTo: "categories" })
|
|
18
18
|
]
|
|
19
19
|
};
|
|
@@ -51,13 +51,17 @@ var productsCollection = {
|
|
|
51
51
|
admin: { useAsTitle: "title" },
|
|
52
52
|
access: publicRead,
|
|
53
53
|
fields: [
|
|
54
|
-
f("title", "text", { required: true }),
|
|
54
|
+
f("title", "text", { required: true, localized: true }),
|
|
55
55
|
f("slug", "text", { required: true, unique: true, index: true }),
|
|
56
|
-
f("description", "richText"),
|
|
56
|
+
f("description", "richText", { localized: true }),
|
|
57
57
|
f("categories", "relationship", { relationTo: "categories", hasMany: true }),
|
|
58
58
|
f("images", "relationship", { relationTo: "media", hasMany: true }),
|
|
59
59
|
f("seo", "group", {
|
|
60
|
-
fields: [
|
|
60
|
+
fields: [
|
|
61
|
+
f("title", "text", { localized: true }),
|
|
62
|
+
f("description", "textarea", { localized: true }),
|
|
63
|
+
f("image", "relationship", { relationTo: "media" })
|
|
64
|
+
]
|
|
61
65
|
})
|
|
62
66
|
]
|
|
63
67
|
};
|
|
@@ -121,14 +125,27 @@ var SLUG_BY_COLLECTION = {
|
|
|
121
125
|
};
|
|
122
126
|
function createBlueprint() {
|
|
123
127
|
const additions = /* @__PURE__ */ new Map();
|
|
128
|
+
const extras = [];
|
|
124
129
|
const extend = (collection, patch) => {
|
|
125
130
|
const slug = SLUG_BY_COLLECTION[collection];
|
|
126
131
|
const list = additions.get(slug) ?? [];
|
|
127
132
|
list.push(...patch.addFields);
|
|
128
133
|
additions.set(slug, list);
|
|
129
134
|
};
|
|
135
|
+
function addCollection(config) {
|
|
136
|
+
const taken = /* @__PURE__ */ new Set([
|
|
137
|
+
...baseCollections.map((c) => c.slug),
|
|
138
|
+
...extras.map((c) => c.slug)
|
|
139
|
+
]);
|
|
140
|
+
if (taken.has(config.slug)) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`[vitrine] blueprint: collection "${config.slug}" already exists \u2014 addCollection() is additive only`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
extras.push(config);
|
|
146
|
+
}
|
|
130
147
|
function build() {
|
|
131
|
-
|
|
148
|
+
const extended = baseCollections.map((base) => {
|
|
132
149
|
const adds = additions.get(base.slug) ?? [];
|
|
133
150
|
if (adds.length === 0) return base;
|
|
134
151
|
const existing = new Set(base.fields.map((field) => field.name));
|
|
@@ -142,8 +159,9 @@ function createBlueprint() {
|
|
|
142
159
|
}
|
|
143
160
|
return { ...base, fields: [...base.fields, ...adds] };
|
|
144
161
|
});
|
|
162
|
+
return [...extended, ...extras];
|
|
145
163
|
}
|
|
146
|
-
return { extend, build };
|
|
164
|
+
return { extend, addCollection, build };
|
|
147
165
|
}
|
|
148
166
|
export {
|
|
149
167
|
PAYLOAD_BLUEPRINT_VERSION,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitrine-kit/payload-blueprint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Vitrine — base Payload collections + additive extend().",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"directory": "packages/payload-blueprint"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@vitrine-kit/contracts": "1.
|
|
32
|
+
"@vitrine-kit/contracts": "1.3.0"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "node scripts/generate-version.mjs && tsup src/index.ts --format esm --dts --clean",
|