@nexload-sdk/payload-schema 2.0.0 → 3.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/CHANGELOG.md +18 -0
- package/README.md +161 -26
- package/dist/core/default-id.d.ts.map +1 -0
- package/dist/{errors.d.ts → core/errors.d.ts} +3 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/{types.d.ts → core/types.d.ts} +50 -31
- package/dist/core/types.d.ts.map +1 -0
- package/dist/entity/define-entity.d.ts +2 -2
- package/dist/entity/define-entity.d.ts.map +1 -1
- package/dist/fields/index.d.ts +42 -17
- package/dist/fields/index.d.ts.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +286 -374
- package/dist/index.js.map +4 -4
- package/dist/internal/blocks-schema.d.ts +9 -0
- package/dist/internal/blocks-schema.d.ts.map +1 -0
- package/dist/internal/canonical-parse.d.ts +11 -0
- package/dist/internal/canonical-parse.d.ts.map +1 -0
- package/dist/internal/chunk-6S4TDSLR.js +157 -0
- package/dist/internal/chunk-6S4TDSLR.js.map +7 -0
- package/dist/internal/chunk-BX5LWYAU.js +157 -0
- package/dist/internal/chunk-BX5LWYAU.js.map +7 -0
- package/dist/internal/clone.d.ts.map +1 -1
- package/dist/internal/composite-child.d.ts +4 -0
- package/dist/internal/composite-child.d.ts.map +1 -0
- package/dist/internal/data-field-types.d.ts +3 -0
- package/dist/internal/data-field-types.d.ts.map +1 -0
- package/dist/internal/entity-binding.d.ts +10 -0
- package/dist/internal/entity-binding.d.ts.map +1 -0
- package/dist/internal/field-definition.d.ts +11 -2
- package/dist/internal/field-definition.d.ts.map +1 -1
- package/dist/payload/canonical-hook.d.ts +5 -0
- package/dist/payload/canonical-hook.d.ts.map +1 -0
- package/dist/payload/compile-field.d.ts +4 -0
- package/dist/payload/compile-field.d.ts.map +1 -0
- package/dist/payload/index.d.ts +3 -0
- package/dist/payload/index.d.ts.map +1 -0
- package/dist/payload/index.js +291 -0
- package/dist/payload/index.js.map +7 -0
- package/dist/payload/payload-fields.d.ts +7 -0
- package/dist/payload/payload-fields.d.ts.map +1 -0
- package/package.json +10 -5
- package/dist/default-id.d.ts.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- /package/dist/{default-id.d.ts → core/default-id.d.ts} +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/core/errors.ts", "../../src/internal/canonical-parse.ts", "../../src/internal/data-field-types.ts", "../../src/internal/entity-binding.ts"],
|
|
4
|
+
"sourcesContent": ["export type SafeIssueSummary = {\n code: string\n path: Array<number | string>\n message: string\n};\n\nexport interface PayloadSchemaErrorDataMap {\n INVALID_ENTITY_NAME: { received: string }\n INVALID_ENTITY: { receivedType: string }\n INVALID_FIELD_NAME: { entity?: string, field: string }\n RESERVED_FIELD_NAME: { entity?: string, field: string, reservedName: string }\n INVALID_FIELD_CONFIGURATION: { entity?: string, fieldPath: string, fieldKind: string, reason: string }\n INVALID_CONSTRAINT_RANGE: {\n entity?: string\n fieldPath: string\n constraint: string\n minimum?: number | string\n maximum?: number | string\n }\n INVALID_DEFAULT_VALUE: { entity?: string, fieldPath: string, fieldKind: string, issues: SafeIssueSummary[] }\n CONFLICTING_DEFAULT_CONFIGURATION: {\n entity?: string\n fieldPath: string\n fieldType: string\n configuredDefaults: readonly [\"defaultValue\", \"dynamicDefaultValue\"]\n }\n EMPTY_SELECT_VALUES: { entity?: string, fieldPath: string }\n INVALID_RELATIONSHIP_CONFIGURATION: {\n entity?: string\n fieldPath: string\n reason: string\n relationTo?: string[]\n }\n INVALID_NESTED_FIELD_CONFIGURATION: {\n entity?: string\n fieldPath: string\n reason: string\n blockingFieldPath?: string\n }\n ASYNC_CANONICAL_SCHEMA_UNSUPPORTED: { entity?: string, fieldPath: string, fieldKind: string }\n RESERVED_PAYLOAD_OPTION: { entity?: string, fieldPath: string, fieldKind: string, option: string }\n DUPLICATE_PAYLOAD_FIELD_NAME: { entity: string, payloadName: string, fieldPaths: string[] }\n INVALID_PAYLOAD_FIELD: { entity: string, fieldPath: string, fieldKind: string, reason: string }\n PAYLOAD_COMPILATION_FAILED: {\n entity: string\n fieldPath?: string\n fieldKind?: string\n operation: \"all\" | \"field\" | \"pick\"\n causeName?: string\n }\n UNKNOWN_FIELD: { entity: string, field: string, availableFields: string[] }\n SCHEMA_UNAVAILABLE: {\n entity: string\n fieldPath: string\n fieldKind: string\n reason: \"native-without-schema\" | \"schema-less-descendant\"\n blockingFieldPath?: string\n }\n INVALID_SCHEMA_FACTORY_RESULT: { entity: string, receivedType: string }\n SCHEMA_DERIVATION_FAILED: { entity: string, causeName?: string }\n INTERNAL_INVARIANT_VIOLATION: { invariant: string, entity?: string, fieldPath?: string }\n}\n\nexport type PayloadSchemaErrorCode = keyof PayloadSchemaErrorDataMap;\n\nexport type PayloadSchemaErrorPhase = \"definition\" | \"internal\" | \"payload-compilation\" | \"schema-derivation\";\n\nexport type SerializedPayloadSchemaError<TCode extends PayloadSchemaErrorCode = PayloadSchemaErrorCode> = {\n name: \"PayloadSchemaError\"\n code: TCode\n phase: PayloadSchemaErrorPhase\n message: string\n data: PayloadSchemaErrorDataMap[TCode]\n};\n\nexport class PayloadSchemaError<TCode extends PayloadSchemaErrorCode> extends Error {\n readonly code: TCode;\n\n readonly phase: PayloadSchemaErrorPhase;\n\n readonly data: PayloadSchemaErrorDataMap[TCode];\n\n override readonly cause?: unknown;\n\n constructor (\n code: TCode, options: {\n phase: PayloadSchemaErrorPhase\n message: string\n data: PayloadSchemaErrorDataMap[TCode]\n cause?: unknown\n }\n ) {\n super(\n options.message, options.cause === undefined ? undefined : { cause: options.cause, }\n );\n this.name = \"PayloadSchemaError\";\n this.code = code;\n this.phase = options.phase;\n this.data = options.data;\n this.cause = options.cause;\n }\n\n toJSON (): SerializedPayloadSchemaError<TCode> {\n return {\n name: \"PayloadSchemaError\",\n code: this.code,\n phase: this.phase,\n message: this.message,\n data: this.data,\n };\n }\n}\n\nexport function isPayloadSchemaError (error: unknown): error is PayloadSchemaError<PayloadSchemaErrorCode>;\nexport function isPayloadSchemaError<TCode extends PayloadSchemaErrorCode> (\n error: unknown,\n code: TCode\n): error is PayloadSchemaError<TCode>;\nexport function isPayloadSchemaError (\n error: unknown,\n code?: PayloadSchemaErrorCode\n): error is PayloadSchemaError<PayloadSchemaErrorCode> {\n return error instanceof PayloadSchemaError && (code === undefined || error.code === code);\n}\n", "import type { z } from \"zod\";\n\nimport type { AnyCanonicalSchema } from \"../core/types.js\";\n\nimport { PayloadSchemaError, type SafeIssueSummary } from \"../core/errors.js\";\n\nexport function errorName (error: unknown): string | undefined {\n return error instanceof Error ? error.name : undefined;\n}\n\nfunction isAsyncParseError (error: unknown): boolean {\n return error instanceof Error\n && (error.constructor.name === \"$ZodAsyncError\" || error.message.includes(\"Encountered Promise during synchronous parse\"));\n}\n\nexport function issueSummaries (error: z.ZodError): SafeIssueSummary[] {\n return error.issues.map((issue) => ({\n code: issue.code,\n path: issue.path.map((part) => (typeof part === \"symbol\" ? part.description ?? part.toString() : part)),\n message: issue.message,\n }));\n}\n\nexport function parseCanonical (\n schema: AnyCanonicalSchema,\n value: unknown,\n context: { entity?: string, fieldPath: string, fieldKind: string }\n): ReturnType<AnyCanonicalSchema[\"safeParse\"]> {\n try {\n return schema.safeParse(value);\n } catch (error) {\n if (isAsyncParseError(error)) {\n throw new PayloadSchemaError(\n \"ASYNC_CANONICAL_SCHEMA_UNSUPPORTED\", {\n phase: \"definition\",\n message: `Canonical schema for field \"${context.fieldPath}\" must be synchronous.`,\n data: context,\n cause: error,\n }\n );\n }\n throw error;\n }\n}\n", "/** Payload field types that affect stored data; the only types an entity may compile to. */\nexport const dataFieldTypes: ReadonlySet<string> = new Set([\n \"array\",\n \"blocks\",\n \"checkbox\",\n \"code\",\n \"date\",\n \"email\",\n \"group\",\n \"join\",\n \"json\",\n \"number\",\n \"point\",\n \"radio\",\n \"relationship\",\n \"richText\",\n \"select\",\n \"text\",\n \"textarea\",\n \"upload\"\n]);\n", "import type { FieldSeed } from \"./field-definition.js\";\n\nimport { PayloadSchemaError } from \"../core/errors.js\";\n\nexport const entityBindingSymbol: unique symbol = Symbol(\"payload-schema.entity-binding\");\n\nexport type EntityBinding = {\n readonly name: string\n readonly entries: ReadonlyArray<readonly [string, FieldSeed]>\n};\n\nexport function attachEntityBinding (\n target: object, binding: EntityBinding\n): void {\n Object.defineProperty(\n target, entityBindingSymbol, {\n configurable: false,\n enumerable: false,\n value: Object.freeze({\n name: binding.name,\n entries: Object.freeze(binding.entries.map(([\n name,\n seed\n ]) => Object.freeze([\n name,\n seed\n ] as const))),\n }),\n writable: false,\n }\n );\n}\n\nfunction receivedTypeOf (value: unknown): string {\n if (value === null) return \"null\";\n if (Array.isArray(value)) return \"array\";\n\n return typeof value;\n}\n\nexport function getEntityBinding (value: unknown): EntityBinding {\n const binding = ((typeof value === \"object\" && value !== null) || typeof value === \"function\")\n && Object.hasOwn(value, entityBindingSymbol)\n ? (value as { [entityBindingSymbol]?: unknown })[entityBindingSymbol]\n : undefined;\n\n if (!binding || typeof binding !== \"object\") {\n throw new PayloadSchemaError(\n \"INVALID_ENTITY\", {\n phase: \"payload-compilation\",\n message: \"Expected an entity created by defineEntity().\",\n data: { receivedType: receivedTypeOf(value), },\n }\n );\n }\n\n return binding as EntityBinding;\n}\n\nexport function findEntityEntry (\n entityName: string,\n entries: ReadonlyArray<readonly [string, FieldSeed]>,\n key: PropertyKey\n): readonly [string, FieldSeed] {\n const entry = entries.find(([name]) => name === key);\n\n if (!entry) {\n throw new PayloadSchemaError(\n \"UNKNOWN_FIELD\", {\n phase: \"schema-derivation\",\n message: `Unknown field \"${String(key)}\" in entity \"${entityName}\".`,\n data: { entity: entityName, field: String(key), availableFields: entries.map(([name]) => name), },\n }\n );\n }\n\n return entry;\n}\n"],
|
|
5
|
+
"mappings": ";;;AA2EO,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AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,SAAS,gBACd,YACA,SACA,KAC8B;AAC9B,QAAM,QAAQ,QAAQ,KAAK,CAAC,CAAC,IAAI,MAAM,SAAS,GAAG;AAEnD,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR;AAAA,MAAiB;AAAA,QACf,OAAO;AAAA,QACP,SAAS,kBAAkB,OAAO,GAAG,CAAC,gBAAgB,UAAU;AAAA,QAChE,MAAM,EAAE,QAAQ,YAAY,OAAO,OAAO,GAAG,GAAG,iBAAiB,QAAQ,IAAI,CAAC,CAAC,IAAI,MAAM,IAAI,EAAG;AAAA,MAClG;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// @nexload-sdk/payload-schema v3.0.0 (build 2026-11-25T11:31:32.762Z)
|
|
2
|
+
|
|
3
|
+
// src/core/errors.ts
|
|
4
|
+
var PayloadSchemaError = class extends Error {
|
|
5
|
+
code;
|
|
6
|
+
phase;
|
|
7
|
+
data;
|
|
8
|
+
cause;
|
|
9
|
+
constructor(code, options) {
|
|
10
|
+
super(
|
|
11
|
+
options.message,
|
|
12
|
+
options.cause === void 0 ? void 0 : { cause: options.cause }
|
|
13
|
+
);
|
|
14
|
+
this.name = "PayloadSchemaError";
|
|
15
|
+
this.code = code;
|
|
16
|
+
this.phase = options.phase;
|
|
17
|
+
this.data = options.data;
|
|
18
|
+
this.cause = options.cause;
|
|
19
|
+
}
|
|
20
|
+
toJSON() {
|
|
21
|
+
return {
|
|
22
|
+
name: "PayloadSchemaError",
|
|
23
|
+
code: this.code,
|
|
24
|
+
phase: this.phase,
|
|
25
|
+
message: this.message,
|
|
26
|
+
data: this.data
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
function isPayloadSchemaError(error, code) {
|
|
31
|
+
return error instanceof PayloadSchemaError && (code === void 0 || error.code === code);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/internal/canonical-parse.ts
|
|
35
|
+
function errorName(error) {
|
|
36
|
+
return error instanceof Error ? error.name : void 0;
|
|
37
|
+
}
|
|
38
|
+
function isAsyncParseError(error) {
|
|
39
|
+
return error instanceof Error && (error.constructor.name === "$ZodAsyncError" || error.message.includes("Encountered Promise during synchronous parse"));
|
|
40
|
+
}
|
|
41
|
+
function issueSummaries(error) {
|
|
42
|
+
return error.issues.map((issue) => ({
|
|
43
|
+
code: issue.code,
|
|
44
|
+
path: issue.path.map((part) => typeof part === "symbol" ? part.description ?? part.toString() : part),
|
|
45
|
+
message: issue.message
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
function parseCanonical(schema, value, context) {
|
|
49
|
+
try {
|
|
50
|
+
return schema.safeParse(value);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (isAsyncParseError(error)) {
|
|
53
|
+
throw new PayloadSchemaError(
|
|
54
|
+
"ASYNC_CANONICAL_SCHEMA_UNSUPPORTED",
|
|
55
|
+
{
|
|
56
|
+
phase: "definition",
|
|
57
|
+
message: `Canonical schema for field "${context.fieldPath}" must be synchronous.`,
|
|
58
|
+
data: context,
|
|
59
|
+
cause: error
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/internal/data-field-types.ts
|
|
68
|
+
var dataFieldTypes = /* @__PURE__ */ new Set([
|
|
69
|
+
"array",
|
|
70
|
+
"blocks",
|
|
71
|
+
"checkbox",
|
|
72
|
+
"code",
|
|
73
|
+
"date",
|
|
74
|
+
"email",
|
|
75
|
+
"group",
|
|
76
|
+
"join",
|
|
77
|
+
"json",
|
|
78
|
+
"number",
|
|
79
|
+
"point",
|
|
80
|
+
"radio",
|
|
81
|
+
"relationship",
|
|
82
|
+
"richText",
|
|
83
|
+
"select",
|
|
84
|
+
"text",
|
|
85
|
+
"textarea",
|
|
86
|
+
"upload"
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
// src/internal/entity-binding.ts
|
|
90
|
+
var entityBindingSymbol = /* @__PURE__ */ Symbol("payload-schema.entity-binding");
|
|
91
|
+
function attachEntityBinding(target, binding) {
|
|
92
|
+
Object.defineProperty(
|
|
93
|
+
target,
|
|
94
|
+
entityBindingSymbol,
|
|
95
|
+
{
|
|
96
|
+
configurable: false,
|
|
97
|
+
enumerable: false,
|
|
98
|
+
value: Object.freeze({
|
|
99
|
+
name: binding.name,
|
|
100
|
+
entries: Object.freeze(binding.entries.map(([
|
|
101
|
+
name,
|
|
102
|
+
seed
|
|
103
|
+
]) => Object.freeze([
|
|
104
|
+
name,
|
|
105
|
+
seed
|
|
106
|
+
])))
|
|
107
|
+
}),
|
|
108
|
+
writable: false
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
function receivedTypeOf(value) {
|
|
113
|
+
if (value === null) return "null";
|
|
114
|
+
if (Array.isArray(value)) return "array";
|
|
115
|
+
return typeof value;
|
|
116
|
+
}
|
|
117
|
+
function getEntityBinding(value) {
|
|
118
|
+
const binding = (typeof value === "object" && value !== null || typeof value === "function") && Object.hasOwn(value, entityBindingSymbol) ? value[entityBindingSymbol] : void 0;
|
|
119
|
+
if (!binding || typeof binding !== "object") {
|
|
120
|
+
throw new PayloadSchemaError(
|
|
121
|
+
"INVALID_ENTITY",
|
|
122
|
+
{
|
|
123
|
+
phase: "payload-compilation",
|
|
124
|
+
message: "Expected an entity created by defineEntity().",
|
|
125
|
+
data: { receivedType: receivedTypeOf(value) }
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return binding;
|
|
130
|
+
}
|
|
131
|
+
function findEntityEntry(entityName, entries, key) {
|
|
132
|
+
const entry = entries.find(([name]) => name === key);
|
|
133
|
+
if (!entry) {
|
|
134
|
+
throw new PayloadSchemaError(
|
|
135
|
+
"UNKNOWN_FIELD",
|
|
136
|
+
{
|
|
137
|
+
phase: "schema-derivation",
|
|
138
|
+
message: `Unknown field "${String(key)}" in entity "${entityName}".`,
|
|
139
|
+
data: { entity: entityName, field: String(key), availableFields: entries.map(([name]) => name) }
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return entry;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export {
|
|
147
|
+
PayloadSchemaError,
|
|
148
|
+
isPayloadSchemaError,
|
|
149
|
+
errorName,
|
|
150
|
+
issueSummaries,
|
|
151
|
+
parseCanonical,
|
|
152
|
+
dataFieldTypes,
|
|
153
|
+
attachEntityBinding,
|
|
154
|
+
getEntityBinding,
|
|
155
|
+
findEntityEntry
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=chunk-BX5LWYAU.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/core/errors.ts", "../../src/internal/canonical-parse.ts", "../../src/internal/data-field-types.ts", "../../src/internal/entity-binding.ts"],
|
|
4
|
+
"sourcesContent": ["export type SafeIssueSummary = {\n code: string\n path: Array<number | string>\n message: string\n};\n\nexport interface PayloadSchemaErrorDataMap {\n INVALID_ENTITY_NAME: { received: string }\n INVALID_ENTITY: { receivedType: string }\n INVALID_FIELD_NAME: { entity?: string, field: string }\n RESERVED_FIELD_NAME: { entity?: string, field: string, reservedName: string }\n INVALID_FIELD_CONFIGURATION: { entity?: string, fieldPath: string, fieldKind: string, reason: string }\n INVALID_CONSTRAINT_RANGE: {\n entity?: string\n fieldPath: string\n constraint: string\n minimum?: number | string\n maximum?: number | string\n }\n INVALID_DEFAULT_VALUE: { entity?: string, fieldPath: string, fieldKind: string, issues: SafeIssueSummary[] }\n CONFLICTING_DEFAULT_CONFIGURATION: {\n entity?: string\n fieldPath: string\n fieldType: string\n configuredDefaults: readonly [\"defaultValue\", \"dynamicDefaultValue\"]\n }\n EMPTY_SELECT_VALUES: { entity?: string, fieldPath: string }\n INVALID_RELATIONSHIP_CONFIGURATION: {\n entity?: string\n fieldPath: string\n reason: string\n relationTo?: string[]\n }\n INVALID_NESTED_FIELD_CONFIGURATION: {\n entity?: string\n fieldPath: string\n reason: string\n blockingFieldPath?: string\n }\n ASYNC_CANONICAL_SCHEMA_UNSUPPORTED: { entity?: string, fieldPath: string, fieldKind: string }\n RESERVED_PAYLOAD_OPTION: { entity?: string, fieldPath: string, fieldKind: string, option: string }\n DUPLICATE_PAYLOAD_FIELD_NAME: { entity: string, payloadName: string, fieldPaths: string[] }\n INVALID_PAYLOAD_FIELD: { entity: string, fieldPath: string, fieldKind: string, reason: string }\n PAYLOAD_COMPILATION_FAILED: {\n entity: string\n fieldPath?: string\n fieldKind?: string\n operation: \"all\" | \"field\" | \"pick\"\n causeName?: string\n }\n UNKNOWN_FIELD: { entity: string, field: string, availableFields: string[] }\n SCHEMA_UNAVAILABLE: {\n entity: string\n fieldPath: string\n fieldKind: string\n reason: \"native-without-schema\" | \"schema-less-descendant\"\n blockingFieldPath?: string\n }\n INVALID_SCHEMA_FACTORY_RESULT: { entity: string, receivedType: string }\n SCHEMA_DERIVATION_FAILED: { entity: string, causeName?: string }\n INTERNAL_INVARIANT_VIOLATION: { invariant: string, entity?: string, fieldPath?: string }\n}\n\nexport type PayloadSchemaErrorCode = keyof PayloadSchemaErrorDataMap;\n\nexport type PayloadSchemaErrorPhase = \"definition\" | \"internal\" | \"payload-compilation\" | \"schema-derivation\";\n\nexport type SerializedPayloadSchemaError<TCode extends PayloadSchemaErrorCode = PayloadSchemaErrorCode> = {\n name: \"PayloadSchemaError\"\n code: TCode\n phase: PayloadSchemaErrorPhase\n message: string\n data: PayloadSchemaErrorDataMap[TCode]\n};\n\nexport class PayloadSchemaError<TCode extends PayloadSchemaErrorCode> extends Error {\n readonly code: TCode;\n\n readonly phase: PayloadSchemaErrorPhase;\n\n readonly data: PayloadSchemaErrorDataMap[TCode];\n\n override readonly cause?: unknown;\n\n constructor (\n code: TCode, options: {\n phase: PayloadSchemaErrorPhase\n message: string\n data: PayloadSchemaErrorDataMap[TCode]\n cause?: unknown\n }\n ) {\n super(\n options.message, options.cause === undefined ? undefined : { cause: options.cause, }\n );\n this.name = \"PayloadSchemaError\";\n this.code = code;\n this.phase = options.phase;\n this.data = options.data;\n this.cause = options.cause;\n }\n\n toJSON (): SerializedPayloadSchemaError<TCode> {\n return {\n name: \"PayloadSchemaError\",\n code: this.code,\n phase: this.phase,\n message: this.message,\n data: this.data,\n };\n }\n}\n\nexport function isPayloadSchemaError (error: unknown): error is PayloadSchemaError<PayloadSchemaErrorCode>;\nexport function isPayloadSchemaError<TCode extends PayloadSchemaErrorCode> (\n error: unknown,\n code: TCode\n): error is PayloadSchemaError<TCode>;\nexport function isPayloadSchemaError (\n error: unknown,\n code?: PayloadSchemaErrorCode\n): error is PayloadSchemaError<PayloadSchemaErrorCode> {\n return error instanceof PayloadSchemaError && (code === undefined || error.code === code);\n}\n", "import type { z } from \"zod\";\n\nimport type { AnyCanonicalSchema } from \"../core/types.js\";\n\nimport { PayloadSchemaError, type SafeIssueSummary } from \"../core/errors.js\";\n\nexport function errorName (error: unknown): string | undefined {\n return error instanceof Error ? error.name : undefined;\n}\n\nfunction isAsyncParseError (error: unknown): boolean {\n return error instanceof Error\n && (error.constructor.name === \"$ZodAsyncError\" || error.message.includes(\"Encountered Promise during synchronous parse\"));\n}\n\nexport function issueSummaries (error: z.ZodError): SafeIssueSummary[] {\n return error.issues.map((issue) => ({\n code: issue.code,\n path: issue.path.map((part) => (typeof part === \"symbol\" ? part.description ?? part.toString() : part)),\n message: issue.message,\n }));\n}\n\nexport function parseCanonical (\n schema: AnyCanonicalSchema,\n value: unknown,\n context: { entity?: string, fieldPath: string, fieldKind: string }\n): ReturnType<AnyCanonicalSchema[\"safeParse\"]> {\n try {\n return schema.safeParse(value);\n } catch (error) {\n if (isAsyncParseError(error)) {\n throw new PayloadSchemaError(\n \"ASYNC_CANONICAL_SCHEMA_UNSUPPORTED\", {\n phase: \"definition\",\n message: `Canonical schema for field \"${context.fieldPath}\" must be synchronous.`,\n data: context,\n cause: error,\n }\n );\n }\n throw error;\n }\n}\n", "/** Payload field types that affect stored data; the only types an entity may compile to. */\nexport const dataFieldTypes: ReadonlySet<string> = new Set([\n \"array\",\n \"blocks\",\n \"checkbox\",\n \"code\",\n \"date\",\n \"email\",\n \"group\",\n \"join\",\n \"json\",\n \"number\",\n \"point\",\n \"radio\",\n \"relationship\",\n \"richText\",\n \"select\",\n \"text\",\n \"textarea\",\n \"upload\"\n]);\n", "import type { FieldSeed } from \"./field-definition.js\";\n\nimport { PayloadSchemaError } from \"../core/errors.js\";\n\nexport const entityBindingSymbol: unique symbol = Symbol(\"payload-schema.entity-binding\");\n\nexport type EntityBinding = {\n readonly name: string\n readonly entries: ReadonlyArray<readonly [string, FieldSeed]>\n};\n\nexport function attachEntityBinding (\n target: object, binding: EntityBinding\n): void {\n Object.defineProperty(\n target, entityBindingSymbol, {\n configurable: false,\n enumerable: false,\n value: Object.freeze({\n name: binding.name,\n entries: Object.freeze(binding.entries.map(([\n name,\n seed\n ]) => Object.freeze([\n name,\n seed\n ] as const))),\n }),\n writable: false,\n }\n );\n}\n\nfunction receivedTypeOf (value: unknown): string {\n if (value === null) return \"null\";\n if (Array.isArray(value)) return \"array\";\n\n return typeof value;\n}\n\nexport function getEntityBinding (value: unknown): EntityBinding {\n const binding = ((typeof value === \"object\" && value !== null) || typeof value === \"function\")\n && Object.hasOwn(value, entityBindingSymbol)\n ? (value as { [entityBindingSymbol]?: unknown })[entityBindingSymbol]\n : undefined;\n\n if (!binding || typeof binding !== \"object\") {\n throw new PayloadSchemaError(\n \"INVALID_ENTITY\", {\n phase: \"payload-compilation\",\n message: \"Expected an entity created by defineEntity().\",\n data: { receivedType: receivedTypeOf(value), },\n }\n );\n }\n\n return binding as EntityBinding;\n}\n\nexport function findEntityEntry (\n entityName: string,\n entries: ReadonlyArray<readonly [string, FieldSeed]>,\n key: PropertyKey\n): readonly [string, FieldSeed] {\n const entry = entries.find(([name]) => name === key);\n\n if (!entry) {\n throw new PayloadSchemaError(\n \"UNKNOWN_FIELD\", {\n phase: \"schema-derivation\",\n message: `Unknown field \"${String(key)}\" in entity \"${entityName}\".`,\n data: { entity: entityName, field: String(key), availableFields: entries.map(([name]) => name), },\n }\n );\n }\n\n return entry;\n}\n"],
|
|
5
|
+
"mappings": ";;;AA2EO,IAAM,qBAAN,cAAuE,MAAM;AAAA,EACzE;AAAA,EAEA;AAAA,EAEA;AAAA,EAES;AAAA,EAElB,YACE,MAAa,SAMb;AACA;AAAA,MACE,QAAQ;AAAA,MAAS,QAAQ,UAAU,SAAY,SAAY,EAAE,OAAO,QAAQ,MAAO;AAAA,IACrF;AACA,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,QAAQ,QAAQ;AACrB,SAAK,OAAO,QAAQ;AACpB,SAAK,QAAQ,QAAQ;AAAA,EACvB;AAAA,EAEA,SAA+C;AAC7C,WAAO;AAAA,MACL,MAAM;AAAA,MACN,MAAM,KAAK;AAAA,MACX,OAAO,KAAK;AAAA,MACZ,SAAS,KAAK;AAAA,MACd,MAAM,KAAK;AAAA,IACb;AAAA,EACF;AACF;AAOO,SAAS,qBACd,OACA,MACqD;AACrD,SAAO,iBAAiB,uBAAuB,SAAS,UAAa,MAAM,SAAS;AACtF;;;ACrHO,SAAS,UAAW,OAAoC;AAC7D,SAAO,iBAAiB,QAAQ,MAAM,OAAO;AAC/C;AAEA,SAAS,kBAAmB,OAAyB;AACnD,SAAO,iBAAiB,UAClB,MAAM,YAAY,SAAS,oBAAoB,MAAM,QAAQ,SAAS,8CAA8C;AAC5H;AAEO,SAAS,eAAgB,OAAuC;AACrE,SAAO,MAAM,OAAO,IAAI,CAAC,WAAW;AAAA,IAClC,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM,KAAK,IAAI,CAAC,SAAU,OAAO,SAAS,W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AAkB,OAA+B;AAC/D,QAAM,WAAY,OAAO,UAAU,YAAY,UAAU,QAAS,OAAO,UAAU,eAC9E,OAAO,OAAO,OAAO,mBAAmB,IACxC,MAA8C,mBAAmB,IAClE;AAEJ,MAAI,CAAC,WAAW,OAAO,YAAY,UAAU;AAC3C,UAAM,IAAI;AAAA,MACR;AAAA,MAAkB;AAAA,QAChB,OAAO;AAAA,QACP,SAAS;AAAA,QACT,MAAM,EAAE,cAAc,eAAe,KAAK,EAAG;AAAA,MAC/C;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAEO,SAAS,gBACd,YACA,SACA,KAC8B;AAC9B,QAAM,QAAQ,QAAQ,KAAK,CAAC,CAAC,IAAI,MAAM,SAAS,GAAG;AAEnD,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR;AAAA,MAAiB;AAAA,QACf,OAAO;AAAA,QACP,SAAS,kBAAkB,OAAO,GAAG,CAAC,gBAAgB,UAAU;AAAA,QAChE,MAAM,EAAE,QAAQ,YAAY,OAAO,OAAO,GAAG,GAAG,iBAAiB,QAAQ,IAAI,CAAC,CAAC,IAAI,MAAM,IAAI,EAAG;AAAA,MAClG;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clone.d.ts","sourceRoot":"","sources":["../../src/internal/clone.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clone.d.ts","sourceRoot":"","sources":["../../src/internal/clone.ts"],"names":[],"mappings":"AAMA,wBAAgB,WAAW,CAAC,MAAM,EAAG,KAAK,EAAE,MAAM,GAAG,MAAM,CAmB1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composite-child.d.ts","sourceRoot":"","sources":["../../src/internal/composite-child.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,wBAAgB,oBAAoB,CAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CAiBzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-field-types.d.ts","sourceRoot":"","sources":["../../src/internal/data-field-types.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,MAAM,CAmB7C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FieldSeed } from "./field-definition.js";
|
|
2
|
+
export declare const entityBindingSymbol: unique symbol;
|
|
3
|
+
export type EntityBinding = {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly entries: ReadonlyArray<readonly [string, FieldSeed]>;
|
|
6
|
+
};
|
|
7
|
+
export declare function attachEntityBinding(target: object, binding: EntityBinding): void;
|
|
8
|
+
export declare function getEntityBinding(value: unknown): EntityBinding;
|
|
9
|
+
export declare function findEntityEntry(entityName: string, entries: ReadonlyArray<readonly [string, FieldSeed]>, key: PropertyKey): readonly [string, FieldSeed];
|
|
10
|
+
//# sourceMappingURL=entity-binding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-binding.d.ts","sourceRoot":"","sources":["../../src/internal/entity-binding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAIvD,eAAO,MAAM,mBAAmB,EAAE,OAAO,MAAgD,CAAC;AAE1F,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAA;CAC9D,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GACrC,IAAI,CAkBN;AASD,wBAAgB,gBAAgB,CAAE,KAAK,EAAE,OAAO,GAAG,aAAa,CAiB/D;AAED,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,EACpD,GAAG,EAAE,WAAW,GACf,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAc9B"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import type { AnyCanonicalSchema, AnyFieldDefinition, EntityFieldMap, FieldDefinition, PayloadDataField } from "../types.js";
|
|
2
1
|
import type { z } from "zod";
|
|
2
|
+
import type { AnyCanonicalSchema, AnyFieldDefinition, EntityFieldMap, FieldDefinition, PayloadDataField } from "../core/types.js";
|
|
3
3
|
export declare const fieldSeedSymbol: unique symbol;
|
|
4
|
+
export type BlockSeed = {
|
|
5
|
+
slug: string;
|
|
6
|
+
payloadExtras: Record<string, unknown>;
|
|
7
|
+
children: ReadonlyArray<readonly [string, FieldSeed]>;
|
|
8
|
+
blockingFieldPath?: string;
|
|
9
|
+
};
|
|
4
10
|
export type FieldSeed = {
|
|
5
11
|
kind: string;
|
|
6
12
|
payloadType: string;
|
|
@@ -14,6 +20,9 @@ export type FieldSeed = {
|
|
|
14
20
|
hasMany?: boolean;
|
|
15
21
|
currency?: string;
|
|
16
22
|
children?: ReadonlyArray<readonly [string, FieldSeed]>;
|
|
23
|
+
blocks?: ReadonlyArray<BlockSeed>;
|
|
24
|
+
minRows?: number;
|
|
25
|
+
maxRows?: number;
|
|
17
26
|
blockingFieldPath?: string;
|
|
18
27
|
relation?: {
|
|
19
28
|
relationTo: string | readonly string[];
|
|
@@ -26,7 +35,7 @@ export type FieldSeed = {
|
|
|
26
35
|
dynamicDefaultConfigured?: boolean;
|
|
27
36
|
dynamicDefault?: unknown;
|
|
28
37
|
};
|
|
29
|
-
export declare function createFieldDefinition<TKind extends string, TSchema extends AnyCanonicalSchema | undefined, TPayloadField extends PayloadDataField>(seed: FieldSeed): FieldDefinition<TKind, TSchema, TPayloadField>;
|
|
38
|
+
export declare function createFieldDefinition<TKind extends string, TSchema extends AnyCanonicalSchema | undefined, TPayloadField extends PayloadDataField, TRequired extends boolean = boolean>(seed: FieldSeed): FieldDefinition<TKind, TSchema, TPayloadField, TRequired>;
|
|
30
39
|
export declare function getFieldSeed(field: AnyFieldDefinition): FieldSeed;
|
|
31
40
|
export declare function fieldEntries(fields: EntityFieldMap): ReadonlyArray<readonly [string, FieldSeed]>;
|
|
32
41
|
export type CanonicalShape<TFields extends EntityFieldMap> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-definition.d.ts","sourceRoot":"","sources":["../../src/internal/field-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAAE,kBAAkB,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAC1F,MAAM,
|
|
1
|
+
{"version":3,"file":"field-definition.d.ts","sourceRoot":"","sources":["../../src/internal/field-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EACV,kBAAkB,EAAE,kBAAkB,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAC1F,MAAM,kBAAkB,CAAC;AAE1B,eAAO,MAAM,eAAe,EAAE,OAAO,MAA4C,CAAC;AAElF,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACtC,QAAQ,EAAE,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAA;IACrD,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CA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AAE,SAAS,CAAC,CAO7E;AAED,wBAAgB,YAAY,CAAE,KAAK,EAAE,kBAAkB,GAAG,SAAS,CAMlE;AAED,wBAAgB,YAAY,CAAE,MAAM,EAAE,cAAc,GAAG,aAAa,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAQjG;AAED,MAAM,MAAM,cAAc,CAAC,OAAO,SAAS,cAAc,IAAI;KAC1D,IAAI,IAAI,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;CACrE,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { FieldHook } from "payload";
|
|
2
|
+
import type { FieldSeed } from "../internal/field-definition.js";
|
|
3
|
+
export declare function canonicalHook(seed: FieldSeed, entity: string, fieldPath: string): FieldHook;
|
|
4
|
+
export declare function appendCanonicalHook(value: unknown, hook: FieldHook): Record<string, unknown>;
|
|
5
|
+
//# sourceMappingURL=canonical-hook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-hook.d.ts","sourceRoot":"","sources":["../../src/payload/canonical-hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAcjE,wBAAgB,aAAa,CAC3B,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GACjD,SAAS,CAmBX;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,GAC9B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA2CzB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PayloadDataField } from "../core/types.js";
|
|
2
|
+
import type { FieldSeed } from "../internal/field-definition.js";
|
|
3
|
+
export declare function compileField(seed: FieldSeed, name: string, entity: string, fieldPath: string, operation: "all" | "field" | "pick"): PayloadDataField;
|
|
4
|
+
//# sourceMappingURL=compile-field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-field.d.ts","sourceRoot":"","sources":["../../src/payload/compile-field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAQjE,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,GAClC,gBAAgB,CA2GlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/payload/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// @nexload-sdk/payload-schema v3.0.0 (build 2026-11-25T11:31:32.762Z)
|
|
2
|
+
import {
|
|
3
|
+
PayloadSchemaError,
|
|
4
|
+
dataFieldTypes,
|
|
5
|
+
errorName,
|
|
6
|
+
findEntityEntry,
|
|
7
|
+
getEntityBinding,
|
|
8
|
+
isPayloadSchemaError,
|
|
9
|
+
parseCanonical
|
|
10
|
+
} from "../internal/chunk-BX5LWYAU.js";
|
|
11
|
+
|
|
12
|
+
// src/internal/clone.ts
|
|
13
|
+
function isPlainObject(value) {
|
|
14
|
+
const prototype = Object.getPrototypeOf(value);
|
|
15
|
+
return prototype === Object.prototype || prototype === null;
|
|
16
|
+
}
|
|
17
|
+
function cloneConfig(value) {
|
|
18
|
+
if (Array.isArray(value)) return value.map((item) => cloneConfig(item));
|
|
19
|
+
if (value === null || typeof value !== "object" || !isPlainObject(value)) return value;
|
|
20
|
+
const clone = Object.create(Object.getPrototypeOf(value));
|
|
21
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
22
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
23
|
+
value,
|
|
24
|
+
key
|
|
25
|
+
);
|
|
26
|
+
if (!descriptor) continue;
|
|
27
|
+
if ("value" in descriptor) descriptor.value = cloneConfig(descriptor.value);
|
|
28
|
+
Object.defineProperty(
|
|
29
|
+
clone,
|
|
30
|
+
key,
|
|
31
|
+
descriptor
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return clone;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/payload/canonical-hook.ts
|
|
38
|
+
import { ValidationError } from "payload";
|
|
39
|
+
function validationPath(basePath, issuePath) {
|
|
40
|
+
return [
|
|
41
|
+
...basePath,
|
|
42
|
+
...issuePath
|
|
43
|
+
].map(String).join(".");
|
|
44
|
+
}
|
|
45
|
+
function canonicalHook(seed, entity, fieldPath) {
|
|
46
|
+
return ({ path, req, value }) => {
|
|
47
|
+
if (value === void 0 || value === null || !seed.runtimeSchema) return value;
|
|
48
|
+
const result = parseCanonical(
|
|
49
|
+
seed.runtimeSchema,
|
|
50
|
+
value,
|
|
51
|
+
{ entity, fieldPath, fieldKind: seed.kind }
|
|
52
|
+
);
|
|
53
|
+
if (result.success) return result.data;
|
|
54
|
+
const basePath = Array.isArray(path) && path.length ? path : fieldPath.split(".");
|
|
55
|
+
throw new ValidationError({
|
|
56
|
+
req,
|
|
57
|
+
errors: result.error.issues.map((issue) => ({
|
|
58
|
+
path: validationPath(
|
|
59
|
+
basePath,
|
|
60
|
+
issue.path
|
|
61
|
+
),
|
|
62
|
+
message: issue.message
|
|
63
|
+
}))
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function appendCanonicalHook(value, hook) {
|
|
68
|
+
const hooks = value && typeof value === "object" ? cloneConfig(value) : {};
|
|
69
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
70
|
+
hooks,
|
|
71
|
+
"beforeValidate"
|
|
72
|
+
);
|
|
73
|
+
if (descriptor && !("value" in descriptor)) {
|
|
74
|
+
Object.defineProperty(
|
|
75
|
+
hooks,
|
|
76
|
+
"beforeValidate",
|
|
77
|
+
{
|
|
78
|
+
...descriptor,
|
|
79
|
+
get: descriptor.get ? function() {
|
|
80
|
+
const consumerHooks2 = descriptor.get?.call(this);
|
|
81
|
+
return [
|
|
82
|
+
...Array.isArray(consumerHooks2) ? consumerHooks2 : [],
|
|
83
|
+
hook
|
|
84
|
+
];
|
|
85
|
+
} : () => [hook]
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
return hooks;
|
|
89
|
+
}
|
|
90
|
+
const consumerHooks = descriptor && "value" in descriptor && Array.isArray(descriptor.value) ? descriptor.value : [];
|
|
91
|
+
Object.defineProperty(
|
|
92
|
+
hooks,
|
|
93
|
+
"beforeValidate",
|
|
94
|
+
{
|
|
95
|
+
configurable: true,
|
|
96
|
+
enumerable: true,
|
|
97
|
+
value: [
|
|
98
|
+
...consumerHooks,
|
|
99
|
+
hook
|
|
100
|
+
],
|
|
101
|
+
writable: true
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
return hooks;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/payload/compile-field.ts
|
|
108
|
+
function compileField(seed, name, entity, fieldPath, operation) {
|
|
109
|
+
try {
|
|
110
|
+
const extras = cloneConfig(seed.payloadExtras);
|
|
111
|
+
const core = cloneConfig(seed.payloadCore);
|
|
112
|
+
const compiled = Object.create(Object.prototype);
|
|
113
|
+
const extraDescriptors = Object.getOwnPropertyDescriptors(extras);
|
|
114
|
+
const hooksDescriptor = extraDescriptors.hooks;
|
|
115
|
+
delete extraDescriptors.hooks;
|
|
116
|
+
Object.defineProperties(
|
|
117
|
+
compiled,
|
|
118
|
+
extraDescriptors
|
|
119
|
+
);
|
|
120
|
+
Object.defineProperties(
|
|
121
|
+
compiled,
|
|
122
|
+
Object.getOwnPropertyDescriptors(core)
|
|
123
|
+
);
|
|
124
|
+
Object.defineProperties(
|
|
125
|
+
compiled,
|
|
126
|
+
{
|
|
127
|
+
name: { configurable: true, enumerable: true, value: name, writable: true },
|
|
128
|
+
type: { configurable: true, enumerable: true, value: seed.payloadType, writable: true }
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
if (seed.children) {
|
|
132
|
+
compiled.fields = seed.children.map(([
|
|
133
|
+
childName,
|
|
134
|
+
child
|
|
135
|
+
]) => compileField(
|
|
136
|
+
child,
|
|
137
|
+
childName,
|
|
138
|
+
entity,
|
|
139
|
+
`${fieldPath}.${childName}`,
|
|
140
|
+
operation
|
|
141
|
+
));
|
|
142
|
+
}
|
|
143
|
+
if (seed.blocks) {
|
|
144
|
+
compiled.blocks = seed.blocks.map((block) => {
|
|
145
|
+
const blockExtras = cloneConfig(block.payloadExtras);
|
|
146
|
+
const compiledBlock = Object.create(Object.prototype);
|
|
147
|
+
Object.defineProperties(
|
|
148
|
+
compiledBlock,
|
|
149
|
+
Object.getOwnPropertyDescriptors(blockExtras)
|
|
150
|
+
);
|
|
151
|
+
compiledBlock.slug = block.slug;
|
|
152
|
+
compiledBlock.fields = block.children.map(([
|
|
153
|
+
childName,
|
|
154
|
+
child
|
|
155
|
+
]) => compileField(
|
|
156
|
+
child,
|
|
157
|
+
childName,
|
|
158
|
+
entity,
|
|
159
|
+
`${fieldPath}.${block.slug}.${childName}`,
|
|
160
|
+
operation
|
|
161
|
+
));
|
|
162
|
+
return compiledBlock;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (seed.runtimeSchema) {
|
|
166
|
+
const hook = canonicalHook(
|
|
167
|
+
seed,
|
|
168
|
+
entity,
|
|
169
|
+
fieldPath
|
|
170
|
+
);
|
|
171
|
+
if (hooksDescriptor && !("value" in hooksDescriptor)) {
|
|
172
|
+
Object.defineProperty(
|
|
173
|
+
compiled,
|
|
174
|
+
"hooks",
|
|
175
|
+
{
|
|
176
|
+
...hooksDescriptor,
|
|
177
|
+
get: hooksDescriptor.get ? function() {
|
|
178
|
+
return appendCanonicalHook(
|
|
179
|
+
hooksDescriptor.get?.call(this),
|
|
180
|
+
hook
|
|
181
|
+
);
|
|
182
|
+
} : () => appendCanonicalHook(
|
|
183
|
+
void 0,
|
|
184
|
+
hook
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
} else {
|
|
189
|
+
Object.defineProperty(
|
|
190
|
+
compiled,
|
|
191
|
+
"hooks",
|
|
192
|
+
{
|
|
193
|
+
configurable: true,
|
|
194
|
+
enumerable: true,
|
|
195
|
+
value: appendCanonicalHook(
|
|
196
|
+
hooksDescriptor && "value" in hooksDescriptor ? hooksDescriptor.value : void 0,
|
|
197
|
+
hook
|
|
198
|
+
),
|
|
199
|
+
writable: true
|
|
200
|
+
}
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
} else if (hooksDescriptor) {
|
|
204
|
+
Object.defineProperty(
|
|
205
|
+
compiled,
|
|
206
|
+
"hooks",
|
|
207
|
+
hooksDescriptor
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
if (!dataFieldTypes.has(seed.payloadType)) {
|
|
211
|
+
throw new PayloadSchemaError(
|
|
212
|
+
"INVALID_PAYLOAD_FIELD",
|
|
213
|
+
{
|
|
214
|
+
phase: "payload-compilation",
|
|
215
|
+
message: `Field "${fieldPath}" does not compile to a data-affecting Payload field.`,
|
|
216
|
+
data: { entity, fieldPath, fieldKind: seed.kind, reason: `unsupported type ${seed.payloadType}` }
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
return compiled;
|
|
221
|
+
} catch (error) {
|
|
222
|
+
if (isPayloadSchemaError(error)) throw error;
|
|
223
|
+
throw new PayloadSchemaError(
|
|
224
|
+
"PAYLOAD_COMPILATION_FAILED",
|
|
225
|
+
{
|
|
226
|
+
phase: "payload-compilation",
|
|
227
|
+
message: `Failed to compile Payload field "${fieldPath}".`,
|
|
228
|
+
data: {
|
|
229
|
+
entity,
|
|
230
|
+
fieldPath,
|
|
231
|
+
fieldKind: seed.kind,
|
|
232
|
+
operation,
|
|
233
|
+
causeName: errorName(error)
|
|
234
|
+
},
|
|
235
|
+
cause: error
|
|
236
|
+
}
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/payload/payload-fields.ts
|
|
242
|
+
function payloadFields(entity) {
|
|
243
|
+
const { entries, name: entityName } = getEntityBinding(entity);
|
|
244
|
+
const getEntry = (key) => findEntityEntry(
|
|
245
|
+
entityName,
|
|
246
|
+
entries,
|
|
247
|
+
key
|
|
248
|
+
);
|
|
249
|
+
return Object.freeze({
|
|
250
|
+
all: () => entries.map(([
|
|
251
|
+
name,
|
|
252
|
+
seed
|
|
253
|
+
]) => compileField(
|
|
254
|
+
seed,
|
|
255
|
+
name,
|
|
256
|
+
entityName,
|
|
257
|
+
name,
|
|
258
|
+
"all"
|
|
259
|
+
)),
|
|
260
|
+
field: (key) => {
|
|
261
|
+
const [
|
|
262
|
+
name,
|
|
263
|
+
seed
|
|
264
|
+
] = getEntry(key);
|
|
265
|
+
return compileField(
|
|
266
|
+
seed,
|
|
267
|
+
name,
|
|
268
|
+
entityName,
|
|
269
|
+
name,
|
|
270
|
+
"field"
|
|
271
|
+
);
|
|
272
|
+
},
|
|
273
|
+
pick: (keys) => keys.map((key) => {
|
|
274
|
+
const [
|
|
275
|
+
name,
|
|
276
|
+
seed
|
|
277
|
+
] = getEntry(key);
|
|
278
|
+
return compileField(
|
|
279
|
+
seed,
|
|
280
|
+
name,
|
|
281
|
+
entityName,
|
|
282
|
+
name,
|
|
283
|
+
"pick"
|
|
284
|
+
);
|
|
285
|
+
})
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
export {
|
|
289
|
+
payloadFields
|
|
290
|
+
};
|
|
291
|
+
//# sourceMappingURL=index.js.map
|