@steedos/objectql 2.2.34 → 2.2.37
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/driver/driver.d.ts +1 -0
- package/lib/driver/format.d.ts +15 -0
- package/lib/driver/format.js +31 -0
- package/lib/driver/format.js.map +1 -0
- package/lib/driver/index.d.ts +1 -0
- package/lib/driver/index.js +1 -0
- package/lib/driver/index.js.map +1 -1
- package/lib/driver/meteorMongo.d.ts +2 -1
- package/lib/driver/meteorMongo.js +4 -0
- package/lib/driver/meteorMongo.js.map +1 -1
- package/lib/driver/mongo.d.ts +2 -2
- package/lib/driver/mongo.js +4 -19
- package/lib/driver/mongo.js.map +1 -1
- package/lib/dynamic-load/actions.js +1 -0
- package/lib/dynamic-load/actions.js.map +1 -1
- package/lib/dynamic-load/package.js +1 -0
- package/lib/dynamic-load/package.js.map +1 -1
- package/lib/formula/core.d.ts +1 -0
- package/lib/formula/core.js +3 -3
- package/lib/formula/core.js.map +1 -1
- package/lib/formula/field_formula.d.ts +2 -1
- package/lib/formula/field_formula.js +3 -2
- package/lib/formula/field_formula.js.map +1 -1
- package/lib/types/datasource.d.ts +1 -0
- package/lib/types/datasource.js +3 -0
- package/lib/types/datasource.js.map +1 -1
- package/lib/types/object.d.ts +1 -0
- package/lib/types/object.js +101 -121
- package/lib/types/object.js.map +1 -1
- package/package.json +9 -9
- package/src/driver/driver.ts +3 -2
- package/src/driver/format.ts +36 -0
- package/src/driver/index.ts +4 -3
- package/src/driver/meteorMongo.ts +6 -1
- package/src/driver/mongo.ts +5 -20
- package/src/dynamic-load/actions.ts +1 -0
- package/src/dynamic-load/package.ts +1 -0
- package/src/formula/core.ts +4 -3
- package/src/formula/field_formula.ts +10 -2
- package/src/types/datasource.ts +4 -0
- package/src/types/object.ts +43 -22
package/src/types/object.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { getUserObjectSharesFilters, isTemplateSpace, isCloudAdminSpace, generat
|
|
|
4
4
|
import _ = require("underscore");
|
|
5
5
|
import { SteedosTriggerTypeConfig, SteedosTriggerContextConfig } from "./trigger";
|
|
6
6
|
import { SteedosQueryOptions, SteedosQueryFilters } from "./query";
|
|
7
|
-
import { SteedosDataSourceType, SteedosDatabaseDriverType } from "./datasource";
|
|
7
|
+
import { SteedosDataSourceType, SteedosDatabaseDriverType, getDataSource } from "./datasource";
|
|
8
8
|
import { SteedosFieldDBType } from '../driver/fieldDBType';
|
|
9
9
|
import { runCurrentObjectFieldFormulas, runQuotedByObjectFieldFormulas } from '../formula';
|
|
10
10
|
import { runQuotedByObjectFieldSummaries, runCurrentObjectFieldSummaries } from '../summary';
|
|
@@ -116,7 +116,7 @@ export interface SteedosObjectTypeConfig extends SteedosObjectProperties {
|
|
|
116
116
|
|
|
117
117
|
export const _TRIGGERKEYS = ['beforeFind', 'beforeInsert', 'beforeUpdate', 'beforeDelete', 'afterFind', 'afterCount', 'afterFindOne', 'afterInsert', 'afterUpdate', 'afterDelete', 'beforeAggregate', 'afterAggregate']
|
|
118
118
|
|
|
119
|
-
const properties = ['label', 'icon', 'enable_search', 'sidebar', 'is_enable', 'enable_files', 'enable_tasks', 'enable_notes', 'enable_events', 'enable_api', 'enable_share', 'enable_instances', 'enable_chatter', 'enable_audit', 'enable_web_forms', 'enable_inline_edit', 'enable_approvals', 'enable_trash', 'enable_space_global', 'enable_tree', 'parent_field', 'children_field', 'enable_enhanced_lookup', 'enable_workflow', 'is_view', 'hidden', 'description', 'custom', 'owner', 'methods', '_id', 'relatedList', 'fields_serial_number', "is_enable", "in_development", "version"]
|
|
119
|
+
const properties = ['label', 'icon', 'enable_search', 'sidebar', 'is_enable', 'enable_files', 'enable_tasks', 'enable_notes', 'enable_events', 'enable_api', 'enable_share', 'enable_instances', 'enable_chatter', 'enable_audit', 'enable_web_forms', 'enable_inline_edit', 'enable_approvals', 'enable_trash', 'enable_space_global', 'enable_tree', 'parent_field', 'children_field', 'enable_enhanced_lookup', 'enable_workflow', 'is_view', 'hidden', 'description', 'custom', 'owner', 'methods', '_id', 'relatedList', 'fields_serial_number', "is_enable", "in_development", "version", "paging"]
|
|
120
120
|
|
|
121
121
|
export class SteedosObjectType extends SteedosObjectProperties {
|
|
122
122
|
|
|
@@ -557,10 +557,15 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
557
557
|
}
|
|
558
558
|
|
|
559
559
|
async refreshIndexes(){
|
|
560
|
-
if(this.datasource.driver === SteedosDatabaseDriverType.Mongo){
|
|
560
|
+
if(this.datasource.driver === SteedosDatabaseDriverType.Mongo || this.datasource.driver === SteedosDatabaseDriverType.MeteorMongo){
|
|
561
561
|
const adapter = this.datasource.adapter;
|
|
562
562
|
await adapter.connect()
|
|
563
|
-
|
|
563
|
+
let collection = (adapter as any).collection(this.name);
|
|
564
|
+
if (this.datasource.driver === SteedosDatabaseDriverType.MeteorMongo) {
|
|
565
|
+
let defaultAdapter = getDataSource('default').adapter
|
|
566
|
+
await defaultAdapter.connect();
|
|
567
|
+
collection = (defaultAdapter as any).collection(this.name);
|
|
568
|
+
}
|
|
564
569
|
const indexesInfo = [];
|
|
565
570
|
const dropIndexNames = [];
|
|
566
571
|
for (const key in this.fields) {
|
|
@@ -580,7 +585,7 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
580
585
|
try {
|
|
581
586
|
await collection.createIndex(key, indexInfo)
|
|
582
587
|
} catch (error) {
|
|
583
|
-
|
|
588
|
+
// DO NOTHING
|
|
584
589
|
}
|
|
585
590
|
}
|
|
586
591
|
// await collection.createIndexes(indexesInfo)
|
|
@@ -588,20 +593,20 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
588
593
|
console.error(error)
|
|
589
594
|
}
|
|
590
595
|
}
|
|
591
|
-
if(dropIndexNames && dropIndexNames.length > 0){
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
596
|
+
// if(dropIndexNames && dropIndexNames.length > 0){
|
|
597
|
+
// try {
|
|
598
|
+
// for await (const indexName of dropIndexNames) {
|
|
599
|
+
// try {
|
|
600
|
+
// await collection.dropIndex(indexName)
|
|
601
|
+
// } catch (error) {
|
|
597
602
|
|
|
598
|
-
|
|
599
|
-
|
|
603
|
+
// }
|
|
604
|
+
// }
|
|
600
605
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
}
|
|
606
|
+
// } catch (error) {
|
|
607
|
+
// console.error(error)
|
|
608
|
+
// }
|
|
609
|
+
// }
|
|
605
610
|
}
|
|
606
611
|
}
|
|
607
612
|
|
|
@@ -854,22 +859,26 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
854
859
|
}
|
|
855
860
|
|
|
856
861
|
async insert(doc: Dictionary<any>, userSession?: SteedosUserSession) {
|
|
862
|
+
doc = this.formatRecord(doc);
|
|
857
863
|
return await this.callAdapter('insert', this.table_name, doc, userSession)
|
|
858
864
|
}
|
|
859
865
|
|
|
860
866
|
async update(id: SteedosIDType, doc: Dictionary<any>, userSession?: SteedosUserSession) {
|
|
867
|
+
doc = this.formatRecord(doc);
|
|
861
868
|
await this.processUneditableFields(userSession, doc)
|
|
862
869
|
let clonedId = id;
|
|
863
870
|
return await this.callAdapter('update', this.table_name, clonedId, doc, userSession)
|
|
864
871
|
}
|
|
865
872
|
|
|
866
873
|
async updateOne(id: SteedosIDType, doc: Dictionary<any>, userSession?: SteedosUserSession) {
|
|
874
|
+
doc = this.formatRecord(doc);
|
|
867
875
|
await this.processUneditableFields(userSession, doc)
|
|
868
876
|
let clonedId = id;
|
|
869
877
|
return await this.callAdapter('updateOne', this.table_name, clonedId, doc, userSession)
|
|
870
878
|
}
|
|
871
879
|
// 此函数支持driver: MeteorMongo、Mongo
|
|
872
880
|
async updateMany(queryFilters: SteedosQueryFilters, doc: Dictionary<any>, userSession?: SteedosUserSession) {
|
|
881
|
+
doc = this.formatRecord(doc);
|
|
873
882
|
await this.processUneditableFields(userSession, doc)
|
|
874
883
|
let clonedQueryFilters = queryFilters;
|
|
875
884
|
return await this.callAdapter('updateMany', this.table_name, clonedQueryFilters, doc, userSession)
|
|
@@ -887,10 +896,12 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
887
896
|
}
|
|
888
897
|
|
|
889
898
|
async directInsert(doc: Dictionary<any>, userSession?: SteedosUserSession) {
|
|
899
|
+
doc = this.formatRecord(doc);
|
|
890
900
|
return await this.callAdapter('directInsert', this.table_name, doc, userSession)
|
|
891
901
|
}
|
|
892
902
|
|
|
893
903
|
async directUpdate(id: SteedosIDType, doc: Dictionary<any>, userSession?: SteedosUserSession) {
|
|
904
|
+
doc = this.formatRecord(doc);
|
|
894
905
|
await this.processUneditableFields(userSession, doc)
|
|
895
906
|
let clonedId = id;
|
|
896
907
|
return await this.callAdapter('directUpdate', this.table_name, clonedId, doc, userSession)
|
|
@@ -1661,6 +1672,14 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1661
1672
|
// // })
|
|
1662
1673
|
}
|
|
1663
1674
|
|
|
1675
|
+
private formatRecord(doc: JsonMap) {
|
|
1676
|
+
let adapterFormat = this._datasource["formatRecord"];
|
|
1677
|
+
if (typeof adapterFormat == 'function') {
|
|
1678
|
+
doc = adapterFormat.apply(this._datasource, [doc, this.toConfig()]);
|
|
1679
|
+
}
|
|
1680
|
+
return doc;
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1664
1683
|
private async callAdapter(method: string, ...args: any[]) {
|
|
1665
1684
|
|
|
1666
1685
|
const adapterMethod = this._datasource[method];
|
|
@@ -1779,7 +1798,7 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1779
1798
|
};
|
|
1780
1799
|
|
|
1781
1800
|
private async runRecordFormula(method: string, objectName: string, recordId: string, doc: any, userSession: any) {
|
|
1782
|
-
if (["insert", "update", "updateMany"].indexOf(method) > -1) {
|
|
1801
|
+
if (["insert", "update", "updateMany", "delete"].indexOf(method) > -1) {
|
|
1783
1802
|
if (method === "updateMany") {
|
|
1784
1803
|
// TODO:暂时不支持updateMany公式计算,因为拿不到修改了哪些数据
|
|
1785
1804
|
// let filters: SteedosQueryFilters = args[1];
|
|
@@ -1787,11 +1806,13 @@ export class SteedosObjectType extends SteedosObjectProperties {
|
|
|
1787
1806
|
}
|
|
1788
1807
|
else {
|
|
1789
1808
|
let currentUserId = userSession ? userSession.userId : undefined;
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
// 新建记录时肯定不会有字段被引用,不需要重算被引用的公式字段值
|
|
1793
|
-
await runQuotedByObjectFieldFormulas(objectName, recordId, userSession);
|
|
1809
|
+
if(method !== "delete"){
|
|
1810
|
+
await runCurrentObjectFieldFormulas(objectName, recordId, doc, currentUserId, true);
|
|
1794
1811
|
}
|
|
1812
|
+
// 新建记录时肯定不会有字段被其它对象引用,但是会有当前对象上的字段之间互相引用,所以也需要重算被引用的公式字段值
|
|
1813
|
+
// 见issue: a公式字段,其中应用了b公式字段,记录保存后a字段没计算,编辑后再保存字段计算 #2946
|
|
1814
|
+
const isOnlyForCurrentObject = method === "insert";
|
|
1815
|
+
await runQuotedByObjectFieldFormulas(objectName, recordId, userSession, { isOnlyForCurrentObject });
|
|
1795
1816
|
}
|
|
1796
1817
|
}
|
|
1797
1818
|
}
|