@payloadcms/db-mongodb 3.90.1 → 3.91.0-internal.07e4582
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/init.d.ts.map +1 -1
- package/dist/init.js +89 -67
- package/dist/init.js.map +1 -1
- package/dist/models/buildCollectionSchema.d.ts +8 -2
- package/dist/models/buildCollectionSchema.d.ts.map +1 -1
- package/dist/models/buildCollectionSchema.js +4 -2
- package/dist/models/buildCollectionSchema.js.map +1 -1
- package/dist/models/buildGlobalModel.d.ts +5 -1
- package/dist/models/buildGlobalModel.d.ts.map +1 -1
- package/dist/models/buildGlobalModel.js +4 -2
- package/dist/models/buildGlobalModel.js.map +1 -1
- package/dist/models/buildSchema.d.ts +4 -0
- package/dist/models/buildSchema.d.ts.map +1 -1
- package/dist/models/buildSchema.js +64 -26
- package/dist/models/buildSchema.js.map +1 -1
- package/dist/models/buildSchema.spec.js +387 -0
- package/dist/models/buildSchema.spec.js.map +1 -0
- package/dist/models/schemaBuildContext.d.ts +21 -0
- package/dist/models/schemaBuildContext.d.ts.map +1 -0
- package/dist/models/schemaBuildContext.js +29 -0
- package/dist/models/schemaBuildContext.js.map +1 -0
- package/dist/models/schemaBuildContext.spec.js +72 -0
- package/dist/models/schemaBuildContext.spec.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Connection, Schema } from 'mongoose';
|
|
2
|
+
import type { SchemaBuildContext } from 'payload/internal';
|
|
3
|
+
import type { BuildSchemaOptions } from './buildSchema.js';
|
|
4
|
+
export type MongoSchemaBuildContext = SchemaBuildContext<Schema>;
|
|
5
|
+
/**
|
|
6
|
+
* Connection and global plugins can keep state on each nested schema. Mongoose does not clone
|
|
7
|
+
* those nested schemas when it attaches a discriminator, so cached templates would change plugin
|
|
8
|
+
* application.
|
|
9
|
+
*/
|
|
10
|
+
export declare const createMongoSchemaBuildContext: ({ connection, }: {
|
|
11
|
+
connection: Connection;
|
|
12
|
+
}) => MongoSchemaBuildContext;
|
|
13
|
+
export declare const getBlockSchemaCacheKey: ({ blockSlug, buildSchemaOptions, fieldPath, isLocalized, isReference, isVersion, }: {
|
|
14
|
+
blockSlug: string;
|
|
15
|
+
buildSchemaOptions: BuildSchemaOptions;
|
|
16
|
+
fieldPath: string;
|
|
17
|
+
isLocalized: boolean;
|
|
18
|
+
isReference: boolean;
|
|
19
|
+
isVersion: boolean;
|
|
20
|
+
}) => string;
|
|
21
|
+
//# sourceMappingURL=schemaBuildContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaBuildContext.d.ts","sourceRoot":"","sources":["../../src/models/schemaBuildContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAK1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAE1D,MAAM,MAAM,uBAAuB,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAA;AAiBhE;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,oBAEvC;IACD,UAAU,EAAE,UAAU,CAAA;CACvB,KAAG,uBAQH,CAAA;AAED,eAAO,MAAM,sBAAsB,uFAOhC;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,kBAAkB,EAAE,kBAAkB,CAAA;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,OAAO,CAAA;IACpB,WAAW,EAAE,OAAO,CAAA;IACpB,SAAS,EAAE,OAAO,CAAA;CACnB,KAAG,MASU,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { createSchemaBuildContext } from 'payload/internal';
|
|
3
|
+
const getMongoosePluginRegistry = ({ mongooseInstance })=>mongooseInstance.plugins;
|
|
4
|
+
const defaultMongoosePluginFunctions = new Set(getMongoosePluginRegistry({
|
|
5
|
+
mongooseInstance: new mongoose.Mongoose({
|
|
6
|
+
createInitialConnection: false
|
|
7
|
+
})
|
|
8
|
+
}).map(([plugin])=>plugin));
|
|
9
|
+
/**
|
|
10
|
+
* Connection and global plugins can keep state on each nested schema. Mongoose does not clone
|
|
11
|
+
* those nested schemas when it attaches a discriminator, so cached templates would change plugin
|
|
12
|
+
* application.
|
|
13
|
+
*/ export const createMongoSchemaBuildContext = ({ connection })=>{
|
|
14
|
+
const hasCustomGlobalPlugins = getMongoosePluginRegistry({
|
|
15
|
+
mongooseInstance: connection.base
|
|
16
|
+
}).some(([plugin])=>!defaultMongoosePluginFunctions.has(plugin));
|
|
17
|
+
return createSchemaBuildContext({
|
|
18
|
+
isCacheEnabled: connection.plugins.length === 0 && !hasCustomGlobalPlugins
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const getBlockSchemaCacheKey = ({ blockSlug, buildSchemaOptions, fieldPath, isLocalized, isReference, isVersion })=>[
|
|
22
|
+
`${isReference ? `block:${blockSlug}` : `inline:${fieldPath}/block:${blockSlug}`}${isVersion ? '-version' : ''}`,
|
|
23
|
+
buildSchemaOptions.disableUnique && 'disableUnique:true',
|
|
24
|
+
buildSchemaOptions.draftsEnabled && 'draftsEnabled:true',
|
|
25
|
+
buildSchemaOptions.indexSortableFields && 'indexSortableFields:true',
|
|
26
|
+
isLocalized && 'isLocalized:true'
|
|
27
|
+
].filter(Boolean).join('|');
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=schemaBuildContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/models/schemaBuildContext.ts"],"sourcesContent":["import type { Connection, Schema } from 'mongoose'\nimport type { SchemaBuildContext } from 'payload/internal'\n\nimport mongoose from 'mongoose'\nimport { createSchemaBuildContext } from 'payload/internal'\n\nimport type { BuildSchemaOptions } from './buildSchema.js'\n\nexport type MongoSchemaBuildContext = SchemaBuildContext<Schema>\n\ntype MongoosePluginRegistry = Array<[Parameters<typeof mongoose.plugin>[0], unknown]>\n\nconst getMongoosePluginRegistry = ({\n mongooseInstance,\n}: {\n mongooseInstance: typeof mongoose\n}): MongoosePluginRegistry =>\n (mongooseInstance as { plugins: MongoosePluginRegistry } & typeof mongoose).plugins\n\nconst defaultMongoosePluginFunctions = new Set(\n getMongoosePluginRegistry({\n mongooseInstance: new mongoose.Mongoose({ createInitialConnection: false }),\n }).map(([plugin]) => plugin),\n)\n\n/**\n * Connection and global plugins can keep state on each nested schema. Mongoose does not clone\n * those nested schemas when it attaches a discriminator, so cached templates would change plugin\n * application.\n */\nexport const createMongoSchemaBuildContext = ({\n connection,\n}: {\n connection: Connection\n}): MongoSchemaBuildContext => {\n const hasCustomGlobalPlugins = getMongoosePluginRegistry({\n mongooseInstance: connection.base,\n }).some(([plugin]) => !defaultMongoosePluginFunctions.has(plugin))\n\n return createSchemaBuildContext<Schema>({\n isCacheEnabled: connection.plugins.length === 0 && !hasCustomGlobalPlugins,\n })\n}\n\nexport const getBlockSchemaCacheKey = ({\n blockSlug,\n buildSchemaOptions,\n fieldPath,\n isLocalized,\n isReference,\n isVersion,\n}: {\n blockSlug: string\n buildSchemaOptions: BuildSchemaOptions\n fieldPath: string\n isLocalized: boolean\n isReference: boolean\n isVersion: boolean\n}): string =>\n [\n `${isReference ? `block:${blockSlug}` : `inline:${fieldPath}/block:${blockSlug}`}${isVersion ? '-version' : ''}`,\n buildSchemaOptions.disableUnique && 'disableUnique:true',\n buildSchemaOptions.draftsEnabled && 'draftsEnabled:true',\n buildSchemaOptions.indexSortableFields && 'indexSortableFields:true',\n isLocalized && 'isLocalized:true',\n ]\n .filter(Boolean)\n .join('|')\n"],"names":["mongoose","createSchemaBuildContext","getMongoosePluginRegistry","mongooseInstance","plugins","defaultMongoosePluginFunctions","Set","Mongoose","createInitialConnection","map","plugin","createMongoSchemaBuildContext","connection","hasCustomGlobalPlugins","base","some","has","isCacheEnabled","length","getBlockSchemaCacheKey","blockSlug","buildSchemaOptions","fieldPath","isLocalized","isReference","isVersion","disableUnique","draftsEnabled","indexSortableFields","filter","Boolean","join"],"mappings":"AAGA,OAAOA,cAAc,WAAU;AAC/B,SAASC,wBAAwB,QAAQ,mBAAkB;AAQ3D,MAAMC,4BAA4B,CAAC,EACjCC,gBAAgB,EAGjB,GACC,AAACA,iBAA2EC,OAAO;AAErF,MAAMC,iCAAiC,IAAIC,IACzCJ,0BAA0B;IACxBC,kBAAkB,IAAIH,SAASO,QAAQ,CAAC;QAAEC,yBAAyB;IAAM;AAC3E,GAAGC,GAAG,CAAC,CAAC,CAACC,OAAO,GAAKA;AAGvB;;;;CAIC,GACD,OAAO,MAAMC,gCAAgC,CAAC,EAC5CC,UAAU,EAGX;IACC,MAAMC,yBAAyBX,0BAA0B;QACvDC,kBAAkBS,WAAWE,IAAI;IACnC,GAAGC,IAAI,CAAC,CAAC,CAACL,OAAO,GAAK,CAACL,+BAA+BW,GAAG,CAACN;IAE1D,OAAOT,yBAAiC;QACtCgB,gBAAgBL,WAAWR,OAAO,CAACc,MAAM,KAAK,KAAK,CAACL;IACtD;AACF,EAAC;AAED,OAAO,MAAMM,yBAAyB,CAAC,EACrCC,SAAS,EACTC,kBAAkB,EAClBC,SAAS,EACTC,WAAW,EACXC,WAAW,EACXC,SAAS,EAQV,GACC;QACE,GAAGD,cAAc,CAAC,MAAM,EAAEJ,WAAW,GAAG,CAAC,OAAO,EAAEE,UAAU,OAAO,EAAEF,WAAW,GAAGK,YAAY,aAAa,IAAI;QAChHJ,mBAAmBK,aAAa,IAAI;QACpCL,mBAAmBM,aAAa,IAAI;QACpCN,mBAAmBO,mBAAmB,IAAI;QAC1CL,eAAe;KAChB,CACEM,MAAM,CAACC,SACPC,IAAI,CAAC,KAAI"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
3
|
+
import { createMongoSchemaBuildContext } from './schemaBuildContext.js';
|
|
4
|
+
describe('createMongoSchemaBuildContext', ()=>{
|
|
5
|
+
test('should reuse schemas when the connection has no custom plugins', ()=>{
|
|
6
|
+
const connection = mongoose.createConnection();
|
|
7
|
+
const context = createMongoSchemaBuildContext({
|
|
8
|
+
connection
|
|
9
|
+
});
|
|
10
|
+
const definition = {};
|
|
11
|
+
const build = vi.fn(()=>new mongoose.Schema());
|
|
12
|
+
const first = context.getOrCreate({
|
|
13
|
+
build,
|
|
14
|
+
definition,
|
|
15
|
+
cacheKey: 'block:shared'
|
|
16
|
+
});
|
|
17
|
+
const second = context.getOrCreate({
|
|
18
|
+
build,
|
|
19
|
+
definition,
|
|
20
|
+
cacheKey: 'block:shared'
|
|
21
|
+
});
|
|
22
|
+
expect(first).toBe(second);
|
|
23
|
+
expect(build).toHaveBeenCalledOnce();
|
|
24
|
+
});
|
|
25
|
+
test('should build independent schemas when the connection has a custom plugin', ()=>{
|
|
26
|
+
const connection = mongoose.createConnection();
|
|
27
|
+
connection.plugin(()=>undefined);
|
|
28
|
+
const context = createMongoSchemaBuildContext({
|
|
29
|
+
connection
|
|
30
|
+
});
|
|
31
|
+
const definition = {};
|
|
32
|
+
const build = vi.fn(()=>new mongoose.Schema());
|
|
33
|
+
const first = context.getOrCreate({
|
|
34
|
+
build,
|
|
35
|
+
definition,
|
|
36
|
+
cacheKey: 'block:shared'
|
|
37
|
+
});
|
|
38
|
+
const second = context.getOrCreate({
|
|
39
|
+
build,
|
|
40
|
+
definition,
|
|
41
|
+
cacheKey: 'block:shared'
|
|
42
|
+
});
|
|
43
|
+
expect(first).not.toBe(second);
|
|
44
|
+
expect(build).toHaveBeenCalledTimes(2);
|
|
45
|
+
});
|
|
46
|
+
test('should build independent schemas when the Mongoose instance has a custom plugin', ()=>{
|
|
47
|
+
const mongooseWithCustomPlugin = new mongoose.Mongoose({
|
|
48
|
+
createInitialConnection: false
|
|
49
|
+
});
|
|
50
|
+
mongooseWithCustomPlugin.plugin(()=>undefined);
|
|
51
|
+
const connection = mongooseWithCustomPlugin.createConnection();
|
|
52
|
+
const context = createMongoSchemaBuildContext({
|
|
53
|
+
connection
|
|
54
|
+
});
|
|
55
|
+
const definition = {};
|
|
56
|
+
const build = vi.fn(()=>new mongoose.Schema());
|
|
57
|
+
const first = context.getOrCreate({
|
|
58
|
+
build,
|
|
59
|
+
definition,
|
|
60
|
+
cacheKey: 'block:shared'
|
|
61
|
+
});
|
|
62
|
+
const second = context.getOrCreate({
|
|
63
|
+
build,
|
|
64
|
+
definition,
|
|
65
|
+
cacheKey: 'block:shared'
|
|
66
|
+
});
|
|
67
|
+
expect(first).not.toBe(second);
|
|
68
|
+
expect(build).toHaveBeenCalledTimes(2);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=schemaBuildContext.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/models/schemaBuildContext.spec.ts"],"sourcesContent":["import mongoose from 'mongoose'\nimport { describe, expect, test, vi } from 'vitest'\n\nimport { createMongoSchemaBuildContext } from './schemaBuildContext.js'\n\ndescribe('createMongoSchemaBuildContext', () => {\n test('should reuse schemas when the connection has no custom plugins', () => {\n const connection = mongoose.createConnection()\n const context = createMongoSchemaBuildContext({ connection })\n const definition = {}\n const build = vi.fn(() => new mongoose.Schema())\n\n const first = context.getOrCreate({\n build,\n definition,\n cacheKey: 'block:shared',\n })\n const second = context.getOrCreate({\n build,\n definition,\n cacheKey: 'block:shared',\n })\n\n expect(first).toBe(second)\n expect(build).toHaveBeenCalledOnce()\n })\n\n test('should build independent schemas when the connection has a custom plugin', () => {\n const connection = mongoose.createConnection()\n connection.plugin(() => undefined)\n const context = createMongoSchemaBuildContext({ connection })\n const definition = {}\n const build = vi.fn(() => new mongoose.Schema())\n\n const first = context.getOrCreate({\n build,\n definition,\n cacheKey: 'block:shared',\n })\n const second = context.getOrCreate({\n build,\n definition,\n cacheKey: 'block:shared',\n })\n\n expect(first).not.toBe(second)\n expect(build).toHaveBeenCalledTimes(2)\n })\n\n test('should build independent schemas when the Mongoose instance has a custom plugin', () => {\n const mongooseWithCustomPlugin = new mongoose.Mongoose({ createInitialConnection: false })\n mongooseWithCustomPlugin.plugin(() => undefined)\n const connection = mongooseWithCustomPlugin.createConnection()\n const context = createMongoSchemaBuildContext({ connection })\n const definition = {}\n const build = vi.fn(() => new mongoose.Schema())\n\n const first = context.getOrCreate({\n build,\n definition,\n cacheKey: 'block:shared',\n })\n const second = context.getOrCreate({\n build,\n definition,\n cacheKey: 'block:shared',\n })\n\n expect(first).not.toBe(second)\n expect(build).toHaveBeenCalledTimes(2)\n })\n})\n"],"names":["mongoose","describe","expect","test","vi","createMongoSchemaBuildContext","connection","createConnection","context","definition","build","fn","Schema","first","getOrCreate","cacheKey","second","toBe","toHaveBeenCalledOnce","plugin","undefined","not","toHaveBeenCalledTimes","mongooseWithCustomPlugin","Mongoose","createInitialConnection"],"mappings":"AAAA,OAAOA,cAAc,WAAU;AAC/B,SAASC,QAAQ,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAQ,SAAQ;AAEnD,SAASC,6BAA6B,QAAQ,0BAAyB;AAEvEJ,SAAS,iCAAiC;IACxCE,KAAK,kEAAkE;QACrE,MAAMG,aAAaN,SAASO,gBAAgB;QAC5C,MAAMC,UAAUH,8BAA8B;YAAEC;QAAW;QAC3D,MAAMG,aAAa,CAAC;QACpB,MAAMC,QAAQN,GAAGO,EAAE,CAAC,IAAM,IAAIX,SAASY,MAAM;QAE7C,MAAMC,QAAQL,QAAQM,WAAW,CAAC;YAChCJ;YACAD;YACAM,UAAU;QACZ;QACA,MAAMC,SAASR,QAAQM,WAAW,CAAC;YACjCJ;YACAD;YACAM,UAAU;QACZ;QAEAb,OAAOW,OAAOI,IAAI,CAACD;QACnBd,OAAOQ,OAAOQ,oBAAoB;IACpC;IAEAf,KAAK,4EAA4E;QAC/E,MAAMG,aAAaN,SAASO,gBAAgB;QAC5CD,WAAWa,MAAM,CAAC,IAAMC;QACxB,MAAMZ,UAAUH,8BAA8B;YAAEC;QAAW;QAC3D,MAAMG,aAAa,CAAC;QACpB,MAAMC,QAAQN,GAAGO,EAAE,CAAC,IAAM,IAAIX,SAASY,MAAM;QAE7C,MAAMC,QAAQL,QAAQM,WAAW,CAAC;YAChCJ;YACAD;YACAM,UAAU;QACZ;QACA,MAAMC,SAASR,QAAQM,WAAW,CAAC;YACjCJ;YACAD;YACAM,UAAU;QACZ;QAEAb,OAAOW,OAAOQ,GAAG,CAACJ,IAAI,CAACD;QACvBd,OAAOQ,OAAOY,qBAAqB,CAAC;IACtC;IAEAnB,KAAK,mFAAmF;QACtF,MAAMoB,2BAA2B,IAAIvB,SAASwB,QAAQ,CAAC;YAAEC,yBAAyB;QAAM;QACxFF,yBAAyBJ,MAAM,CAAC,IAAMC;QACtC,MAAMd,aAAaiB,yBAAyBhB,gBAAgB;QAC5D,MAAMC,UAAUH,8BAA8B;YAAEC;QAAW;QAC3D,MAAMG,aAAa,CAAC;QACpB,MAAMC,QAAQN,GAAGO,EAAE,CAAC,IAAM,IAAIX,SAASY,MAAM;QAE7C,MAAMC,QAAQL,QAAQM,WAAW,CAAC;YAChCJ;YACAD;YACAM,UAAU;QACZ;QACA,MAAMC,SAASR,QAAQM,WAAW,CAAC;YACjCJ;YACAD;YACAM,UAAU;QACZ;QAEAb,OAAOW,OAAOQ,GAAG,CAACJ,IAAI,CAACD;QACvBd,OAAOQ,OAAOY,qBAAqB,CAAC;IACtC;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.91.0-internal.07e4582",
|
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"@types/prompts": "^2.4.5",
|
|
54
54
|
"mongodb": "6.20.0",
|
|
55
55
|
"mongodb-memory-server": "10.1.4",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
56
|
+
"payload": "3.91.0-internal.07e4582",
|
|
57
|
+
"@payloadcms/eslint-config": "3.28.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"payload": "3.
|
|
60
|
+
"payload": "3.91.0-internal.07e4582"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "pnpm build:types && pnpm build:swc",
|