@ainsleydev/payload-helper 0.0.25 → 0.0.27
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/gen/types.js +5 -2
- package/dist/gen/types.js.map +1 -1
- package/dist/plugin/schema.js +21 -2
- package/dist/plugin/schema.js.map +1 -1
- package/dist/seed/media.js +1 -1
- package/dist/seed/media.js.map +1 -1
- package/dist/util/validation.d.ts +3 -2
- package/dist/util/validation.js.map +1 -1
- package/package.json +6 -16
package/dist/gen/types.js
CHANGED
|
@@ -8,14 +8,17 @@ import { fieldMapper, schemas } from '../plugin/schema.js';
|
|
|
8
8
|
const outputFile = (process.env.PAYLOAD_TS_OUTPUT_PATH || config.typescript.outputFile).replace('.ts', '.json');
|
|
9
9
|
config.typescript = {
|
|
10
10
|
...config.typescript,
|
|
11
|
-
schema:
|
|
11
|
+
schema: [
|
|
12
|
+
...config.typescript.schema,
|
|
13
|
+
...schemas(opts)
|
|
14
|
+
]
|
|
12
15
|
};
|
|
13
16
|
// biome-ignore lint/style/noParameterAssign: Need to change field mapper.
|
|
14
17
|
config = fieldMapper(config, opts);
|
|
15
18
|
const payload = await getPayload({
|
|
16
19
|
config
|
|
17
20
|
});
|
|
18
|
-
const jsonSchema = configToJSONSchema(
|
|
21
|
+
const jsonSchema = configToJSONSchema(config, payload.db.defaultIDType);
|
|
19
22
|
const prettyJSON = JSON.stringify(jsonSchema, null, 4);
|
|
20
23
|
fs.writeFileSync(outputFile, prettyJSON);
|
|
21
24
|
console.log(`JSON types written to: ${outputFile}`);
|
package/dist/gen/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/gen/types.ts"],"sourcesContent":["import * as fs from 'node:fs';\nimport { type SanitizedConfig, configToJSONSchema, getPayload } from 'payload';\nimport { type SchemaOptions, fieldMapper, schemas } from '../plugin/schema.js';\n\n/**\n * Creates JSON schema types of Payloads Collections & Globals\n */\nexport async function generateTypes(config: SanitizedConfig, opts: SchemaOptions): Promise<void> {\n\tconsole.log('Compiling JSON types for Collections and Globals...');\n\n\tconst outputFile = (process.env.PAYLOAD_TS_OUTPUT_PATH || config.typescript.outputFile).replace(\n\t\t'.ts',\n\t\t'.json',\n\t);\n\n\tconfig.typescript = {\n\t\t...config.typescript,\n\t\tschema: schemas(opts),\n\t};\n\n\t// biome-ignore lint/style/noParameterAssign: Need to change field mapper.\n\tconfig = fieldMapper(config, opts);\n\n\tconst payload = await getPayload({\n\t\tconfig,\n\t\t//disableDBConnect: true,\n\t\t//disableOnInit: true,\n\t});\n\n\tconst jsonSchema = configToJSONSchema(
|
|
1
|
+
{"version":3,"sources":["../../src/gen/types.ts"],"sourcesContent":["import * as fs from 'node:fs';\nimport { type SanitizedConfig, configToJSONSchema, getPayload } from 'payload';\nimport { type SchemaOptions, fieldMapper, schemas } from '../plugin/schema.js';\n\n/**\n * Creates JSON schema types of Payloads Collections & Globals\n */\nexport async function generateTypes(config: SanitizedConfig, opts: SchemaOptions): Promise<void> {\n\tconsole.log('Compiling JSON types for Collections and Globals...');\n\n\tconst outputFile = (process.env.PAYLOAD_TS_OUTPUT_PATH || config.typescript.outputFile).replace(\n\t\t'.ts',\n\t\t'.json',\n\t);\n\n\tconfig.typescript = {\n\t\t...config.typescript,\n\t\tschema: [...config.typescript.schema, ...schemas(opts)],\n\t};\n\n\t// biome-ignore lint/style/noParameterAssign: Need to change field mapper.\n\tconfig = fieldMapper(config, opts);\n\n\tconst payload = await getPayload({\n\t\tconfig,\n\t\t//disableDBConnect: true,\n\t\t//disableOnInit: true,\n\t});\n\n\tconst jsonSchema = configToJSONSchema(config, payload.db.defaultIDType);\n\tconst prettyJSON = JSON.stringify(jsonSchema, null, 4);\n\n\tfs.writeFileSync(outputFile, prettyJSON);\n\n\tconsole.log(`JSON types written to: ${outputFile}`);\n\n\tdelete process.env.GEN_GOLANG;\n}\n"],"names":["fs","configToJSONSchema","getPayload","fieldMapper","schemas","generateTypes","config","opts","console","log","outputFile","process","env","PAYLOAD_TS_OUTPUT_PATH","typescript","replace","schema","payload","jsonSchema","db","defaultIDType","prettyJSON","JSON","stringify","writeFileSync","GEN_GOLANG"],"mappings":"AAAA,YAAYA,QAAQ,UAAU;AAC9B,SAA+BC,kBAAkB,EAAEC,UAAU,QAAQ,UAAU;AAC/E,SAA6BC,WAAW,EAAEC,OAAO,QAAQ,sBAAsB;AAE/E;;CAEC,GACD,OAAO,eAAeC,cAAcC,MAAuB,EAAEC,IAAmB;IAC/EC,QAAQC,GAAG,CAAC;IAEZ,MAAMC,aAAa,AAACC,CAAAA,QAAQC,GAAG,CAACC,sBAAsB,IAAIP,OAAOQ,UAAU,CAACJ,UAAU,AAAD,EAAGK,OAAO,CAC9F,OACA;IAGDT,OAAOQ,UAAU,GAAG;QACnB,GAAGR,OAAOQ,UAAU;QACpBE,QAAQ;eAAIV,OAAOQ,UAAU,CAACE,MAAM;eAAKZ,QAAQG;SAAM;IACxD;IAEA,0EAA0E;IAC1ED,SAASH,YAAYG,QAAQC;IAE7B,MAAMU,UAAU,MAAMf,WAAW;QAChCI;IAGD;IAEA,MAAMY,aAAajB,mBAAmBK,QAAQW,QAAQE,EAAE,CAACC,aAAa;IACtE,MAAMC,aAAaC,KAAKC,SAAS,CAACL,YAAY,MAAM;IAEpDlB,GAAGwB,aAAa,CAACd,YAAYW;IAE7Bb,QAAQC,GAAG,CAAC,CAAC,uBAAuB,EAAEC,YAAY;IAElD,OAAOC,QAAQC,GAAG,CAACa,UAAU;AAC9B"}
|
package/dist/plugin/schema.js
CHANGED
|
@@ -66,9 +66,17 @@
|
|
|
66
66
|
break;
|
|
67
67
|
case 'upload':
|
|
68
68
|
if (opts.useWebKitMedia) {
|
|
69
|
+
const isArray = field.hasMany; // Assuming `hasMany` indicates an array of uploads
|
|
69
70
|
field.typescriptSchema = [
|
|
70
71
|
()=>({
|
|
71
|
-
...
|
|
72
|
+
...isArray ? {
|
|
73
|
+
type: 'array',
|
|
74
|
+
items: {
|
|
75
|
+
...addGoJSONSchema('payload.Media', field.required === true)
|
|
76
|
+
}
|
|
77
|
+
} : {
|
|
78
|
+
...addGoJSONSchema('payload.Media', field.required === true)
|
|
79
|
+
}
|
|
72
80
|
})
|
|
73
81
|
];
|
|
74
82
|
}
|
|
@@ -114,7 +122,7 @@
|
|
|
114
122
|
break;
|
|
115
123
|
}
|
|
116
124
|
}
|
|
117
|
-
if (field.type !== 'ui' && opts.assignRelationships) {
|
|
125
|
+
if (field.type !== 'ui' && (opts.assignRelationships || field.custom?.webkitUseSchema)) {
|
|
118
126
|
if (!Array.isArray(field.typescriptSchema)) {
|
|
119
127
|
field.typescriptSchema = [];
|
|
120
128
|
}
|
|
@@ -172,6 +180,17 @@
|
|
|
172
180
|
delete jsonSchema.properties?.collections?.properties?.['payload-locked-documents'];
|
|
173
181
|
delete jsonSchema.definitions.redirects;
|
|
174
182
|
delete jsonSchema.properties?.collections?.properties?.redirects;
|
|
183
|
+
// I don't know why but Payload duplicates types and adds Select?
|
|
184
|
+
for(const key in jsonSchema.definitions){
|
|
185
|
+
if (key.endsWith('select') || key.endsWith('Select')) {
|
|
186
|
+
delete jsonSchema.definitions[key];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
for(const key in jsonSchema.properties){
|
|
190
|
+
if (key.endsWith('select') || key.endsWith('Select')) {
|
|
191
|
+
delete jsonSchema.properties[key];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
175
194
|
return jsonSchema;
|
|
176
195
|
},
|
|
177
196
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugin/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema';\nimport type { Config, Field, SanitizedConfig } from 'payload';\n\n/**\n * General Options for Generating Schema\n */\nexport interface SchemaOptions {\n\tuseWebKitMedia?: boolean;\n\tassignRelationships?: boolean;\n}\n\n/**\n * This function iterates over properties in JSON schema definitions,\n * passing each property and its key to a callback function.\n */\nconst loopJSONSchemaProperties = (\n\tjsonSchema: JSONSchema4,\n\tcallback: (args: { key: string; property: JSONSchema4 }) => void,\n): JSONSchema4 => {\n\tif (!jsonSchema.definitions) {\n\t\treturn jsonSchema;\n\t}\n\tObject.entries(jsonSchema.definitions).forEach(([definitionKey, definition]) => {\n\t\tif (definition.properties) {\n\t\t\tObject.entries(definition.properties).forEach(([propertyKey, property]) => {\n\t\t\t\tcallback({ key: propertyKey, property });\n\t\t\t});\n\t\t}\n\t});\n\treturn jsonSchema;\n};\n\n/**\n * Adds the necessary GoLang type conversions as a helper func.\n */\nexport const addGoJSONSchema = (type: string, nillable: boolean): Record<string, unknown> => {\n\treturn {\n\t\tgoJSONSchema: {\n\t\t\timports: ['github.com/ainsleydev/webkit/pkg/adapters/payload'],\n\t\t\tnillable: nillable,\n\t\t\ttype: type,\n\t\t},\n\t};\n};\n\n/**\n * Iterates over all the fields within the config, for both collections\n * and globals, and transforms the JSON schema\n * to include the necessary GoLang schema.\n *\n * @param config\n */\nexport const fieldMapper = (config: SanitizedConfig, opts: SchemaOptions) => {\n\tconst mapper = (field: Field): Field => {\n\t\tswitch (field.type) {\n\t\t\tcase 'blocks':\n\t\t\t\tfield.typescriptSchema = [() => ({ ...addGoJSONSchema('payload.Blocks', false) })];\n\t\t\t\tfield.blocks.forEach((block) => {\n\t\t\t\t\tblock.fields = block.fields.map((f) => mapper(f));\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase 'json':\n\t\t\t\tfield.typescriptSchema = [() => ({ ...addGoJSONSchema('payload.JSON', false) })];\n\t\t\t\tbreak;\n\t\t\tcase 'richText':\n\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t() => ({\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t...addGoJSONSchema('payload.RichText', false),\n\t\t\t\t\t}),\n\t\t\t\t];\n\t\t\t\tbreak;\n\t\t\tcase 'upload':\n\t\t\t\tif (opts.useWebKitMedia) {\n\t\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t\t() => ({ ...addGoJSONSchema('payload.Media', field.required === true) }),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'point':\n\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t() => ({\n\t\t\t\t\t\t...addGoJSONSchema('payload.Point', field.required === true),\n\t\t\t\t\t}),\n\t\t\t\t];\n\t\t\t\tbreak;\n\t\t\tcase 'tabs': {\n\t\t\t\tfield.tabs.forEach((tab) => {\n\t\t\t\t\ttab.fields = tab.fields.map((f) => mapper(f));\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'relationship': {\n\t\t\t\tif (field.relationTo === 'forms') {\n\t\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t\t() => ({ ...addGoJSONSchema('payload.Form', field.required === true) }),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'group':\n\t\t\tcase 'array':\n\t\t\tcase 'row':\n\t\t\tcase 'collapsible': {\n\t\t\t\tif (field.type === 'group' && field.name === 'meta') {\n\t\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t\t() => ({ ...addGoJSONSchema('payload.SettingsMeta', true) }),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\tfield.fields = field.fields.map((f) => mapper(f));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t// SEE: https://github.com/ainsleydev/webkit/blob/cdfa078605bec4ee92f2424f69271a0bf6b71366/packages/payload-helper/src/gen/schema.ts#L235\n\t\t}\n\n\t\tif (field.type !== 'ui' && opts.assignRelationships) {\n\t\t\tif (!Array.isArray(field.typescriptSchema)) {\n\t\t\t\tfield.typescriptSchema = [];\n\t\t\t}\n\n\t\t\tif (field.type !== 'tabs' && field.type !== 'row' && field.type !== 'collapsible') {\n\t\t\t\tfield.typescriptSchema.push(({ jsonSchema }) => {\n\t\t\t\t\tconst payload = {\n\t\t\t\t\t\tname: field.name,\n\t\t\t\t\t\ttype: field.type,\n\t\t\t\t\t\tlabel: field.label,\n\t\t\t\t\t} as Record<string, unknown>;\n\n\t\t\t\t\tif (field.type === 'relationship') {\n\t\t\t\t\t\tpayload.hasMany = field.hasMany;\n\t\t\t\t\t\tpayload.relationTo = field.relationTo;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...jsonSchema,\n\t\t\t\t\t\tpayload,\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn field;\n\t};\n\n\tif (config.collections) {\n\t\tconfig.collections.forEach((collection) => {\n\t\t\tcollection.fields = collection.fields.map((field) => mapper(field));\n\t\t});\n\t}\n\n\tif (config.globals) {\n\t\tconfig.globals.forEach((global, index) => {\n\t\t\tglobal.fields = global.fields.map((field) => mapper(field));\n\t\t});\n\t}\n\n\treturn config;\n};\n\n/**\n * Adjusts the JSON schema to include the necessary GoLang schema\n *\n */\nexport const schemas = (\n\topts: SchemaOptions,\n): Array<(args: { jsonSchema: JSONSchema4 }) => JSONSchema4> => [\n\t/**\n\t * Removes the auth & uneeded definitions from the schema.\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tif (!jsonSchema.properties) {\n\t\t\tjsonSchema.properties = {};\n\t\t}\n\t\tif (!jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions = {};\n\t\t}\n\n\t\tif (opts.useWebKitMedia) {\n\t\t\tdelete jsonSchema.definitions.media;\n\t\t\tdelete jsonSchema.properties?.collections?.properties?.media;\n\t\t}\n\n\t\tdelete jsonSchema.properties.auth;\n\t\tdelete jsonSchema.definitions['payload-locked-documents'];\n\t\tdelete jsonSchema.properties?.collections?.properties?.['payload-locked-documents'];\n\t\tdelete jsonSchema.definitions.redirects;\n\t\tdelete jsonSchema.properties?.collections?.properties?.redirects;\n\t\treturn jsonSchema;\n\t},\n\t/**\n\t * Adds the settings and media definitions to the schema\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tif (!jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions = {};\n\t\t}\n\n\t\tif ('settings' in jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions.settings = {\n\t\t\t\ttype: 'object',\n\t\t\t\tfields: [],\n\t\t\t\t...addGoJSONSchema('payload.Settings', false),\n\t\t\t};\n\t\t}\n\n\t\tif ('forms' in jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions.forms = {\n\t\t\t\ttype: 'object',\n\t\t\t\t...addGoJSONSchema('payload.Form', false),\n\t\t\t\tfields: [],\n\t\t\t};\n\t\t}\n\n\t\tif ('form-submissions' in jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions['form-submissions'] = {\n\t\t\t\ttype: 'object',\n\t\t\t\t...addGoJSONSchema('payload.FormSubmission', false),\n\t\t\t\tfields: [],\n\t\t\t};\n\t\t}\n\n\t\treturn jsonSchema;\n\t},\n\t/**\n\t * Updates the JSON schema so that it doesn't feature oneOf, so Go doesn't\n\t * output it as an interface{}.\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tconst updateRelationship = (property: JSONSchema4) => {\n\t\t\tconst payload = property.payload;\n\t\t\tif (!payload) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (payload.type === 'relationship') {\n\t\t\t\tif (payload.hasMany) {\n\t\t\t\t\tproperty.type = 'array';\n\t\t\t\t\tproperty.items = {\n\t\t\t\t\t\t$ref: `#/definitions/${payload.relationTo}`,\n\t\t\t\t\t};\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tdelete property.oneOf;\n\t\t\t\tproperty.$ref = `#/definitions/${property.payload.relationTo}`;\n\t\t\t}\n\n\t\t\tconst pType = payload.type;\n\t\t\tif (\n\t\t\t\tpType === 'group' ||\n\t\t\t\tpType === 'row' ||\n\t\t\t\tpType === 'collapsible' ||\n\t\t\t\tpType === 'array'\n\t\t\t) {\n\t\t\t\tif (property.properties) {\n\t\t\t\t\tfor (const k in property.properties) {\n\t\t\t\t\t\tupdateRelationship(property.properties[k]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t};\n\n\t\tloopJSONSchemaProperties(jsonSchema, ({ property }) => {\n\t\t\tupdateRelationship(property);\n\t\t});\n\t\treturn jsonSchema;\n\t},\n\t/**\n\t * Changes blockType to a string so it's not an *interface{} when\n\t * comparing block types in Go.\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tloopJSONSchemaProperties(jsonSchema, ({ property, key }) => {\n\t\t\tif (key === 'blockType') {\n\t\t\t\tproperty.type = 'string';\n\t\t\t\tdelete property.const;\n\t\t\t}\n\t\t});\n\t\treturn jsonSchema;\n\t},\n\t/**\n\t * Changes blockType to a string so it's not an *interface{} when\n\t * comparing block types in Go.\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tloopJSONSchemaProperties(jsonSchema, ({ property, key }) => {\n\t\t\tconst payload = property.payload;\n\t\t\tif (payload && payload.type === 'relationship' && payload.name === 'form') {\n\t\t\t\tdelete property.$ref;\n\t\t\t}\n\t\t});\n\t\treturn jsonSchema;\n\t},\n];\n"],"names":["loopJSONSchemaProperties","jsonSchema","callback","definitions","Object","entries","forEach","definitionKey","definition","properties","propertyKey","property","key","addGoJSONSchema","type","nillable","goJSONSchema","imports","fieldMapper","config","opts","mapper","field","typescriptSchema","blocks","block","fields","map","f","useWebKitMedia","required","tabs","tab","relationTo","name","assignRelationships","Array","isArray","push","payload","label","hasMany","collections","collection","globals","global","index","schemas","media","auth","redirects","settings","forms","updateRelationship","items","$ref","oneOf","pType","k","const"],"mappings":"AAWA;;;CAGC,GACD,MAAMA,2BAA2B,CAChCC,YACAC;IAEA,IAAI,CAACD,WAAWE,WAAW,EAAE;QAC5B,OAAOF;IACR;IACAG,OAAOC,OAAO,CAACJ,WAAWE,WAAW,EAAEG,OAAO,CAAC,CAAC,CAACC,eAAeC,WAAW;QAC1E,IAAIA,WAAWC,UAAU,EAAE;YAC1BL,OAAOC,OA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AAU,EAAE;wBACxB,IAAK,MAAMiD,KAAK/C,SAASF,UAAU,CAAE;4BACpC4C,mBAAmB1C,SAASF,UAAU,CAACiD,EAAE;wBAC1C;oBACD;oBACA;gBACD;YACD;YAEA1D,yBAAyBC,YAAY,CAAC,EAAEU,QAAQ,EAAE;gBACjD0C,mBAAmB1C;YACpB;YACA,OAAOV;QACR;QACA;;;EAGC,GACD,CAAC,EAAEA,UAAU,EAAE;YACdD,yBAAyBC,YAAY,CAAC,EAAEU,QAAQ,EAAEC,GAAG,EAAE;gBACtD,IAAIA,QAAQ,aAAa;oBACxBD,SAASG,IAAI,GAAG;oBAChB,OAAOH,SAASgD,KAAK;gBACtB;YACD;YACA,OAAO1D;QACR;QACA;;;EAGC,GACD,CAAC,EAAEA,UAAU,EAAE;YACdD,yBAAyBC,YAAY,CAAC,EAAEU,QAAQ,EAAEC,GAAG,EAAE;gBACtD,MAAM2B,UAAU5B,SAAS4B,OAAO;gBAChC,IAAIA,WAAWA,QAAQzB,IAAI,KAAK,kBAAkByB,QAAQL,IAAI,KAAK,QAAQ;oBAC1E,OAAOvB,SAAS4C,IAAI;gBACrB;YACD;YACA,OAAOtD;QACR;KACA,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/plugin/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema';\nimport type { Config, Field, SanitizedConfig } from 'payload';\n\n/**\n * General Options for Generating Schema\n */\nexport interface SchemaOptions {\n\tuseWebKitMedia?: boolean;\n\tassignRelationships?: boolean;\n}\n\n/**\n * This function iterates over properties in JSON schema definitions,\n * passing each property and its key to a callback function.\n */\nconst loopJSONSchemaProperties = (\n\tjsonSchema: JSONSchema4,\n\tcallback: (args: { key: string; property: JSONSchema4 }) => void,\n): JSONSchema4 => {\n\tif (!jsonSchema.definitions) {\n\t\treturn jsonSchema;\n\t}\n\tObject.entries(jsonSchema.definitions).forEach(([definitionKey, definition]) => {\n\t\tif (definition.properties) {\n\t\t\tObject.entries(definition.properties).forEach(([propertyKey, property]) => {\n\t\t\t\tcallback({ key: propertyKey, property });\n\t\t\t});\n\t\t}\n\t});\n\treturn jsonSchema;\n};\n\n/**\n * Adds the necessary GoLang type conversions as a helper func.\n */\nexport const addGoJSONSchema = (type: string, nillable: boolean): Record<string, unknown> => {\n\treturn {\n\t\tgoJSONSchema: {\n\t\t\timports: ['github.com/ainsleydev/webkit/pkg/adapters/payload'],\n\t\t\tnillable: nillable,\n\t\t\ttype: type,\n\t\t},\n\t};\n};\n\n/**\n * Iterates over all the fields within the config, for both collections\n * and globals, and transforms the JSON schema\n * to include the necessary GoLang schema.\n *\n * @param config\n */\nexport const fieldMapper = (config: SanitizedConfig, opts: SchemaOptions) => {\n\tconst mapper = (field: Field): Field => {\n\t\tswitch (field.type) {\n\t\t\tcase 'blocks':\n\t\t\t\tfield.typescriptSchema = [() => ({ ...addGoJSONSchema('payload.Blocks', false) })];\n\t\t\t\tfield.blocks.forEach((block) => {\n\t\t\t\t\tblock.fields = block.fields.map((f) => mapper(f));\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase 'json':\n\t\t\t\tfield.typescriptSchema = [() => ({ ...addGoJSONSchema('payload.JSON', false) })];\n\t\t\t\tbreak;\n\t\t\tcase 'richText':\n\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t() => ({\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t...addGoJSONSchema('payload.RichText', false),\n\t\t\t\t\t}),\n\t\t\t\t];\n\t\t\t\tbreak;\n\t\t\tcase 'upload':\n\t\t\t\tif (opts.useWebKitMedia) {\n\t\t\t\t\tconst isArray = field.hasMany; // Assuming `hasMany` indicates an array of uploads\n\t\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t\t() => ({\n\t\t\t\t\t\t\t...(isArray\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\ttype: 'array',\n\t\t\t\t\t\t\t\t\t\titems: {\n\t\t\t\t\t\t\t\t\t\t\t...addGoJSONSchema(\n\t\t\t\t\t\t\t\t\t\t\t\t'payload.Media',\n\t\t\t\t\t\t\t\t\t\t\t\tfield.required === true,\n\t\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: { ...addGoJSONSchema('payload.Media', field.required === true) }),\n\t\t\t\t\t\t}),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'point':\n\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t() => ({\n\t\t\t\t\t\t...addGoJSONSchema('payload.Point', field.required === true),\n\t\t\t\t\t}),\n\t\t\t\t];\n\t\t\t\tbreak;\n\t\t\tcase 'tabs': {\n\t\t\t\tfield.tabs.forEach((tab) => {\n\t\t\t\t\ttab.fields = tab.fields.map((f) => mapper(f));\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'relationship': {\n\t\t\t\tif (field.relationTo === 'forms') {\n\t\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t\t() => ({ ...addGoJSONSchema('payload.Form', field.required === true) }),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'group':\n\t\t\tcase 'array':\n\t\t\tcase 'row':\n\t\t\tcase 'collapsible': {\n\t\t\t\tif (field.type === 'group' && field.name === 'meta') {\n\t\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t\t() => ({ ...addGoJSONSchema('payload.SettingsMeta', true) }),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\tfield.fields = field.fields.map((f) => mapper(f));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t// SEE: https://github.com/ainsleydev/webkit/blob/cdfa078605bec4ee92f2424f69271a0bf6b71366/packages/payload-helper/src/gen/schema.ts#L235\n\t\t}\n\n\t\tif (field.type !== 'ui' && (opts.assignRelationships || field.custom?.webkitUseSchema)) {\n\t\t\tif (!Array.isArray(field.typescriptSchema)) {\n\t\t\t\tfield.typescriptSchema = [];\n\t\t\t}\n\n\t\t\tif (field.type !== 'tabs' && field.type !== 'row' && field.type !== 'collapsible') {\n\t\t\t\tfield.typescriptSchema.push(({ jsonSchema }) => {\n\t\t\t\t\tconst payload = {\n\t\t\t\t\t\tname: field.name,\n\t\t\t\t\t\ttype: field.type,\n\t\t\t\t\t\tlabel: field.label,\n\t\t\t\t\t} as Record<string, unknown>;\n\n\t\t\t\t\tif (field.type === 'relationship') {\n\t\t\t\t\t\tpayload.hasMany = field.hasMany;\n\t\t\t\t\t\tpayload.relationTo = field.relationTo;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...jsonSchema,\n\t\t\t\t\t\tpayload,\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn field;\n\t};\n\n\tif (config.collections) {\n\t\tconfig.collections.forEach((collection) => {\n\t\t\tcollection.fields = collection.fields.map((field) => mapper(field));\n\t\t});\n\t}\n\n\tif (config.globals) {\n\t\tconfig.globals.forEach((global, index) => {\n\t\t\tglobal.fields = global.fields.map((field) => mapper(field));\n\t\t});\n\t}\n\n\treturn config;\n};\n\n/**\n * Adjusts the JSON schema to include the necessary GoLang schema\n *\n */\nexport const schemas = (\n\topts: SchemaOptions,\n): Array<(args: { jsonSchema: JSONSchema4 }) => JSONSchema4> => [\n\t/**\n\t * Removes the auth & uneeded definitions from the schema.\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tif (!jsonSchema.properties) {\n\t\t\tjsonSchema.properties = {};\n\t\t}\n\t\tif (!jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions = {};\n\t\t}\n\n\t\tif (opts.useWebKitMedia) {\n\t\t\tdelete jsonSchema.definitions.media;\n\t\t\tdelete jsonSchema.properties?.collections?.properties?.media;\n\t\t}\n\n\t\tdelete jsonSchema.properties.auth;\n\t\tdelete jsonSchema.definitions['payload-locked-documents'];\n\t\tdelete jsonSchema.properties?.collections?.properties?.['payload-locked-documents'];\n\t\tdelete jsonSchema.definitions.redirects;\n\t\tdelete jsonSchema.properties?.collections?.properties?.redirects;\n\n\t\t// I don't know why but Payload duplicates types and adds Select?\n\n\t\tfor (const key in jsonSchema.definitions) {\n\t\t\tif (key.endsWith('select') || key.endsWith('Select')) {\n\t\t\t\tdelete jsonSchema.definitions[key];\n\t\t\t}\n\t\t}\n\n\t\tfor (const key in jsonSchema.properties) {\n\t\t\tif (key.endsWith('select') || key.endsWith('Select')) {\n\t\t\t\tdelete jsonSchema.properties[key];\n\t\t\t}\n\t\t}\n\n\t\treturn jsonSchema;\n\t},\n\t/**\n\t * Adds the settings and media definitions to the schema\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tif (!jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions = {};\n\t\t}\n\n\t\tif ('settings' in jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions.settings = {\n\t\t\t\ttype: 'object',\n\t\t\t\tfields: [],\n\t\t\t\t...addGoJSONSchema('payload.Settings', false),\n\t\t\t};\n\t\t}\n\n\t\tif ('forms' in jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions.forms = {\n\t\t\t\ttype: 'object',\n\t\t\t\t...addGoJSONSchema('payload.Form', false),\n\t\t\t\tfields: [],\n\t\t\t};\n\t\t}\n\n\t\tif ('form-submissions' in jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions['form-submissions'] = {\n\t\t\t\ttype: 'object',\n\t\t\t\t...addGoJSONSchema('payload.FormSubmission', false),\n\t\t\t\tfields: [],\n\t\t\t};\n\t\t}\n\n\t\treturn jsonSchema;\n\t},\n\t/**\n\t * Updates the JSON schema so that it doesn't feature oneOf, so Go doesn't\n\t * output it as an interface{}.\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tconst updateRelationship = (property: JSONSchema4) => {\n\t\t\tconst payload = property.payload;\n\t\t\tif (!payload) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (payload.type === 'relationship') {\n\t\t\t\tif (payload.hasMany) {\n\t\t\t\t\tproperty.type = 'array';\n\t\t\t\t\tproperty.items = {\n\t\t\t\t\t\t$ref: `#/definitions/${payload.relationTo}`,\n\t\t\t\t\t};\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tdelete property.oneOf;\n\t\t\t\tproperty.$ref = `#/definitions/${property.payload.relationTo}`;\n\t\t\t}\n\n\t\t\tconst pType = payload.type;\n\t\t\tif (\n\t\t\t\tpType === 'group' ||\n\t\t\t\tpType === 'row' ||\n\t\t\t\tpType === 'collapsible' ||\n\t\t\t\tpType === 'array'\n\t\t\t) {\n\t\t\t\tif (property.properties) {\n\t\t\t\t\tfor (const k in property.properties) {\n\t\t\t\t\t\tupdateRelationship(property.properties[k]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t};\n\n\t\tloopJSONSchemaProperties(jsonSchema, ({ property }) => {\n\t\t\tupdateRelationship(property);\n\t\t});\n\t\treturn jsonSchema;\n\t},\n\t/**\n\t * Changes blockType to a string so it's not an *interface{} when\n\t * comparing block types in Go.\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tloopJSONSchemaProperties(jsonSchema, ({ property, key }) => {\n\t\t\tif (key === 'blockType') {\n\t\t\t\tproperty.type = 'string';\n\t\t\t\tdelete property.const;\n\t\t\t}\n\t\t});\n\t\treturn jsonSchema;\n\t},\n\t/**\n\t * Changes blockType to a string so it's not an *interface{} when\n\t * comparing block types in Go.\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tloopJSONSchemaProperties(jsonSchema, ({ property, key }) => {\n\t\t\tconst payload = property.payload;\n\t\t\tif (payload && payload.type === 'relationship' && payload.name === 'form') {\n\t\t\t\tdelete property.$ref;\n\t\t\t}\n\t\t});\n\t\treturn jsonSchema;\n\t},\n];\n"],"names":["loopJSONSchemaProperties","jsonSchema","callback","definitions","Object","entries","forEach","definitionKey","definition","properties","propertyKey","property","key","addGoJSONSchema","type","nillable","goJSONSchema","imports","fieldMapper","config","opts","mapper","field","typescriptSchema","blocks","block","fields","map","f","useWebKitMedia","isArray","hasMany","items","required","tabs","tab","relationTo","name","assignRelationships","custom","webkitUseSchema","Array","push","payload","label","collections","collection","globals","global","index","schemas","media","auth","redirects","endsWith","settings","forms","updateRelationship","$ref","oneOf","pType","k","const"],"mappings":"AAWA;;;CAGC,GACD,MAAMA,2BAA2B,CAChCC,YACAC;IAEA,IAAI,CAACD,WAAWE,WAAW,EAAE;QAC5B,OAAOF;IACR;IACAG,OAAOC,OAAO,CAACJ,WAAWE,WAAW,EAAEG,OAAO,CAAC,CAAC,CAACC,eAAeC,WAAW;QAC1E,IAAIA,WAAWC,UAAU,EAAE;YAC1BL,OAAOC,OAAO,CAACG,WAAWC,UAAU,EAAEH,OAAO,CAAC,CAAC,CAACI,aAAaC,SAAS;gBACrET,SAAS;oBAAEU,KAAKF;oBAAaC;gBAAS;YACvC;QACD;IACD;IACA,OAAOV;AACR;AAEA;;CAEC,GACD,OAAO,MAAMY,kBAAkB,CAACC,MAAcC;IAC7C,OAAO;QACNC,cAAc;YACbC,SAAS;gBAAC;aAAoD;YAC9DF,UAAUA;YACVD,MAAMA;QACP;IACD;AACD,EAAE;AAEF;;;;;;CAMC,GACD,OAAO,MAAMI,cAAc,CAACC,QAAyBC;IACpD,MAAMC,SAAS,CAACC;QACf,OAAQA,MAAMR,IAAI;YACjB,KAAK;gBACJQ,MAAMC,gBAAgB,GAAG;oBAAC,IAAO,CAAA;4BAAE,GAAGV,gBAAgB,kBAAkB,MAAM;wBAAC,CAAA;iBAAG;gBAClFS,MAAME,MAAM,CAAClB,OAAO,CAAC,CAACmB;oBACrBA,MAAMC,MAAM,GAAGD,MAAMC,MAAM,CAACC,GAAG,CAAC,CAACC,IAAMP,OAAOO;gBAC/C;gBACA;YACD,KAAK;gBACJN,MAAMC,gBAAgB,GAAG;oBAAC,IAAO,CAAA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AAyBC,YAAY,CAAC,EAAEU,QAAQ,EAAE;gBACjD8C,mBAAmB9C;YACpB;YACA,OAAOV;QACR;QACA;;;EAGC,GACD,CAAC,EAAEA,UAAU,EAAE;YACdD,yBAAyBC,YAAY,CAAC,EAAEU,QAAQ,EAAEC,GAAG,EAAE;gBACtD,IAAIA,QAAQ,aAAa;oBACxBD,SAASG,IAAI,GAAG;oBAChB,OAAOH,SAASmD,KAAK;gBACtB;YACD;YACA,OAAO7D;QACR;QACA;;;EAGC,GACD,CAAC,EAAEA,UAAU,EAAE;YACdD,yBAAyBC,YAAY,CAAC,EAAEU,QAAQ,EAAEC,GAAG,EAAE;gBACtD,MAAM+B,UAAUhC,SAASgC,OAAO;gBAChC,IAAIA,WAAWA,QAAQ7B,IAAI,KAAK,kBAAkB6B,QAAQN,IAAI,KAAK,QAAQ;oBAC1E,OAAO1B,SAAS+C,IAAI;gBACrB;YACD;YACA,OAAOzD;QACR;KACA,CAAC"}
|
package/dist/seed/media.js
CHANGED
|
@@ -10,7 +10,7 @@ import { htmlToLexical } from '../util/lexical.js';
|
|
|
10
10
|
*/ export const uploadMedia = async (req, payload, dirname, media)=>{
|
|
11
11
|
try {
|
|
12
12
|
const image = await getFileByPath(path.resolve(dirname, media.path));
|
|
13
|
-
const caption = media.caption ?
|
|
13
|
+
const caption = media.caption ? htmlToLexical(media.caption) : null;
|
|
14
14
|
return await payload.create({
|
|
15
15
|
collection: 'media',
|
|
16
16
|
file: image,
|
package/dist/seed/media.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/seed/media.ts"],"sourcesContent":["import path from 'node:path';\nimport type { Payload, PayloadRequest } from 'payload';\nimport { getFileByPath } from 'payload';\nimport { htmlToLexical } from '../util/lexical.js';\nimport type { Media, MediaSeed } from './types.js';\n\n/**\n *\n * @param req\n * @param payload\n * @param dirname\n * @param media\n */\nexport const uploadMedia = async (\n\treq: PayloadRequest,\n\tpayload: Payload,\n\tdirname: string,\n\tmedia: MediaSeed,\n): Promise<Media> => {\n\ttry {\n\t\tconst image = await getFileByPath(path.resolve(dirname, media.path));\n\t\tconst caption = media.caption ?
|
|
1
|
+
{"version":3,"sources":["../../src/seed/media.ts"],"sourcesContent":["import path from 'node:path';\nimport type { Payload, PayloadRequest } from 'payload';\nimport { getFileByPath } from 'payload';\nimport { htmlToLexical } from '../util/lexical.js';\nimport type { Media, MediaSeed } from './types.js';\n\n/**\n *\n * @param req\n * @param payload\n * @param dirname\n * @param media\n */\nexport const uploadMedia = async (\n\treq: PayloadRequest,\n\tpayload: Payload,\n\tdirname: string,\n\tmedia: MediaSeed,\n): Promise<Media> => {\n\ttry {\n\t\tconst image = await getFileByPath(path.resolve(dirname, media.path));\n\t\tconst caption = media.caption ? htmlToLexical(media.caption) : null;\n\n\t\treturn (await payload.create({\n\t\t\tcollection: 'media',\n\t\t\tfile: image,\n\t\t\tdata: {\n\t\t\t\talt: media.alt,\n\t\t\t\tcaption: caption,\n\t\t\t},\n\t\t\treq,\n\t\t})) as unknown as Media;\n\t} catch (error) {\n\t\tpayload.logger.error(`Uploading media: ${error}`);\n\t\tthrow error;\n\t}\n};\n"],"names":["path","getFileByPath","htmlToLexical","uploadMedia","req","payload","dirname","media","image","resolve","caption","create","collection","file","data","alt","error","logger"],"mappings":"AAAA,OAAOA,UAAU,YAAY;AAE7B,SAASC,aAAa,QAAQ,UAAU;AACxC,SAASC,aAAa,QAAQ,qBAAqB;AAGnD;;;;;;CAMC,GACD,OAAO,MAAMC,cAAc,OAC1BC,KACAC,SACAC,SACAC;IAEA,IAAI;QACH,MAAMC,QAAQ,MAAMP,cAAcD,KAAKS,OAAO,CAACH,SAASC,MAAMP,IAAI;QAClE,MAAMU,UAAUH,MAAMG,OAAO,GAAGR,cAAcK,MAAMG,OAAO,IAAI;QAE/D,OAAQ,MAAML,QAAQM,MAAM,CAAC;YAC5BC,YAAY;YACZC,MAAML;YACNM,MAAM;gBACLC,KAAKR,MAAMQ,GAAG;gBACdL,SAASA;YACV;YACAN;QACD;IACD,EAAE,OAAOY,OAAO;QACfX,QAAQY,MAAM,CAACD,KAAK,CAAC,CAAC,iBAAiB,EAAEA,OAAO;QAChD,MAAMA;IACP;AACD,EAAE"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const
|
|
1
|
+
import type { TextFieldSingleValidation } from 'payload';
|
|
2
|
+
export declare const validateURL: TextFieldSingleValidation;
|
|
3
|
+
export declare const validatePostcode: TextFieldSingleValidation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/validation.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/util/validation.ts"],"sourcesContent":["import type { TextFieldSingleValidation } from 'payload';\n\nexport const validateURL: TextFieldSingleValidation = async (value) => {\n\tif (!value) {\n\t\treturn true;\n\t}\n\ttry {\n\t\tnew URL(value);\n\t\treturn true;\n\t} catch (error) {\n\t\treturn 'Please enter a valid URL';\n\t}\n};\n\nexport const validatePostcode: TextFieldSingleValidation = async (value) => {\n\tif (!value) {\n\t\treturn true;\n\t}\n\tconst postcodeRegex = /^[A-Z]{1,2}\\d[A-Z\\d]? ?\\d[A-Z]{2}$/i;\n\tif (!postcodeRegex.test(value)) {\n\t\treturn 'Invalid postcode format';\n\t}\n\treturn true;\n};\n"],"names":["validateURL","value","URL","error","validatePostcode","postcodeRegex","test"],"mappings":"AAEA,OAAO,MAAMA,cAAyC,OAAOC;IAC5D,IAAI,CAACA,OAAO;QACX,OAAO;IACR;IACA,IAAI;QACH,IAAIC,IAAID;QACR,OAAO;IACR,EAAE,OAAOE,OAAO;QACf,OAAO;IACR;AACD,EAAE;AAEF,OAAO,MAAMC,mBAA8C,OAAOH;IACjE,IAAI,CAACA,OAAO;QACX,OAAO;IACR;IACA,MAAMI,gBAAgB;IACtB,IAAI,CAACA,cAAcC,IAAI,CAACL,QAAQ;QAC/B,OAAO;IACR;IACA,OAAO;AACR,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainsleydev/payload-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"description": "Payload CMS utilities, collections and global types for ainsley.dev builds",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"@lexical/headless": "0.20.0",
|
|
36
36
|
"@lexical/html": "0.20.0",
|
|
37
37
|
"@nouance/payload-better-fields-plugin": "^1.4.1",
|
|
38
|
-
"@payloadcms/db-sqlite": "3.
|
|
39
|
-
"@payloadcms/richtext-lexical": "3.
|
|
40
|
-
"@payloadcms/plugin-form-builder": "3.
|
|
41
|
-
"@payloadcms/plugin-seo": "3.
|
|
38
|
+
"@payloadcms/db-sqlite": "3.14.0",
|
|
39
|
+
"@payloadcms/richtext-lexical": "3.14.0",
|
|
40
|
+
"@payloadcms/plugin-form-builder": "3.14.0",
|
|
41
|
+
"@payloadcms/plugin-seo": "3.14.0",
|
|
42
42
|
"@types/json-schema": "^7.0.15",
|
|
43
43
|
"chalk": "^5.3.0",
|
|
44
44
|
"commander": "^12.1.0",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"jsdom": "^24.1.1",
|
|
47
47
|
"lexical": "0.20.0",
|
|
48
48
|
"mime-types": "^2.1.35",
|
|
49
|
-
"payload": "3.
|
|
49
|
+
"payload": "3.14.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@ainsleydev/eslint-config": "workspace:*",
|
|
@@ -66,15 +66,5 @@
|
|
|
66
66
|
"engines": {
|
|
67
67
|
"node": ">=18",
|
|
68
68
|
"pnpm": ">=9"
|
|
69
|
-
},
|
|
70
|
-
"pnpm": {
|
|
71
|
-
"overrides": {
|
|
72
|
-
"@lexical/*": "0.20.0",
|
|
73
|
-
"lexical": "0.20.0"
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
"overrides": {
|
|
77
|
-
"@lexical/*": "0.20.0",
|
|
78
|
-
"lexical": "0.20.0"
|
|
79
69
|
}
|
|
80
70
|
}
|