odm-client 0.0.1

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.
@@ -0,0 +1,48 @@
1
+ import { ColumnMeta, SchemaMeta, PageResult, FindManyOptions, FindPageOptions } from '../types';
2
+ import { Db as cloudbaseDatabase } from '@cloudbase/database';
3
+
4
+ export declare class CloudBaseClient {
5
+ readonly client: cloudbaseDatabase;
6
+ readonly schemaMeta: SchemaMeta;
7
+ readonly context: any;
8
+ readonly fieldMetaMap: Record<string, Record<string, ColumnMeta>>;
9
+ private idField;
10
+ constructor(client: cloudbaseDatabase, schemaMeta: SchemaMeta, context?: any);
11
+ findUnique(tableName: string, { where, select }: {
12
+ where: Record<string, any>;
13
+ select?: Record<string, boolean>;
14
+ }): Promise<Record<string, any> | null>;
15
+ findUniqueOrThrow(tableName: string, { where, select }: {
16
+ where: Record<string, any>;
17
+ select?: Record<string, boolean>;
18
+ }): Promise<Record<string, any>>;
19
+ findFirst(tableName: string, args?: {
20
+ where?: Record<string, any>;
21
+ orderBy?: Record<string, 'asc' | 'desc'>;
22
+ select?: Record<string, boolean>;
23
+ }): Promise<Record<string, any> | null>;
24
+ findFirstOrThrow(tableName: string, args?: {
25
+ where?: Record<string, any>;
26
+ orderBy?: Record<string, 'asc' | 'desc'>;
27
+ select?: Record<string, boolean>;
28
+ }): Promise<Record<string, any>>;
29
+ private getFindQuery;
30
+ private findManyInner;
31
+ findMany(tableName: string, options?: FindManyOptions): Promise<Record<string, any>[]>;
32
+ findPage(tableName: string, options?: FindPageOptions): Promise<PageResult>;
33
+ create(tableName: string, { data }: {
34
+ data: Record<string, any>;
35
+ }): Promise<{
36
+ _id: string;
37
+ }>;
38
+ update(tableName: string, { where, data }: {
39
+ where: Record<string, any>;
40
+ data: Record<string, any>;
41
+ }): Promise<void>;
42
+ delete(tableName: string, { where }: {
43
+ where: Record<string, any>;
44
+ }): Promise<void>;
45
+ count(tableName: string, args?: {
46
+ where?: Record<string, any>;
47
+ }): Promise<number>;
48
+ }
@@ -0,0 +1,4 @@
1
+ import { SchemaMeta } from '../types/index';
2
+ import { Db } from '@cloudbase/database';
3
+
4
+ export declare function createCloudBaseClient<T>(client: Db, schemaMeta: SchemaMeta, context?: any): T;
@@ -0,0 +1,64 @@
1
+ import { ColumnMeta, SchemaMeta, PageResult, FindManyOptions, FindPageOptions } from '../types';
2
+ import { Db } from 'mongodb';
3
+
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>>;
9
+ private idField;
10
+ constructor(client: Db, schemaMeta: SchemaMeta, context?: any);
11
+ private getObjectId;
12
+ /**
13
+ * 辅助方法:安全获取集合实例
14
+ */
15
+ private getCollection;
16
+ /**
17
+ * 辅助方法:尝试将字符串转换为 ObjectId
18
+ */
19
+ private normalizeId;
20
+ /**
21
+ * 辅助方法:构建 MongoDB Sort 对象
22
+ */
23
+ private buildSort;
24
+ /**
25
+ * 辅助方法:构建 MongoDB FindOptions
26
+ */
27
+ private buildFindOptions;
28
+ findUnique(tableName: string, { where, select }: {
29
+ where: Record<string, any>;
30
+ select?: Record<string, boolean>;
31
+ }): Promise<Record<string, any> | null>;
32
+ findUniqueOrThrow(tableName: string, { where, select }: {
33
+ where: Record<string, any>;
34
+ select?: Record<string, boolean>;
35
+ }): Promise<Record<string, any>>;
36
+ findFirst(tableName: string, args?: {
37
+ where?: Record<string, any>;
38
+ orderBy?: Record<string, 'asc' | 'desc'>;
39
+ select?: Record<string, boolean>;
40
+ }): Promise<Record<string, any> | null>;
41
+ findFirstOrThrow(tableName: string, args?: {
42
+ where?: Record<string, any>;
43
+ orderBy?: Record<string, 'asc' | 'desc'>;
44
+ select?: Record<string, boolean>;
45
+ }): Promise<Record<string, any>>;
46
+ private findManyInner;
47
+ findMany(tableName: string, options?: FindManyOptions): Promise<Record<string, any>[]>;
48
+ findPage(tableName: string, options?: FindPageOptions): Promise<PageResult>;
49
+ create(tableName: string, { data }: {
50
+ data: Record<string, any>;
51
+ }): Promise<{
52
+ _id: string;
53
+ }>;
54
+ update(tableName: string, { where, data }: {
55
+ where: Record<string, any>;
56
+ data: Record<string, any>;
57
+ }): Promise<void>;
58
+ delete(tableName: string, { where }: {
59
+ where: Record<string, any>;
60
+ }): Promise<void>;
61
+ count(tableName: string, args?: {
62
+ where?: Record<string, any>;
63
+ }): Promise<number>;
64
+ }
@@ -0,0 +1,4 @@
1
+ import { SchemaMeta } from '../types/index';
2
+ import { Db as MongoDb } from 'mongodb';
3
+
4
+ export declare function createMongoDBClient<T>(client: MongoDb, schemaMeta: SchemaMeta, context?: any): T;
@@ -0,0 +1,11 @@
1
+ import { ObjectId } from 'mongodb';
2
+ import { ColumnMeta } from '../types';
3
+
4
+ export declare class QueryBuilder {
5
+ static buildCloudBaseQuery(where: Record<string, any> | undefined, columnMetaMap: Record<string, ColumnMeta>): {};
6
+ static buildMongodbQuery(where: Record<string, any> | undefined, columnMetaMap: Record<string, ColumnMeta>, getObjectId: (id: string) => ObjectId): {};
7
+ static getOrderByArray(orderBy: Record<string, 'asc' | 'desc'> | undefined): {
8
+ fieldName: string;
9
+ order: "asc" | "desc";
10
+ }[];
11
+ }
@@ -0,0 +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;
@@ -0,0 +1,124 @@
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";
5
+ class k {
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), {});
13
+ }
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) {
18
+ if (r) {
19
+ const f = await this.client.collection(t).doc(e[this.idField]).field(r).get();
20
+ return ((d = f == null ? void 0 : f.data) == null ? void 0 : d[0]) ?? null;
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;
24
+ }
25
+ const n = y.buildCloudBaseQuery(e, this.fieldMetaMap[t]);
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;
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;
32
+ }
33
+ async findUniqueOrThrow(t, { where: e, select: r }) {
34
+ const i = await this.findUnique(t, { where: e, select: r });
35
+ if (!i)
36
+ throw new Error("Data Not Found");
37
+ return i;
38
+ }
39
+ async findFirst(t, e) {
40
+ const { data: r } = await this.findManyInner(t, {
41
+ where: e == null ? void 0 : e.where,
42
+ orderBy: e == null ? void 0 : e.orderBy,
43
+ select: e == null ? void 0 : e.select,
44
+ limit: 1,
45
+ offset: 0
46
+ });
47
+ return (r == null ? void 0 : r[0]) ?? null;
48
+ }
49
+ async findFirstOrThrow(t, e) {
50
+ const r = await this.findFirst(t, e);
51
+ if (!r)
52
+ throw new Error("Data Not Found");
53
+ return r;
54
+ }
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);
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);
60
+ }), n;
61
+ }
62
+ async findManyInner(t, e) {
63
+ return await this.getFindQuery(t, e).get();
64
+ }
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;
68
+ }
69
+ async findPage(t, e) {
70
+ const i = (e == null ? void 0 : e.limit) || 10;
71
+ if (i > 1e3)
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 };
75
+ }
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]) };
79
+ }
80
+ async update(t, { where: e, data: r }) {
81
+ const i = C(r, this.schemaMeta[t]), n = Object.keys(e ?? {});
82
+ if (n.length === 1 && n[0] === this.idField) {
83
+ await this.client.collection(t).doc(e[this.idField]).update(i);
84
+ return;
85
+ }
86
+ const c = y.buildCloudBaseQuery(e, this.fieldMetaMap[t]);
87
+ await this.client.collection(t).where(c).update(i);
88
+ }
89
+ async delete(t, { where: e }) {
90
+ const r = Object.keys(e ?? {});
91
+ if (r.length === 1 && r[0] === this.idField)
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();
95
+ }
96
+ async count(t, e) {
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;
100
+ } catch (r) {
101
+ throw console.error("count error:", r), r;
102
+ }
103
+ }
104
+ }
105
+ function U(u, t, e) {
106
+ const r = new k(u, t, e), i = {};
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)
119
+ };
120
+ }), i;
121
+ }
122
+ export {
123
+ U as createCloudBaseClient
124
+ };
@@ -0,0 +1,48 @@
1
+ import { ColumnType, SearchIndexSort } from '../types';
2
+
3
+ export interface TableOptions {
4
+ name: string;
5
+ }
6
+ export interface FieldOptions {
7
+ type: ColumnType;
8
+ default?: any | ((data: any, context?: any) => any);
9
+ isIndex?: boolean;
10
+ indexSort?: SearchIndexSort;
11
+ indexOptions?: {
12
+ unique: boolean;
13
+ };
14
+ }
15
+ export interface CreatedAtOptions {
16
+ isIndex?: boolean;
17
+ indexSort?: SearchIndexSort;
18
+ indexOptions?: {
19
+ unique: boolean;
20
+ };
21
+ }
22
+ export interface UpdatedAtOptions {
23
+ isIndex?: boolean;
24
+ indexSort?: SearchIndexSort;
25
+ indexOptions?: {
26
+ unique: boolean;
27
+ };
28
+ }
29
+ /**
30
+ * 表装饰器:标记一个类为表格存储的表定义
31
+ */
32
+ export declare function Table(options: TableOptions): ClassDecorator;
33
+ /**
34
+ * 主键字段装饰器:标记一个字段为主键列
35
+ */
36
+ export declare function PrimaryKey(): PropertyDecorator;
37
+ /**
38
+ * 普通字段装饰器:标记一个字段为数据列
39
+ */
40
+ export declare function Field(options: FieldOptions): PropertyDecorator;
41
+ /**
42
+ * 创建时间装饰器:标记一个字段为创建时间
43
+ */
44
+ export declare function CreatedAt(options?: CreatedAtOptions): PropertyDecorator;
45
+ /**
46
+ * 更新时间装饰器:标记一个字段为更新时间
47
+ */
48
+ export declare function UpdatedAt(options?: UpdatedAtOptions): PropertyDecorator;
@@ -0,0 +1,72 @@
1
+ function Q(n) {
2
+ if (!n || typeof n != "object")
3
+ return !1;
4
+ const t = Object.getPrototypeOf(n);
5
+ return t === null || t === Object.prototype || Object.getPrototypeOf(t) === null ? Object.prototype.toString.call(n) === "[object Object]" : !1;
6
+ }
7
+ function D(n) {
8
+ return typeof n == "string";
9
+ }
10
+ function j(n, t, r) {
11
+ return typeof n == "function" ? n(t, r) : n;
12
+ }
13
+ function c(n, t, r) {
14
+ const e = { ...n }, s = /* @__PURE__ */ new Date();
15
+ for (const i of t.columns)
16
+ if (!(e[i.name] !== void 0 && e[i.name] !== null)) {
17
+ if (i.createdAt) {
18
+ e[i.name] = s;
19
+ continue;
20
+ }
21
+ if (i.updatedAt) {
22
+ e[i.name] = s;
23
+ continue;
24
+ }
25
+ if (i.type === "date" && D(e[i.name])) {
26
+ e[i.name] = new Date(e[i.name]);
27
+ continue;
28
+ }
29
+ i.default !== void 0 && (e[i.name] = j(i.default, n, r));
30
+ }
31
+ return e;
32
+ }
33
+ function S(n, t) {
34
+ var s;
35
+ const r = { ...n }, e = /* @__PURE__ */ new Date();
36
+ return (s = t == null ? void 0 : t.columns) == null || s.forEach((i) => {
37
+ i.updatedAt && (n[i.name] = e), i.type === "date" && D(r[i.name]) && (r[i.name] = new Date(r[i.name]));
38
+ }), r;
39
+ }
40
+ const d = "_id";
41
+ function p(n, t, r, e) {
42
+ var s, i;
43
+ return Q(t) ? ((s = r == null ? void 0 : r[n]) == null ? void 0 : s.type) === "date" || n === d ? Object.entries(t).reduce((f, [y, o]) => {
44
+ var w;
45
+ return y === "$not" ? f[y] = p(n, o, r, e) : Array.isArray(o) ? f[y] = o.map((O) => p(n, O, r, e)) : D(o) && ((w = r == null ? void 0 : r[n]) == null ? void 0 : w.type) === "date" ? f[y] = new Date(o) : D(o) && n === d && e ? f[y] = e(o) : f[y] = o, f;
46
+ }, {}) : t : ((i = r == null ? void 0 : r[n]) == null ? void 0 : i.type) === "date" && D(t) ? new Date(t) : t;
47
+ }
48
+ function P(n, t, r, e) {
49
+ return n === "$and" ? Array.isArray(t) ? t.map((s) => A(s, r, e)) : A(t, r, e) : n === "$or" ? Array.isArray(t) ? t.map((s) => A(s, r, e)) : A(t, r, e) : p(n, t, r, e);
50
+ }
51
+ function A(n, t, r) {
52
+ return Object.entries(n).reduce((s, [i, u]) => (s[i] = P(i, u, t, r), s), {});
53
+ }
54
+ class g {
55
+ static buildCloudBaseQuery(t, r) {
56
+ return A(t ?? {}, r);
57
+ }
58
+ static buildMongodbQuery(t, r, e) {
59
+ return A(t ?? {}, r, e);
60
+ }
61
+ static getOrderByArray(t) {
62
+ return Object.entries(t ?? {}).map(([r, e]) => ({
63
+ fieldName: r,
64
+ order: e
65
+ }));
66
+ }
67
+ }
68
+ export {
69
+ g as Q,
70
+ c as a,
71
+ S as b
72
+ };
@@ -0,0 +1 @@
1
+ "use strict";function Q(n){if(!n||typeof n!="object")return!1;const t=Object.getPrototypeOf(n);return t===null||t===Object.prototype||Object.getPrototypeOf(t)===null?Object.prototype.toString.call(n)==="[object Object]":!1}function p(n){return typeof n=="string"}function j(n,t,r){return typeof n=="function"?n(t,r):n}function c(n,t,r){const e={...n},s=new Date;for(const i of t.columns)if(!(e[i.name]!==void 0&&e[i.name]!==null)){if(i.createdAt){e[i.name]=s;continue}if(i.updatedAt){e[i.name]=s;continue}if(i.type==="date"&&p(e[i.name])){e[i.name]=new Date(e[i.name]);continue}i.default!==void 0&&(e[i.name]=j(i.default,n,r))}return e}function P(n,t){var s;const r={...n},e=new Date;return(s=t==null?void 0:t.columns)==null||s.forEach(i=>{i.updatedAt&&(n[i.name]=e),i.type==="date"&&p(r[i.name])&&(r[i.name]=new Date(r[i.name]))}),r}const w="_id";function D(n,t,r,e){var s,i;return Q(t)?((s=r==null?void 0:r[n])==null?void 0:s.type)==="date"||n===w?Object.entries(t).reduce((f,[y,o])=>{var d;return y==="$not"?f[y]=D(n,o,r,e):Array.isArray(o)?f[y]=o.map(O=>D(n,O,r,e)):p(o)&&((d=r==null?void 0:r[n])==null?void 0:d.type)==="date"?f[y]=new Date(o):p(o)&&n===w&&e?f[y]=e(o):f[y]=o,f},{}):t:((i=r==null?void 0:r[n])==null?void 0:i.type)==="date"&&p(t)?new Date(t):t}function B(n,t,r,e){return n==="$and"?Array.isArray(t)?t.map(s=>u(s,r,e)):u(t,r,e):n==="$or"?Array.isArray(t)?t.map(s=>u(s,r,e)):u(t,r,e):D(n,t,r,e)}function u(n,t,r){return Object.entries(n).reduce((s,[i,A])=>(s[i]=B(i,A,t,r),s),{})}class S{static buildCloudBaseQuery(t,r){return u(t??{},r)}static buildMongodbQuery(t,r,e){return u(t??{},r,e)}static getOrderByArray(t){return Object.entries(t??{}).map(([r,e])=>({fieldName:r,order:e}))}}exports.QueryBuilder=S;exports.applyDefaultValues=c;exports.applyUpdateValues=P;
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./cloudbase-index.cjs"),o=require("./mongodb-index.cjs");function a(e){return t=>{}}function i(){return(e,t)=>{}}function u(e){return(t,r)=>{}}function d(e){return(t,r)=>{}}function p(e){return(t,r)=>{}}exports.createCloudBaseClient=n.createCloudBaseClient;exports.createMongoDBClient=o.createMongoDBClient;exports.CreatedAt=d;exports.Field=u;exports.PrimaryKey=i;exports.Table=a;exports.UpdatedAt=p;
@@ -0,0 +1,4 @@
1
+ export * from './decorators';
2
+ export * from './types';
3
+ export { createCloudBaseClient } from './client/cloudbase-index';
4
+ export { createMongoDBClient } from './client/mongodb-index';
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ import { createCloudBaseClient as c } from "./cloudbase-index.js";
2
+ import { createMongoDBClient as g } from "./mongodb-index.js";
3
+ function o(t) {
4
+ return (e) => {
5
+ };
6
+ }
7
+ function n() {
8
+ return (t, e) => {
9
+ };
10
+ }
11
+ function p(t) {
12
+ return (e, r) => {
13
+ };
14
+ }
15
+ function i(t) {
16
+ return (e, r) => {
17
+ };
18
+ }
19
+ function a(t) {
20
+ return (e, r) => {
21
+ };
22
+ }
23
+ export {
24
+ i as CreatedAt,
25
+ p as Field,
26
+ n as PrimaryKey,
27
+ o as Table,
28
+ a as UpdatedAt,
29
+ c as createCloudBaseClient,
30
+ g as createMongoDBClient
31
+ };