Files
klz-cables.com/.pnpm-store/v10/files/dd/99e06201a70823c1b539bf385a89e04a5edd37daa5bb951f937131b3e66566a098e779e66300c6a5635c7f68d1aa23c0930ae9289ad883988d2bfe3a932804
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

125 lines
3.2 KiB
Plaintext

/** Mocked `req`, we don't need to use transactions, neither we want `createLocalReq` overhead. */ const req = {};
export class DatabaseKVAdapter {
payload;
collectionSlug;
constructor(payload, collectionSlug){
this.payload = payload;
this.collectionSlug = collectionSlug;
}
async clear() {
await this.payload.db.deleteMany({
collection: this.collectionSlug,
req,
where: {}
});
}
async delete(key) {
await this.payload.db.deleteOne({
collection: this.collectionSlug,
req,
where: {
key: {
equals: key
}
}
});
}
async get(key) {
const doc = await this.payload.db.findOne({
collection: this.collectionSlug,
joins: false,
req,
select: {
data: true,
key: true
},
where: {
key: {
equals: key
}
}
});
if (doc === null) {
return null;
}
return doc.data;
}
async has(key) {
const { totalDocs } = await this.payload.db.count({
collection: this.collectionSlug,
req,
where: {
key: {
equals: key
}
}
});
return totalDocs > 0;
}
async keys() {
const result = await this.payload.db.find({
collection: this.collectionSlug,
limit: 0,
pagination: false,
req,
select: {
key: true
}
});
return result.docs.map((each)=>each.key);
}
async set(key, data) {
await this.payload.db.upsert({
collection: this.collectionSlug,
data: {
data,
key
},
joins: false,
req,
select: {},
where: {
key: {
equals: key
}
}
});
}
}
export const databaseKVAdapter = (options = {})=>{
const collectionSlug = options.kvCollectionOverrides?.slug ?? 'payload-kv';
return {
init: ({ payload })=>new DatabaseKVAdapter(payload, collectionSlug),
kvCollection: {
slug: collectionSlug,
access: {
create: ()=>false,
delete: ()=>false,
read: ()=>false,
update: ()=>false
},
admin: {
hidden: true
},
fields: [
{
name: 'key',
type: 'text',
index: true,
required: true,
unique: true
},
{
name: 'data',
type: 'json',
required: true
}
],
lockDocuments: false,
timestamps: false,
...options.kvCollectionOverrides
}
};
};
//# sourceMappingURL=DatabaseKVAdapter.js.map