odm-client 0.0.1 → 0.0.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.
Files changed (51) hide show
  1. package/dist/client/mongodb-client.d.ts +9 -7
  2. package/dist/client/mongodb-index.d.ts +2 -2
  3. package/dist/cloudbase-index.cjs +1 -1
  4. package/dist/cloudbase-index.js +66 -56
  5. package/dist/decorators/index.d.ts +7 -0
  6. package/dist/deps/_commonjsHelpers-KaVRbhAgd4-5pgl5rkso.js +28 -0
  7. package/dist/deps/_commonjsHelpers-KaVRbhAgd4-r4alsdeis.js +1 -0
  8. package/dist/deps/acorn-DYjaOAP8Gz-29lcn4w0b.js +16 -0
  9. package/dist/deps/acorn-DYjaOAP8Gz-gyct7wut5.js +3005 -0
  10. package/dist/deps/angular-1bp1uAROl4-bz9b1prej.js +2533 -0
  11. package/dist/deps/angular-1bp1uAROl4-z3xa5q2km.js +3 -0
  12. package/dist/deps/babel-_P9jsDBVVy-ipfz7c01i.js +7217 -0
  13. package/dist/deps/babel-_P9jsDBVVy-kjb76ly0t.js +15 -0
  14. package/dist/deps/estree-Q-oFBmJEml-u09jq3zep.js +44 -0
  15. package/dist/deps/estree-Q-oFBmJEml-w9z7zljkf.js +4528 -0
  16. package/dist/deps/flow-j77MFvzLrn-kf5rv1yl1.js +20 -0
  17. package/dist/deps/flow-j77MFvzLrn-l8rtylmcl.js +27411 -0
  18. package/dist/deps/glimmer-ewQPb5nTUl-5p9240228.js +37 -0
  19. package/dist/deps/glimmer-ewQPb5nTUl-xsdp5ejns.js +2703 -0
  20. package/dist/deps/graphql-8EXR1_taGG-a4my17998.js +28 -0
  21. package/dist/deps/graphql-8EXR1_taGG-iqqy1396h.js +1221 -0
  22. package/dist/deps/html-dGbiW_CFWL-inuu6eaf1.js +25 -0
  23. package/dist/deps/html-dGbiW_CFWL-mq1pmq7je.js +2791 -0
  24. package/dist/deps/markdown-vAYIRClyWZ-el25zjeip.js +62 -0
  25. package/dist/deps/markdown-vAYIRClyWZ-f8svm8az3.js +3190 -0
  26. package/dist/deps/meriyah-d5_qqf88x--ntk7vora9.js +5 -0
  27. package/dist/deps/meriyah-d5_qqf88x--tbqv1nv9b.js +2645 -0
  28. package/dist/deps/postcss-Vz5bDQ3hJO-if8y8k5xi.js +4739 -0
  29. package/dist/deps/postcss-Vz5bDQ3hJO-rmv75nb4j.js +61 -0
  30. package/dist/deps/typescript-2hCq12HCbJ-n0w7fscoa.js +21 -0
  31. package/dist/deps/typescript-2hCq12HCbJ-yusfiayfb.js +12947 -0
  32. package/dist/deps/yaml-I5o0CrcX7J-ibk1yd293.js +4079 -0
  33. package/dist/deps/yaml-I5o0CrcX7J-xyc4o9p22.js +159 -0
  34. package/dist/generator/cloudbase-init-generator.d.ts +8 -0
  35. package/dist/generator/enum-generator.d.ts +3 -0
  36. package/dist/generator/index.d.ts +6 -0
  37. package/dist/generator/mongodb-init-generator.d.ts +9 -0
  38. package/dist/generator/parser.d.ts +21 -0
  39. package/dist/generator/table-generator.d.ts +3 -0
  40. package/dist/generator/type-generator.d.ts +6 -0
  41. package/dist/index.cjs +1 -1
  42. package/dist/index.d.ts +1 -1
  43. package/dist/index.js +6 -29
  44. package/dist/index2.cjs +42770 -0
  45. package/dist/index2.js +242204 -0
  46. package/dist/mongodb-index.cjs +11 -11
  47. package/dist/mongodb-index.js +2103 -2106
  48. package/dist/types/index.d.ts +14 -0
  49. package/package.json +3 -1
  50. /package/dist/deps/{query-builder-h6B2D2BCoQ-4ajykqs3m.js → query-builder-h6B2D2BCoQ-f5zcr506g.js} +0 -0
  51. /package/dist/deps/{query-builder-h6B2D2BCoQ-wqso6i87o.js → query-builder-h6B2D2BCoQ-iw94q0kiz.js} +0 -0
@@ -1,13 +1,15 @@
1
- import { ColumnMeta, SchemaMeta, PageResult, FindManyOptions, FindPageOptions } from '../types';
2
- import { Db } from 'mongodb';
1
+ import { SchemaMeta, PageResult, FindManyOptions, FindPageOptions } from '../types';
2
+ import { MongoClient, ClientSession } from 'mongodb';
3
3
 
4
4
  export declare class MongoDbClient {
5
- readonly client: Db;
6
- readonly schemaMeta: SchemaMeta;
7
- readonly context: any;
8
- readonly fieldMetaMap: Record<string, Record<string, ColumnMeta>>;
5
+ private client;
6
+ private schemaMeta;
7
+ private context;
8
+ private fieldMetaMap;
9
9
  private idField;
10
- constructor(client: Db, schemaMeta: SchemaMeta, context?: any);
10
+ private dbName;
11
+ private session;
12
+ constructor(client: MongoClient, schemaMeta: SchemaMeta, context?: any, session?: ClientSession);
11
13
  private getObjectId;
12
14
  /**
13
15
  * 辅助方法:安全获取集合实例
@@ -1,4 +1,4 @@
1
1
  import { SchemaMeta } from '../types/index';
2
- import { Db as MongoDb } from 'mongodb';
2
+ import { MongoClient } from 'mongodb';
3
3
 
4
- export declare function createMongoDBClient<T>(client: MongoDb, schemaMeta: SchemaMeta, context?: any): T;
4
+ export declare function createMongoDBClient<T>(client: MongoClient, schemaMeta: SchemaMeta, context?: any): T;
@@ -1 +1 @@
1
- "use strict";var F=Object.defineProperty;var q=(u,t,e)=>t in u?F(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e;var f=(u,t,e)=>q(u,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./deps/query-builder-h6B2D2BCoQ-wqso6i87o.js");class C{constructor(t,e,r){f(this,"client");f(this,"schemaMeta");f(this,"context");f(this,"fieldMetaMap",{});f(this,"idField","_id");this.client=t,this.schemaMeta=e,this.context=r,this.fieldMetaMap=Object.entries(e).reduce((i,[d,c])=>(i[d]=c.columns.reduce((n,h)=>(n[h.name]=h,n),{}),i),{})}async findUnique(t,{where:e,select:r}){var n,h,s,w;const i=Object.keys(e??{});if(i.length===1&&i[0]===this.idField){if(r){const y=await this.client.collection(t).doc(e[this.idField]).field(r).get();return((n=y==null?void 0:y.data)==null?void 0:n[0])??null}const l=await this.client.collection(t).doc(e[this.idField]).get();return((h=l==null?void 0:l.data)==null?void 0:h[0])??null}const d=a.QueryBuilder.buildCloudBaseQuery(e,this.fieldMetaMap[t]);if(r){const l=await this.client.collection(t).where(d).field(r).get();return((s=l==null?void 0:l.data)==null?void 0:s[0])??null}const c=await this.client.collection(t).where(d).get();return((w=c==null?void 0:c.data)==null?void 0:w[0])??null}async findUniqueOrThrow(t,{where:e,select:r}){const i=await this.findUnique(t,{where:e,select:r});if(!i)throw new Error("Data Not Found");return i}async findFirst(t,e){const{data:r}=await this.findManyInner(t,{where:e==null?void 0:e.where,orderBy:e==null?void 0:e.orderBy,select:e==null?void 0:e.select,limit:1,offset:0});return(r==null?void 0:r[0])??null}async findFirstOrThrow(t,e){const r=await this.findFirst(t,e);if(!r)throw new Error("Data Not Found");return r}getFindQuery(t,e){const r=a.QueryBuilder.buildCloudBaseQuery((e==null?void 0:e.where)??{},this.fieldMetaMap[t]),i=a.QueryBuilder.getOrderByArray(e==null?void 0:e.orderBy);let d;return e!=null&&e.select?d=this.client.collection(t).where(r).field(e==null?void 0:e.select).skip((e==null?void 0:e.offset)??0):d=this.client.collection(t).where(r).skip((e==null?void 0:e.offset)??0),(e==null?void 0:e.limit)!=null&&(d=d.limit(e.limit)),i.length>0&&i.forEach(c=>{d=d.orderBy(c.fieldName,c.order)}),d}async findManyInner(t,e){return await this.getFindQuery(t,e).get()}async findMany(t,e){const r=e==null?void 0:e.where,i=e==null?void 0:e.orderBy,d=e==null?void 0:e.select,{data:c}=await this.findManyInner(t,{where:r,orderBy:i,select:d,limit:1e3,offset:0});return c}async findPage(t,e){const i=(e==null?void 0:e.limit)||10;if(i>1e3)throw new Error("limit must be less than or equal to 1000");const d=e==null?void 0:e.where,c=e==null?void 0:e.orderBy,n=(e==null?void 0:e.page)||1,h=e==null?void 0:e.select,s=(n-1)*i,w=this.findManyInner(t,{where:d,orderBy:c,select:h,limit:i,offset:s}),l=this.count(t,{where:d}),{data:y}=await w,B=await l,M=Math.ceil(B/i);return{data:y,total:B,page:n,pageCount:M,limit:i,hasPrev:n>1,hasNext:n<M}}async create(t,{data:e}){const r=a.applyDefaultValues(e,this.schemaMeta[t],this.context),i=await this.client.collection(t).add(r);return{_id:(i==null?void 0:i.id)??(i==null?void 0:i[this.idField])}}async update(t,{where:e,data:r}){const i=a.applyUpdateValues(r,this.schemaMeta[t]),d=Object.keys(e??{});if(d.length===1&&d[0]===this.idField){await this.client.collection(t).doc(e[this.idField]).update(i);return}const c=a.QueryBuilder.buildCloudBaseQuery(e,this.fieldMetaMap[t]);await this.client.collection(t).where(c).update(i)}async delete(t,{where:e}){const r=Object.keys(e??{});if(r.length===1&&r[0]===this.idField)return await this.client.collection(t).doc(e[this.idField]).remove();const i=a.QueryBuilder.buildCloudBaseQuery(e,this.fieldMetaMap[t]);await this.client.collection(t).where(i).remove()}async count(t,e){try{const r=this.getFindQuery(t,{where:e==null?void 0:e.where,offset:0}),{total:i}=await r.count();return i}catch(r){throw console.error("count error:",r),r}}}function O(u,t,e){const r=new C(u,t,e),i={};return Object.keys(t).forEach(d=>{i[d]={findUnique:c=>r.findUnique(d,c),findUniqueOrThrow:c=>r.findUniqueOrThrow(d,c),findFirst:c=>r.findFirst(d,c),findFirstOrThrow:c=>r.findFirstOrThrow(d,c),findMany:c=>r.findMany(d,c),findPage:c=>r.findPage(d,c),create:c=>r.create(d,c),update:c=>r.update(d,c),delete:c=>r.delete(d,c),count:c=>r.count(d,c)}}),i}exports.createCloudBaseClient=O;
1
+ "use strict";var q=Object.defineProperty;var C=(l,t,e)=>t in l?q(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e;var f=(l,t,e)=>C(l,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./deps/query-builder-h6B2D2BCoQ-iw94q0kiz.js");class O{constructor(t,e,r){f(this,"client");f(this,"schemaMeta");f(this,"context");f(this,"fieldMetaMap",{});f(this,"idField","_id");this.client=t,this.schemaMeta=e,this.context=r,this.fieldMetaMap=Object.entries(e).reduce((c,[n,i])=>(c[n]=i.columns.reduce((d,u)=>(d[u.name]=u,d),{}),c),{})}async findUnique(t,{where:e,select:r}){var d,u,s,w;const c=Object.keys(e??{});if(c.length===1&&c[0]===this.idField){if(r){const y=await this.client.collection(t).doc(e[this.idField]).field(r).get();return((d=y==null?void 0:y.data)==null?void 0:d[0])??null}const a=await this.client.collection(t).doc(e[this.idField]).get();return((u=a==null?void 0:a.data)==null?void 0:u[0])??null}const n=h.QueryBuilder.buildCloudBaseQuery(e,this.fieldMetaMap[t]);if(r){const a=await this.client.collection(t).where(n).field(r).get();return((s=a==null?void 0:a.data)==null?void 0:s[0])??null}const i=await this.client.collection(t).where(n).get();return((w=i==null?void 0:i.data)==null?void 0:w[0])??null}async findUniqueOrThrow(t,{where:e,select:r}){const c=await this.findUnique(t,{where:e,select:r});if(!c)throw new Error("Data Not Found");return c}async findFirst(t,e){const{data:r}=await this.findManyInner(t,{where:e==null?void 0:e.where,orderBy:e==null?void 0:e.orderBy,select:e==null?void 0:e.select,limit:1,offset:0});return(r==null?void 0:r[0])??null}async findFirstOrThrow(t,e){const r=await this.findFirst(t,e);if(!r)throw new Error("Data Not Found");return r}getFindQuery(t,e){const r=h.QueryBuilder.buildCloudBaseQuery((e==null?void 0:e.where)??{},this.fieldMetaMap[t]),c=h.QueryBuilder.getOrderByArray(e==null?void 0:e.orderBy);let n;return e!=null&&e.select?n=this.client.collection(t).where(r).field(e==null?void 0:e.select).skip((e==null?void 0:e.offset)??0):n=this.client.collection(t).where(r).skip((e==null?void 0:e.offset)??0),(e==null?void 0:e.limit)!=null&&(n=n.limit(e.limit)),c.length>0&&c.forEach(i=>{n=n.orderBy(i.fieldName,i.order)}),n}async findManyInner(t,e){return await this.getFindQuery(t,e).get()}async findMany(t,e){const r=e==null?void 0:e.where,c=e==null?void 0:e.orderBy,n=e==null?void 0:e.select,{data:i}=await this.findManyInner(t,{where:r,orderBy:c,select:n,limit:1e3,offset:0});return i}async findPage(t,e){const c=(e==null?void 0:e.limit)||10;if(c>1e3)throw new Error("limit must be less than or equal to 1000");const n=e==null?void 0:e.where,i=e==null?void 0:e.orderBy,d=(e==null?void 0:e.page)||1,u=e==null?void 0:e.select,s=(d-1)*c,w=this.findManyInner(t,{where:n,orderBy:i,select:u,limit:c,offset:s}),a=this.count(t,{where:n}),{data:y}=await w,B=await a,M=Math.ceil(B/c);return{data:y,total:B,page:d,pageCount:M,limit:c,hasPrev:d>1,hasNext:d<M}}async create(t,{data:e}){const r=h.applyDefaultValues(e,this.schemaMeta[t],this.context),c=await this.client.collection(t).add(r);return{_id:(c==null?void 0:c.id)??(c==null?void 0:c[this.idField])}}async update(t,{where:e,data:r}){const c=h.applyUpdateValues(r,this.schemaMeta[t]),n=Object.keys(e??{});if(n.length===1&&n[0]===this.idField){await this.client.collection(t).doc(e[this.idField]).update(c);return}const i=h.QueryBuilder.buildCloudBaseQuery(e,this.fieldMetaMap[t]);await this.client.collection(t).where(i).update(c)}async delete(t,{where:e}){const r=Object.keys(e??{});if(r.length===1&&r[0]===this.idField)return await this.client.collection(t).doc(e[this.idField]).remove();const c=h.QueryBuilder.buildCloudBaseQuery(e,this.fieldMetaMap[t]);await this.client.collection(t).where(c).remove()}async count(t,e){try{const r=this.getFindQuery(t,{where:e==null?void 0:e.where,offset:0}),{total:c}=await r.count();return c}catch(r){throw console.error("count error:",r),r}}}function F(l,t,e){const r=new O(l,t,e),c={};return Object.keys(t).forEach(n=>{c[n]={findUnique:i=>r.findUnique(n,i),findUniqueOrThrow:i=>r.findUniqueOrThrow(n,i),findFirst:i=>r.findFirst(n,i),findFirstOrThrow:i=>r.findFirstOrThrow(n,i),findMany:i=>r.findMany(n,i),findPage:i=>r.findPage(n,i),create:i=>r.create(n,i),update:i=>r.update(n,i),delete:i=>r.delete(n,i),count:i=>r.count(n,i)}}),c.$transaction=async n=>{const i=await l.startTransaction();try{const d=F(i,t,e);d.$transaction=void 0;const u=await n(d);return await i.commit(),u}catch(d){throw await i.rollback(),d}},c}exports.createCloudBaseClient=F;
@@ -1,40 +1,40 @@
1
1
  var B = Object.defineProperty;
2
- var q = (u, t, e) => t in u ? B(u, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : u[t] = e;
3
- var a = (u, t, e) => q(u, typeof t != "symbol" ? t + "" : t, e);
4
- import { Q as y, a as O, b as C } from "./deps/query-builder-h6B2D2BCoQ-4ajykqs3m.js";
2
+ var q = (l, t, e) => t in l ? B(l, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[t] = e;
3
+ var h = (l, t, e) => q(l, typeof t != "symbol" ? t + "" : t, e);
4
+ import { Q as s, a as C, b as O } from "./deps/query-builder-h6B2D2BCoQ-f5zcr506g.js";
5
5
  class k {
6
6
  constructor(t, e, r) {
7
- a(this, "client");
8
- a(this, "schemaMeta");
9
- a(this, "context");
10
- a(this, "fieldMetaMap", {});
11
- a(this, "idField", "_id");
12
- this.client = t, this.schemaMeta = e, this.context = r, this.fieldMetaMap = Object.entries(e).reduce((i, [n, c]) => (i[n] = c.columns.reduce((d, h) => (d[h.name] = h, d), {}), i), {});
7
+ h(this, "client");
8
+ h(this, "schemaMeta");
9
+ h(this, "context");
10
+ h(this, "fieldMetaMap", {});
11
+ h(this, "idField", "_id");
12
+ this.client = t, this.schemaMeta = e, this.context = r, this.fieldMetaMap = Object.entries(e).reduce((c, [n, i]) => (c[n] = i.columns.reduce((d, a) => (d[a.name] = a, d), {}), c), {});
13
13
  }
14
14
  async findUnique(t, { where: e, select: r }) {
15
- var d, h, s, w;
16
- const i = Object.keys(e ?? {});
17
- if (i.length === 1 && i[0] === this.idField) {
15
+ var d, a, y, w;
16
+ const c = Object.keys(e ?? {});
17
+ if (c.length === 1 && c[0] === this.idField) {
18
18
  if (r) {
19
19
  const f = await this.client.collection(t).doc(e[this.idField]).field(r).get();
20
20
  return ((d = f == null ? void 0 : f.data) == null ? void 0 : d[0]) ?? null;
21
21
  }
22
- const l = await this.client.collection(t).doc(e[this.idField]).get();
23
- return ((h = l == null ? void 0 : l.data) == null ? void 0 : h[0]) ?? null;
22
+ const u = await this.client.collection(t).doc(e[this.idField]).get();
23
+ return ((a = u == null ? void 0 : u.data) == null ? void 0 : a[0]) ?? null;
24
24
  }
25
- const n = y.buildCloudBaseQuery(e, this.fieldMetaMap[t]);
25
+ const n = s.buildCloudBaseQuery(e, this.fieldMetaMap[t]);
26
26
  if (r) {
27
- const l = await this.client.collection(t).where(n).field(r).get();
28
- return ((s = l == null ? void 0 : l.data) == null ? void 0 : s[0]) ?? null;
27
+ const u = await this.client.collection(t).where(n).field(r).get();
28
+ return ((y = u == null ? void 0 : u.data) == null ? void 0 : y[0]) ?? null;
29
29
  }
30
- const c = await this.client.collection(t).where(n).get();
31
- return ((w = c == null ? void 0 : c.data) == null ? void 0 : w[0]) ?? null;
30
+ const i = await this.client.collection(t).where(n).get();
31
+ return ((w = i == null ? void 0 : i.data) == null ? void 0 : w[0]) ?? null;
32
32
  }
33
33
  async findUniqueOrThrow(t, { where: e, select: r }) {
34
- const i = await this.findUnique(t, { where: e, select: r });
35
- if (!i)
34
+ const c = await this.findUnique(t, { where: e, select: r });
35
+ if (!c)
36
36
  throw new Error("Data Not Found");
37
- return i;
37
+ return c;
38
38
  }
39
39
  async findFirst(t, e) {
40
40
  const { data: r } = await this.findManyInner(t, {
@@ -53,72 +53,82 @@ class k {
53
53
  return r;
54
54
  }
55
55
  getFindQuery(t, e) {
56
- const r = y.buildCloudBaseQuery((e == null ? void 0 : e.where) ?? {}, this.fieldMetaMap[t]), i = y.getOrderByArray(e == null ? void 0 : e.orderBy);
56
+ const r = s.buildCloudBaseQuery((e == null ? void 0 : e.where) ?? {}, this.fieldMetaMap[t]), c = s.getOrderByArray(e == null ? void 0 : e.orderBy);
57
57
  let n;
58
- return e != null && e.select ? n = this.client.collection(t).where(r).field(e == null ? void 0 : e.select).skip((e == null ? void 0 : e.offset) ?? 0) : n = this.client.collection(t).where(r).skip((e == null ? void 0 : e.offset) ?? 0), (e == null ? void 0 : e.limit) != null && (n = n.limit(e.limit)), i.length > 0 && i.forEach((c) => {
59
- n = n.orderBy(c.fieldName, c.order);
58
+ return e != null && e.select ? n = this.client.collection(t).where(r).field(e == null ? void 0 : e.select).skip((e == null ? void 0 : e.offset) ?? 0) : n = this.client.collection(t).where(r).skip((e == null ? void 0 : e.offset) ?? 0), (e == null ? void 0 : e.limit) != null && (n = n.limit(e.limit)), c.length > 0 && c.forEach((i) => {
59
+ n = n.orderBy(i.fieldName, i.order);
60
60
  }), n;
61
61
  }
62
62
  async findManyInner(t, e) {
63
63
  return await this.getFindQuery(t, e).get();
64
64
  }
65
65
  async findMany(t, e) {
66
- const r = e == null ? void 0 : e.where, i = e == null ? void 0 : e.orderBy, n = e == null ? void 0 : e.select, { data: c } = await this.findManyInner(t, { where: r, orderBy: i, select: n, limit: 1e3, offset: 0 });
67
- return c;
66
+ const r = e == null ? void 0 : e.where, c = e == null ? void 0 : e.orderBy, n = e == null ? void 0 : e.select, { data: i } = await this.findManyInner(t, { where: r, orderBy: c, select: n, limit: 1e3, offset: 0 });
67
+ return i;
68
68
  }
69
69
  async findPage(t, e) {
70
- const i = (e == null ? void 0 : e.limit) || 10;
71
- if (i > 1e3)
70
+ const c = (e == null ? void 0 : e.limit) || 10;
71
+ if (c > 1e3)
72
72
  throw new Error("limit must be less than or equal to 1000");
73
- const n = e == null ? void 0 : e.where, c = e == null ? void 0 : e.orderBy, d = (e == null ? void 0 : e.page) || 1, h = e == null ? void 0 : e.select, s = (d - 1) * i, w = this.findManyInner(t, { where: n, orderBy: c, select: h, limit: i, offset: s }), l = this.count(t, { where: n }), { data: f } = await w, M = await l, F = Math.ceil(M / i);
74
- return { data: f, total: M, page: d, pageCount: F, limit: i, hasPrev: d > 1, hasNext: d < F };
73
+ const n = e == null ? void 0 : e.where, i = e == null ? void 0 : e.orderBy, d = (e == null ? void 0 : e.page) || 1, a = e == null ? void 0 : e.select, y = (d - 1) * c, w = this.findManyInner(t, { where: n, orderBy: i, select: a, limit: c, offset: y }), u = this.count(t, { where: n }), { data: f } = await w, F = await u, M = Math.ceil(F / c);
74
+ return { data: f, total: F, page: d, pageCount: M, limit: c, hasPrev: d > 1, hasNext: d < M };
75
75
  }
76
76
  async create(t, { data: e }) {
77
- const r = O(e, this.schemaMeta[t], this.context), i = await this.client.collection(t).add(r);
78
- return { _id: (i == null ? void 0 : i.id) ?? (i == null ? void 0 : i[this.idField]) };
77
+ const r = C(e, this.schemaMeta[t], this.context), c = await this.client.collection(t).add(r);
78
+ return { _id: (c == null ? void 0 : c.id) ?? (c == null ? void 0 : c[this.idField]) };
79
79
  }
80
80
  async update(t, { where: e, data: r }) {
81
- const i = C(r, this.schemaMeta[t]), n = Object.keys(e ?? {});
81
+ const c = O(r, this.schemaMeta[t]), n = Object.keys(e ?? {});
82
82
  if (n.length === 1 && n[0] === this.idField) {
83
- await this.client.collection(t).doc(e[this.idField]).update(i);
83
+ await this.client.collection(t).doc(e[this.idField]).update(c);
84
84
  return;
85
85
  }
86
- const c = y.buildCloudBaseQuery(e, this.fieldMetaMap[t]);
87
- await this.client.collection(t).where(c).update(i);
86
+ const i = s.buildCloudBaseQuery(e, this.fieldMetaMap[t]);
87
+ await this.client.collection(t).where(i).update(c);
88
88
  }
89
89
  async delete(t, { where: e }) {
90
90
  const r = Object.keys(e ?? {});
91
91
  if (r.length === 1 && r[0] === this.idField)
92
92
  return await this.client.collection(t).doc(e[this.idField]).remove();
93
- const i = y.buildCloudBaseQuery(e, this.fieldMetaMap[t]);
94
- await this.client.collection(t).where(i).remove();
93
+ const c = s.buildCloudBaseQuery(e, this.fieldMetaMap[t]);
94
+ await this.client.collection(t).where(c).remove();
95
95
  }
96
96
  async count(t, e) {
97
97
  try {
98
- const r = this.getFindQuery(t, { where: e == null ? void 0 : e.where, offset: 0 }), { total: i } = await r.count();
99
- return i;
98
+ const r = this.getFindQuery(t, { where: e == null ? void 0 : e.where, offset: 0 }), { total: c } = await r.count();
99
+ return c;
100
100
  } catch (r) {
101
101
  throw console.error("count error:", r), r;
102
102
  }
103
103
  }
104
104
  }
105
- function U(u, t, e) {
106
- const r = new k(u, t, e), i = {};
105
+ function Q(l, t, e) {
106
+ const r = new k(l, t, e), c = {};
107
107
  return Object.keys(t).forEach((n) => {
108
- i[n] = {
109
- findUnique: (c) => r.findUnique(n, c),
110
- findUniqueOrThrow: (c) => r.findUniqueOrThrow(n, c),
111
- findFirst: (c) => r.findFirst(n, c),
112
- findFirstOrThrow: (c) => r.findFirstOrThrow(n, c),
113
- findMany: (c) => r.findMany(n, c),
114
- findPage: (c) => r.findPage(n, c),
115
- create: (c) => r.create(n, c),
116
- update: (c) => r.update(n, c),
117
- delete: (c) => r.delete(n, c),
118
- count: (c) => r.count(n, c)
108
+ c[n] = {
109
+ findUnique: (i) => r.findUnique(n, i),
110
+ findUniqueOrThrow: (i) => r.findUniqueOrThrow(n, i),
111
+ findFirst: (i) => r.findFirst(n, i),
112
+ findFirstOrThrow: (i) => r.findFirstOrThrow(n, i),
113
+ findMany: (i) => r.findMany(n, i),
114
+ findPage: (i) => r.findPage(n, i),
115
+ create: (i) => r.create(n, i),
116
+ update: (i) => r.update(n, i),
117
+ delete: (i) => r.delete(n, i),
118
+ count: (i) => r.count(n, i)
119
119
  };
120
- }), i;
120
+ }), c.$transaction = async (n) => {
121
+ const i = await l.startTransaction();
122
+ try {
123
+ const d = Q(i, t, e);
124
+ d.$transaction = void 0;
125
+ const a = await n(d);
126
+ return await i.commit(), a;
127
+ } catch (d) {
128
+ throw await i.rollback(), d;
129
+ }
130
+ }, c;
121
131
  }
122
132
  export {
123
- U as createCloudBaseClient
133
+ Q as createCloudBaseClient
124
134
  };
@@ -5,14 +5,20 @@ export interface TableOptions {
5
5
  }
6
6
  export interface FieldOptions {
7
7
  type: ColumnType;
8
+ title?: string;
8
9
  default?: any | ((data: any, context?: any) => any);
9
10
  isIndex?: boolean;
10
11
  indexSort?: SearchIndexSort;
11
12
  indexOptions?: {
12
13
  unique: boolean;
13
14
  };
15
+ enum?: Record<string, {
16
+ label: string;
17
+ value: any;
18
+ }>;
14
19
  }
15
20
  export interface CreatedAtOptions {
21
+ title?: string;
16
22
  isIndex?: boolean;
17
23
  indexSort?: SearchIndexSort;
18
24
  indexOptions?: {
@@ -20,6 +26,7 @@ export interface CreatedAtOptions {
20
26
  };
21
27
  }
22
28
  export interface UpdatedAtOptions {
29
+ title?: string;
23
30
  isIndex?: boolean;
24
31
  indexSort?: SearchIndexSort;
25
32
  indexOptions?: {
@@ -0,0 +1,28 @@
1
+ var u = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
2
+ function f(e) {
3
+ return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
4
+ }
5
+ function l(e) {
6
+ if (e.__esModule) return e;
7
+ var r = e.default;
8
+ if (typeof r == "function") {
9
+ var t = function o() {
10
+ return this instanceof o ? Reflect.construct(r, arguments, this.constructor) : r.apply(this, arguments);
11
+ };
12
+ t.prototype = r.prototype;
13
+ } else t = {};
14
+ return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(e).forEach(function(o) {
15
+ var n = Object.getOwnPropertyDescriptor(e, o);
16
+ Object.defineProperty(t, o, n.get ? n : {
17
+ enumerable: !0,
18
+ get: function() {
19
+ return e[o];
20
+ }
21
+ });
22
+ }), t;
23
+ }
24
+ export {
25
+ l as a,
26
+ u as c,
27
+ f as g
28
+ };
@@ -0,0 +1 @@
1
+ "use strict";var u=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function f(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function l(e){if(e.__esModule)return e;var r=e.default;if(typeof r=="function"){var t=function o(){return this instanceof o?Reflect.construct(r,arguments,this.constructor):r.apply(this,arguments)};t.prototype=r.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(e).forEach(function(o){var n=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,n.get?n:{enumerable:!0,get:function(){return e[o]}})}),t}exports.commonjsGlobal=u;exports.getAugmentedNamespace=l;exports.getDefaultExportFromCjs=f;