@kyro-cms/core 0.12.66 → 0.12.67
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/README.md +1 -1
- package/dist/{WebhookService-Bue85CZq.d.ts → WebhookService-CGNSlclW.d.ts} +1 -1
- package/dist/{WebhookService-B-jb55_P.d.cts → WebhookService-CIQPD1We.d.cts} +1 -1
- package/dist/api-handler-graphql.cjs +1 -1
- package/dist/api-handler-graphql.js +1 -1
- package/dist/api-handler-trpc.cjs +1 -1
- package/dist/api-handler-trpc.js +1 -1
- package/dist/api-handler.cjs +1 -1
- package/dist/api-handler.js +1 -1
- package/dist/{base-CU2tjpsX.d.cts → base-Ds06wMo9.d.cts} +2 -2
- package/dist/{base-CTeNj4rw.d.ts → base-DxDXLyWe.d.ts} +2 -2
- package/dist/chunk-2XUD2OPJ.js +121 -0
- package/dist/{chunk-LVHWORV4.js → chunk-4YCI3HBD.js} +3 -3
- package/dist/chunk-7LLCXY5O.cjs +19 -0
- package/dist/{chunk-N4HVIKNF.cjs → chunk-B3BSVEFC.cjs} +1 -1
- package/dist/{chunk-EQDO2U65.cjs → chunk-CTIQQ3ZX.cjs} +17 -17
- package/dist/{chunk-EUOOUY3K.js → chunk-EJN3FJWB.js} +2 -2
- package/dist/{chunk-6VMTMVGV.cjs → chunk-GH4OVDIL.cjs} +1 -1
- package/dist/{chunk-YLJYAAXH.js → chunk-HEGM2QMX.js} +18 -18
- package/dist/{chunk-YFUH3SST.cjs → chunk-IL2TMAHB.cjs} +25 -25
- package/dist/chunk-JCEJ4VTN.js +20 -0
- package/dist/chunk-JSTDCK3Z.js +2 -0
- package/dist/chunk-MSC4G2HF.cjs +2 -0
- package/dist/{chunk-AXT3QPVM.js → chunk-MVZSSTCV.js} +26 -26
- package/dist/chunk-MYGHZQMO.cjs +1 -0
- package/dist/{chunk-KCQBV3MA.js → chunk-VTOL3URF.js} +1 -1
- package/dist/chunk-ZED7JS6I.cjs +120 -0
- package/dist/client.cjs +1 -1
- package/dist/client.d.cts +3 -3
- package/dist/client.d.ts +3 -3
- package/dist/client.js +1 -1
- package/dist/drizzle/index.cjs +1 -1
- package/dist/drizzle/index.d.cts +3 -3
- package/dist/drizzle/index.d.ts +3 -3
- package/dist/drizzle/index.js +1 -1
- package/dist/fields/index.d.cts +2 -2
- package/dist/fields/index.d.ts +2 -2
- package/dist/graphql/index.d.cts +3 -3
- package/dist/graphql/index.d.ts +3 -3
- package/dist/{index-HNBjfQpn.d.cts → index-BHYGO3yF.d.cts} +2 -2
- package/dist/{index-Bz9JqRGI.d.cts → index-D7kt5jT_.d.ts} +12 -1
- package/dist/{index-Bz9JqRGI.d.ts → index-DPtCjn94.d.cts} +12 -1
- package/dist/{index-DowyndWK.d.ts → index-DTy4k1oU.d.ts} +2 -2
- package/dist/index.cjs +5 -5
- package/dist/index.d.cts +12 -12
- package/dist/index.d.ts +12 -12
- package/dist/index.js +6 -6
- package/dist/{local-4MZ7KOL3.js → local-DPLKZQA3.js} +1 -1
- package/dist/{local-NDTKWJQ6.cjs → local-S5VA7IXE.cjs} +1 -1
- package/dist/mongodb/index.cjs +1 -1
- package/dist/mongodb/index.d.cts +3 -3
- package/dist/mongodb/index.d.ts +3 -3
- package/dist/mongodb/index.js +1 -1
- package/dist/rest/index.cjs +1 -1
- package/dist/rest/index.d.cts +4 -4
- package/dist/rest/index.d.ts +4 -4
- package/dist/rest/index.js +1 -1
- package/dist/templates/index.cjs +1 -1
- package/dist/templates/index.d.cts +2 -2
- package/dist/templates/index.d.ts +2 -2
- package/dist/templates/index.js +1 -1
- package/dist/trpc/index.d.cts +3 -3
- package/dist/trpc/index.d.ts +3 -3
- package/dist/{types-euTszc-1.d.cts → types-BKPEavuy.d.cts} +3 -0
- package/dist/{types-euTszc-1.d.ts → types-BKPEavuy.d.ts} +3 -0
- package/dist/{types-ComJeXGL.d.cts → types-BWJx6zzm.d.ts} +38 -14
- package/dist/{types-COokblgr.d.ts → types-CeAQSR87.d.cts} +38 -14
- package/package.json +2 -2
- package/dist/chunk-6KERPHAL.cjs +0 -2
- package/dist/chunk-FX3Y3ZT5.cjs +0 -120
- package/dist/chunk-HKYBQYAJ.cjs +0 -19
- package/dist/chunk-RVWHGHST.js +0 -121
- package/dist/chunk-T4JJVUGT.js +0 -20
|
@@ -30,6 +30,9 @@ interface FieldAdmin {
|
|
|
30
30
|
action?: string;
|
|
31
31
|
method?: string;
|
|
32
32
|
inline?: boolean;
|
|
33
|
+
compact?: boolean;
|
|
34
|
+
collapsible?: boolean;
|
|
35
|
+
initCollapsed?: boolean;
|
|
33
36
|
pickerMode?: "drawer" | "dropdown";
|
|
34
37
|
condition?: ((data: Record<string, unknown>, siblingData: Record<string, unknown>) => boolean) | DeclarativeCondition;
|
|
35
38
|
}
|
|
@@ -30,6 +30,9 @@ interface FieldAdmin {
|
|
|
30
30
|
action?: string;
|
|
31
31
|
method?: string;
|
|
32
32
|
inline?: boolean;
|
|
33
|
+
compact?: boolean;
|
|
34
|
+
collapsible?: boolean;
|
|
35
|
+
initCollapsed?: boolean;
|
|
33
36
|
pickerMode?: "drawer" | "dropdown";
|
|
34
37
|
condition?: ((data: Record<string, unknown>, siblingData: Record<string, unknown>) => boolean) | DeclarativeCondition;
|
|
35
38
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as Field } from './types-
|
|
1
|
+
import { F as Field } from './types-BKPEavuy.js';
|
|
2
2
|
|
|
3
3
|
interface Request {
|
|
4
4
|
body?: any;
|
|
@@ -417,16 +417,41 @@ interface AdminConfig {
|
|
|
417
417
|
};
|
|
418
418
|
layout?: "split" | "single";
|
|
419
419
|
}
|
|
420
|
-
/**
|
|
421
|
-
* Field overrides allow modifying specific field properties by path.
|
|
422
|
-
* Path uses dot notation: "fieldName" or "groupField.arrayField.targetField"
|
|
423
|
-
* Commonly used to extend relationship fields with additional collections.
|
|
424
|
-
*/
|
|
425
420
|
interface FieldOverrides {
|
|
426
|
-
[fieldPath: string]:
|
|
427
|
-
|
|
428
|
-
|
|
421
|
+
[fieldPath: string]: any;
|
|
422
|
+
}
|
|
423
|
+
interface CollectionOverrideConfig extends Partial<AdminConfig> {
|
|
424
|
+
label?: string;
|
|
425
|
+
singularLabel?: string;
|
|
426
|
+
labelPlural?: string;
|
|
427
|
+
labels?: {
|
|
428
|
+
singular?: string;
|
|
429
|
+
plural?: string;
|
|
429
430
|
};
|
|
431
|
+
hidden?: boolean;
|
|
432
|
+
timestamps?: boolean;
|
|
433
|
+
versions?: {
|
|
434
|
+
drafts?: boolean;
|
|
435
|
+
maxPerDoc?: number;
|
|
436
|
+
autosave?: boolean;
|
|
437
|
+
};
|
|
438
|
+
seo?: boolean | Record<string, any>;
|
|
439
|
+
access?: CollectionAccess;
|
|
440
|
+
hooks?: CollectionHooks;
|
|
441
|
+
fields?: FieldOverrides;
|
|
442
|
+
blocks?: Record<string, any> | any[];
|
|
443
|
+
tabs?: Record<string, any> | any[];
|
|
444
|
+
[key: string]: any;
|
|
445
|
+
}
|
|
446
|
+
interface GlobalOverrideConfig extends Partial<AdminConfig> {
|
|
447
|
+
label?: string;
|
|
448
|
+
hidden?: boolean;
|
|
449
|
+
access?: GlobalAccess;
|
|
450
|
+
hooks?: GlobalHooks;
|
|
451
|
+
fields?: FieldOverrides;
|
|
452
|
+
blocks?: Record<string, any> | any[];
|
|
453
|
+
tabs?: Record<string, any> | any[];
|
|
454
|
+
[key: string]: any;
|
|
430
455
|
}
|
|
431
456
|
interface UploadConfig {
|
|
432
457
|
staticDir?: string;
|
|
@@ -437,7 +462,7 @@ interface UploadConfig {
|
|
|
437
462
|
crop?: boolean;
|
|
438
463
|
focalPoint?: boolean;
|
|
439
464
|
formatOptions?: {
|
|
440
|
-
format: "webp" | "png" | "jpg";
|
|
465
|
+
format: "webp" | "png" | "jpg" | "avif";
|
|
441
466
|
options?: Record<string, unknown>;
|
|
442
467
|
};
|
|
443
468
|
resizeOptions?: Record<string, any>;
|
|
@@ -450,7 +475,7 @@ interface ImageSize {
|
|
|
450
475
|
crop?: string;
|
|
451
476
|
position?: string;
|
|
452
477
|
formatOptions?: {
|
|
453
|
-
format: "webp" | "png" | "jpg";
|
|
478
|
+
format: "webp" | "png" | "jpg" | "avif";
|
|
454
479
|
};
|
|
455
480
|
generateImageName?: (doc: any) => string;
|
|
456
481
|
}
|
|
@@ -722,9 +747,8 @@ interface KyroConfig {
|
|
|
722
747
|
disable?: boolean;
|
|
723
748
|
indexRoute?: string;
|
|
724
749
|
components?: Record<string, any>;
|
|
725
|
-
collectionOverrides?: Record<string,
|
|
726
|
-
|
|
727
|
-
}>;
|
|
750
|
+
collectionOverrides?: Record<string, CollectionOverrideConfig>;
|
|
751
|
+
globalOverrides?: Record<string, GlobalOverrideConfig>;
|
|
728
752
|
};
|
|
729
753
|
upload?: {
|
|
730
754
|
limits?: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as Field } from './types-
|
|
1
|
+
import { F as Field } from './types-BKPEavuy.cjs';
|
|
2
2
|
|
|
3
3
|
interface Request {
|
|
4
4
|
body?: any;
|
|
@@ -417,16 +417,41 @@ interface AdminConfig {
|
|
|
417
417
|
};
|
|
418
418
|
layout?: "split" | "single";
|
|
419
419
|
}
|
|
420
|
-
/**
|
|
421
|
-
* Field overrides allow modifying specific field properties by path.
|
|
422
|
-
* Path uses dot notation: "fieldName" or "groupField.arrayField.targetField"
|
|
423
|
-
* Commonly used to extend relationship fields with additional collections.
|
|
424
|
-
*/
|
|
425
420
|
interface FieldOverrides {
|
|
426
|
-
[fieldPath: string]:
|
|
427
|
-
|
|
428
|
-
|
|
421
|
+
[fieldPath: string]: any;
|
|
422
|
+
}
|
|
423
|
+
interface CollectionOverrideConfig extends Partial<AdminConfig> {
|
|
424
|
+
label?: string;
|
|
425
|
+
singularLabel?: string;
|
|
426
|
+
labelPlural?: string;
|
|
427
|
+
labels?: {
|
|
428
|
+
singular?: string;
|
|
429
|
+
plural?: string;
|
|
429
430
|
};
|
|
431
|
+
hidden?: boolean;
|
|
432
|
+
timestamps?: boolean;
|
|
433
|
+
versions?: {
|
|
434
|
+
drafts?: boolean;
|
|
435
|
+
maxPerDoc?: number;
|
|
436
|
+
autosave?: boolean;
|
|
437
|
+
};
|
|
438
|
+
seo?: boolean | Record<string, any>;
|
|
439
|
+
access?: CollectionAccess;
|
|
440
|
+
hooks?: CollectionHooks;
|
|
441
|
+
fields?: FieldOverrides;
|
|
442
|
+
blocks?: Record<string, any> | any[];
|
|
443
|
+
tabs?: Record<string, any> | any[];
|
|
444
|
+
[key: string]: any;
|
|
445
|
+
}
|
|
446
|
+
interface GlobalOverrideConfig extends Partial<AdminConfig> {
|
|
447
|
+
label?: string;
|
|
448
|
+
hidden?: boolean;
|
|
449
|
+
access?: GlobalAccess;
|
|
450
|
+
hooks?: GlobalHooks;
|
|
451
|
+
fields?: FieldOverrides;
|
|
452
|
+
blocks?: Record<string, any> | any[];
|
|
453
|
+
tabs?: Record<string, any> | any[];
|
|
454
|
+
[key: string]: any;
|
|
430
455
|
}
|
|
431
456
|
interface UploadConfig {
|
|
432
457
|
staticDir?: string;
|
|
@@ -437,7 +462,7 @@ interface UploadConfig {
|
|
|
437
462
|
crop?: boolean;
|
|
438
463
|
focalPoint?: boolean;
|
|
439
464
|
formatOptions?: {
|
|
440
|
-
format: "webp" | "png" | "jpg";
|
|
465
|
+
format: "webp" | "png" | "jpg" | "avif";
|
|
441
466
|
options?: Record<string, unknown>;
|
|
442
467
|
};
|
|
443
468
|
resizeOptions?: Record<string, any>;
|
|
@@ -450,7 +475,7 @@ interface ImageSize {
|
|
|
450
475
|
crop?: string;
|
|
451
476
|
position?: string;
|
|
452
477
|
formatOptions?: {
|
|
453
|
-
format: "webp" | "png" | "jpg";
|
|
478
|
+
format: "webp" | "png" | "jpg" | "avif";
|
|
454
479
|
};
|
|
455
480
|
generateImageName?: (doc: any) => string;
|
|
456
481
|
}
|
|
@@ -722,9 +747,8 @@ interface KyroConfig {
|
|
|
722
747
|
disable?: boolean;
|
|
723
748
|
indexRoute?: string;
|
|
724
749
|
components?: Record<string, any>;
|
|
725
|
-
collectionOverrides?: Record<string,
|
|
726
|
-
|
|
727
|
-
}>;
|
|
750
|
+
collectionOverrides?: Record<string, CollectionOverrideConfig>;
|
|
751
|
+
globalOverrides?: Record<string, GlobalOverrideConfig>;
|
|
728
752
|
};
|
|
729
753
|
upload?: {
|
|
730
754
|
limits?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kyro-cms/core",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.67",
|
|
4
4
|
"description": "Astro-native headless CMS with multi-database adapters, multi-protocol APIs, and multi-vendor support",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22"
|
|
@@ -191,7 +191,7 @@
|
|
|
191
191
|
"ws": "^8.18.0",
|
|
192
192
|
"zod": "^3.24.0",
|
|
193
193
|
"zod-to-json-schema": "^3.25.2",
|
|
194
|
-
"@kyro-cms/ai": "0.12.
|
|
194
|
+
"@kyro-cms/ai": "0.12.67"
|
|
195
195
|
},
|
|
196
196
|
"devDependencies": {
|
|
197
197
|
"@tailwindcss/vite": "^4.0.0",
|
package/dist/chunk-6KERPHAL.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var chunkVQ53TFYA_cjs=require('./chunk-VQ53TFYA.cjs'),chunkF4ITQ6XQ_cjs=require('./chunk-F4ITQ6XQ.cjs'),chunkZOVH6QT5_cjs=require('./chunk-ZOVH6QT5.cjs'),chunkBUNLC3II_cjs=require('./chunk-BUNLC3II.cjs'),crypto=require('crypto');chunkBUNLC3II_cjs.h();chunkBUNLC3II_cjs.h();var b=class extends chunkVQ53TFYA_cjs.a{dialect="mongodb";client;db;database;connectionString;constructor(o){if(super(),o.connectionString){this.connectionString=o.connectionString;try{let e=new URL(o.connectionString);this.database=e.pathname.replace(/^\//,"")||"kyro_cms";}catch{this.database="kyro_cms";}}else this.client=o.client,this.database=o.database;}async connect(){if(this.connectionString&&!this.client){let o;try{let e=await import('./lib-5QYYN6ML.cjs');o=e.MongoClient??e.default?.MongoClient;}catch{chunkF4ITQ6XQ_cjs.a(["mongodb"]);let n=await import('./lib-5QYYN6ML.cjs');o=n.MongoClient??n.default?.MongoClient;}this.client=new o(this.connectionString),await this.client.connect();}this.db=this.client.db(this.database),this.connected=true;}async disconnect(){this.client&&(await this.client.close(),this.connected=false);}getMongoCollection(o){if(!this.db)throw new Error("MongoDB not connected");return this.db.collection(o)}async find(o){let{collection:e,where:n={},sort:s,limit:t=10,page:i=1,tenantId:r,select:a,draft:d}=o,l=this.getCollectionConfig(e),f=this.getMongoCollection(e),g={...n};this.tenantContext&&l.tenantScoped&&(g=chunkVQ53TFYA_cjs.c({where:g},e,this.tenantContext,chunkVQ53TFYA_cjs.b).where||{});let u=this.buildFilter(g,l.tenantScoped?r:void 0),c=l.fields.find(p=>p.name==="status"),h=c?.type==="select"&&Array.isArray(c.options)&&c.options.some(p=>p.value==="published");!d&&h&&(u.status="published");let y=this.parseSort(s),O={[y.field]:y.direction==="asc"?1:-1},$=(i-1)*t,[x,M]=await Promise.all([f.find(u).sort(O).skip($).limit(t).project(this.buildProjection(a)).toArray(),f.countDocuments(u)]),C=x.map(p=>this.processResult(p,l));return this.tenantContext&&!this.tenantContext.isSuperAdmin&&(C=C.filter(p=>chunkVQ53TFYA_cjs.d(p,e,this.tenantContext,chunkVQ53TFYA_cjs.b))),d&&(C=await Promise.all(C.map(async p=>{let m=await this.getMongoCollection(`${e}_versions`).findOne({document_id:p.id},{sort:{createdAt:-1}});if(m){let P=typeof m.data=="string"?JSON.parse(m.data):m.data&&typeof m.data=="object"?m.data:{};return {...p,...P,status:p.status,_hasUnpublishedChanges:m.status==="draft"}}return p}))),{docs:C,...this.calculatePagination(i,t,M)}}async findByID(o){let{collection:e,id:n,tenantId:s,draft:t}=o,i=this.getCollectionConfig(e),r=this.getMongoCollection(e);if(this.tenantContext&&i.tenantScoped){let u={_id:n,tenantId:this.tenantContext.tenantId};if(!chunkVQ53TFYA_cjs.d(u,e,this.tenantContext,chunkVQ53TFYA_cjs.b))return null}let a={_id:n};s&&i.tenantScoped&&(a.tenantId=s);let d=i.fields.find(u=>u.name==="status"),l=d?.type==="select"&&Array.isArray(d.options)&&d.options.some(u=>u.value==="published");!t&&l&&(a.status="published");let f=await r.findOne(a);if(!f)return null;let g=this.processResult(f,i);if(t){let c=await this.getMongoCollection(`${e}_versions`).findOne({document_id:g.id},{sort:{createdAt:-1}});if(c){let h=typeof c.data=="string"?JSON.parse(c.data):c.data&&typeof c.data=="object"?c.data:{};g={...g,...h,status:g.status,_hasUnpublishedChanges:c.status==="draft"};}}return g}async create(o){let{collection:e,data:n,tenantId:s}=o,t=this.getCollectionConfig(e),i=this.getMongoCollection(e),r=this.prepareData(n,t),a=r.id||this.generateId();delete r.id;let d={...r,_id:a};return s&&t.tenantScoped&&(d.tenantId=s),await i.insertOne(d),this.processResult(d,t)}async update(o){let{collection:e,id:n,data:s,tenantId:t}=o,i=this.getCollectionConfig(e),r=this.getMongoCollection(e),a={_id:n};t&&i.tenantScoped&&(a.tenantId=t);let d=this.prepareData(s,i),l=await r.findOneAndUpdate(a,{$set:d},{returnDocument:"after"});if(!l)throw new Error(`Document not found: ${e}/${n}`);return this.processResult(l,i)}async delete(o){let{collection:e,id:n,tenantId:s}=o,t=this.getCollectionConfig(e),i=this.getMongoCollection(e),r={_id:n};s&&t.tenantScoped&&(r.tenantId=s);let a=await i.findOneAndDelete(r);if(!a)throw new Error(`Document not found: ${e}/${n}`);return this.processResult(a,t)}async count(o){let{collection:e,where:n={},tenantId:s}=o,t=this.getCollectionConfig(e),i=this.getMongoCollection(e),r=this.buildFilter(n,t.tenantScoped?s:void 0);return i.countDocuments(r)}async findOne(o){let{collection:e,where:n={},tenantId:s,draft:t}=o,i=this.getCollectionConfig(e),r=this.getMongoCollection(e),a=this.buildFilter(n,i.tenantScoped?s:void 0),d=i.fields.find(u=>u.name==="status"),l=d?.type==="select"&&Array.isArray(d.options)&&d.options.some(u=>u.value==="published");!t&&l&&(a.status="published");let f=await r.findOne(a);if(!f)return null;let g=this.processResult(f,i);if(t){let c=await this.getMongoCollection(`${e}_versions`).findOne({document_id:g.id},{sort:{createdAt:-1}});if(c){let h=typeof c.data=="string"?JSON.parse(c.data):c.data&&typeof c.data=="object"?c.data:{};g={...g,...h,status:g.status};}}return g}async findVersions(o){let{collection:e,documentId:n,sort:s,limit:t=10,page:i=1,tenantId:r}=o,a=this.getCollectionConfig(e),d=this.getMongoCollection(`${e}_versions`),l={document_id:n,autosave:{$ne:true}};r&&a.tenantScoped&&(l.tenant_id=r);let f=(i-1)*t,g=this.parseSort(s),u={[g.field]:g.direction==="asc"?1:-1},[c,h]=await Promise.all([d.find(l).sort(u).skip(f).limit(t).toArray(),d.countDocuments(l)]);return {docs:c.map(y=>this.processResult(y,{})),...this.calculatePagination(i,t,h)}}async findVersionByID(o){let{collection:e,versionId:n,tenantId:s}=o,t=this.getCollectionConfig(e),i=this.getMongoCollection(`${e}_versions`),r={_id:n};s&&t.tenantScoped&&(r.tenant_id=s);let a=await i.findOne(r);return a?this.processResult(a,{}):null}async createVersion(o){let{collection:e,documentId:n,data:s,status:t,createdBy:i,changeDescription:r,tenantId:a,autosave:d}=o,l=this.getCollectionConfig(e),f=this.getMongoCollection(`${e}_versions`);if(d){let c={document_id:n,collection_slug:e,autosave:true};a&&l.tenantScoped&&(c.tenant_id=a);let h=await f.findOne(c);if(h){let y=new Date().toISOString();return await f.updateOne({_id:h._id},{$set:{data:s,status:t,updatedAt:y}}),this.processResult({...h,data:s,status:t,updatedAt:y},{})}}let g=new Date().toISOString(),u={_id:this.generateId(),document_id:n,collection_slug:e,data:s,status:t,autosave:d===true,created_by:i,change_description:r,createdAt:g,updatedAt:g};if(a&&l.tenantScoped&&(u.tenant_id=a),await f.insertOne(u),!d){let c=this.getCollectionConfig(e);c.versions?.maxPerDoc&&await this.deleteVersions({collection:e,documentId:n,keepLatest:c.versions.maxPerDoc,tenantId:a});}return this.processResult(u,{})}async updateLatestVersion(o){return this.createVersion({...o,autosave:true})}async deleteVersions(o){let{collection:e,documentId:n,keepLatest:s,tenantId:t}=o,i=this.getCollectionConfig(e),r=this.getMongoCollection(`${e}_versions`);if(s){let a={document_id:n,autosave:{$ne:true}};t&&i.tenantScoped&&(a.tenant_id=t);let l=(await r.find(a).sort({createdAt:-1}).limit(s).project({_id:1}).toArray()).map(f=>f._id);l.length>0&&await r.deleteMany({document_id:n,autosave:{$ne:true},_id:{$nin:l},...t&&i.tenantScoped?{tenant_id:t}:{}});}else {let a={document_id:n};t&&i.tenantScoped&&(a.tenant_id=t),await r.deleteMany(a);}}async migrate(){for(let o of this.collections.values()){let e=this.getMongoCollection(o.slug);await e.createIndex({_id:1}),o.tenantScoped&&await e.createIndex({tenantId:1}),o.timestamps&&await e.createIndex({createdAt:-1});for(let n of o.fields)n.unique&&n.name&&await e.createIndex({[n.name]:1},{unique:true}),n.indexed&&n.name&&await e.createIndex({[n.name]:1});}}getCollectionConfig(o){if(o.startsWith("_globals_")){let n=o.replace("_globals_",""),s=this.globals.get(n);if(!s)throw new Error(`Global "${n}" not found`);return s}let e=this.collections.get(o);if(!e)throw new Error(`Collection "${o}" not found`);return e}buildFilter(o={},e){let n={};e&&(n.tenantId=e);for(let[s,t]of Object.entries(o))if(s==="AND"&&Array.isArray(t)){let i=t.map(r=>this.buildFilter(r));Object.assign(n,...i);}else if(s==="OR"&&Array.isArray(t))n.$or=t.map(i=>this.buildFilter(i));else if(typeof t=="object"&&t!==null&&!Array.isArray(t)){let i={};if(t.equals!==void 0){n[s==="id"?"_id":s]=t.equals;continue}t.not_equals!==void 0&&(i.$ne=t.not_equals),t.in!==void 0&&(i.$in=t.in),t.not_in!==void 0&&(i.$nin=t.not_in),t.greater_than!==void 0&&(i.$gt=t.greater_than),t.greater_than_equal!==void 0&&(i.$gte=t.greater_than_equal),t.less_than!==void 0&&(i.$lt=t.less_than),t.less_than_equal!==void 0&&(i.$lte=t.less_than_equal),t.like!==void 0&&(i.$regex=new RegExp(t.like.replace(/%/g,".*"),"i")),t.not_like!==void 0&&(i.$not=new RegExp(t.not_like.replace(/%/g,".*"),"i")),t.contains!==void 0&&(i.$regex=new RegExp(`.*${t.contains}.*`,"i")),t.exists!==void 0&&(i.$exists=t.exists),Object.keys(i).length>0&&(n[s==="id"?"_id":s]=i);}else n[s==="id"?"_id":s]=t;return n}buildProjection(o){if(!o||o.length===0)return;let e={_id:1};for(let n of o)e[n]=1;return e}processResult(o,e){if(!o)return null;let n={...o};for(let s of Object.keys(n))/^\d+$/.test(s)&&delete n[s];return o._id&&(n.id=o._id,delete n._id),delete n.__v,n.createdAt&&(n.createdAt=new Date(n.createdAt).toISOString()),n.updatedAt&&(n.updatedAt=new Date(n.updatedAt).toISOString()),chunkZOVH6QT5_cjs.a(n)}generateId(){let o=Date.now().toString(16).padStart(12,"0"),e=crypto.randomBytes(6).toString("hex");return o+e}};function V(v){return new b(v)}
|
|
2
|
-
exports.a=b;exports.b=V;
|