@ainsleydev/payload-helper 0.0.32 → 0.0.33
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/collections/Media.js.map +1 -1
- package/dist/gen/types.js.map +1 -1
- package/dist/globals/Navigation.js +6 -4
- package/dist/globals/Navigation.js.map +1 -1
- package/dist/plugin/hooks.js.map +1 -1
- package/dist/plugin/schema.js +4 -2
- package/dist/plugin/schema.js.map +1 -1
- package/dist/seed/media.js.map +1 -1
- package/dist/seed/seed.js.map +1 -1
- package/dist/util/env.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/Media.ts"],"sourcesContent":["import { lexicalEditor } from '@payloadcms/richtext-lexical';\nimport * as mime from 'mime-types';\nimport type { CollectionConfig, Field, PayloadRequest, UploadConfig } from 'payload';\nimport type { ImageSize } from 'payload';\nimport env from '../util/env.js';\n\nexport interface MediaArgs {\n\tincludeAvif?: boolean;\n\tadditionalFields?: Field[];\n\tuploadOverrides?: Partial<UploadConfig>;\n}\n\nexport const imageSizes: ImageSize[] = [\n\t{\n\t\tname: 'webp',\n\t\twidth: undefined,\n\t\theight: undefined,\n\t\tformatOptions: {\n\t\t\tformat: 'webp',\n\t\t\toptions: {\n\t\t\t\tquality: 80,\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tname: 'thumbnail',\n\t\twidth: 200,\n\t\theight: undefined,\n\t\tposition: 'centre',\n\t},\n\t{\n\t\tname: 'thumbnail_webp',\n\t\twidth: 200,\n\t\theight: undefined,\n\t\tposition: 'centre',\n\t\tformatOptions: {\n\t\t\tformat: 'webp',\n\t\t\toptions: {\n\t\t\t\tquality: 80,\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tname: 'mobile',\n\t\twidth: 500,\n\t\theight: undefined,\n\t},\n\t{\n\t\tname: 'mobile_webp',\n\t\twidth: 500,\n\t\theight: undefined,\n\t\tformatOptions: {\n\t\t\tformat: 'webp',\n\t\t\toptions: {\n\t\t\t\tquality: 80,\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tname: 'tablet',\n\t\twidth: 800,\n\t\theight: undefined,\n\t},\n\t{\n\t\tname: 'tablet_webp',\n\t\twidth: 800,\n\t\theight: undefined,\n\t\tformatOptions: {\n\t\t\tformat: 'webp',\n\t\t\toptions: {\n\t\t\t\tquality: 80,\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tname: 'desktop',\n\t\twidth: 1200,\n\t\theight: undefined,\n\t},\n\t{\n\t\tname: 'desktop_webp',\n\t\twidth: 1200,\n\t\theight: undefined,\n\t\tformatOptions: {\n\t\t\tformat: 'webp',\n\t\t\toptions: {\n\t\t\t\tquality: 80,\n\t\t\t},\n\t\t},\n\t},\n];\n\nexport const imageSizesWithAvif = (): ImageSize[] => {\n\treturn [\n\t\t...imageSizes,\n\t\t{\n\t\t\tname: 'avif',\n\t\t\twidth: undefined,\n\t\t\theight: undefined,\n\t\t\tformatOptions: {\n\t\t\t\tformat: 'avif',\n\t\t\t\toptions: {\n\t\t\t\t\tquality: 60,\n\t\t\t\t\teffort: 1,\n\t\t\t\t\tchromaSubsampling: '4:4:4',\n\t\t\t\t\tbitdepth: 8,\n\t\t\t\t\tlossless: false,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'thumbnail_avif',\n\t\t\twidth: 200,\n\t\t\theight: undefined,\n\t\t\tposition: 'centre',\n\t\t\tformatOptions: {\n\t\t\t\tformat: 'avif',\n\t\t\t\toptions: {\n\t\t\t\t\tquality: 60,\n\t\t\t\t\teffort: 1,\n\t\t\t\t\tchromaSubsampling: '4:4:4',\n\t\t\t\t\tbitdepth: 8,\n\t\t\t\t\tlossless: false,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'mobile_avif',\n\t\t\twidth: 500,\n\t\t\theight: undefined,\n\t\t\tformatOptions: {\n\t\t\t\tformat: 'avif',\n\t\t\t\toptions: {\n\t\t\t\t\tquality: 60,\n\t\t\t\t\teffort: 1,\n\t\t\t\t\tchromaSubsampling: '4:4:4',\n\t\t\t\t\tbitdepth: 8,\n\t\t\t\t\tlossless: false,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'tablet_avif',\n\t\t\twidth: 800,\n\t\t\theight: undefined,\n\t\t\tformatOptions: {\n\t\t\t\tformat: 'avif',\n\t\t\t\toptions: {\n\t\t\t\t\tquality: 60,\n\t\t\t\t\teffort: 1,\n\t\t\t\t\tchromaSubsampling: '4:4:4',\n\t\t\t\t\tbitdepth: 8,\n\t\t\t\t\tlossless: false,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'desktop_avif',\n\t\t\twidth: 1200,\n\t\t\theight: undefined,\n\t\t\tformatOptions: {\n\t\t\t\tformat: 'avif',\n\t\t\t\toptions: {\n\t\t\t\t\tquality: 80,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t];\n};\n\nexport const Media = (args: MediaArgs = {}): CollectionConfig => {\n\tlet sizes = imageSizes;\n\tif (args.includeAvif) {\n\t\tsizes = imageSizesWithAvif();\n\t}\n\n\treturn {\n\t\tslug: 'media',\n\t\taccess: {\n\t\t\tread: () => true,\n\t\t},\n\t\tfields: [\n\t\t\t{\n\t\t\t\tname: 'alt',\n\t\t\t\ttype: 'text',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'caption',\n\t\t\t\ttype: 'richText',\n\t\t\t\trequired: false,\n\t\t\t\teditor: lexicalEditor({\n\t\t\t\t\tfeatures: ({ defaultFeatures }) => {\n\t\t\t\t\t\treturn defaultFeatures.filter((feature) => {\n\t\t\t\t\t\t\treturn feature.key === 'paragraph' || feature.key === 'link';\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t},\n\t\t\t...(args.additionalFields ? args.additionalFields : []),\n\t\t],\n\t\tupload: {\n\t\t\tstaticDir: 'media',\n\t\t\tadminThumbnail: 'tablet',\n\t\t\tdisableLocalStorage: env.isProduction,\n\t\t\thandlers: [\n\t\t\t\tasync (req: PayloadRequest, args) => {\n\t\t\t\t\tconst logger = req.payload.logger;\n\t\t\t\t\tconst { params } = args;\n\t\t\t\t\tconst { collection, filename } = params;\n\n\t\t\t\t\tif (collection !== 'media') {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst contentType = mime.lookup(filename);\n\t\t\t\t\tif (!contentType) {\n\t\t\t\t\t\tlogger.error(`Unable to find mime type for file: ${filename}`);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst headers = new Headers();\n\t\t\t\t\theaders.set('Content-Type', contentType);\n\t\t\t\t\theaders.set('Cache-Control', 'public, max-age=31536000');\n\n\t\t\t\t\treq.responseHeaders = headers;\n\t\t\t\t},\n\t\t\t],\n\t\t\timageSizes: sizes,\n\t\t\t...(args.uploadOverrides ? args.uploadOverrides : {}),\n\t\t},\n\t};\n};\n"],"names":["lexicalEditor","mime","env","imageSizes","name","width","undefined","height","formatOptions","format","options","quality","position","imageSizesWithAvif","effort","chromaSubsampling","bitdepth","lossless","Media","args","sizes","includeAvif","slug","access","read","fields","type","required","editor","features","defaultFeatures","filter","feature","key","additionalFields","upload","staticDir","adminThumbnail","disableLocalStorage","isProduction","handlers","req","logger","payload","params","collection","filename","contentType","lookup","error","headers","Headers","set","responseHeaders","uploadOverrides"],"mappings":"AAAA,SAASA,aAAa,QAAQ,+BAA+B;AAC7D,YAAYC,UAAU,aAAa;AAGnC,OAAOC,SAAS,iBAAiB;AAQjC,OAAO,MAAMC,aAA0B;IACtC;QACCC,MAAM;QACNC,OAAOC;QACPC,QAAQD;QACRE,eAAe;YACdC,QAAQ;YACRC,SAAS;gBACRC,SAAS;YACV;QACD;IACD;IACA;QACCP,MAAM;QACNC,OAAO;QACPE,QAAQD;QACRM,UAAU;IACX;IACA;QACCR,MAAM;QACNC,OAAO;QACPE,QAAQD;QACRM,UAAU;QACVJ,eAAe;YACdC,QAAQ;YACRC,SAAS;gBACRC,SAAS;YACV;QACD;IACD;IACA;QACCP,MAAM;QACNC,OAAO;QACPE,QAAQD;IACT;IACA;QACCF,MAAM;QACNC,OAAO;QACPE,QAAQD;QACRE,eAAe;YACdC,QAAQ;YACRC,SAAS;gBACRC,SAAS;YACV;QACD;IACD;IACA;QACCP,MAAM;QACNC,OAAO;QACPE,QAAQD;IACT;IACA;QACCF,MAAM;QACNC,OAAO;QACPE,QAAQD;QACRE,eAAe;YACdC,QAAQ;YACRC,SAAS;gBACRC,SAAS;YACV;QACD;IACD;IACA;QACCP,MAAM;QACNC,OAAO;QACPE,QAAQD;IACT;IACA;QACCF,MAAM;QACNC,OAAO;QACPE,QAAQD;QACRE,eAAe;YACdC,QAAQ;YACRC,SAAS;gBACRC,SAAS;YACV;QACD;IACD;CACA,CAAC;AAEF,OAAO,MAAME,qBAAqB;IACjC,OAAO;WACHV;QACH;YACCC,MAAM;YACNC,OAAOC;YACPC,QAAQD;YACRE,eAAe;gBACdC,QAAQ;gBACRC,SAAS;oBACRC,SAAS;oBACTG,QAAQ;oBACRC,mBAAmB;oBACnBC,UAAU;oBACVC,UAAU;gBACX;YACD;QACD;QACA;YACCb,MAAM;YACNC,OAAO;YACPE,QAAQD;YACRM,UAAU;YACVJ,eAAe;gBACdC,QAAQ;gBACRC,SAAS;oBACRC,SAAS;oBACTG,QAAQ;oBACRC,mBAAmB;oBACnBC,UAAU;oBACVC,UAAU;gBACX;YACD;QACD;QACA;YACCb,MAAM;YACNC,OAAO;YACPE,QAAQD;YACRE,eAAe;gBACdC,QAAQ;gBACRC,SAAS;oBACRC,SAAS;oBACTG,QAAQ;oBACRC,mBAAmB;oBACnBC,UAAU;oBACVC,UAAU;gBACX;YACD;QACD;QACA;YACCb,MAAM;YACNC,OAAO;YACPE,QAAQD;YACRE,eAAe;gBACdC,QAAQ;gBACRC,SAAS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import { lexicalEditor } from '@payloadcms/richtext-lexical';\nimport * as mime from 'mime-types';\nimport type { CollectionConfig, Field, PayloadRequest, UploadConfig } from 'payload';\nimport type { ImageSize } from 'payload';\nimport env from '../util/env.js';\n\nexport interface MediaArgs {\n\tincludeAvif?: boolean;\n\tadditionalFields?: Field[];\n\tuploadOverrides?: Partial<UploadConfig>;\n}\n\nexport const imageSizes: ImageSize[] = [\n\t{\n\t\tname: 'webp',\n\t\twidth: undefined,\n\t\theight: undefined,\n\t\tformatOptions: {\n\t\t\tformat: 'webp',\n\t\t\toptions: {\n\t\t\t\tquality: 80,\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tname: 'thumbnail',\n\t\twidth: 200,\n\t\theight: undefined,\n\t\tposition: 'centre',\n\t},\n\t{\n\t\tname: 'thumbnail_webp',\n\t\twidth: 200,\n\t\theight: undefined,\n\t\tposition: 'centre',\n\t\tformatOptions: {\n\t\t\tformat: 'webp',\n\t\t\toptions: {\n\t\t\t\tquality: 80,\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tname: 'mobile',\n\t\twidth: 500,\n\t\theight: undefined,\n\t},\n\t{\n\t\tname: 'mobile_webp',\n\t\twidth: 500,\n\t\theight: undefined,\n\t\tformatOptions: {\n\t\t\tformat: 'webp',\n\t\t\toptions: {\n\t\t\t\tquality: 80,\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tname: 'tablet',\n\t\twidth: 800,\n\t\theight: undefined,\n\t},\n\t{\n\t\tname: 'tablet_webp',\n\t\twidth: 800,\n\t\theight: undefined,\n\t\tformatOptions: {\n\t\t\tformat: 'webp',\n\t\t\toptions: {\n\t\t\t\tquality: 80,\n\t\t\t},\n\t\t},\n\t},\n\t{\n\t\tname: 'desktop',\n\t\twidth: 1200,\n\t\theight: undefined,\n\t},\n\t{\n\t\tname: 'desktop_webp',\n\t\twidth: 1200,\n\t\theight: undefined,\n\t\tformatOptions: {\n\t\t\tformat: 'webp',\n\t\t\toptions: {\n\t\t\t\tquality: 80,\n\t\t\t},\n\t\t},\n\t},\n];\n\nexport const imageSizesWithAvif = (): ImageSize[] => {\n\treturn [\n\t\t...imageSizes,\n\t\t{\n\t\t\tname: 'avif',\n\t\t\twidth: undefined,\n\t\t\theight: undefined,\n\t\t\tformatOptions: {\n\t\t\t\tformat: 'avif',\n\t\t\t\toptions: {\n\t\t\t\t\tquality: 60,\n\t\t\t\t\teffort: 1,\n\t\t\t\t\tchromaSubsampling: '4:4:4',\n\t\t\t\t\tbitdepth: 8,\n\t\t\t\t\tlossless: false,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'thumbnail_avif',\n\t\t\twidth: 200,\n\t\t\theight: undefined,\n\t\t\tposition: 'centre',\n\t\t\tformatOptions: {\n\t\t\t\tformat: 'avif',\n\t\t\t\toptions: {\n\t\t\t\t\tquality: 60,\n\t\t\t\t\teffort: 1,\n\t\t\t\t\tchromaSubsampling: '4:4:4',\n\t\t\t\t\tbitdepth: 8,\n\t\t\t\t\tlossless: false,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'mobile_avif',\n\t\t\twidth: 500,\n\t\t\theight: undefined,\n\t\t\tformatOptions: {\n\t\t\t\tformat: 'avif',\n\t\t\t\toptions: {\n\t\t\t\t\tquality: 60,\n\t\t\t\t\teffort: 1,\n\t\t\t\t\tchromaSubsampling: '4:4:4',\n\t\t\t\t\tbitdepth: 8,\n\t\t\t\t\tlossless: false,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'tablet_avif',\n\t\t\twidth: 800,\n\t\t\theight: undefined,\n\t\t\tformatOptions: {\n\t\t\t\tformat: 'avif',\n\t\t\t\toptions: {\n\t\t\t\t\tquality: 60,\n\t\t\t\t\teffort: 1,\n\t\t\t\t\tchromaSubsampling: '4:4:4',\n\t\t\t\t\tbitdepth: 8,\n\t\t\t\t\tlossless: false,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\tname: 'desktop_avif',\n\t\t\twidth: 1200,\n\t\t\theight: undefined,\n\t\t\tformatOptions: {\n\t\t\t\tformat: 'avif',\n\t\t\t\toptions: {\n\t\t\t\t\tquality: 80,\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t];\n};\n\nexport const Media = (args: MediaArgs = {}): CollectionConfig => {\n\tlet sizes = imageSizes;\n\tif (args.includeAvif) {\n\t\tsizes = imageSizesWithAvif();\n\t}\n\n\treturn {\n\t\tslug: 'media',\n\t\taccess: {\n\t\t\tread: () => true,\n\t\t},\n\t\tfields: [\n\t\t\t{\n\t\t\t\tname: 'alt',\n\t\t\t\ttype: 'text',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'caption',\n\t\t\t\ttype: 'richText',\n\t\t\t\trequired: false,\n\t\t\t\teditor: lexicalEditor({\n\t\t\t\t\tfeatures: ({ defaultFeatures }) => {\n\t\t\t\t\t\treturn defaultFeatures.filter((feature) => {\n\t\t\t\t\t\t\treturn feature.key === 'paragraph' || feature.key === 'link';\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t},\n\t\t\t...(args.additionalFields ? args.additionalFields : []),\n\t\t],\n\t\tupload: {\n\t\t\tstaticDir: 'media',\n\t\t\tadminThumbnail: 'tablet',\n\t\t\tdisableLocalStorage: env.isProduction,\n\t\t\thandlers: [\n\t\t\t\tasync (req: PayloadRequest, args) => {\n\t\t\t\t\tconst logger = req.payload.logger;\n\t\t\t\t\tconst { params } = args;\n\t\t\t\t\tconst { collection, filename } = params;\n\n\t\t\t\t\tif (collection !== 'media') {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst contentType = mime.lookup(filename);\n\t\t\t\t\tif (!contentType) {\n\t\t\t\t\t\tlogger.error(`Unable to find mime type for file: ${filename}`);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst headers = new Headers();\n\t\t\t\t\theaders.set('Content-Type', contentType);\n\t\t\t\t\theaders.set('Cache-Control', 'public, max-age=31536000');\n\n\t\t\t\t\treq.responseHeaders = headers;\n\t\t\t\t},\n\t\t\t],\n\t\t\timageSizes: sizes,\n\t\t\t...(args.uploadOverrides ? args.uploadOverrides : {}),\n\t\t},\n\t};\n};\n"],"names":["lexicalEditor","mime","env","imageSizes","name","width","undefined","height","formatOptions","format","options","quality","position","imageSizesWithAvif","effort","chromaSubsampling","bitdepth","lossless","Media","args","sizes","includeAvif","slug","access","read","fields","type","required","editor","features","defaultFeatures","filter","feature","key","additionalFields","upload","staticDir","adminThumbnail","disableLocalStorage","isProduction","handlers","req","logger","payload","params","collection","filename","contentType","lookup","error","headers","Headers","set","responseHeaders","uploadOverrides"],"mappings":"AAAA,SAASA,aAAa,QAAQ,+BAA+B;AAC7D,YAAYC,UAAU,aAAa;AAGnC,OAAOC,SAAS,iBAAiB;AAQjC,OAAO,MAAMC,aAA0B;IACtC;QACCC,MAAM;QACNC,OAAOC;QACPC,QAAQD;QACRE,eAAe;YACdC,QAAQ;YACRC,SAAS;gBACRC,SAAS;YACV;QACD;IACD;IACA;QACCP,MAAM;QACNC,OAAO;QACPE,QAAQD;QACRM,UAAU;IACX;IACA;QACCR,MAAM;QACNC,OAAO;QACPE,QAAQD;QACRM,UAAU;QACVJ,eAAe;YACdC,QAAQ;YACRC,SAAS;gBACRC,SAAS;YACV;QACD;IACD;IACA;QACCP,MAAM;QACNC,OAAO;QACPE,QAAQD;IACT;IACA;QACCF,MAAM;QACNC,OAAO;QACPE,QAAQD;QACRE,eAAe;YACdC,QAAQ;YACRC,SAAS;gBACRC,SAAS;YACV;QACD;IACD;IACA;QACCP,MAAM;QACNC,OAAO;QACPE,QAAQD;IACT;IACA;QACCF,MAAM;QACNC,OAAO;QACPE,QAAQD;QACRE,eAAe;YACdC,QAAQ;YACRC,SAAS;gBACRC,SAAS;YACV;QACD;IACD;IACA;QACCP,MAAM;QACNC,OAAO;QACPE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AAU;YACX;YACA;gBACCvB,MAAM;gBACNsB,MAAM;gBACNC,UAAU;gBACVC,QAAQ5B,cAAc;oBACrB6B,UAAU,CAAC,EAAEC,eAAe,EAAE;wBAC7B,OAAOA,gBAAgBC,MAAM,CAAC,CAACC;4BAC9B,OAAOA,QAAQC,GAAG,KAAK,eAAeD,QAAQC,GAAG,KAAK;wBACvD;oBACD;gBACD;YACD;eACId,KAAKe,gBAAgB,GAAGf,KAAKe,gBAAgB,GAAG,EAAE;SACtD;QACDC,QAAQ;YACPC,WAAW;YACXC,gBAAgB;YAChBC,qBAAqBpC,IAAIqC,YAAY;YACrCC,UAAU;gBACT,OAAOC,KAAqBtB;oBAC3B,MAAMuB,SAASD,IAAIE,OAAO,CAACD,MAAM;oBACjC,MAAM,EAAEE,MAAM,EAAE,GAAGzB;oBACnB,MAAM,EAAE0B,UAAU,EAAEC,QAAQ,EAAE,GAAGF;oBAEjC,IAAIC,eAAe,SAAS;wBAC3B;oBACD;oBAEA,MAAME,cAAc9C,KAAK+C,MAAM,CAACF;oBAChC,IAAI,CAACC,aAAa;wBACjBL,OAAOO,KAAK,CAAC,CAAC,mCAAmC,EAAEH,UAAU;wBAC7D;oBACD;oBAEA,MAAMI,UAAU,IAAIC;oBACpBD,QAAQE,GAAG,CAAC,gBAAgBL;oBAC5BG,QAAQE,GAAG,CAAC,iBAAiB;oBAE7BX,IAAIY,eAAe,GAAGH;gBACvB;aACA;YACD/C,YAAYiB;YACZ,GAAID,KAAKmC,eAAe,GAAGnC,KAAKmC,eAAe,GAAG,CAAC,CAAC;QACrD;IACD;AACD,EAAE"}
|
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: [...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,
|
|
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"}
|
|
@@ -72,11 +72,12 @@
|
|
|
72
72
|
const tabs = [
|
|
73
73
|
{
|
|
74
74
|
label: 'Header',
|
|
75
|
+
name: 'header',
|
|
75
76
|
fields: [
|
|
76
77
|
{
|
|
77
|
-
name: '
|
|
78
|
-
type: 'array',
|
|
78
|
+
name: 'items',
|
|
79
79
|
label: 'Items',
|
|
80
|
+
type: 'array',
|
|
80
81
|
interfaceName: 'NavigationHeaderLinks',
|
|
81
82
|
maxRows: 8,
|
|
82
83
|
labels: {
|
|
@@ -99,11 +100,12 @@
|
|
|
99
100
|
if (config?.includeFooter) {
|
|
100
101
|
tabs.push({
|
|
101
102
|
label: 'Footer',
|
|
103
|
+
name: 'footer',
|
|
102
104
|
fields: [
|
|
103
105
|
{
|
|
104
|
-
name: '
|
|
105
|
-
type: 'array',
|
|
106
|
+
name: 'items',
|
|
106
107
|
label: 'Items',
|
|
108
|
+
type: 'array',
|
|
107
109
|
interfaceName: 'NavigationFooterLinks',
|
|
108
110
|
maxRows: 8,
|
|
109
111
|
labels: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/globals/Navigation.ts"],"sourcesContent":["import type { ArrayField, Field, GlobalConfig, Tab } from 'payload';\n\n/**\n * Navigation Configuration for the header and footer\n * nav links.\n */\ninterface NavigationConfig {\n\tincludeFooter?: boolean;\n\theader?: NavigationMenuConfig;\n\tfooter?: NavigationMenuConfig;\n\tadditionalTabs?: Tab[];\n}\n\n/**\n * Navigation Menu Configuration defines the config for an\n * individual navigation menu, i.e Header or Footer.\n */\ninterface NavigationMenuConfig {\n\tmaxDepth?: number;\n\tadditionalFields?: Field[];\n}\n\n/**\n * Function to generate children structure recursively.\n *\n * @param depth Current depth\n * @param maxDepth Maximum depth to generate children\n * @param fields Fields to include at each level\n */\nconst generateChildren = (depth: number, maxDepth: number, fields: Field[]): Field[] => {\n\tif (depth >= maxDepth) {\n\t\treturn [];\n\t}\n\n\t// Only generate children if depth is less than maxDepth\n\tif (depth < maxDepth - 1) {\n\t\treturn [\n\t\t\t{\n\t\t\t\tname: 'children',\n\t\t\t\ttype: 'array',\n\t\t\t\tlabel: `Children Level ${depth + 1}`,\n\t\t\t\tfields: [...fields, ...generateChildren(depth + 1, maxDepth, fields)],\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [];\n};\n\n/**\n * The default navigation field links.\n */\nconst navFields: Field[] = [\n\t{\n\t\ttype: 'row',\n\t\tfields: [\n\t\t\t{\n\t\t\t\tname: 'label',\n\t\t\t\tlabel: 'Label',\n\t\t\t\ttype: 'text',\n\t\t\t\trequired: true,\n\t\t\t\tadmin: {\n\t\t\t\t\twidth: '50%',\n\t\t\t\t\tdescription: 'Enter the text that will appear as a label for the link.',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'url',\n\t\t\t\tlabel: 'URL',\n\t\t\t\ttype: 'text',\n\t\t\t\trequired: true,\n\t\t\t\tadmin: {\n\t\t\t\t\twidth: '50%',\n\t\t\t\t\tdescription: 'Enter a URL where the link will direct too.',\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tname: 'newTab',\n\t\tlabel: 'Open in a new tab?',\n\t\ttype: 'checkbox',\n\t\tdefaultValue: false,\n\t\tadmin: {\n\t\t\tdescription: 'Check this box if you would like the link to open in a new tab.',\n\t\t},\n\t},\n];\n\n/**\n * Navigation Global Configuration\n * Additional fields will be appended to each navigation item.\n *\n * @constructor\n * @param config\n */\nexport const Navigation = (config?: NavigationConfig): GlobalConfig => {\n\tconst tabs: Tab[] = [\n\t\t{\n\t\t\tlabel: 'Header',\n\t\t\tfields: [\n\t\t\t\t{\n\t\t\t\t\tname: '
|
|
1
|
+
{"version":3,"sources":["../../src/globals/Navigation.ts"],"sourcesContent":["import type { ArrayField, Field, GlobalConfig, Tab } from 'payload';\n\n/**\n * Navigation Configuration for the header and footer\n * nav links.\n */\ninterface NavigationConfig {\n\tincludeFooter?: boolean;\n\theader?: NavigationMenuConfig;\n\tfooter?: NavigationMenuConfig;\n\tadditionalTabs?: Tab[];\n}\n\n/**\n * Navigation Menu Configuration defines the config for an\n * individual navigation menu, i.e Header or Footer.\n */\ninterface NavigationMenuConfig {\n\tmaxDepth?: number;\n\tadditionalFields?: Field[];\n}\n\n/**\n * Function to generate children structure recursively.\n *\n * @param depth Current depth\n * @param maxDepth Maximum depth to generate children\n * @param fields Fields to include at each level\n */\nconst generateChildren = (depth: number, maxDepth: number, fields: Field[]): Field[] => {\n\tif (depth >= maxDepth) {\n\t\treturn [];\n\t}\n\n\t// Only generate children if depth is less than maxDepth\n\tif (depth < maxDepth - 1) {\n\t\treturn [\n\t\t\t{\n\t\t\t\tname: 'children',\n\t\t\t\ttype: 'array',\n\t\t\t\tlabel: `Children Level ${depth + 1}`,\n\t\t\t\tfields: [...fields, ...generateChildren(depth + 1, maxDepth, fields)],\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [];\n};\n\n/**\n * The default navigation field links.\n */\nconst navFields: Field[] = [\n\t{\n\t\ttype: 'row',\n\t\tfields: [\n\t\t\t{\n\t\t\t\tname: 'label',\n\t\t\t\tlabel: 'Label',\n\t\t\t\ttype: 'text',\n\t\t\t\trequired: true,\n\t\t\t\tadmin: {\n\t\t\t\t\twidth: '50%',\n\t\t\t\t\tdescription: 'Enter the text that will appear as a label for the link.',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tname: 'url',\n\t\t\t\tlabel: 'URL',\n\t\t\t\ttype: 'text',\n\t\t\t\trequired: true,\n\t\t\t\tadmin: {\n\t\t\t\t\twidth: '50%',\n\t\t\t\t\tdescription: 'Enter a URL where the link will direct too.',\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t},\n\t{\n\t\tname: 'newTab',\n\t\tlabel: 'Open in a new tab?',\n\t\ttype: 'checkbox',\n\t\tdefaultValue: false,\n\t\tadmin: {\n\t\t\tdescription: 'Check this box if you would like the link to open in a new tab.',\n\t\t},\n\t},\n];\n\n/**\n * Navigation Global Configuration\n * Additional fields will be appended to each navigation item.\n *\n * @constructor\n * @param config\n */\nexport const Navigation = (config?: NavigationConfig): GlobalConfig => {\n\tconst tabs: Tab[] = [\n\t\t{\n\t\t\tlabel: 'Header',\n\t\t\tname: 'header',\n\t\t\tfields: [\n\t\t\t\t{\n\t\t\t\t\tname: 'items',\n\t\t\t\t\tlabel: 'Items',\n\t\t\t\t\ttype: 'array',\n\t\t\t\t\tinterfaceName: 'NavigationHeaderLinks',\n\t\t\t\t\tmaxRows: 8,\n\t\t\t\t\tlabels: {\n\t\t\t\t\t\tsingular: 'Link',\n\t\t\t\t\t\tplural: 'Links',\n\t\t\t\t\t},\n\t\t\t\t\tadmin: {\n\t\t\t\t\t\tinitCollapsed: true,\n\t\t\t\t\t\tisSortable: true,\n\t\t\t\t\t},\n\t\t\t\t\tfields: [\n\t\t\t\t\t\t...navFields,\n\t\t\t\t\t\t...(config?.header?.maxDepth\n\t\t\t\t\t\t\t? generateChildren(0, config.header.maxDepth, navFields)\n\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t...(config?.header?.additionalFields ? config.header.additionalFields : []),\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t} as ArrayField,\n\t];\n\n\tif (config?.includeFooter) {\n\t\ttabs.push({\n\t\t\tlabel: 'Footer',\n\t\t\tname: 'footer',\n\t\t\tfields: [\n\t\t\t\t{\n\t\t\t\t\tname: 'items',\n\t\t\t\t\tlabel: 'Items',\n\t\t\t\t\ttype: 'array',\n\t\t\t\t\tinterfaceName: 'NavigationFooterLinks',\n\t\t\t\t\tmaxRows: 8,\n\t\t\t\t\tlabels: {\n\t\t\t\t\t\tsingular: 'Link',\n\t\t\t\t\t\tplural: 'Links',\n\t\t\t\t\t},\n\t\t\t\t\tadmin: {\n\t\t\t\t\t\tinitCollapsed: true,\n\t\t\t\t\t\tisSortable: true,\n\t\t\t\t\t},\n\t\t\t\t\tfields: [\n\t\t\t\t\t\t...navFields,\n\t\t\t\t\t\t...(config?.footer?.maxDepth\n\t\t\t\t\t\t\t? generateChildren(0, config.footer.maxDepth, navFields)\n\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t...(config?.footer?.additionalFields ? config.footer.additionalFields : []),\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t} as ArrayField);\n\t}\n\n\treturn {\n\t\tslug: 'navigation',\n\t\ttypescript: {\n\t\t\tinterface: 'Navigation',\n\t\t},\n\t\tgraphQL: {\n\t\t\tname: 'Navigation',\n\t\t},\n\t\taccess: {\n\t\t\tread: () => true,\n\t\t},\n\t\tfields: [\n\t\t\t{\n\t\t\t\ttype: 'tabs',\n\t\t\t\ttabs: [...tabs, ...(config?.additionalTabs ? config.additionalTabs : [])],\n\t\t\t},\n\t\t],\n\t};\n};\n"],"names":["generateChildren","depth","maxDepth","fields","name","type","label","navFields","required","admin","width","description","defaultValue","Navigation","config","tabs","interfaceName","maxRows","labels","singular","plural","initCollapsed","isSortable","header","additionalFields","includeFooter","push","footer","slug","typescript","interface","graphQL","access","read","additionalTabs"],"mappings":"AAsBA;;;;;;CAMC,GACD,MAAMA,mBAAmB,CAACC,OAAeC,UAAkBC;IAC1D,IAAIF,SAASC,UAAU;QACtB,OAAO,EAAE;IACV;IAEA,wDAAwD;IACxD,IAAID,QAAQC,WAAW,GAAG;QACzB,OAAO;YACN;gBACCE,MAAM;gBACNC,MAAM;gBACNC,OAAO,CAAC,eAAe,EAAEL,QAAQ,GAAG;gBACpCE,QAAQ;uBAAIA;uBAAWH,iBAAiBC,QAAQ,GAAGC,UAAUC;iBAAQ;YACtE;SACA;IACF;IAEA,OAAO,EAAE;AACV;AAEA;;CAEC,GACD,MAAMI,YAAqB;IAC1B;QACCF,MAAM;QACNF,QAAQ;YACP;gBACCC,MAAM;gBACNE,OAAO;gBACPD,MAAM;gBACNG,UAAU;gBACVC,OAAO;oBACNC,OAAO;oBACPC,aAAa;gBACd;YACD;YACA;gBACCP,MAAM;gBACNE,OAAO;gBACPD,MAAM;gBACNG,UAAU;gBACVC,OAAO;oBACNC,OAAO;oBACPC,aAAa;gBACd;YACD;SACA;IACF;IACA;QACCP,MAAM;QACNE,OAAO;QACPD,MAAM;QACNO,cAAc;QACdH,OAAO;YACNE,aAAa;QACd;IACD;CACA;AAED;;;;;;CAMC,GACD,OAAO,MAAME,aAAa,CAACC;IAC1B,MAAMC,OAAc;QACnB;YACCT,OAAO;YACPF,MAAM;YACND,QAAQ;gBACP;oBACCC,MAAM;oBACNE,OAAO;oBACPD,MAAM;oBACNW,eAAe;oBACfC,SAAS;oBACTC,QAAQ;wBACPC,UAAU;wBACVC,QAAQ;oBACT;oBACAX,OAAO;wBACNY,eAAe;wBACfC,YAAY;oBACb;oBACAnB,QAAQ;2BACJI;2BACCO,QAAQS,QAAQrB,WACjBF,iBAAiB,GAAGc,OAAOS,MAAM,CAACrB,QAAQ,EAAEK,aAC5C,EAAE;2BACDO,QAAQS,QAAQC,mBAAmBV,OAAOS,MAAM,CAACC,gBAAgB,GAAG,EAAE;qBAC1E;gBACF;aACA;QACF;KACA;IAED,IAAIV,QAAQW,eAAe;QAC1BV,KAAKW,IAAI,CAAC;YACTpB,OAAO;YACPF,MAAM;YACND,QAAQ;gBACP;oBACCC,MAAM;oBACNE,OAAO;oBACPD,MAAM;oBACNW,eAAe;oBACfC,SAAS;oBACTC,QAAQ;wBACPC,UAAU;wBACVC,QAAQ;oBACT;oBACAX,OAAO;wBACNY,eAAe;wBACfC,YAAY;oBACb;oBACAnB,QAAQ;2BACJI;2BACCO,QAAQa,QAAQzB,WACjBF,iBAAiB,GAAGc,OAAOa,MAAM,CAACzB,QAAQ,EAAEK,aAC5C,EAAE;2BACDO,QAAQa,QAAQH,mBAAmBV,OAAOa,MAAM,CAACH,gBAAgB,GAAG,EAAE;qBAC1E;gBACF;aACA;QACF;IACD;IAEA,OAAO;QACNI,MAAM;QACNC,YAAY;YACXC,WAAW;QACZ;QACAC,SAAS;YACR3B,MAAM;QACP;QACA4B,QAAQ;YACPC,MAAM,IAAM;QACb;QACA9B,QAAQ;YACP;gBACCE,MAAM;gBACNU,MAAM;uBAAIA;uBAAUD,QAAQoB,iBAAiBpB,OAAOoB,cAAc,GAAG,EAAE;iBAAE;YAC1E;SACA;IACF;AACD,EAAE"}
|
package/dist/plugin/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugin/hooks.ts"],"sourcesContent":["import type { Field, Payload } from 'payload';\nimport type { CollectionAfterChangeHook, GlobalAfterChangeHook } from 'payload';\nimport type { WebServerConfig } from '../types.js';\n\n/**\n * TODO\n */\nexport type CacheBustConfig = {\n\tserver?: WebServerConfig;\n\tslug: string;\n\tfields: Field[];\n\tisCollection: boolean;\n};\n\n/**\n * Cache hook is responsible for notifying the web server of changes\n * on Collections or Globals as defined by the endpoint.\n */\nconst cacheBust = async (\n\tconfig: CacheBustConfig,\n\tpayload: Payload,\n\tdoc: unknown,\n\tpreviousDoc: unknown,\n) => {\n\tconst logger = payload.logger;\n\n\tconst endpoint =\n\t\tnew URL(config?.server?.cacheEndpoint ?? '', config?.server?.baseURL ?? '').href ?? '';\n\n\ttry {\n\t\tconst response = await fetch(endpoint, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tslug: config.slug,\n\t\t\t\tfields: config.fields,\n\t\t\t\ttype: config.isCollection ? 'collection' : 'global',\n\t\t\t\tdoc: doc,\n\t\t\t\tprevDoc: previousDoc,\n\t\t\t}),\n\t\t});\n\t\tlogger.info(`Webhook response status: ${response.status}`);\n\t} catch (err) {\n\t\tlogger.error(`Webhook error ${err}`);\n\t}\n};\n\nexport const cacheHookCollections = (config: CacheBustConfig): CollectionAfterChangeHook => {\n\treturn async ({ req, doc, previousDoc, operation }) => {\n\t\tif (operation !== 'update') {\n\t\t\treturn;\n\t\t}\n\t\tawait cacheBust(config, req.payload, doc, previousDoc);\n\t};\n};\n\nexport const cacheHookGlobals = (config: CacheBustConfig): GlobalAfterChangeHook => {\n\treturn async ({ req, doc, previousDoc }) => {\n\t\tawait cacheBust(config, req.payload, doc, previousDoc);\n\t};\n};\n"],"names":["cacheBust","config","payload","doc","previousDoc","logger","endpoint","URL","server","cacheEndpoint","baseURL","href","response","fetch","method","headers","body","JSON","stringify","slug","fields","type","isCollection","prevDoc","info","status","err","error","cacheHookCollections","req","operation","cacheHookGlobals"],"mappings":"AAcA;;;CAGC,GACD,MAAMA,YAAY,OACjBC,QACAC,SACAC,KACAC;IAEA,MAAMC,SAASH,QAAQG,MAAM;IAE7B,MAAMC,WACL,IAAIC,IAAIN,QAAQO,QAAQC,iBAAiB,IAAIR,QAAQO,QAAQE,WAAW,IAAIC,IAAI,IAAI;IAErF,IAAI;QACH,MAAMC,WAAW,MAAMC,MAAMP,UAAU;YACtCQ,QAAQ;YACRC,SAAS;gBACR,gBAAgB;YACjB;YACAC,MAAMC,KAAKC,SAAS,CAAC;gBACpBC,MAAMlB,OAAOkB,IAAI;gBACjBC,QAAQnB,OAAOmB,MAAM;gBACrBC,MAAMpB,OAAOqB,YAAY,GAAG,eAAe;gBAC3CnB,KAAKA;gBACLoB,SAASnB;YACV;QACD;QACAC,OAAOmB,IAAI,CAAC,CAAC,yBAAyB,EAAEZ,SAASa,MAAM,
|
|
1
|
+
{"version":3,"sources":["../../src/plugin/hooks.ts"],"sourcesContent":["import type { Field, Payload } from 'payload';\nimport type { CollectionAfterChangeHook, GlobalAfterChangeHook } from 'payload';\nimport type { WebServerConfig } from '../types.js';\n\n/**\n * TODO\n */\nexport type CacheBustConfig = {\n\tserver?: WebServerConfig;\n\tslug: string;\n\tfields: Field[];\n\tisCollection: boolean;\n};\n\n/**\n * Cache hook is responsible for notifying the web server of changes\n * on Collections or Globals as defined by the endpoint.\n */\nconst cacheBust = async (\n\tconfig: CacheBustConfig,\n\tpayload: Payload,\n\tdoc: unknown,\n\tpreviousDoc: unknown,\n) => {\n\tconst logger = payload.logger;\n\n\tconst endpoint =\n\t\tnew URL(config?.server?.cacheEndpoint ?? '', config?.server?.baseURL ?? '').href ?? '';\n\n\ttry {\n\t\tconst response = await fetch(endpoint, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\tslug: config.slug,\n\t\t\t\tfields: config.fields,\n\t\t\t\ttype: config.isCollection ? 'collection' : 'global',\n\t\t\t\tdoc: doc,\n\t\t\t\tprevDoc: previousDoc,\n\t\t\t}),\n\t\t});\n\t\tlogger.info(`Webhook response status: ${response.status}`);\n\t} catch (err) {\n\t\tlogger.error(`Webhook error ${err}`);\n\t}\n};\n\nexport const cacheHookCollections = (config: CacheBustConfig): CollectionAfterChangeHook => {\n\treturn async ({ req, doc, previousDoc, operation }) => {\n\t\tif (operation !== 'update') {\n\t\t\treturn;\n\t\t}\n\t\tawait cacheBust(config, req.payload, doc, previousDoc);\n\t};\n};\n\nexport const cacheHookGlobals = (config: CacheBustConfig): GlobalAfterChangeHook => {\n\treturn async ({ req, doc, previousDoc }) => {\n\t\tawait cacheBust(config, req.payload, doc, previousDoc);\n\t};\n};\n"],"names":["cacheBust","config","payload","doc","previousDoc","logger","endpoint","URL","server","cacheEndpoint","baseURL","href","response","fetch","method","headers","body","JSON","stringify","slug","fields","type","isCollection","prevDoc","info","status","err","error","cacheHookCollections","req","operation","cacheHookGlobals"],"mappings":"AAcA;;;CAGC,GACD,MAAMA,YAAY,OACjBC,QACAC,SACAC,KACAC;IAEA,MAAMC,SAASH,QAAQG,MAAM;IAE7B,MAAMC,WACL,IAAIC,IAAIN,QAAQO,QAAQC,iBAAiB,IAAIR,QAAQO,QAAQE,WAAW,IAAIC,IAAI,IAAI;IAErF,IAAI;QACH,MAAMC,WAAW,MAAMC,MAAMP,UAAU;YACtCQ,QAAQ;YACRC,SAAS;gBACR,gBAAgB;YACjB;YACAC,MAAMC,KAAKC,SAAS,CAAC;gBACpBC,MAAMlB,OAAOkB,IAAI;gBACjBC,QAAQnB,OAAOmB,MAAM;gBACrBC,MAAMpB,OAAOqB,YAAY,GAAG,eAAe;gBAC3CnB,KAAKA;gBACLoB,SAASnB;YACV;QACD;QACAC,OAAOmB,IAAI,CAAC,CAAC,yBAAyB,EAAEZ,SAASa,MAAM,EAAE;IAC1D,EAAE,OAAOC,KAAK;QACbrB,OAAOsB,KAAK,CAAC,CAAC,cAAc,EAAED,KAAK;IACpC;AACD;AAEA,OAAO,MAAME,uBAAuB,CAAC3B;IACpC,OAAO,OAAO,EAAE4B,GAAG,EAAE1B,GAAG,EAAEC,WAAW,EAAE0B,SAAS,EAAE;QACjD,IAAIA,cAAc,UAAU;YAC3B;QACD;QACA,MAAM9B,UAAUC,QAAQ4B,IAAI3B,OAAO,EAAEC,KAAKC;IAC3C;AACD,EAAE;AAEF,OAAO,MAAM2B,mBAAmB,CAAC9B;IAChC,OAAO,OAAO,EAAE4B,GAAG,EAAE1B,GAAG,EAAEC,WAAW,EAAE;QACtC,MAAMJ,UAAUC,QAAQ4B,IAAI3B,OAAO,EAAEC,KAAKC;IAC3C;AACD,EAAE"}
|
package/dist/plugin/schema.js
CHANGED
|
@@ -111,7 +111,8 @@
|
|
|
111
111
|
case 'row':
|
|
112
112
|
case 'collapsible':
|
|
113
113
|
{
|
|
114
|
-
|
|
114
|
+
// @ts-ignore
|
|
115
|
+
if (field.type === 'group' && field?.name === 'meta') {
|
|
115
116
|
field.typescriptSchema = [
|
|
116
117
|
()=>({
|
|
117
118
|
...addGoJSONSchema('payload.SettingsMeta', true)
|
|
@@ -129,7 +130,8 @@
|
|
|
129
130
|
if (field.type !== 'tabs' && field.type !== 'row' && field.type !== 'collapsible') {
|
|
130
131
|
field.typescriptSchema.push(({ jsonSchema })=>{
|
|
131
132
|
const payload = {
|
|
132
|
-
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
name: field?.name,
|
|
133
135
|
type: field.type,
|
|
134
136
|
label: field.label
|
|
135
137
|
};
|
|
@@ -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\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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SACT;oBACD,IAAIjD,SAASF,UAAU,EAAE;wBACxB,IAAK,MAAMoD,KAAKlD,SAASF,UAAU,CAAE;4BACpCgD,mBAAmB9C,SAASF,UAAU,CAACoD,EAAE;wBAC1C;oBACD;oBACA;gBACD;YACD;YAEA7D,yBAAyBC,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"}
|
|
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\t// @ts-ignore\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\t// @ts-ignore\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,O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;4BACpCgD,mBAAmB9C,SAASF,UAAU,CAACoD,EAAE;wBAC1C;oBACD;oBACA;gBACD;YACD;YAEA7D,yBAAyBC,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.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 ? 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,
|
|
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"}
|
package/dist/seed/seed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/seed/seed.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport {\n\ttype Payload,\n\ttype PayloadRequest,\n\ttype SanitizedConfig,\n\tcommitTransaction,\n\tgetPayload,\n\tinitTransaction,\n\tkillTransaction,\n} from 'payload';\nimport env from '../util/env.js';\n\nconst filename = fileURLToPath(import.meta.url);\nconst dirname = path.dirname(filename);\n\n/**\n * A function that seeds the database with initial data.\n */\nexport type Seeder = (args: { payload: Payload; req: PayloadRequest }) => Promise<void>;\n\n/**\n * Options for the seed function.\n * Note: You must use path.resolve for the paths, i.e. path.resolve(__dirname, 'path/to/file')\n */\nexport type SeedOptions = {\n\tconfig: SanitizedConfig;\n\tseeder: Seeder;\n};\n\n/**\n * Seeds the database with initial data.\n *\n * @param opts - The options for seeding.\n * @returns A promise that resolves when the seeding is complete.\n */\nexport const seed = (opts: {\n\tseeder: Seeder;\n\tconfig: SanitizedConfig;\n}) => {\n\tconst fn = async () => {\n\t\tprocess.env.PAYLOAD_DROP_DATABASE = 'true';\n\n\t\tconst payload = await getPayload({\n\t\t\tconfig: opts.config,\n\t\t});\n\t\tconst req = { payload } as PayloadRequest;\n\n\t\tawait initTransaction(req);\n\n\t\tdelete process.env.PAYLOAD_DROP_DATABASE;\n\n\t\ttry {\n\t\t\t// Creating new tables\n\t\t\tpayload.logger.info('Creating indexes...');\n\t\t\ttry {\n\t\t\t\tif (payload.db.init) {\n\t\t\t\t\tawait payload.db.init();\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tpayload.logger.error(`Creating database: ${error}`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tpayload.logger.info('Migrating DB...');\n\t\t\tawait payload.db.migrate();\n\n\t\t\t// Clearing local media\n\t\t\tif (!env.isProduction) {\n\t\t\t\tpayload.logger.info('Clearing media...');\n\t\t\t\tconst mediaDir = path.resolve(dirname, '../../media');\n\t\t\t\tif (fs.existsSync(mediaDir)) {\n\t\t\t\t\tfs.rmSync(mediaDir, { recursive: true, force: true });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Run user defined seed script\n\t\t\tawait opts.seeder({ payload, req });\n\n\t\t\tawait commitTransaction(req);\n\n\t\t\tpayload.logger.info('Seed complete');\n\t\t} catch (err) {\n\t\t\tconst message = err instanceof Error ? err.message : 'Unknown error';\n\t\t\tpayload.logger.error(`Seed failed: ${message}`);\n\t\t\tawait killTransaction(req);\n\t\t}\n\t};\n\n\tfn()\n\t\t.then(() => process.exit(0))\n\t\t.catch((e) => {\n\t\t\tconsole.error(e);\n\t\t\tprocess.exit(1);\n\t\t});\n};\n"],"names":["fs","path","fileURLToPath","commitTransaction","getPayload","initTransaction","killTransaction","env","filename","url","dirname","seed","opts","fn","process","PAYLOAD_DROP_DATABASE","payload","config","req","logger","info","db","init","error","migrate","isProduction","mediaDir","resolve","existsSync","rmSync","recursive","force","seeder","err","message","Error","then","exit","catch","e","console"],"mappings":"AAAA,OAAOA,QAAQ,UAAU;AACzB,OAAOC,UAAU,YAAY;AAC7B,SAASC,aAAa,QAAQ,WAAW;AACzC,SAICC,iBAAiB,EACjBC,UAAU,EACVC,eAAe,EACfC,eAAe,QACT,UAAU;AACjB,OAAOC,SAAS,iBAAiB;AAEjC,MAAMC,WAAWN,cAAc,YAAYO,GAAG;AAC9C,MAAMC,UAAUT,KAAKS,OAAO,CAACF;AAgB7B;;;;;CAKC,GACD,OAAO,MAAMG,OAAO,CAACC;IAIpB,MAAMC,KAAK;QACVC,QAAQP,GAAG,CAACQ,qBAAqB,GAAG;QAEpC,MAAMC,UAAU,MAAMZ,WAAW;YAChCa,QAAQL,KAAKK,MAAM;QACpB;QACA,MAAMC,MAAM;YAAEF;QAAQ;QAEtB,MAAMX,gBAAgBa;QAEtB,OAAOJ,QAAQP,GAAG,CAACQ,qBAAqB;QAExC,IAAI;YACH,sBAAsB;YACtBC,QAAQG,MAAM,CAACC,IAAI,CAAC;YACpB,IAAI;gBACH,IAAIJ,QAAQK,EAAE,CAACC,IAAI,EAAE;oBACpB,MAAMN,QAAQK,EAAE,CAACC,IAAI;gBACtB;YACD,EAAE,OAAOC,OAAO;gBACfP,QAAQG,MAAM,CAACI,KAAK,CAAC,CAAC,mBAAmB,EAAEA,
|
|
1
|
+
{"version":3,"sources":["../../src/seed/seed.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport {\n\ttype Payload,\n\ttype PayloadRequest,\n\ttype SanitizedConfig,\n\tcommitTransaction,\n\tgetPayload,\n\tinitTransaction,\n\tkillTransaction,\n} from 'payload';\nimport env from '../util/env.js';\n\nconst filename = fileURLToPath(import.meta.url);\nconst dirname = path.dirname(filename);\n\n/**\n * A function that seeds the database with initial data.\n */\nexport type Seeder = (args: { payload: Payload; req: PayloadRequest }) => Promise<void>;\n\n/**\n * Options for the seed function.\n * Note: You must use path.resolve for the paths, i.e. path.resolve(__dirname, 'path/to/file')\n */\nexport type SeedOptions = {\n\tconfig: SanitizedConfig;\n\tseeder: Seeder;\n};\n\n/**\n * Seeds the database with initial data.\n *\n * @param opts - The options for seeding.\n * @returns A promise that resolves when the seeding is complete.\n */\nexport const seed = (opts: {\n\tseeder: Seeder;\n\tconfig: SanitizedConfig;\n}) => {\n\tconst fn = async () => {\n\t\tprocess.env.PAYLOAD_DROP_DATABASE = 'true';\n\n\t\tconst payload = await getPayload({\n\t\t\tconfig: opts.config,\n\t\t});\n\t\tconst req = { payload } as PayloadRequest;\n\n\t\tawait initTransaction(req);\n\n\t\tdelete process.env.PAYLOAD_DROP_DATABASE;\n\n\t\ttry {\n\t\t\t// Creating new tables\n\t\t\tpayload.logger.info('Creating indexes...');\n\t\t\ttry {\n\t\t\t\tif (payload.db.init) {\n\t\t\t\t\tawait payload.db.init();\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tpayload.logger.error(`Creating database: ${error}`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tpayload.logger.info('Migrating DB...');\n\t\t\tawait payload.db.migrate();\n\n\t\t\t// Clearing local media\n\t\t\tif (!env.isProduction) {\n\t\t\t\tpayload.logger.info('Clearing media...');\n\t\t\t\tconst mediaDir = path.resolve(dirname, '../../media');\n\t\t\t\tif (fs.existsSync(mediaDir)) {\n\t\t\t\t\tfs.rmSync(mediaDir, { recursive: true, force: true });\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Run user defined seed script\n\t\t\tawait opts.seeder({ payload, req });\n\n\t\t\tawait commitTransaction(req);\n\n\t\t\tpayload.logger.info('Seed complete');\n\t\t} catch (err) {\n\t\t\tconst message = err instanceof Error ? err.message : 'Unknown error';\n\t\t\tpayload.logger.error(`Seed failed: ${message}`);\n\t\t\tawait killTransaction(req);\n\t\t}\n\t};\n\n\tfn()\n\t\t.then(() => process.exit(0))\n\t\t.catch((e) => {\n\t\t\tconsole.error(e);\n\t\t\tprocess.exit(1);\n\t\t});\n};\n"],"names":["fs","path","fileURLToPath","commitTransaction","getPayload","initTransaction","killTransaction","env","filename","url","dirname","seed","opts","fn","process","PAYLOAD_DROP_DATABASE","payload","config","req","logger","info","db","init","error","migrate","isProduction","mediaDir","resolve","existsSync","rmSync","recursive","force","seeder","err","message","Error","then","exit","catch","e","console"],"mappings":"AAAA,OAAOA,QAAQ,UAAU;AACzB,OAAOC,UAAU,YAAY;AAC7B,SAASC,aAAa,QAAQ,WAAW;AACzC,SAICC,iBAAiB,EACjBC,UAAU,EACVC,eAAe,EACfC,eAAe,QACT,UAAU;AACjB,OAAOC,SAAS,iBAAiB;AAEjC,MAAMC,WAAWN,cAAc,YAAYO,GAAG;AAC9C,MAAMC,UAAUT,KAAKS,OAAO,CAACF;AAgB7B;;;;;CAKC,GACD,OAAO,MAAMG,OAAO,CAACC;IAIpB,MAAMC,KAAK;QACVC,QAAQP,GAAG,CAACQ,qBAAqB,GAAG;QAEpC,MAAMC,UAAU,MAAMZ,WAAW;YAChCa,QAAQL,KAAKK,MAAM;QACpB;QACA,MAAMC,MAAM;YAAEF;QAAQ;QAEtB,MAAMX,gBAAgBa;QAEtB,OAAOJ,QAAQP,GAAG,CAACQ,qBAAqB;QAExC,IAAI;YACH,sBAAsB;YACtBC,QAAQG,MAAM,CAACC,IAAI,CAAC;YACpB,IAAI;gBACH,IAAIJ,QAAQK,EAAE,CAACC,IAAI,EAAE;oBACpB,MAAMN,QAAQK,EAAE,CAACC,IAAI;gBACtB;YACD,EAAE,OAAOC,OAAO;gBACfP,QAAQG,MAAM,CAACI,KAAK,CAAC,CAAC,mBAAmB,EAAEA,OAAO;gBAClD;YACD;YAEAP,QAAQG,MAAM,CAACC,IAAI,CAAC;YACpB,MAAMJ,QAAQK,EAAE,CAACG,OAAO;YAExB,uBAAuB;YACvB,IAAI,CAACjB,IAAIkB,YAAY,EAAE;gBACtBT,QAAQG,MAAM,CAACC,IAAI,CAAC;gBACpB,MAAMM,WAAWzB,KAAK0B,OAAO,CAACjB,SAAS;gBACvC,IAAIV,GAAG4B,UAAU,CAACF,WAAW;oBAC5B1B,GAAG6B,MAAM,CAACH,UAAU;wBAAEI,WAAW;wBAAMC,OAAO;oBAAK;gBACpD;YACD;YAEA,+BAA+B;YAC/B,MAAMnB,KAAKoB,MAAM,CAAC;gBAAEhB;gBAASE;YAAI;YAEjC,MAAMf,kBAAkBe;YAExBF,QAAQG,MAAM,CAACC,IAAI,CAAC;QACrB,EAAE,OAAOa,KAAK;YACb,MAAMC,UAAUD,eAAeE,QAAQF,IAAIC,OAAO,GAAG;YACrDlB,QAAQG,MAAM,CAACI,KAAK,CAAC,CAAC,aAAa,EAAEW,SAAS;YAC9C,MAAM5B,gBAAgBY;QACvB;IACD;IAEAL,KACEuB,IAAI,CAAC,IAAMtB,QAAQuB,IAAI,CAAC,IACxBC,KAAK,CAAC,CAACC;QACPC,QAAQjB,KAAK,CAACgB;QACdzB,QAAQuB,IAAI,CAAC;IACd;AACF,EAAE"}
|
package/dist/util/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/env.ts"],"sourcesContent":["function hasKey(key: string): boolean {\n\treturn Object.prototype.hasOwnProperty.call(process.env, key);\n}\n\nfunction envFn<T>(key: string, defaultValue: T): string | T {\n\treturn hasKey(key) ? (process.env[key] as string) : defaultValue;\n}\n\nfunction getKey(key: string): string {\n\treturn process.env[key] ?? '';\n}\n\nconst utils = {\n\tisProduction: getKey('NODE_ENV') === 'production',\n\n\tint(key: string, defaultValue?: number): number | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\treturn Number.parseInt(getKey(key), 10);\n\t},\n\n\tfloat(key: string, defaultValue?: number): number | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\treturn Number.parseFloat(getKey(key));\n\t},\n\n\tbool(key: string, defaultValue?: boolean): boolean | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\treturn getKey(key) === 'true';\n\t},\n\n\tjson(key: string, defaultValue?: object) {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\ttry {\n\t\t\treturn JSON.parse(getKey(key));\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\tthrow new Error(`Invalid json environment variable ${key}: ${error.message}`);\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t},\n\n\tarray(key: string, defaultValue?: string[]): string[] | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\tlet value = getKey(key);\n\n\t\tif (value.startsWith('[') && value.endsWith(']')) {\n\t\t\tvalue = value.substring(1, value.length - 1);\n\t\t}\n\n\t\treturn value.split(',').map((v) => {\n\t\t\treturn v.trim().replace(/^\"(.*)\"$/, '$1');\n\t\t});\n\t},\n\n\tdate(key: string, defaultValue?: Date): Date | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\treturn new Date(getKey(key));\n\t},\n\n\toneOf(key: string, expectedValues?: unknown[], defaultValue?: unknown) {\n\t\tif (!expectedValues) {\n\t\t\tthrow new Error('env.oneOf requires expectedValues');\n\t\t}\n\n\t\tif (defaultValue && !expectedValues.includes(defaultValue)) {\n\t\t\tthrow new Error('env.oneOf requires defaultValue to be included in expectedValues');\n\t\t}\n\n\t\tconst rawValue = envFn(key, defaultValue);\n\t\treturn expectedValues.includes(rawValue) ? rawValue : defaultValue;\n\t},\n};\n\nconst env = Object.assign(envFn, utils);\n\nexport default env;\n"],"names":["hasKey","key","Object","prototype","hasOwnProperty","call","process","env","envFn","defaultValue","getKey","utils","isProduction","int","Number","parseInt","float","parseFloat","bool","json","JSON","parse","error","Error","message","array","value","startsWith","endsWith","substring","length","split","map","v","trim","replace","date","Date","oneOf","expectedValues","includes","rawValue","assign"],"mappings":"AAAA,SAASA,OAAOC,GAAW;IAC1B,OAAOC,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACC,QAAQC,GAAG,EAAEN;AAC1D;AAEA,SAASO,MAASP,GAAW,EAAEQ,YAAe;IAC7C,OAAOT,OAAOC,OAAQK,QAAQC,GAAG,CAACN,IAAI,GAAcQ;AACrD;AAEA,SAASC,OAAOT,GAAW;IAC1B,OAAOK,QAAQC,GAAG,CAACN,IAAI,IAAI;AAC5B;AAEA,MAAMU,QAAQ;IACbC,cAAcF,OAAO,gBAAgB;IAErCG,KAAIZ,GAAW,EAAEQ,YAAqB;QACrC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,OAAOK,OAAOC,QAAQ,CAACL,OAAOT,MAAM;IACrC;IAEAe,OAAMf,GAAW,EAAEQ,YAAqB;QACvC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,OAAOK,OAAOG,UAAU,CAACP,OAAOT;IACjC;IAEAiB,MAAKjB,GAAW,EAAEQ,YAAsB;QACvC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,OAAOC,OAAOT,SAAS;IACxB;IAEAkB,MAAKlB,GAAW,EAAEQ,YAAqB;QACtC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,IAAI;YACH,OAAOW,KAAKC,KAAK,CAACX,OAAOT;QAC1B,EAAE,OAAOqB,OAAO;YACf,IAAIA,iBAAiBC,OAAO;gBAC3B,MAAM,IAAIA,MAAM,CAAC,kCAAkC,EAAEtB,IAAI,EAAE,EAAEqB,MAAME,OAAO,
|
|
1
|
+
{"version":3,"sources":["../../src/util/env.ts"],"sourcesContent":["function hasKey(key: string): boolean {\n\treturn Object.prototype.hasOwnProperty.call(process.env, key);\n}\n\nfunction envFn<T>(key: string, defaultValue: T): string | T {\n\treturn hasKey(key) ? (process.env[key] as string) : defaultValue;\n}\n\nfunction getKey(key: string): string {\n\treturn process.env[key] ?? '';\n}\n\nconst utils = {\n\tisProduction: getKey('NODE_ENV') === 'production',\n\n\tint(key: string, defaultValue?: number): number | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\treturn Number.parseInt(getKey(key), 10);\n\t},\n\n\tfloat(key: string, defaultValue?: number): number | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\treturn Number.parseFloat(getKey(key));\n\t},\n\n\tbool(key: string, defaultValue?: boolean): boolean | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\treturn getKey(key) === 'true';\n\t},\n\n\tjson(key: string, defaultValue?: object) {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\ttry {\n\t\t\treturn JSON.parse(getKey(key));\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\tthrow new Error(`Invalid json environment variable ${key}: ${error.message}`);\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t},\n\n\tarray(key: string, defaultValue?: string[]): string[] | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\tlet value = getKey(key);\n\n\t\tif (value.startsWith('[') && value.endsWith(']')) {\n\t\t\tvalue = value.substring(1, value.length - 1);\n\t\t}\n\n\t\treturn value.split(',').map((v) => {\n\t\t\treturn v.trim().replace(/^\"(.*)\"$/, '$1');\n\t\t});\n\t},\n\n\tdate(key: string, defaultValue?: Date): Date | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\treturn new Date(getKey(key));\n\t},\n\n\toneOf(key: string, expectedValues?: unknown[], defaultValue?: unknown) {\n\t\tif (!expectedValues) {\n\t\t\tthrow new Error('env.oneOf requires expectedValues');\n\t\t}\n\n\t\tif (defaultValue && !expectedValues.includes(defaultValue)) {\n\t\t\tthrow new Error('env.oneOf requires defaultValue to be included in expectedValues');\n\t\t}\n\n\t\tconst rawValue = envFn(key, defaultValue);\n\t\treturn expectedValues.includes(rawValue) ? rawValue : defaultValue;\n\t},\n};\n\nconst env = Object.assign(envFn, utils);\n\nexport default env;\n"],"names":["hasKey","key","Object","prototype","hasOwnProperty","call","process","env","envFn","defaultValue","getKey","utils","isProduction","int","Number","parseInt","float","parseFloat","bool","json","JSON","parse","error","Error","message","array","value","startsWith","endsWith","substring","length","split","map","v","trim","replace","date","Date","oneOf","expectedValues","includes","rawValue","assign"],"mappings":"AAAA,SAASA,OAAOC,GAAW;IAC1B,OAAOC,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACC,QAAQC,GAAG,EAAEN;AAC1D;AAEA,SAASO,MAASP,GAAW,EAAEQ,YAAe;IAC7C,OAAOT,OAAOC,OAAQK,QAAQC,GAAG,CAACN,IAAI,GAAcQ;AACrD;AAEA,SAASC,OAAOT,GAAW;IAC1B,OAAOK,QAAQC,GAAG,CAACN,IAAI,IAAI;AAC5B;AAEA,MAAMU,QAAQ;IACbC,cAAcF,OAAO,gBAAgB;IAErCG,KAAIZ,GAAW,EAAEQ,YAAqB;QACrC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,OAAOK,OAAOC,QAAQ,CAACL,OAAOT,MAAM;IACrC;IAEAe,OAAMf,GAAW,EAAEQ,YAAqB;QACvC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,OAAOK,OAAOG,UAAU,CAACP,OAAOT;IACjC;IAEAiB,MAAKjB,GAAW,EAAEQ,YAAsB;QACvC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,OAAOC,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ED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainsleydev/payload-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"description": "Payload CMS utilities, collections and global types for ainsley.dev builds",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"files": ["dist", "bin.js", "types.js", "types.ts", "types.d.ts"],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"payload": "3.
|
|
36
|
-
"@payloadcms/db-sqlite": "3.
|
|
37
|
-
"@payloadcms/richtext-lexical": "3.
|
|
38
|
-
"@payloadcms/plugin-form-builder": "3.
|
|
39
|
-
"@payloadcms/plugin-seo": "3.
|
|
35
|
+
"payload": "3.56.0",
|
|
36
|
+
"@payloadcms/db-sqlite": "3.56.0",
|
|
37
|
+
"@payloadcms/richtext-lexical": "3.56.0",
|
|
38
|
+
"@payloadcms/plugin-form-builder": "3.56.0",
|
|
39
|
+
"@payloadcms/plugin-seo": "3.56.0",
|
|
40
40
|
"@lexical/headless": "0.28.0",
|
|
41
41
|
"@lexical/html": "0.28.0",
|
|
42
42
|
"@nouance/payload-better-fields-plugin": "^1.4.1",
|