@jd-data-limited/easy-fm 2.0.4 → 3.0.1

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 (3) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +27 -17
  3. package/src/index.ts +25 -25
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jd-data-limited/easy-fm",
3
- "version": "2.0.4",
3
+ "version": "3.0.1",
4
4
  "dependencies": {
5
5
  "@types/btoa": "^1.2.3",
6
6
  "@types/events": "^3.0.0",
package/src/index.js CHANGED
@@ -1220,7 +1220,7 @@ export class Database extends EventEmitter {
1220
1220
  });
1221
1221
  });
1222
1222
  }
1223
- script(name, parameter) {
1223
+ script(name, parameter = "") {
1224
1224
  return { name, parameter };
1225
1225
  }
1226
1226
  _tokenExpired() {
@@ -1457,21 +1457,32 @@ export class RecordBase extends EventEmitter {
1457
1457
  });
1458
1458
  }));
1459
1459
  }
1460
- commit(extraBody = {
1461
- fieldData: undefined
1462
- }) {
1460
+ commit(extraBody) {
1463
1461
  return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
1464
1462
  let data = this.toObject();
1465
1463
  delete data.recordId;
1466
1464
  delete data.modId;
1465
+ if (extraBody.scripts.after) {
1466
+ data["script"] = extraBody.scripts.after.name;
1467
+ if (extraBody.scripts.after.parameter)
1468
+ data["param"] = extraBody.scripts.after.parameter;
1469
+ }
1470
+ if (extraBody.scripts.prerequest) {
1471
+ data["script"] = extraBody.scripts.after.name;
1472
+ if (extraBody.scripts.prerequest.parameter)
1473
+ data["param"] = extraBody.scripts.prerequest.parameter;
1474
+ }
1475
+ if (extraBody.scripts.presort) {
1476
+ data["script"] = extraBody.scripts.presort.name;
1477
+ if (extraBody.scripts.presort.parameter)
1478
+ data["param"] = extraBody.scripts.presort.parameter;
1479
+ }
1467
1480
  if (this.recordId === -1) {
1468
1481
  // This is a new LayoutRecord
1469
- for (let item of Object.keys(data))
1470
- extraBody[item] = data[item];
1471
1482
  this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
1472
1483
  port: 443,
1473
1484
  method: "POST",
1474
- body: JSON.stringify(extraBody)
1485
+ body: JSON.stringify(data)
1475
1486
  })
1476
1487
  .then(res => {
1477
1488
  if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
@@ -1491,13 +1502,12 @@ export class RecordBase extends EventEmitter {
1491
1502
  });
1492
1503
  return;
1493
1504
  }
1494
- for (let item of Object.keys(data))
1495
- extraBody[item] = data[item];
1505
+ // for (let item of Object.keys(data)) extraBody[item] = data[item]
1496
1506
  console.log(extraBody.portalData);
1497
1507
  this.layout.database.apiRequest(this.endpoint, {
1498
1508
  port: 443,
1499
1509
  method: "PATCH",
1500
- body: JSON.stringify(extraBody)
1510
+ body: JSON.stringify(data)
1501
1511
  })
1502
1512
  .then(res => {
1503
1513
  if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
@@ -1785,7 +1795,7 @@ export class PortalRecord extends RecordBase {
1785
1795
  super._onSave();
1786
1796
  this.portal.record._onSave();
1787
1797
  }
1788
- commit(extraBody = { fieldData: undefined }) {
1798
+ commit(extraBody) {
1789
1799
  return this.portal.record.commit(extraBody);
1790
1800
  }
1791
1801
  toObject(fieldFilter) {
@@ -1868,18 +1878,18 @@ export class RecordGetRange extends RecordGetOperation {
1868
1878
  if (extraBody.scripts) {
1869
1879
  if (extraBody.scripts.prerequest) {
1870
1880
  params.push("script.prerequest=" + extraBody.scripts.prerequest.name);
1871
- if (extraBody.scripts.prerequest.param)
1872
- params.push("script.prerequest.param=" + extraBody.scripts.prerequest.param);
1881
+ if (extraBody.scripts.prerequest.parameter)
1882
+ params.push("script.prerequest.param=" + extraBody.scripts.prerequest.parameter);
1873
1883
  }
1874
1884
  if (extraBody.scripts.presort) {
1875
1885
  params.push("script.presort=" + extraBody.scripts.presort.name);
1876
- if (extraBody.scripts.presort.param)
1877
- params.push("script.presort.param=" + extraBody.scripts.presort.param);
1886
+ if (extraBody.scripts.presort.parameter)
1887
+ params.push("script.presort.param=" + extraBody.scripts.presort.parameter);
1878
1888
  }
1879
1889
  if (extraBody.scripts.after) {
1880
1890
  params.push("script=" + extraBody.scripts.after.name);
1881
- if (extraBody.scripts.after.param)
1882
- params.push("script.param=" + extraBody.scripts.after.param);
1891
+ if (extraBody.scripts.after.parameter)
1892
+ params.push("script.param=" + extraBody.scripts.after.parameter);
1883
1893
  }
1884
1894
  }
1885
1895
  if (params.length === 0)
package/src/index.ts CHANGED
@@ -67,18 +67,9 @@ interface limitPortalsInterface {
67
67
 
68
68
  interface extraBodyOptions {
69
69
  scripts?: {
70
- prerequest?: {
71
- name: string,
72
- param?: string
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
 
@@ -1367,7 +1358,7 @@ export class Database extends EventEmitter {
1367
1358
  })
1368
1359
  }
1369
1360
 
1370
- script(name, parameter): Script {
1361
+ script(name, parameter = ""): Script {
1371
1362
  return ({name, parameter} as Script)
1372
1363
  }
1373
1364
 
@@ -1639,22 +1630,32 @@ export class RecordBase extends EventEmitter {
1639
1630
  })
1640
1631
  }
1641
1632
 
1642
- commit(extraBody = {
1643
- fieldData: undefined
1644
- }): Promise<RecordBase | FMError> {
1633
+ commit(extraBody: extraBodyOptions): Promise<RecordBase | FMError> {
1645
1634
  return new Promise(async (resolve, reject) => {
1646
1635
  let data = this.toObject()
1647
1636
  delete data.recordId
1648
1637
  delete data.modId
1649
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
+
1650
1652
  if (this.recordId === -1) {
1651
1653
  // This is a new LayoutRecord
1652
- for (let item of Object.keys(data)) extraBody[item] = data[item]
1653
1654
 
1654
1655
  this.layout.database.apiRequest(`${this.layout.endpoint}/records`, {
1655
1656
  port: 443,
1656
1657
  method: "POST",
1657
- body: JSON.stringify(extraBody)
1658
+ body: JSON.stringify(data)
1658
1659
  })
1659
1660
  .then(res => {
1660
1661
  if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
@@ -1676,12 +1677,11 @@ export class RecordBase extends EventEmitter {
1676
1677
  return
1677
1678
  }
1678
1679
 
1679
- for (let item of Object.keys(data)) extraBody[item] = data[item]
1680
- console.log((extraBody as any).portalData)
1680
+ // for (let item of Object.keys(data)) extraBody[item] = data[item]
1681
1681
  this.layout.database.apiRequest(this.endpoint, {
1682
1682
  port: 443,
1683
1683
  method: "PATCH",
1684
- body: JSON.stringify(extraBody)
1684
+ body: JSON.stringify(data)
1685
1685
  })
1686
1686
  .then(res => {
1687
1687
  if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
@@ -2013,7 +2013,7 @@ export class PortalRecord extends RecordBase {
2013
2013
  this.portal.record._onSave()
2014
2014
  }
2015
2015
 
2016
- commit(extraBody = {fieldData: undefined}) {
2016
+ commit(extraBody: extraBodyOptions) {
2017
2017
  return this.portal.record.commit(extraBody)
2018
2018
  }
2019
2019
 
@@ -2100,15 +2100,15 @@ export class RecordGetRange extends RecordGetOperation {
2100
2100
  if (extraBody.scripts) {
2101
2101
  if (extraBody.scripts.prerequest) {
2102
2102
  params.push("script.prerequest=" + extraBody.scripts.prerequest.name)
2103
- if (extraBody.scripts.prerequest.param) params.push("script.prerequest.param=" + extraBody.scripts.prerequest.param)
2103
+ if (extraBody.scripts.prerequest.parameter) params.push("script.prerequest.param=" + extraBody.scripts.prerequest.parameter)
2104
2104
  }
2105
2105
  if (extraBody.scripts.presort) {
2106
2106
  params.push("script.presort=" + extraBody.scripts.presort.name)
2107
- if (extraBody.scripts.presort.param) params.push("script.presort.param=" + extraBody.scripts.presort.param)
2107
+ if (extraBody.scripts.presort.parameter) params.push("script.presort.param=" + extraBody.scripts.presort.parameter)
2108
2108
  }
2109
2109
  if (extraBody.scripts.after) {
2110
2110
  params.push("script=" + extraBody.scripts.after.name)
2111
- if (extraBody.scripts.after.param) params.push("script.param=" + extraBody.scripts.after.param)
2111
+ if (extraBody.scripts.after.parameter) params.push("script.param=" + extraBody.scripts.after.parameter)
2112
2112
  }
2113
2113
  }
2114
2114