payload 4.0.0-internal.5f0cd13 → 4.0.0-internal.a0ef1b8
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/admin/RichText.d.ts +22 -2
- package/dist/admin/RichText.d.ts.map +1 -1
- package/dist/admin/RichText.js.map +1 -1
- package/dist/admin/adapters/devReload.d.ts +9 -0
- package/dist/admin/adapters/devReload.d.ts.map +1 -0
- package/dist/admin/adapters/devReload.js +6 -0
- package/dist/admin/adapters/devReload.js.map +1 -0
- package/dist/admin/adapters/index.d.ts +3 -0
- package/dist/admin/adapters/index.d.ts.map +1 -1
- package/dist/admin/adapters/index.js.map +1 -1
- package/dist/admin/adapters/render.d.ts +16 -0
- package/dist/admin/adapters/render.d.ts.map +1 -0
- package/dist/admin/adapters/render.js +7 -0
- package/dist/admin/adapters/render.js.map +1 -0
- package/dist/admin/adapters/views.d.ts +36 -0
- package/dist/admin/adapters/views.d.ts.map +1 -0
- package/dist/admin/adapters/views.js +7 -0
- package/dist/admin/adapters/views.js.map +1 -0
- package/dist/admin/forms/Field.d.ts +7 -0
- package/dist/admin/forms/Field.d.ts.map +1 -1
- package/dist/admin/forms/Field.js.map +1 -1
- package/dist/admin/forms/Form.d.ts +29 -0
- package/dist/admin/forms/Form.d.ts.map +1 -1
- package/dist/admin/forms/Form.js.map +1 -1
- package/dist/admin/functions/index.d.ts +9 -0
- package/dist/admin/functions/index.d.ts.map +1 -1
- package/dist/admin/functions/index.js.map +1 -1
- package/dist/admin/types.d.ts +1 -1
- package/dist/admin/types.d.ts.map +1 -1
- package/dist/admin/types.js.map +1 -1
- package/dist/admin/views/dashboard.d.ts +7 -0
- package/dist/admin/views/dashboard.d.ts.map +1 -1
- package/dist/admin/views/dashboard.js.map +1 -1
- package/dist/admin/views/document.d.ts +7 -1
- package/dist/admin/views/document.d.ts.map +1 -1
- package/dist/admin/views/document.js.map +1 -1
- package/dist/auth/defaultAccess.d.ts +1 -1
- package/dist/auth/defaultAccess.d.ts.map +1 -1
- package/dist/auth/defaultAccess.js +1 -1
- package/dist/auth/defaultAccess.js.map +1 -1
- package/dist/auth/defaultUser.d.ts.map +1 -1
- package/dist/auth/defaultUser.js +2 -1
- package/dist/auth/defaultUser.js.map +1 -1
- package/dist/bin/build.d.ts +25 -0
- package/dist/bin/build.d.ts.map +1 -0
- package/dist/bin/build.js +80 -0
- package/dist/bin/build.js.map +1 -0
- package/dist/bin/build.spec.js +170 -0
- package/dist/bin/build.spec.js.map +1 -0
- package/dist/bin/generateImportMap/index.d.ts.map +1 -1
- package/dist/bin/generateImportMap/index.js +8 -5
- package/dist/bin/generateImportMap/index.js.map +1 -1
- package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.d.ts +5 -1
- package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.d.ts.map +1 -1
- package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js +24 -18
- package/dist/bin/generateImportMap/utilities/resolveImportMapFilePath.js.map +1 -1
- package/dist/bin/generateTypes.d.ts +3 -2
- package/dist/bin/generateTypes.d.ts.map +1 -1
- package/dist/bin/generateTypes.js +4 -0
- package/dist/bin/generateTypes.js.map +1 -1
- package/dist/bin/index.d.ts.map +1 -1
- package/dist/bin/index.js +9 -0
- package/dist/bin/index.js.map +1 -1
- package/dist/bin/loadEnv.d.ts +3 -1
- package/dist/bin/loadEnv.d.ts.map +1 -1
- package/dist/bin/loadEnv.js +40 -10
- package/dist/bin/loadEnv.js.map +1 -1
- package/dist/collections/config/defaults.js +2 -2
- package/dist/collections/config/defaults.js.map +1 -1
- package/dist/collections/config/defaults.spec.js +47 -0
- package/dist/collections/config/defaults.spec.js.map +1 -0
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +1 -0
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/local/duplicate.d.ts.map +1 -1
- package/dist/collections/operations/local/duplicate.js.map +1 -1
- package/dist/collections/operations/local/find.d.ts.map +1 -1
- package/dist/collections/operations/local/find.js.map +1 -1
- package/dist/collections/operations/local/findByID.d.ts.map +1 -1
- package/dist/collections/operations/local/findByID.js.map +1 -1
- package/dist/collections/operations/local/findVersionByID.d.ts.map +1 -1
- package/dist/collections/operations/local/findVersionByID.js.map +1 -1
- package/dist/collections/operations/local/findVersions.d.ts.map +1 -1
- package/dist/collections/operations/local/findVersions.js.map +1 -1
- package/dist/collections/operations/local/restoreVersion.d.ts.map +1 -1
- package/dist/collections/operations/local/restoreVersion.js.map +1 -1
- package/dist/collections/operations/utilities/update.d.ts.map +1 -1
- package/dist/collections/operations/utilities/update.js +16 -8
- package/dist/collections/operations/utilities/update.js.map +1 -1
- package/dist/config/types.d.ts +10 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js +1 -0
- package/dist/config/types.js.map +1 -1
- package/dist/database/migrations/migrationsCollection.d.ts.map +1 -1
- package/dist/database/migrations/migrationsCollection.js +2 -1
- package/dist/database/migrations/migrationsCollection.js.map +1 -1
- package/dist/exports/shared.d.ts +20 -0
- package/dist/exports/shared.d.ts.map +1 -1
- package/dist/exports/shared.js +20 -0
- package/dist/exports/shared.js.map +1 -1
- package/dist/fields/config/client.d.ts +1 -1
- package/dist/fields/config/client.d.ts.map +1 -1
- package/dist/fields/config/client.js +1 -1
- package/dist/fields/config/client.js.map +1 -1
- package/dist/fields/validations.d.ts.map +1 -1
- package/dist/fields/validations.js +5 -4
- package/dist/fields/validations.js.map +1 -1
- package/dist/globals/config/sanitize.d.ts.map +1 -1
- package/dist/globals/config/sanitize.js +1 -0
- package/dist/globals/config/sanitize.js.map +1 -1
- package/dist/globals/config/sanitize.spec.js +43 -0
- package/dist/globals/config/sanitize.spec.js.map +1 -0
- package/dist/globals/operations/local/findOne.d.ts.map +1 -1
- package/dist/globals/operations/local/findOne.js.map +1 -1
- package/dist/globals/operations/local/update.d.ts.map +1 -1
- package/dist/globals/operations/local/update.js.map +1 -1
- package/dist/index.bundled.d.ts +178 -17
- package/dist/index.d.ts +8 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +50 -33
- package/dist/index.js.map +1 -1
- package/dist/kv/adapters/DatabaseKVAdapter.d.ts.map +1 -1
- package/dist/kv/adapters/DatabaseKVAdapter.js +1 -0
- package/dist/kv/adapters/DatabaseKVAdapter.js.map +1 -1
- package/dist/locked-documents/config.d.ts.map +1 -1
- package/dist/locked-documents/config.js +2 -1
- package/dist/locked-documents/config.js.map +1 -1
- package/dist/preferences/config.d.ts.map +1 -1
- package/dist/preferences/config.js +2 -1
- package/dist/preferences/config.js.map +1 -1
- package/dist/query-presets/config.d.ts.map +1 -1
- package/dist/query-presets/config.js +2 -1
- package/dist/query-presets/config.js.map +1 -1
- package/dist/queues/config/collection.d.ts.map +1 -1
- package/dist/queues/config/collection.js +2 -1
- package/dist/queues/config/collection.js.map +1 -1
- package/dist/queues/config/generateJobsJSONSchemas.js +2 -2
- package/dist/queues/config/generateJobsJSONSchemas.js.map +1 -1
- package/dist/queues/config/global.d.ts.map +1 -1
- package/dist/queues/config/global.js +2 -1
- package/dist/queues/config/global.js.map +1 -1
- package/dist/uploads/fetchAPI-multipart/processMultipart.d.ts.map +1 -1
- package/dist/uploads/fetchAPI-multipart/processMultipart.js +14 -1
- package/dist/uploads/fetchAPI-multipart/processMultipart.js.map +1 -1
- package/dist/uploads/generateFileData.d.ts +2 -1
- package/dist/uploads/generateFileData.d.ts.map +1 -1
- package/dist/uploads/generateFileData.js +5 -2
- package/dist/uploads/generateFileData.js.map +1 -1
- package/dist/uploads/safeFetch.d.ts.map +1 -1
- package/dist/uploads/safeFetch.js +11 -5
- package/dist/uploads/safeFetch.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts +25 -0
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +73 -31
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/configToJSONSchema.spec.js +216 -29
- package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
- package/dist/utilities/dependencies/dependencyChecker.js +1 -1
- package/dist/utilities/dependencies/dependencyChecker.js.map +1 -1
- package/dist/utilities/dependencies/getDependencies.d.ts.map +1 -1
- package/dist/utilities/dependencies/getDependencies.js +5 -5
- package/dist/utilities/dependencies/getDependencies.js.map +1 -1
- package/dist/utilities/dynamicImport.js +1 -1
- package/dist/utilities/dynamicImport.js.map +1 -1
- package/dist/utilities/formatErrors.d.ts.map +1 -1
- package/dist/utilities/formatErrors.js +3 -1
- package/dist/utilities/formatErrors.js.map +1 -1
- package/dist/utilities/getRequestLanguage.d.ts +2 -2
- package/dist/utilities/getRequestLanguage.d.ts.map +1 -1
- package/dist/utilities/getRequestLanguage.js.map +1 -1
- package/dist/utilities/handleEndpoints.d.ts.map +1 -1
- package/dist/utilities/handleEndpoints.js +7 -3
- package/dist/utilities/handleEndpoints.js.map +1 -1
- package/dist/utilities/isRSCEnabled.d.ts +12 -0
- package/dist/utilities/isRSCEnabled.d.ts.map +1 -0
- package/dist/utilities/isRSCEnabled.js +14 -0
- package/dist/utilities/isRSCEnabled.js.map +1 -0
- package/dist/utilities/telemetry/conf/envPaths.d.ts.map +1 -1
- package/dist/utilities/telemetry/conf/envPaths.js +31 -40
- package/dist/utilities/telemetry/conf/envPaths.js.map +1 -1
- package/dist/utilities/transformColumnPreferences.js +4 -2
- package/dist/utilities/transformColumnPreferences.js.map +1 -1
- package/package.json +8 -5
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
2
|
import process from 'node:process';
|
|
3
|
+
import { getLogger } from '../../utilities/logger.js';
|
|
3
4
|
import { iterateConfig } from './iterateConfig.js';
|
|
4
5
|
import { addPayloadComponentToImportMap } from './utilities/addPayloadComponentToImportMap.js';
|
|
5
6
|
import { getImportMapToBaseDirPath } from './utilities/getImportMapToBaseDirPath.js';
|
|
6
7
|
import { resolveImportMapFilePath } from './utilities/resolveImportMapFilePath.js';
|
|
7
8
|
export async function generateImportMap(config, options) {
|
|
9
|
+
const logger = getLogger('payload', 'sync');
|
|
8
10
|
const shouldLog = options?.log ?? true;
|
|
9
11
|
if (shouldLog) {
|
|
10
|
-
|
|
12
|
+
logger.info('Generating import map');
|
|
11
13
|
}
|
|
12
14
|
const importMap = {};
|
|
13
15
|
const imports = {};
|
|
@@ -35,7 +37,7 @@ export async function generateImportMap(config, options) {
|
|
|
35
37
|
return;
|
|
36
38
|
}
|
|
37
39
|
if (typeof payloadComponent !== 'object' && typeof payloadComponent !== 'string') {
|
|
38
|
-
|
|
40
|
+
logger.error(payloadComponent);
|
|
39
41
|
throw new Error('addToImportMap > Payload component must be an object or a string');
|
|
40
42
|
}
|
|
41
43
|
if (Array.isArray(payloadComponent)) {
|
|
@@ -72,6 +74,7 @@ export async function generateImportMap(config, options) {
|
|
|
72
74
|
});
|
|
73
75
|
}
|
|
74
76
|
export async function writeImportMap({ componentMap, force, importMap, importMapFilePath, log }) {
|
|
77
|
+
const logger = getLogger('payload', 'sync');
|
|
75
78
|
const imports = [];
|
|
76
79
|
for (const [identifier, { path, specifier }] of Object.entries(importMap)){
|
|
77
80
|
imports.push(`import { ${specifier} as ${identifier} } from '${path}'`);
|
|
@@ -92,13 +95,13 @@ ${mapKeys.join(',\n')}
|
|
|
92
95
|
const currentImportMap = await fs.readFile(importMapFilePath, 'utf-8');
|
|
93
96
|
if (currentImportMap?.trim() === importMapOutputFile?.trim()) {
|
|
94
97
|
if (log) {
|
|
95
|
-
|
|
98
|
+
logger.info('No new imports found, skipping writing import map');
|
|
96
99
|
}
|
|
97
100
|
return;
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
if (log) {
|
|
101
|
-
|
|
104
|
+
logger.info(`Writing import map to ${importMapFilePath}`);
|
|
102
105
|
}
|
|
103
106
|
await fs.writeFile(importMapFilePath, importMapOutputFile);
|
|
104
107
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/bin/generateImportMap/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/bin/generateImportMap/index.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport process from 'node:process'\n\nimport type { PayloadComponent, SanitizedConfig } from '../../config/types.js'\n\nimport { getLogger } from '../../utilities/logger.js'\nimport { iterateConfig } from './iterateConfig.js'\nimport { addPayloadComponentToImportMap } from './utilities/addPayloadComponentToImportMap.js'\nimport { getImportMapToBaseDirPath } from './utilities/getImportMapToBaseDirPath.js'\nimport { resolveImportMapFilePath } from './utilities/resolveImportMapFilePath.js'\n\ntype ImportIdentifier = string\ntype ImportSpecifier = string\ntype ImportPath = string\ntype UserImportPath = string\n\n/**\n * Import Map before being written to the file. Only contains all paths\n */\nexport type InternalImportMap = {\n [path: UserImportPath]: ImportIdentifier\n}\n\n/**\n * Imports of the import map.\n */\nexport type Imports = {\n [identifier: ImportIdentifier]: {\n path: ImportPath\n specifier: ImportSpecifier\n }\n}\n\n/**\n * Import Map after being imported from the actual import map. Contains all the actual imported components\n */\nexport type ImportMap = {\n [path: UserImportPath]: any\n}\n\nexport type AddToImportMap = (payloadComponent?: PayloadComponent | PayloadComponent[]) => void\n\nexport async function generateImportMap(\n config: SanitizedConfig,\n options?: {\n force?: boolean /**\n * If true, will not throw an error if the import map file path cannot be resolved\n Instead, it will return silently.\n */\n ignoreResolveError?: boolean\n log: boolean\n },\n): Promise<void> {\n const logger = getLogger('payload', 'sync')\n const shouldLog = options?.log ?? true\n\n if (shouldLog) {\n logger.info('Generating import map')\n }\n\n const importMap: InternalImportMap = {}\n const imports: Imports = {}\n\n // Determine the root directory of the project - usually the directory where the src or app folder is located\n const rootDir = process.env.ROOT_DIR ?? process.cwd()\n\n const baseDir = config.admin.importMap.baseDir ?? process.cwd()\n\n const importMapFilePath = await resolveImportMapFilePath({\n adminRoute: config.routes.admin,\n importMapFile: config?.admin?.importMap?.importMapFile,\n rootDir,\n })\n\n if (importMapFilePath instanceof Error) {\n if (options?.ignoreResolveError) {\n return\n } else {\n throw importMapFilePath\n }\n }\n\n const importMapToBaseDirPath = getImportMapToBaseDirPath({\n baseDir,\n importMapPath: importMapFilePath,\n })\n\n const addToImportMap: AddToImportMap = (payloadComponent) => {\n if (!payloadComponent) {\n return\n }\n\n if (typeof payloadComponent !== 'object' && typeof payloadComponent !== 'string') {\n logger.error(payloadComponent)\n throw new Error('addToImportMap > Payload component must be an object or a string')\n }\n\n if (Array.isArray(payloadComponent)) {\n for (const component of payloadComponent) {\n addPayloadComponentToImportMap({\n importMap,\n importMapToBaseDirPath,\n imports,\n payloadComponent: component,\n })\n }\n } else {\n addPayloadComponentToImportMap({\n importMap,\n importMapToBaseDirPath,\n imports,\n payloadComponent,\n })\n }\n }\n\n iterateConfig({\n addToImportMap,\n baseDir: config.admin.importMap.baseDir,\n config,\n importMap,\n imports,\n })\n\n await writeImportMap({\n componentMap: importMap,\n force: options?.force,\n importMap: imports,\n importMapFilePath,\n log: shouldLog,\n })\n}\n\nexport async function writeImportMap({\n componentMap,\n force,\n importMap,\n importMapFilePath,\n log,\n}: {\n componentMap: InternalImportMap\n force?: boolean\n importMap: Imports\n importMapFilePath: string\n log?: boolean\n}) {\n const logger = getLogger('payload', 'sync')\n const imports: string[] = []\n for (const [identifier, { path, specifier }] of Object.entries(importMap)) {\n imports.push(`import { ${specifier} as ${identifier} } from '${path}'`)\n }\n\n const mapKeys: string[] = []\n for (const [userPath, identifier] of Object.entries(componentMap)) {\n mapKeys.push(` \"${userPath}\": ${identifier}`)\n }\n\n const importMapOutputFile = `${imports.join('\\n')}\n\n/** @type import('payload').ImportMap */\nexport const importMap = {\n${mapKeys.join(',\\n')}\n}\n`\n\n if (!force) {\n // Read current import map and check in the IMPORTS if there are any new imports. If not, don't write the file.\n const currentImportMap = await fs.readFile(importMapFilePath, 'utf-8')\n\n if (currentImportMap?.trim() === importMapOutputFile?.trim()) {\n if (log) {\n logger.info('No new imports found, skipping writing import map')\n }\n return\n }\n }\n\n if (log) {\n logger.info(`Writing import map to ${importMapFilePath}`)\n }\n\n await fs.writeFile(importMapFilePath, importMapOutputFile)\n}\n"],"names":["fs","process","getLogger","iterateConfig","addPayloadComponentToImportMap","getImportMapToBaseDirPath","resolveImportMapFilePath","generateImportMap","config","options","logger","shouldLog","log","info","importMap","imports","rootDir","env","ROOT_DIR","cwd","baseDir","admin","importMapFilePath","adminRoute","routes","importMapFile","Error","ignoreResolveError","importMapToBaseDirPath","importMapPath","addToImportMap","payloadComponent","error","Array","isArray","component","writeImportMap","componentMap","force","identifier","path","specifier","Object","entries","push","mapKeys","userPath","importMapOutputFile","join","currentImportMap","readFile","trim","writeFile"],"mappings":"AAAA,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,aAAa,eAAc;AAIlC,SAASC,SAAS,QAAQ,4BAA2B;AACrD,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,8BAA8B,QAAQ,gDAA+C;AAC9F,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,wBAAwB,QAAQ,0CAAyC;AAiClF,OAAO,eAAeC,kBACpBC,MAAuB,EACvBC,OAOC;IAED,MAAMC,SAASR,UAAU,WAAW;IACpC,MAAMS,YAAYF,SAASG,OAAO;IAElC,IAAID,WAAW;QACbD,OAAOG,IAAI,CAAC;IACd;IAEA,MAAMC,YAA+B,CAAC;IACtC,MAAMC,UAAmB,CAAC;IAE1B,6GAA6G;IAC7G,MAAMC,UAAUf,QAAQgB,GAAG,CAACC,QAAQ,IAAIjB,QAAQkB,GAAG;IAEnD,MAAMC,UAAUZ,OAAOa,KAAK,CAACP,SAAS,CAACM,OAAO,IAAInB,QAAQkB,GAAG;IAE7D,MAAMG,oBAAoB,MAAMhB,yBAAyB;QACvDiB,YAAYf,OAAOgB,MAAM,CAACH,KAAK;QAC/BI,eAAejB,QAAQa,OAAOP,WAAWW;QACzCT;IACF;IAEA,IAAIM,6BAA6BI,OAAO;QACtC,IAAIjB,SAASkB,oBAAoB;YAC/B;QACF,OAAO;YACL,MAAML;Q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AAMQ,sBAAsB,GAAGhC,QAAQiC,IAAI,CAAC,MAAM;;;;AAIpD,EAAEH,QAAQG,IAAI,CAAC,OAAO;;AAEtB,CAAC;IAEC,IAAI,CAACV,OAAO;QACV,+GAA+G;QAC/G,MAAMW,mBAAmB,MAAMjD,GAAGkD,QAAQ,CAAC5B,mBAAmB;QAE9D,IAAI2B,kBAAkBE,WAAWJ,qBAAqBI,QAAQ;YAC5D,IAAIvC,KAAK;gBACPF,OAAOG,IAAI,CAAC;YACd;YACA;QACF;IACF;IAEA,IAAID,KAAK;QACPF,OAAOG,IAAI,CAAC,CAAC,sBAAsB,EAAES,mBAAmB;IAC1D;IAEA,MAAMtB,GAAGoD,SAAS,CAAC9B,mBAAmByB;AACxC"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns the path to the import map file. If the import map file is not found, it throws an error.
|
|
3
|
+
*
|
|
4
|
+
* @param candidateDirectories - Optional array of directory paths to search for the import map.
|
|
5
|
+
* Defaults to Next.js app directory convention. Framework adapters can provide their own.
|
|
3
6
|
*/
|
|
4
|
-
export declare function resolveImportMapFilePath({ adminRoute, importMapFile, rootDir, }: {
|
|
7
|
+
export declare function resolveImportMapFilePath({ adminRoute, candidateDirectories, importMapFile, rootDir, }: {
|
|
5
8
|
adminRoute?: string;
|
|
9
|
+
candidateDirectories?: string[];
|
|
6
10
|
importMapFile?: string;
|
|
7
11
|
rootDir: string;
|
|
8
12
|
}): Promise<Error | string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveImportMapFilePath.d.ts","sourceRoot":"","sources":["../../../../src/bin/generateImportMap/utilities/resolveImportMapFilePath.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolveImportMapFilePath.d.ts","sourceRoot":"","sources":["../../../../src/bin/generateImportMap/utilities/resolveImportMapFilePath.ts"],"names":[],"mappings":"AAqBA;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAAC,EAC7C,UAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,OAAO,GACR,EAAE;IACD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG,OAAO,CAAC,KAAK,GAAG,MAAM,CAAC,CAkC1B"}
|
|
@@ -8,9 +8,19 @@ async function pathOrFileExists(path) {
|
|
|
8
8
|
return false;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Default directory patterns for Next.js import map resolution.
|
|
13
|
+
* Other framework adapters can provide their own patterns via `candidateDirectories`.
|
|
14
|
+
*/ const defaultCandidateDirectories = (rootDir, adminRoute)=>[
|
|
15
|
+
path.resolve(rootDir, `app/(payload)${adminRoute}/`),
|
|
16
|
+
path.resolve(rootDir, `src/app/(payload)${adminRoute}/`)
|
|
17
|
+
];
|
|
11
18
|
/**
|
|
12
19
|
* Returns the path to the import map file. If the import map file is not found, it throws an error.
|
|
13
|
-
|
|
20
|
+
*
|
|
21
|
+
* @param candidateDirectories - Optional array of directory paths to search for the import map.
|
|
22
|
+
* Defaults to Next.js app directory convention. Framework adapters can provide their own.
|
|
23
|
+
*/ export async function resolveImportMapFilePath({ adminRoute = '/admin', candidateDirectories, importMapFile, rootDir }) {
|
|
14
24
|
let importMapFilePath = undefined;
|
|
15
25
|
if (importMapFile?.length) {
|
|
16
26
|
if (!await pathOrFileExists(importMapFile)) {
|
|
@@ -24,24 +34,20 @@ async function pathOrFileExists(path) {
|
|
|
24
34
|
}
|
|
25
35
|
importMapFilePath = importMapFile;
|
|
26
36
|
} else {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
const directories = candidateDirectories ?? defaultCandidateDirectories(rootDir, adminRoute);
|
|
38
|
+
for (const dir of directories){
|
|
39
|
+
if (await pathOrFileExists(dir)) {
|
|
40
|
+
importMapFilePath = path.resolve(dir, 'importMap.js');
|
|
41
|
+
if (!await pathOrFileExists(importMapFilePath)) {
|
|
42
|
+
await fs.writeFile(importMapFilePath, '', {
|
|
43
|
+
flag: 'wx'
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
35
47
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
await fs.writeFile(importMapFilePath, '', {
|
|
40
|
-
flag: 'wx'
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
return new Error(`Could not find Payload import map folder. Looked in ${appLocation} and ${srcAppLocation}`);
|
|
48
|
+
}
|
|
49
|
+
if (!importMapFilePath) {
|
|
50
|
+
return new Error(`Could not find Payload import map folder. Looked in ${directories.join(' and ')}`);
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
53
|
return importMapFilePath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/bin/generateImportMap/utilities/resolveImportMapFilePath.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\n\nasync function pathOrFileExists(path: string): Promise<boolean> {\n try {\n await fs.access(path)\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Returns the path to the import map file. If the import map file is not found, it throws an error.\n */\nexport async function resolveImportMapFilePath({\n adminRoute = '/admin',\n importMapFile,\n rootDir,\n}: {\n adminRoute?: string\n importMapFile?: string\n rootDir: string\n}): Promise<Error | string> {\n let importMapFilePath: string | undefined = undefined\n\n if (importMapFile?.length) {\n if (!(await pathOrFileExists(importMapFile))) {\n try {\n await fs.writeFile(importMapFile, '', { flag: 'wx' })\n } catch (err) {\n return new Error(\n `Could not find the import map file at ${importMapFile}${err instanceof Error && err?.message ? `: ${err.message}` : ''}`,\n )\n }\n }\n importMapFilePath = importMapFile\n } else {\n const
|
|
1
|
+
{"version":3,"sources":["../../../../src/bin/generateImportMap/utilities/resolveImportMapFilePath.ts"],"sourcesContent":["import fs from 'fs/promises'\nimport path from 'path'\n\nasync function pathOrFileExists(path: string): Promise<boolean> {\n try {\n await fs.access(path)\n return true\n } catch {\n return false\n }\n}\n\n/**\n * Default directory patterns for Next.js import map resolution.\n * Other framework adapters can provide their own patterns via `candidateDirectories`.\n */\nconst defaultCandidateDirectories = (rootDir: string, adminRoute: string): string[] => [\n path.resolve(rootDir, `app/(payload)${adminRoute}/`),\n path.resolve(rootDir, `src/app/(payload)${adminRoute}/`),\n]\n\n/**\n * Returns the path to the import map file. If the import map file is not found, it throws an error.\n *\n * @param candidateDirectories - Optional array of directory paths to search for the import map.\n * Defaults to Next.js app directory convention. Framework adapters can provide their own.\n */\nexport async function resolveImportMapFilePath({\n adminRoute = '/admin',\n candidateDirectories,\n importMapFile,\n rootDir,\n}: {\n adminRoute?: string\n candidateDirectories?: string[]\n importMapFile?: string\n rootDir: string\n}): Promise<Error | string> {\n let importMapFilePath: string | undefined = undefined\n\n if (importMapFile?.length) {\n if (!(await pathOrFileExists(importMapFile))) {\n try {\n await fs.writeFile(importMapFile, '', { flag: 'wx' })\n } catch (err) {\n return new Error(\n `Could not find the import map file at ${importMapFile}${err instanceof Error && err?.message ? `: ${err.message}` : ''}`,\n )\n }\n }\n importMapFilePath = importMapFile\n } else {\n const directories = candidateDirectories ?? defaultCandidateDirectories(rootDir, adminRoute)\n\n for (const dir of directories) {\n if (await pathOrFileExists(dir)) {\n importMapFilePath = path.resolve(dir, 'importMap.js')\n if (!(await pathOrFileExists(importMapFilePath))) {\n await fs.writeFile(importMapFilePath, '', { flag: 'wx' })\n }\n break\n }\n }\n\n if (!importMapFilePath) {\n return new Error(\n `Could not find Payload import map folder. Looked in ${directories.join(' and ')}`,\n )\n }\n }\n return importMapFilePath\n}\n"],"names":["fs","path","pathOrFileExists","access","defaultCandidateDirectories","rootDir","adminRoute","resolve","resolveImportMapFilePath","candidateDirectories","importMapFile","importMapFilePath","undefined","length","writeFile","flag","err","Error","message","directories","dir","join"],"mappings":"AAAA,OAAOA,QAAQ,cAAa;AAC5B,OAAOC,UAAU,OAAM;AAEvB,eAAeC,iBAAiBD,IAAY;IAC1C,IAAI;QACF,MAAMD,GAAGG,MAAM,CAACF;QAChB,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEA;;;CAGC,GACD,MAAMG,8BAA8B,CAACC,SAAiBC,aAAiC;QACrFL,KAAKM,OAAO,CAACF,SAAS,CAAC,aAAa,EAAEC,WAAW,CAAC,CAAC;QACnDL,KAAKM,OAAO,CAACF,SAAS,CAAC,iBAAiB,EAAEC,WAAW,CAAC,CAAC;KACxD;AAED;;;;;CAKC,GACD,OAAO,eAAeE,yBAAyB,EAC7CF,aAAa,QAAQ,EACrBG,oBAAoB,EACpBC,aAAa,EACbL,OAAO,EAMR;IACC,IAAIM,oBAAwCC;IAE5C,IAAIF,eAAeG,QAAQ;QACzB,IAAI,CAAE,MAAMX,iBAAiBQ,gBAAiB;YAC5C,IAAI;gBACF,MAAMV,GAAGc,SAAS,CAACJ,eAAe,IAAI;oBAAEK,MAAM;gBAAK;YACrD,EAAE,OAAOC,KAAK;gBACZ,OAAO,IAAIC,MACT,CAAC,sCAAsC,EAAEP,gBAAgBM,eAAeC,SAASD,KAAKE,UAAU,CAAC,EAAE,EAAEF,IAAIE,OAAO,EAAE,GAAG,IAAI;YAE7H;QACF;QACAP,oBAAoBD;IACtB,OAAO;QACL,MAAMS,cAAcV,wBAAwBL,4BAA4BC,SAASC;QAEjF,KAAK,MAAMc,OAAOD,YAAa;YAC7B,IAAI,MAAMjB,iBAAiBkB,MAAM;gBAC/BT,oBAAoBV,KAAKM,OAAO,CAACa,KAAK;gBACtC,IAAI,CAAE,MAAMlB,iBAAiBS,oBAAqB;oBAChD,MAAMX,GAAGc,SAAS,CAACH,mBAAmB,IAAI;wBAAEI,MAAM;oBAAK;gBACzD;gBACA;YACF;QACF;QAEA,IAAI,CAACJ,mBAAmB;YACtB,OAAO,IAAIM,MACT,CAAC,oDAAoD,EAAEE,YAAYE,IAAI,CAAC,UAAU;QAEtF;IACF;IACA,OAAOV;AACT"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SanitizedConfig } from '../config/types.js';
|
|
2
2
|
export declare function generateTypes(config: SanitizedConfig, options?: {
|
|
3
|
-
log
|
|
4
|
-
|
|
3
|
+
log?: boolean;
|
|
4
|
+
returnString?: boolean;
|
|
5
|
+
}): Promise<string | void>;
|
|
5
6
|
//# sourceMappingURL=generateTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.d.ts","sourceRoot":"","sources":["../../src/bin/generateTypes.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAMzD,wBAAsB,aAAa,CACjC,MAAM,EAAE,eAAe,EACvB,OAAO,CAAC,EAAE;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"generateTypes.d.ts","sourceRoot":"","sources":["../../src/bin/generateTypes.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAMzD,wBAAsB,aAAa,CACjC,MAAM,EAAE,eAAe,EACvB,OAAO,CAAC,EAAE;IAAE,GAAG,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,GAClD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAgFxB"}
|
|
@@ -57,6 +57,10 @@ export async function generateTypes(config, options) {
|
|
|
57
57
|
compiled += `\n\n${declare}`;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
+
// Return the generated types instead of writing them to disk.
|
|
61
|
+
if (options?.returnString) {
|
|
62
|
+
return compiled;
|
|
63
|
+
}
|
|
60
64
|
// Diff the compiled types against the existing types file
|
|
61
65
|
try {
|
|
62
66
|
const existingTypes = await fs.readFile(outputFile, 'utf-8');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bin/generateTypes.ts"],"sourcesContent":["import type { AcceptedLanguages } from '@payloadcms/translations'\n\nimport { initI18n } from '@payloadcms/translations'\nimport fs from 'fs/promises'\nimport { compile } from 'json-schema-to-typescript'\n\nimport type { SanitizedConfig } from '../config/types.js'\n\nimport { addSelectGenericsToGeneratedTypes } from '../utilities/addSelectGenericsToGeneretedTypes.js'\nimport { configToJSONSchema } from '../utilities/configToJSONSchema.js'\nimport { getLogger } from '../utilities/logger.js'\n\nexport async function generateTypes(\n config: SanitizedConfig,\n options?: { log
|
|
1
|
+
{"version":3,"sources":["../../src/bin/generateTypes.ts"],"sourcesContent":["import type { AcceptedLanguages } from '@payloadcms/translations'\n\nimport { initI18n } from '@payloadcms/translations'\nimport fs from 'fs/promises'\nimport { compile } from 'json-schema-to-typescript'\n\nimport type { SanitizedConfig } from '../config/types.js'\n\nimport { addSelectGenericsToGeneratedTypes } from '../utilities/addSelectGenericsToGeneretedTypes.js'\nimport { configToJSONSchema } from '../utilities/configToJSONSchema.js'\nimport { getLogger } from '../utilities/logger.js'\n\nexport async function generateTypes(\n config: SanitizedConfig,\n options?: { log?: boolean; returnString?: boolean },\n): Promise<string | void> {\n const logger = getLogger('payload', 'sync')\n const outputFile = process.env.PAYLOAD_TS_OUTPUT_PATH || config.typescript.outputFile\n\n const shouldLog = options?.log ?? true\n\n if (shouldLog) {\n logger.info('Compiling TS types for Collections and Globals...')\n }\n\n const languages = Object.keys(config.i18n.supportedLanguages) as AcceptedLanguages[]\n\n const language = languages.includes('en') ? 'en' : config.i18n.fallbackLanguage\n\n const i18n = await initI18n({ config: config.i18n, context: 'api', language })\n\n const { jsonSchema, typeStringDefinitions } = configToJSONSchema(\n config,\n config.db.defaultIDType,\n i18n,\n )\n\n const declare = `declare module 'payload' {\\n export interface GeneratedTypes extends Config {}\\n}`\n const declareWithTSIgnoreError = `declare module 'payload' {\\n // @ts-ignore \\n export interface GeneratedTypes extends Config {}\\n}`\n\n let compiled = await compile(jsonSchema, 'Config', {\n bannerComment:\n '/* tslint:disable */\\n/* eslint-disable */\\n/**\\n* This file was automatically generated by Payload.\\n* DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config,\\n* and re-run `payload generate:types` to regenerate this file.\\n*/',\n style: {\n singleQuote: true,\n },\n // Generates code for $defs that aren't referenced by the schema. Reason:\n // If a field defines an interfaceName, it should be included in the generated types\n // even if it's not used by another type. Reason: the user might want to use it in their own code.\n unreachableDefinitions: true,\n // Allow resolving external file references in $ref pointers\n cwd: process.cwd(),\n })\n\n compiled = addSelectGenericsToGeneratedTypes({ compiledGeneratedTypes: compiled })\n\n if (typeStringDefinitions.size > 0) {\n const block = [...typeStringDefinitions].join('\\n\\n')\n compiled = `${compiled.trimEnd()}\\n\\n${block}\\n`\n }\n\n if (config.typescript.postProcess?.length) {\n for (const fn of config.typescript.postProcess) {\n compiled = fn({ compiledTypes: compiled, config })\n }\n }\n\n if (config.typescript.declare !== false) {\n if (config.typescript.declare?.ignoreTSError) {\n compiled += `\\n\\n${declareWithTSIgnoreError}`\n } else {\n compiled += `\\n\\n${declare}`\n }\n }\n\n // Return the generated types instead of writing them to disk.\n if (options?.returnString) {\n return compiled\n }\n\n // Diff the compiled types against the existing types file\n try {\n const existingTypes = await fs.readFile(outputFile, 'utf-8')\n\n if (compiled === existingTypes) {\n return\n }\n } catch (_) {\n // swallow err\n }\n\n await fs.writeFile(outputFile, compiled)\n if (shouldLog) {\n logger.info(`Types written to ${outputFile}`)\n }\n}\n"],"names":["initI18n","fs","compile","addSelectGenericsToGeneratedTypes","configToJSONSchema","getLogger","generateTypes","config","options","logger","outputFile","process","env","PAYLOAD_TS_OUTPUT_PATH","typescript","shouldLog","log","info","languages","Object","keys","i18n","supportedLanguages","language","includes","fallbackLanguage","context","jsonSchema","typeStringDefinitions","db","defaultIDType","declare","declareWithTSIgnoreError","compiled","bannerComment","style","singleQuote","unreachableDefinitions","cwd","compiledGeneratedTypes","size","block","join","trimEnd","postProcess","length","fn","compiledTypes","ignoreTSError","returnString","existingTypes","readFile","_","writeFile"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,2BAA0B;AACnD,OAAOC,QAAQ,cAAa;AAC5B,SAASC,OAAO,QAAQ,4BAA2B;AAInD,SAASC,iCAAiC,QAAQ,oDAAmD;AACrG,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,SAAS,QAAQ,yBAAwB;AAElD,OAAO,eAAeC,cACpBC,MAAuB,EACvBC,OAAmD;IAEnD,MAAMC,SAASJ,UAAU,WAAW;IACpC,MAAMK,aAAaC,QAAQC,GAAG,CAACC,sBAAsB,IAAIN,OAAOO,UAAU,CAACJ,UAAU;IAErF,MAAMK,YAAYP,SAASQ,OAAO;IAElC,IAAID,WAAW;QACbN,OAAOQ,IAAI,CAAC;IACd;IAEA,MAAMC,YAAYC,OAAOC,IAAI,CAACb,OAAOc,IAAI,CAACC,kBAAkB;IAE5D,MAAMC,WAAWL,UAAUM,QAAQ,CAAC,QAAQ,OAAOjB,OAAOc,IAAI,CAACI,gBAAgB;IAE/E,MAAMJ,OAAO,MAAMrB,SAAS;QAAEO,QAAQA,OAAOc,IAAI;QAAEK,SAAS;QAAOH;IAAS;IAE5E,MAAM,EAAEI,UAAU,EAAEC,qBAAqB,EAAE,GAAGxB,mBAC5CG,QACAA,OAAOsB,EAAE,CAACC,aAAa,EACvBT;IAGF,MAAMU,UAAU,CAAC,kFAAkF,CAAC;IACpG,MAAMC,2BAA2B,CAAC,oGAAoG,CAAC;IAEvI,IAAIC,WAAW,MAAM/B,QAAQyB,YAAY,UAAU;QACjDO,eACE;QACFC,OAAO;YACLC,aAAa;QACf;QACA,yEAAyE;QACzE,oFAAoF;QACpF,kGAAkG;QAClGC,wBAAwB;QACxB,4DAA4D;QAC5DC,KAAK3B,QAAQ2B,GAAG;IAClB;IAEAL,WAAW9B,kCAAkC;QAAEoC,wBAAwBN;IAAS;IAEhF,IAAIL,sBAAsBY,IAAI,GAAG,GAAG;QAClC,MAAMC,QAAQ;eAAIb;SAAsB,CAACc,IAAI,CAAC;QAC9CT,WAAW,GAAGA,SAASU,OAAO,GAAG,IAAI,EAAEF,MAAM,EAAE,CAAC;IAClD;IAEA,IAAIlC,OAAOO,UAAU,CAAC8B,WAAW,EAAEC,QAAQ;QACzC,KAAK,MAAMC,MAAMvC,OAAOO,UAAU,CAAC8B,WAAW,CAAE;YAC9CX,WAAWa,GAAG;gBAAEC,eAAed;gBAAU1B;YAAO;QAClD;IACF;IAEA,IAAIA,OAAOO,UAAU,CAACiB,OAAO,KAAK,OAAO;QACvC,IAAIxB,OAAOO,UAAU,CAACiB,OAAO,EAAEiB,eAAe;YAC5Cf,YAAY,CAAC,IAAI,EAAED,0BAA0B;QAC/C,OAAO;YACLC,YAAY,CAAC,IAAI,EAAEF,SAAS;QAC9B;IACF;IAEA,8DAA8D;IAC9D,IAAIvB,SAASyC,cAAc;QACzB,OAAOhB;IACT;IAEA,0DAA0D;IAC1D,IAAI;QACF,MAAMiB,gBAAgB,MAAMjD,GAAGkD,QAAQ,CAACzC,YAAY;QAEpD,IAAIuB,aAAaiB,eAAe;YAC9B;QACF;IACF,EAAE,OAAOE,GAAG;IACV,cAAc;IAChB;IAEA,MAAMnD,GAAGoD,SAAS,CAAC3C,YAAYuB;IAC/B,IAAIlB,WAAW;QACbN,OAAOQ,IAAI,CAAC,CAAC,iBAAiB,EAAEP,YAAY;IAC9C;AACF"}
|
package/dist/bin/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":"AA4BA,eAAO,MAAM,GAAG,qBAgCf,CAAA"}
|
package/dist/bin/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { pathToFileURL } from 'node:url';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { findConfig } from '../config/find.js';
|
|
6
6
|
import { getPayload } from '../index.js';
|
|
7
|
+
import { build } from './build.js';
|
|
7
8
|
import { generateImportMap } from './generateImportMap/index.js';
|
|
8
9
|
import { generateTypes } from './generateTypes.js';
|
|
9
10
|
import { info } from './info.js';
|
|
@@ -11,6 +12,7 @@ import { loadEnv } from './loadEnv.js';
|
|
|
11
12
|
import { migrate, availableCommands as migrateCommands } from './migrate.js';
|
|
12
13
|
// Note: this does not account for any user bin scripts
|
|
13
14
|
const availableScripts = [
|
|
15
|
+
'build',
|
|
14
16
|
'generate:db-schema',
|
|
15
17
|
'generate:importmap',
|
|
16
18
|
'generate:types',
|
|
@@ -121,6 +123,13 @@ async function runBinScript({ args, script }) {
|
|
|
121
123
|
await generateImportMap(config);
|
|
122
124
|
return {};
|
|
123
125
|
}
|
|
126
|
+
if (script === 'build') {
|
|
127
|
+
await build({
|
|
128
|
+
config
|
|
129
|
+
});
|
|
130
|
+
return {} // build() awaits next build and owns process exit, propagating its code
|
|
131
|
+
;
|
|
132
|
+
}
|
|
124
133
|
if (script === 'jobs:run') {
|
|
125
134
|
const payload = await getPayload({
|
|
126
135
|
config
|
package/dist/bin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bin/index.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport { Cron } from 'croner'\nimport minimist from 'minimist'\nimport { pathToFileURL } from 'node:url'\nimport path from 'path'\n\nimport { findConfig } from '../config/find.js'\nimport { getPayload, type Payload } from '../index.js'\nimport { generateImportMap } from './generateImportMap/index.js'\nimport { generateTypes } from './generateTypes.js'\nimport { info } from './info.js'\nimport { loadEnv } from './loadEnv.js'\nimport { migrate, availableCommands as migrateCommands } from './migrate.js'\n\n// Note: this does not account for any user bin scripts\nconst availableScripts = [\n 'generate:db-schema',\n 'generate:importmap',\n 'generate:types',\n 'info',\n 'jobs:run',\n 'jobs:handle-schedules',\n 'run',\n ...migrateCommands,\n] as const\n\nexport const bin = async () => {\n loadEnv()\n process.env.DISABLE_PAYLOAD_HMR = 'true'\n\n const args = minimist(process.argv.slice(2))\n const script = (typeof args._[0] === 'string' ? args._[0] : '').toLowerCase()\n\n if (args.cron) {\n new Cron(\n args.cron,\n async () => {\n // If the bin script initializes payload (getPayload), this will only happen once, as getPayload\n // caches the payload instance on the module scope => no need to manually cache and manage getPayload initialization\n // outside the Cron here.\n await runBinScript({ args, script })\n },\n {\n // Do not run consecutive crons if previous crons still ongoing\n protect: true,\n },\n )\n\n process.stdin.resume() // Keep the process alive\n\n return\n } else {\n const { payload } = await runBinScript({ args, script })\n if (payload) {\n await payload.destroy() // close database connections after running jobs so process can exit cleanly\n }\n process.exit(0)\n }\n}\n\nasync function runBinScript({\n args,\n script,\n}: {\n args: minimist.ParsedArgs\n script: string\n}): Promise<{\n /**\n * Scripts can return a payload instance if it exists. The bin script runner can then safely\n * shut off the instance, depending on if it's running in a cron job or not.\n */\n payload?: Payload\n}> {\n if (script === 'info') {\n await info()\n return {}\n }\n\n if (script === 'run') {\n const scriptPath = args._[1]\n if (!scriptPath) {\n console.error('Please provide a script path to run.')\n process.exit(1)\n }\n\n const absoluteScriptPath = path.resolve(process.cwd(), scriptPath)\n\n // Modify process.argv to remove 'run' and the script path\n const originalArgv = process.argv\n process.argv = [process.argv[0]!, process.argv[1]!, ...args._.slice(2)]\n\n try {\n await import(pathToFileURL(absoluteScriptPath).toString())\n } catch (error) {\n console.error(`Error running script: ${absoluteScriptPath}`)\n console.error(error)\n process.exit(1)\n } finally {\n // Restore original process.argv\n process.argv = originalArgv\n }\n return {}\n }\n\n const configPath = findConfig()\n const configPromise = await import(pathToFileURL(configPath).toString())\n let config = await configPromise\n if (config.default) {\n config = await config.default\n }\n\n const userBinScript = Array.isArray(config.bin)\n ? config.bin.find(({ key }: { key: string }) => key === script)\n : false\n\n if (userBinScript) {\n try {\n const module = await import(pathToFileURL(userBinScript.scriptPath).toString())\n\n if (!module.script || typeof module.script !== 'function') {\n console.error(\n `Could not find \"script\" function export for script ${userBinScript.key} in ${userBinScript.scriptPath}`,\n )\n } else {\n await module.script(config).catch((err: unknown) => {\n console.log(`Script ${userBinScript.key} failed, details:`)\n console.error(err)\n })\n }\n } catch (err) {\n console.log(`Could not find associated bin script for the ${userBinScript.key} command`)\n console.error(err)\n }\n\n return {}\n }\n\n if (script.startsWith('migrate')) {\n await migrate({ config, parsedArgs: args })\n return {}\n }\n\n if (script === 'generate:types') {\n await generateTypes(config)\n return {}\n }\n\n if (script === 'generate:importmap') {\n await generateImportMap(config)\n return {}\n }\n\n if (script === 'jobs:run') {\n const payload = await getPayload({ config }) // Do not setup crons here - this bin script can set up its own crons\n const limit = args.limit ? parseInt(args.limit, 10) : undefined\n const queue = args.queue ? args.queue : undefined\n const allQueues = !!args['all-queues']\n const handleSchedules = !!args['handle-schedules']\n\n if (handleSchedules) {\n await payload.jobs.handleSchedules({\n allQueues,\n queue,\n })\n }\n\n await payload.jobs.run({\n allQueues,\n limit,\n queue,\n })\n\n return { payload }\n }\n\n if (script === 'jobs:handle-schedules') {\n const payload = await getPayload({ config }) // Do not setup crons here - this bin script can set up its own crons\n const queue = args.queue ? args.queue : undefined\n const allQueues = !!args['all-queues']\n\n await payload.jobs.handleSchedules({\n allQueues,\n queue,\n })\n\n return { payload }\n }\n\n if (script === 'generate:db-schema') {\n // Barebones instance to access database adapter, without connecting to the DB\n const payload = await getPayload({ config, disableDBConnect: true, disableOnInit: true }) // Do not setup crons here\n\n if (typeof payload.db.generateSchema !== 'function') {\n payload.logger.error({\n msg: `${payload.db.packageName} does not support database schema generation`,\n })\n\n await payload.destroy()\n process.exit(1)\n }\n\n await payload.db.generateSchema({\n log: args.log === 'false' ? false : true,\n prettify: args.prettify === 'false' ? false : true,\n })\n\n return { payload }\n }\n\n console.error(script ? `Unknown command: \"${script}\"` : 'Please provide a command to run')\n console.log(`\\nAvailable commands:\\n${availableScripts.map((c) => ` - ${c}`).join('\\n')}`)\n\n process.exit(1)\n}\n"],"names":["Cron","minimist","pathToFileURL","path","findConfig","getPayload","generateImportMap","generateTypes","info","loadEnv","migrate","availableCommands","migrateCommands","availableScripts","bin","process","env","DISABLE_PAYLOAD_HMR","args","argv","slice","script","_","toLowerCase","cron","runBinScript","protect","stdin","resume","payload","destroy","exit","scriptPath","console","error","absoluteScriptPath","resolve","cwd","originalArgv","toString","configPath","configPromise","config","default","userBinScript","Array","isArray","find","key","module","catch","err","log","startsWith","parsedArgs","limit","parseInt","undefined","queue","allQueues","handleSchedules","jobs","run","disableDBConnect","disableOnInit","db","generateSchema","logger","msg","packageName","prettify","map","c","join"],"mappings":"AAAA,6BAA6B,GAC7B,SAASA,IAAI,QAAQ,SAAQ;AAC7B,OAAOC,cAAc,WAAU;AAC/B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAEvB,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,UAAU,QAAsB,cAAa;AACtD,SAASC,iBAAiB,QAAQ,+BAA8B;AAChE,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,OAAO,EAAEC,qBAAqBC,eAAe,QAAQ,eAAc;AAE5E,uDAAuD;AACvD,MAAMC,mBAAmB;IACvB;IACA;IACA;IACA;IACA;IACA;IACA;OACGD;CACJ;AAED,OAAO,MAAME,MAAM;IACjBL;IACAM,QAAQC,GAAG,CAACC,mBAAmB,GAAG;IAElC,MAAMC,OAAOjB,SAASc,QAAQI,IAAI,CAACC,KAAK,CAAC;IACzC,MAAMC,SAAS,AAAC,CAAA,OAAOH,KAAKI,CAAC,CAAC,EAAE,KAAK,WAAWJ,KAAKI,CAAC,CAAC,EAAE,GAAG,EAAC,EAAGC,WAAW;IAE3E,IAAIL,KAAKM,IAAI,EAAE;QACb,IAAIxB,KACFkB,K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cAAc,CAAC;YAC9Bd,KAAKlC,KAAKkC,GAAG,KAAK,UAAU,QAAQ;YACpCkB,UAAUpD,KAAKoD,QAAQ,KAAK,UAAU,QAAQ;QAChD;QAEA,OAAO;YAAEzC;QAAQ;IACnB;IAEAI,QAAQC,KAAK,CAACb,SAAS,CAAC,kBAAkB,EAAEA,OAAO,CAAC,CAAC,GAAG;IACxDY,QAAQmB,GAAG,CAAC,CAAC,uBAAuB,EAAEvC,iBAAiB0D,GAAG,CAAC,CAACC,IAAM,CAAC,IAAI,EAAEA,GAAG,EAAEC,IAAI,CAAC,OAAO;IAE1F1D,QAAQgB,IAAI,CAAC;AACf"}
|
|
1
|
+
{"version":3,"sources":["../../src/bin/index.ts"],"sourcesContent":["/* eslint-disable no-console */\nimport { Cron } from 'croner'\nimport minimist from 'minimist'\nimport { pathToFileURL } from 'node:url'\nimport path from 'path'\n\nimport { findConfig } from '../config/find.js'\nimport { getPayload, type Payload } from '../index.js'\nimport { build } from './build.js'\nimport { generateImportMap } from './generateImportMap/index.js'\nimport { generateTypes } from './generateTypes.js'\nimport { info } from './info.js'\nimport { loadEnv } from './loadEnv.js'\nimport { migrate, availableCommands as migrateCommands } from './migrate.js'\n\n// Note: this does not account for any user bin scripts\nconst availableScripts = [\n 'build',\n 'generate:db-schema',\n 'generate:importmap',\n 'generate:types',\n 'info',\n 'jobs:run',\n 'jobs:handle-schedules',\n 'run',\n ...migrateCommands,\n] as const\n\nexport const bin = async () => {\n loadEnv()\n process.env.DISABLE_PAYLOAD_HMR = 'true'\n\n const args = minimist(process.argv.slice(2))\n const script = (typeof args._[0] === 'string' ? args._[0] : '').toLowerCase()\n\n if (args.cron) {\n new Cron(\n args.cron,\n async () => {\n // If the bin script initializes payload (getPayload), this will only happen once, as getPayload\n // caches the payload instance on the module scope => no need to manually cache and manage getPayload initialization\n // outside the Cron here.\n await runBinScript({ args, script })\n },\n {\n // Do not run consecutive crons if previous crons still ongoing\n protect: true,\n },\n )\n\n process.stdin.resume() // Keep the process alive\n\n return\n } else {\n const { payload } = await runBinScript({ args, script })\n if (payload) {\n await payload.destroy() // close database connections after running jobs so process can exit cleanly\n }\n process.exit(0)\n }\n}\n\nasync function runBinScript({\n args,\n script,\n}: {\n args: minimist.ParsedArgs\n script: string\n}): Promise<{\n /**\n * Scripts can return a payload instance if it exists. The bin script runner can then safely\n * shut off the instance, depending on if it's running in a cron job or not.\n */\n payload?: Payload\n}> {\n if (script === 'info') {\n await info()\n return {}\n }\n\n if (script === 'run') {\n const scriptPath = args._[1]\n if (!scriptPath) {\n console.error('Please provide a script path to run.')\n process.exit(1)\n }\n\n const absoluteScriptPath = path.resolve(process.cwd(), scriptPath)\n\n // Modify process.argv to remove 'run' and the script path\n const originalArgv = process.argv\n process.argv = [process.argv[0]!, process.argv[1]!, ...args._.slice(2)]\n\n try {\n await import(pathToFileURL(absoluteScriptPath).toString())\n } catch (error) {\n console.error(`Error running script: ${absoluteScriptPath}`)\n console.error(error)\n process.exit(1)\n } finally {\n // Restore original process.argv\n process.argv = originalArgv\n }\n return {}\n }\n\n const configPath = findConfig()\n const configPromise = await import(pathToFileURL(configPath).toString())\n let config = await configPromise\n if (config.default) {\n config = await config.default\n }\n\n const userBinScript = Array.isArray(config.bin)\n ? config.bin.find(({ key }: { key: string }) => key === script)\n : false\n\n if (userBinScript) {\n try {\n const module = await import(pathToFileURL(userBinScript.scriptPath).toString())\n\n if (!module.script || typeof module.script !== 'function') {\n console.error(\n `Could not find \"script\" function export for script ${userBinScript.key} in ${userBinScript.scriptPath}`,\n )\n } else {\n await module.script(config).catch((err: unknown) => {\n console.log(`Script ${userBinScript.key} failed, details:`)\n console.error(err)\n })\n }\n } catch (err) {\n console.log(`Could not find associated bin script for the ${userBinScript.key} command`)\n console.error(err)\n }\n\n return {}\n }\n\n if (script.startsWith('migrate')) {\n await migrate({ config, parsedArgs: args })\n return {}\n }\n\n if (script === 'generate:types') {\n await generateTypes(config)\n return {}\n }\n\n if (script === 'generate:importmap') {\n await generateImportMap(config)\n return {}\n }\n\n if (script === 'build') {\n await build({ config })\n return {} // build() awaits next build and owns process exit, propagating its code\n }\n\n if (script === 'jobs:run') {\n const payload = await getPayload({ config }) // Do not setup crons here - this bin script can set up its own crons\n const limit = args.limit ? parseInt(args.limit, 10) : undefined\n const queue = args.queue ? args.queue : undefined\n const allQueues = !!args['all-queues']\n const handleSchedules = !!args['handle-schedules']\n\n if (handleSchedules) {\n await payload.jobs.handleSchedules({\n allQueues,\n queue,\n })\n }\n\n await payload.jobs.run({\n allQueues,\n limit,\n queue,\n })\n\n return { payload }\n }\n\n if (script === 'jobs:handle-schedules') {\n const payload = await getPayload({ config }) // Do not setup crons here - this bin script can set up its own crons\n const queue = args.queue ? args.queue : undefined\n const allQueues = !!args['all-queues']\n\n await payload.jobs.handleSchedules({\n allQueues,\n queue,\n })\n\n return { payload }\n }\n\n if (script === 'generate:db-schema') {\n // Barebones instance to access database adapter, without connecting to the DB\n const payload = await getPayload({ config, disableDBConnect: true, disableOnInit: true }) // Do not setup crons here\n\n if (typeof payload.db.generateSchema !== 'function') {\n payload.logger.error({\n msg: `${payload.db.packageName} does not support database schema generation`,\n })\n\n await payload.destroy()\n process.exit(1)\n }\n\n await payload.db.generateSchema({\n log: args.log === 'false' ? false : true,\n prettify: args.prettify === 'false' ? false : true,\n })\n\n return { payload }\n }\n\n console.error(script ? `Unknown command: \"${script}\"` : 'Please provide a command to run')\n console.log(`\\nAvailable commands:\\n${availableScripts.map((c) => ` - ${c}`).join('\\n')}`)\n\n process.exit(1)\n}\n"],"names":["Cron","minimist","pathToFileURL","path","findConfig","getPayload","build","generateImportMap","generateTypes","info","loadEnv","migrate","availableCommands","migrateCommands","availableScripts","bin","process","env","DISABLE_PAYLOAD_HMR","args","argv","slice","script","_","toLowerCase","cron","runBinScript","protect","stdin","resume","payload","destroy","exit","scriptPath","console","error","absoluteScriptPath","resolve","cwd","originalArgv","toString","configPath","configPromise","config","default","userBinScript","Array","isArray","find","key","module","catch","err","log","startsWith","parsedArgs","limit","parseInt","undefined","queue","allQueues","handleSchedules","jobs","run","disableDBConnect","disableOnInit","db","generateSchema","logger","msg","packageName","prettify","map","c","join"],"mappings":"AAAA,6BAA6B,GAC7B,SAASA,IAAI,QAAQ,SAAQ;AAC7B,OAAOC,cAAc,WAAU;AAC/B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAEvB,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,UAAU,QAAsB,cAAa;AACtD,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,iBAAiB,QAAQ,+BAA8B;AAChE,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,OAAO,EAAEC,qBAAqBC,eAAe,QAAQ,eAAc;AAE5E,uDAAuD;AACvD,MAAMC,mBAAmB;IACvB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;OACGD;CACJ;AAED,OAAO,MAAME,MAAM;IACjBL;IACAM,QAAQC,GAAG,CAACC,mBAAmB,GAAG;IAElC,MAAMC,OAAOlB,SAASe,QAAQI,IAAI,CAACC,KAAK,CAAC;IACzC,MAAMC,SAAS,AAAC,CAAA,OAAOH,KAAKI,CAAC,CAAC,EAAE,KAAK,WAAWJ,KAAKI,CAAC,CAAC,EAAE,GAAG,EAAC,EAAGC,WAAW;IAE3E,IAAIL,KAAKM,IAAI,EAAE;QACb,IAAIzB,KACFmB,KAAKM,IAAI,EACT;YACE,gGAAgG;YAChG,oHAAoH;YACpH,yBAAyB;YACzB,MAAMC,aAAa;gBAAEP;gBAAMG;YAAO;QACpC,GACA;YACE,+DAA+D;YAC/DK,SAAS;QACX;QAGFX,QAAQY,KAAK,CAACC,MAAM,IAAG,yBAAyB;QAEhD;IACF,OAAO;QACL,MAAM,EAAEC,OAAO,EAAE,GAAG,MAAMJ,aAAa;YAAEP;YAAMG;QAAO;QACtD,IAAIQ,SAAS;Y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EAAEA,OAAO,CAAC,CAAC,GAAG;IACxDY,QAAQmB,GAAG,CAAC,CAAC,uBAAuB,EAAEvC,iBAAiB0D,GAAG,CAAC,CAACC,IAAM,CAAC,IAAI,EAAEA,GAAG,EAAEC,IAAI,CAAC,OAAO;IAE1F1D,QAAQgB,IAAI,CAAC;AACf"}
|
package/dist/bin/loadEnv.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Try to find user's env files and load
|
|
2
|
+
* Try to find user's env files and load them.
|
|
3
|
+
* Supports .env, .env.local, .env.development, .env.production, etc.
|
|
4
|
+
* (same file priority as Next.js)
|
|
3
5
|
*/
|
|
4
6
|
export declare function loadEnv(path?: string): void;
|
|
5
7
|
//# sourceMappingURL=loadEnv.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadEnv.d.ts","sourceRoot":"","sources":["../../src/bin/loadEnv.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loadEnv.d.ts","sourceRoot":"","sources":["../../src/bin/loadEnv.ts"],"names":[],"mappings":"AAoCA;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,QAqBpC"}
|
package/dist/bin/loadEnv.js
CHANGED
|
@@ -1,22 +1,52 @@
|
|
|
1
|
-
import
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
import dotenvExpand from 'dotenv-expand';
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
|
+
import nodePath from 'path';
|
|
2
5
|
import { findUpSync } from '../utilities/findUp.js';
|
|
3
|
-
const { loadEnvConfig } = nextEnvImport;
|
|
4
6
|
/**
|
|
5
|
-
*
|
|
7
|
+
* Loads env files in priority order (same as Next.js convention):
|
|
8
|
+
* .env.${NODE_ENV}.local, .env.local (not for test), .env.${NODE_ENV}, .env
|
|
9
|
+
*/ function loadEnvFiles(dir, isDev) {
|
|
10
|
+
const nodeEnv = process.env.NODE_ENV || (isDev ? 'development' : 'production');
|
|
11
|
+
const envFiles = [
|
|
12
|
+
`.env.${nodeEnv}.local`,
|
|
13
|
+
...nodeEnv !== 'test' ? [
|
|
14
|
+
'.env.local'
|
|
15
|
+
] : [],
|
|
16
|
+
`.env.${nodeEnv}`,
|
|
17
|
+
'.env'
|
|
18
|
+
];
|
|
19
|
+
let loaded = false;
|
|
20
|
+
for (const envFile of envFiles){
|
|
21
|
+
const filePath = nodePath.resolve(dir, envFile);
|
|
22
|
+
if (existsSync(filePath)) {
|
|
23
|
+
const result = dotenv.config({
|
|
24
|
+
path: filePath
|
|
25
|
+
});
|
|
26
|
+
if (result.parsed) {
|
|
27
|
+
dotenvExpand.expand(result);
|
|
28
|
+
loaded = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return loaded;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Try to find user's env files and load them.
|
|
36
|
+
* Supports .env, .env.local, .env.development, .env.production, etc.
|
|
37
|
+
* (same file priority as Next.js)
|
|
6
38
|
*/ export function loadEnv(path) {
|
|
39
|
+
const isDev = process.env.NODE_ENV !== 'production';
|
|
7
40
|
if (path?.length) {
|
|
8
|
-
|
|
41
|
+
loadEnvFiles(path, isDev);
|
|
9
42
|
return;
|
|
10
43
|
}
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
if (!loadedEnvFiles?.length) {
|
|
14
|
-
// use findUp to find the env file. So, run loadEnvConfig for every directory upwards
|
|
44
|
+
const loaded = loadEnvFiles(process.cwd(), isDev);
|
|
45
|
+
if (!loaded) {
|
|
15
46
|
findUpSync({
|
|
16
47
|
// @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve
|
|
17
48
|
condition: (dir)=>{
|
|
18
|
-
|
|
19
|
-
if (loadedEnvFiles?.length) {
|
|
49
|
+
if (loadEnvFiles(dir, isDev)) {
|
|
20
50
|
return true;
|
|
21
51
|
}
|
|
22
52
|
},
|
package/dist/bin/loadEnv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bin/loadEnv.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/bin/loadEnv.ts"],"sourcesContent":["import dotenv from 'dotenv'\nimport dotenvExpand from 'dotenv-expand'\nimport { existsSync } from 'fs'\nimport nodePath from 'path'\n\nimport { findUpSync } from '../utilities/findUp.js'\n\n/**\n * Loads env files in priority order (same as Next.js convention):\n * .env.${NODE_ENV}.local, .env.local (not for test), .env.${NODE_ENV}, .env\n */\nfunction loadEnvFiles(dir: string, isDev: boolean): boolean {\n const nodeEnv = process.env.NODE_ENV || (isDev ? 'development' : 'production')\n const envFiles = [\n `.env.${nodeEnv}.local`,\n ...(nodeEnv !== 'test' ? ['.env.local'] : []),\n `.env.${nodeEnv}`,\n '.env',\n ]\n\n let loaded = false\n\n for (const envFile of envFiles) {\n const filePath = nodePath.resolve(dir, envFile)\n if (existsSync(filePath)) {\n const result = dotenv.config({ path: filePath })\n if (result.parsed) {\n dotenvExpand.expand(result)\n loaded = true\n }\n }\n }\n\n return loaded\n}\n\n/**\n * Try to find user's env files and load them.\n * Supports .env, .env.local, .env.development, .env.production, etc.\n * (same file priority as Next.js)\n */\nexport function loadEnv(path?: string) {\n const isDev = process.env.NODE_ENV !== 'production'\n\n if (path?.length) {\n loadEnvFiles(path, isDev)\n return\n }\n\n const loaded = loadEnvFiles(process.cwd(), isDev)\n\n if (!loaded) {\n findUpSync({\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n condition: (dir) => {\n if (loadEnvFiles(dir, isDev)) {\n return true\n }\n },\n dir: process.cwd(),\n })\n }\n}\n"],"names":["dotenv","dotenvExpand","existsSync","nodePath","findUpSync","loadEnvFiles","dir","isDev","nodeEnv","process","env","NODE_ENV","envFiles","loaded","envFile","filePath","resolve","result","config","path","parsed","expand","loadEnv","length","cwd","condition"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,OAAO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
55
|
+
versions: true
|
|
56
56
|
};
|
|
57
57
|
export const addDefaultsToCollectionConfig = (collection)=>{
|
|
58
58
|
collection.access = {
|
|
@@ -109,7 +109,7 @@ export const addDefaultsToCollectionConfig = (collection)=>{
|
|
|
109
109
|
};
|
|
110
110
|
collection.timestamps = collection.timestamps ?? true;
|
|
111
111
|
collection.upload = collection.upload ?? false;
|
|
112
|
-
collection.versions = collection.versions ??
|
|
112
|
+
collection.versions = collection.versions ?? true;
|
|
113
113
|
collection.indexes = collection.indexes ?? [];
|
|
114
114
|
return collection;
|
|
115
115
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/config/defaults.ts"],"sourcesContent":["import type { IncomingAuthType, LoginWithUsernameOptions } from '../../auth/types.js'\nimport type { CollectionConfig } from './types.js'\n\nimport { defaultAccess } from '../../auth/defaultAccess.js'\n\n/**\n * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.\n */\nexport const defaults: Partial<CollectionConfig> = {\n access: {\n create: defaultAccess,\n delete: defaultAccess,\n read: defaultAccess,\n unlock: defaultAccess,\n update: defaultAccess,\n },\n admin: {\n components: {},\n custom: {},\n enableRichTextLink: true,\n enableRichTextRelationship: true,\n pagination: {\n defaultLimit: 10,\n limits: [5, 10, 25, 50, 100],\n },\n useAsTitle: 'id',\n },\n auth: false,\n custom: {},\n endpoints: [],\n fields: [],\n hooks: {\n afterChange: [],\n afterDelete: [],\n afterForgotPassword: [],\n afterLogin: [],\n afterLogout: [],\n afterMe: [],\n afterOperation: [],\n afterRead: [],\n afterRefresh: [],\n beforeChange: [],\n beforeDelete: [],\n beforeLogin: [],\n beforeOperation: [],\n beforeRead: [],\n beforeValidate: [],\n me: [],\n refresh: [],\n },\n indexes: [],\n timestamps: true,\n upload: false,\n versions:
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/config/defaults.ts"],"sourcesContent":["import type { IncomingAuthType, LoginWithUsernameOptions } from '../../auth/types.js'\nimport type { CollectionConfig } from './types.js'\n\nimport { defaultAccess } from '../../auth/defaultAccess.js'\n\n/**\n * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.\n */\nexport const defaults: Partial<CollectionConfig> = {\n access: {\n create: defaultAccess,\n delete: defaultAccess,\n read: defaultAccess,\n unlock: defaultAccess,\n update: defaultAccess,\n },\n admin: {\n components: {},\n custom: {},\n enableRichTextLink: true,\n enableRichTextRelationship: true,\n pagination: {\n defaultLimit: 10,\n limits: [5, 10, 25, 50, 100],\n },\n useAsTitle: 'id',\n },\n auth: false,\n custom: {},\n endpoints: [],\n fields: [],\n hooks: {\n afterChange: [],\n afterDelete: [],\n afterForgotPassword: [],\n afterLogin: [],\n afterLogout: [],\n afterMe: [],\n afterOperation: [],\n afterRead: [],\n afterRefresh: [],\n beforeChange: [],\n beforeDelete: [],\n beforeLogin: [],\n beforeOperation: [],\n beforeRead: [],\n beforeValidate: [],\n me: [],\n refresh: [],\n },\n indexes: [],\n timestamps: true,\n upload: false,\n versions: true,\n}\n\nexport const addDefaultsToCollectionConfig = (collection: CollectionConfig): CollectionConfig => {\n collection.access = {\n create: defaultAccess,\n delete: defaultAccess,\n read: defaultAccess,\n unlock: defaultAccess,\n update: defaultAccess,\n ...(collection.access || {}),\n }\n\n collection.admin = {\n components: {},\n custom: {},\n enableRichTextLink: true,\n enableRichTextRelationship: true,\n useAsTitle: 'id',\n ...(collection.admin || {}),\n pagination: {\n defaultLimit: 10,\n limits: [5, 10, 25, 50, 100],\n ...(collection.admin?.pagination || {}),\n },\n }\n\n collection.auth = collection.auth ?? false\n collection.custom = collection.custom ?? {}\n collection.endpoints = collection.endpoints ?? []\n collection.fields = collection.fields ?? []\n collection.hierarchy = collection.hierarchy ?? false\n\n collection.hooks = {\n afterChange: [],\n afterDelete: [],\n afterForgotPassword: [],\n afterLogin: [],\n afterLogout: [],\n afterMe: [],\n afterOperation: [],\n afterRead: [],\n afterRefresh: [],\n beforeChange: [],\n beforeDelete: [],\n beforeLogin: [],\n beforeOperation: [],\n beforeRead: [],\n beforeValidate: [],\n me: [],\n refresh: [],\n ...(collection.hooks || {}),\n }\n\n collection.timestamps = collection.timestamps ?? true\n collection.upload = collection.upload ?? false\n collection.versions = collection.versions ?? true\n\n collection.indexes = collection.indexes ?? []\n\n return collection\n}\n\n/**\n * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.\n */\nexport const authDefaults: IncomingAuthType = {\n cookies: {\n sameSite: 'Lax',\n secure: false,\n },\n forgotPassword: {},\n lockTime: 600000, // 10 minutes\n loginWithUsername: false,\n maxLoginAttempts: 5,\n tokenExpiration: 7200,\n useSessions: true,\n verify: false,\n}\n\nexport const addDefaultsToAuthConfig = (auth: IncomingAuthType): IncomingAuthType => {\n auth.cookies = {\n sameSite: 'Lax',\n secure: false,\n ...(auth.cookies || {}),\n }\n\n auth.forgotPassword = auth.forgotPassword ?? {}\n auth.lockTime = auth.lockTime ?? 600000 // 10 minutes\n auth.loginWithUsername = auth.loginWithUsername ?? false\n auth.maxLoginAttempts = auth.maxLoginAttempts ?? 5\n auth.tokenExpiration = auth.tokenExpiration ?? 7200\n auth.useSessions = auth.useSessions ?? true\n auth.verify = auth.verify ?? false\n auth.strategies = auth.strategies ?? []\n\n if (!auth.disableLocalStrategy && auth.verify === true) {\n auth.verify = {}\n }\n\n return auth\n}\n\n/**\n * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.\n */\nexport const loginWithUsernameDefaults: LoginWithUsernameOptions = {\n allowEmailLogin: false,\n requireEmail: false,\n requireUsername: true,\n}\n\nexport const addDefaultsToLoginWithUsernameConfig = (\n loginWithUsername: LoginWithUsernameOptions,\n): LoginWithUsernameOptions =>\n ({\n allowEmailLogin: false,\n requireEmail: false,\n requireUsername: true,\n ...(loginWithUsername || {}),\n }) as LoginWithUsernameOptions\n"],"names":["defaultAccess","defaults","access","create","delete","read","unlock","update","admin","components","custom","enableRichTextLink","enableRichTextRelationship","pagination","defaultLimit","limits","useAsTitle","auth","endpoints","fields","hooks","afterChange","afterDelete","afterForgotPassword","afterLogin","afterLogout","afterMe","afterOperation","afterRead","afterRefresh","beforeChange","beforeDelete","beforeLogin","beforeOperation","beforeRead","beforeValidate","me","refresh","indexes","timestamps","upload","versions","addDefaultsToCollectionConfig","collection","hierarchy","authDefaults","cookies","sameSite","secure","forgotPassword","lockTime","loginWithUsername","maxLoginAttempts","tokenExpiration","useSessions","verify","addDefaultsToAuthConfig","strategies","disableLocalStrategy","loginWithUsernameDefaults","allowEmailLogin","requireEmail","requireUsername","addDefaultsToLoginWithUsernameConfig"],"mappings":"AAGA,SAASA,aAAa,QAAQ,8BAA6B;AAE3D;;CAEC,GACD,OAAO,MAAMC,WAAsC;IACjDC,QAAQ;QACNC,QAAQH;QACRI,QAAQJ;QACRK,MAAML;QACNM,QAAQN;QACRO,QAAQP;IACV;IACAQ,OAAO;QACLC,YAAY,CAAC;QACbC,QAAQ,CAAC;QACTC,oBAAoB;QACpBC,4BAA4B;QAC5BC,YAAY;YACVC,cAAc;YACdC,QAAQ;gBAAC;gBAAG;gBAAI;gBAAI;gBAAI;aAAI;QAC9B;QACAC,YAAY;IACd;IACAC,MAAM;IACNP,QAAQ,CAAC;IACTQ,WAAW,EAAE;IACbC,QAAQ,EAAE;IACVC,OAAO;QACLC,aAAa,EAAE;QACfC,aAAa,EAAE;QACfC,qBAAqB,EAAE;QACvBC,YAAY,EAAE;QACdC,aAAa,EAAE;QACfC,SAAS,EAAE;QACXC,gBAAgB,EAAE;QAClBC,WAAW,EAAE;QACbC,cAAc,EAAE;QAChBC,cAAc,EAAE;QAChBC,cAAc,EAAE;QAChBC,aAAa,EAAE;QACfC,iBAAiB,EAAE;QACnBC,YAAY,EAAE;QACdC,gBAAgB,EAAE;QAClBC,IAAI,EAAE;QACNC,SAAS,EAAE;IACb;IACAC,SAAS,EAAE;IACXC,YAAY;IACZC,QAAQ;IACRC,UAAU;AACZ,EA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,CAAA;QACCS,iBAAiB;QACjBC,cAAc;QACdC,iBAAiB;QACjB,GAAIX,qBAAqB,CAAC,CAAC;IAC7B,CAAA,EAA8B"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { addDefaultsToCollectionConfig } from './defaults.js';
|
|
3
|
+
describe('addDefaultsToCollectionConfig', ()=>{
|
|
4
|
+
it('should default versions to true when not specified', ()=>{
|
|
5
|
+
const collection = {
|
|
6
|
+
slug: 'posts',
|
|
7
|
+
fields: []
|
|
8
|
+
};
|
|
9
|
+
const result = addDefaultsToCollectionConfig(collection);
|
|
10
|
+
expect(result.versions).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
it('should preserve explicit versions: false', ()=>{
|
|
13
|
+
const collection = {
|
|
14
|
+
slug: 'users',
|
|
15
|
+
fields: [],
|
|
16
|
+
versions: false
|
|
17
|
+
};
|
|
18
|
+
const result = addDefaultsToCollectionConfig(collection);
|
|
19
|
+
expect(result.versions).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
it('should preserve explicit versions object config', ()=>{
|
|
22
|
+
const collection = {
|
|
23
|
+
slug: 'posts',
|
|
24
|
+
fields: [],
|
|
25
|
+
versions: {
|
|
26
|
+
drafts: true,
|
|
27
|
+
maxPerDoc: 50
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const result = addDefaultsToCollectionConfig(collection);
|
|
31
|
+
expect(result.versions).toEqual({
|
|
32
|
+
drafts: true,
|
|
33
|
+
maxPerDoc: 50
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
it('should preserve explicit versions: true', ()=>{
|
|
37
|
+
const collection = {
|
|
38
|
+
slug: 'posts',
|
|
39
|
+
fields: [],
|
|
40
|
+
versions: true
|
|
41
|
+
};
|
|
42
|
+
const result = addDefaultsToCollectionConfig(collection);
|
|
43
|
+
expect(result.versions).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=defaults.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/config/defaults.spec.ts"],"sourcesContent":["import type { CollectionConfig } from './types.js'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { addDefaultsToCollectionConfig } from './defaults.js'\n\ndescribe('addDefaultsToCollectionConfig', () => {\n it('should default versions to true when not specified', () => {\n const collection: CollectionConfig = {\n slug: 'posts',\n fields: [],\n }\n\n const result = addDefaultsToCollectionConfig(collection)\n\n expect(result.versions).toBe(true)\n })\n\n it('should preserve explicit versions: false', () => {\n const collection: CollectionConfig = {\n slug: 'users',\n fields: [],\n versions: false,\n }\n\n const result = addDefaultsToCollectionConfig(collection)\n\n expect(result.versions).toBe(false)\n })\n\n it('should preserve explicit versions object config', () => {\n const collection: CollectionConfig = {\n slug: 'posts',\n fields: [],\n versions: { drafts: true, maxPerDoc: 50 },\n }\n\n const result = addDefaultsToCollectionConfig(collection)\n\n expect(result.versions).toEqual({ drafts: true, maxPerDoc: 50 })\n })\n\n it('should preserve explicit versions: true', () => {\n const collection: CollectionConfig = {\n slug: 'posts',\n fields: [],\n versions: true,\n }\n\n const result = addDefaultsToCollectionConfig(collection)\n\n expect(result.versions).toBe(true)\n })\n})\n"],"names":["describe","expect","it","addDefaultsToCollectionConfig","collection","slug","fields","result","versions","toBe","drafts","maxPerDoc","toEqual"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,6BAA6B,QAAQ,gBAAe;AAE7DH,SAAS,iCAAiC;IACxCE,GAAG,sDAAsD;QACvD,MAAME,aAA+B;YACnCC,MAAM;YACNC,QAAQ,EAAE;QACZ;QAEA,MAAMC,SAASJ,8BAA8BC;QAE7CH,OAAOM,OAAOC,QAAQ,EAAEC,IAAI,CAAC;IAC/B;IAEAP,GAAG,4CAA4C;QAC7C,MAAME,aAA+B;YACnCC,MAAM;YACNC,QAAQ,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