@jd-data-limited/easy-fm 2.0.4 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +25 -24
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.0",
4
4
  "dependencies": {
5
5
  "@types/btoa": "^1.2.3",
6
6
  "@types/events": "^3.0.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,12 @@ 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
+ // for (let item of Object.keys(data)) extraBody[item] = data[item]
1680
1681
  console.log((extraBody as any).portalData)
1681
1682
  this.layout.database.apiRequest(this.endpoint, {
1682
1683
  port: 443,
1683
1684
  method: "PATCH",
1684
- body: JSON.stringify(extraBody)
1685
+ body: JSON.stringify(data)
1685
1686
  })
1686
1687
  .then(res => {
1687
1688
  if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
@@ -2013,7 +2014,7 @@ export class PortalRecord extends RecordBase {
2013
2014
  this.portal.record._onSave()
2014
2015
  }
2015
2016
 
2016
- commit(extraBody = {fieldData: undefined}) {
2017
+ commit(extraBody: extraBodyOptions) {
2017
2018
  return this.portal.record.commit(extraBody)
2018
2019
  }
2019
2020
 
@@ -2100,15 +2101,15 @@ export class RecordGetRange extends RecordGetOperation {
2100
2101
  if (extraBody.scripts) {
2101
2102
  if (extraBody.scripts.prerequest) {
2102
2103
  params.push("script.prerequest=" + extraBody.scripts.prerequest.name)
2103
- if (extraBody.scripts.prerequest.param) params.push("script.prerequest.param=" + extraBody.scripts.prerequest.param)
2104
+ if (extraBody.scripts.prerequest.parameter) params.push("script.prerequest.param=" + extraBody.scripts.prerequest.parameter)
2104
2105
  }
2105
2106
  if (extraBody.scripts.presort) {
2106
2107
  params.push("script.presort=" + extraBody.scripts.presort.name)
2107
- if (extraBody.scripts.presort.param) params.push("script.presort.param=" + extraBody.scripts.presort.param)
2108
+ if (extraBody.scripts.presort.parameter) params.push("script.presort.param=" + extraBody.scripts.presort.parameter)
2108
2109
  }
2109
2110
  if (extraBody.scripts.after) {
2110
2111
  params.push("script=" + extraBody.scripts.after.name)
2111
- if (extraBody.scripts.after.param) params.push("script.param=" + extraBody.scripts.after.param)
2112
+ if (extraBody.scripts.after.parameter) params.push("script.param=" + extraBody.scripts.after.parameter)
2112
2113
  }
2113
2114
  }
2114
2115