@ainsleydev/payload-helper 0.0.11 → 0.0.12

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.
@@ -194,9 +194,12 @@
194
194
  * Updates the JSON schema so that it doesn't feature oneOf, so Go doesn't
195
195
  * output it as an interface{}.
196
196
  */ ({ jsonSchema })=>{
197
- loopJSONSchemaProperties(jsonSchema, ({ property })=>{
197
+ const updateRelationship = (property)=>{
198
198
  const payload = property.payload;
199
- if (payload && payload.type === 'relationship') {
199
+ if (!payload) {
200
+ return;
201
+ }
202
+ if (payload.type === 'relationship') {
200
203
  if (payload.hasMany) {
201
204
  property.type = 'array';
202
205
  property.items = {
@@ -207,6 +210,18 @@
207
210
  delete property.oneOf;
208
211
  property.$ref = `#/definitions/${property.payload.relationTo}`;
209
212
  }
213
+ const pType = payload.type;
214
+ if (pType === 'group' || pType === 'row' || pType === 'collapsible' || pType === 'array') {
215
+ if (property.properties) {
216
+ for(const k in property.properties){
217
+ updateRelationship(property.properties[k]);
218
+ }
219
+ }
220
+ return;
221
+ }
222
+ };
223
+ loopJSONSchemaProperties(jsonSchema, ({ property })=>{
224
+ updateRelationship(property);
210
225
  });
211
226
  return jsonSchema;
212
227
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugin/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema';\nimport type { Config, Field } from 'payload';\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: Config) => {\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('[]byte', 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\tfield.typescriptSchema = [\n\t\t\t\t\t() => ({ ...addGoJSONSchema('payload.Media', field.required === true) }),\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\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') {\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: 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\t\tdelete jsonSchema.properties.auth;\n\t\tdelete jsonSchema.definitions.media;\n\t\tdelete jsonSchema.properties?.collections?.properties?.media;\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\tloopJSONSchemaProperties(jsonSchema, ({ property }) => {\n\t\t\tconst payload = property.payload;\n\t\t\tif (payload && 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\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","mapper","field","typescriptSchema","blocks","block","fields","map","f","required","tabs","tab","relationTo","name","Array","isArray","push","payload","label","hasMany","collections","collection","globals","global","index","schemas","auth","media","redirects","settings","forms","items","$ref","oneOf","const"],"mappings":"AAGA;;;CAGC,GACD,MAAMA,2BAA2B,CAChCC,YACAC;IAEA,IAAI,CAACD,WAAWE,WAAW,EAAE;QAC5B,OAAOF;IACR;IACAG,OAAOC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IAAI,KAAK,kBAAkBsB,QAAQJ,IAAI,KAAK,QAAQ;gBAC1E,OAAOrB,SAASwC,IAAI;YACrB;QACD;QACA,OAAOlD;IACR;CACA,CAAC"}
1
+ {"version":3,"sources":["../../src/plugin/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema';\nimport type { Config, Field } from 'payload';\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: Config) => {\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('[]byte', 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\tfield.typescriptSchema = [\n\t\t\t\t\t() => ({ ...addGoJSONSchema('payload.Media', field.required === true) }),\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\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') {\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: 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\t\tdelete jsonSchema.properties.auth;\n\t\tdelete jsonSchema.definitions.media;\n\t\tdelete jsonSchema.properties?.collections?.properties?.media;\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","mapper","field","typescriptSchema","blocks","block","fields","map","f","required","tabs","tab","relationTo","name","Array","isArray","push","payload","label","hasMany","collections","collection","globals","global","index","schemas","auth","media","redirects","settings","forms","updateRelationship","items","$ref","oneOf","pType","k","const"],"mappings":"AAGA;;;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;IAC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,EAAEC,GAAG,EAAE;YACtD,MAAMwB,UAAUzB,SAASyB,OAAO;YAChC,IAAIA,WAAWA,QAAQtB,IAAI,KAAK,kBAAkBsB,QAAQJ,IAAI,KAAK,QAAQ;gBAC1E,OAAOrB,SAASyC,IAAI;YACrB;QACD;QACA,OAAOnD;IACR;CACA,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainsleydev/payload-helper",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Payload CMS utilities, collections and global types for ainsley.dev builds",
5
5
  "license": "MIT",
6
6
  "type": "module",