odm-client 0.0.5 → 0.0.7
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/dist/client/cloudbase-client.d.ts +1 -0
- package/dist/client/mongodb-client.d.ts +1 -0
- package/dist/{cloudbase-index.cjs → cloudbase.cjs} +1 -1
- package/dist/cloudbase.d.ts +1 -0
- package/dist/{cloudbase-index.js → cloudbase.js} +37 -25
- package/dist/{index2.cjs → generate.cjs} +6 -5
- package/dist/generate.d.ts +1 -0
- package/dist/{index2.js → generate.js} +17 -16
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +13 -19
- package/dist/{mongodb-index.cjs → mongodb.cjs} +2 -2
- package/dist/mongodb.d.ts +1 -0
- package/dist/{mongodb-index.js → mongodb.js} +8 -4
- package/package.json +16 -1
- /package/dist/deps/{_commonjsHelpers-KaVRbhAgd4-5e44xjkup.js → _commonjsHelpers-KaVRbhAgd4-70zzshp9b.js} +0 -0
- /package/dist/deps/{_commonjsHelpers-KaVRbhAgd4-bqfwq0htn.js → _commonjsHelpers-KaVRbhAgd4-res8ony5t.js} +0 -0
- /package/dist/deps/{acorn-DYjaOAP8Gz-c1zv3fupp.js → acorn-DYjaOAP8Gz-fpcmmyt75.js} +0 -0
- /package/dist/deps/{acorn-DYjaOAP8Gz-yd9wbp0u1.js → acorn-DYjaOAP8Gz-l01xlmx0w.js} +0 -0
- /package/dist/deps/{angular-1bp1uAROl4-8g0c11l56.js → angular-1bp1uAROl4-chbuw4r6h.js} +0 -0
- /package/dist/deps/{angular-1bp1uAROl4-9ivn4c5b3.js → angular-1bp1uAROl4-xjez32hd5.js} +0 -0
- /package/dist/deps/{babel-_P9jsDBVVy-h9th63jz9.js → babel-_P9jsDBVVy-2yg3c3b7n.js} +0 -0
- /package/dist/deps/{babel-_P9jsDBVVy-89klf6zkq.js → babel-_P9jsDBVVy-gh7w5yta8.js} +0 -0
- /package/dist/deps/{estree-Q-oFBmJEml-bwlnamlux.js → estree-Q-oFBmJEml-fsfbvfibz.js} +0 -0
- /package/dist/deps/{estree-Q-oFBmJEml-rqdkbjor8.js → estree-Q-oFBmJEml-vi8e4c16l.js} +0 -0
- /package/dist/deps/{flow-j77MFvzLrn-bw2xq88jp.js → flow-j77MFvzLrn-ljbwxlbx6.js} +0 -0
- /package/dist/deps/{flow-j77MFvzLrn-9l22ilt66.js → flow-j77MFvzLrn-rz2mp7fwm.js} +0 -0
- /package/dist/deps/{glimmer-ewQPb5nTUl-l9fzegsk9.js → glimmer-ewQPb5nTUl-swqp20fyl.js} +0 -0
- /package/dist/deps/{glimmer-ewQPb5nTUl-0skyrfotb.js → glimmer-ewQPb5nTUl-wafxvcg8d.js} +0 -0
- /package/dist/deps/{graphql-8EXR1_taGG-mope94e2h.js → graphql-8EXR1_taGG-072rubu6y.js} +0 -0
- /package/dist/deps/{graphql-8EXR1_taGG-10lynn1ml.js → graphql-8EXR1_taGG-i3wmfpne3.js} +0 -0
- /package/dist/deps/{html-dGbiW_CFWL-1tqgharao.js → html-dGbiW_CFWL-bp9vlk1kr.js} +0 -0
- /package/dist/deps/{html-dGbiW_CFWL-zmtfculbf.js → html-dGbiW_CFWL-k3g9oy2c5.js} +0 -0
- /package/dist/deps/{markdown-vAYIRClyWZ-z48qcj07n.js → markdown-vAYIRClyWZ-c7vkwmbjh.js} +0 -0
- /package/dist/deps/{markdown-vAYIRClyWZ-qeglajr0z.js → markdown-vAYIRClyWZ-z6hbtj81z.js} +0 -0
- /package/dist/deps/{meriyah-d5_qqf88x--ayvczp9za.js → meriyah-d5_qqf88x--1vh4l145g.js} +0 -0
- /package/dist/deps/{meriyah-d5_qqf88x--s495t5yup.js → meriyah-d5_qqf88x--r70sg2xzw.js} +0 -0
- /package/dist/deps/{postcss-Vz5bDQ3hJO-jsw4ivkia.js → postcss-Vz5bDQ3hJO-a81conqgc.js} +0 -0
- /package/dist/deps/{postcss-Vz5bDQ3hJO-75l8k0pnu.js → postcss-Vz5bDQ3hJO-hu3djwl2q.js} +0 -0
- /package/dist/deps/{query-builder-h6B2D2BCoQ-hi672ju0i.js → query-builder-h6B2D2BCoQ-md9vwh2qw.js} +0 -0
- /package/dist/deps/{query-builder-h6B2D2BCoQ-33f97qk7e.js → query-builder-h6B2D2BCoQ-zzx9xwrhd.js} +0 -0
- /package/dist/deps/{typescript-2hCq12HCbJ-kcwi4a0yz.js → typescript-2hCq12HCbJ-i2im1m0zb.js} +0 -0
- /package/dist/deps/{typescript-2hCq12HCbJ-q6p9eige4.js → typescript-2hCq12HCbJ-n3fmg7w0v.js} +0 -0
- /package/dist/deps/{yaml-I5o0CrcX7J-93fx0pyvm.js → yaml-I5o0CrcX7J-fi8ekhimn.js} +0 -0
- /package/dist/deps/{yaml-I5o0CrcX7J-d0drtacrr.js → yaml-I5o0CrcX7J-lsxhbyw7g.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var q=Object.defineProperty;var
|
|
1
|
+
"use strict";var q=Object.defineProperty;var g=(l,t,e)=>t in l?q(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e;var s=(l,t,e)=>g(l,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./deps/query-builder-h6B2D2BCoQ-md9vwh2qw.js");class C{constructor(t,e,r){s(this,"client");s(this,"schemaMeta");s(this,"context");s(this,"fieldMetaMap",{});s(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,a)=>(d[a.name]=a,d),{}),c),{})}async findUnique(t,{where:e,select:r}){var d,a,f,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 u=await this.client.collection(t).doc(e[this.idField]).get();return((a=u==null?void 0:u.data)==null?void 0:a[0])??null}const n=h.QueryBuilder.buildCloudBaseQuery(e,this.fieldMetaMap[t]);if(r){const u=await this.client.collection(t).where(n).field(r).get();return((f=u==null?void 0:u.data)==null?void 0:f[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,a=e==null?void 0:e.select,f=(d-1)*c,w=this.findManyInner(t,{where:n,orderBy:i,select:a,limit:c,offset:f}),u=this.count(t,{where:n}),{data:y}=await w,B=await u,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}}async aggregate(t,e){let r=this.client.collection(t).aggregate();e==null||e.forEach(n=>{Object.entries(n??{}).forEach(([d,a])=>{const f=d.replace(/^\$/,"");r=r[f](a)})});const c=await r.end();return c==null?void 0:c.data}}function F(l,t,e){const r=new C(l,t,e),c={$dbClient:l};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),aggregate:i=>r.aggregate(n,i)}}),c.$transaction=async n=>{const i=await l.startTransaction();try{const d=F(i,t,e);d.$transaction=void 0;const a=await n(d);return await i.commit(),a}catch(d){throw await i.rollback(),d}},c}exports.createCloudBaseClient=F;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createCloudBaseClient } from './client/cloudbase-index';
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
var B = Object.defineProperty;
|
|
2
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
|
|
4
|
-
import { Q as
|
|
5
|
-
class
|
|
3
|
+
var f = (l, t, e) => q(l, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { Q as y, a as g, b as C } from "./deps/query-builder-h6B2D2BCoQ-zzx9xwrhd.js";
|
|
5
|
+
class O {
|
|
6
6
|
constructor(t, e, r) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
f(this, "client");
|
|
8
|
+
f(this, "schemaMeta");
|
|
9
|
+
f(this, "context");
|
|
10
|
+
f(this, "fieldMetaMap", {});
|
|
11
|
+
f(this, "idField", "_id");
|
|
12
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, a,
|
|
15
|
+
var d, a, h, w;
|
|
16
16
|
const c = Object.keys(e ?? {});
|
|
17
17
|
if (c.length === 1 && c[0] === this.idField) {
|
|
18
18
|
if (r) {
|
|
19
|
-
const
|
|
20
|
-
return ((d =
|
|
19
|
+
const s = await this.client.collection(t).doc(e[this.idField]).field(r).get();
|
|
20
|
+
return ((d = s == null ? void 0 : s.data) == null ? void 0 : d[0]) ?? null;
|
|
21
21
|
}
|
|
22
22
|
const u = await this.client.collection(t).doc(e[this.idField]).get();
|
|
23
23
|
return ((a = u == null ? void 0 : u.data) == null ? void 0 : a[0]) ?? null;
|
|
24
24
|
}
|
|
25
|
-
const n =
|
|
25
|
+
const n = y.buildCloudBaseQuery(e, this.fieldMetaMap[t]);
|
|
26
26
|
if (r) {
|
|
27
27
|
const u = await this.client.collection(t).where(n).field(r).get();
|
|
28
|
-
return ((
|
|
28
|
+
return ((h = u == null ? void 0 : u.data) == null ? void 0 : h[0]) ?? null;
|
|
29
29
|
}
|
|
30
30
|
const i = await this.client.collection(t).where(n).get();
|
|
31
31
|
return ((w = i == null ? void 0 : i.data) == null ? void 0 : w[0]) ?? null;
|
|
@@ -53,7 +53,7 @@ class k {
|
|
|
53
53
|
return r;
|
|
54
54
|
}
|
|
55
55
|
getFindQuery(t, e) {
|
|
56
|
-
const r =
|
|
56
|
+
const r = y.buildCloudBaseQuery((e == null ? void 0 : e.where) ?? {}, this.fieldMetaMap[t]), c = y.getOrderByArray(e == null ? void 0 : e.orderBy);
|
|
57
57
|
let n;
|
|
58
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
59
|
n = n.orderBy(i.fieldName, i.order);
|
|
@@ -70,27 +70,27 @@ class k {
|
|
|
70
70
|
const c = (e == null ? void 0 : e.limit) || 10;
|
|
71
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, i = e == null ? void 0 : e.orderBy, d = (e == null ? void 0 : e.page) || 1, a = e == null ? void 0 : e.select,
|
|
74
|
-
return { data:
|
|
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, h = (d - 1) * c, w = this.findManyInner(t, { where: n, orderBy: i, select: a, limit: c, offset: h }), u = this.count(t, { where: n }), { data: s } = await w, F = await u, M = Math.ceil(F / c);
|
|
74
|
+
return { data: s, 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 =
|
|
77
|
+
const r = g(e, this.schemaMeta[t], this.context), c = await this.client.collection(t).add(r);
|
|
78
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 c =
|
|
81
|
+
const c = C(r, this.schemaMeta[t]), n = Object.keys(e ?? {});
|
|
82
82
|
if (n.length === 1 && n[0] === this.idField) {
|
|
83
83
|
await this.client.collection(t).doc(e[this.idField]).update(c);
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
|
-
const i =
|
|
86
|
+
const i = y.buildCloudBaseQuery(e, this.fieldMetaMap[t]);
|
|
87
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 c =
|
|
93
|
+
const c = y.buildCloudBaseQuery(e, this.fieldMetaMap[t]);
|
|
94
94
|
await this.client.collection(t).where(c).remove();
|
|
95
95
|
}
|
|
96
96
|
async count(t, e) {
|
|
@@ -101,9 +101,20 @@ class k {
|
|
|
101
101
|
throw console.error("count error:", r), r;
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
+
async aggregate(t, e) {
|
|
105
|
+
let r = this.client.collection(t).aggregate();
|
|
106
|
+
e == null || e.forEach((n) => {
|
|
107
|
+
Object.entries(n ?? {}).forEach(([d, a]) => {
|
|
108
|
+
const h = d.replace(/^\$/, "");
|
|
109
|
+
r = r[h](a);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
const c = await r.end();
|
|
113
|
+
return c == null ? void 0 : c.data;
|
|
114
|
+
}
|
|
104
115
|
}
|
|
105
|
-
function
|
|
106
|
-
const r = new
|
|
116
|
+
function k(l, t, e) {
|
|
117
|
+
const r = new O(l, t, e), c = { $dbClient: l };
|
|
107
118
|
return Object.keys(t).forEach((n) => {
|
|
108
119
|
c[n] = {
|
|
109
120
|
findUnique: (i) => r.findUnique(n, i),
|
|
@@ -115,12 +126,13 @@ function Q(l, t, e) {
|
|
|
115
126
|
create: (i) => r.create(n, i),
|
|
116
127
|
update: (i) => r.update(n, i),
|
|
117
128
|
delete: (i) => r.delete(n, i),
|
|
118
|
-
count: (i) => r.count(n, i)
|
|
129
|
+
count: (i) => r.count(n, i),
|
|
130
|
+
aggregate: (i) => r.aggregate(n, i)
|
|
119
131
|
};
|
|
120
132
|
}), c.$transaction = async (n) => {
|
|
121
133
|
const i = await l.startTransaction();
|
|
122
134
|
try {
|
|
123
|
-
const d =
|
|
135
|
+
const d = k(i, t, e);
|
|
124
136
|
d.$transaction = void 0;
|
|
125
137
|
const a = await n(d);
|
|
126
138
|
return await i.commit(), a;
|
|
@@ -130,5 +142,5 @@ function Q(l, t, e) {
|
|
|
130
142
|
}, c;
|
|
131
143
|
}
|
|
132
144
|
export {
|
|
133
|
-
|
|
145
|
+
k as createCloudBaseClient
|
|
134
146
|
};
|