@steedos/objectql 2.2.50-beta.7 → 2.2.51-beta.2
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/lib/services/helpers/graphql/consts.d.ts +17 -0
- package/lib/services/helpers/graphql/consts.js +28 -0
- package/lib/services/helpers/graphql/consts.js.map +1 -0
- package/lib/services/helpers/graphql/getQueryFields.js +17 -2
- package/lib/services/helpers/graphql/getQueryFields.js.map +1 -1
- package/lib/services/helpers/graphql/index.d.ts +1 -1
- package/lib/services/helpers/graphql/index.js +31 -46
- package/lib/services/helpers/graphql/index.js.map +1 -1
- package/lib/util/index.js +7 -0
- package/lib/util/index.js.map +1 -1
- package/package.json +10 -10
- package/src/actions/field_updates.ts +0 -118
- package/src/actions/index.ts +0 -3
- package/src/actions/types/field_update_target.ts +0 -7
- package/src/actions/types/workflow_notification.ts +0 -9
- package/src/actions/types/workflow_rule.ts +0 -11
- package/src/actions/workflow_notifications.ts +0 -81
- package/src/actions/workflow_rule.ts +0 -136
- package/src/driver/driver.ts +0 -102
- package/src/driver/field-encrytion/index.ts +0 -8
- package/src/driver/field-encrytion/sharedconst.ts +0 -34
- package/src/driver/fieldDBType.ts +0 -14
- package/src/driver/format.ts +0 -36
- package/src/driver/index.ts +0 -20
- package/src/driver/metadata.ts +0 -226
- package/src/driver/meteorMongo.ts +0 -639
- package/src/driver/mongo.ts +0 -416
- package/src/driver/mysql.ts +0 -47
- package/src/driver/oracle.ts +0 -60
- package/src/driver/postgres.ts +0 -46
- package/src/driver/sqlite3.ts +0 -40
- package/src/driver/sqlserver.ts +0 -52
- package/src/dynamic-load/actions.ts +0 -146
- package/src/dynamic-load/approval_process.ts +0 -73
- package/src/dynamic-load/button.ts +0 -75
- package/src/dynamic-load/chart.ts +0 -22
- package/src/dynamic-load/client_script.ts +0 -65
- package/src/dynamic-load/field.ts +0 -77
- package/src/dynamic-load/flow_role.ts +0 -46
- package/src/dynamic-load/index.ts +0 -21
- package/src/dynamic-load/layout.ts +0 -53
- package/src/dynamic-load/listview.ts +0 -57
- package/src/dynamic-load/method.ts +0 -63
- package/src/dynamic-load/object_translations.ts +0 -61
- package/src/dynamic-load/originalObject.ts +0 -8
- package/src/dynamic-load/package.ts +0 -312
- package/src/dynamic-load/page.ts +0 -23
- package/src/dynamic-load/permission.ts +0 -71
- package/src/dynamic-load/permissionset.ts +0 -78
- package/src/dynamic-load/preload_data.ts +0 -104
- package/src/dynamic-load/profile.ts +0 -90
- package/src/dynamic-load/query.ts +0 -22
- package/src/dynamic-load/restrictionRules.ts +0 -23
- package/src/dynamic-load/role.ts +0 -46
- package/src/dynamic-load/shareRules.ts +0 -23
- package/src/dynamic-load/tab.ts +0 -17
- package/src/dynamic-load/tabs.ts +0 -13
- package/src/dynamic-load/translations.ts +0 -54
- package/src/dynamic-load/trigger.ts +0 -236
- package/src/dynamic-load/validation_rule.ts +0 -77
- package/src/dynamic-load/workflow.ts +0 -114
- package/src/errors/index.ts +0 -111
- package/src/formula/core.ts +0 -490
- package/src/formula/field_formula.ts +0 -107
- package/src/formula/index.ts +0 -81
- package/src/formula/params.ts +0 -197
- package/src/formula/recompute.ts +0 -65
- package/src/formula/simple_params.ts +0 -92
- package/src/formula/type.ts +0 -107
- package/src/formula/util.ts +0 -207
- package/src/index.ts +0 -24
- package/src/metadata-register/_base.ts +0 -85
- package/src/metadata-register/app.ts +0 -30
- package/src/metadata-register/chart.ts +0 -9
- package/src/metadata-register/index.ts +0 -123
- package/src/metadata-register/layout.ts +0 -38
- package/src/metadata-register/object.ts +0 -68
- package/src/metadata-register/page.ts +0 -9
- package/src/metadata-register/permissionFields.ts +0 -13
- package/src/metadata-register/permissionset.ts +0 -25
- package/src/metadata-register/process.ts +0 -16
- package/src/metadata-register/processTrigger.ts +0 -24
- package/src/metadata-register/profile.ts +0 -25
- package/src/metadata-register/query.ts +0 -9
- package/src/metadata-register/restrictionRules.ts +0 -12
- package/src/metadata-register/shareRules.ts +0 -13
- package/src/metadata-register/tab.ts +0 -9
- package/src/metadata-register/tabs.ts +0 -43
- package/src/services/datasourceServiceFactory.ts +0 -55
- package/src/services/helpers/graphql/getPrimaryFieldType.ts +0 -48
- package/src/services/helpers/graphql/getQueryFields.ts +0 -36
- package/src/services/helpers/graphql/index.ts +0 -681
- package/src/services/helpers/rest.ts +0 -57
- package/src/services/index.ts +0 -13
- package/src/services/objectService.ts +0 -846
- package/src/services/objectServiceDispatcher.ts +0 -209
- package/src/services/objectServiceFactory.ts +0 -29
- package/src/summary/core.ts +0 -263
- package/src/summary/field_summary.ts +0 -71
- package/src/summary/index.ts +0 -96
- package/src/summary/recompute.ts +0 -31
- package/src/summary/type.ts +0 -60
- package/src/ts-types/index.ts +0 -3
- package/src/ts-types/permissionset.ts +0 -8
- package/src/ts-types/profile.ts +0 -11
- package/src/ts-types/triggerActionParams.ts +0 -22
- package/src/typeorm/driver.ts +0 -379
- package/src/typeorm/index.ts +0 -3
- package/src/typeorm/util.ts +0 -147
- package/src/types/action.ts +0 -52
- package/src/types/app.ts +0 -280
- package/src/types/config.ts +0 -152
- package/src/types/connection.ts +0 -87
- package/src/types/dashboard.ts +0 -91
- package/src/types/datasource.ts +0 -570
- package/src/types/field.ts +0 -370
- package/src/types/field_permission.ts +0 -42
- package/src/types/field_types.ts +0 -1
- package/src/types/index.ts +0 -21
- package/src/types/list_view.ts +0 -56
- package/src/types/listeners.ts +0 -18
- package/src/types/object.ts +0 -2076
- package/src/types/object_dynamic_load.ts +0 -426
- package/src/types/object_events.ts +0 -43
- package/src/types/object_layouts.ts +0 -20
- package/src/types/object_permission.ts +0 -134
- package/src/types/query.ts +0 -28
- package/src/types/report.ts +0 -128
- package/src/types/restrictionRule.ts +0 -57
- package/src/types/schema.ts +0 -273
- package/src/types/shareRule.ts +0 -57
- package/src/types/trigger.ts +0 -88
- package/src/types/userSession.ts +0 -45
- package/src/types/validation_rules.ts +0 -29
- package/src/util/convert.ts +0 -131
- package/src/util/field.ts +0 -93
- package/src/util/function_expression.ts +0 -63
- package/src/util/index.ts +0 -1058
- package/src/util/locale.ts +0 -24
- package/src/util/permission_shares.ts +0 -25
- package/src/util/suffix.ts +0 -78
- package/src/util/transform.ts +0 -239
- package/src/validators/index.ts +0 -36
|
@@ -1,639 +0,0 @@
|
|
|
1
|
-
import { JsonMap, Dictionary } from "@salesforce/ts-types";
|
|
2
|
-
import { SteedosDriver } from "./index"
|
|
3
|
-
import { SteedosQueryOptions, SteedosQueryFilters } from "../types/query";
|
|
4
|
-
import { SteedosIDType, SteedosObjectType } from "../types";
|
|
5
|
-
import { SteedosDriverConfig } from "./driver";
|
|
6
|
-
import { formatFiltersToODataQuery } from "@steedos/filters";
|
|
7
|
-
import { createFilter } from 'odata-v4-mongodb';
|
|
8
|
-
import { createQuery } from 'odata-v4-mongodb';
|
|
9
|
-
import _ = require("underscore");
|
|
10
|
-
import { SteedosFieldDBType } from "./fieldDBType";
|
|
11
|
-
import { ObjectId } from "mongodb";
|
|
12
|
-
import { formatRecord } from './format';
|
|
13
|
-
|
|
14
|
-
var Fiber = require('fibers');
|
|
15
|
-
|
|
16
|
-
declare var Creator: any;
|
|
17
|
-
declare var DDP: any;
|
|
18
|
-
declare var DDPCommon: any;
|
|
19
|
-
|
|
20
|
-
export class SteedosMeteorMongoDriver implements SteedosDriver {
|
|
21
|
-
|
|
22
|
-
getSupportedColumnTypes() {
|
|
23
|
-
return [
|
|
24
|
-
SteedosFieldDBType.varchar,
|
|
25
|
-
SteedosFieldDBType.text,
|
|
26
|
-
SteedosFieldDBType.number,
|
|
27
|
-
SteedosFieldDBType.boolean,
|
|
28
|
-
SteedosFieldDBType.date,
|
|
29
|
-
SteedosFieldDBType.dateTime,
|
|
30
|
-
SteedosFieldDBType.json,
|
|
31
|
-
SteedosFieldDBType.array
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
connect() {
|
|
36
|
-
}
|
|
37
|
-
close() {
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async init() {
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
constructor(config: SteedosDriverConfig) {
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
formatFiltersToMongoQuery(filters: any): JsonMap {
|
|
48
|
-
let emptyFilters = {};
|
|
49
|
-
let odataQuery: string = "";
|
|
50
|
-
if (_.isString(filters)) {
|
|
51
|
-
odataQuery = filters;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
odataQuery = formatFiltersToODataQuery(filters)
|
|
55
|
-
}
|
|
56
|
-
if (!odataQuery) {
|
|
57
|
-
return emptyFilters;
|
|
58
|
-
}
|
|
59
|
-
let query: JsonMap = createFilter(odataQuery);
|
|
60
|
-
return query;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/* TODO: */
|
|
64
|
-
getMongoFilters(filters: SteedosQueryFilters): JsonMap {
|
|
65
|
-
let emptyFilters = {};
|
|
66
|
-
if (_.isUndefined(filters)) {
|
|
67
|
-
return emptyFilters;
|
|
68
|
-
}
|
|
69
|
-
if (_.isString(filters) && !filters.length) {
|
|
70
|
-
return emptyFilters
|
|
71
|
-
}
|
|
72
|
-
if (_.isArray(filters) && !filters.length) {
|
|
73
|
-
return emptyFilters
|
|
74
|
-
}
|
|
75
|
-
let mongoFilters: JsonMap = this.formatFiltersToMongoQuery(filters);
|
|
76
|
-
return mongoFilters
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
getMongoFieldsOptions(fields: string[] | string): JsonMap {
|
|
80
|
-
if (typeof fields == "string") {
|
|
81
|
-
fields = (<string>fields).split(",").map((n) => { return n.trim(); });
|
|
82
|
-
}
|
|
83
|
-
if (!(fields && fields.length)) {
|
|
84
|
-
// throw new Error("fields must not be undefined or empty");
|
|
85
|
-
return {}
|
|
86
|
-
}
|
|
87
|
-
let projection: JsonMap = {};
|
|
88
|
-
(<string[]>fields).forEach((field) => {
|
|
89
|
-
if (field) {
|
|
90
|
-
projection[field] = 1;
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
return projection;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
getMongoSortOptions(sort: string): JsonMap {
|
|
97
|
-
let result: JsonMap = undefined;
|
|
98
|
-
if (sort && typeof sort === "string") {
|
|
99
|
-
let arraySort: string[] = sort.split(",").map((n) => { return n.trim(); });
|
|
100
|
-
let stringSort: string = "";
|
|
101
|
-
arraySort.forEach((n) => {
|
|
102
|
-
if (n) {
|
|
103
|
-
stringSort += `${n},`
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
stringSort = stringSort.replace(/,$/g, "");
|
|
107
|
-
result = createQuery(`$orderby=${stringSort}`).sort;
|
|
108
|
-
}
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/* TODO: */
|
|
113
|
-
getMongoOptions(options: SteedosQueryOptions): JsonMap {
|
|
114
|
-
if (_.isUndefined(options)) {
|
|
115
|
-
return {};
|
|
116
|
-
}
|
|
117
|
-
let result: JsonMap = {};
|
|
118
|
-
let projection: JsonMap = this.getMongoFieldsOptions(options.fields);
|
|
119
|
-
let sort: JsonMap = this.getMongoSortOptions(options.sort);
|
|
120
|
-
result.fields = projection;
|
|
121
|
-
result.sort = sort;
|
|
122
|
-
result.limit = options.top;
|
|
123
|
-
result.skip = options.skip;
|
|
124
|
-
return result;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
getAggregateOptions(options: SteedosQueryOptions): any[] {
|
|
128
|
-
if (_.isUndefined(options)) {
|
|
129
|
-
return [];
|
|
130
|
-
}
|
|
131
|
-
let result = [];
|
|
132
|
-
let projection: JsonMap = this.getMongoFieldsOptions(options.fields);
|
|
133
|
-
let sort: JsonMap = this.getMongoSortOptions(options.sort);
|
|
134
|
-
if (!_.isEmpty(projection)) {
|
|
135
|
-
result.push({ $project: projection });
|
|
136
|
-
}
|
|
137
|
-
if (!_.isEmpty(sort)) {
|
|
138
|
-
result.push({ $sort: sort });
|
|
139
|
-
}
|
|
140
|
-
if (options.skip) {
|
|
141
|
-
result.push({ $skip: options.skip });
|
|
142
|
-
}
|
|
143
|
-
if (options.top) {
|
|
144
|
-
result.push({ $limit: options.top });
|
|
145
|
-
}
|
|
146
|
-
return result;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
getAggregateSortOption(options: SteedosQueryOptions): any {
|
|
150
|
-
if (_.isUndefined(options)) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
let sort: JsonMap = this.getMongoSortOptions(options.sort);
|
|
154
|
-
if (!_.isEmpty(sort)) {
|
|
155
|
-
return { $sort: sort };
|
|
156
|
-
}
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
getAggregateProjectionOption(options: SteedosQueryOptions): any {
|
|
161
|
-
if (_.isUndefined(options)) {
|
|
162
|
-
return [];
|
|
163
|
-
}
|
|
164
|
-
let projection: JsonMap = this.getMongoFieldsOptions(options.fields);
|
|
165
|
-
if (!_.isEmpty(projection)) {
|
|
166
|
-
return { $project: projection };
|
|
167
|
-
}
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
getAggregateSkipLimitOptions(options: SteedosQueryOptions): any {
|
|
172
|
-
if (_.isUndefined(options)) {
|
|
173
|
-
return [];
|
|
174
|
-
}
|
|
175
|
-
let result = [];
|
|
176
|
-
if (options.skip) {
|
|
177
|
-
result.push({ $skip: options.skip });
|
|
178
|
-
}
|
|
179
|
-
if (options.top) {
|
|
180
|
-
result.push({ $limit: options.top });
|
|
181
|
-
}
|
|
182
|
-
return result;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
collection(name: string) {
|
|
186
|
-
return Creator.Collections[name];
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
async find(tableName: string, query: SteedosQueryOptions, userId?: SteedosIDType) {
|
|
190
|
-
let collection = this.collection(tableName);
|
|
191
|
-
|
|
192
|
-
let mongoFilters = this.getMongoFilters(query.filters);
|
|
193
|
-
let mongoOptions = this.getMongoOptions(query);
|
|
194
|
-
|
|
195
|
-
return await new Promise((resolve, reject) => {
|
|
196
|
-
Fiber(function () {
|
|
197
|
-
try {
|
|
198
|
-
let invocation = new DDPCommon.MethodInvocation({
|
|
199
|
-
isSimulation: true,
|
|
200
|
-
userId: userId,
|
|
201
|
-
connection: null,
|
|
202
|
-
randomSeed: DDPCommon.makeRpcSeed()
|
|
203
|
-
})
|
|
204
|
-
let result = DDP._CurrentInvocation.withValue(invocation, function () {
|
|
205
|
-
return collection.find(mongoFilters, mongoOptions).fetch();
|
|
206
|
-
})
|
|
207
|
-
resolve(result);
|
|
208
|
-
} catch (error) {
|
|
209
|
-
reject(error)
|
|
210
|
-
}
|
|
211
|
-
}).run()
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
async aggregate(tableName: string, query: SteedosQueryOptions, externalPipeline: any[], userId?: SteedosIDType) {
|
|
216
|
-
let collection = this.collection(tableName);
|
|
217
|
-
let rawCollection = collection.rawCollection();
|
|
218
|
-
let pipeline = [];
|
|
219
|
-
|
|
220
|
-
let mongoFilters = this.getMongoFilters(query.filters);
|
|
221
|
-
let sortOption = this.getAggregateSortOption(query);
|
|
222
|
-
if (sortOption) {
|
|
223
|
-
pipeline.push(sortOption);
|
|
224
|
-
}
|
|
225
|
-
pipeline.push({ $match: mongoFilters });
|
|
226
|
-
let skipLimitOptions = this.getAggregateSkipLimitOptions(query);
|
|
227
|
-
if (!_.isEmpty(skipLimitOptions)) {
|
|
228
|
-
pipeline = pipeline.concat(skipLimitOptions);
|
|
229
|
-
}
|
|
230
|
-
let projectionOption = this.getAggregateProjectionOption(query);
|
|
231
|
-
if (projectionOption) {
|
|
232
|
-
pipeline.push(projectionOption);
|
|
233
|
-
}
|
|
234
|
-
if (!_.isEmpty(externalPipeline)) {
|
|
235
|
-
pipeline = pipeline.concat(externalPipeline);
|
|
236
|
-
}
|
|
237
|
-
return await new Promise((resolve, reject) => {
|
|
238
|
-
Fiber(function () {
|
|
239
|
-
try {
|
|
240
|
-
rawCollection.aggregate(pipeline).toArray(function (err, data) {
|
|
241
|
-
if (err) {
|
|
242
|
-
reject(err);
|
|
243
|
-
}
|
|
244
|
-
resolve(data);
|
|
245
|
-
});
|
|
246
|
-
} catch (error) {
|
|
247
|
-
reject(error)
|
|
248
|
-
}
|
|
249
|
-
}).run()
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
async directAggregate(tableName: string, query: SteedosQueryOptions, externalPipeline: any[], userId?: SteedosIDType) {
|
|
254
|
-
let collection = this.collection(tableName);
|
|
255
|
-
let rawCollection = collection.rawCollection();
|
|
256
|
-
let pipeline = [];
|
|
257
|
-
|
|
258
|
-
let mongoFilters = this.getMongoFilters(query.filters);
|
|
259
|
-
let aggregateOptions = this.getAggregateOptions(query);
|
|
260
|
-
|
|
261
|
-
pipeline.push({ $match: mongoFilters });
|
|
262
|
-
|
|
263
|
-
pipeline = pipeline.concat(aggregateOptions).concat(externalPipeline);
|
|
264
|
-
|
|
265
|
-
return await new Promise((resolve, reject) => {
|
|
266
|
-
Fiber(function () {
|
|
267
|
-
try {
|
|
268
|
-
rawCollection.aggregate(pipeline).toArray(function (err, data) {
|
|
269
|
-
if (err) {
|
|
270
|
-
reject(err);
|
|
271
|
-
}
|
|
272
|
-
resolve(data);
|
|
273
|
-
});
|
|
274
|
-
} catch (error) {
|
|
275
|
-
reject(error)
|
|
276
|
-
}
|
|
277
|
-
}).run()
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
async directAggregatePrefixalPipeline(tableName: string, query: SteedosQueryOptions, prefixalPipeline: any[], userId?: SteedosIDType) {
|
|
282
|
-
let collection = this.collection(tableName);
|
|
283
|
-
let rawCollection = collection.rawCollection();
|
|
284
|
-
let pipeline = [];
|
|
285
|
-
|
|
286
|
-
let mongoFilters = this.getMongoFilters(query.filters);
|
|
287
|
-
let aggregateOptions = this.getAggregateOptions(query);
|
|
288
|
-
|
|
289
|
-
pipeline.push({ $match: mongoFilters });
|
|
290
|
-
|
|
291
|
-
// pipeline中的次序不能错,一定要先$lookup,再$match,再$project、$sort、$skip、$limit等,否则查询结果可能为空,比如公式字段中就用到了$lookup
|
|
292
|
-
pipeline = prefixalPipeline.concat(pipeline).concat(aggregateOptions);
|
|
293
|
-
|
|
294
|
-
return await new Promise((resolve, reject) => {
|
|
295
|
-
Fiber(function () {
|
|
296
|
-
try {
|
|
297
|
-
rawCollection.aggregate(pipeline).toArray(function (err, data) {
|
|
298
|
-
if (err) {
|
|
299
|
-
reject(err);
|
|
300
|
-
}
|
|
301
|
-
resolve(data);
|
|
302
|
-
});
|
|
303
|
-
} catch (error) {
|
|
304
|
-
reject(error)
|
|
305
|
-
}
|
|
306
|
-
}).run()
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
async count(tableName: string, query: SteedosQueryOptions, userId?: SteedosIDType) {
|
|
311
|
-
let collection = this.collection(tableName);
|
|
312
|
-
let mongoFilters = this.getMongoFilters(query.filters);
|
|
313
|
-
let mongoOptions = this.getMongoOptions(query);
|
|
314
|
-
return await new Promise((resolve, reject) => {
|
|
315
|
-
Fiber(function () {
|
|
316
|
-
try {
|
|
317
|
-
let invocation = new DDPCommon.MethodInvocation({
|
|
318
|
-
isSimulation: true,
|
|
319
|
-
userId: userId,
|
|
320
|
-
connection: null,
|
|
321
|
-
randomSeed: DDPCommon.makeRpcSeed()
|
|
322
|
-
})
|
|
323
|
-
let result = DDP._CurrentInvocation.withValue(invocation, function () {
|
|
324
|
-
return collection.find(mongoFilters, mongoOptions).count();
|
|
325
|
-
})
|
|
326
|
-
resolve(result);
|
|
327
|
-
} catch (error) {
|
|
328
|
-
reject(error)
|
|
329
|
-
}
|
|
330
|
-
}).run()
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
async findOne(tableName: string, id: SteedosIDType, query: SteedosQueryOptions, userId?: SteedosIDType) {
|
|
335
|
-
let collection = this.collection(tableName);
|
|
336
|
-
let mongoFilters = this.getMongoFilters(query.filters);
|
|
337
|
-
let mongoOptions = this.getMongoOptions(query);
|
|
338
|
-
let self = this;
|
|
339
|
-
return await new Promise((resolve, reject) => {
|
|
340
|
-
Fiber(function () {
|
|
341
|
-
try {
|
|
342
|
-
let invocation = new DDPCommon.MethodInvocation({
|
|
343
|
-
isSimulation: true,
|
|
344
|
-
userId: userId,
|
|
345
|
-
connection: null,
|
|
346
|
-
randomSeed: DDPCommon.makeRpcSeed()
|
|
347
|
-
})
|
|
348
|
-
let result = DDP._CurrentInvocation.withValue(invocation, function () {
|
|
349
|
-
let selector: any = { _id: id };
|
|
350
|
-
if (_.isObject(id)) {
|
|
351
|
-
selector = self.getMongoFilters(id['filters']);
|
|
352
|
-
}
|
|
353
|
-
if (!_.isEmpty(mongoFilters)) {
|
|
354
|
-
selector = Object.assign(mongoFilters, selector);
|
|
355
|
-
}
|
|
356
|
-
return collection.findOne(selector, mongoOptions);
|
|
357
|
-
})
|
|
358
|
-
resolve(result);
|
|
359
|
-
} catch (error) {
|
|
360
|
-
reject(error)
|
|
361
|
-
}
|
|
362
|
-
}).run()
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
async insert(tableName: string, data: Dictionary<any>, userId?: SteedosIDType) {
|
|
367
|
-
let collection = this.collection(tableName);
|
|
368
|
-
return await new Promise((resolve, reject) => {
|
|
369
|
-
Fiber(function () {
|
|
370
|
-
try {
|
|
371
|
-
data._id = data._id || collection._makeNewID();
|
|
372
|
-
|
|
373
|
-
let invocation = new DDPCommon.MethodInvocation({
|
|
374
|
-
isSimulation: true,
|
|
375
|
-
userId: userId,
|
|
376
|
-
connection: null,
|
|
377
|
-
randomSeed: DDPCommon.makeRpcSeed()
|
|
378
|
-
})
|
|
379
|
-
let result = DDP._CurrentInvocation.withValue(invocation, function () {
|
|
380
|
-
let recordId = collection.insert(data, { validate: false });
|
|
381
|
-
return collection.findOne({ _id: recordId });
|
|
382
|
-
})
|
|
383
|
-
resolve(result);
|
|
384
|
-
} catch (error) {
|
|
385
|
-
reject(error)
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
}).run()
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
async update(tableName: string, id: SteedosIDType | SteedosQueryOptions, data: Dictionary<any>, userId?: SteedosIDType) {
|
|
393
|
-
let collection = this.collection(tableName);
|
|
394
|
-
let selector;
|
|
395
|
-
if (_.isObject(id)) {
|
|
396
|
-
selector = this.getMongoFilters(id['filters']);
|
|
397
|
-
} else {
|
|
398
|
-
selector = { _id: id };
|
|
399
|
-
}
|
|
400
|
-
return await new Promise((resolve, reject) => {
|
|
401
|
-
Fiber(function () {
|
|
402
|
-
try {
|
|
403
|
-
let invocation = new DDPCommon.MethodInvocation({
|
|
404
|
-
isSimulation: true,
|
|
405
|
-
userId: userId,
|
|
406
|
-
connection: null,
|
|
407
|
-
randomSeed: DDPCommon.makeRpcSeed()
|
|
408
|
-
})
|
|
409
|
-
|
|
410
|
-
const options = { $set: {} };
|
|
411
|
-
const keys = _.keys(data);
|
|
412
|
-
_.each(keys, function (key) {
|
|
413
|
-
if (_.include(['$inc', '$min', '$max', '$mul'], key)) {
|
|
414
|
-
options[key] = data[key];
|
|
415
|
-
} else {
|
|
416
|
-
options.$set[key] = data[key];
|
|
417
|
-
}
|
|
418
|
-
})
|
|
419
|
-
|
|
420
|
-
let result = DDP._CurrentInvocation.withValue(invocation, function () {
|
|
421
|
-
collection.update(selector, options, { validate: false });
|
|
422
|
-
return collection.findOne(selector);
|
|
423
|
-
})
|
|
424
|
-
resolve(result);
|
|
425
|
-
} catch (error) {
|
|
426
|
-
reject(error)
|
|
427
|
-
}
|
|
428
|
-
}).run()
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
async updateOne(tableName: string, id: SteedosIDType | SteedosQueryOptions, data: Dictionary<any>, userId?: SteedosIDType) {
|
|
433
|
-
let collection = this.collection(tableName);
|
|
434
|
-
let selector;
|
|
435
|
-
if (_.isObject(id)) {
|
|
436
|
-
selector = this.getMongoFilters(id['filters']);
|
|
437
|
-
} else {
|
|
438
|
-
selector = { _id: id };
|
|
439
|
-
}
|
|
440
|
-
return await new Promise((resolve, reject) => {
|
|
441
|
-
Fiber(function () {
|
|
442
|
-
try {
|
|
443
|
-
let invocation = new DDPCommon.MethodInvocation({
|
|
444
|
-
isSimulation: true,
|
|
445
|
-
userId: userId,
|
|
446
|
-
connection: null,
|
|
447
|
-
randomSeed: DDPCommon.makeRpcSeed()
|
|
448
|
-
})
|
|
449
|
-
let result = DDP._CurrentInvocation.withValue(invocation, function () {
|
|
450
|
-
collection.update(selector, { $set: data });
|
|
451
|
-
return collection.findOne(selector);
|
|
452
|
-
})
|
|
453
|
-
resolve(result);
|
|
454
|
-
} catch (error) {
|
|
455
|
-
reject(error)
|
|
456
|
-
}
|
|
457
|
-
}).run()
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
async updateMany(tableName: string, queryFilters: SteedosQueryFilters, data: Dictionary<any>, userId?: SteedosIDType) {
|
|
462
|
-
let collection = this.collection(tableName);
|
|
463
|
-
let mongoFilters = this.getMongoFilters(queryFilters);
|
|
464
|
-
return await new Promise((resolve, reject) => {
|
|
465
|
-
Fiber(function () {
|
|
466
|
-
try {
|
|
467
|
-
let invocation = new DDPCommon.MethodInvocation({
|
|
468
|
-
isSimulation: true,
|
|
469
|
-
userId: userId,
|
|
470
|
-
connection: null,
|
|
471
|
-
randomSeed: DDPCommon.makeRpcSeed()
|
|
472
|
-
})
|
|
473
|
-
let result = DDP._CurrentInvocation.withValue(invocation, function () {
|
|
474
|
-
return collection.update(mongoFilters, { $set: data }, { multi: true });
|
|
475
|
-
})
|
|
476
|
-
resolve(result);
|
|
477
|
-
} catch (error) {
|
|
478
|
-
reject(error)
|
|
479
|
-
}
|
|
480
|
-
}).run()
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
async delete(tableName: string, id: SteedosIDType | SteedosQueryOptions, userId?: SteedosIDType) {
|
|
485
|
-
let collection = this.collection(tableName);
|
|
486
|
-
let selector;
|
|
487
|
-
if (_.isObject(id)) {
|
|
488
|
-
selector = this.getMongoFilters(id['filters']);
|
|
489
|
-
} else {
|
|
490
|
-
selector = { _id: id };
|
|
491
|
-
}
|
|
492
|
-
return await new Promise((resolve, reject) => {
|
|
493
|
-
Fiber(function () {
|
|
494
|
-
try {
|
|
495
|
-
let invocation = new DDPCommon.MethodInvocation({
|
|
496
|
-
isSimulation: true,
|
|
497
|
-
userId: userId,
|
|
498
|
-
connection: null,
|
|
499
|
-
randomSeed: DDPCommon.makeRpcSeed()
|
|
500
|
-
})
|
|
501
|
-
let result = DDP._CurrentInvocation.withValue(invocation, function () {
|
|
502
|
-
return collection.remove(selector);
|
|
503
|
-
})
|
|
504
|
-
resolve(result);
|
|
505
|
-
} catch (error) {
|
|
506
|
-
reject(error)
|
|
507
|
-
}
|
|
508
|
-
}).run()
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
async directFind(tableName: string, query: SteedosQueryOptions, userId?: SteedosIDType) {
|
|
513
|
-
let collection = this.collection(tableName);
|
|
514
|
-
|
|
515
|
-
let mongoFilters = this.getMongoFilters(query.filters);
|
|
516
|
-
let mongoOptions = this.getMongoOptions(query);
|
|
517
|
-
|
|
518
|
-
return await new Promise((resolve, reject) => {
|
|
519
|
-
Fiber(function () {
|
|
520
|
-
try {
|
|
521
|
-
let invocation = new DDPCommon.MethodInvocation({
|
|
522
|
-
isSimulation: true,
|
|
523
|
-
userId: userId,
|
|
524
|
-
connection: null,
|
|
525
|
-
randomSeed: DDPCommon.makeRpcSeed()
|
|
526
|
-
})
|
|
527
|
-
let result = DDP._CurrentInvocation.withValue(invocation, function () {
|
|
528
|
-
return collection.direct.find(mongoFilters, mongoOptions).fetch();
|
|
529
|
-
})
|
|
530
|
-
resolve(result);
|
|
531
|
-
} catch (error) {
|
|
532
|
-
reject(error)
|
|
533
|
-
}
|
|
534
|
-
}).run()
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
async directUpdate(tableName: string, id: SteedosIDType | SteedosQueryOptions, data: Dictionary<any>, userId?: SteedosIDType) {
|
|
539
|
-
let collection = this.collection(tableName);
|
|
540
|
-
let selector;
|
|
541
|
-
if (_.isObject(id)) {
|
|
542
|
-
selector = this.getMongoFilters(id['filters']);
|
|
543
|
-
} else {
|
|
544
|
-
selector = { _id: id };
|
|
545
|
-
}
|
|
546
|
-
return await new Promise((resolve, reject) => {
|
|
547
|
-
Fiber(function () {
|
|
548
|
-
try {
|
|
549
|
-
let invocation = new DDPCommon.MethodInvocation({
|
|
550
|
-
isSimulation: true,
|
|
551
|
-
userId: userId,
|
|
552
|
-
connection: null,
|
|
553
|
-
randomSeed: DDPCommon.makeRpcSeed()
|
|
554
|
-
})
|
|
555
|
-
|
|
556
|
-
const options = { $set: {} };
|
|
557
|
-
const keys = _.keys(data);
|
|
558
|
-
_.each(keys, function (key) {
|
|
559
|
-
if (_.include(['$inc', '$min', '$max', '$mul'], key)) {
|
|
560
|
-
options[key] = data[key];
|
|
561
|
-
} else {
|
|
562
|
-
options.$set[key] = data[key];
|
|
563
|
-
}
|
|
564
|
-
})
|
|
565
|
-
|
|
566
|
-
let result = DDP._CurrentInvocation.withValue(invocation, function () {
|
|
567
|
-
collection.direct.update(selector, options);
|
|
568
|
-
return collection.findOne(selector);
|
|
569
|
-
})
|
|
570
|
-
resolve(result);
|
|
571
|
-
} catch (error) {
|
|
572
|
-
reject(error)
|
|
573
|
-
}
|
|
574
|
-
}).run()
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
async directInsert(tableName: string, data: Dictionary<any>, userId?: SteedosIDType) {
|
|
579
|
-
let collection = this.collection(tableName);
|
|
580
|
-
return await new Promise((resolve, reject) => {
|
|
581
|
-
Fiber(function () {
|
|
582
|
-
try {
|
|
583
|
-
data._id = data._id || collection._makeNewID();
|
|
584
|
-
|
|
585
|
-
let invocation = new DDPCommon.MethodInvocation({
|
|
586
|
-
isSimulation: true,
|
|
587
|
-
userId: userId,
|
|
588
|
-
connection: null,
|
|
589
|
-
randomSeed: DDPCommon.makeRpcSeed()
|
|
590
|
-
})
|
|
591
|
-
let result = DDP._CurrentInvocation.withValue(invocation, function () {
|
|
592
|
-
let recordId = collection.direct.insert(data);
|
|
593
|
-
return collection.findOne({ _id: recordId });
|
|
594
|
-
})
|
|
595
|
-
resolve(result);
|
|
596
|
-
} catch (error) {
|
|
597
|
-
reject(error)
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
}).run()
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
async directDelete(tableName: string, id: SteedosIDType | SteedosQueryOptions, userId?: SteedosIDType) {
|
|
605
|
-
let collection = this.collection(tableName);
|
|
606
|
-
let selector;
|
|
607
|
-
if (_.isObject(id)) {
|
|
608
|
-
selector = this.getMongoFilters(id['filters']);
|
|
609
|
-
} else {
|
|
610
|
-
selector = { _id: id };
|
|
611
|
-
}
|
|
612
|
-
return await new Promise((resolve, reject) => {
|
|
613
|
-
Fiber(function () {
|
|
614
|
-
try {
|
|
615
|
-
let invocation = new DDPCommon.MethodInvocation({
|
|
616
|
-
isSimulation: true,
|
|
617
|
-
userId: userId,
|
|
618
|
-
connection: null,
|
|
619
|
-
randomSeed: DDPCommon.makeRpcSeed()
|
|
620
|
-
})
|
|
621
|
-
let result = DDP._CurrentInvocation.withValue(invocation, function () {
|
|
622
|
-
return collection.direct.remove(selector);
|
|
623
|
-
})
|
|
624
|
-
resolve(result);
|
|
625
|
-
} catch (error) {
|
|
626
|
-
reject(error)
|
|
627
|
-
}
|
|
628
|
-
}).run()
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
_makeNewID(tableName?: string) {
|
|
633
|
-
return new ObjectId().toHexString();
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
formatRecord(doc: Dictionary<any>, objectConfig: SteedosObjectType){
|
|
637
|
-
return formatRecord(doc, objectConfig);
|
|
638
|
-
}
|
|
639
|
-
}
|