@byted-apaas/server-sdk-node 0.0.1-beta.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 (163) hide show
  1. package/LICENSE +7 -0
  2. package/NOTICE +3 -0
  3. package/README.md +1 -0
  4. package/application/application.d.ts +27 -0
  5. package/application/application.js +2 -0
  6. package/application/application.ts +40 -0
  7. package/application/function/function.d.ts +14 -0
  8. package/application/function/function.js +21 -0
  9. package/application/function/function.ts +37 -0
  10. package/application/impl/common.d.ts +2 -0
  11. package/application/impl/common.js +50 -0
  12. package/application/impl/common.ts +50 -0
  13. package/application/impl/impl.d.ts +16 -0
  14. package/application/impl/impl.js +38 -0
  15. package/application/impl/impl.ts +48 -0
  16. package/constants/constants.d.ts +10 -0
  17. package/constants/constants.js +15 -0
  18. package/constants/constants.ts +15 -0
  19. package/context/context.d.ts +74 -0
  20. package/context/context.js +25 -0
  21. package/context/context.ts +130 -0
  22. package/context/db/db.d.ts +73 -0
  23. package/context/db/db.js +4 -0
  24. package/context/db/db.ts +80 -0
  25. package/context/db/impl/IObject.d.ts +251 -0
  26. package/context/db/impl/IObject.js +5 -0
  27. package/context/db/impl/IObject.ts +247 -0
  28. package/context/db/impl/db.d.ts +61 -0
  29. package/context/db/impl/db.js +86 -0
  30. package/context/db/impl/db.ts +95 -0
  31. package/context/db/impl/object.d.ts +92 -0
  32. package/context/db/impl/object.js +524 -0
  33. package/context/db/impl/object.ts +631 -0
  34. package/context/db/impl/oql/ioql.d.ts +6 -0
  35. package/context/db/impl/oql/ioql.js +4 -0
  36. package/context/db/impl/oql/ioql.ts +9 -0
  37. package/context/db/impl/oql/oql.d.ts +8 -0
  38. package/context/db/impl/oql/oql.js +21 -0
  39. package/context/db/impl/oql/oql.ts +25 -0
  40. package/context/db/impl/order.d.ts +9 -0
  41. package/context/db/impl/order.js +15 -0
  42. package/context/db/impl/order.ts +19 -0
  43. package/context/db/impl/propertiesStore.d.ts +8 -0
  44. package/context/db/impl/propertiesStore.js +29 -0
  45. package/context/db/impl/propertiesStore.ts +31 -0
  46. package/context/db/impl/queryBuilder.d.ts +29 -0
  47. package/context/db/impl/queryBuilder.js +78 -0
  48. package/context/db/impl/queryBuilder.ts +106 -0
  49. package/context/db/impl/transaction/index.d.ts +20 -0
  50. package/context/db/impl/transaction/index.js +277 -0
  51. package/context/db/impl/transaction/index.ts +340 -0
  52. package/context/db/impl/transaction/operation.d.ts +27 -0
  53. package/context/db/impl/transaction/operation.js +69 -0
  54. package/context/db/impl/transaction/operation.ts +72 -0
  55. package/context/db/impl/transaction.d.ts +67 -0
  56. package/context/db/impl/transaction.js +4 -0
  57. package/context/db/impl/transaction.ts +79 -0
  58. package/context/globalConfig/globalConfig.d.ts +7 -0
  59. package/context/globalConfig/globalConfig.js +16 -0
  60. package/context/globalConfig/globalConfig.ts +14 -0
  61. package/context/metadata/components/common.d.ts +6 -0
  62. package/context/metadata/components/common.js +17 -0
  63. package/context/metadata/components/common.ts +22 -0
  64. package/context/metadata/components/components.d.ts +12 -0
  65. package/context/metadata/components/components.js +19 -0
  66. package/context/metadata/components/components.ts +22 -0
  67. package/context/metadata/components/desktop/list.d.ts +16 -0
  68. package/context/metadata/components/desktop/list.js +402 -0
  69. package/context/metadata/components/desktop/list.ts +457 -0
  70. package/context/metadata/components/desktop/recordDetail.d.ts +11 -0
  71. package/context/metadata/components/desktop/recordDetail.js +53 -0
  72. package/context/metadata/components/desktop/recordDetail.ts +67 -0
  73. package/context/metadata/components/mobile/list.d.ts +24 -0
  74. package/context/metadata/components/mobile/list.js +145 -0
  75. package/context/metadata/components/mobile/list.ts +179 -0
  76. package/context/metadata/metadata.d.ts +61 -0
  77. package/context/metadata/metadata.js +103 -0
  78. package/context/metadata/metadata.ts +178 -0
  79. package/context/metadata/objects/fields.d.ts +130 -0
  80. package/context/metadata/objects/fields.js +334 -0
  81. package/context/metadata/objects/fields.ts +457 -0
  82. package/context/metadata/objects/fields.util.d.ts +40 -0
  83. package/context/metadata/objects/fields.util.js +319 -0
  84. package/context/metadata/objects/fields.util.ts +360 -0
  85. package/context/metadata/objects/objects.d.ts +11 -0
  86. package/context/metadata/objects/objects.js +20 -0
  87. package/context/metadata/objects/objects.ts +30 -0
  88. package/context/metadata/types/common.d.ts +6 -0
  89. package/context/metadata/types/common.js +9 -0
  90. package/context/metadata/types/common.ts +13 -0
  91. package/context/metadata/types/components.d.ts +90 -0
  92. package/context/metadata/types/components.js +4 -0
  93. package/context/metadata/types/components.ts +108 -0
  94. package/context/metadata/types/objects.d.ts +226 -0
  95. package/context/metadata/types/objects.js +4 -0
  96. package/context/metadata/types/objects.ts +254 -0
  97. package/context/msg/msg.d.ts +38 -0
  98. package/context/msg/msg.js +35 -0
  99. package/context/msg/msg.ts +52 -0
  100. package/context/resources/IResources.d.ts +66 -0
  101. package/context/resources/IResources.js +2 -0
  102. package/context/resources/IResources.ts +73 -0
  103. package/context/resources/impl/resources.d.ts +42 -0
  104. package/context/resources/impl/resources.js +150 -0
  105. package/context/resources/impl/resources.ts +173 -0
  106. package/context/tasks/tasks.d.ts +33 -0
  107. package/context/tasks/tasks.js +139 -0
  108. package/context/tasks/tasks.ts +159 -0
  109. package/data/index.d.ts +27 -0
  110. package/data/index.js +4 -0
  111. package/data/index.ts +30 -0
  112. package/hooks/api.d.ts +61 -0
  113. package/hooks/api.js +327 -0
  114. package/hooks/api.ts +341 -0
  115. package/hooks/hooks.d.ts +1 -0
  116. package/hooks/hooks.js +88 -0
  117. package/hooks/hooks.ts +100 -0
  118. package/kunlun/kunlun.d.ts +55 -0
  119. package/kunlun/kunlun.js +58 -0
  120. package/kunlun/kunlun.ts +72 -0
  121. package/kunlun/operator/IOperator.d.ts +158 -0
  122. package/kunlun/operator/IOperator.js +4 -0
  123. package/kunlun/operator/IOperator.ts +166 -0
  124. package/kunlun/operator/impl/expression.d.ts +47 -0
  125. package/kunlun/operator/impl/expression.js +56 -0
  126. package/kunlun/operator/impl/expression.ts +74 -0
  127. package/kunlun/operator/impl/logic.d.ts +50 -0
  128. package/kunlun/operator/impl/logic.js +509 -0
  129. package/kunlun/operator/impl/logic.ts +598 -0
  130. package/kunlun/operator/impl/logicV2.d.ts +58 -0
  131. package/kunlun/operator/impl/logicV2.js +200 -0
  132. package/kunlun/operator/impl/logicV2.ts +254 -0
  133. package/kunlun/operator/impl/operator.d.ts +179 -0
  134. package/kunlun/operator/impl/operator.js +222 -0
  135. package/kunlun/operator/impl/operator.ts +258 -0
  136. package/kunlun/operator/impl/operatorV2.d.ts +180 -0
  137. package/kunlun/operator/impl/operatorV2.js +216 -0
  138. package/kunlun/operator/impl/operatorV2.ts +249 -0
  139. package/lib/core.d.ts +4 -0
  140. package/lib/core.js +19 -0
  141. package/lib/core.ts +7 -0
  142. package/package.json +50 -0
  143. package/request/common.d.ts +13 -0
  144. package/request/common.js +87 -0
  145. package/request/common.ts +91 -0
  146. package/request/constants.d.ts +10 -0
  147. package/request/constants.js +25 -0
  148. package/request/constants.ts +25 -0
  149. package/request/faasinfra.d.ts +8 -0
  150. package/request/faasinfra.js +358 -0
  151. package/request/faasinfra.ts +393 -0
  152. package/request/innerapi.d.ts +67 -0
  153. package/request/innerapi.js +1412 -0
  154. package/request/innerapi.ts +1648 -0
  155. package/request/interface.d.ts +95 -0
  156. package/request/interface.js +41 -0
  157. package/request/interface.ts +169 -0
  158. package/request/openapi.d.ts +69 -0
  159. package/request/openapi.js +1014 -0
  160. package/request/openapi.ts +1223 -0
  161. package/types/types.d.ts +79 -0
  162. package/types/types.js +4 -0
  163. package/types/types.ts +108 -0
@@ -0,0 +1,73 @@
1
+ import { currentObjApiName } from '../../data';
2
+ import { _IKAllEndpoint, _IKSyncEndpoint, _IKQuery } from './impl/IObject';
3
+ import { ITransactionGetter } from './impl/transaction';
4
+ import { IOql } from './impl/oql/ioql';
5
+ /**
6
+ * - IDBGetter 是声明 DB interface 的顶级入口,在使用时应该避免直接使用 IDB 和 IDBWithCurrentObject
7
+ * 应该直接使用 IDBGetter。
8
+ * - 目前 IDBGetter 支持的是 currentObject 方法的动态声明,使用泛型实现,期望传入的 T 是 Context 结构。
9
+ * - 如果 Context 有 objectApiName 属性,则拥有 .db.currentObject 和 .db.transaction.currentObject
10
+ */
11
+ export declare type IDBGetter<T, mt> = T extends {
12
+ 'objectApiName': string;
13
+ } ? IDB<T, mt> & IDBWithCurrentObject<{}, mt> : IDB<{}, mt>;
14
+ /**
15
+ * IDB 经由 IDBGetter 返回,是 DB 的基础接口结构
16
+ */
17
+ export interface IDB<T, mt> {
18
+ /**
19
+ * 操作指定对象的记录数据
20
+ * @param objectApiName 指定对象的 ApiName
21
+ * @example
22
+ * ```
23
+ * context.db.object("_user").where({
24
+ * gender: "male"
25
+ * }).find()
26
+ * ```
27
+ */
28
+ object<T extends keyof mt>(objectApiName: T): _IKAllEndpoint<mt[T]> & _IKQuery<mt[T]>;
29
+ /**
30
+ * 创建一个新的空事务
31
+ * @example
32
+ * ```
33
+ * let tx = context.db.newTransaction();
34
+ * let user = tx.object("_user").registerCreate({
35
+ * _name: new kunlun.type.Multilingual({ zh: "用户1", en: "user1" }),
36
+ * });
37
+ * let contract = tx.object("contract").registerCreate({
38
+ * _name: new kunlun.type.Multilingual({ zh: "用户1的合同", en: "user1's contract" }),
39
+ * user: {id: user._id}
40
+ * });
41
+ * await tx.commit();
42
+ * ```
43
+ */
44
+ newTransaction(): ITransactionGetter<T, mt>;
45
+ /**
46
+ * OQL 操作
47
+ * @param oql OQL 语句
48
+ * @example
49
+ * ```
50
+ * let users = await context.db.oql("select _email from _user").execute();
51
+ * ```
52
+ */
53
+ oql(oql: string): IOql;
54
+ }
55
+ /**
56
+ * IDBWithCurrentObject 经由 IDBGetter 返回,是 DB 的动态增加的接口结构
57
+ */
58
+ export interface IDBWithCurrentObject<T, mt> {
59
+ /**
60
+ * 无需入参,操作当前对象的记录数据
61
+ */
62
+ currentObject(): _IKAllEndpoint<mt[currentObjApiName]> & _IKQuery<mt[currentObjApiName]>;
63
+ }
64
+ /**
65
+ * IDBSync 仅包含同步调用接口,当前应用场景为 OpenSDK
66
+ */
67
+ export interface IDBSync<mt = Record<string, never>> {
68
+ /**
69
+ * 操作指定对象的记录数据
70
+ * @param objectApiName 指定对象的 ApiName
71
+ */
72
+ object(objectApiName: string): _IKSyncEndpoint<mt> & _IKQuery<mt>;
73
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // Copyright 2022 ByteDance Ltd. and/or its affiliates
3
+ // SPDX-License-Identifier: MIT
4
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,80 @@
1
+ // Copyright 2022 ByteDance Ltd. and/or its affiliates
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { currentObjApiName } from '../../data'
5
+ import { _IKAllEndpoint, _IKSyncEndpoint, _IKQuery } from './impl/IObject';
6
+ import { ITransactionGetter } from './impl/transaction';
7
+ import { IOql } from './impl/oql/ioql';
8
+
9
+ /**
10
+ * - IDBGetter 是声明 DB interface 的顶级入口,在使用时应该避免直接使用 IDB 和 IDBWithCurrentObject
11
+ * 应该直接使用 IDBGetter。
12
+ * - 目前 IDBGetter 支持的是 currentObject 方法的动态声明,使用泛型实现,期望传入的 T 是 Context 结构。
13
+ * - 如果 Context 有 objectApiName 属性,则拥有 .db.currentObject 和 .db.transaction.currentObject
14
+ */
15
+ export type IDBGetter<T, mt> = T extends { 'objectApiName': string } ? IDB<T, mt> & IDBWithCurrentObject<{}, mt> : IDB<{}, mt>;
16
+
17
+ /**
18
+ * IDB 经由 IDBGetter 返回,是 DB 的基础接口结构
19
+ */
20
+ export interface IDB<T, mt> {
21
+ /**
22
+ * 操作指定对象的记录数据
23
+ * @param objectApiName 指定对象的 ApiName
24
+ * @example
25
+ * ```
26
+ * context.db.object("_user").where({
27
+ * gender: "male"
28
+ * }).find()
29
+ * ```
30
+ */
31
+ object<T extends keyof mt>(objectApiName: T): _IKAllEndpoint<mt[T]> & _IKQuery<mt[T]>;
32
+
33
+ /**
34
+ * 创建一个新的空事务
35
+ * @example
36
+ * ```
37
+ * let tx = context.db.newTransaction();
38
+ * let user = tx.object("_user").registerCreate({
39
+ * _name: new kunlun.type.Multilingual({ zh: "用户1", en: "user1" }),
40
+ * });
41
+ * let contract = tx.object("contract").registerCreate({
42
+ * _name: new kunlun.type.Multilingual({ zh: "用户1的合同", en: "user1's contract" }),
43
+ * user: {id: user._id}
44
+ * });
45
+ * await tx.commit();
46
+ * ```
47
+ */
48
+ newTransaction(): ITransactionGetter<T, mt>;
49
+ /**
50
+ * OQL 操作
51
+ * @param oql OQL 语句
52
+ * @example
53
+ * ```
54
+ * let users = await context.db.oql("select _email from _user").execute();
55
+ * ```
56
+ */
57
+ oql(oql: string): IOql;
58
+ }
59
+
60
+ /**
61
+ * IDBWithCurrentObject 经由 IDBGetter 返回,是 DB 的动态增加的接口结构
62
+ */
63
+ export interface IDBWithCurrentObject<T, mt> {
64
+ /**
65
+ * 无需入参,操作当前对象的记录数据
66
+ */
67
+ // @ts-ignore
68
+ currentObject(): _IKAllEndpoint<mt[currentObjApiName]> & _IKQuery<mt[currentObjApiName]>;
69
+ }
70
+
71
+ /**
72
+ * IDBSync 仅包含同步调用接口,当前应用场景为 OpenSDK
73
+ */
74
+ export interface IDBSync<mt = Record<string, never>> {
75
+ /**
76
+ * 操作指定对象的记录数据
77
+ * @param objectApiName 指定对象的 ApiName
78
+ */
79
+ object(objectApiName: string): _IKSyncEndpoint<mt> & _IKQuery<mt>;
80
+ }
@@ -0,0 +1,251 @@
1
+ import { _Cond, _Record, _WhereCond } from '../../../types/types';
2
+ export interface _IKAllEndpoint<T> extends _IKSyncEndpoint<T>, _IKAsyncEndpoint<T> {
3
+ }
4
+ export interface _IKSyncEndpoint<T> {
5
+ /**
6
+ * 创建记录
7
+ * @param recordMap 用于创建的一条记录
8
+ * @paramExample {_name: "John", age: 19, gender: "male"}
9
+ * @example
10
+ * ```
11
+ * context.db.object("_department").create({
12
+ * _name: new kunlun.type.Multilingual({ zh: "部门" }),
13
+ * _manager: { _id: 1660000000 },
14
+ * _status: "_active"
15
+ * })
16
+ * ```
17
+ */
18
+ create(recordMap: _Cond<T>): Promise<{
19
+ _id: number;
20
+ }>;
21
+ /**
22
+ * 删除记录
23
+ * @param recordID 用于删除的一条记录的 ID
24
+ * @example
25
+ * ```
26
+ * context.db.object("_user").delete(123456789123)
27
+ * ```
28
+ */
29
+ delete(recordID: number): Promise<void>;
30
+ /**
31
+ * 删除记录
32
+ * @param record 用于删除的一条完整记录
33
+ * @example
34
+ * ```
35
+ * context.db.object("_user").delete(context.targetRecord.original)
36
+ * ```
37
+ */
38
+ delete(record: _Cond<T>): Promise<void>;
39
+ /**
40
+ * 指定 _id 后,更新对应记录
41
+ * @param _id 主键
42
+ * @param recordMap 用于更新的一条记录
43
+ * @paramExample {_name: "John", age: 19, gender: "male"}
44
+ * @example
45
+ * ```
46
+ * context.db.object("_user").update(1660000000, {
47
+ * gender: "male"
48
+ * })
49
+ * ```
50
+ */
51
+ update(_id: number, recordMap: _Cond<T>): Promise<void>;
52
+ /**
53
+ * 指定 _id 后,更新对应记录
54
+ * @param recordMap 用于更新的一条记录,需对 _id 赋值
55
+ * @paramExample {_id: 1660000000, _name: "John", age: 19, gender: "male"}
56
+ * @example
57
+ * ```
58
+ * context.db.object("_user").update({
59
+ * _id: 1660000000,
60
+ * gender: "male"
61
+ * })
62
+ * ```
63
+ */
64
+ update(recordMap: _Cond<T>): Promise<void>;
65
+ /**
66
+ * 批量创建记录
67
+ * @param recordMapList 多条用于创建的记录数据组成的数组
68
+ * @paramExample [{_name: "John", age: 19, gender: "male"}, {_name: "Alis", age: 16, gender: "female"}]
69
+ */
70
+ batchCreate(recordMapList: _Cond<T>[]): Promise<number[]>;
71
+ /**
72
+ * 批量删除记录
73
+ * @param recordIdList 多个用于删除的记录 ID 组成的数组
74
+ * @paramExample [1001, 1002, 1003]
75
+ */
76
+ batchDelete(recordIdList: number[]): Promise<void>;
77
+ /**
78
+ * 批量删除记录
79
+ * @param recordList 多条用于删除的记录数据组成的数组,记录数据需对 _id 赋值
80
+ * @paramExample [{_id: 1001, _name: "John", gender: "male"}, {_id: 1002, _name: "Alis", gender: "female"}]
81
+ */
82
+ batchDelete(recordList: _Cond<T>[]): Promise<void>;
83
+ /**
84
+ * 根据 _id 批量更新记录
85
+ * @param recordMapList 多条用于更新的记录数据组成的数组,记录数据需对 _id 赋值
86
+ * @paramExample [{_id: 1001, _name: "John", gender: "male"}, {_id: 1002, _name: "Alis", gender: "female"}]
87
+ */
88
+ batchUpdate(recordMapList: _Cond<T>[]): Promise<void>;
89
+ }
90
+ export interface _IKAsyncEndpoint<T> {
91
+ /**
92
+ * 批量创建记录(为异步任务)
93
+ * @param recordMapList 用于创建的多条记录
94
+ * @paramExample [{_name: "John", age: 19, gender: "male"}, {_name: "Alis", age: 16, gender: "female"}]
95
+ */
96
+ batchCreateAsync(recordMapList: _Cond<T>[]): Promise<{
97
+ taskID: number;
98
+ }>;
99
+ /**
100
+ * 批量删除记录(为异步任务)
101
+ * @param recordIDList 用于删除的多条记录的 ID 列表
102
+ */
103
+ batchDeleteAsync(recordIDList: number[]): Promise<{
104
+ taskID: number;
105
+ }>;
106
+ /**
107
+ * 批量删除记录(为异步任务)
108
+ * @param recordList 用于删除的多条完整记录的列表
109
+ */
110
+ batchDeleteAsync(recordList: _Cond<T>[]): Promise<{
111
+ taskID: number;
112
+ }>;
113
+ /**
114
+ * 根据 _id 批量更新记录(为异步任务)
115
+ * @param recordMapList 用于更新的多条记录,需对 _id 赋值
116
+ * @paramExample [{_id: 1001, _name: "John", gender: "male"}, {_id: 1002, _name: "Alis", gender: "female"}]
117
+ */
118
+ batchUpdateAsync(recordMapList: _Cond<T>[]): Promise<{
119
+ taskID: number;
120
+ }>;
121
+ }
122
+ export interface _IKQuery<T> {
123
+ /**
124
+ * 无需入参,返回全部符合条件的记录
125
+ * @example
126
+ * ```
127
+ * context.db.object("_user").where({
128
+ * gender: "male"
129
+ * }).findAll()
130
+ * ```
131
+ */
132
+ findAll(): Promise<_Record<T>[]>;
133
+ /**
134
+ * 无需入参,返回符合条件的记录,单次返回 200 条
135
+ * @example
136
+ * ```
137
+ * context.db.object("_user").where({
138
+ * gender: "male"
139
+ * }).find()
140
+ * ```
141
+ */
142
+ find(): Promise<_Record<T>[]>;
143
+ /**
144
+ * 无需入参,返回排在第一位的记录
145
+ * @example
146
+ * ```
147
+ * context.db.object("_user").where({
148
+ * gender: "male"
149
+ * }).findOne()
150
+ * ```
151
+ */
152
+ findOne(): Promise<_Record<T>>;
153
+ /**
154
+ * 根据指定字段升序排序(a -> z, 0 -> 9)
155
+ * @param fieldApiNames 排序依据的字段数组,按先后顺序确定优先级
156
+ * @example
157
+ * ```
158
+ * context.db.object("_user").orderBy(["_email", "_phoneNumber"]).find()
159
+ * ```
160
+ */
161
+ orderBy<K extends keyof T>(fieldApiNames: K[]): _IKQuery<T>;
162
+ /**
163
+ * 根据指定字段升序排序(a -> z, 0 -> 9)
164
+ * @param fieldApiNames 排序依据的字段,按先后顺序确定优先级,用逗号分隔
165
+ * @example
166
+ * ```
167
+ * context.db.object("_user").orderBy("_email", "_phoneNumber").find()
168
+ * ```
169
+ */
170
+ orderBy<K extends keyof T>(...fieldApiNames: K[]): _IKQuery<T>;
171
+ /**
172
+ * 根据指定字段降序排序(z -> a, 9 -> 0)
173
+ * @param fieldApiNames 排序依据的字段数组,按先后顺序确定优先级
174
+ * @example
175
+ * ```
176
+ * context.db.object("_user").orderByDesc("_email", "_phoneNumber").find()
177
+ * ```
178
+ */
179
+ orderByDesc<K extends keyof T>(fieldApiNames: K[]): _IKQuery<T>;
180
+ /**
181
+ * 根据指定字段降序排序(z -> a, 9 -> 0)
182
+ * @param fieldApiNames 排序依据的字段,按先后顺序确定优先级,用逗号分隔
183
+ * @example
184
+ * ```
185
+ * context.db.object("_user").orderByDesc("_email", "_phoneNumber").find()
186
+ * ```
187
+ */
188
+ orderByDesc<K extends keyof T>(...fieldApiNames: K[]): _IKQuery<T>;
189
+ /**
190
+ * 指定需返回的字段
191
+ * @param fieldApiNames 需返回的字段数组
192
+ * @example
193
+ * ```
194
+ * context.db.object("_user").select(["_name", "_email"]).find()
195
+ * ```
196
+ */
197
+ select<K extends keyof T>(fieldApiNames: K[]): _IKQuery<T>;
198
+ /**
199
+ * 指定需返回的字段
200
+ * @param fieldApiNames 需返回的字段,用逗号分隔
201
+ * @example
202
+ * ```
203
+ * context.db.object("_user").select("_name", "_email").find()
204
+ * ```
205
+ */
206
+ select<K extends keyof T>(...fieldApiNames: K[]): _IKQuery<T>;
207
+ /**
208
+ * 设置查询条件
209
+ * @param conditionMap 对字段赋值以指定查询筛选条件
210
+ * @paramExample {gender: "male"}
211
+ * @example
212
+ * ```
213
+ * context.db.object("_user").where({
214
+ * gender: "male"
215
+ * }).find()
216
+ * ```
217
+ */
218
+ where(conditionMap: _WhereCond<T>): _IKQuery<T>;
219
+ /**
220
+ * 设置查询条件
221
+ */
222
+ where(): _IKQuery<T>;
223
+ /**
224
+ * 指定分页查询的数量
225
+ * @param limit 分页查询的数量
226
+ * @paramExample 10
227
+ * @example
228
+ * ```
229
+ * context.db.object("_user").limit(10)
230
+ * ```
231
+ */
232
+ limit(limit: number): _IKQuery<T>;
233
+ /**
234
+ * 指定分页查询的偏移量
235
+ * @param offset 分页查询的偏移量
236
+ * @paramExample 0
237
+ * @example
238
+ * ```
239
+ * context.db.object("_user").offset(0)
240
+ * ```
241
+ */
242
+ offset(offset: number): _IKQuery<T>;
243
+ /**
244
+ * 指定条件的行数
245
+ * @example
246
+ * ```
247
+ * context.db.object("_user").count()
248
+ * ```
249
+ */
250
+ count(): Promise<number>;
251
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ // Copyright 2022 ByteDance Ltd. and/or its affiliates
3
+ // SPDX-License-Identifier: MIT
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ ;
@@ -0,0 +1,247 @@
1
+ // Copyright 2022 ByteDance Ltd. and/or its affiliates
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { _Cond, _Record, _WhereCond } from '../../../types/types'
5
+
6
+ export interface _IKAllEndpoint<T> extends _IKSyncEndpoint<T>, _IKAsyncEndpoint<T> { };
7
+
8
+ export interface _IKSyncEndpoint<T> {
9
+ /**
10
+ * 创建记录
11
+ * @param recordMap 用于创建的一条记录
12
+ * @paramExample {_name: "John", age: 19, gender: "male"}
13
+ * @example
14
+ * ```
15
+ * context.db.object("_department").create({
16
+ * _name: new kunlun.type.Multilingual({ zh: "部门" }),
17
+ * _manager: { _id: 1660000000 },
18
+ * _status: "_active"
19
+ * })
20
+ * ```
21
+ */
22
+ create(recordMap: _Cond<T>): Promise<{ _id: number }>;
23
+ /**
24
+ * 删除记录
25
+ * @param recordID 用于删除的一条记录的 ID
26
+ * @example
27
+ * ```
28
+ * context.db.object("_user").delete(123456789123)
29
+ * ```
30
+ */
31
+ delete(recordID: number): Promise<void>;
32
+ /**
33
+ * 删除记录
34
+ * @param record 用于删除的一条完整记录
35
+ * @example
36
+ * ```
37
+ * context.db.object("_user").delete(context.targetRecord.original)
38
+ * ```
39
+ */
40
+ delete(record: _Cond<T>): Promise<void>;
41
+ /**
42
+ * 指定 _id 后,更新对应记录
43
+ * @param _id 主键
44
+ * @param recordMap 用于更新的一条记录
45
+ * @paramExample {_name: "John", age: 19, gender: "male"}
46
+ * @example
47
+ * ```
48
+ * context.db.object("_user").update(1660000000, {
49
+ * gender: "male"
50
+ * })
51
+ * ```
52
+ */
53
+ update(_id: number, recordMap: _Cond<T>): Promise<void>;
54
+ /**
55
+ * 指定 _id 后,更新对应记录
56
+ * @param recordMap 用于更新的一条记录,需对 _id 赋值
57
+ * @paramExample {_id: 1660000000, _name: "John", age: 19, gender: "male"}
58
+ * @example
59
+ * ```
60
+ * context.db.object("_user").update({
61
+ * _id: 1660000000,
62
+ * gender: "male"
63
+ * })
64
+ * ```
65
+ */
66
+ update(recordMap: _Cond<T>): Promise<void>;
67
+ /**
68
+ * 批量创建记录
69
+ * @param recordMapList 多条用于创建的记录数据组成的数组
70
+ * @paramExample [{_name: "John", age: 19, gender: "male"}, {_name: "Alis", age: 16, gender: "female"}]
71
+ */
72
+ batchCreate(recordMapList: _Cond<T>[]): Promise<number[]>;
73
+ /**
74
+ * 批量删除记录
75
+ * @param recordIdList 多个用于删除的记录 ID 组成的数组
76
+ * @paramExample [1001, 1002, 1003]
77
+ */
78
+ batchDelete(recordIdList: number[]): Promise<void>;
79
+ /**
80
+ * 批量删除记录
81
+ * @param recordList 多条用于删除的记录数据组成的数组,记录数据需对 _id 赋值
82
+ * @paramExample [{_id: 1001, _name: "John", gender: "male"}, {_id: 1002, _name: "Alis", gender: "female"}]
83
+ */
84
+ batchDelete(recordList: _Cond<T>[]): Promise<void>;
85
+ /**
86
+ * 根据 _id 批量更新记录
87
+ * @param recordMapList 多条用于更新的记录数据组成的数组,记录数据需对 _id 赋值
88
+ * @paramExample [{_id: 1001, _name: "John", gender: "male"}, {_id: 1002, _name: "Alis", gender: "female"}]
89
+ */
90
+ batchUpdate(recordMapList: _Cond<T>[]): Promise<void>;
91
+ }
92
+
93
+ export interface _IKAsyncEndpoint<T> {
94
+ /**
95
+ * 批量创建记录(为异步任务)
96
+ * @param recordMapList 用于创建的多条记录
97
+ * @paramExample [{_name: "John", age: 19, gender: "male"}, {_name: "Alis", age: 16, gender: "female"}]
98
+ */
99
+ batchCreateAsync(recordMapList: _Cond<T>[]): Promise<{ taskID: number }>;
100
+ /**
101
+ * 批量删除记录(为异步任务)
102
+ * @param recordIDList 用于删除的多条记录的 ID 列表
103
+ */
104
+ batchDeleteAsync(recordIDList: number[]): Promise<{ taskID: number }>;
105
+ /**
106
+ * 批量删除记录(为异步任务)
107
+ * @param recordList 用于删除的多条完整记录的列表
108
+ */
109
+ batchDeleteAsync(recordList: _Cond<T>[]): Promise<{ taskID: number }>;
110
+ /**
111
+ * 根据 _id 批量更新记录(为异步任务)
112
+ * @param recordMapList 用于更新的多条记录,需对 _id 赋值
113
+ * @paramExample [{_id: 1001, _name: "John", gender: "male"}, {_id: 1002, _name: "Alis", gender: "female"}]
114
+ */
115
+ batchUpdateAsync(recordMapList: _Cond<T>[]): Promise<{ taskID: number }>;
116
+ }
117
+
118
+ export interface _IKQuery<T> {
119
+ /**
120
+ * 无需入参,返回全部符合条件的记录
121
+ * @example
122
+ * ```
123
+ * context.db.object("_user").where({
124
+ * gender: "male"
125
+ * }).findAll()
126
+ * ```
127
+ */
128
+ findAll(): Promise<_Record<T>[]>;
129
+ /**
130
+ * 无需入参,返回符合条件的记录,单次返回 200 条
131
+ * @example
132
+ * ```
133
+ * context.db.object("_user").where({
134
+ * gender: "male"
135
+ * }).find()
136
+ * ```
137
+ */
138
+ find(): Promise<_Record<T>[]>;
139
+ /**
140
+ * 无需入参,返回排在第一位的记录
141
+ * @example
142
+ * ```
143
+ * context.db.object("_user").where({
144
+ * gender: "male"
145
+ * }).findOne()
146
+ * ```
147
+ */
148
+ findOne(): Promise<_Record<T>>;
149
+ /**
150
+ * 根据指定字段升序排序(a -> z, 0 -> 9)
151
+ * @param fieldApiNames 排序依据的字段数组,按先后顺序确定优先级
152
+ * @example
153
+ * ```
154
+ * context.db.object("_user").orderBy(["_email", "_phoneNumber"]).find()
155
+ * ```
156
+ */
157
+ orderBy<K extends keyof T>(fieldApiNames: K[]): _IKQuery<T>;
158
+ /**
159
+ * 根据指定字段升序排序(a -> z, 0 -> 9)
160
+ * @param fieldApiNames 排序依据的字段,按先后顺序确定优先级,用逗号分隔
161
+ * @example
162
+ * ```
163
+ * context.db.object("_user").orderBy("_email", "_phoneNumber").find()
164
+ * ```
165
+ */
166
+ orderBy<K extends keyof T>(...fieldApiNames: K[]): _IKQuery<T>;
167
+ /**
168
+ * 根据指定字段降序排序(z -> a, 9 -> 0)
169
+ * @param fieldApiNames 排序依据的字段数组,按先后顺序确定优先级
170
+ * @example
171
+ * ```
172
+ * context.db.object("_user").orderByDesc("_email", "_phoneNumber").find()
173
+ * ```
174
+ */
175
+ orderByDesc<K extends keyof T>(fieldApiNames: K[]): _IKQuery<T>;
176
+ /**
177
+ * 根据指定字段降序排序(z -> a, 9 -> 0)
178
+ * @param fieldApiNames 排序依据的字段,按先后顺序确定优先级,用逗号分隔
179
+ * @example
180
+ * ```
181
+ * context.db.object("_user").orderByDesc("_email", "_phoneNumber").find()
182
+ * ```
183
+ */
184
+ orderByDesc<K extends keyof T>(...fieldApiNames: K[]): _IKQuery<T>;
185
+ /**
186
+ * 指定需返回的字段
187
+ * @param fieldApiNames 需返回的字段数组
188
+ * @example
189
+ * ```
190
+ * context.db.object("_user").select(["_name", "_email"]).find()
191
+ * ```
192
+ */
193
+ select<K extends keyof T>(fieldApiNames: K[]): _IKQuery<T>;
194
+ /**
195
+ * 指定需返回的字段
196
+ * @param fieldApiNames 需返回的字段,用逗号分隔
197
+ * @example
198
+ * ```
199
+ * context.db.object("_user").select("_name", "_email").find()
200
+ * ```
201
+ */
202
+ select<K extends keyof T>(...fieldApiNames: K[]): _IKQuery<T>;
203
+ /**
204
+ * 设置查询条件
205
+ * @param conditionMap 对字段赋值以指定查询筛选条件
206
+ * @paramExample {gender: "male"}
207
+ * @example
208
+ * ```
209
+ * context.db.object("_user").where({
210
+ * gender: "male"
211
+ * }).find()
212
+ * ```
213
+ */
214
+ where(conditionMap: _WhereCond<T>): _IKQuery<T>;
215
+ /**
216
+ * 设置查询条件
217
+ */
218
+ where(): _IKQuery<T>;
219
+ /**
220
+ * 指定分页查询的数量
221
+ * @param limit 分页查询的数量
222
+ * @paramExample 10
223
+ * @example
224
+ * ```
225
+ * context.db.object("_user").limit(10)
226
+ * ```
227
+ */
228
+ limit(limit: number): _IKQuery<T>;
229
+ /**
230
+ * 指定分页查询的偏移量
231
+ * @param offset 分页查询的偏移量
232
+ * @paramExample 0
233
+ * @example
234
+ * ```
235
+ * context.db.object("_user").offset(0)
236
+ * ```
237
+ */
238
+ offset(offset: number): _IKQuery<T>;
239
+ /**
240
+ * 指定条件的行数
241
+ * @example
242
+ * ```
243
+ * context.db.object("_user").count()
244
+ * ```
245
+ */
246
+ count(): Promise<number>;
247
+ }