@next-buildr/payload 0.0.0-stage → 2.0.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/LICENSE +21 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/adapter/adapter.test.d.ts +2 -0
- package/dist/adapter/adapter.test.d.ts.map +1 -0
- package/dist/adapter/adapter.test.js +282 -0
- package/dist/adapter/canvas-data-source.d.ts +9 -0
- package/dist/adapter/canvas-data-source.d.ts.map +1 -0
- package/dist/adapter/canvas-data-source.js +24 -0
- package/dist/adapter/document-adapter.d.ts +20 -0
- package/dist/adapter/document-adapter.d.ts.map +1 -0
- package/dist/adapter/document-adapter.js +183 -0
- package/dist/adapter/http.d.ts +34 -0
- package/dist/adapter/http.d.ts.map +1 -0
- package/dist/adapter/http.js +72 -0
- package/dist/adapter/index.d.ts +4 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/adapter/index.js +5 -0
- package/dist/admin/index.d.ts +4 -0
- package/dist/admin/index.d.ts.map +1 -0
- package/dist/admin/index.js +2 -0
- package/dist/admin/layout-field-connected.d.ts +6 -0
- package/dist/admin/layout-field-connected.d.ts.map +1 -0
- package/dist/admin/layout-field-connected.js +16 -0
- package/dist/admin/layout-field-view.d.ts +16 -0
- package/dist/admin/layout-field-view.d.ts.map +1 -0
- package/dist/admin/layout-field-view.js +14 -0
- package/dist/admin/layout-field.d.ts +6 -0
- package/dist/admin/layout-field.d.ts.map +1 -0
- package/dist/admin/layout-field.js +13 -0
- package/dist/admin/layout-field.test.d.ts +2 -0
- package/dist/admin/layout-field.test.d.ts.map +1 -0
- package/dist/admin/layout-field.test.js +41 -0
- package/dist/contract.d.ts +289 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +176 -0
- package/dist/data/build-context.d.ts +20 -0
- package/dist/data/build-context.d.ts.map +1 -0
- package/dist/data/build-context.js +25 -0
- package/dist/data/data.test.d.ts +2 -0
- package/dist/data/data.test.d.ts.map +1 -0
- package/dist/data/data.test.js +261 -0
- package/dist/data/index.d.ts +10 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/index.js +5 -0
- package/dist/data/normalize.d.ts +14 -0
- package/dist/data/normalize.d.ts.map +1 -0
- package/dist/data/normalize.js +128 -0
- package/dist/data/payload-data-source.d.ts +42 -0
- package/dist/data/payload-data-source.d.ts.map +1 -0
- package/dist/data/payload-data-source.js +179 -0
- package/dist/data/payload-data-source.test.d.ts +2 -0
- package/dist/data/payload-data-source.test.d.ts.map +1 -0
- package/dist/data/payload-data-source.test.js +160 -0
- package/dist/data/resolve-layout.d.ts +45 -0
- package/dist/data/resolve-layout.d.ts.map +1 -0
- package/dist/data/resolve-layout.js +111 -0
- package/dist/data/schema-from-fields.d.ts +63 -0
- package/dist/data/schema-from-fields.d.ts.map +1 -0
- package/dist/data/schema-from-fields.js +178 -0
- package/dist/data/where.d.ts +53 -0
- package/dist/data/where.d.ts.map +1 -0
- package/dist/data/where.js +210 -0
- package/dist/mcp/http-backend.d.ts +35 -0
- package/dist/mcp/http-backend.d.ts.map +1 -0
- package/dist/mcp/http-backend.js +337 -0
- package/dist/mcp/http-backend.test.d.ts +2 -0
- package/dist/mcp/http-backend.test.d.ts.map +1 -0
- package/dist/mcp/http-backend.test.js +178 -0
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/route.d.ts +63 -0
- package/dist/mcp/route.d.ts.map +1 -0
- package/dist/mcp/route.js +230 -0
- package/dist/next/get-document.d.ts +64 -0
- package/dist/next/get-document.d.ts.map +1 -0
- package/dist/next/get-document.js +208 -0
- package/dist/next/get-document.test.d.ts +2 -0
- package/dist/next/get-document.test.d.ts.map +1 -0
- package/dist/next/get-document.test.js +155 -0
- package/dist/next/index.d.ts +9 -0
- package/dist/next/index.d.ts.map +1 -0
- package/dist/next/index.js +4 -0
- package/dist/next/next-helpers.test.d.ts +2 -0
- package/dist/next/next-helpers.test.d.ts.map +1 -0
- package/dist/next/next-helpers.test.js +122 -0
- package/dist/next/revalidate.d.ts +44 -0
- package/dist/next/revalidate.d.ts.map +1 -0
- package/dist/next/revalidate.js +45 -0
- package/dist/next/seo.d.ts +43 -0
- package/dist/next/seo.d.ts.map +1 -0
- package/dist/next/seo.js +53 -0
- package/dist/next/tags.d.ts +23 -0
- package/dist/next/tags.d.ts.map +1 -0
- package/dist/next/tags.js +31 -0
- package/dist/plugin/access.d.ts +19 -0
- package/dist/plugin/access.d.ts.map +1 -0
- package/dist/plugin/access.js +32 -0
- package/dist/plugin/collections/form-submissions.d.ts +10 -0
- package/dist/plugin/collections/form-submissions.d.ts.map +1 -0
- package/dist/plugin/collections/form-submissions.js +37 -0
- package/dist/plugin/collections/templates.d.ts +13 -0
- package/dist/plugin/collections/templates.d.ts.map +1 -0
- package/dist/plugin/collections/templates.js +118 -0
- package/dist/plugin/endpoints/access.test.d.ts +2 -0
- package/dist/plugin/endpoints/access.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/access.test.js +91 -0
- package/dist/plugin/endpoints/adapter-contract.test.d.ts +2 -0
- package/dist/plugin/endpoints/adapter-contract.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/adapter-contract.test.js +45 -0
- package/dist/plugin/endpoints/context.d.ts +65 -0
- package/dist/plugin/endpoints/context.d.ts.map +1 -0
- package/dist/plugin/endpoints/context.js +113 -0
- package/dist/plugin/endpoints/data-context.d.ts +8 -0
- package/dist/plugin/endpoints/data-context.d.ts.map +1 -0
- package/dist/plugin/endpoints/data-context.js +63 -0
- package/dist/plugin/endpoints/data-endpoints.test.d.ts +2 -0
- package/dist/plugin/endpoints/data-endpoints.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/data-endpoints.test.js +125 -0
- package/dist/plugin/endpoints/data-query.test.d.ts +2 -0
- package/dist/plugin/endpoints/data-query.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/data-query.test.js +96 -0
- package/dist/plugin/endpoints/data-schema.d.ts +5 -0
- package/dist/plugin/endpoints/data-schema.d.ts.map +1 -0
- package/dist/plugin/endpoints/data-schema.js +21 -0
- package/dist/plugin/endpoints/data.d.ts +10 -0
- package/dist/plugin/endpoints/data.d.ts.map +1 -0
- package/dist/plugin/endpoints/data.js +96 -0
- package/dist/plugin/endpoints/document.d.ts +11 -0
- package/dist/plugin/endpoints/document.d.ts.map +1 -0
- package/dist/plugin/endpoints/document.js +119 -0
- package/dist/plugin/endpoints/documents.d.ts +10 -0
- package/dist/plugin/endpoints/documents.d.ts.map +1 -0
- package/dist/plugin/endpoints/documents.js +145 -0
- package/dist/plugin/endpoints/endpoints.test-kit.d.ts +42 -0
- package/dist/plugin/endpoints/endpoints.test-kit.d.ts.map +1 -0
- package/dist/plugin/endpoints/endpoints.test-kit.js +141 -0
- package/dist/plugin/endpoints/endpoints.test.d.ts +2 -0
- package/dist/plugin/endpoints/endpoints.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/endpoints.test.js +209 -0
- package/dist/plugin/endpoints/forms.d.ts +16 -0
- package/dist/plugin/endpoints/forms.d.ts.map +1 -0
- package/dist/plugin/endpoints/forms.js +199 -0
- package/dist/plugin/endpoints/forms.test.d.ts +2 -0
- package/dist/plugin/endpoints/forms.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/forms.test.js +346 -0
- package/dist/plugin/endpoints/guards.d.ts +9 -0
- package/dist/plugin/endpoints/guards.d.ts.map +1 -0
- package/dist/plugin/endpoints/guards.js +35 -0
- package/dist/plugin/endpoints/index.d.ts +6 -0
- package/dist/plugin/endpoints/index.d.ts.map +1 -0
- package/dist/plugin/endpoints/index.js +32 -0
- package/dist/plugin/endpoints/locales-no-fallback.test.d.ts +2 -0
- package/dist/plugin/endpoints/locales-no-fallback.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/locales-no-fallback.test.js +30 -0
- package/dist/plugin/endpoints/locales.test.d.ts +2 -0
- package/dist/plugin/endpoints/locales.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/locales.test.js +128 -0
- package/dist/plugin/endpoints/manifest.d.ts +5 -0
- package/dist/plugin/endpoints/manifest.d.ts.map +1 -0
- package/dist/plugin/endpoints/manifest.js +18 -0
- package/dist/plugin/endpoints/mcp-http-backend.test.d.ts +2 -0
- package/dist/plugin/endpoints/mcp-http-backend.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/mcp-http-backend.test.js +84 -0
- package/dist/plugin/endpoints/mcp-off.test.d.ts +2 -0
- package/dist/plugin/endpoints/mcp-off.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/mcp-off.test.js +33 -0
- package/dist/plugin/endpoints/mcp-publish.test.d.ts +2 -0
- package/dist/plugin/endpoints/mcp-publish.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/mcp-publish.test.js +42 -0
- package/dist/plugin/endpoints/mcp-route.test.d.ts +2 -0
- package/dist/plugin/endpoints/mcp-route.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/mcp-route.test.js +132 -0
- package/dist/plugin/endpoints/mcp.test.d.ts +2 -0
- package/dist/plugin/endpoints/mcp.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/mcp.test.js +231 -0
- package/dist/plugin/endpoints/media.d.ts +7 -0
- package/dist/plugin/endpoints/media.d.ts.map +1 -0
- package/dist/plugin/endpoints/media.js +115 -0
- package/dist/plugin/endpoints/media.test.d.ts +2 -0
- package/dist/plugin/endpoints/media.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/media.test.js +95 -0
- package/dist/plugin/endpoints/publish-a11y.test.d.ts +2 -0
- package/dist/plugin/endpoints/publish-a11y.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/publish-a11y.test.js +27 -0
- package/dist/plugin/endpoints/publish.d.ts +9 -0
- package/dist/plugin/endpoints/publish.d.ts.map +1 -0
- package/dist/plugin/endpoints/publish.js +81 -0
- package/dist/plugin/endpoints/rename.d.ts +9 -0
- package/dist/plugin/endpoints/rename.d.ts.map +1 -0
- package/dist/plugin/endpoints/rename.js +47 -0
- package/dist/plugin/endpoints/respond.d.ts +9 -0
- package/dist/plugin/endpoints/respond.d.ts.map +1 -0
- package/dist/plugin/endpoints/respond.js +10 -0
- package/dist/plugin/endpoints/samples.d.ts +5 -0
- package/dist/plugin/endpoints/samples.d.ts.map +1 -0
- package/dist/plugin/endpoints/samples.js +42 -0
- package/dist/plugin/endpoints/save.d.ts +9 -0
- package/dist/plugin/endpoints/save.d.ts.map +1 -0
- package/dist/plugin/endpoints/save.js +58 -0
- package/dist/plugin/endpoints/session.d.ts +5 -0
- package/dist/plugin/endpoints/session.d.ts.map +1 -0
- package/dist/plugin/endpoints/session.js +30 -0
- package/dist/plugin/endpoints/templates.test.d.ts +2 -0
- package/dist/plugin/endpoints/templates.test.d.ts.map +1 -0
- package/dist/plugin/endpoints/templates.test.js +191 -0
- package/dist/plugin/fields.d.ts +28 -0
- package/dist/plugin/fields.d.ts.map +1 -0
- package/dist/plugin/fields.js +62 -0
- package/dist/plugin/forms/forms.test.d.ts +2 -0
- package/dist/plugin/forms/forms.test.d.ts.map +1 -0
- package/dist/plugin/forms/forms.test.js +88 -0
- package/dist/plugin/forms/notify.d.ts +6 -0
- package/dist/plugin/forms/notify.d.ts.map +1 -0
- package/dist/plugin/forms/notify.js +13 -0
- package/dist/plugin/forms/rate-limit.d.ts +24 -0
- package/dist/plugin/forms/rate-limit.d.ts.map +1 -0
- package/dist/plugin/forms/rate-limit.js +36 -0
- package/dist/plugin/forms/validate.d.ts +22 -0
- package/dist/plugin/forms/validate.d.ts.map +1 -0
- package/dist/plugin/forms/validate.js +79 -0
- package/dist/plugin/hooks/layout-hook.d.ts +9 -0
- package/dist/plugin/hooks/layout-hook.d.ts.map +1 -0
- package/dist/plugin/hooks/layout-hook.js +33 -0
- package/dist/plugin/hooks/layout-hook.test.d.ts +2 -0
- package/dist/plugin/hooks/layout-hook.test.d.ts.map +1 -0
- package/dist/plugin/hooks/layout-hook.test.js +191 -0
- package/dist/plugin/hooks/process-layout.d.ts +32 -0
- package/dist/plugin/hooks/process-layout.d.ts.map +1 -0
- package/dist/plugin/hooks/process-layout.js +68 -0
- package/dist/plugin/hooks/read-layout.d.ts +17 -0
- package/dist/plugin/hooks/read-layout.d.ts.map +1 -0
- package/dist/plugin/hooks/read-layout.js +39 -0
- package/dist/plugin/index.d.ts +18 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +105 -0
- package/dist/plugin/locales.d.ts +32 -0
- package/dist/plugin/locales.d.ts.map +1 -0
- package/dist/plugin/locales.js +56 -0
- package/dist/plugin/options.d.ts +77 -0
- package/dist/plugin/options.d.ts.map +1 -0
- package/dist/plugin/options.js +123 -0
- package/dist/plugin/plugin.test.d.ts +2 -0
- package/dist/plugin/plugin.test.d.ts.map +1 -0
- package/dist/plugin/plugin.test.js +186 -0
- package/dist/plugin/write-guard.d.ts +14 -0
- package/dist/plugin/write-guard.d.ts.map +1 -0
- package/dist/plugin/write-guard.js +18 -0
- package/package.json +107 -3
- package/README.md +0 -3
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @next-buildr/payload/adapter: createPayloadAdapter, createPayloadCanvasDataSource - the
|
|
2
|
+
// browser-side fetch client. Must never import the `payload` framework itself.
|
|
3
|
+
export { createPayloadCanvasDataSource } from './canvas-data-source.js';
|
|
4
|
+
export { createPayloadAdapter } from './document-adapter.js';
|
|
5
|
+
export { AdapterError } from './http.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The field wired to Payload form and document state; loaded on demand (see `LayoutField`). */
|
|
2
|
+
export declare function ConnectedLayoutField(props: {
|
|
3
|
+
readonly path: string;
|
|
4
|
+
readonly editorRoute?: string;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
//# sourceMappingURL=layout-field-connected.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout-field-connected.d.ts","sourceRoot":"","sources":["../../src/admin/layout-field-connected.tsx"],"names":[],"mappings":"AAUA,gGAAgG;AAChG,wBAAgB,oBAAoB,CAAC,KAAK,EAAE;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B,+BAWA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useDocumentInfo, useField } from '@payloadcms/ui';
|
|
4
|
+
import { LayoutFieldView } from './layout-field-view.js';
|
|
5
|
+
const countNodes = (value) => {
|
|
6
|
+
if (typeof value !== 'object' || value === null)
|
|
7
|
+
return undefined;
|
|
8
|
+
const nodes = value.nodes;
|
|
9
|
+
return typeof nodes === 'object' && nodes !== null ? Object.keys(nodes).length : undefined;
|
|
10
|
+
};
|
|
11
|
+
/** The field wired to Payload form and document state; loaded on demand (see `LayoutField`). */
|
|
12
|
+
export function ConnectedLayoutField(props) {
|
|
13
|
+
const { value } = useField({ path: props.path });
|
|
14
|
+
const info = useDocumentInfo();
|
|
15
|
+
return (_jsx(LayoutFieldView, { nodeCount: countNodes(value), id: info.id, collection: info.collectionSlug ?? '', editorRoute: props.editorRoute ?? '/buildr/edit' }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface LayoutFieldViewProps {
|
|
2
|
+
/** Nodes in the stored document; `undefined` when nothing was built yet. */
|
|
3
|
+
readonly nodeCount: number | undefined;
|
|
4
|
+
/** `undefined` for a document that is not saved yet. */
|
|
5
|
+
readonly id: string | number | undefined;
|
|
6
|
+
readonly collection: string;
|
|
7
|
+
readonly editorRoute: string;
|
|
8
|
+
/** Opens a window; injected so the button can be tested without a browser. */
|
|
9
|
+
readonly open?: (url: string, name: string) => void;
|
|
10
|
+
}
|
|
11
|
+
/** The window name is per document, so a second click reuses the tab that is already open. */
|
|
12
|
+
export declare const editorWindowName: (collection: string, id: string | number) => string;
|
|
13
|
+
export declare const editorUrl: (editorRoute: string, collection: string, id: string | number) => string;
|
|
14
|
+
/** A summary of the layout and the button that opens the builder (docs/payload.md). */
|
|
15
|
+
export declare function LayoutFieldView(props: LayoutFieldViewProps): import("react").JSX.Element;
|
|
16
|
+
//# sourceMappingURL=layout-field-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout-field-view.d.ts","sourceRoot":"","sources":["../../src/admin/layout-field-view.tsx"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,wDAAwD;IACxD,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACrD;AAED,8FAA8F;AAC9F,eAAO,MAAM,gBAAgB,eAAgB,MAAM,MAAM,MAAM,GAAG,MAAM,WAC1C,CAAC;AAE/B,eAAO,MAAM,SAAS,gBAAiB,MAAM,cAAc,MAAM,MAAM,MAAM,GAAG,MAAM,WACmB,CAAC;AAE1G,uFAAuF;AACvF,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,+BAwB1D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** The window name is per document, so a second click reuses the tab that is already open. */
|
|
3
|
+
export const editorWindowName = (collection, id) => `buildr-${collection}-${id}`;
|
|
4
|
+
export const editorUrl = (editorRoute, collection, id) => `${editorRoute.replace(/\/$/, '')}/${encodeURIComponent(collection)}/${encodeURIComponent(String(id))}`;
|
|
5
|
+
/** A summary of the layout and the button that opens the builder (docs/payload.md). */
|
|
6
|
+
export function LayoutFieldView(props) {
|
|
7
|
+
const { id, collection, nodeCount } = props;
|
|
8
|
+
const open = props.open ?? ((url, name) => void window.open(url, name));
|
|
9
|
+
const saved = id !== undefined && id !== '';
|
|
10
|
+
return (_jsxs("div", { className: "field-type buildr-layout-field", children: [_jsx("span", { className: "field-label", children: "Layout" }), _jsx("p", { "data-testid": "buildr-layout-summary", children: nodeCount === undefined ? 'Nothing built yet.' : `${nodeCount} elements.` }), _jsx("button", { type: "button", className: "btn btn--style-primary btn--size-medium", disabled: !saved, title: saved ? undefined : 'Save the document first', onClick: () => {
|
|
11
|
+
if (saved)
|
|
12
|
+
open(editorUrl(props.editorRoute, collection, id), editorWindowName(collection, id));
|
|
13
|
+
}, children: "Edit with Visual Builder" })] }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The `layout` field of a collection with the plugin installed (referenced from the import map). */
|
|
2
|
+
export declare function LayoutField(props: {
|
|
3
|
+
readonly path: string;
|
|
4
|
+
readonly editorRoute?: string;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
//# sourceMappingURL=layout-field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout-field.d.ts","sourceRoot":"","sources":["../../src/admin/layout-field.tsx"],"names":[],"mappings":"AAUA,qGAAqG;AACrG,wBAAgB,WAAW,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,+BAM1F"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { lazy, Suspense } from 'react';
|
|
4
|
+
// Payload UI pulls in stylesheets, which a plain Node import (the Payload CLI, the entry-point
|
|
5
|
+
// smoke test) cannot load; the bundler splits it out and only the admin ever renders it.
|
|
6
|
+
const Connected = lazy(async () => {
|
|
7
|
+
const mod = await import('./layout-field-connected.js');
|
|
8
|
+
return { default: mod.ConnectedLayoutField };
|
|
9
|
+
});
|
|
10
|
+
/** The `layout` field of a collection with the plugin installed (referenced from the import map). */
|
|
11
|
+
export function LayoutField(props) {
|
|
12
|
+
return (_jsx(Suspense, { fallback: null, children: _jsx(Connected, { ...props }) }));
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout-field.test.d.ts","sourceRoot":"","sources":["../../src/admin/layout-field.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// @vitest-environment jsdom
|
|
3
|
+
import { act } from 'react';
|
|
4
|
+
import { createRoot } from 'react-dom/client';
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import { editorUrl, editorWindowName, LayoutFieldView } from './layout-field-view.js';
|
|
7
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
8
|
+
describe('LayoutFieldView', () => {
|
|
9
|
+
let container;
|
|
10
|
+
let root;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
container = document.createElement('div');
|
|
13
|
+
document.body.append(container);
|
|
14
|
+
root = createRoot(container);
|
|
15
|
+
});
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
act(() => root.unmount());
|
|
18
|
+
container.remove();
|
|
19
|
+
});
|
|
20
|
+
const mount = (props, open = vi.fn()) => {
|
|
21
|
+
act(() => root.render(_jsx(LayoutFieldView, { nodeCount: 12, id: "42", collection: "pages", editorRoute: "/buildr/edit", open: open, ...props })));
|
|
22
|
+
return { open, button: container.querySelector('button') };
|
|
23
|
+
};
|
|
24
|
+
it('opens the editor of the document in a named window', () => {
|
|
25
|
+
const { open, button } = mount({});
|
|
26
|
+
expect(container.textContent).toContain('12 elements.');
|
|
27
|
+
act(() => button.click());
|
|
28
|
+
expect(open).toHaveBeenCalledWith('/buildr/edit/pages/42', 'buildr-pages-42');
|
|
29
|
+
});
|
|
30
|
+
it('is inactive for a document that is not saved yet', () => {
|
|
31
|
+
const { open, button } = mount({ id: undefined, nodeCount: undefined });
|
|
32
|
+
expect(button.disabled).toBe(true);
|
|
33
|
+
act(() => button.click());
|
|
34
|
+
expect(open).not.toHaveBeenCalled();
|
|
35
|
+
expect(container.textContent).toContain('Nothing built yet.');
|
|
36
|
+
});
|
|
37
|
+
it('builds the URL and window name safely', () => {
|
|
38
|
+
expect(editorUrl('/buildr/edit/', 'a b', 7)).toBe('/buildr/edit/a%20b/7');
|
|
39
|
+
expect(editorWindowName('pages', 7)).toBe('buildr-pages-7');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The builder API contract (docs/payload.md#endpoint-contract): the request and response shapes of
|
|
4
|
+
* `/api/buildr/*`, defined once and shared by the endpoint implementations and the HTTP adapter.
|
|
5
|
+
* Documents travel as `unknown`; they are validated by `processLayout` on the server and by
|
|
6
|
+
* `parseDocument` in the adapter, not by these schemas.
|
|
7
|
+
*/
|
|
8
|
+
export declare const diagnosticSchema: z.ZodObject<{
|
|
9
|
+
code: z.ZodString;
|
|
10
|
+
message: z.ZodString;
|
|
11
|
+
severity: z.ZodEnum<{
|
|
12
|
+
error: "error";
|
|
13
|
+
warning: "warning";
|
|
14
|
+
}>;
|
|
15
|
+
path: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
16
|
+
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
export type ContractDiagnostic = z.infer<typeof diagnosticSchema>;
|
|
19
|
+
export declare const documentRefSchema: z.ZodObject<{
|
|
20
|
+
collection: z.ZodString;
|
|
21
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
export declare const sessionResponseSchema: z.ZodObject<{
|
|
24
|
+
user: z.ZodObject<{
|
|
25
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
26
|
+
email: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
permissions: z.ZodObject<{
|
|
29
|
+
canEdit: z.ZodBoolean;
|
|
30
|
+
canPublish: z.ZodBoolean;
|
|
31
|
+
canUnlockTemplates: z.ZodBoolean;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
limits: z.ZodObject<{
|
|
34
|
+
maxNodes: z.ZodNumber;
|
|
35
|
+
maxBytes: z.ZodNumber;
|
|
36
|
+
}, z.core.$strip>;
|
|
37
|
+
publishPolicy: z.ZodOptional<z.ZodEnum<{
|
|
38
|
+
block: "block";
|
|
39
|
+
warn: "warn";
|
|
40
|
+
}>>;
|
|
41
|
+
locales: z.ZodOptional<z.ZodObject<{
|
|
42
|
+
locales: z.ZodArray<z.ZodString>;
|
|
43
|
+
default: z.ZodString;
|
|
44
|
+
fallback: z.ZodBoolean;
|
|
45
|
+
intl: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
46
|
+
}, z.core.$strip>>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
export type SessionResponse = z.infer<typeof sessionResponseSchema>;
|
|
49
|
+
export declare const documentQuerySchema: z.ZodObject<{
|
|
50
|
+
draft: z.ZodOptional<z.ZodEnum<{
|
|
51
|
+
0: "0";
|
|
52
|
+
1: "1";
|
|
53
|
+
}>>;
|
|
54
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
export declare const documentResponseSchema: z.ZodObject<{
|
|
57
|
+
ref: z.ZodObject<{
|
|
58
|
+
collection: z.ZodString;
|
|
59
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
60
|
+
}, z.core.$strip>;
|
|
61
|
+
title: z.ZodString;
|
|
62
|
+
slug: z.ZodNullable<z.ZodString>;
|
|
63
|
+
status: z.ZodEnum<{
|
|
64
|
+
draft: "draft";
|
|
65
|
+
published: "published";
|
|
66
|
+
}>;
|
|
67
|
+
updatedAt: z.ZodString;
|
|
68
|
+
revision: z.ZodNumber;
|
|
69
|
+
document: z.ZodUnknown;
|
|
70
|
+
contextRef: z.ZodString;
|
|
71
|
+
layoutSource: z.ZodEnum<{
|
|
72
|
+
builtin: "builtin";
|
|
73
|
+
"default-template": "default-template";
|
|
74
|
+
document: "document";
|
|
75
|
+
template: "template";
|
|
76
|
+
}>;
|
|
77
|
+
layoutRef: z.ZodNullable<z.ZodString>;
|
|
78
|
+
previewPath: z.ZodNullable<z.ZodString>;
|
|
79
|
+
readOnly: z.ZodOptional<z.ZodBoolean>;
|
|
80
|
+
}, z.core.$strip>;
|
|
81
|
+
export type DocumentResponse = z.infer<typeof documentResponseSchema>;
|
|
82
|
+
/** `GET /api/buildr/documents/:collection/:id/revision`: the revision without the document. */
|
|
83
|
+
export declare const revisionResponseSchema: z.ZodObject<{
|
|
84
|
+
revision: z.ZodNumber;
|
|
85
|
+
updatedAt: z.ZodString;
|
|
86
|
+
updatedBy: z.ZodOptional<z.ZodString>;
|
|
87
|
+
}, z.core.$strip>;
|
|
88
|
+
export type RevisionResponse = z.infer<typeof revisionResponseSchema>;
|
|
89
|
+
export declare const saveRequestSchema: z.ZodObject<{
|
|
90
|
+
document: z.ZodUnknown;
|
|
91
|
+
baseRevision: z.ZodNumber;
|
|
92
|
+
autosave: z.ZodBoolean;
|
|
93
|
+
}, z.core.$strip>;
|
|
94
|
+
export type SaveRequest = z.infer<typeof saveRequestSchema>;
|
|
95
|
+
export declare const saveResponseSchema: z.ZodObject<{
|
|
96
|
+
revision: z.ZodNumber;
|
|
97
|
+
updatedAt: z.ZodString;
|
|
98
|
+
}, z.core.$strip>;
|
|
99
|
+
export type SaveResponse = z.infer<typeof saveResponseSchema>;
|
|
100
|
+
/** `PATCH /buildr/documents/:collection/:id`: renames the document; the layout is not touched. */
|
|
101
|
+
export declare const renameRequestSchema: z.ZodObject<{
|
|
102
|
+
title: z.ZodString;
|
|
103
|
+
}, z.core.$strip>;
|
|
104
|
+
export type RenameRequest = z.infer<typeof renameRequestSchema>;
|
|
105
|
+
export declare const renameResponseSchema: z.ZodObject<{
|
|
106
|
+
title: z.ZodString;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
export type RenameResponse = z.infer<typeof renameResponseSchema>;
|
|
109
|
+
export declare const publishRequestSchema: z.ZodObject<{
|
|
110
|
+
baseRevision: z.ZodNumber;
|
|
111
|
+
}, z.core.$strip>;
|
|
112
|
+
export type PublishRequest = z.infer<typeof publishRequestSchema>;
|
|
113
|
+
export declare const publishResponseSchema: z.ZodObject<{
|
|
114
|
+
status: z.ZodLiteral<"published">;
|
|
115
|
+
publishedAt: z.ZodString;
|
|
116
|
+
revision: z.ZodNumber;
|
|
117
|
+
updatedAt: z.ZodString;
|
|
118
|
+
}, z.core.$strip>;
|
|
119
|
+
export type PublishResponse = z.infer<typeof publishResponseSchema>;
|
|
120
|
+
/** `409`: somebody saved in the meantime. */
|
|
121
|
+
export declare const conflictResponseSchema: z.ZodObject<{
|
|
122
|
+
currentRevision: z.ZodNumber;
|
|
123
|
+
}, z.core.$strip>;
|
|
124
|
+
export type ConflictResponse = z.infer<typeof conflictResponseSchema>;
|
|
125
|
+
/** `422`: the document is not acceptable; `diagnostics` say why. */
|
|
126
|
+
export declare const invalidResponseSchema: z.ZodObject<{
|
|
127
|
+
diagnostics: z.ZodArray<z.ZodObject<{
|
|
128
|
+
code: z.ZodString;
|
|
129
|
+
message: z.ZodString;
|
|
130
|
+
severity: z.ZodEnum<{
|
|
131
|
+
error: "error";
|
|
132
|
+
warning: "warning";
|
|
133
|
+
}>;
|
|
134
|
+
path: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
135
|
+
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
136
|
+
}, z.core.$strip>>;
|
|
137
|
+
}, z.core.$strip>;
|
|
138
|
+
export type InvalidResponse = z.infer<typeof invalidResponseSchema>;
|
|
139
|
+
/** Every other refusal (`400`, `401`, `403`, `404`). */
|
|
140
|
+
export declare const errorResponseSchema: z.ZodObject<{
|
|
141
|
+
error: z.ZodString;
|
|
142
|
+
}, z.core.$strip>;
|
|
143
|
+
export type ErrorResponse = z.infer<typeof errorResponseSchema>;
|
|
144
|
+
/** The base path of the builder API under Payload's `routes.api`. */
|
|
145
|
+
export declare const BUILDR_API_PATH = "/buildr";
|
|
146
|
+
/** `GET /buildr/data-schema/:collection` answers with core's `DataSchema`. */
|
|
147
|
+
export declare const dataSchemaResponseSchema: z.ZodType<import("@next-buildr/core").DataSchema, unknown, z.core.$ZodTypeInternals<import("@next-buildr/core").DataSchema, unknown>>;
|
|
148
|
+
export declare const dataContextQuerySchema: z.ZodObject<{
|
|
149
|
+
collection: z.ZodString;
|
|
150
|
+
id: z.ZodString;
|
|
151
|
+
draft: z.ZodOptional<z.ZodEnum<{
|
|
152
|
+
0: "0";
|
|
153
|
+
1: "1";
|
|
154
|
+
}>>;
|
|
155
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
156
|
+
}, z.core.$strip>;
|
|
157
|
+
/** The scopes a canvas binds against: `{ site, [context]: doc, route }`. */
|
|
158
|
+
export declare const dataContextResponseSchema: z.ZodObject<{
|
|
159
|
+
scopes: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
160
|
+
}, z.core.$strip>;
|
|
161
|
+
export type DataContextResponse = z.infer<typeof dataContextResponseSchema>;
|
|
162
|
+
export declare const samplesResponseSchema: z.ZodObject<{
|
|
163
|
+
items: z.ZodArray<z.ZodObject<{
|
|
164
|
+
id: z.ZodString;
|
|
165
|
+
title: z.ZodString;
|
|
166
|
+
}, z.core.$strip>>;
|
|
167
|
+
}, z.core.$strip>;
|
|
168
|
+
export type SamplesResponse = z.infer<typeof samplesResponseSchema>;
|
|
169
|
+
/** `POST /buildr/data/query`: one resolved query, answered with the access of the editing user. */
|
|
170
|
+
export declare const dataQueryRequestSchema: z.ZodObject<{
|
|
171
|
+
spec: z.ZodType<import("@next-buildr/core").ResolvedQuerySpec, unknown, z.core.$ZodTypeInternals<import("@next-buildr/core").ResolvedQuerySpec, unknown>>;
|
|
172
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
173
|
+
}, z.core.$strip>;
|
|
174
|
+
export type DataQueryRequest = z.infer<typeof dataQueryRequestSchema>;
|
|
175
|
+
export declare const dataQueryResponseSchema: z.ZodType<import("@next-buildr/core").QueryResult, unknown, z.core.$ZodTypeInternals<import("@next-buildr/core").QueryResult, unknown>>;
|
|
176
|
+
/** `POST /buildr/data/media`: media assets by id; unknown ids are left out. */
|
|
177
|
+
export declare const dataMediaRequestSchema: z.ZodObject<{
|
|
178
|
+
ids: z.ZodArray<z.ZodString>;
|
|
179
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
180
|
+
}, z.core.$strip>;
|
|
181
|
+
export type DataMediaRequest = z.infer<typeof dataMediaRequestSchema>;
|
|
182
|
+
export declare const dataMediaResponseSchema: z.ZodRecord<z.ZodString, z.ZodType<import("@next-buildr/core").MediaAsset, unknown, z.core.$ZodTypeInternals<import("@next-buildr/core").MediaAsset, unknown>>>;
|
|
183
|
+
/** `GET /buildr/media?search&type&page`: the picker's listing. */
|
|
184
|
+
export declare const mediaListQuerySchema: z.ZodObject<{
|
|
185
|
+
search: z.ZodOptional<z.ZodString>;
|
|
186
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
187
|
+
audio: "audio";
|
|
188
|
+
image: "image";
|
|
189
|
+
video: "video";
|
|
190
|
+
}>>;
|
|
191
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
192
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
193
|
+
}, z.core.$strip>;
|
|
194
|
+
export declare const mediaListResponseSchema: z.ZodObject<{
|
|
195
|
+
items: z.ZodArray<z.ZodType<import("@next-buildr/core").MediaAsset, unknown, z.core.$ZodTypeInternals<import("@next-buildr/core").MediaAsset, unknown>>>;
|
|
196
|
+
page: z.ZodNumber;
|
|
197
|
+
totalPages: z.ZodNumber;
|
|
198
|
+
}, z.core.$strip>;
|
|
199
|
+
export type MediaListResponse = z.infer<typeof mediaListResponseSchema>;
|
|
200
|
+
/** How many documents a page of `GET /buildr/documents` holds. */
|
|
201
|
+
export declare const DOCUMENT_LIST_PAGE_SIZE = 20;
|
|
202
|
+
/** `GET /buildr/documents?collection&search&page`: the builder documents the user may read. */
|
|
203
|
+
export declare const documentListQuerySchema: z.ZodObject<{
|
|
204
|
+
collection: z.ZodString;
|
|
205
|
+
search: z.ZodOptional<z.ZodString>;
|
|
206
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
207
|
+
}, z.core.$strip>;
|
|
208
|
+
export type DocumentListQuery = z.infer<typeof documentListQuerySchema>;
|
|
209
|
+
/** One document in a listing (and the answer of a creation): enough to pick it and open it. */
|
|
210
|
+
export declare const documentSummarySchema: z.ZodObject<{
|
|
211
|
+
ref: z.ZodObject<{
|
|
212
|
+
collection: z.ZodString;
|
|
213
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
214
|
+
}, z.core.$strip>;
|
|
215
|
+
title: z.ZodString;
|
|
216
|
+
slug: z.ZodNullable<z.ZodString>;
|
|
217
|
+
status: z.ZodEnum<{
|
|
218
|
+
draft: "draft";
|
|
219
|
+
published: "published";
|
|
220
|
+
}>;
|
|
221
|
+
updatedAt: z.ZodString;
|
|
222
|
+
revision: z.ZodNumber;
|
|
223
|
+
layoutSource: z.ZodEnum<{
|
|
224
|
+
builtin: "builtin";
|
|
225
|
+
"default-template": "default-template";
|
|
226
|
+
document: "document";
|
|
227
|
+
template: "template";
|
|
228
|
+
}>;
|
|
229
|
+
previewPath: z.ZodNullable<z.ZodString>;
|
|
230
|
+
}, z.core.$strip>;
|
|
231
|
+
export type DocumentSummary = z.infer<typeof documentSummarySchema>;
|
|
232
|
+
export declare const documentListResponseSchema: z.ZodObject<{
|
|
233
|
+
items: z.ZodArray<z.ZodObject<{
|
|
234
|
+
ref: z.ZodObject<{
|
|
235
|
+
collection: z.ZodString;
|
|
236
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
237
|
+
}, z.core.$strip>;
|
|
238
|
+
title: z.ZodString;
|
|
239
|
+
slug: z.ZodNullable<z.ZodString>;
|
|
240
|
+
status: z.ZodEnum<{
|
|
241
|
+
draft: "draft";
|
|
242
|
+
published: "published";
|
|
243
|
+
}>;
|
|
244
|
+
updatedAt: z.ZodString;
|
|
245
|
+
revision: z.ZodNumber;
|
|
246
|
+
layoutSource: z.ZodEnum<{
|
|
247
|
+
builtin: "builtin";
|
|
248
|
+
"default-template": "default-template";
|
|
249
|
+
document: "document";
|
|
250
|
+
template: "template";
|
|
251
|
+
}>;
|
|
252
|
+
previewPath: z.ZodNullable<z.ZodString>;
|
|
253
|
+
}, z.core.$strip>>;
|
|
254
|
+
page: z.ZodNumber;
|
|
255
|
+
totalPages: z.ZodNumber;
|
|
256
|
+
}, z.core.$strip>;
|
|
257
|
+
export type DocumentListResponse = z.infer<typeof documentListResponseSchema>;
|
|
258
|
+
/** `POST /buildr/documents`: creates a draft (never published) in a builder collection. */
|
|
259
|
+
export declare const createDocumentRequestSchema: z.ZodObject<{
|
|
260
|
+
collection: z.ZodString;
|
|
261
|
+
title: z.ZodString;
|
|
262
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
263
|
+
template: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
264
|
+
}, z.core.$strip>;
|
|
265
|
+
export type CreateDocumentRequest = z.infer<typeof createDocumentRequestSchema>;
|
|
266
|
+
/** `201`: the new draft. */
|
|
267
|
+
export declare const createDocumentResponseSchema: z.ZodObject<{
|
|
268
|
+
ref: z.ZodObject<{
|
|
269
|
+
collection: z.ZodString;
|
|
270
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
271
|
+
}, z.core.$strip>;
|
|
272
|
+
title: z.ZodString;
|
|
273
|
+
slug: z.ZodNullable<z.ZodString>;
|
|
274
|
+
status: z.ZodEnum<{
|
|
275
|
+
draft: "draft";
|
|
276
|
+
published: "published";
|
|
277
|
+
}>;
|
|
278
|
+
updatedAt: z.ZodString;
|
|
279
|
+
revision: z.ZodNumber;
|
|
280
|
+
layoutSource: z.ZodEnum<{
|
|
281
|
+
builtin: "builtin";
|
|
282
|
+
"default-template": "default-template";
|
|
283
|
+
document: "document";
|
|
284
|
+
template: "template";
|
|
285
|
+
}>;
|
|
286
|
+
previewPath: z.ZodNullable<z.ZodString>;
|
|
287
|
+
}, z.core.$strip>;
|
|
288
|
+
export type CreateDocumentResponse = DocumentSummary;
|
|
289
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"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"}
|
package/dist/contract.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { dataSchemaSchema, mediaAssetSchema, queryResultSchema, resolvedQuerySpecSchema, } from '@next-buildr/core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* The builder API contract (docs/payload.md#endpoint-contract): the request and response shapes of
|
|
5
|
+
* `/api/buildr/*`, defined once and shared by the endpoint implementations and the HTTP adapter.
|
|
6
|
+
* Documents travel as `unknown`; they are validated by `processLayout` on the server and by
|
|
7
|
+
* `parseDocument` in the adapter, not by these schemas.
|
|
8
|
+
*/
|
|
9
|
+
export const diagnosticSchema = z.object({
|
|
10
|
+
code: z.string(),
|
|
11
|
+
message: z.string(),
|
|
12
|
+
severity: z.enum(['error', 'warning']),
|
|
13
|
+
path: z.array(z.union([z.string(), z.number()])).optional(),
|
|
14
|
+
details: z.record(z.string(), z.unknown()).optional(),
|
|
15
|
+
});
|
|
16
|
+
export const documentRefSchema = z.object({
|
|
17
|
+
collection: z.string(),
|
|
18
|
+
id: z.union([z.string(), z.number()]),
|
|
19
|
+
});
|
|
20
|
+
export const sessionResponseSchema = z.object({
|
|
21
|
+
user: z.object({ id: z.union([z.string(), z.number()]), email: z.string().optional() }),
|
|
22
|
+
permissions: z.object({
|
|
23
|
+
canEdit: z.boolean(),
|
|
24
|
+
canPublish: z.boolean(),
|
|
25
|
+
canUnlockTemplates: z.boolean(),
|
|
26
|
+
}),
|
|
27
|
+
limits: z.object({ maxNodes: z.number(), maxBytes: z.number() }),
|
|
28
|
+
/** `a11y.publish`: with `block`, a document with accessibility errors cannot be published. */
|
|
29
|
+
publishPolicy: z.enum(['warn', 'block']).optional(),
|
|
30
|
+
/** The languages of the site; absent without Payload localization. */
|
|
31
|
+
locales: z
|
|
32
|
+
.object({
|
|
33
|
+
locales: z.array(z.string()),
|
|
34
|
+
default: z.string(),
|
|
35
|
+
fallback: z.boolean(),
|
|
36
|
+
intl: z.record(z.string(), z.string()),
|
|
37
|
+
})
|
|
38
|
+
.optional(),
|
|
39
|
+
});
|
|
40
|
+
export const documentQuerySchema = z.object({
|
|
41
|
+
draft: z.enum(['0', '1']).optional(),
|
|
42
|
+
locale: z.string().optional(),
|
|
43
|
+
});
|
|
44
|
+
export const documentResponseSchema = z.object({
|
|
45
|
+
ref: documentRefSchema,
|
|
46
|
+
title: z.string(),
|
|
47
|
+
slug: z.string().nullable(),
|
|
48
|
+
status: z.enum(['draft', 'published']),
|
|
49
|
+
updatedAt: z.string(),
|
|
50
|
+
/** Changes with every builder save; the next save says which one it builds on. */
|
|
51
|
+
revision: z.number().int().nonnegative(),
|
|
52
|
+
document: z.unknown(),
|
|
53
|
+
/** What the canvas gets as its data context: `{collection}:{id}`. */
|
|
54
|
+
contextRef: z.string(),
|
|
55
|
+
/**
|
|
56
|
+
* Where `document` came from: the document's own layout, its template, the collection's default
|
|
57
|
+
* template, or nothing yet (`builtin`: the canvas is blank and the site shows the built-in layout).
|
|
58
|
+
*/
|
|
59
|
+
layoutSource: z.enum(['document', 'template', 'default-template', 'builtin']),
|
|
60
|
+
/** `{collection}:{id}` of the document that holds the layout; `null` for `builtin`. */
|
|
61
|
+
layoutRef: z.string().nullable(),
|
|
62
|
+
/** The public path of the document, when the collection defines one. */
|
|
63
|
+
previewPath: z.string().nullable(),
|
|
64
|
+
readOnly: z.boolean().optional(),
|
|
65
|
+
});
|
|
66
|
+
/** `GET /api/buildr/documents/:collection/:id/revision`: the revision without the document. */
|
|
67
|
+
export const revisionResponseSchema = z.object({
|
|
68
|
+
revision: z.number().int().nonnegative(),
|
|
69
|
+
updatedAt: z.string(),
|
|
70
|
+
/** Who made the last builder write (a name or an email); only with `mcp.enabled`. */
|
|
71
|
+
updatedBy: z.string().optional(),
|
|
72
|
+
});
|
|
73
|
+
export const saveRequestSchema = z.object({
|
|
74
|
+
document: z.unknown(),
|
|
75
|
+
baseRevision: z.number().int().nonnegative(),
|
|
76
|
+
autosave: z.boolean(),
|
|
77
|
+
});
|
|
78
|
+
export const saveResponseSchema = z.object({
|
|
79
|
+
revision: z.number().int().nonnegative(),
|
|
80
|
+
updatedAt: z.string(),
|
|
81
|
+
});
|
|
82
|
+
/** `PATCH /buildr/documents/:collection/:id`: renames the document; the layout is not touched. */
|
|
83
|
+
export const renameRequestSchema = z.object({ title: z.string().trim().min(1).max(200) });
|
|
84
|
+
export const renameResponseSchema = z.object({ title: z.string() });
|
|
85
|
+
export const publishRequestSchema = z.object({ baseRevision: z.number().int().nonnegative() });
|
|
86
|
+
export const publishResponseSchema = z.object({
|
|
87
|
+
status: z.literal('published'),
|
|
88
|
+
publishedAt: z.string(),
|
|
89
|
+
revision: z.number().int().nonnegative(),
|
|
90
|
+
updatedAt: z.string(),
|
|
91
|
+
});
|
|
92
|
+
/** `409`: somebody saved in the meantime. */
|
|
93
|
+
export const conflictResponseSchema = z.object({ currentRevision: z.number().int().nonnegative() });
|
|
94
|
+
/** `422`: the document is not acceptable; `diagnostics` say why. */
|
|
95
|
+
export const invalidResponseSchema = z.object({ diagnostics: z.array(diagnosticSchema) });
|
|
96
|
+
/** Every other refusal (`400`, `401`, `403`, `404`). */
|
|
97
|
+
export const errorResponseSchema = z.object({ error: z.string() });
|
|
98
|
+
/** The base path of the builder API under Payload's `routes.api`. */
|
|
99
|
+
export const BUILDR_API_PATH = '/buildr';
|
|
100
|
+
/** `GET /buildr/data-schema/:collection` answers with core's `DataSchema`. */
|
|
101
|
+
export const dataSchemaResponseSchema = dataSchemaSchema;
|
|
102
|
+
export const dataContextQuerySchema = z.object({
|
|
103
|
+
collection: z.string().min(1),
|
|
104
|
+
id: z.string().min(1),
|
|
105
|
+
draft: z.enum(['0', '1']).optional(),
|
|
106
|
+
locale: z.string().optional(),
|
|
107
|
+
});
|
|
108
|
+
/** The scopes a canvas binds against: `{ site, [context]: doc, route }`. */
|
|
109
|
+
export const dataContextResponseSchema = z.object({ scopes: z.record(z.string(), z.unknown()) });
|
|
110
|
+
export const samplesResponseSchema = z.object({
|
|
111
|
+
items: z.array(z.object({ id: z.string(), title: z.string() })),
|
|
112
|
+
});
|
|
113
|
+
/** `POST /buildr/data/query`: one resolved query, answered with the access of the editing user. */
|
|
114
|
+
export const dataQueryRequestSchema = z.object({
|
|
115
|
+
spec: resolvedQuerySpecSchema,
|
|
116
|
+
locale: z.string().optional(),
|
|
117
|
+
});
|
|
118
|
+
export const dataQueryResponseSchema = queryResultSchema;
|
|
119
|
+
/** `POST /buildr/data/media`: media assets by id; unknown ids are left out. */
|
|
120
|
+
export const dataMediaRequestSchema = z.object({
|
|
121
|
+
ids: z.array(z.string().min(1)).max(100),
|
|
122
|
+
locale: z.string().optional(),
|
|
123
|
+
});
|
|
124
|
+
export const dataMediaResponseSchema = z.record(z.string(), mediaAssetSchema);
|
|
125
|
+
/** `GET /buildr/media?search&type&page`: the picker's listing. */
|
|
126
|
+
export const mediaListQuerySchema = z.object({
|
|
127
|
+
search: z.string().max(200).optional(),
|
|
128
|
+
type: z.enum(['image', 'video', 'audio']).optional(),
|
|
129
|
+
page: z.coerce.number().int().min(1).default(1),
|
|
130
|
+
locale: z.string().max(35).optional(),
|
|
131
|
+
});
|
|
132
|
+
export const mediaListResponseSchema = z.object({
|
|
133
|
+
items: z.array(mediaAssetSchema),
|
|
134
|
+
page: z.number().int(),
|
|
135
|
+
totalPages: z.number().int(),
|
|
136
|
+
});
|
|
137
|
+
/** How many documents a page of `GET /buildr/documents` holds. */
|
|
138
|
+
export const DOCUMENT_LIST_PAGE_SIZE = 20;
|
|
139
|
+
/** `GET /buildr/documents?collection&search&page`: the builder documents the user may read. */
|
|
140
|
+
export const documentListQuerySchema = z.object({
|
|
141
|
+
collection: z.string().min(1),
|
|
142
|
+
search: z.string().max(200).optional(),
|
|
143
|
+
page: z.coerce.number().int().min(1).default(1),
|
|
144
|
+
});
|
|
145
|
+
/** One document in a listing (and the answer of a creation): enough to pick it and open it. */
|
|
146
|
+
export const documentSummarySchema = z.object({
|
|
147
|
+
ref: documentRefSchema,
|
|
148
|
+
title: z.string(),
|
|
149
|
+
slug: z.string().nullable(),
|
|
150
|
+
status: z.enum(['draft', 'published']),
|
|
151
|
+
updatedAt: z.string(),
|
|
152
|
+
/** The `baseRevision` an open + save starts from. */
|
|
153
|
+
revision: z.number().int().nonnegative(),
|
|
154
|
+
layoutSource: z.enum(['document', 'template', 'default-template', 'builtin']),
|
|
155
|
+
previewPath: z.string().nullable(),
|
|
156
|
+
});
|
|
157
|
+
export const documentListResponseSchema = z.object({
|
|
158
|
+
items: z.array(documentSummarySchema),
|
|
159
|
+
page: z.number().int(),
|
|
160
|
+
totalPages: z.number().int(),
|
|
161
|
+
});
|
|
162
|
+
/** `POST /buildr/documents`: creates a draft (never published) in a builder collection. */
|
|
163
|
+
export const createDocumentRequestSchema = z.object({
|
|
164
|
+
collection: z.string().min(1),
|
|
165
|
+
title: z.string().trim().min(1).max(200),
|
|
166
|
+
slug: z
|
|
167
|
+
.string()
|
|
168
|
+
.min(1)
|
|
169
|
+
.max(200)
|
|
170
|
+
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, 'lowercase words separated by hyphens')
|
|
171
|
+
.optional(),
|
|
172
|
+
/** The id of a template of the collection (`buildr-templates`) the document starts from. */
|
|
173
|
+
template: z.union([z.string().min(1), z.number()]).optional(),
|
|
174
|
+
});
|
|
175
|
+
/** `201`: the new draft. */
|
|
176
|
+
export const createDocumentResponseSchema = documentSummarySchema;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SchemaOptions, SchemaSource } from './schema-from-fields.ts';
|
|
2
|
+
export interface BuildContextInput {
|
|
3
|
+
readonly source: SchemaSource;
|
|
4
|
+
readonly options: SchemaOptions;
|
|
5
|
+
readonly collection: string;
|
|
6
|
+
readonly doc: Record<string, unknown>;
|
|
7
|
+
/** The site global's document, when there is one and the user may read it. */
|
|
8
|
+
readonly site?: Record<string, unknown> | undefined;
|
|
9
|
+
readonly route: {
|
|
10
|
+
readonly path: string;
|
|
11
|
+
readonly locale: string;
|
|
12
|
+
readonly page?: number;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The data scopes of a document: `{ site, [context]: doc, route }`, shaped exactly like the schema
|
|
17
|
+
* `schemaFromCollection` derives (same allow-list), ready to be served to the canvas as `scopes`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function buildContext(input: BuildContextInput): Record<string, unknown>;
|
|
20
|
+
//# sourceMappingURL=build-context.d.ts.map
|