@payloadcms/next 4.0.0-canary.36 → 4.0.0-canary.37

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.
@@ -0,0 +1,8 @@
1
+ import type { InitReqResult } from 'payload';
2
+ import type { InitReqArgs } from 'payload/internal';
3
+ type NextInitReqArgs = {
4
+ key: string;
5
+ } & Omit<InitReqArgs, 'cache' | 'key' | 'serverAdapter'>;
6
+ export declare const initReq: (args: NextInitReqArgs) => Promise<InitReqResult>;
7
+ export {};
8
+ //# sourceMappingURL=initReq.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initReq.d.ts","sourceRoot":"","sources":["../../src/utilities/initReq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAsC,MAAM,kBAAkB,CAAA;AAsBvF,KAAK,eAAe,GAAG;IACrB,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,KAAK,GAAG,eAAe,CAAC,CAAA;AAExD,eAAO,MAAM,OAAO,SAAU,eAAe,2BAKzC,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { initReq as initPayloadReq } from 'payload/internal';
2
+ import { nextServerAdapter } from '../adapters/server.js';
3
+ import { selectiveCache } from './selectiveCache.js';
4
+ const partialResultCache = selectiveCache('partialResult');
5
+ const localeCache = selectiveCache('locale');
6
+ const requestResultCache = selectiveCache('requestResult');
7
+ const cache = {
8
+ getLocale: (resolveLocale, ...key) => localeCache.get({
9
+ create: resolveLocale,
10
+ key
11
+ }),
12
+ getPartial: createPartialResult => partialResultCache.get({
13
+ create: createPartialResult,
14
+ key: ['global']
15
+ }),
16
+ getRequest: (createRequestResult, key, ...cacheArgs) => requestResultCache.get({
17
+ create: createRequestResult,
18
+ key: [key, ...cacheArgs]
19
+ })
20
+ };
21
+ export const initReq = args => initPayloadReq({
22
+ ...args,
23
+ cache,
24
+ serverAdapter: nextServerAdapter
25
+ });
26
+ //# sourceMappingURL=initReq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initReq.js","names":["initReq","initPayloadReq","nextServerAdapter","selectiveCache","partialResultCache","localeCache","requestResultCache","cache","getLocale","resolveLocale","key","get","create","getPartial","createPartialResult","getRequest","createRequestResult","cacheArgs","args","serverAdapter"],"sources":["../../src/utilities/initReq.ts"],"sourcesContent":["import type { InitReqResult } from 'payload'\nimport type { InitReqArgs, InitReqCache, InitReqPartialResult } from 'payload/internal'\n\nimport { initReq as initPayloadReq } from 'payload/internal'\n\nimport { nextServerAdapter } from '../adapters/server.js'\nimport { selectiveCache } from './selectiveCache.js'\n\nconst partialResultCache = selectiveCache<InitReqPartialResult>('partialResult')\nconst localeCache = selectiveCache<Pick<InitReqResult, 'locale'>>('locale')\nconst requestResultCache = selectiveCache<InitReqResult>('requestResult')\n\nconst cache: InitReqCache = {\n getLocale: (resolveLocale, ...key) => localeCache.get({ create: resolveLocale, key }),\n getPartial: (createPartialResult) =>\n partialResultCache.get({ create: createPartialResult, key: ['global'] }),\n getRequest: (createRequestResult, key, ...cacheArgs) =>\n requestResultCache.get({\n create: createRequestResult,\n key: [key, ...cacheArgs],\n }),\n}\n\ntype NextInitReqArgs = {\n key: string\n} & Omit<InitReqArgs, 'cache' | 'key' | 'serverAdapter'>\n\nexport const initReq = (args: NextInitReqArgs) =>\n initPayloadReq({\n ...args,\n cache,\n serverAdapter: nextServerAdapter,\n })\n"],"mappings":"AAGA,SAASA,OAAA,IAAWC,cAAc,QAAQ;AAE1C,SAASC,iBAAiB,QAAQ;AAClC,SAASC,cAAc,QAAQ;AAE/B,MAAMC,kBAAA,GAAqBD,cAAA,CAAqC;AAChE,MAAME,WAAA,GAAcF,cAAA,CAA8C;AAClE,MAAMG,kBAAA,GAAqBH,cAAA,CAA8B;AAEzD,MAAMI,KAAA,GAAsB;EAC1BC,SAAA,EAAWA,CAACC,aAAA,EAAe,GAAGC,GAAA,KAAQL,WAAA,CAAYM,GAAG,CAAC;IAAEC,MAAA,EAAQH,aAAA;IAAeC;EAAI;EACnFG,UAAA,EAAaC,mBAAA,IACXV,kBAAA,CAAmBO,GAAG,CAAC;IAAEC,MAAA,EAAQE,mBAAA;IAAqBJ,GAAA,EAAK,CAAC;EAAU;EACxEK,UAAA,EAAYA,CAACC,mBAAA,EAAqBN,GAAA,EAAK,GAAGO,SAAA,KACxCX,kBAAA,CAAmBK,GAAG,CAAC;IACrBC,MAAA,EAAQI,mBAAA;IACRN,GAAA,EAAK,CAACA,GAAA,E,GAAQO,SAAA;EAChB;AACJ;AAMA,OAAO,MAAMjB,OAAA,GAAWkB,IAAA,IACtBjB,cAAA,CAAe;EACb,GAAGiB,IAAI;EACPX,KAAA;EACAY,aAAA,EAAejB;AACjB","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ type CachedValue = object;
2
+ type GetCachedArgs<TValue extends object> = {
3
+ /** Creates the value when it is not cached. */
4
+ create: () => Promise<TValue>;
5
+ /** Values that identify the cached value. */
6
+ key: unknown[];
7
+ };
8
+ /**
9
+ * Creates a selective cache function that provides more control over React's request-level caching behavior.
10
+ *
11
+ * @param namespace - A namespace to group related cached values
12
+ * @returns A function that manages cached values within the specified namespace
13
+ */
14
+ export declare function selectiveCache<TValue extends object = CachedValue>(namespace: string): {
15
+ get: ({ create, key }: GetCachedArgs<TValue>) => Promise<TValue>;
16
+ };
17
+ export {};
18
+ //# sourceMappingURL=selectiveCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectiveCache.d.ts","sourceRoot":"","sources":["../../src/utilities/selectiveCache.ts"],"names":[],"mappings":"AAEA,KAAK,WAAW,GAAG,MAAM,CAAA;AAEzB,KAAK,aAAa,CAAC,MAAM,SAAS,MAAM,IAAI;IAC1C,+CAA+C;IAC/C,MAAM,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;IAC7B,6CAA6C;IAC7C,GAAG,EAAE,OAAO,EAAE,CAAA;CACf,CAAA;AAaD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,SAAS,MAAM,GAAG,WAAW,EAAE,SAAS,EAAE,MAAM;IA4BjF,GAAG,oBAlBqC,aAAa,CAAC,MAAM,CAAC,KAAG,OAAO,CAAC,MAAM,CAAC;EAoBlF"}
@@ -0,0 +1,36 @@
1
+ import { cache } from 'react';
2
+ // Module-scoped cache container that holds all cached, stable containers
3
+ // - these may hold the stable value, or a promise to the stable value
4
+ const globalCacheContainer = {};
5
+ /**
6
+ * Creates a selective cache function that provides more control over React's request-level caching behavior.
7
+ *
8
+ * @param namespace - A namespace to group related cached values
9
+ * @returns A function that manages cached values within the specified namespace
10
+ */
11
+ export function selectiveCache(namespace) {
12
+ if (!globalCacheContainer[namespace]) {
13
+ globalCacheContainer[namespace] = cache((..._args) => ({
14
+ value: null
15
+ }));
16
+ }
17
+ /**
18
+ * Gets or creates a cached value for a specific key within the namespace
19
+ */
20
+ const getCached = async ({
21
+ create,
22
+ key
23
+ }) => {
24
+ const stableObjectFn = globalCacheContainer[namespace];
25
+ const stableObject = stableObjectFn(...key);
26
+ if (stableObject?.value && 'then' in stableObject.value && typeof stableObject.value?.then === 'function') {
27
+ return await stableObject.value;
28
+ }
29
+ stableObject.value = create();
30
+ return await stableObject.value;
31
+ };
32
+ return {
33
+ get: getCached
34
+ };
35
+ }
36
+ //# sourceMappingURL=selectiveCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selectiveCache.js","names":["cache","globalCacheContainer","selectiveCache","namespace","_args","value","getCached","create","key","stableObjectFn","stableObject","then","get"],"sources":["../../src/utilities/selectiveCache.ts"],"sourcesContent":["import { cache } from 'react'\n\ntype CachedValue = object\n\ntype GetCachedArgs<TValue extends object> = {\n /** Creates the value when it is not cached. */\n create: () => Promise<TValue>\n /** Values that identify the cached value. */\n key: unknown[]\n}\n\n// Module-scoped cache container that holds all cached, stable containers\n// - these may hold the stable value, or a promise to the stable value\nconst globalCacheContainer: Record<\n string,\n <TValue extends object = CachedValue>(\n ...args: unknown[]\n ) => {\n value: null | Promise<TValue> | TValue\n }\n> = {}\n\n/**\n * Creates a selective cache function that provides more control over React's request-level caching behavior.\n *\n * @param namespace - A namespace to group related cached values\n * @returns A function that manages cached values within the specified namespace\n */\nexport function selectiveCache<TValue extends object = CachedValue>(namespace: string) {\n if (!globalCacheContainer[namespace]) {\n globalCacheContainer[namespace] = cache((..._args) => ({\n value: null,\n }))\n }\n\n /**\n * Gets or creates a cached value for a specific key within the namespace\n */\n const getCached = async ({ create, key }: GetCachedArgs<TValue>): Promise<TValue> => {\n const stableObjectFn = globalCacheContainer[namespace]\n const stableObject = stableObjectFn<TValue>(...key)\n\n if (\n stableObject?.value &&\n 'then' in stableObject.value &&\n typeof stableObject.value?.then === 'function'\n ) {\n return await stableObject.value\n }\n\n stableObject.value = create()\n\n return await stableObject.value\n }\n\n return {\n get: getCached,\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ;AAWtB;AACA;AACA,MAAMC,oBAAA,GAOF,CAAC;AAEL;;;;;;AAMA,OAAO,SAASC,eAAoDC,SAAiB;EACnF,IAAI,CAACF,oBAAoB,CAACE,SAAA,CAAU,EAAE;IACpCF,oBAAoB,CAACE,SAAA,CAAU,GAAGH,KAAA,CAAM,CAAC,GAAGI,KAAA,MAAW;MACrDC,KAAA,EAAO;IACT;EACF;EAEA;;;EAGA,MAAMC,SAAA,GAAY,MAAAA,CAAO;IAAEC,MAAM;IAAEC;EAAG,CAAyB;IAC7D,MAAMC,cAAA,GAAiBR,oBAAoB,CAACE,SAAA,CAAU;IACtD,MAAMO,YAAA,GAAeD,cAAA,IAA0BD,GAAA;IAE/C,IACEE,YAAA,EAAcL,KAAA,IACd,UAAUK,YAAA,CAAaL,KAAK,IAC5B,OAAOK,YAAA,CAAaL,KAAK,EAAEM,IAAA,KAAS,YACpC;MACA,OAAO,MAAMD,YAAA,CAAaL,KAAK;IACjC;IAEAK,YAAA,CAAaL,KAAK,GAAGE,MAAA;IAErB,OAAO,MAAMG,YAAA,CAAaL,KAAK;EACjC;EAEA,OAAO;IACLO,GAAA,EAAKN;EACP;AACF","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/next",
3
- "version": "4.0.0-canary.36",
3
+ "version": "4.0.0-canary.37",
4
4
  "homepage": "https://payloadcms.com",
5
5
  "repository": {
6
6
  "type": "git",
@@ -84,9 +84,9 @@
84
84
  "qs-esm": "8.0.1",
85
85
  "sass": "1.77.4",
86
86
  "uuid": "14.0.0",
87
- "@payloadcms/graphql": "4.0.0-canary.36",
88
- "@payloadcms/ui": "4.0.0-canary.36",
89
- "@payloadcms/translations": "4.0.0-canary.36"
87
+ "@payloadcms/graphql": "4.0.0-canary.37",
88
+ "@payloadcms/translations": "4.0.0-canary.37",
89
+ "@payloadcms/ui": "4.0.0-canary.37"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@babel/cli": "7.27.2",
@@ -103,12 +103,12 @@
103
103
  "esbuild-sass-plugin": "3.3.1",
104
104
  "swc-plugin-transform-remove-imports": "8.3.0",
105
105
  "@payloadcms/eslint-config": "3.28.0",
106
- "payload": "4.0.0-canary.36"
106
+ "payload": "4.0.0-canary.37"
107
107
  },
108
108
  "peerDependencies": {
109
109
  "graphql": "^16.8.1",
110
110
  "next": ">=16.2.6 <17.0.0",
111
- "payload": "4.0.0-canary.36"
111
+ "payload": "4.0.0-canary.37"
112
112
  },
113
113
  "engines": {
114
114
  "node": ">=24.15.0"