@ainsleydev/payload-helper 0.0.8 → 0.0.10

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.
Files changed (63) hide show
  1. package/dist/cli/bin.d.ts +2 -0
  2. package/dist/cli/bin.js +17 -0
  3. package/dist/cli/bin.js.map +1 -0
  4. package/dist/cli/types.d.ts +4 -0
  5. package/dist/cli/types.js +34 -0
  6. package/dist/cli/types.js.map +1 -0
  7. package/dist/collections/Media.d.ts +10 -0
  8. package/dist/collections/Media.js +150 -0
  9. package/dist/collections/Media.js.map +1 -0
  10. package/dist/collections/Redirects.d.ts +10 -0
  11. package/dist/collections/Redirects.js +72 -0
  12. package/dist/collections/Redirects.js.map +1 -0
  13. package/dist/common/SEO.d.ts +6 -0
  14. package/dist/common/SEO.js +45 -0
  15. package/dist/common/SEO.js.map +1 -0
  16. package/dist/endpoints/slug.d.ts +7 -0
  17. package/dist/endpoints/slug.js +38 -0
  18. package/dist/endpoints/slug.js.map +1 -0
  19. package/dist/globals/Navigation.d.ts +28 -0
  20. package/dist/globals/Navigation.js +138 -0
  21. package/dist/globals/Navigation.js.map +1 -0
  22. package/dist/globals/Settings.d.ts +10 -0
  23. package/dist/globals/Settings.js +346 -0
  24. package/dist/globals/Settings.js.map +1 -0
  25. package/dist/globals/countries.d.ts +1 -0
  26. package/dist/globals/countries.js +198 -0
  27. package/dist/globals/countries.js.map +1 -0
  28. package/dist/globals/locales.d.ts +7 -0
  29. package/dist/globals/locales.js +2664 -0
  30. package/dist/globals/locales.js.map +1 -0
  31. package/dist/index.d.ts +9 -0
  32. package/dist/index.js +23 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/plugin/schema.d.ts +21 -0
  35. package/dist/plugin/schema.js +239 -0
  36. package/dist/plugin/schema.js.map +1 -0
  37. package/dist/seed/media.d.ts +10 -0
  38. package/dist/seed/media.js +29 -0
  39. package/dist/seed/media.js.map +1 -0
  40. package/dist/seed/seed.d.ts +31 -0
  41. package/dist/seed/seed.js +84 -0
  42. package/dist/seed/seed.js.map +1 -0
  43. package/dist/seed/types.d.ts +125 -0
  44. package/dist/seed/types.js +3 -0
  45. package/dist/seed/types.js.map +1 -0
  46. package/dist/types.d.ts +10 -0
  47. package/dist/types.js +4 -0
  48. package/dist/types.js.map +1 -0
  49. package/dist/util/env.d.ts +12 -0
  50. package/dist/util/env.js +75 -0
  51. package/dist/util/env.js.map +1 -0
  52. package/dist/util/fields.d.ts +7 -0
  53. package/dist/util/fields.js +12 -0
  54. package/dist/util/fields.js.map +1 -0
  55. package/dist/util/lexical.d.ts +15 -0
  56. package/dist/util/lexical.js +123 -0
  57. package/dist/util/lexical.js.map +1 -0
  58. package/dist/util/lexical.test.js +21 -0
  59. package/dist/util/lexical.test.js.map +1 -0
  60. package/dist/util/validation.d.ts +2 -0
  61. package/dist/util/validation.js +23 -0
  62. package/dist/util/validation.js.map +1 -0
  63. package/package.json +2 -2
@@ -0,0 +1,84 @@
1
+ import dotenv from 'dotenv';
2
+ import { commitTransaction, getPayload, initTransaction, killTransaction } from 'payload';
3
+ import { importConfig } from 'payload/node';
4
+ import env from "../util/env.js";
5
+ import path from "node:path";
6
+ import fs from "node:fs";
7
+ import { fileURLToPath } from "node:url";
8
+ const filename = fileURLToPath(import.meta.url);
9
+ const dirname = path.dirname(filename);
10
+ export var DBAdapter;
11
+ (function(DBAdapter) {
12
+ DBAdapter["Postgres"] = "postgres";
13
+ })(DBAdapter || (DBAdapter = {}));
14
+ /**
15
+ * Seeds the database with initial data.
16
+ *
17
+ * @param opts - The options for seeding.
18
+ * @returns A promise that resolves when the seeding is complete.
19
+ */ export const seed = (opts)=>{
20
+ const fn = async ()=>{
21
+ dotenv.config({
22
+ path: opts.envPath
23
+ });
24
+ process.env.PAYLOAD_DROP_DATABASE = 'true';
25
+ const config = await importConfig(opts.configPath);
26
+ const payload = await getPayload({
27
+ config
28
+ });
29
+ const req = {
30
+ payload
31
+ };
32
+ await initTransaction(req);
33
+ delete process.env.PAYLOAD_DROP_DATABASE;
34
+ try {
35
+ // Init
36
+ payload.logger.info("Initialising Payload...");
37
+ await payload.init({
38
+ config: payload.config
39
+ });
40
+ // Creating new tables
41
+ payload.logger.info('Creating indexes...');
42
+ try {
43
+ if (payload.db.init) {
44
+ await payload.db.init();
45
+ }
46
+ } catch (error) {
47
+ payload.logger.error(`Creating database: ${error}`);
48
+ return;
49
+ }
50
+ if (env.isProduction) {
51
+ payload.logger.info('Migrating DB...');
52
+ await payload.db.migrate();
53
+ }
54
+ // Clearing local media
55
+ if (!env.isProduction) {
56
+ payload.logger.info('Clearing media...');
57
+ const mediaDir = path.resolve(dirname, '../../media');
58
+ if (fs.existsSync(mediaDir)) {
59
+ fs.rmSync(mediaDir, {
60
+ recursive: true,
61
+ force: true
62
+ });
63
+ }
64
+ }
65
+ // Run user defined seed script
66
+ await opts.seeder({
67
+ payload,
68
+ req
69
+ });
70
+ await commitTransaction(req);
71
+ payload.logger.info('Seed complete');
72
+ } catch (err) {
73
+ const message = err instanceof Error ? err.message : 'Unknown error';
74
+ payload.logger.error(`Seed failed: ${message}`);
75
+ await killTransaction(req);
76
+ }
77
+ };
78
+ fn().then(()=>process.exit(0)).catch((e)=>{
79
+ console.error(e);
80
+ process.exit(1);
81
+ });
82
+ };
83
+
84
+ //# sourceMappingURL=seed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/seed/seed.ts"],"sourcesContent":["import dotenv from 'dotenv';\nimport {\n\ttype Payload,\n\ttype PayloadRequest,\n\tcommitTransaction,\n\tgetPayload,\n\tinitTransaction,\n\tkillTransaction,\n} from 'payload';\nimport { importConfig } from 'payload/node';\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\tenvPath: string;\n\tconfigPath: string;\n\tdbAdapter: DBAdapter;\n\tseeder: Seeder;\n};\n\n/**\n * The database adapter to use, which will remove and recreate the database.\n */\nexport enum DBAdapter {\n\tPostgres = 'postgres',\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: SeedOptions) => {\n\tconst fn = async () => {\n\t\tdotenv.config({\n\t\t\tpath: opts.envPath,\n\t\t});\n\n\t\tprocess.env.PAYLOAD_DROP_DATABASE = 'true';\n\n\t\tconst config = await importConfig(opts.configPath);\n\t\tconst payload = await getPayload({ config });\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// Init\n\t\t\tpayload.logger.info(\"Initialising Payload...\")\n\t\t\tawait payload.init({\n\t\t\t\tconfig: payload.config,\n\t\t\t});\n\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\tif (env.isProduction) {\n\t\t\t\tpayload.logger.info('Migrating DB...');\n\t\t\t\tawait payload.db.migrate();\n\t\t\t}\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":["dotenv","commitTransaction","getPayload","initTransaction","killTransaction","importConfig","env","path","fs","fileURLToPath","filename","url","dirname","DBAdapter","seed","opts","fn","config","envPath","process","PAYLOAD_DROP_DATABASE","configPath","payload","req","logger","info","init","db","error","isProduction","migrate","mediaDir","resolve","existsSync","rmSync","recursive","force","seeder","err","message","Error","then","exit","catch","e","console"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAGCC,iBAAiB,EACjBC,UAAU,EACVC,eAAe,EACfC,eAAe,QACT,UAAU;AACjB,SAASC,YAAY,QAAQ,eAAe;AAC5C,OAAOC,SAAS,iBAAiB;AACjC,OAAOC,UAAU,YAAY;AAC7B,OAAOC,QAAQ,UAAU;AACzB,SAAQC,aAAa,QAAO,WAAW;AAEvC,MAAMC,WAAWD,cAAc,YAAYE,GAAG;AAC9C,MAAMC,UAAUL,KAAKK,OAAO,CAACF;;UAqBjBG;;GAAAA,cAAAA;AAIZ;;;;;CAKC,GACD,OAAO,MAAMC,OAAO,CAACC;IACpB,MAAMC,KAAK;QACVhB,OAAOiB,MAAM,CAAC;YACbV,MAAMQ,KAAKG,OAAO;QACnB;QAEAC,QAAQb,GAAG,CAACc,qBAAqB,GAAG;QAEpC,MAAMH,SAAS,MAAMZ,aAAaU,KAAKM,UAAU;QACjD,MAAMC,UAAU,MAAMpB,WAAW;YAAEe;QAAO;QAC1C,MAAMM,MAAM;YAAED;QAAQ;QAEtB,MAAMnB,gBAAgBoB;QAEtB,OAAO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jB,KAAK,CAACgB;QACdzB,QAAQuB,IAAI,CAAC;IACd;AACF,EAAE"}
@@ -0,0 +1,125 @@
1
+ export interface MediaSeed {
2
+ path: string;
3
+ alt: string;
4
+ caption?: string;
5
+ }
6
+ export interface Media {
7
+ id: number;
8
+ alt: string;
9
+ caption?: {
10
+ root: {
11
+ type: string;
12
+ children: {
13
+ type: string;
14
+ version: number;
15
+ [k: string]: unknown;
16
+ }[];
17
+ direction: ('ltr' | 'rtl') | null;
18
+ format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
19
+ indent: number;
20
+ version: number;
21
+ };
22
+ [k: string]: unknown;
23
+ } | null;
24
+ updatedAt: string;
25
+ createdAt: string;
26
+ url?: string | null;
27
+ thumbnailURL?: string | null;
28
+ filename?: string | null;
29
+ mimeType?: string | null;
30
+ filesize?: number | null;
31
+ width?: number | null;
32
+ height?: number | null;
33
+ focalX?: number | null;
34
+ focalY?: number | null;
35
+ sizes?: {
36
+ webp?: {
37
+ url?: string | null;
38
+ width?: number | null;
39
+ height?: number | null;
40
+ mimeType?: string | null;
41
+ filesize?: number | null;
42
+ filename?: string | null;
43
+ };
44
+ avif?: {
45
+ url?: string | null;
46
+ width?: number | null;
47
+ height?: number | null;
48
+ mimeType?: string | null;
49
+ filesize?: number | null;
50
+ filename?: string | null;
51
+ };
52
+ thumbnail?: {
53
+ url?: string | null;
54
+ width?: number | null;
55
+ height?: number | null;
56
+ mimeType?: string | null;
57
+ filesize?: number | null;
58
+ filename?: string | null;
59
+ };
60
+ thumbnail_webp?: {
61
+ url?: string | null;
62
+ width?: number | null;
63
+ height?: number | null;
64
+ mimeType?: string | null;
65
+ filesize?: number | null;
66
+ filename?: string | null;
67
+ };
68
+ thumbnail_avif?: {
69
+ url?: string | null;
70
+ width?: number | null;
71
+ height?: number | null;
72
+ mimeType?: string | null;
73
+ filesize?: number | null;
74
+ filename?: string | null;
75
+ };
76
+ mobile?: {
77
+ url?: string | null;
78
+ width?: number | null;
79
+ height?: number | null;
80
+ mimeType?: string | null;
81
+ filesize?: number | null;
82
+ filename?: string | null;
83
+ };
84
+ mobile_webp?: {
85
+ url?: string | null;
86
+ width?: number | null;
87
+ height?: number | null;
88
+ mimeType?: string | null;
89
+ filesize?: number | null;
90
+ filename?: string | null;
91
+ };
92
+ mobile_avif?: {
93
+ url?: string | null;
94
+ width?: number | null;
95
+ height?: number | null;
96
+ mimeType?: string | null;
97
+ filesize?: number | null;
98
+ filename?: string | null;
99
+ };
100
+ tablet?: {
101
+ url?: string | null;
102
+ width?: number | null;
103
+ height?: number | null;
104
+ mimeType?: string | null;
105
+ filesize?: number | null;
106
+ filename?: string | null;
107
+ };
108
+ tablet_webp?: {
109
+ url?: string | null;
110
+ width?: number | null;
111
+ height?: number | null;
112
+ mimeType?: string | null;
113
+ filesize?: number | null;
114
+ filename?: string | null;
115
+ };
116
+ tablet_avif?: {
117
+ url?: string | null;
118
+ width?: number | null;
119
+ height?: number | null;
120
+ mimeType?: string | null;
121
+ filesize?: number | null;
122
+ filename?: string | null;
123
+ };
124
+ };
125
+ }
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/seed/types.ts"],"sourcesContent":["export interface MediaSeed {\n\tpath: string;\n\talt: string;\n\tcaption?: string;\n}\n\nexport interface Media {\n\tid: number;\n\talt: string;\n\tcaption?: {\n\t\troot: {\n\t\t\ttype: string;\n\t\t\tchildren: {\n\t\t\t\ttype: string;\n\t\t\t\tversion: number;\n\t\t\t\t[k: string]: unknown;\n\t\t\t}[];\n\t\t\tdirection: ('ltr' | 'rtl') | null;\n\t\t\tformat: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';\n\t\t\tindent: number;\n\t\t\tversion: number;\n\t\t};\n\t\t[k: string]: unknown;\n\t} | null;\n\tupdatedAt: string;\n\tcreatedAt: string;\n\turl?: string | null;\n\tthumbnailURL?: string | null;\n\tfilename?: string | null;\n\tmimeType?: string | null;\n\tfilesize?: number | null;\n\twidth?: number | null;\n\theight?: number | null;\n\tfocalX?: number | null;\n\tfocalY?: number | null;\n\tsizes?: {\n\t\twebp?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tavif?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tthumbnail?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tthumbnail_webp?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tthumbnail_avif?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tmobile?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tmobile_webp?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tmobile_avif?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\ttablet?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\ttablet_webp?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\ttablet_avif?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t};\n}\n"],"names":[],"mappings":"AAMA,WAuHC"}
@@ -0,0 +1,10 @@
1
+ import type { GlobalConfig, Tab } from 'payload';
2
+ export type SettingsConfig = {
3
+ additionalTabs?: Tab[];
4
+ override: (args: {
5
+ config: GlobalConfig;
6
+ }) => GlobalConfig;
7
+ };
8
+ export type PayloadHelperPluginConfig = {
9
+ settings?: SettingsConfig;
10
+ };
package/dist/types.js ADDED
@@ -0,0 +1,4 @@
1
+ // import type { SEOPluginConfig } from "@payloadcms/plugin-seo/types";
2
+ export { };
3
+
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["// import type { SEOPluginConfig } from \"@payloadcms/plugin-seo/types\";\nimport type { GlobalConfig, Tab } from 'payload';\n\nexport type SettingsConfig = {\n\tadditionalTabs?: Tab[];\n\toverride: (args: {\n\t\tconfig: GlobalConfig;\n\t}) => GlobalConfig;\n};\nexport type PayloadHelperPluginConfig = {\n\tsettings?: SettingsConfig;\n\t// seo?: (args: {\n\t// \tconfig: SEOPluginConfig;\n\t// }) => SEOPluginConfig;\n};\n"],"names":[],"mappings":"AAAA,uEAAuE;AASvE,WAKE"}
@@ -0,0 +1,12 @@
1
+ declare function envFn<T>(key: string, defaultValue: T): string | T;
2
+ declare const env: typeof envFn & {
3
+ isProduction: boolean;
4
+ int(key: string, defaultValue?: number): number | undefined;
5
+ float(key: string, defaultValue?: number): number | undefined;
6
+ bool(key: string, defaultValue?: boolean): boolean | undefined;
7
+ json(key: string, defaultValue?: object): any;
8
+ array(key: string, defaultValue?: string[]): string[] | undefined;
9
+ date(key: string, defaultValue?: Date): Date | undefined;
10
+ oneOf(key: string, expectedValues?: unknown[], defaultValue?: unknown): unknown;
11
+ };
12
+ export default env;
@@ -0,0 +1,75 @@
1
+ function hasKey(key) {
2
+ return Object.prototype.hasOwnProperty.call(process.env, key);
3
+ }
4
+ function envFn(key, defaultValue) {
5
+ return hasKey(key) ? process.env[key] : defaultValue;
6
+ }
7
+ function getKey(key) {
8
+ return process.env[key] ?? '';
9
+ }
10
+ const utils = {
11
+ isProduction: getKey('NODE_ENV') === 'production',
12
+ int (key, defaultValue) {
13
+ if (!hasKey(key)) {
14
+ return defaultValue;
15
+ }
16
+ return Number.parseInt(getKey(key), 10);
17
+ },
18
+ float (key, defaultValue) {
19
+ if (!hasKey(key)) {
20
+ return defaultValue;
21
+ }
22
+ return Number.parseFloat(getKey(key));
23
+ },
24
+ bool (key, defaultValue) {
25
+ if (!hasKey(key)) {
26
+ return defaultValue;
27
+ }
28
+ return getKey(key) === 'true';
29
+ },
30
+ json (key, defaultValue) {
31
+ if (!hasKey(key)) {
32
+ return defaultValue;
33
+ }
34
+ try {
35
+ return JSON.parse(getKey(key));
36
+ } catch (error) {
37
+ if (error instanceof Error) {
38
+ throw new Error(`Invalid json environment variable ${key}: ${error.message}`);
39
+ }
40
+ throw error;
41
+ }
42
+ },
43
+ array (key, defaultValue) {
44
+ if (!hasKey(key)) {
45
+ return defaultValue;
46
+ }
47
+ let value = getKey(key);
48
+ if (value.startsWith('[') && value.endsWith(']')) {
49
+ value = value.substring(1, value.length - 1);
50
+ }
51
+ return value.split(',').map((v)=>{
52
+ return v.trim().replace(/^"(.*)"$/, '$1');
53
+ });
54
+ },
55
+ date (key, defaultValue) {
56
+ if (!hasKey(key)) {
57
+ return defaultValue;
58
+ }
59
+ return new Date(getKey(key));
60
+ },
61
+ oneOf (key, expectedValues, defaultValue) {
62
+ if (!expectedValues) {
63
+ throw new Error('env.oneOf requires expectedValues');
64
+ }
65
+ if (defaultValue && !expectedValues.includes(defaultValue)) {
66
+ throw new Error('env.oneOf requires defaultValue to be included in expectedValues');
67
+ }
68
+ const rawValue = envFn(key, defaultValue);
69
+ return expectedValues.includes(rawValue) ? rawValue : defaultValue;
70
+ }
71
+ };
72
+ const env = Object.assign(envFn, utils);
73
+ export default env;
74
+
75
+ //# sourceMappingURL=env.js.map
@@ -0,0 +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,OAA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AAmB;QACpC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,OAAO,IAAI4B,KAAK3B,OAAOT;IACxB;IAEAqC,OAAMrC,GAAW,EAAEsC,cAA0B,EAAE9B,YAAsB;QACpE,IAAI,CAAC8B,gBAAgB;YACpB,MAAM,IAAIhB,MAAM;QACjB;QAEA,IAAId,gBAAgB,CAAC8B,eAAeC,QAAQ,CAAC/B,eAAe;YAC3D,MAAM,IAAIc,MAAM;QACjB;QAEA,MAAMkB,WAAWjC,MAAMP,KAAKQ;QAC5B,OAAO8B,eAAeC,QAAQ,CAACC,YAAYA,WAAWhC;IACvD;AACD;AAEA,MAAMF,MAAML,OAAOwC,MAAM,CAAClC,OAAOG;AAEjC,eAAeJ,IAAI"}
@@ -0,0 +1,7 @@
1
+ import type { Field } from 'payload';
2
+ /**
3
+ * Determines if a Payload field has a name property.
4
+ *
5
+ * @param field
6
+ */
7
+ export declare const fieldHasName: (field: Field) => boolean;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Determines if a Payload field has a name property.
3
+ *
4
+ * @param field
5
+ */ export const fieldHasName = (field)=>{
6
+ if (field.type === 'ui') {
7
+ return false;
8
+ }
9
+ return field.type !== 'tabs' && field.type !== 'row' && field.type !== 'collapsible';
10
+ };
11
+
12
+ //# sourceMappingURL=fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/fields.ts"],"sourcesContent":["import type { Field } from 'payload';\n\n/**\n * Determines if a Payload field has a name property.\n *\n * @param field\n */\nexport const fieldHasName = (field: Field): boolean => {\n\tif (field.type === 'ui') {\n\t\treturn false;\n\t}\n\treturn field.type !== 'tabs' && field.type !== 'row' && field.type !== 'collapsible';\n};\n"],"names":["fieldHasName","field","type"],"mappings":"AAEA;;;;CAIC,GACD,OAAO,MAAMA,eAAe,CAACC;IAC5B,IAAIA,MAAMC,IAAI,KAAK,MAAM;QACxB,OAAO;IACR;IACA,OAAOD,MAAMC,IAAI,KAAK,UAAUD,MAAMC,IAAI,KAAK,SAASD,MAAMC,IAAI,KAAK;AACxE,EAAE"}
@@ -0,0 +1,15 @@
1
+ import type { SerializedEditorState } from 'lexical';
2
+ /**
3
+ * Converts an HTML string to a Lexical editor state.
4
+ *
5
+ * @param {string} html - The HTML string to convert.
6
+ * @returns {SerializedEditorState} The serialized editor state.
7
+ */
8
+ export declare const htmlToLexical: (html: string) => SerializedEditorState;
9
+ /**
10
+ * Converts a Lexical editor state to an HTML string.
11
+ *
12
+ * @param {SerializedEditorState} json - The serialized editor state to convert.
13
+ * @returns {string} The HTML string.
14
+ */
15
+ export declare const lexicalToHtml: (json: SerializedEditorState) => string;
@@ -0,0 +1,123 @@
1
+ import { createHeadlessEditor } from '@lexical/headless';
2
+ import { $generateHtmlFromNodes, $generateNodesFromDOM } from '@lexical/html';
3
+ // import { sqliteAdapter } from '@payloadcms/db-sqlite';
4
+ // import {
5
+ // defaultEditorConfig,
6
+ // getEnabledNodes,
7
+ // lexicalEditor,
8
+ // sanitizeServerEditorConfig,
9
+ // } from '@payloadcms/richtext-lexical';
10
+ import { JSDOM } from 'jsdom';
11
+ import { $getRoot, $getSelection } from 'lexical';
12
+ // import { buildConfig, getPayload } from 'payload';
13
+ // import { importWithoutClientFiles } from 'payload/node';
14
+ // const loadEditor = async (): Promise<LexicalEditor> => {
15
+ // const config = {
16
+ // secret: 'testing',
17
+ // editor: lexicalEditor({
18
+ // admin: {
19
+ // hideGutter: false,
20
+ // },
21
+ // }),
22
+ // db: sqliteAdapter({
23
+ // client: {
24
+ // url: 'file:./local.db',
25
+ // },
26
+ // }),
27
+ // };
28
+ //
29
+ // const instance = await getPayload({
30
+ // config: buildConfig(config),
31
+ // });
32
+ //
33
+ // const editorConfig = await sanitizeServerEditorConfig(defaultEditorConfig, instance.config);
34
+ //
35
+ // return createHeadlessEditor({
36
+ // nodes: getEnabledNodes({
37
+ // editorConfig,
38
+ // }),
39
+ // });
40
+ // };
41
+ /**
42
+ * Converts an HTML string to a Lexical editor state.
43
+ *
44
+ * @param {string} html - The HTML string to convert.
45
+ * @returns {SerializedEditorState} The serialized editor state.
46
+ */ export const htmlToLexical = (html)=>{
47
+ const editor = createHeadlessEditor({
48
+ nodes: [],
49
+ onError: (error)=>{
50
+ console.error(error);
51
+ }
52
+ });
53
+ editor.update(()=>{
54
+ // In a headless environment you can use a package such as JSDom to parse the HTML string.
55
+ const dom = new JSDOM(`<!DOCTYPE html><body>${html}</body>`);
56
+ // Once you have the DOM instance it's easy to generate LexicalNodes.
57
+ const nodes = $generateNodesFromDOM(editor, dom.window.document);
58
+ // Select the root
59
+ $getRoot().select();
60
+ // Insert them at a selection.
61
+ const selection = $getSelection();
62
+ if (selection) selection.insertNodes(nodes);
63
+ }, {
64
+ discrete: true
65
+ });
66
+ return editor.getEditorState().toJSON();
67
+ // let state = {};
68
+ //
69
+ // loadEditor().then((editor) => {
70
+ // editor.update(
71
+ // () => {
72
+ // // In a headless environment you can use a package such as JSDom to parse the HTML string.
73
+ // const dom = new JSDOM(`<!DOCTYPE html><body>${html}</body>`);
74
+ //
75
+ // // Once you have the DOM instance it's easy to generate LexicalNodes.
76
+ // const nodes = $generateNodesFromDOM(editor, dom.window.document);
77
+ //
78
+ // // Select the root
79
+ // $getRoot().select();
80
+ //
81
+ // // Insert them at a selection.
82
+ // const selection = $getSelection();
83
+ //
84
+ // if (selection) selection.insertNodes(nodes);
85
+ // },
86
+ // { discrete: true },
87
+ // );
88
+ //
89
+ // state = editor.getEditorState().toJSON();
90
+ // });
91
+ //
92
+ // return state as SerializedEditorState;
93
+ };
94
+ /**
95
+ * Converts a Lexical editor state to an HTML string.
96
+ *
97
+ * @param {SerializedEditorState} json - The serialized editor state to convert.
98
+ * @returns {string} The HTML string.
99
+ */ export const lexicalToHtml = (json)=>{
100
+ const editor = createHeadlessEditor({
101
+ nodes: [],
102
+ onError: (error)=>{
103
+ console.error(error);
104
+ }
105
+ });
106
+ // Initialize a JSDOM instance
107
+ const dom = new JSDOM('');
108
+ // @ts-ignore
109
+ globalThis.window = dom.window;
110
+ globalThis.document = dom.window.document;
111
+ editor.update(()=>{
112
+ const editorState = editor.parseEditorState(json);
113
+ editor.setEditorState(editorState);
114
+ });
115
+ // Convert the editor state to HTML
116
+ let html = '';
117
+ editor.getEditorState().read(()=>{
118
+ html = $generateHtmlFromNodes(editor);
119
+ });
120
+ return html;
121
+ };
122
+
123
+ //# sourceMappingURL=lexical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/lexical.ts"],"sourcesContent":["import { createHeadlessEditor } from '@lexical/headless';\nimport { $generateHtmlFromNodes, $generateNodesFromDOM } from '@lexical/html';\n// import { sqliteAdapter } from '@payloadcms/db-sqlite';\n// import {\n// \tdefaultEditorConfig,\n// \tgetEnabledNodes,\n// \tlexicalEditor,\n// \tsanitizeServerEditorConfig,\n// } from '@payloadcms/richtext-lexical';\nimport { JSDOM } from 'jsdom';\nimport { $getRoot, $getSelection, type LexicalEditor } from 'lexical';\nimport type { SerializedEditorState } from 'lexical';\n// import { buildConfig, getPayload } from 'payload';\n// import { importWithoutClientFiles } from 'payload/node';\n\n// const loadEditor = async (): Promise<LexicalEditor> => {\n// \tconst config = {\n// \t\tsecret: 'testing',\n// \t\teditor: lexicalEditor({\n// \t\t\tadmin: {\n// \t\t\t\thideGutter: false,\n// \t\t\t},\n// \t\t}),\n// \t\tdb: sqliteAdapter({\n// \t\t\tclient: {\n// \t\t\t\turl: 'file:./local.db',\n// \t\t\t},\n// \t\t}),\n// \t};\n//\n// \tconst instance = await getPayload({\n// \t\tconfig: buildConfig(config),\n// \t});\n//\n// \tconst editorConfig = await sanitizeServerEditorConfig(defaultEditorConfig, instance.config);\n//\n// \treturn createHeadlessEditor({\n// \t\tnodes: getEnabledNodes({\n// \t\t\teditorConfig,\n// \t\t}),\n// \t});\n// };\n\n/**\n * Converts an HTML string to a Lexical editor state.\n *\n * @param {string} html - The HTML string to convert.\n * @returns {SerializedEditorState} The serialized editor state.\n */\nexport const htmlToLexical = (html: string): SerializedEditorState => {\n\tconst editor = createHeadlessEditor({\n\t\tnodes: [],\n\t\tonError: (error) => {\n\t\t\tconsole.error(error);\n\t\t},\n\t});\n\n\teditor.update(\n\t\t() => {\n\t\t\t// In a headless environment you can use a package such as JSDom to parse the HTML string.\n\t\t\tconst dom = new JSDOM(`<!DOCTYPE html><body>${html}</body>`);\n\n\t\t\t// Once you have the DOM instance it's easy to generate LexicalNodes.\n\t\t\tconst nodes = $generateNodesFromDOM(editor, dom.window.document);\n\n\t\t\t// Select the root\n\t\t\t$getRoot().select();\n\n\t\t\t// Insert them at a selection.\n\t\t\tconst selection = $getSelection();\n\n\t\t\tif (selection) selection.insertNodes(nodes);\n\t\t},\n\t\t{ discrete: true },\n\t);\n\n\treturn editor.getEditorState().toJSON();\n\n\t// let state = {};\n\t//\n\t// loadEditor().then((editor) => {\n\t// \teditor.update(\n\t// \t\t() => {\n\t// \t\t\t// In a headless environment you can use a package such as JSDom to parse the HTML string.\n\t// \t\t\tconst dom = new JSDOM(`<!DOCTYPE html><body>${html}</body>`);\n\t//\n\t// \t\t\t// Once you have the DOM instance it's easy to generate LexicalNodes.\n\t// \t\t\tconst nodes = $generateNodesFromDOM(editor, dom.window.document);\n\t//\n\t// \t\t\t// Select the root\n\t// \t\t\t$getRoot().select();\n\t//\n\t// \t\t\t// Insert them at a selection.\n\t// \t\t\tconst selection = $getSelection();\n\t//\n\t// \t\t\tif (selection) selection.insertNodes(nodes);\n\t// \t\t},\n\t// \t\t{ discrete: true },\n\t// \t);\n\t//\n\t// \tstate = editor.getEditorState().toJSON();\n\t// });\n\t//\n\t// return state as SerializedEditorState;\n};\n\n/**\n * Converts a Lexical editor state to an HTML string.\n *\n * @param {SerializedEditorState} json - The serialized editor state to convert.\n * @returns {string} The HTML string.\n */\nexport const lexicalToHtml = (json: SerializedEditorState): string => {\n\tconst editor = createHeadlessEditor({\n\t\tnodes: [],\n\t\tonError: (error) => {\n\t\t\tconsole.error(error);\n\t\t},\n\t});\n\n\t// Initialize a JSDOM instance\n\tconst dom = new JSDOM('');\n\n\t// @ts-ignore\n\tglobalThis.window = dom.window;\n\tglobalThis.document = dom.window.document;\n\n\teditor.update(() => {\n\t\tconst editorState = editor.parseEditorState(json);\n\t\teditor.setEditorState(editorState);\n\t});\n\n\t// Convert the editor state to HTML\n\tlet html = '';\n\teditor.getEditorState().read(() => {\n\t\thtml = $generateHtmlFromNodes(editor);\n\t});\n\n\treturn html;\n};\n"],"names":["createHeadlessEditor","$generateHtmlFromNodes","$generateNodesFromDOM","JSDOM","$getRoot","$getSelection","htmlToLexical","html","editor","nodes","onError","error","console","update","dom","window","document","select","selection","insertNodes","discrete","getEditorState","toJSON","lexicalToHtml","json","globalThis","editorState","parseEditorState","setEditorState","read"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,oBAAoB;AACzD,SAASC,sBAAsB,EAAEC,qBAAqB,QAAQ,gBAAgB;AAC9E,yDAAyD;AACzD,WAAW;AACX,wBAAwB;AACxB,oBAAoB;AACpB,kBAAkB;AAClB,+BAA+B;AAC/B,yCAAyC;AACzC,SAASC,KAAK,QAAQ,QAAQ;AAC9B,SAASC,QAAQ,EAAEC,aAAa,QAA4B,UAAU;AAEtE,qDAAqD;AACrD,2DAA2D;AAE3D,2DAA2D;AAC3D,oBAAoB;AACpB,uBAAuB;AACvB,4BAA4B;AAC5B,cAAc;AACd,yBAAyB;AACzB,QAAQ;AACR,QAAQ;AACR,wBAAwB;AACxB,eAAe;AACf,8BAA8B;AAC9B,QAAQ;AACR,QAAQ;AACR,MAAM;AACN,EAAE;AACF,uCAAuC;AACvC,iCAAiC;AACjC,OAAO;AACP,EAAE;AACF,gGAAgG;AAChG,EAAE;AACF,iCAAiC;AACjC,6BAA6B;AAC7B,mBAAmB;AACnB,QAAQ;AACR,OAAO;AACP,KAAK;AAEL;;;;;CAKC,GACD,OAAO,MAAMC,gBAAgB,CAACC;IAC7B,MAAMC,SAASR,qBAAqB;QACnCS,OAAO,EAAE;QAC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IACXC,OAAOa,cAAc,GAAGQ,IAAI,CAAC;QAC5BtB,OAAON,uBAAuBO;IAC/B;IAEA,OAAOD;AACR,EAAE"}
@@ -0,0 +1,21 @@
1
+ import { htmlToLexical } from './lexical';
2
+ describe('htmlToLexical', ()=>{
3
+ it('should convert an HTML string to a Lexical editor state', ()=>{
4
+ const html = '<p>Hello, world!</p>';
5
+ const editorState = htmlToLexical(html);
6
+ expect(editorState).toEqual({
7
+ nodes: [
8
+ {
9
+ type: 'paragraph',
10
+ children: [
11
+ {
12
+ text: 'Hello, world!'
13
+ }
14
+ ]
15
+ }
16
+ ]
17
+ });
18
+ });
19
+ });
20
+
21
+ //# sourceMappingURL=lexical.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/lexical.test.ts"],"sourcesContent":["import { htmlToLexical } from './lexical';\n\ndescribe('htmlToLexical', () => {\n\tit('should convert an HTML string to a Lexical editor state', () => {\n\t\tconst html = '<p>Hello, world!</p>';\n\t\tconst editorState = htmlToLexical(html);\n\n\t\texpect(editorState).toEqual({\n\t\t\tnodes: [\n\t\t\t\t{\n\t\t\t\t\ttype: 'paragraph',\n\t\t\t\t\tchildren: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttext: 'Hello, world!',\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});\n\t});\n});\n"],"names":["htmlToLexical","describe","it","html","editorState","expect","toEqual","nodes","type","children","text"],"mappings":"AAAA,SAASA,aAAa,QAAQ,YAAY;AAE1CC,SAAS,iBAAiB;IACzBC,GAAG,2DAA2D;QAC7D,MAAMC,OAAO;QACb,MAAMC,cAAcJ,cAAcG;QAElCE,OAAOD,aAAaE,OAAO,CAAC;YAC3BC,OAAO;gBACN;oBACCC,MAAM;oBACNC,UAAU;wBACT;4BACCC,MAAM;wBACP;qBACA;gBACF;aACA;QACF;IACD;AACD"}
@@ -0,0 +1,2 @@
1
+ export declare const validateURL: (value: string) => Promise<true | "Please enter a valid URL">;
2
+ export declare const validatePostcode: (value: string) => Promise<true | "Invalid postcode format">;
@@ -0,0 +1,23 @@
1
+ export const validateURL = async (value)=>{
2
+ if (!value) {
3
+ return true;
4
+ }
5
+ try {
6
+ new URL(value);
7
+ return true;
8
+ } catch (error) {
9
+ return 'Please enter a valid URL';
10
+ }
11
+ };
12
+ export const validatePostcode = async (value)=>{
13
+ if (!value) {
14
+ return true;
15
+ }
16
+ const postcodeRegex = /^[A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}$/i;
17
+ if (!postcodeRegex.test(value)) {
18
+ return 'Invalid postcode format';
19
+ }
20
+ return true;
21
+ };
22
+
23
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/validation.ts"],"sourcesContent":["export const validateURL = async (value: string) => {\n\tif (!value) {\n\t\treturn true;\n\t}\n\ttry {\n\t\tnew URL(value);\n\t\treturn true;\n\t} catch (error) {\n\t\treturn 'Please enter a valid URL';\n\t}\n};\n\nexport const validatePostcode = async (value: string) => {\n\tif (!value) {\n\t\treturn true;\n\t}\n\tconst postcodeRegex = /^[A-Z]{1,2}\\d[A-Z\\d]? ?\\d[A-Z]{2}$/i;\n\tif (!postcodeRegex.test(value)) {\n\t\treturn 'Invalid postcode format';\n\t}\n\treturn true;\n};\n"],"names":["validateURL","value","URL","error","validatePostcode","postcodeRegex","test"],"mappings":"AAAA,OAAO,MAAMA,cAAc,OAAOC;IACjC,IAAI,CAACA,OAAO;QACX,OAAO;IACR;IACA,IAAI;QACH,IAAIC,IAAID;QACR,OAAO;IACR,EAAE,OAAOE,OAAO;QACf,OAAO;IACR;AACD,EAAE;AAEF,OAAO,MAAMC,mBAAmB,OAAOH;IACtC,IAAI,CAACA,OAAO;QACX,OAAO;IACR;IACA,MAAMI,gBAAgB;IACtB,IAAI,CAACA,cAAcC,IAAI,CAACL,QAAQ;QAC/B,OAAO;IACR;IACA,OAAO;AACR,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainsleydev/payload-helper",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Payload CMS utilities, collections and global types for ainsley.dev builds",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -23,7 +23,7 @@
23
23
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
24
24
  "format": "biome format --write . --apply-unsafe --organise-imports",
25
25
  "lint": "biome lint --write .",
26
- "release": "pnpm build & npm publish --access public",
26
+ "release": "pnpm build && npm publish --access public",
27
27
  "clean": "rimraf {dist,*.tsbuildinfo}",
28
28
  "test": "jest"
29
29
  },