@ainsleydev/payload-helper 0.0.23 → 0.0.25
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/cli/bin.js +1 -9
- package/dist/cli/bin.js.map +1 -1
- package/dist/collections/Media.d.ts +10 -6
- package/dist/collections/Media.js +165 -134
- package/dist/collections/Media.js.map +1 -1
- package/dist/gen/types.d.ts +6 -0
- package/dist/{cli → gen}/types.js +9 -18
- package/dist/gen/types.js.map +1 -0
- package/dist/globals/Navigation.js.map +1 -1
- package/dist/globals/Settings.d.ts +1 -1
- package/dist/globals/Settings.js.map +1 -1
- package/dist/index.js +29 -32
- package/dist/index.js.map +1 -1
- package/dist/plugin/hooks.js.map +1 -1
- package/dist/plugin/schema.d.ts +10 -3
- package/dist/plugin/schema.js +106 -93
- package/dist/plugin/schema.js.map +1 -1
- package/dist/seed/media.js.map +1 -1
- package/dist/seed/seed.d.ts +6 -11
- package/dist/seed/seed.js +7 -24
- package/dist/seed/seed.js.map +1 -1
- package/dist/util/env.js.map +1 -1
- package/package.json +20 -10
- package/dist/cli/types.d.ts +0 -4
- package/dist/cli/types.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { cacheHookCollections, cacheHookGlobals } from './plugin/hooks.js';
|
|
2
|
-
import { fieldMapper, schemas } from './plugin/schema.js';
|
|
3
|
-
import env from './util/env.js';
|
|
4
2
|
// export const test = (pluginOptions: PayloadHelperPluginConfig): Plugin[] => {
|
|
5
3
|
// return [
|
|
6
4
|
// seoPlugin({
|
|
@@ -24,52 +22,51 @@ import env from './util/env.js';
|
|
|
24
22
|
* @constructor
|
|
25
23
|
* @param pluginOptions
|
|
26
24
|
*/ export const payloadHelper = (pluginOptions)=>(incomingConfig)=>{
|
|
27
|
-
const genGoLang = env.bool('GEN_GOLANG', false);
|
|
28
|
-
if (genGoLang) {
|
|
29
|
-
incomingConfig.typescript = {
|
|
30
|
-
...incomingConfig.typescript,
|
|
31
|
-
schema: schemas
|
|
32
|
-
};
|
|
33
|
-
// biome-ignore lint/style/noParameterAssign: Need to change field mapper.
|
|
34
|
-
incomingConfig = fieldMapper(incomingConfig);
|
|
35
|
-
}
|
|
36
25
|
// TODO: Validate Config
|
|
37
26
|
// Update typescript generation file
|
|
38
27
|
incomingConfig.typescript = incomingConfig.typescript || {};
|
|
39
28
|
incomingConfig.typescript.outputFile = './src/types/payload.ts';
|
|
40
29
|
// Map collections & add hooks
|
|
41
30
|
incomingConfig.collections = (incomingConfig.collections || []).map((collection)=>{
|
|
42
|
-
if (collection.upload) {
|
|
31
|
+
if (collection.upload !== undefined && collection.upload !== true) {
|
|
43
32
|
return collection;
|
|
44
33
|
}
|
|
34
|
+
const hooks = collection.hooks || {};
|
|
35
|
+
// Add afterChange hook only if webServer is defined
|
|
36
|
+
if (pluginOptions.webServer) {
|
|
37
|
+
hooks.afterChange = [
|
|
38
|
+
...hooks.afterChange || [],
|
|
39
|
+
cacheHookCollections({
|
|
40
|
+
server: pluginOptions.webServer,
|
|
41
|
+
slug: collection.slug,
|
|
42
|
+
fields: collection.fields,
|
|
43
|
+
isCollection: true
|
|
44
|
+
})
|
|
45
|
+
];
|
|
46
|
+
}
|
|
45
47
|
return {
|
|
46
48
|
...collection,
|
|
47
|
-
hooks
|
|
48
|
-
afterChange: [
|
|
49
|
-
cacheHookCollections({
|
|
50
|
-
server: pluginOptions.webServer,
|
|
51
|
-
slug: collection.slug,
|
|
52
|
-
fields: collection.fields,
|
|
53
|
-
isCollection: true
|
|
54
|
-
})
|
|
55
|
-
]
|
|
56
|
-
}
|
|
49
|
+
hooks
|
|
57
50
|
};
|
|
58
51
|
});
|
|
59
52
|
// Map globals & add hooks
|
|
60
53
|
incomingConfig.globals = (incomingConfig.globals || []).map((global)=>{
|
|
54
|
+
const hooks = global.hooks || {};
|
|
55
|
+
// Add afterChange hook only if webServer is defined
|
|
56
|
+
if (pluginOptions.webServer) {
|
|
57
|
+
hooks.afterChange = [
|
|
58
|
+
...hooks.afterChange || [],
|
|
59
|
+
cacheHookGlobals({
|
|
60
|
+
server: pluginOptions.webServer,
|
|
61
|
+
slug: global.slug,
|
|
62
|
+
fields: global.fields,
|
|
63
|
+
isCollection: true
|
|
64
|
+
})
|
|
65
|
+
];
|
|
66
|
+
}
|
|
61
67
|
return {
|
|
62
68
|
...global,
|
|
63
|
-
hooks
|
|
64
|
-
afterChange: [
|
|
65
|
-
cacheHookGlobals({
|
|
66
|
-
server: pluginOptions.webServer,
|
|
67
|
-
slug: global.slug,
|
|
68
|
-
fields: global.fields,
|
|
69
|
-
isCollection: true
|
|
70
|
-
})
|
|
71
|
-
]
|
|
72
|
-
}
|
|
69
|
+
hooks
|
|
73
70
|
};
|
|
74
71
|
});
|
|
75
72
|
return incomingConfig;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionConfig, Config } from 'payload';\nimport { cacheHookCollections, cacheHookGlobals } from './plugin/hooks.js';\nimport { fieldMapper, schemas } from './plugin/schema.js';\nimport type { PayloadHelperPluginConfig } from './types.js';\nimport env from './util/env.js';\n\n// export const test = (pluginOptions: PayloadHelperPluginConfig): Plugin[] => {\n// \treturn [\n// \t\tseoPlugin({\n// \t\t\tcollections: pluginOptions?.seo?.collections,\n// \t\t\tglobals: pluginOptions?.seo?.globals,\n// \t\t\tfields: [...SEOFields, pluginOptions.seo?.fields],\n// \t\t\ttabbedUI: true,\n// \t\t\tuploadsCollection: 'media',\n// \t\t\tgenerateTitle: pluginOptions?.seo?.generateTitle ?\n// \t\t\t\tpluginOptions?.seo?.generateTitle :\n// \t\t\t\t({ doc }) => `${pluginOptions.siteName} — ${doc?.title?.value ?? ''}`,\n// \t\t\tgenerateDescription: pluginOptions?.seo?.generateDescription ?\n// \t\t\t\tpluginOptions?.seo?.generateDescription :\n// \t\t\t\t({ doc }) => doc?.excerpt?.value,\n// \t\t}),\n// \t];\n// };\n\n/**\n * Payload Helper Plugin for websites at ainsley.dev\n *\n * @constructor\n * @param pluginOptions\n */\nexport const payloadHelper =\n\t(pluginOptions: PayloadHelperPluginConfig) =>\n\t(incomingConfig: Config): Config => {\n\t\
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionConfig, Config } from 'payload';\nimport { cacheHookCollections, cacheHookGlobals } from './plugin/hooks.js';\nimport { fieldMapper, schemas } from './plugin/schema.js';\nimport type { PayloadHelperPluginConfig } from './types.js';\nimport env from './util/env.js';\n\n// export const test = (pluginOptions: PayloadHelperPluginConfig): Plugin[] => {\n// \treturn [\n// \t\tseoPlugin({\n// \t\t\tcollections: pluginOptions?.seo?.collections,\n// \t\t\tglobals: pluginOptions?.seo?.globals,\n// \t\t\tfields: [...SEOFields, pluginOptions.seo?.fields],\n// \t\t\ttabbedUI: true,\n// \t\t\tuploadsCollection: 'media',\n// \t\t\tgenerateTitle: pluginOptions?.seo?.generateTitle ?\n// \t\t\t\tpluginOptions?.seo?.generateTitle :\n// \t\t\t\t({ doc }) => `${pluginOptions.siteName} — ${doc?.title?.value ?? ''}`,\n// \t\t\tgenerateDescription: pluginOptions?.seo?.generateDescription ?\n// \t\t\t\tpluginOptions?.seo?.generateDescription :\n// \t\t\t\t({ doc }) => doc?.excerpt?.value,\n// \t\t}),\n// \t];\n// };\n\n/**\n * Payload Helper Plugin for websites at ainsley.dev\n *\n * @constructor\n * @param pluginOptions\n */\nexport const payloadHelper =\n\t(pluginOptions: PayloadHelperPluginConfig) =>\n\t(incomingConfig: Config): Config => {\n\t\t// TODO: Validate Config\n\n\t\t// Update typescript generation file\n\t\tincomingConfig.typescript = incomingConfig.typescript || {};\n\t\tincomingConfig.typescript.outputFile = './src/types/payload.ts';\n\n\t\t// Map collections & add hooks\n\t\tincomingConfig.collections = (incomingConfig.collections || []).map(\n\t\t\t(collection): CollectionConfig => {\n\t\t\t\tif (collection.upload !== undefined && collection.upload !== true) {\n\t\t\t\t\treturn collection;\n\t\t\t\t}\n\n\t\t\t\tconst hooks = collection.hooks || {};\n\n\t\t\t\t// Add afterChange hook only if webServer is defined\n\t\t\t\tif (pluginOptions.webServer) {\n\t\t\t\t\thooks.afterChange = [\n\t\t\t\t\t\t...(hooks.afterChange || []),\n\t\t\t\t\t\tcacheHookCollections({\n\t\t\t\t\t\t\tserver: pluginOptions.webServer,\n\t\t\t\t\t\t\tslug: collection.slug,\n\t\t\t\t\t\t\tfields: collection.fields,\n\t\t\t\t\t\t\tisCollection: true,\n\t\t\t\t\t\t}),\n\t\t\t\t\t];\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\t...collection,\n\t\t\t\t\thooks,\n\t\t\t\t};\n\t\t\t},\n\t\t);\n\n\t\t// Map globals & add hooks\n\t\tincomingConfig.globals = (incomingConfig.globals || []).map((global) => {\n\t\t\tconst hooks = global.hooks || {};\n\n\t\t\t// Add afterChange hook only if webServer is defined\n\t\t\tif (pluginOptions.webServer) {\n\t\t\t\thooks.afterChange = [\n\t\t\t\t\t...(hooks.afterChange || []),\n\t\t\t\t\tcacheHookGlobals({\n\t\t\t\t\t\tserver: pluginOptions.webServer,\n\t\t\t\t\t\tslug: global.slug,\n\t\t\t\t\t\tfields: global.fields,\n\t\t\t\t\t\tisCollection: true,\n\t\t\t\t\t}),\n\t\t\t\t];\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...global,\n\t\t\t\thooks,\n\t\t\t};\n\t\t});\n\n\t\treturn incomingConfig;\n\t};\n"],"names":["cacheHookCollections","cacheHookGlobals","payloadHelper","pluginOptions","incomingConfig","typescript","outputFile","collections","map","collection","upload","undefined","hooks","webServer","afterChange","server","slug","fields","isCollection","globals","global"],"mappings":"AACA,SAASA,oBAAoB,EAAEC,gBAAgB,QAAQ,oBAAoB;AAK3E,gFAAgF;AAChF,YAAY;AACZ,gBAAgB;AAChB,mDAAmD;AACnD,2CAA2C;AAC3C,wDAAwD;AACxD,qBAAqB;AAC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ACrBC,cAAc;oBACf;iBACA;YACF;YAEA,OAAO;gBACN,GAAGE,MAAM;gBACTR;YACD;QACD;QAEA,OAAOR;IACR,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.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { JSONSchema4 } from 'json-schema';
|
|
2
|
-
import type {
|
|
2
|
+
import type { SanitizedConfig } from 'payload';
|
|
3
|
+
/**
|
|
4
|
+
* General Options for Generating Schema
|
|
5
|
+
*/
|
|
6
|
+
export interface SchemaOptions {
|
|
7
|
+
useWebKitMedia?: boolean;
|
|
8
|
+
assignRelationships?: boolean;
|
|
9
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
* Adds the necessary GoLang type conversions as a helper func.
|
|
5
12
|
*/
|
|
@@ -11,11 +18,11 @@ export declare const addGoJSONSchema: (type: string, nillable: boolean) => Recor
|
|
|
11
18
|
*
|
|
12
19
|
* @param config
|
|
13
20
|
*/
|
|
14
|
-
export declare const fieldMapper: (config:
|
|
21
|
+
export declare const fieldMapper: (config: SanitizedConfig, opts: SchemaOptions) => SanitizedConfig;
|
|
15
22
|
/**
|
|
16
23
|
* Adjusts the JSON schema to include the necessary GoLang schema
|
|
17
24
|
*
|
|
18
25
|
*/
|
|
19
|
-
export declare const schemas: Array<(args: {
|
|
26
|
+
export declare const schemas: (opts: SchemaOptions) => Array<(args: {
|
|
20
27
|
jsonSchema: JSONSchema4;
|
|
21
28
|
}) => JSONSchema4>;
|
package/dist/plugin/schema.js
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
* to include the necessary GoLang schema.
|
|
37
37
|
*
|
|
38
38
|
* @param config
|
|
39
|
-
*/ export const fieldMapper = (config)=>{
|
|
39
|
+
*/ export const fieldMapper = (config, opts)=>{
|
|
40
40
|
const mapper = (field)=>{
|
|
41
41
|
switch(field.type){
|
|
42
42
|
case 'blocks':
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
case 'json':
|
|
53
53
|
field.typescriptSchema = [
|
|
54
54
|
()=>({
|
|
55
|
-
...addGoJSONSchema('
|
|
55
|
+
...addGoJSONSchema('payload.JSON', false)
|
|
56
56
|
})
|
|
57
57
|
];
|
|
58
58
|
break;
|
|
@@ -65,9 +65,18 @@
|
|
|
65
65
|
];
|
|
66
66
|
break;
|
|
67
67
|
case 'upload':
|
|
68
|
+
if (opts.useWebKitMedia) {
|
|
69
|
+
field.typescriptSchema = [
|
|
70
|
+
()=>({
|
|
71
|
+
...addGoJSONSchema('payload.Media', field.required === true)
|
|
72
|
+
})
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
case 'point':
|
|
68
77
|
field.typescriptSchema = [
|
|
69
78
|
()=>({
|
|
70
|
-
...addGoJSONSchema('payload.
|
|
79
|
+
...addGoJSONSchema('payload.Point', field.required === true)
|
|
71
80
|
})
|
|
72
81
|
];
|
|
73
82
|
break;
|
|
@@ -105,7 +114,7 @@
|
|
|
105
114
|
break;
|
|
106
115
|
}
|
|
107
116
|
}
|
|
108
|
-
if (field.type !== 'ui') {
|
|
117
|
+
if (field.type !== 'ui' && opts.assignRelationships) {
|
|
109
118
|
if (!Array.isArray(field.typescriptSchema)) {
|
|
110
119
|
field.typescriptSchema = [];
|
|
111
120
|
}
|
|
@@ -144,111 +153,115 @@
|
|
|
144
153
|
/**
|
|
145
154
|
* Adjusts the JSON schema to include the necessary GoLang schema
|
|
146
155
|
*
|
|
147
|
-
*/ export const schemas = [
|
|
148
|
-
|
|
156
|
+
*/ export const schemas = (opts)=>[
|
|
157
|
+
/**
|
|
149
158
|
* Removes the auth & uneeded definitions from the schema.
|
|
150
159
|
*/ ({ jsonSchema })=>{
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
if (!jsonSchema.properties) {
|
|
161
|
+
jsonSchema.properties = {};
|
|
162
|
+
}
|
|
163
|
+
if (!jsonSchema.definitions) {
|
|
164
|
+
jsonSchema.definitions = {};
|
|
165
|
+
}
|
|
166
|
+
if (opts.useWebKitMedia) {
|
|
167
|
+
delete jsonSchema.definitions.media;
|
|
168
|
+
delete jsonSchema.properties?.collections?.properties?.media;
|
|
169
|
+
}
|
|
170
|
+
delete jsonSchema.properties.auth;
|
|
171
|
+
delete jsonSchema.definitions['payload-locked-documents'];
|
|
172
|
+
delete jsonSchema.properties?.collections?.properties?.['payload-locked-documents'];
|
|
173
|
+
delete jsonSchema.definitions.redirects;
|
|
174
|
+
delete jsonSchema.properties?.collections?.properties?.redirects;
|
|
175
|
+
return jsonSchema;
|
|
176
|
+
},
|
|
177
|
+
/**
|
|
165
178
|
* Adds the settings and media definitions to the schema
|
|
166
179
|
*/ ({ jsonSchema })=>{
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
180
|
+
if (!jsonSchema.definitions) {
|
|
181
|
+
jsonSchema.definitions = {};
|
|
182
|
+
}
|
|
183
|
+
if ('settings' in jsonSchema.definitions) {
|
|
184
|
+
jsonSchema.definitions.settings = {
|
|
185
|
+
type: 'object',
|
|
186
|
+
fields: [],
|
|
187
|
+
...addGoJSONSchema('payload.Settings', false)
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
if ('forms' in jsonSchema.definitions) {
|
|
191
|
+
jsonSchema.definitions.forms = {
|
|
192
|
+
type: 'object',
|
|
193
|
+
...addGoJSONSchema('payload.Form', false),
|
|
194
|
+
fields: []
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
if ('form-submissions' in jsonSchema.definitions) {
|
|
198
|
+
jsonSchema.definitions['form-submissions'] = {
|
|
199
|
+
type: 'object',
|
|
200
|
+
...addGoJSONSchema('payload.FormSubmission', false),
|
|
201
|
+
fields: []
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
return jsonSchema;
|
|
205
|
+
},
|
|
206
|
+
/**
|
|
194
207
|
* Updates the JSON schema so that it doesn't feature oneOf, so Go doesn't
|
|
195
208
|
* output it as an interface{}.
|
|
196
209
|
*/ ({ jsonSchema })=>{
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
if (payload.type === 'relationship') {
|
|
203
|
-
if (payload.hasMany) {
|
|
204
|
-
property.type = 'array';
|
|
205
|
-
property.items = {
|
|
206
|
-
$ref: `#/definitions/${payload.relationTo}`
|
|
207
|
-
};
|
|
210
|
+
const updateRelationship = (property)=>{
|
|
211
|
+
const payload = property.payload;
|
|
212
|
+
if (!payload) {
|
|
208
213
|
return;
|
|
209
214
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
updateRelationship(property.properties[k]);
|
|
215
|
+
if (payload.type === 'relationship') {
|
|
216
|
+
if (payload.hasMany) {
|
|
217
|
+
property.type = 'array';
|
|
218
|
+
property.items = {
|
|
219
|
+
$ref: `#/definitions/${payload.relationTo}`
|
|
220
|
+
};
|
|
221
|
+
return;
|
|
218
222
|
}
|
|
223
|
+
delete property.oneOf;
|
|
224
|
+
property.$ref = `#/definitions/${property.payload.relationTo}`;
|
|
219
225
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
const pType = payload.type;
|
|
227
|
+
if (pType === 'group' || pType === 'row' || pType === 'collapsible' || pType === 'array') {
|
|
228
|
+
if (property.properties) {
|
|
229
|
+
for(const k in property.properties){
|
|
230
|
+
updateRelationship(property.properties[k]);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
loopJSONSchemaProperties(jsonSchema, ({ property })=>{
|
|
237
|
+
updateRelationship(property);
|
|
238
|
+
});
|
|
239
|
+
return jsonSchema;
|
|
240
|
+
},
|
|
241
|
+
/**
|
|
229
242
|
* Changes blockType to a string so it's not an *interface{} when
|
|
230
243
|
* comparing block types in Go.
|
|
231
244
|
*/ ({ jsonSchema })=>{
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
245
|
+
loopJSONSchemaProperties(jsonSchema, ({ property, key })=>{
|
|
246
|
+
if (key === 'blockType') {
|
|
247
|
+
property.type = 'string';
|
|
248
|
+
delete property.const;
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
return jsonSchema;
|
|
252
|
+
},
|
|
253
|
+
/**
|
|
241
254
|
* Changes blockType to a string so it's not an *interface{} when
|
|
242
255
|
* comparing block types in Go.
|
|
243
256
|
*/ ({ jsonSchema })=>{
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
];
|
|
257
|
+
loopJSONSchemaProperties(jsonSchema, ({ property, key })=>{
|
|
258
|
+
const payload = property.payload;
|
|
259
|
+
if (payload && payload.type === 'relationship' && payload.name === 'form') {
|
|
260
|
+
delete property.$ref;
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
return jsonSchema;
|
|
264
|
+
}
|
|
265
|
+
];
|
|
253
266
|
|
|
254
267
|
//# sourceMappingURL=schema.js.map
|
|
@@ -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\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;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;IAC3B,MAAMC,SAAS,CAACC;QACf,OAAQA,MAAMP,IAAI;YACjB,KAAK;gBACJO,MAAMC,gBAAgB,GAAG;oBAAC,IAAO,CAAA;4BAAE,GAAGT,gBAAgB,kBAAkB,MAAM;wBAAC,CAAA;iBAAG;gBAClFQ,MAAME,MAAM,CAACjB,OAAO,CAAC,CAACkB;oBACrBA,MAAMC,MAAM,GAAGD,MAAMC,MAAM,CAACC,GAAG,CAAC,CAACC,IAAMP,OAAOO;gBAC/C;gBACA;YACD,KAAK;gBACJN,MAAMC,gBAAgB,GAAG;oBAAC,IAAO,CAAA;4BAAE,GAAGT,gBAAgB,UAAU,MAAM;wBAAC,CAAA;iBAAG;gBAC1E;YACD,KAAK;gBACJQ,MAAMC,gBAAgB,GAAG;oBACxB,IAAO,CAAA;4BACNR,MAAM;4BACN,GAAG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KAAK5C,SAASF,UAAU,CAAE;wBACpCyC,mBAAmBvC,SAASF,UAAU,CAAC8C,EAAE;oBAC1C;gBACD;gBACA;YACD;QACD;QAEAvD,yBAAyBC,YAAY,CAAC,EAAEU,QAAQ,EAAE;YACjDuC,mBAAmBvC;QACpB;QACA,OAAOV;IACR;IACA;;;EAGC,GACD,CAAC,EAAEA,UAAU,EAAE;QACdD,yBAAyBC,YAAY,CAAC,EAAEU,QAAQ,EAAEC,GAAG,EAAE;YACtD,IAAIA,QAAQ,aAAa;gBACxBD,SAASG,IAAI,GAAG;gBAChB,OAAOH,SAAS6C,KAAK;YACtB;QACD;QACA,OAAOvD;IACR;IACA;;;EAGC,GACD,CAAC,EAAEA,UAAU,EAAE;QACdD,yBAAyBC,YAAY,CAAC,EAAEU,QAAQ,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"}
|
|
1
|
+
{"version":3,"sources":["../../src/plugin/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema';\nimport type { Config, Field, SanitizedConfig } from 'payload';\n\n/**\n * General Options for Generating Schema\n */\nexport interface SchemaOptions {\n\tuseWebKitMedia?: boolean;\n\tassignRelationships?: boolean;\n}\n\n/**\n * This function iterates over properties in JSON schema definitions,\n * passing each property and its key to a callback function.\n */\nconst loopJSONSchemaProperties = (\n\tjsonSchema: JSONSchema4,\n\tcallback: (args: { key: string; property: JSONSchema4 }) => void,\n): JSONSchema4 => {\n\tif (!jsonSchema.definitions) {\n\t\treturn jsonSchema;\n\t}\n\tObject.entries(jsonSchema.definitions).forEach(([definitionKey, definition]) => {\n\t\tif (definition.properties) {\n\t\t\tObject.entries(definition.properties).forEach(([propertyKey, property]) => {\n\t\t\t\tcallback({ key: propertyKey, property });\n\t\t\t});\n\t\t}\n\t});\n\treturn jsonSchema;\n};\n\n/**\n * Adds the necessary GoLang type conversions as a helper func.\n */\nexport const addGoJSONSchema = (type: string, nillable: boolean): Record<string, unknown> => {\n\treturn {\n\t\tgoJSONSchema: {\n\t\t\timports: ['github.com/ainsleydev/webkit/pkg/adapters/payload'],\n\t\t\tnillable: nillable,\n\t\t\ttype: type,\n\t\t},\n\t};\n};\n\n/**\n * Iterates over all the fields within the config, for both collections\n * and globals, and transforms the JSON schema\n * to include the necessary GoLang schema.\n *\n * @param config\n */\nexport const fieldMapper = (config: SanitizedConfig, opts: SchemaOptions) => {\n\tconst mapper = (field: Field): Field => {\n\t\tswitch (field.type) {\n\t\t\tcase 'blocks':\n\t\t\t\tfield.typescriptSchema = [() => ({ ...addGoJSONSchema('payload.Blocks', false) })];\n\t\t\t\tfield.blocks.forEach((block) => {\n\t\t\t\t\tblock.fields = block.fields.map((f) => mapper(f));\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase 'json':\n\t\t\t\tfield.typescriptSchema = [() => ({ ...addGoJSONSchema('payload.JSON', false) })];\n\t\t\t\tbreak;\n\t\t\tcase 'richText':\n\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t() => ({\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t...addGoJSONSchema('payload.RichText', false),\n\t\t\t\t\t}),\n\t\t\t\t];\n\t\t\t\tbreak;\n\t\t\tcase 'upload':\n\t\t\t\tif (opts.useWebKitMedia) {\n\t\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t\t() => ({ ...addGoJSONSchema('payload.Media', field.required === true) }),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase 'point':\n\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t() => ({\n\t\t\t\t\t\t...addGoJSONSchema('payload.Point', field.required === true),\n\t\t\t\t\t}),\n\t\t\t\t];\n\t\t\t\tbreak;\n\t\t\tcase 'tabs': {\n\t\t\t\tfield.tabs.forEach((tab) => {\n\t\t\t\t\ttab.fields = tab.fields.map((f) => mapper(f));\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase 'relationship': {\n\t\t\t\tif (field.relationTo === 'forms') {\n\t\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t\t() => ({ ...addGoJSONSchema('payload.Form', field.required === true) }),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase 'group':\n\t\t\tcase 'array':\n\t\t\tcase 'row':\n\t\t\tcase 'collapsible': {\n\t\t\t\tif (field.type === 'group' && field.name === 'meta') {\n\t\t\t\t\tfield.typescriptSchema = [\n\t\t\t\t\t\t() => ({ ...addGoJSONSchema('payload.SettingsMeta', true) }),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t\tfield.fields = field.fields.map((f) => mapper(f));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\t// SEE: https://github.com/ainsleydev/webkit/blob/cdfa078605bec4ee92f2424f69271a0bf6b71366/packages/payload-helper/src/gen/schema.ts#L235\n\t\t}\n\n\t\tif (field.type !== 'ui' && opts.assignRelationships) {\n\t\t\tif (!Array.isArray(field.typescriptSchema)) {\n\t\t\t\tfield.typescriptSchema = [];\n\t\t\t}\n\n\t\t\tif (field.type !== 'tabs' && field.type !== 'row' && field.type !== 'collapsible') {\n\t\t\t\tfield.typescriptSchema.push(({ jsonSchema }) => {\n\t\t\t\t\tconst payload = {\n\t\t\t\t\t\tname: field.name,\n\t\t\t\t\t\ttype: field.type,\n\t\t\t\t\t\tlabel: field.label,\n\t\t\t\t\t} as Record<string, unknown>;\n\n\t\t\t\t\tif (field.type === 'relationship') {\n\t\t\t\t\t\tpayload.hasMany = field.hasMany;\n\t\t\t\t\t\tpayload.relationTo = field.relationTo;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...jsonSchema,\n\t\t\t\t\t\tpayload,\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn field;\n\t};\n\n\tif (config.collections) {\n\t\tconfig.collections.forEach((collection) => {\n\t\t\tcollection.fields = collection.fields.map((field) => mapper(field));\n\t\t});\n\t}\n\n\tif (config.globals) {\n\t\tconfig.globals.forEach((global, index) => {\n\t\t\tglobal.fields = global.fields.map((field) => mapper(field));\n\t\t});\n\t}\n\n\treturn config;\n};\n\n/**\n * Adjusts the JSON schema to include the necessary GoLang schema\n *\n */\nexport const schemas = (\n\topts: SchemaOptions,\n): Array<(args: { jsonSchema: JSONSchema4 }) => JSONSchema4> => [\n\t/**\n\t * Removes the auth & uneeded definitions from the schema.\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tif (!jsonSchema.properties) {\n\t\t\tjsonSchema.properties = {};\n\t\t}\n\t\tif (!jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions = {};\n\t\t}\n\n\t\tif (opts.useWebKitMedia) {\n\t\t\tdelete jsonSchema.definitions.media;\n\t\t\tdelete jsonSchema.properties?.collections?.properties?.media;\n\t\t}\n\n\t\tdelete jsonSchema.properties.auth;\n\t\tdelete jsonSchema.definitions['payload-locked-documents'];\n\t\tdelete jsonSchema.properties?.collections?.properties?.['payload-locked-documents'];\n\t\tdelete jsonSchema.definitions.redirects;\n\t\tdelete jsonSchema.properties?.collections?.properties?.redirects;\n\t\treturn jsonSchema;\n\t},\n\t/**\n\t * Adds the settings and media definitions to the schema\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tif (!jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions = {};\n\t\t}\n\n\t\tif ('settings' in jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions.settings = {\n\t\t\t\ttype: 'object',\n\t\t\t\tfields: [],\n\t\t\t\t...addGoJSONSchema('payload.Settings', false),\n\t\t\t};\n\t\t}\n\n\t\tif ('forms' in jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions.forms = {\n\t\t\t\ttype: 'object',\n\t\t\t\t...addGoJSONSchema('payload.Form', false),\n\t\t\t\tfields: [],\n\t\t\t};\n\t\t}\n\n\t\tif ('form-submissions' in jsonSchema.definitions) {\n\t\t\tjsonSchema.definitions['form-submissions'] = {\n\t\t\t\ttype: 'object',\n\t\t\t\t...addGoJSONSchema('payload.FormSubmission', false),\n\t\t\t\tfields: [],\n\t\t\t};\n\t\t}\n\n\t\treturn jsonSchema;\n\t},\n\t/**\n\t * Updates the JSON schema so that it doesn't feature oneOf, so Go doesn't\n\t * output it as an interface{}.\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tconst updateRelationship = (property: JSONSchema4) => {\n\t\t\tconst payload = property.payload;\n\t\t\tif (!payload) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (payload.type === 'relationship') {\n\t\t\t\tif (payload.hasMany) {\n\t\t\t\t\tproperty.type = 'array';\n\t\t\t\t\tproperty.items = {\n\t\t\t\t\t\t$ref: `#/definitions/${payload.relationTo}`,\n\t\t\t\t\t};\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tdelete property.oneOf;\n\t\t\t\tproperty.$ref = `#/definitions/${property.payload.relationTo}`;\n\t\t\t}\n\n\t\t\tconst pType = payload.type;\n\t\t\tif (\n\t\t\t\tpType === 'group' ||\n\t\t\t\tpType === 'row' ||\n\t\t\t\tpType === 'collapsible' ||\n\t\t\t\tpType === 'array'\n\t\t\t) {\n\t\t\t\tif (property.properties) {\n\t\t\t\t\tfor (const k in property.properties) {\n\t\t\t\t\t\tupdateRelationship(property.properties[k]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t};\n\n\t\tloopJSONSchemaProperties(jsonSchema, ({ property }) => {\n\t\t\tupdateRelationship(property);\n\t\t});\n\t\treturn jsonSchema;\n\t},\n\t/**\n\t * Changes blockType to a string so it's not an *interface{} when\n\t * comparing block types in Go.\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tloopJSONSchemaProperties(jsonSchema, ({ property, key }) => {\n\t\t\tif (key === 'blockType') {\n\t\t\t\tproperty.type = 'string';\n\t\t\t\tdelete property.const;\n\t\t\t}\n\t\t});\n\t\treturn jsonSchema;\n\t},\n\t/**\n\t * Changes blockType to a string so it's not an *interface{} when\n\t * comparing block types in Go.\n\t */\n\t({ jsonSchema }): JSONSchema4 => {\n\t\tloopJSONSchemaProperties(jsonSchema, ({ property, key }) => {\n\t\t\tconst payload = property.payload;\n\t\t\tif (payload && payload.type === 'relationship' && payload.name === 'form') {\n\t\t\t\tdelete property.$ref;\n\t\t\t}\n\t\t});\n\t\treturn jsonSchema;\n\t},\n];\n"],"names":["loopJSONSchemaProperties","jsonSchema","callback","definitions","Object","entries","forEach","definitionKey","definition","properties","propertyKey","property","key","addGoJSONSchema","type","nillable","goJSONSchema","imports","fieldMapper","config","opts","mapper","field","typescriptSchema","blocks","block","fields","map","f","useWebKitMedia","required","tabs","tab","relationTo","name","assignRelationships","Array","isArray","push","payload","label","hasMany","collections","collection","globals","global","index","schemas","media","auth","redirects","settings","forms","updateRelationship","items","$ref","oneOf","pType","k","const"],"mappings":"AAWA;;;CAGC,GACD,MAAMA,2BAA2B,CAChCC,YACAC;IAEA,IAAI,CAACD,WAAWE,WAAW,EAAE;QAC5B,OAAOF;IACR;IACAG,OAAOC,OAAO,CAACJ,WAAWE,WAAW,EAAEG,OAAO,CAAC,CAAC,CAACC,eAAeC,WAAW;QAC1E,IAAIA,WAAWC,UAAU,EAAE;YAC1BL,OAAOC,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,UA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,UAAU,EAAE;YACdD,yBAAyBC,YAAY,CAAC,EAAEU,QAAQ,EAAEC,GAAG,EAAE;gBACtD,IAAIA,QAAQ,aAAa;oBACxBD,SAASG,IAAI,GAAG;oBAChB,OAAOH,SAASgD,KAAK;gBACtB;YACD;YACA,OAAO1D;QACR;QACA;;;EAGC,GACD,CAAC,EAAEA,UAAU,EAAE;YACdD,yBAAyBC,YAAY,CAAC,EAAEU,QAAQ,EAAEC,GAAG,EAAE;gBACtD,MAAM2B,UAAU5B,SAAS4B,OAAO;gBAChC,IAAIA,WAAWA,QAAQzB,IAAI,KAAK,kBAAkByB,QAAQL,IAAI,KAAK,QAAQ;oBAC1E,OAAOvB,SAAS4C,IAAI;gBACrB;YACD;YACA,OAAOtD;QACR;KACA,CAAC"}
|
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 ? await 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,GAAG,MAAMR,cAAcK,MAAMG,OAAO,IAAI;QAErE,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 ? await 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,GAAG,MAAMR,cAAcK,MAAMG,OAAO,IAAI;QAErE,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.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Payload, type PayloadRequest } from 'payload';
|
|
1
|
+
import { type Payload, type PayloadRequest, type SanitizedConfig } from 'payload';
|
|
2
2
|
/**
|
|
3
3
|
* A function that seeds the database with initial data.
|
|
4
4
|
*/
|
|
@@ -11,21 +11,16 @@ export type Seeder = (args: {
|
|
|
11
11
|
* Note: You must use path.resolve for the paths, i.e. path.resolve(__dirname, 'path/to/file')
|
|
12
12
|
*/
|
|
13
13
|
export type SeedOptions = {
|
|
14
|
-
|
|
15
|
-
configPath: string;
|
|
16
|
-
dbAdapter: DBAdapter;
|
|
14
|
+
config: SanitizedConfig;
|
|
17
15
|
seeder: Seeder;
|
|
18
16
|
};
|
|
19
|
-
/**
|
|
20
|
-
* The database adapter to use, which will remove and recreate the database.
|
|
21
|
-
*/
|
|
22
|
-
export declare enum DBAdapter {
|
|
23
|
-
Postgres = "postgres"
|
|
24
|
-
}
|
|
25
17
|
/**
|
|
26
18
|
* Seeds the database with initial data.
|
|
27
19
|
*
|
|
28
20
|
* @param opts - The options for seeding.
|
|
29
21
|
* @returns A promise that resolves when the seeding is complete.
|
|
30
22
|
*/
|
|
31
|
-
export declare const seed: (opts:
|
|
23
|
+
export declare const seed: (opts: {
|
|
24
|
+
seeder: Seeder;
|
|
25
|
+
config: SanitizedConfig;
|
|
26
|
+
}) => void;
|
package/dist/seed/seed.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import dotenv from 'dotenv';
|
|
2
1
|
import { commitTransaction, getPayload, initTransaction, killTransaction } from 'payload';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { fileURLToPath } from "node:url";
|
|
2
|
+
import env from '../util/env.js';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
8
6
|
const filename = fileURLToPath(import.meta.url);
|
|
9
7
|
const dirname = path.dirname(filename);
|
|
10
|
-
export var DBAdapter;
|
|
11
|
-
(function(DBAdapter) {
|
|
12
|
-
DBAdapter["Postgres"] = "postgres";
|
|
13
|
-
})(DBAdapter || (DBAdapter = {}));
|
|
14
8
|
/**
|
|
15
9
|
* Seeds the database with initial data.
|
|
16
10
|
*
|
|
@@ -18,13 +12,9 @@ export var DBAdapter;
|
|
|
18
12
|
* @returns A promise that resolves when the seeding is complete.
|
|
19
13
|
*/ export const seed = (opts)=>{
|
|
20
14
|
const fn = async ()=>{
|
|
21
|
-
dotenv.config({
|
|
22
|
-
path: opts.envPath
|
|
23
|
-
});
|
|
24
15
|
process.env.PAYLOAD_DROP_DATABASE = 'true';
|
|
25
|
-
const config = await importConfig(opts.configPath);
|
|
26
16
|
const payload = await getPayload({
|
|
27
|
-
config
|
|
17
|
+
config: opts.config
|
|
28
18
|
});
|
|
29
19
|
const req = {
|
|
30
20
|
payload
|
|
@@ -32,11 +22,6 @@ export var DBAdapter;
|
|
|
32
22
|
await initTransaction(req);
|
|
33
23
|
delete process.env.PAYLOAD_DROP_DATABASE;
|
|
34
24
|
try {
|
|
35
|
-
// Init
|
|
36
|
-
payload.logger.info("Initialising Payload...");
|
|
37
|
-
await payload.init({
|
|
38
|
-
config: payload.config
|
|
39
|
-
});
|
|
40
25
|
// Creating new tables
|
|
41
26
|
payload.logger.info('Creating indexes...');
|
|
42
27
|
try {
|
|
@@ -47,10 +32,8 @@ export var DBAdapter;
|
|
|
47
32
|
payload.logger.error(`Creating database: ${error}`);
|
|
48
33
|
return;
|
|
49
34
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
await payload.db.migrate();
|
|
53
|
-
}
|
|
35
|
+
payload.logger.info('Migrating DB...');
|
|
36
|
+
await payload.db.migrate();
|
|
54
37
|
// Clearing local media
|
|
55
38
|
if (!env.isProduction) {
|
|
56
39
|
payload.logger.info('Clearing media...');
|
package/dist/seed/seed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/seed/seed.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/seed/seed.ts"],"sourcesContent":["import {\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';\nimport path from 'node:path';\nimport fs from 'node:fs';\nimport { fileURLToPath } from 'node:url';\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":["commitTransaction","getPayload","initTransaction","killTransaction","env","path","fs","fileURLToPath","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,SAICA,iBAAiB,EACjBC,UAAU,EACVC,eAAe,EACfC,eAAe,QACT,UAAU;AACjB,OAAOC,SAAS,iBAAiB;AACjC,OAAOC,UAAU,YAAY;AAC7B,OAAOC,QAAQ,UAAU;AACzB,SAASC,aAAa,QAAQ,WAAW;AAEzC,MAAMC,WAAWD,cAAc,YAAYE,GAAG;AAC9C,MAAMC,UAAUL,KAAKK,OAAO,CAACF;AAgB7B;;;;;CAKC,GACD,OAAO,MAAMG,OAAO,CAACC;IAIpB,MAAMC,KAAK;QACVC,QAAQV,GAAG,CAACW,qBAAqB,GAAG;QAEpC,MAAMC,UAAU,MAAMf,WAAW;YAChCgB,QAAQL,KAAKK,MAAM;QACpB;QACA,MAAMC,MAAM;YAAEF;QAAQ;QAEtB,MAAMd,gBAAgBgB;QAEtB,OAAOJ,QAAQV,GAAG,CAACW,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,CAACpB,IAAIqB,YAAY,EAAE;gBACtBT,QAAQG,MAAM,CAACC,IAAI,CAAC;gBACpB,MAAMM,WAAWrB,KAAKsB,OAAO,CAACjB,SAAS;gBACvC,IAAIJ,GAAGsB,UAAU,CAACF,WAAW;oBAC5BpB,GAAGuB,MAAM,CAACH,UAAU;wBAAEI,WAAW;wBAAMC,OAAO;oBAAK;gBACpD;YACD;YAEA,+BAA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