@jd-data-limited/easy-fm 2.0.3 → 3.0.0
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/package.json +1 -1
- package/src/index.js +22 -5
- package/src/index.ts +61 -36
- package/test.js +17 -14
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1263,7 +1263,7 @@ export class Database extends EventEmitter {
|
|
|
1263
1263
|
}
|
|
1264
1264
|
export class Layout {
|
|
1265
1265
|
constructor(database, name) {
|
|
1266
|
-
this.records = new
|
|
1266
|
+
this.records = new LayoutRecordManager(this);
|
|
1267
1267
|
this.database = database;
|
|
1268
1268
|
this.name = name;
|
|
1269
1269
|
}
|
|
@@ -1325,7 +1325,7 @@ export class Layout {
|
|
|
1325
1325
|
});
|
|
1326
1326
|
}
|
|
1327
1327
|
}
|
|
1328
|
-
class
|
|
1328
|
+
class LayoutRecordManager {
|
|
1329
1329
|
constructor(layout) {
|
|
1330
1330
|
this.layout = layout;
|
|
1331
1331
|
}
|
|
@@ -1337,7 +1337,10 @@ class LayourRecordManager {
|
|
|
1337
1337
|
for (let _field of this.layout.metadata.fieldMetaData) {
|
|
1338
1338
|
fields[_field.name] = "";
|
|
1339
1339
|
}
|
|
1340
|
-
|
|
1340
|
+
let portals = {};
|
|
1341
|
+
for (let _portal of Object.keys(this.layout.metadata.portalMetaData))
|
|
1342
|
+
portals[_portal] = [];
|
|
1343
|
+
resolve(new LayoutRecord(this.layout, -1, 0, fields, portals));
|
|
1341
1344
|
}).catch(e => {
|
|
1342
1345
|
reject(e);
|
|
1343
1346
|
});
|
|
@@ -1463,7 +1466,8 @@ export class RecordBase extends EventEmitter {
|
|
|
1463
1466
|
delete data.modId;
|
|
1464
1467
|
if (this.recordId === -1) {
|
|
1465
1468
|
// This is a new LayoutRecord
|
|
1466
|
-
|
|
1469
|
+
for (let item of Object.keys(data))
|
|
1470
|
+
extraBody[item] = data[item];
|
|
1467
1471
|
this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
|
|
1468
1472
|
port: 443,
|
|
1469
1473
|
method: "POST",
|
|
@@ -1489,6 +1493,7 @@ export class RecordBase extends EventEmitter {
|
|
|
1489
1493
|
}
|
|
1490
1494
|
for (let item of Object.keys(data))
|
|
1491
1495
|
extraBody[item] = data[item];
|
|
1496
|
+
console.log(extraBody.portalData);
|
|
1492
1497
|
this.layout.database.apiRequest(this.endpoint, {
|
|
1493
1498
|
port: 443,
|
|
1494
1499
|
method: "PATCH",
|
|
@@ -1760,6 +1765,15 @@ export class Portal {
|
|
|
1760
1765
|
this.record = record;
|
|
1761
1766
|
this.name = name;
|
|
1762
1767
|
}
|
|
1768
|
+
create() {
|
|
1769
|
+
let fields = {};
|
|
1770
|
+
for (let _field of this.record.layout.metadata.portalMetaData[this.name]) {
|
|
1771
|
+
fields[_field.name] = "";
|
|
1772
|
+
}
|
|
1773
|
+
let record = new PortalRecord(this.record, this, -1, -1, fields);
|
|
1774
|
+
this.records.push(record);
|
|
1775
|
+
return record;
|
|
1776
|
+
}
|
|
1763
1777
|
}
|
|
1764
1778
|
export class PortalRecord extends RecordBase {
|
|
1765
1779
|
constructor(record, portal, recordId, modId = recordId, fieldData = {}) {
|
|
@@ -1777,13 +1791,16 @@ export class PortalRecord extends RecordBase {
|
|
|
1777
1791
|
toObject(fieldFilter) {
|
|
1778
1792
|
super.toObject();
|
|
1779
1793
|
let res = {
|
|
1780
|
-
recordId: this.recordId, modId: this.modId
|
|
1794
|
+
recordId: this.recordId === -1 ? undefined : this.recordId, modId: this.modId === -1 ? undefined : this.modId
|
|
1781
1795
|
};
|
|
1782
1796
|
for (let field of this.fields.filter(a => fieldFilter(a)))
|
|
1783
1797
|
res[field.id] = field.value;
|
|
1784
1798
|
// console.log(res)
|
|
1785
1799
|
return res;
|
|
1786
1800
|
}
|
|
1801
|
+
getField(field) {
|
|
1802
|
+
return this.fields.find(_field => _field.id === field) || this.fields.find(_field => _field.id === this.portal.name + "::" + field);
|
|
1803
|
+
}
|
|
1787
1804
|
}
|
|
1788
1805
|
export class RecordGetOperation {
|
|
1789
1806
|
constructor(layout) {
|
package/src/index.ts
CHANGED
|
@@ -67,18 +67,9 @@ interface limitPortalsInterface {
|
|
|
67
67
|
|
|
68
68
|
interface extraBodyOptions {
|
|
69
69
|
scripts?: {
|
|
70
|
-
prerequest?:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
},
|
|
74
|
-
presort?: {
|
|
75
|
-
name: string,
|
|
76
|
-
param?: string
|
|
77
|
-
},
|
|
78
|
-
after?: {
|
|
79
|
-
name: string,
|
|
80
|
-
param?: string
|
|
81
|
-
},
|
|
70
|
+
prerequest?: Script,
|
|
71
|
+
presort?: Script,
|
|
72
|
+
after?: Script,
|
|
82
73
|
}
|
|
83
74
|
}
|
|
84
75
|
|
|
@@ -1120,7 +1111,7 @@ interface portalDataObject {
|
|
|
1120
1111
|
[key: string]: recordObject
|
|
1121
1112
|
}
|
|
1122
1113
|
|
|
1123
|
-
interface
|
|
1114
|
+
interface FieldMetaData {
|
|
1124
1115
|
name: string,
|
|
1125
1116
|
type: string,
|
|
1126
1117
|
displayType: string,
|
|
@@ -1137,6 +1128,13 @@ interface fieldMetaData {
|
|
|
1137
1128
|
repetitionEnd: number
|
|
1138
1129
|
}
|
|
1139
1130
|
|
|
1131
|
+
interface LayoutMetaData {
|
|
1132
|
+
fieldMetaData: FieldMetaData[],
|
|
1133
|
+
portalMetaData?: {
|
|
1134
|
+
[key: string]: FieldMetaData[]
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1140
1138
|
interface FMHostMetadata {
|
|
1141
1139
|
productInfo: {
|
|
1142
1140
|
buildDate: Date,
|
|
@@ -1360,7 +1358,7 @@ export class Database extends EventEmitter {
|
|
|
1360
1358
|
})
|
|
1361
1359
|
}
|
|
1362
1360
|
|
|
1363
|
-
script(name, parameter): Script {
|
|
1361
|
+
script(name, parameter = ""): Script {
|
|
1364
1362
|
return ({name, parameter} as Script)
|
|
1365
1363
|
}
|
|
1366
1364
|
|
|
@@ -1409,7 +1407,7 @@ export class Database extends EventEmitter {
|
|
|
1409
1407
|
|
|
1410
1408
|
export class Layout {
|
|
1411
1409
|
readonly database: Database;
|
|
1412
|
-
readonly records = new
|
|
1410
|
+
readonly records = new LayoutRecordManager(this)
|
|
1413
1411
|
protected name: string;
|
|
1414
1412
|
metadata: any;
|
|
1415
1413
|
|
|
@@ -1482,7 +1480,7 @@ export class Layout {
|
|
|
1482
1480
|
}
|
|
1483
1481
|
}
|
|
1484
1482
|
|
|
1485
|
-
class
|
|
1483
|
+
class LayoutRecordManager {
|
|
1486
1484
|
readonly layout: Layout
|
|
1487
1485
|
|
|
1488
1486
|
constructor(layout: Layout) {
|
|
@@ -1497,7 +1495,9 @@ class LayourRecordManager {
|
|
|
1497
1495
|
for (let _field of this.layout.metadata.fieldMetaData) {
|
|
1498
1496
|
fields[_field.name] = ""
|
|
1499
1497
|
}
|
|
1500
|
-
|
|
1498
|
+
let portals = {}
|
|
1499
|
+
for (let _portal of Object.keys(this.layout.metadata.portalMetaData)) portals[_portal] = []
|
|
1500
|
+
resolve(new LayoutRecord(this.layout, -1, 0, fields, portals))
|
|
1501
1501
|
}).catch(e => {
|
|
1502
1502
|
reject(e)
|
|
1503
1503
|
})
|
|
@@ -1630,22 +1630,32 @@ export class RecordBase extends EventEmitter {
|
|
|
1630
1630
|
})
|
|
1631
1631
|
}
|
|
1632
1632
|
|
|
1633
|
-
commit(extraBody
|
|
1634
|
-
fieldData: undefined
|
|
1635
|
-
}): Promise<RecordBase | FMError> {
|
|
1633
|
+
commit(extraBody: extraBodyOptions): Promise<RecordBase | FMError> {
|
|
1636
1634
|
return new Promise(async (resolve, reject) => {
|
|
1637
1635
|
let data = this.toObject()
|
|
1638
1636
|
delete data.recordId
|
|
1639
1637
|
delete data.modId
|
|
1640
1638
|
|
|
1639
|
+
if (extraBody.scripts.after) {
|
|
1640
|
+
data["script"] = extraBody.scripts.after.name
|
|
1641
|
+
if (extraBody.scripts.after.parameter) data["param"] = extraBody.scripts.after.parameter
|
|
1642
|
+
}
|
|
1643
|
+
if (extraBody.scripts.prerequest) {
|
|
1644
|
+
data["script"] = extraBody.scripts.after.name
|
|
1645
|
+
if (extraBody.scripts.prerequest.parameter) data["param"] = extraBody.scripts.prerequest.parameter
|
|
1646
|
+
}
|
|
1647
|
+
if (extraBody.scripts.presort) {
|
|
1648
|
+
data["script"] = extraBody.scripts.presort.name
|
|
1649
|
+
if (extraBody.scripts.presort.parameter) data["param"] = extraBody.scripts.presort.parameter
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1641
1652
|
if (this.recordId === -1) {
|
|
1642
1653
|
// This is a new LayoutRecord
|
|
1643
|
-
extraBody.fieldData = data.fieldData
|
|
1644
1654
|
|
|
1645
1655
|
this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
|
|
1646
1656
|
port: 443,
|
|
1647
1657
|
method: "POST",
|
|
1648
|
-
body: JSON.stringify(
|
|
1658
|
+
body: JSON.stringify(data)
|
|
1649
1659
|
})
|
|
1650
1660
|
.then(res => {
|
|
1651
1661
|
if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
@@ -1667,11 +1677,12 @@ export class RecordBase extends EventEmitter {
|
|
|
1667
1677
|
return
|
|
1668
1678
|
}
|
|
1669
1679
|
|
|
1670
|
-
for (let item of Object.keys(data)) extraBody[item] = data[item]
|
|
1680
|
+
// for (let item of Object.keys(data)) extraBody[item] = data[item]
|
|
1681
|
+
console.log((extraBody as any).portalData)
|
|
1671
1682
|
this.layout.database.apiRequest(this.endpoint, {
|
|
1672
1683
|
port: 443,
|
|
1673
1684
|
method: "PATCH",
|
|
1674
|
-
body: JSON.stringify(
|
|
1685
|
+
body: JSON.stringify(data)
|
|
1675
1686
|
})
|
|
1676
1687
|
.then(res => {
|
|
1677
1688
|
if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
@@ -1820,7 +1831,7 @@ export class LayoutRecord extends RecordBase {
|
|
|
1820
1831
|
|
|
1821
1832
|
export class Field {
|
|
1822
1833
|
record: RecordBase;
|
|
1823
|
-
id:
|
|
1834
|
+
id: string;
|
|
1824
1835
|
protected _value: string | number | Date;
|
|
1825
1836
|
edited: boolean;
|
|
1826
1837
|
|
|
@@ -1845,7 +1856,7 @@ export class Field {
|
|
|
1845
1856
|
this.edited = true
|
|
1846
1857
|
}
|
|
1847
1858
|
|
|
1848
|
-
get metadata():
|
|
1859
|
+
get metadata(): FieldMetaData {
|
|
1849
1860
|
if (!this.record.layout.metadata) {
|
|
1850
1861
|
// Default to a regular text field
|
|
1851
1862
|
return {
|
|
@@ -1863,10 +1874,10 @@ export class Field {
|
|
|
1863
1874
|
timeOfDay: false,
|
|
1864
1875
|
repetitionStart: 1,
|
|
1865
1876
|
repetitionEnd: 1
|
|
1866
|
-
} as
|
|
1877
|
+
} as FieldMetaData
|
|
1867
1878
|
}
|
|
1868
1879
|
if (this.record instanceof PortalRecord) {
|
|
1869
|
-
return this.record.layout.metadata.portalMetaData[this.record.portal.name || "portal not attached"].find(i => i.name === this.id) as
|
|
1880
|
+
return this.record.layout.metadata.portalMetaData[this.record.portal.name || "portal not attached"].find(i => i.name === this.id) as FieldMetaData || {
|
|
1870
1881
|
name: this.id.toString(),
|
|
1871
1882
|
type: 'normal',
|
|
1872
1883
|
displayType: 'editText',
|
|
@@ -1881,10 +1892,10 @@ export class Field {
|
|
|
1881
1892
|
timeOfDay: false,
|
|
1882
1893
|
repetitionStart: 1,
|
|
1883
1894
|
repetitionEnd: 1
|
|
1884
|
-
} as
|
|
1895
|
+
} as FieldMetaData
|
|
1885
1896
|
}
|
|
1886
1897
|
else {
|
|
1887
|
-
return this.record.layout.metadata.fieldMetaData.find(i => i.name === this.id) as
|
|
1898
|
+
return this.record.layout.metadata.fieldMetaData.find(i => i.name === this.id) as FieldMetaData || {
|
|
1888
1899
|
name: this.id.toString(),
|
|
1889
1900
|
type: 'normal',
|
|
1890
1901
|
displayType: 'editText',
|
|
@@ -1899,7 +1910,7 @@ export class Field {
|
|
|
1899
1910
|
timeOfDay: false,
|
|
1900
1911
|
repetitionStart: 1,
|
|
1901
1912
|
repetitionEnd: 1
|
|
1902
|
-
} as
|
|
1913
|
+
} as FieldMetaData
|
|
1903
1914
|
}
|
|
1904
1915
|
}
|
|
1905
1916
|
|
|
@@ -1976,6 +1987,16 @@ export class Portal {
|
|
|
1976
1987
|
this.record = record
|
|
1977
1988
|
this.name = name
|
|
1978
1989
|
}
|
|
1990
|
+
|
|
1991
|
+
create() {
|
|
1992
|
+
let fields = {}
|
|
1993
|
+
for (let _field of this.record.layout.metadata.portalMetaData[this.name]) {
|
|
1994
|
+
fields[_field.name] = ""
|
|
1995
|
+
}
|
|
1996
|
+
let record = new PortalRecord(this.record, this, -1, -1, fields)
|
|
1997
|
+
this.records.push(record)
|
|
1998
|
+
return record
|
|
1999
|
+
}
|
|
1979
2000
|
}
|
|
1980
2001
|
|
|
1981
2002
|
export class PortalRecord extends RecordBase {
|
|
@@ -1993,19 +2014,23 @@ export class PortalRecord extends RecordBase {
|
|
|
1993
2014
|
this.portal.record._onSave()
|
|
1994
2015
|
}
|
|
1995
2016
|
|
|
1996
|
-
commit(extraBody
|
|
2017
|
+
commit(extraBody: extraBodyOptions) {
|
|
1997
2018
|
return this.portal.record.commit(extraBody)
|
|
1998
2019
|
}
|
|
1999
2020
|
|
|
2000
2021
|
toObject(fieldFilter): any {
|
|
2001
2022
|
super.toObject()
|
|
2002
2023
|
let res = {
|
|
2003
|
-
recordId: this.recordId, modId: this.modId
|
|
2024
|
+
recordId: this.recordId === -1 ? undefined : this.recordId, modId: this.modId === - 1 ? undefined : this.modId
|
|
2004
2025
|
} as recordObject
|
|
2005
2026
|
for (let field of this.fields.filter(a => fieldFilter(a))) res[field.id] = field.value
|
|
2006
2027
|
// console.log(res)
|
|
2007
2028
|
return res
|
|
2008
2029
|
}
|
|
2030
|
+
|
|
2031
|
+
getField(field) {
|
|
2032
|
+
return this.fields.find(_field => _field.id === field) || this.fields.find(_field => _field.id === this.portal.name + "::" + field)
|
|
2033
|
+
}
|
|
2009
2034
|
}
|
|
2010
2035
|
|
|
2011
2036
|
export class RecordGetOperation {
|
|
@@ -2076,15 +2101,15 @@ export class RecordGetRange extends RecordGetOperation {
|
|
|
2076
2101
|
if (extraBody.scripts) {
|
|
2077
2102
|
if (extraBody.scripts.prerequest) {
|
|
2078
2103
|
params.push("script.prerequest=" + extraBody.scripts.prerequest.name)
|
|
2079
|
-
if (extraBody.scripts.prerequest.
|
|
2104
|
+
if (extraBody.scripts.prerequest.parameter) params.push("script.prerequest.param=" + extraBody.scripts.prerequest.parameter)
|
|
2080
2105
|
}
|
|
2081
2106
|
if (extraBody.scripts.presort) {
|
|
2082
2107
|
params.push("script.presort=" + extraBody.scripts.presort.name)
|
|
2083
|
-
if (extraBody.scripts.presort.
|
|
2108
|
+
if (extraBody.scripts.presort.parameter) params.push("script.presort.param=" + extraBody.scripts.presort.parameter)
|
|
2084
2109
|
}
|
|
2085
2110
|
if (extraBody.scripts.after) {
|
|
2086
2111
|
params.push("script=" + extraBody.scripts.after.name)
|
|
2087
|
-
if (extraBody.scripts.after.
|
|
2112
|
+
if (extraBody.scripts.after.parameter) params.push("script.param=" + extraBody.scripts.after.parameter)
|
|
2088
2113
|
}
|
|
2089
2114
|
}
|
|
2090
2115
|
|
package/test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import FMHost from "./
|
|
1
|
+
import FMHost from "./src/index.js";
|
|
2
2
|
import * as fs from "fs";
|
|
3
|
-
import {DOWNLOAD_MODES} from "./
|
|
3
|
+
import {DOWNLOAD_MODES} from "./src/index.js";
|
|
4
4
|
|
|
5
5
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
|
6
6
|
|
|
@@ -16,17 +16,20 @@ const database = host.database({
|
|
|
16
16
|
})
|
|
17
17
|
database.login()
|
|
18
18
|
.then(async () => {
|
|
19
|
-
let layout = database.getLayout("
|
|
20
|
-
|
|
19
|
+
let layout = database.getLayout("ReportsJSON")
|
|
20
|
+
await layout.getLayoutMeta()
|
|
21
|
+
console.log(layout.metadata)
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
let record = (await layout.records.range(4, 9).fetch())[0]
|
|
24
|
+
|
|
25
|
+
record.getField("In|PartnerID").set("42565F30-5F5D-44A4-83A0-E52128974581")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
let portal = record.getPortal("Reports|Archive")
|
|
29
|
+
let portal_record = portal.create()
|
|
30
|
+
portal_record.getField("SampleClass").set("Hello!")
|
|
31
|
+
|
|
32
|
+
await record.commit()
|
|
33
|
+
await record.get()
|
|
34
|
+
console.log(record.getField("__PrimaryKey").value)
|
|
32
35
|
})
|