@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
package/src/driver/mongo.ts
DELETED
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
import { JsonMap, Dictionary } from "@salesforce/ts-types";
|
|
2
|
-
import { SteedosDriver, SteedosFieldDBType } from "./index"
|
|
3
|
-
import { MongoClient, ObjectId } from "mongodb";
|
|
4
|
-
import { SteedosQueryOptions, SteedosQueryFilters } from "../types/query";
|
|
5
|
-
import { SteedosIDType, SteedosObjectType } from "../types";
|
|
6
|
-
import { SteedosDriverConfig } from "./driver";
|
|
7
|
-
import { formatFiltersToODataQuery } from "@steedos/filters";
|
|
8
|
-
import { createFilter, createQuery } from 'odata-v4-mongodb';
|
|
9
|
-
import _ = require("underscore");
|
|
10
|
-
import { wrapAsync } from '../util';
|
|
11
|
-
import { SteedosFieldEncryptionSharedConsts } from './field-encrytion';
|
|
12
|
-
import { formatRecord } from './format';
|
|
13
|
-
|
|
14
|
-
export class SteedosMongoDriver implements SteedosDriver {
|
|
15
|
-
_url: string;
|
|
16
|
-
_client: any;
|
|
17
|
-
_config: SteedosDriverConfig;
|
|
18
|
-
_collections: Dictionary<any>;
|
|
19
|
-
_encryption: any;
|
|
20
|
-
|
|
21
|
-
constructor(config: SteedosDriverConfig) {
|
|
22
|
-
this._collections = {};
|
|
23
|
-
this._config = config;
|
|
24
|
-
this._url = this.buildConnectionUrl();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Builds connection url that is passed to underlying driver to perform connection to the mongodb database.
|
|
29
|
-
*/
|
|
30
|
-
protected buildConnectionUrl(): string {
|
|
31
|
-
if (this._config.url)
|
|
32
|
-
return this._config.url;
|
|
33
|
-
|
|
34
|
-
const credentialsUrlPart = (this._config.username && this._config.password)
|
|
35
|
-
? `${this._config.username}:${this._config.password}@`
|
|
36
|
-
: "";
|
|
37
|
-
if (!this._config.database) {
|
|
38
|
-
throw new Error('Not find database');
|
|
39
|
-
}
|
|
40
|
-
return `mongodb://${credentialsUrlPart}${this._config.host || "127.0.0.1"}:${this._config.port || "27017"}/${this._config.database}`;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async init() {
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getSupportedColumnTypes() {
|
|
48
|
-
return [
|
|
49
|
-
SteedosFieldDBType.varchar,
|
|
50
|
-
SteedosFieldDBType.text,
|
|
51
|
-
SteedosFieldDBType.number,
|
|
52
|
-
SteedosFieldDBType.boolean,
|
|
53
|
-
SteedosFieldDBType.date,
|
|
54
|
-
SteedosFieldDBType.dateTime,
|
|
55
|
-
SteedosFieldDBType.json,
|
|
56
|
-
SteedosFieldDBType.array
|
|
57
|
-
]
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async encryptValue(value: any) {
|
|
61
|
-
if (this._encryption) {
|
|
62
|
-
const { altKeyName } = SteedosFieldEncryptionSharedConsts;
|
|
63
|
-
const encryption = this._encryption;
|
|
64
|
-
let encryptValue = await encryption.encrypt(
|
|
65
|
-
value,
|
|
66
|
-
{
|
|
67
|
-
keyAltName: altKeyName,
|
|
68
|
-
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic'
|
|
69
|
-
}
|
|
70
|
-
)
|
|
71
|
-
return encryptValue;
|
|
72
|
-
}
|
|
73
|
-
return value;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async connect() {
|
|
77
|
-
if (!this._client) {
|
|
78
|
-
if (process.env.STEEDOS_CSFLE_MASTER_KEY) {
|
|
79
|
-
const { ClientEncryption } = require("mongodb-client-encryption");
|
|
80
|
-
const { keyVaultNamespace, getKMSProviders } = SteedosFieldEncryptionSharedConsts;
|
|
81
|
-
const kmsProvider = await getKMSProviders();
|
|
82
|
-
this._client = await MongoClient.connect(this._url, {
|
|
83
|
-
useNewUrlParser: true,
|
|
84
|
-
useUnifiedTopology: true,
|
|
85
|
-
monitorCommands: true,
|
|
86
|
-
autoEncryption: {
|
|
87
|
-
keyVaultNamespace: keyVaultNamespace,
|
|
88
|
-
kmsProviders: kmsProvider,
|
|
89
|
-
bypassAutoEncryption: true,
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
this._encryption = new ClientEncryption(this._client, {
|
|
93
|
-
keyVaultNamespace: keyVaultNamespace,
|
|
94
|
-
kmsProviders: kmsProvider,
|
|
95
|
-
});
|
|
96
|
-
} else {
|
|
97
|
-
this._client = await MongoClient.connect(this._url, { useNewUrlParser: true, useUnifiedTopology: true });
|
|
98
|
-
}
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async close() {
|
|
104
|
-
if (this._client) {
|
|
105
|
-
await this._client.close();
|
|
106
|
-
this._client = null;
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
formatFiltersToMongoQuery(filters: any): JsonMap {
|
|
112
|
-
let emptyFilters = {};
|
|
113
|
-
let odataQuery: string = "";
|
|
114
|
-
if (_.isString(filters)) {
|
|
115
|
-
odataQuery = filters;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
odataQuery = formatFiltersToODataQuery(filters)
|
|
119
|
-
}
|
|
120
|
-
if(!odataQuery){
|
|
121
|
-
return emptyFilters;
|
|
122
|
-
}
|
|
123
|
-
let query: JsonMap = createFilter(odataQuery);
|
|
124
|
-
return query;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
getMongoFilters(filters: SteedosQueryFilters): JsonMap {
|
|
128
|
-
let emptyFilters = {};
|
|
129
|
-
if (_.isUndefined(filters)) {
|
|
130
|
-
return emptyFilters;
|
|
131
|
-
}
|
|
132
|
-
if (_.isString(filters) && !filters.length) {
|
|
133
|
-
return emptyFilters
|
|
134
|
-
}
|
|
135
|
-
if (_.isArray(filters) && !filters.length) {
|
|
136
|
-
return emptyFilters
|
|
137
|
-
}
|
|
138
|
-
let mongoFilters: JsonMap = this.formatFiltersToMongoQuery(filters);
|
|
139
|
-
return mongoFilters
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
getMongoFieldsOptions(fields: string[] | string): JsonMap {
|
|
143
|
-
if (typeof fields == "string") {
|
|
144
|
-
fields = (<string>fields).split(",").map((n) => { return n.trim(); });
|
|
145
|
-
}
|
|
146
|
-
if (!(fields && fields.length)) {
|
|
147
|
-
// throw new Error("fields must not be undefined or empty");
|
|
148
|
-
return {}
|
|
149
|
-
}
|
|
150
|
-
let projection: JsonMap = {};
|
|
151
|
-
(<string[]>fields).forEach((field) => {
|
|
152
|
-
if (field) {
|
|
153
|
-
projection[field] = 1;
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
return projection;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
getMongoSortOptions(sort: string): JsonMap {
|
|
160
|
-
let result: JsonMap = undefined;
|
|
161
|
-
if (sort && typeof sort === "string") {
|
|
162
|
-
let arraySort: string[] = sort.split(",").map((n) => { return n.trim(); });
|
|
163
|
-
let stringSort: string = "";
|
|
164
|
-
arraySort.forEach((n) => {
|
|
165
|
-
if (n) {
|
|
166
|
-
stringSort += `${n},`
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
stringSort = stringSort.replace(/,$/g, "");
|
|
170
|
-
result = createQuery(`$orderby=${stringSort}`).sort;
|
|
171
|
-
}
|
|
172
|
-
return result;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
getMongoOptions(options: SteedosQueryOptions): JsonMap {
|
|
176
|
-
if (_.isUndefined(options)) {
|
|
177
|
-
return {};
|
|
178
|
-
}
|
|
179
|
-
let result: JsonMap = {};
|
|
180
|
-
let projection: JsonMap = this.getMongoFieldsOptions(options.fields);
|
|
181
|
-
let sort: JsonMap = this.getMongoSortOptions(options.sort);
|
|
182
|
-
result.projection = projection;
|
|
183
|
-
result.sort = sort;
|
|
184
|
-
result.limit = options.top;
|
|
185
|
-
result.skip = options.skip;
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
getAggregateOptions(options: SteedosQueryOptions): any[] {
|
|
190
|
-
if (_.isUndefined(options)) {
|
|
191
|
-
return [];
|
|
192
|
-
}
|
|
193
|
-
let result = [];
|
|
194
|
-
let projection: JsonMap = this.getMongoFieldsOptions(options.fields);
|
|
195
|
-
let sort: JsonMap = this.getMongoSortOptions(options.sort);
|
|
196
|
-
if (!_.isEmpty(projection)) {
|
|
197
|
-
result.push({ $project: projection });
|
|
198
|
-
}
|
|
199
|
-
if (!_.isEmpty(sort)) {
|
|
200
|
-
result.push({ $sort: sort });
|
|
201
|
-
}
|
|
202
|
-
if (options.skip) {
|
|
203
|
-
result.push({ $skip: options.skip });
|
|
204
|
-
}
|
|
205
|
-
if (options.top) {
|
|
206
|
-
result.push({ $limit: options.top });
|
|
207
|
-
}
|
|
208
|
-
return result;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
collection(name: string) {
|
|
212
|
-
if (!this._collections[name]) {
|
|
213
|
-
let db = this._client.db();
|
|
214
|
-
let locale = this._config.locale;
|
|
215
|
-
if (locale) {
|
|
216
|
-
wrapAsync(function () {
|
|
217
|
-
return db.createCollection(name, {
|
|
218
|
-
'collation': { 'locale': locale }
|
|
219
|
-
})
|
|
220
|
-
}, {})
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
this._collections[name] = db.collection(name);
|
|
224
|
-
}
|
|
225
|
-
return this._collections[name];
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
async find(tableName: string, query: SteedosQueryOptions) {
|
|
229
|
-
await this.connect();
|
|
230
|
-
let collection = this.collection(tableName);
|
|
231
|
-
|
|
232
|
-
let mongoFilters = this.getMongoFilters(query.filters);
|
|
233
|
-
let mongoOptions = this.getMongoOptions(query);
|
|
234
|
-
let result = await collection.find(mongoFilters, mongoOptions).toArray();
|
|
235
|
-
|
|
236
|
-
return result;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
async aggregate(tableName: string, query: SteedosQueryOptions, externalPipeline: any[]) {
|
|
240
|
-
await this.connect();
|
|
241
|
-
let collection = this.collection(tableName);
|
|
242
|
-
let pipeline = [];
|
|
243
|
-
|
|
244
|
-
let mongoFilters = this.getMongoFilters(query.filters);
|
|
245
|
-
let aggregateOptions = this.getAggregateOptions(query);
|
|
246
|
-
|
|
247
|
-
pipeline.push({ $match: mongoFilters });
|
|
248
|
-
|
|
249
|
-
pipeline = pipeline.concat(aggregateOptions).concat(externalPipeline);
|
|
250
|
-
|
|
251
|
-
let result = await collection.aggregate(pipeline).toArray();
|
|
252
|
-
|
|
253
|
-
return result;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
async directAggregate(tableName: string, query: SteedosQueryOptions, externalPipeline: any[], userId?: SteedosIDType) {
|
|
257
|
-
let collection = this.collection(tableName);
|
|
258
|
-
let pipeline = [];
|
|
259
|
-
if(query.filters){
|
|
260
|
-
let mongoFilters = this.getMongoFilters(query.filters);
|
|
261
|
-
let aggregateOptions = this.getAggregateOptions(query);
|
|
262
|
-
pipeline.push({ $match: mongoFilters });
|
|
263
|
-
pipeline = pipeline.concat(aggregateOptions)
|
|
264
|
-
}
|
|
265
|
-
pipeline = pipeline.concat(externalPipeline);
|
|
266
|
-
let result = await collection.aggregate(pipeline).toArray();
|
|
267
|
-
return result;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
async directAggregatePrefixalPipeline(tableName: string, query: SteedosQueryOptions, prefixalPipeline: any[], userId?: SteedosIDType) {
|
|
271
|
-
let collection = this.collection(tableName);
|
|
272
|
-
let pipeline = [];
|
|
273
|
-
|
|
274
|
-
let mongoFilters = this.getMongoFilters(query.filters);
|
|
275
|
-
let aggregateOptions = this.getAggregateOptions(query);
|
|
276
|
-
|
|
277
|
-
pipeline.push({ $match: mongoFilters });
|
|
278
|
-
|
|
279
|
-
// pipeline中的次序不能错,一定要先$lookup,再$match,再$project、$sort、$skip、$limit等,否则查询结果可能为空,比如公式字段中就用到了$lookup
|
|
280
|
-
pipeline = prefixalPipeline.concat(pipeline).concat(aggregateOptions);
|
|
281
|
-
|
|
282
|
-
let result = await collection.aggregate(pipeline).toArray();
|
|
283
|
-
return result;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
async count(tableName: string, query: SteedosQueryOptions) {
|
|
287
|
-
await this.connect();
|
|
288
|
-
let collection = this.collection(tableName);
|
|
289
|
-
|
|
290
|
-
let mongoFilters = this.getMongoFilters(query.filters);
|
|
291
|
-
let mongoOptions = this.getMongoOptions(query);
|
|
292
|
-
let result = await collection.find(mongoFilters, mongoOptions).count();
|
|
293
|
-
|
|
294
|
-
return result;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
async findOne(tableName: string, id: SteedosIDType | SteedosQueryOptions, query: SteedosQueryOptions) {
|
|
298
|
-
await this.connect();
|
|
299
|
-
let collection = this.collection(tableName);
|
|
300
|
-
let mongoOptions = this.getMongoOptions(query);
|
|
301
|
-
let mongoFilters = this.getMongoFilters(query.filters);
|
|
302
|
-
let selector: any = { _id: id };
|
|
303
|
-
if (_.isObject(id)) {
|
|
304
|
-
selector = this.getMongoFilters(id['filters']);
|
|
305
|
-
}
|
|
306
|
-
if (!_.isEmpty(mongoFilters)) {
|
|
307
|
-
selector = Object.assign(mongoFilters, selector);
|
|
308
|
-
}
|
|
309
|
-
let result = await collection.findOne(selector, mongoOptions);
|
|
310
|
-
|
|
311
|
-
return result;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
async insert(tableName: string, data: Dictionary<any>) {
|
|
315
|
-
await this.connect();
|
|
316
|
-
data._id = data._id || new ObjectId().toHexString();
|
|
317
|
-
let collection = this.collection(tableName);
|
|
318
|
-
let result = await collection.insertOne(data);
|
|
319
|
-
return result.ops[0];
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
async update(tableName: string, id: SteedosIDType | SteedosQueryOptions, data: Dictionary<any>) {
|
|
323
|
-
if (_.isEmpty(data)) {
|
|
324
|
-
throw new Error("the params 'data' must not be empty");
|
|
325
|
-
}
|
|
326
|
-
await this.connect();
|
|
327
|
-
let collection = this.collection(tableName);
|
|
328
|
-
let selector;
|
|
329
|
-
if (_.isObject(id)) {
|
|
330
|
-
selector = this.getMongoFilters(id['filters']);
|
|
331
|
-
} else {
|
|
332
|
-
selector = { _id: id };
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
const options = {$set: {}};
|
|
336
|
-
const keys = _.keys(data);
|
|
337
|
-
_.each(keys, function(key){
|
|
338
|
-
if(_.include(['$inc','$min','$max','$mul'], key)){
|
|
339
|
-
options[key] = data[key];
|
|
340
|
-
}else{
|
|
341
|
-
options.$set[key] = data[key];
|
|
342
|
-
}
|
|
343
|
-
})
|
|
344
|
-
let result = await collection.updateOne(selector, options);
|
|
345
|
-
if (result.result.ok) {
|
|
346
|
-
result = await collection.findOne(selector);
|
|
347
|
-
return result;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
async updateOne(tableName: string, id: SteedosIDType | SteedosQueryOptions, data: Dictionary<any>) {
|
|
352
|
-
if (_.isEmpty(data)) {
|
|
353
|
-
throw new Error("the params 'data' must not be empty");
|
|
354
|
-
}
|
|
355
|
-
await this.connect();
|
|
356
|
-
let collection = this.collection(tableName);
|
|
357
|
-
let selector;
|
|
358
|
-
if (_.isObject(id)) {
|
|
359
|
-
selector = this.getMongoFilters(id['filters']);
|
|
360
|
-
} else {
|
|
361
|
-
selector = { _id: id };
|
|
362
|
-
}
|
|
363
|
-
let result = await collection.updateOne(selector, { $set: data });
|
|
364
|
-
if (result.result.ok) {
|
|
365
|
-
result = await collection.findOne(selector);
|
|
366
|
-
return result;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
async updateMany(tableName: string, queryFilters: SteedosQueryFilters, data: Dictionary<any>) {
|
|
371
|
-
if (_.isEmpty(data)) {
|
|
372
|
-
throw new Error("the params 'data' must not be empty");
|
|
373
|
-
}
|
|
374
|
-
await this.connect();
|
|
375
|
-
let collection = this.collection(tableName);
|
|
376
|
-
let mongoFilters = this.getMongoFilters(queryFilters);
|
|
377
|
-
return await collection.update(mongoFilters, { $set: data }, { multi: true });
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
async delete(tableName: string, id: SteedosIDType | SteedosQueryOptions) {
|
|
381
|
-
await this.connect();
|
|
382
|
-
let collection = this.collection(tableName);
|
|
383
|
-
let selector;
|
|
384
|
-
if (_.isObject(id)) {
|
|
385
|
-
selector = this.getMongoFilters(id['filters']);
|
|
386
|
-
} else {
|
|
387
|
-
selector = { _id: id };
|
|
388
|
-
}
|
|
389
|
-
const result = await collection.deleteOne(selector);
|
|
390
|
-
return result?.deletedCount;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
async directFind(tableName: string, query: SteedosQueryOptions) {
|
|
394
|
-
return this.find(tableName, query)
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
async directInsert(tableName: string, data: Dictionary<any>) {
|
|
398
|
-
return this.insert(tableName, data)
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
async directUpdate(tableName: string, id: SteedosIDType | SteedosQueryOptions, data: Dictionary<any>) {
|
|
402
|
-
return this.update(tableName, id, data)
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
async directDelete(tableName: string, id: SteedosIDType | SteedosQueryOptions) {
|
|
406
|
-
return this.delete(tableName, id)
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
_makeNewID(tableName?: string){
|
|
410
|
-
return new ObjectId().toHexString();
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
formatRecord(doc: Dictionary<any>, objectConfig: SteedosObjectType){
|
|
414
|
-
return formatRecord(doc, objectConfig);
|
|
415
|
-
}
|
|
416
|
-
}
|
package/src/driver/mysql.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { SteedosFieldDBType } from "./index";
|
|
2
|
-
import { ConnectionOptions, EntitySchema } from "typeorm";
|
|
3
|
-
import { SteedosDriverConfig } from "./driver";
|
|
4
|
-
import { SteedosTypeormDriver } from "../typeorm";
|
|
5
|
-
import { Dictionary } from "@salesforce/ts-types";
|
|
6
|
-
import { SteedosObjectType } from "../types";
|
|
7
|
-
import { SQLLang } from 'odata-v4-sql';
|
|
8
|
-
import { getEntities } from "../typeorm";
|
|
9
|
-
|
|
10
|
-
export class SteedosMySqlDriver extends SteedosTypeormDriver {
|
|
11
|
-
getSupportedColumnTypes() {
|
|
12
|
-
return [
|
|
13
|
-
SteedosFieldDBType.varchar,
|
|
14
|
-
SteedosFieldDBType.text,
|
|
15
|
-
SteedosFieldDBType.number,
|
|
16
|
-
SteedosFieldDBType.boolean,
|
|
17
|
-
SteedosFieldDBType.date,
|
|
18
|
-
SteedosFieldDBType.dateTime
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
sqlLang: SQLLang = SQLLang.MySql;
|
|
23
|
-
|
|
24
|
-
constructor(config: SteedosDriverConfig) {
|
|
25
|
-
super(config);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getConnectionOptions(): ConnectionOptions {
|
|
29
|
-
return {
|
|
30
|
-
type: "mysql",
|
|
31
|
-
url: this._url,
|
|
32
|
-
name: (new Date()).getTime().toString(),
|
|
33
|
-
entities: Object.values(this._entities),
|
|
34
|
-
host: this.config.host,
|
|
35
|
-
port: this.config.port,
|
|
36
|
-
username: this.config.username,
|
|
37
|
-
password: this.config.password,
|
|
38
|
-
database: this.config.database,
|
|
39
|
-
timezone: this.config.timezone,
|
|
40
|
-
logging: this.config.logging
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getEntities(objects: Dictionary<SteedosObjectType>): Dictionary<EntitySchema> {
|
|
45
|
-
return getEntities(objects, "mssql");
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/driver/oracle.ts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { SteedosFieldDBType } from "./index";
|
|
2
|
-
import { ConnectionOptions, EntitySchema } from "typeorm";
|
|
3
|
-
import { SteedosDriverConfig } from "./driver";
|
|
4
|
-
import { SteedosTypeormDriver } from "../typeorm";
|
|
5
|
-
import { Dictionary } from "@salesforce/ts-types";
|
|
6
|
-
import { SteedosObjectType } from "../types";
|
|
7
|
-
import { SQLLang } from 'odata-v4-sql';
|
|
8
|
-
import { getEntities } from "../typeorm";
|
|
9
|
-
|
|
10
|
-
export class SteedosOracleDriver extends SteedosTypeormDriver {
|
|
11
|
-
getSupportedColumnTypes() {
|
|
12
|
-
return [
|
|
13
|
-
SteedosFieldDBType.varchar,
|
|
14
|
-
SteedosFieldDBType.text,
|
|
15
|
-
SteedosFieldDBType.number,
|
|
16
|
-
SteedosFieldDBType.boolean,
|
|
17
|
-
SteedosFieldDBType.date,
|
|
18
|
-
SteedosFieldDBType.dateTime
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
sqlLang: SQLLang = SQLLang.Oracle;
|
|
23
|
-
|
|
24
|
-
constructor(config: SteedosDriverConfig) {
|
|
25
|
-
super(config);
|
|
26
|
-
if (!process.env.ORA_SDTZ) {
|
|
27
|
-
// 设置日期/时间字段默认时区为UTC
|
|
28
|
-
process.env.ORA_SDTZ = 'UTC';
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
getConnectionOptions(): ConnectionOptions {
|
|
33
|
-
let connectString = this.config.connectString;
|
|
34
|
-
if (!connectString){
|
|
35
|
-
connectString = `${this.config.host}:${this.config.port}/${this.config.database}`;
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
type: "oracle",
|
|
39
|
-
url: this._url,
|
|
40
|
-
name: (new Date()).getTime().toString(),
|
|
41
|
-
entities: Object.values(this._entities),
|
|
42
|
-
host: this.config.host,
|
|
43
|
-
port: this.config.port,
|
|
44
|
-
username: this.config.username,
|
|
45
|
-
password: this.config.password,
|
|
46
|
-
database: this.config.database,
|
|
47
|
-
connectString: connectString,
|
|
48
|
-
logging: this.config.logging
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getEntities(objects: Dictionary<SteedosObjectType>): Dictionary<EntitySchema> {
|
|
53
|
-
return getEntities(objects, "oracle");
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async getDatabaseVersion() {
|
|
57
|
-
let result = await this.run(`select version from sys.product_component_version where product like '%Oracle%'`);
|
|
58
|
-
return result.length && result[0] && result[0].VERSION;
|
|
59
|
-
}
|
|
60
|
-
}
|
package/src/driver/postgres.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { SteedosFieldDBType } from "./index";
|
|
2
|
-
import { ConnectionOptions, EntitySchema } from "typeorm";
|
|
3
|
-
import { SteedosDriverConfig } from "./driver";
|
|
4
|
-
import { SteedosTypeormDriver } from "../typeorm";
|
|
5
|
-
import { Dictionary } from "@salesforce/ts-types";
|
|
6
|
-
import { SteedosObjectType } from "../types";
|
|
7
|
-
import { SQLLang } from 'odata-v4-sql';
|
|
8
|
-
import { getEntities } from "../typeorm";
|
|
9
|
-
|
|
10
|
-
export class SteedosPostgresDriver extends SteedosTypeormDriver {
|
|
11
|
-
getSupportedColumnTypes() {
|
|
12
|
-
return [
|
|
13
|
-
SteedosFieldDBType.varchar,
|
|
14
|
-
SteedosFieldDBType.text,
|
|
15
|
-
SteedosFieldDBType.number,
|
|
16
|
-
SteedosFieldDBType.boolean,
|
|
17
|
-
SteedosFieldDBType.date,
|
|
18
|
-
SteedosFieldDBType.dateTime
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
sqlLang: SQLLang = SQLLang.PostgreSql;
|
|
23
|
-
|
|
24
|
-
constructor(config: SteedosDriverConfig) {
|
|
25
|
-
super(config);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getConnectionOptions(): ConnectionOptions {
|
|
29
|
-
return {
|
|
30
|
-
type: "postgres",
|
|
31
|
-
url: this._url,
|
|
32
|
-
name: (new Date()).getTime().toString(),
|
|
33
|
-
entities: Object.values(this._entities),
|
|
34
|
-
host: this.config.host,
|
|
35
|
-
port: this.config.port,
|
|
36
|
-
username: this.config.username,
|
|
37
|
-
password: this.config.password,
|
|
38
|
-
database: this.config.database,
|
|
39
|
-
logging: this.config.logging
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
getEntities(objects: Dictionary<SteedosObjectType>): Dictionary<EntitySchema> {
|
|
44
|
-
return getEntities(objects, "postgres");
|
|
45
|
-
}
|
|
46
|
-
}
|
package/src/driver/sqlite3.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { SteedosFieldDBType } from "./index";
|
|
2
|
-
import { ConnectionOptions, EntitySchema } from "typeorm";
|
|
3
|
-
import { SteedosDriverConfig } from "./driver";
|
|
4
|
-
import { SteedosTypeormDriver, getEntities } from "../typeorm";
|
|
5
|
-
import { SQLLang } from 'odata-v4-sql';
|
|
6
|
-
import { Dictionary } from "@salesforce/ts-types";
|
|
7
|
-
import { SteedosObjectType } from "../types";
|
|
8
|
-
|
|
9
|
-
export class SteedosSqlite3Driver extends SteedosTypeormDriver {
|
|
10
|
-
getSupportedColumnTypes() {
|
|
11
|
-
return [
|
|
12
|
-
SteedosFieldDBType.varchar,
|
|
13
|
-
SteedosFieldDBType.text,
|
|
14
|
-
SteedosFieldDBType.number,
|
|
15
|
-
SteedosFieldDBType.boolean,
|
|
16
|
-
SteedosFieldDBType.date,
|
|
17
|
-
SteedosFieldDBType.dateTime
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
sqlLang: SQLLang = SQLLang.Oracle;
|
|
22
|
-
|
|
23
|
-
constructor(config: SteedosDriverConfig) {
|
|
24
|
-
super(config);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getConnectionOptions(): ConnectionOptions {
|
|
28
|
-
return {
|
|
29
|
-
type: "sqlite",
|
|
30
|
-
database: this._url,
|
|
31
|
-
name: (new Date()).getTime().toString(),
|
|
32
|
-
entities: Object.values(this._entities),
|
|
33
|
-
logging: this.config.logging
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
getEntities(objects: Dictionary<SteedosObjectType>): Dictionary<EntitySchema> {
|
|
38
|
-
return getEntities(objects, "sqlite");
|
|
39
|
-
}
|
|
40
|
-
}
|
package/src/driver/sqlserver.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { SteedosFieldDBType } from "./index";
|
|
2
|
-
import { ConnectionOptions, EntitySchema } from "typeorm";
|
|
3
|
-
import { SteedosDriverConfig } from "./driver";
|
|
4
|
-
import { SteedosTypeormDriver } from "../typeorm";
|
|
5
|
-
import { Dictionary } from "@salesforce/ts-types";
|
|
6
|
-
import { SteedosObjectType } from "../types";
|
|
7
|
-
import { SQLLang } from 'odata-v4-sql';
|
|
8
|
-
import { getEntities } from "../typeorm";
|
|
9
|
-
|
|
10
|
-
export class SteedosSqlServerDriver extends SteedosTypeormDriver {
|
|
11
|
-
getSupportedColumnTypes() {
|
|
12
|
-
return [
|
|
13
|
-
SteedosFieldDBType.varchar,
|
|
14
|
-
SteedosFieldDBType.text,
|
|
15
|
-
SteedosFieldDBType.number,
|
|
16
|
-
SteedosFieldDBType.boolean,
|
|
17
|
-
SteedosFieldDBType.date,
|
|
18
|
-
SteedosFieldDBType.dateTime
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
sqlLang: SQLLang = SQLLang.MsSql;
|
|
23
|
-
|
|
24
|
-
constructor(config: SteedosDriverConfig) {
|
|
25
|
-
super(config);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getConnectionOptions(): ConnectionOptions {
|
|
29
|
-
return {
|
|
30
|
-
type: "mssql",
|
|
31
|
-
url: this._url,
|
|
32
|
-
name: (new Date()).getTime().toString(),
|
|
33
|
-
entities: Object.values(this._entities),
|
|
34
|
-
host: this.config.host,
|
|
35
|
-
port: this.config.port,
|
|
36
|
-
username: this.config.username,
|
|
37
|
-
password: this.config.password,
|
|
38
|
-
database: this.config.database,
|
|
39
|
-
options: this.config.options,
|
|
40
|
-
logging: this.config.logging
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getEntities(objects: Dictionary<SteedosObjectType>): Dictionary<EntitySchema> {
|
|
45
|
-
return getEntities(objects, "mssql");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async getDatabaseVersion() {
|
|
49
|
-
let result = await this.run(`SELECT SERVERPROPERTY('ProductVersion') AS VERSION`);
|
|
50
|
-
return result.length && result[0] && result[0].VERSION;
|
|
51
|
-
}
|
|
52
|
-
}
|