payload-smart-cache 1.1.1 → 1.1.3
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/LICENSE +21 -0
- package/dist/endpoints/publish.d.ts.map +1 -1
- package/dist/endpoints/publish.js +5 -3
- package/dist/endpoints/publish.js.map +1 -1
- package/package.json +26 -26
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 DAVINCI CODING GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../../src/endpoints/publish.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAKvD,eAAO,MAAM,4BAA4B,mBACvB,sBAAsB,CAAC,gBAAgB,CAAC,KACvD,
|
|
1
|
+
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../../src/endpoints/publish.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGxD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAKvD,eAAO,MAAM,4BAA4B,mBACvB,sBAAsB,CAAC,gBAAgB,CAAC,KACvD,QAoIC,CAAC"}
|
|
@@ -13,8 +13,8 @@ export const createPublishChangesEndpoint = (publishHandler)=>ENDPOINTS.publishC
|
|
|
13
13
|
limit: 0,
|
|
14
14
|
sort: '-updatedAt'
|
|
15
15
|
});
|
|
16
|
-
if (changesToPublish.length === 0) return
|
|
17
|
-
|
|
16
|
+
if (changesToPublish.length === 0) return Response.json({
|
|
17
|
+
message: 'No changes to publish'
|
|
18
18
|
});
|
|
19
19
|
const tagsToInvalidate = new Set();
|
|
20
20
|
const collectionChanges = new CollectionChanges();
|
|
@@ -96,7 +96,9 @@ export const createPublishChangesEndpoint = (publishHandler)=>ENDPOINTS.publishC
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
|
-
return
|
|
99
|
+
return Response.json({
|
|
100
|
+
message: 'OK'
|
|
101
|
+
}, {
|
|
100
102
|
headers: headersWithCors({
|
|
101
103
|
headers: new Headers(),
|
|
102
104
|
req
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/publish.ts"],"sourcesContent":["import { revalidateTag } from 'next/cache';\nimport type { CollectionSlug, Endpoint } from 'payload';\nimport { APIError, headersWithCors } from 'payload';\nimport { ENDPOINTS } from '@/const';\nimport type { SmartCachePluginConfig } from '../index';\nimport type { EntitySlug } from '../types';\nimport { CollectionChanges } from '../utils/collection-changes';\nimport { createDependencyGraph } from '../utils/dependency-graph';\n\nexport const createPublishChangesEndpoint = (\n publishHandler: SmartCachePluginConfig['publishHandler'],\n): Endpoint =>\n ENDPOINTS.publishChanges.endpoint(async (req) => {\n if (!req.user) {\n throw new APIError('Unauthorized', 401);\n }\n\n const { payload } = req;\n\n const { docs: changesToPublish } = await payload.find({\n collection: 'publish-queue',\n limit: 0,\n sort: '-updatedAt',\n });\n\n if (changesToPublish.length === 0)\n return
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/publish.ts"],"sourcesContent":["import { revalidateTag } from 'next/cache';\nimport type { CollectionSlug, Endpoint } from 'payload';\nimport { APIError, headersWithCors } from 'payload';\nimport { ENDPOINTS } from '@/const';\nimport type { SmartCachePluginConfig } from '../index';\nimport type { EntitySlug } from '../types';\nimport { CollectionChanges } from '../utils/collection-changes';\nimport { createDependencyGraph } from '../utils/dependency-graph';\n\nexport const createPublishChangesEndpoint = (\n publishHandler: SmartCachePluginConfig['publishHandler'],\n): Endpoint =>\n ENDPOINTS.publishChanges.endpoint(async (req) => {\n if (!req.user) {\n throw new APIError('Unauthorized', 401);\n }\n\n const { payload } = req;\n\n const { docs: changesToPublish } = await payload.find({\n collection: 'publish-queue',\n limit: 0,\n sort: '-updatedAt',\n });\n\n if (changesToPublish.length === 0)\n return Response.json({ message: 'No changes to publish' });\n\n const tagsToInvalidate = new Set<EntitySlug>();\n const collectionChanges = new CollectionChanges();\n\n for (const change of changesToPublish) {\n if (typeof change.entityId !== 'string') {\n tagsToInvalidate.add(change.entityType as EntitySlug);\n }\n }\n\n collectionChanges.initialize(changesToPublish);\n\n const graph = createDependencyGraph(payload);\n\n async function trackAffectedItems(\n collection: CollectionSlug,\n ids: string[],\n visited: Set<string>,\n ): Promise<void> {\n const dependents = graph.getDependants(collection);\n\n if (dependents.length === 0) return;\n\n for (const dependent of dependents) {\n if (dependent.entity.type === 'global') {\n tagsToInvalidate.add(dependent.entity.slug);\n continue;\n }\n\n if (visited.has(dependent.entity.slug)) continue;\n\n // Query each field separately to avoid duplicate table alias errors\n // when multiple fields map to the same table (e.g., highlights.split-image-text.image\n // and architecture.split-image-text.image both use projects_blocks_split_image_text)\n const allAffectedItems = new Map<\n string,\n {\n id: string | number;\n }\n >();\n\n for (const field of dependent.fields) {\n const { docs } = await payload.find({\n collection: dependent.entity.slug,\n where: field.polymorphic\n ? {\n and: [\n { [`${field.field}.relationTo`]: { equals: collection } },\n { [`${field.field}.value`]: { in: ids } },\n ],\n }\n : {\n [field.field]: {\n in: ids,\n },\n },\n });\n\n // Use a Map keyed by ID to deduplicate results\n for (const item of docs) {\n allAffectedItems.set(item.id.toString(), item);\n }\n }\n\n const affectedItems = Array.from(allAffectedItems.values());\n\n visited.add(dependent.entity.slug);\n\n if (affectedItems.length === 0) continue;\n\n for (const item of affectedItems) {\n collectionChanges.addItem(dependent.entity.slug, item.id.toString());\n }\n\n await trackAffectedItems(\n dependent.entity.slug,\n affectedItems.map((item) => item.id.toString()),\n visited,\n );\n }\n }\n\n const initialCollections = Array.from(collectionChanges.entries()).map(\n ([slug, ids]) => [slug, Array.from(ids)] as const,\n );\n\n for (const [collection, ids] of initialCollections) {\n await trackAffectedItems(collection, ids, new Set<string>());\n }\n\n for (const entity of collectionChanges.keys()) {\n tagsToInvalidate.add(entity);\n }\n\n for (const tag of tagsToInvalidate) {\n revalidateTag(tag);\n }\n\n await publishHandler?.(collectionChanges.serialize());\n\n await payload.delete({\n collection: 'publish-queue',\n where: {\n id: { in: changesToPublish.map((change) => change.id) },\n },\n });\n\n return Response.json(\n { message: 'OK' },\n {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n },\n );\n });\n"],"names":["revalidateTag","APIError","headersWithCors","ENDPOINTS","CollectionChanges","createDependencyGraph","createPublishChangesEndpoint","publishHandler","publishChanges","endpoint","req","user","payload","docs","changesToPublish","find","collection","limit","sort","length","Response","json","message","tagsToInvalidate","Set","collectionChanges","change","entityId","add","entityType","initialize","graph","trackAffectedItems","ids","visited","dependents","getDependants","dependent","entity","type","slug","has","allAffectedItems","Map","field","fields","where","polymorphic","and","equals","in","item","set","id","toString","affectedItems","Array","from","values","addItem","map","initialCollections","entries","keys","tag","serialize","delete","headers","Headers"],"mappings":"AAAA,SAASA,aAAa,QAAQ,aAAa;AAE3C,SAASC,QAAQ,EAAEC,eAAe,QAAQ,UAAU;AACpD,SAASC,SAAS,QAAQ,UAAU;AAGpC,SAASC,iBAAiB,QAAQ,8BAA8B;AAChE,SAASC,qBAAqB,QAAQ,4BAA4B;AAElE,OAAO,MAAMC,+BAA+B,CAC1CC,iBAEAJ,UAAUK,cAAc,CAACC,QAAQ,CAAC,OAAOC;QACvC,IAAI,CAACA,IAAIC,IAAI,EAAE;YACb,MAAM,IAAIV,SAAS,gBAAgB;QACrC;QAEA,MAAM,EAAEW,OAAO,EAAE,GAAGF;QAEpB,MAAM,EAAEG,MAAMC,gBAAgB,EAAE,GAAG,MAAMF,QAAQG,IAAI,CAAC;YACpDC,YAAY;YACZC,OAAO;YACPC,MAAM;QACR;QAEA,IAAIJ,iBAAiBK,MAAM,KAAK,GAC9B,OAAOC,SAASC,IAAI,CAAC;YAAEC,SAAS;QAAwB;QAE1D,MAAMC,mBAAmB,IAAIC;QAC7B,MAAMC,oBAAoB,IAAIrB;QAE9B,KAAK,MAAMsB,UAAUZ,iBAAkB;YACrC,IAAI,OAAOY,OAAOC,QAAQ,KAAK,UAAU;gBACvCJ,iBAAiBK,GAAG,CAACF,OAAOG,UAAU;YACxC;QACF;QAEAJ,kBAAkBK,UAAU,CAAChB;QAE7B,MAAMiB,QAAQ1B,sBAAsBO;QAEpC,eAAeoB,mBACbhB,UAA0B,EAC1BiB,GAAa,EACbC,OAAoB;YAEpB,MAAMC,aAAaJ,MAAMK,aAAa,CAACpB;YAEvC,IAAImB,WAAWhB,MAAM,KAAK,GAAG;YAE7B,KAAK,MAAM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C,MAAM,CAACE,IAAI,EACrBe,cAAcK,GAAG,CAAC,CAACT,OAASA,KAAKE,EAAE,CAACC,QAAQ,KAC5CpB;YAEJ;QACF;QAEA,MAAM2B,qBAAqBL,MAAMC,IAAI,CAAChC,kBAAkBqC,OAAO,IAAIF,GAAG,CACpE,CAAC,CAACpB,MAAMP,IAAI,GAAK;gBAACO;gBAAMgB,MAAMC,IAAI,CAACxB;aAAK;QAG1C,KAAK,MAAM,CAACjB,YAAYiB,IAAI,IAAI4B,mBAAoB;YAClD,MAAM7B,mBAAmBhB,YAAYiB,KAAK,IAAIT;QAChD;QAEA,KAAK,MAAMc,UAAUb,kBAAkBsC,IAAI,GAAI;YAC7CxC,iBAAiBK,GAAG,CAACU;QACvB;QAEA,KAAK,MAAM0B,OAAOzC,iBAAkB;YAClCvB,cAAcgE;QAChB;QAEA,MAAMzD,iBAAiBkB,kBAAkBwC,SAAS;QAElD,MAAMrD,QAAQsD,MAAM,CAAC;YACnBlD,YAAY;YACZ8B,OAAO;gBACLO,IAAI;oBAAEH,IAAIpC,iBAAiB8C,GAAG,CAAC,CAAClC,SAAWA,OAAO2B,EAAE;gBAAE;YACxD;QACF;QAEA,OAAOjC,SAASC,IAAI,CAClB;YAAEC,SAAS;QAAK,GAChB;YACE6C,SAASjE,gBAAgB;gBACvBiE,SAAS,IAAIC;gBACb1D;YACF;QACF;IAEJ,GAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payload-smart-cache",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Payload Plugin for Cached Data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"payload",
|
|
@@ -40,37 +40,25 @@
|
|
|
40
40
|
"files": [
|
|
41
41
|
"dist"
|
|
42
42
|
],
|
|
43
|
-
"scripts": {
|
|
44
|
-
"prebuild": "rm -f src/_common 2>/dev/null; pnpm typecheck",
|
|
45
|
-
"build": "plugin-build",
|
|
46
|
-
"clean": "rm -rf dist && rm -rf node_modules",
|
|
47
|
-
"dev": "plugin-build --watch",
|
|
48
|
-
"generate:types": "generate-types",
|
|
49
|
-
"lint": "biome check .",
|
|
50
|
-
"lint:fix": "biome check --write .",
|
|
51
|
-
"test": "vitest run --passWithNoTests",
|
|
52
|
-
"test:watch": "vitest",
|
|
53
|
-
"typecheck": "tsc --noEmit"
|
|
54
|
-
},
|
|
55
43
|
"dependencies": {
|
|
56
44
|
"graph-data-structure": "^4.5.0",
|
|
57
45
|
"lodash-es": "^4.17.21",
|
|
58
|
-
"zod": "
|
|
46
|
+
"zod": "4.3.5"
|
|
59
47
|
},
|
|
60
48
|
"devDependencies": {
|
|
61
|
-
"@payloadcms/ui": "
|
|
62
|
-
"@repo/common": "workspace:*",
|
|
49
|
+
"@payloadcms/ui": "3.72.0",
|
|
63
50
|
"@types/lodash-es": "^4.17.12",
|
|
64
51
|
"@types/node": "^22.5.4",
|
|
65
|
-
"@types/react": "
|
|
66
|
-
"@types/react-dom": "
|
|
67
|
-
"next": "
|
|
68
|
-
"payload": "
|
|
69
|
-
"react": "
|
|
70
|
-
"react-dom": "
|
|
71
|
-
"typescript": "
|
|
72
|
-
"vite": "
|
|
73
|
-
"vitest": "^3.1.2"
|
|
52
|
+
"@types/react": "19.2.1",
|
|
53
|
+
"@types/react-dom": "19.2.1",
|
|
54
|
+
"next": "15.5.9",
|
|
55
|
+
"payload": "3.72.0",
|
|
56
|
+
"react": "19.2.1",
|
|
57
|
+
"react-dom": "19.2.1",
|
|
58
|
+
"typescript": "5.7.3",
|
|
59
|
+
"vite": "7.0.6",
|
|
60
|
+
"vitest": "^3.1.2",
|
|
61
|
+
"@repo/common": "0.0.1"
|
|
74
62
|
},
|
|
75
63
|
"peerDependencies": {
|
|
76
64
|
"@payloadcms/next": ">=3.72.0",
|
|
@@ -84,5 +72,17 @@
|
|
|
84
72
|
},
|
|
85
73
|
"publishConfig": {
|
|
86
74
|
"access": "public"
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"prebuild": "rm -f src/_common 2>/dev/null; pnpm typecheck",
|
|
78
|
+
"build": "plugin-build",
|
|
79
|
+
"clean": "rm -rf dist && rm -rf node_modules",
|
|
80
|
+
"dev": "plugin-build --watch",
|
|
81
|
+
"generate:types": "generate-types",
|
|
82
|
+
"lint": "biome check .",
|
|
83
|
+
"lint:fix": "biome check --write .",
|
|
84
|
+
"test": "vitest run --passWithNoTests",
|
|
85
|
+
"test:watch": "vitest",
|
|
86
|
+
"typecheck": "tsc --noEmit"
|
|
87
87
|
}
|
|
88
|
-
}
|
|
88
|
+
}
|