@jd-data-limited/easy-fm 1.3.0 → 1.3.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.
- package/dist/index.js +37 -19
- package/package.json +2 -2
- package/src/index.ts +31 -31
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
};
|
|
13
13
|
// const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
|
14
14
|
import fetch, { File, FormData } from 'node-fetch';
|
|
15
|
+
import 'node-fetch';
|
|
15
16
|
import { EventEmitter } from "events";
|
|
16
17
|
// @ts-ignore
|
|
17
18
|
import * as moment from "moment";
|
|
@@ -1182,7 +1183,7 @@ export class Database extends EventEmitter {
|
|
|
1182
1183
|
});
|
|
1183
1184
|
}
|
|
1184
1185
|
getLayout(name) {
|
|
1185
|
-
return new
|
|
1186
|
+
return new Layout(this, name);
|
|
1186
1187
|
}
|
|
1187
1188
|
setGlobals(globalFields) {
|
|
1188
1189
|
// console.log({globalFields})
|
|
@@ -1211,9 +1212,9 @@ export class Database extends EventEmitter {
|
|
|
1211
1212
|
this.emit("token_expired");
|
|
1212
1213
|
}
|
|
1213
1214
|
}
|
|
1214
|
-
class
|
|
1215
|
+
export class Layout {
|
|
1215
1216
|
constructor(database, name) {
|
|
1216
|
-
this.records = new
|
|
1217
|
+
this.records = new LayourRecordManager(this);
|
|
1217
1218
|
this.database = database;
|
|
1218
1219
|
this.name = name;
|
|
1219
1220
|
}
|
|
@@ -1275,7 +1276,7 @@ class layout {
|
|
|
1275
1276
|
});
|
|
1276
1277
|
}
|
|
1277
1278
|
}
|
|
1278
|
-
class
|
|
1279
|
+
class LayourRecordManager {
|
|
1279
1280
|
constructor(layout) {
|
|
1280
1281
|
this.layout = layout;
|
|
1281
1282
|
}
|
|
@@ -1310,13 +1311,13 @@ class layoutRecordManager {
|
|
|
1310
1311
|
});
|
|
1311
1312
|
}
|
|
1312
1313
|
range() {
|
|
1313
|
-
return new
|
|
1314
|
+
return new RecordGetRange(this.layout);
|
|
1314
1315
|
}
|
|
1315
1316
|
find() {
|
|
1316
|
-
return new
|
|
1317
|
+
return new Find(this.layout);
|
|
1317
1318
|
}
|
|
1318
1319
|
}
|
|
1319
|
-
class RecordBase extends EventEmitter {
|
|
1320
|
+
export class RecordBase extends EventEmitter {
|
|
1320
1321
|
constructor(layout, recordId, modId = recordId) {
|
|
1321
1322
|
super();
|
|
1322
1323
|
this.portals = [];
|
|
@@ -1332,7 +1333,7 @@ class RecordBase extends EventEmitter {
|
|
|
1332
1333
|
}
|
|
1333
1334
|
processPortalData(portalData) {
|
|
1334
1335
|
for (let item of Object.keys(portalData)) {
|
|
1335
|
-
let _portal = new
|
|
1336
|
+
let _portal = new Portal(this, item);
|
|
1336
1337
|
_portal.records = portalData[item].map(item => {
|
|
1337
1338
|
let fieldData = item;
|
|
1338
1339
|
delete fieldData.recordId;
|
|
@@ -1344,7 +1345,7 @@ class RecordBase extends EventEmitter {
|
|
|
1344
1345
|
}
|
|
1345
1346
|
processFieldData(fieldData) {
|
|
1346
1347
|
return Object.keys(fieldData).map(item => {
|
|
1347
|
-
let _field = new
|
|
1348
|
+
let _field = new Field(this, item, fieldData[item]);
|
|
1348
1349
|
if (!!fieldData[item]) {
|
|
1349
1350
|
if (_field.metadata.result === "timeStamp") {
|
|
1350
1351
|
// @ts-ignore
|
|
@@ -1561,7 +1562,7 @@ class RecordBase extends EventEmitter {
|
|
|
1561
1562
|
return obj;
|
|
1562
1563
|
}
|
|
1563
1564
|
}
|
|
1564
|
-
class LayoutRecord extends RecordBase {
|
|
1565
|
+
export class LayoutRecord extends RecordBase {
|
|
1565
1566
|
constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
|
|
1566
1567
|
super(layout, recordId, modId);
|
|
1567
1568
|
this.fields = this.processFieldData(fieldData);
|
|
@@ -1571,7 +1572,7 @@ class LayoutRecord extends RecordBase {
|
|
|
1571
1572
|
}
|
|
1572
1573
|
}
|
|
1573
1574
|
}
|
|
1574
|
-
class
|
|
1575
|
+
export class Field {
|
|
1575
1576
|
constructor(record, id, contents) {
|
|
1576
1577
|
this.record = record;
|
|
1577
1578
|
this.id = id;
|
|
@@ -1682,13 +1683,13 @@ class field {
|
|
|
1682
1683
|
});
|
|
1683
1684
|
}
|
|
1684
1685
|
}
|
|
1685
|
-
class
|
|
1686
|
+
export class Portal {
|
|
1686
1687
|
constructor(record, name) {
|
|
1687
1688
|
this.record = record;
|
|
1688
1689
|
this.name = name;
|
|
1689
1690
|
}
|
|
1690
1691
|
}
|
|
1691
|
-
class PortalRecord extends RecordBase {
|
|
1692
|
+
export class PortalRecord extends RecordBase {
|
|
1692
1693
|
constructor(record, portal, recordId, modId = recordId, fieldData = {}) {
|
|
1693
1694
|
super(record.layout, recordId, modId);
|
|
1694
1695
|
this.portal = portal;
|
|
@@ -1712,7 +1713,7 @@ class PortalRecord extends RecordBase {
|
|
|
1712
1713
|
return res;
|
|
1713
1714
|
}
|
|
1714
1715
|
}
|
|
1715
|
-
class
|
|
1716
|
+
export class RecordGetOperation {
|
|
1716
1717
|
constructor(layout) {
|
|
1717
1718
|
this.limit = 100;
|
|
1718
1719
|
this.limitPortals = [];
|
|
@@ -1752,11 +1753,11 @@ class recordGetOperation {
|
|
|
1752
1753
|
return this;
|
|
1753
1754
|
}
|
|
1754
1755
|
}
|
|
1755
|
-
class
|
|
1756
|
+
export class RecordGetRange extends RecordGetOperation {
|
|
1756
1757
|
constructor(layout) {
|
|
1757
1758
|
super(layout);
|
|
1758
1759
|
}
|
|
1759
|
-
generateQueryParams() {
|
|
1760
|
+
generateQueryParams(extraBody = {}) {
|
|
1760
1761
|
let params = [];
|
|
1761
1762
|
if (this.limit !== 100)
|
|
1762
1763
|
params.push("_limit=" + this.limit);
|
|
@@ -1773,15 +1774,32 @@ class recordGetRange extends recordGetOperation {
|
|
|
1773
1774
|
params.push("_limit." + item.portal.name.replace(/[^0-9A-z]/g, "") + "=" + item.limit);
|
|
1774
1775
|
}
|
|
1775
1776
|
}
|
|
1777
|
+
if (extraBody.scripts) {
|
|
1778
|
+
if (extraBody.scripts.prerequest) {
|
|
1779
|
+
params.push("script.prerequest=" + extraBody.scripts.prerequest.name);
|
|
1780
|
+
if (extraBody.scripts.prerequest.param)
|
|
1781
|
+
params.push("script.prerequest.param=" + extraBody.scripts.prerequest.param);
|
|
1782
|
+
}
|
|
1783
|
+
if (extraBody.scripts.presort) {
|
|
1784
|
+
params.push("script.presort=" + extraBody.scripts.presort.name);
|
|
1785
|
+
if (extraBody.scripts.presort.param)
|
|
1786
|
+
params.push("script.presort.param=" + extraBody.scripts.presort.param);
|
|
1787
|
+
}
|
|
1788
|
+
if (extraBody.scripts.after) {
|
|
1789
|
+
params.push("script=" + extraBody.scripts.after.name);
|
|
1790
|
+
if (extraBody.scripts.after.param)
|
|
1791
|
+
params.push("script.param=" + extraBody.scripts.after.param);
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1776
1794
|
if (params.length === 0)
|
|
1777
1795
|
return "";
|
|
1778
1796
|
return "?" + params.join("&");
|
|
1779
1797
|
}
|
|
1780
|
-
run() {
|
|
1798
|
+
run(extraBody = {}) {
|
|
1781
1799
|
return new Promise((resolve, reject) => {
|
|
1782
1800
|
// console.log(this.#toObject())
|
|
1783
1801
|
this.layout.getLayoutMeta().then(() => {
|
|
1784
|
-
return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams()}`, {
|
|
1802
|
+
return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
|
|
1785
1803
|
method: "GET"
|
|
1786
1804
|
});
|
|
1787
1805
|
})
|
|
@@ -1806,7 +1824,7 @@ class recordGetRange extends recordGetOperation {
|
|
|
1806
1824
|
});
|
|
1807
1825
|
}
|
|
1808
1826
|
}
|
|
1809
|
-
class
|
|
1827
|
+
export class Find extends RecordGetOperation {
|
|
1810
1828
|
constructor(layout) {
|
|
1811
1829
|
super(layout);
|
|
1812
1830
|
this.queries = [];
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jd-data-limited/easy-fm",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@types/btoa": "^1.2.3",
|
|
6
6
|
"@types/events": "^3.0.0",
|
|
7
7
|
"moment": "^2.29.4",
|
|
8
|
-
"node-fetch": "
|
|
8
|
+
"node-fetch": "3.2.8",
|
|
9
9
|
"typescript": "^4.9.4"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
package/src/index.ts
CHANGED
|
@@ -58,7 +58,7 @@ interface loginOptionsClaris {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
interface limitPortalsInterface {
|
|
61
|
-
portal:
|
|
61
|
+
portal: Portal,
|
|
62
62
|
offset: number,
|
|
63
63
|
limit: number
|
|
64
64
|
}
|
|
@@ -1307,8 +1307,8 @@ export class Database extends EventEmitter {
|
|
|
1307
1307
|
return (data as any)
|
|
1308
1308
|
}
|
|
1309
1309
|
|
|
1310
|
-
getLayout(name):
|
|
1311
|
-
return new
|
|
1310
|
+
getLayout(name): Layout {
|
|
1311
|
+
return new Layout(this, name)
|
|
1312
1312
|
}
|
|
1313
1313
|
|
|
1314
1314
|
setGlobals(globalFields): Promise<void> {
|
|
@@ -1341,9 +1341,9 @@ export class Database extends EventEmitter {
|
|
|
1341
1341
|
}
|
|
1342
1342
|
}
|
|
1343
1343
|
|
|
1344
|
-
class
|
|
1344
|
+
export class Layout {
|
|
1345
1345
|
readonly database: Database;
|
|
1346
|
-
readonly records = new
|
|
1346
|
+
readonly records = new LayourRecordManager(this)
|
|
1347
1347
|
protected name: string;
|
|
1348
1348
|
metadata: any;
|
|
1349
1349
|
|
|
@@ -1373,7 +1373,7 @@ class layout {
|
|
|
1373
1373
|
/**
|
|
1374
1374
|
* @deprecated use layout.records.find() instead
|
|
1375
1375
|
*/
|
|
1376
|
-
newFind():
|
|
1376
|
+
newFind(): Find {
|
|
1377
1377
|
return this.records.find()
|
|
1378
1378
|
}
|
|
1379
1379
|
|
|
@@ -1399,7 +1399,7 @@ class layout {
|
|
|
1399
1399
|
})
|
|
1400
1400
|
}
|
|
1401
1401
|
|
|
1402
|
-
public getLayoutMeta(): Promise<
|
|
1402
|
+
public getLayoutMeta(): Promise<Layout | FMError> {
|
|
1403
1403
|
return new Promise((resolve, reject) => {
|
|
1404
1404
|
if (this.metadata) {
|
|
1405
1405
|
resolve(this.metadata)
|
|
@@ -1415,10 +1415,10 @@ class layout {
|
|
|
1415
1415
|
}
|
|
1416
1416
|
}
|
|
1417
1417
|
|
|
1418
|
-
class
|
|
1419
|
-
readonly layout:
|
|
1418
|
+
class LayourRecordManager {
|
|
1419
|
+
readonly layout: Layout
|
|
1420
1420
|
|
|
1421
|
-
constructor(layout:
|
|
1421
|
+
constructor(layout: Layout) {
|
|
1422
1422
|
this.layout = layout
|
|
1423
1423
|
}
|
|
1424
1424
|
|
|
@@ -1455,20 +1455,20 @@ class layoutRecordManager {
|
|
|
1455
1455
|
}
|
|
1456
1456
|
|
|
1457
1457
|
range() {
|
|
1458
|
-
return new
|
|
1458
|
+
return new RecordGetRange(this.layout)
|
|
1459
1459
|
}
|
|
1460
1460
|
|
|
1461
|
-
find():
|
|
1462
|
-
return new
|
|
1461
|
+
find(): Find {
|
|
1462
|
+
return new Find(this.layout)
|
|
1463
1463
|
}
|
|
1464
1464
|
}
|
|
1465
1465
|
|
|
1466
|
-
class RecordBase extends EventEmitter {
|
|
1467
|
-
readonly layout:
|
|
1466
|
+
export class RecordBase extends EventEmitter {
|
|
1467
|
+
readonly layout: Layout;
|
|
1468
1468
|
public recordId: number;
|
|
1469
1469
|
modId: number;
|
|
1470
|
-
fields:
|
|
1471
|
-
portals:
|
|
1470
|
+
fields: Field[];
|
|
1471
|
+
portals: Portal[] = [];
|
|
1472
1472
|
protected portalData: any[];
|
|
1473
1473
|
|
|
1474
1474
|
constructor(layout, recordId, modId = recordId) {
|
|
@@ -1488,7 +1488,7 @@ class RecordBase extends EventEmitter {
|
|
|
1488
1488
|
|
|
1489
1489
|
protected processPortalData(portalData): void {
|
|
1490
1490
|
for (let item of Object.keys(portalData)) {
|
|
1491
|
-
let _portal = new
|
|
1491
|
+
let _portal = new Portal(this, item)
|
|
1492
1492
|
_portal.records = portalData[item].map(item => {
|
|
1493
1493
|
let fieldData = item;
|
|
1494
1494
|
delete fieldData.recordId;
|
|
@@ -1499,9 +1499,9 @@ class RecordBase extends EventEmitter {
|
|
|
1499
1499
|
}
|
|
1500
1500
|
}
|
|
1501
1501
|
|
|
1502
|
-
processFieldData(fieldData):
|
|
1502
|
+
processFieldData(fieldData): Field[] {
|
|
1503
1503
|
return Object.keys(fieldData).map(item => {
|
|
1504
|
-
let _field = new
|
|
1504
|
+
let _field = new Field(this, item, fieldData[item])
|
|
1505
1505
|
if (!!fieldData[item]) {
|
|
1506
1506
|
if (_field.metadata.result === "timeStamp") {
|
|
1507
1507
|
// @ts-ignore
|
|
@@ -1726,8 +1726,8 @@ class RecordBase extends EventEmitter {
|
|
|
1726
1726
|
return obj
|
|
1727
1727
|
}
|
|
1728
1728
|
}
|
|
1729
|
-
class LayoutRecord extends RecordBase {
|
|
1730
|
-
portals:
|
|
1729
|
+
export class LayoutRecord extends RecordBase {
|
|
1730
|
+
portals: Portal[];
|
|
1731
1731
|
|
|
1732
1732
|
constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null) {
|
|
1733
1733
|
super(layout, recordId, modId);
|
|
@@ -1739,7 +1739,7 @@ class LayoutRecord extends RecordBase {
|
|
|
1739
1739
|
}
|
|
1740
1740
|
}
|
|
1741
1741
|
|
|
1742
|
-
class
|
|
1742
|
+
export class Field {
|
|
1743
1743
|
record: RecordBase;
|
|
1744
1744
|
id: number;
|
|
1745
1745
|
private _value: string | number | Date;
|
|
@@ -1860,7 +1860,7 @@ class field {
|
|
|
1860
1860
|
}
|
|
1861
1861
|
}
|
|
1862
1862
|
|
|
1863
|
-
class
|
|
1863
|
+
export class Portal {
|
|
1864
1864
|
readonly record: RecordBase;
|
|
1865
1865
|
readonly name: string;
|
|
1866
1866
|
public records: PortalRecord[];
|
|
@@ -1871,8 +1871,8 @@ class portal {
|
|
|
1871
1871
|
}
|
|
1872
1872
|
}
|
|
1873
1873
|
|
|
1874
|
-
class PortalRecord extends RecordBase {
|
|
1875
|
-
readonly portal:
|
|
1874
|
+
export class PortalRecord extends RecordBase {
|
|
1875
|
+
readonly portal: Portal;
|
|
1876
1876
|
|
|
1877
1877
|
constructor(record, portal, recordId, modId = recordId, fieldData = {}) {
|
|
1878
1878
|
super(record.layout, recordId, modId);
|
|
@@ -1901,8 +1901,8 @@ class PortalRecord extends RecordBase {
|
|
|
1901
1901
|
}
|
|
1902
1902
|
}
|
|
1903
1903
|
|
|
1904
|
-
class
|
|
1905
|
-
protected layout:
|
|
1904
|
+
export class RecordGetOperation {
|
|
1905
|
+
protected layout: Layout
|
|
1906
1906
|
protected limit: number = 100
|
|
1907
1907
|
protected scripts: object
|
|
1908
1908
|
protected sort: object[]
|
|
@@ -1923,7 +1923,7 @@ class recordGetOperation {
|
|
|
1923
1923
|
addToPortalLimit() will adjust the results of the get request so that if a layout has multiple portals in it,
|
|
1924
1924
|
only data from the specified ones will be read. This may help reduce load on your FileMaker API
|
|
1925
1925
|
*/
|
|
1926
|
-
addToPortalLimit(portal:
|
|
1926
|
+
addToPortalLimit(portal: Portal, offset = 0, limit = 100) {
|
|
1927
1927
|
if (offset < 0) throw "Portal offset cannot be less than 0"
|
|
1928
1928
|
this.limitPortals.push({portal, offset, limit})
|
|
1929
1929
|
return this
|
|
@@ -1947,7 +1947,7 @@ class recordGetOperation {
|
|
|
1947
1947
|
}
|
|
1948
1948
|
}
|
|
1949
1949
|
|
|
1950
|
-
class
|
|
1950
|
+
export class RecordGetRange extends RecordGetOperation {
|
|
1951
1951
|
constructor(layout) {
|
|
1952
1952
|
super(layout)
|
|
1953
1953
|
}
|
|
@@ -2011,7 +2011,7 @@ class recordGetRange extends recordGetOperation {
|
|
|
2011
2011
|
}
|
|
2012
2012
|
}
|
|
2013
2013
|
|
|
2014
|
-
class
|
|
2014
|
+
export class Find extends RecordGetOperation {
|
|
2015
2015
|
protected queries: object[]
|
|
2016
2016
|
|
|
2017
2017
|
constructor(layout) {
|