@jd-data-limited/easy-fm 3.2.8 → 4.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.
- package/README.md +36 -24
- package/package.json +12 -9
- package/src/FMError.js +2 -2
- package/src/FMError.ts +2 -2
- package/src/connection/FMHost.d.ts +2 -1
- package/src/connection/FMHost.js +1 -2
- package/src/connection/FMHost.ts +4 -4
- package/src/connection/HostBase.d.ts +1 -1
- package/src/connection/HostBase.js +1 -1
- package/src/connection/HostBase.ts +2 -4
- package/src/connection/database.d.ts +10 -10
- package/src/connection/database.js +6 -17
- package/src/connection/database.ts +17 -27
- package/src/connection/databaseBase.d.ts +4 -4
- package/src/connection/databaseBase.js +1 -1
- package/src/connection/databaseBase.ts +4 -6
- package/src/databaseStructure.d.ts +6 -0
- package/src/databaseStructure.js +4 -0
- package/src/databaseStructure.ts +12 -0
- package/src/index.d.ts +3 -6
- package/src/index.js +3 -5
- package/src/index.ts +4 -9
- package/src/layouts/layout.d.ts +3 -17
- package/src/layouts/layout.js +2 -20
- package/src/layouts/layout.ts +5 -27
- package/src/layouts/layoutBase.d.ts +4 -4
- package/src/layouts/layoutBase.js +1 -1
- package/src/layouts/layoutBase.ts +5 -6
- package/src/layouts/layoutInterface.d.ts +1 -1
- package/src/layouts/layoutInterface.js +1 -1
- package/src/layouts/layoutInterface.ts +2 -2
- package/src/layouts/layoutRecordManager.d.ts +5 -6
- package/src/layouts/layoutRecordManager.js +5 -9
- package/src/layouts/layoutRecordManager.ts +12 -16
- package/src/layouts/recordFieldsMap.d.ts +2 -2
- package/src/layouts/recordFieldsMap.js +1 -1
- package/src/layouts/recordFieldsMap.ts +3 -3
- package/src/models/apiResults.d.ts +3 -3
- package/src/models/apiResults.js +1 -1
- package/src/models/apiResults.ts +2 -4
- package/src/records/field.d.ts +3 -23
- package/src/records/field.js +3 -152
- package/src/records/field.ts +4 -169
- package/src/records/fieldBase.d.ts +30 -0
- package/src/records/fieldBase.js +154 -0
- package/src/records/fieldBase.ts +174 -0
- package/src/records/getOperations/recordGetOperation.d.ts +47 -11
- package/src/records/getOperations/recordGetOperation.js +142 -31
- package/src/records/getOperations/recordGetOperation.ts +172 -30
- package/src/records/layoutRecord.d.ts +14 -11
- package/src/records/layoutRecord.js +7 -8
- package/src/records/layoutRecord.ts +32 -22
- package/src/records/portal.d.ts +6 -5
- package/src/records/portal.js +1 -1
- package/src/records/portal.ts +10 -8
- package/src/records/portalBase.d.ts +5 -4
- package/src/records/portalBase.js +1 -1
- package/src/records/portalBase.ts +6 -6
- package/src/records/portalRecord.d.ts +12 -8
- package/src/records/portalRecord.js +6 -8
- package/src/records/portalRecord.ts +17 -16
- package/src/records/recordBase.d.ts +11 -15
- package/src/records/recordBase.js +9 -13
- package/src/records/recordBase.ts +17 -25
- package/src/types.d.ts +18 -15
- package/src/types.js +7 -1
- package/src/types.ts +20 -16
- package/src/records/getOperations/find.d.ts +0 -15
- package/src/records/getOperations/find.js +0 -70
- package/src/records/getOperations/find.ts +0 -77
- package/src/records/getOperations/recordGetRange.d.ts +0 -13
- package/src/records/getOperations/recordGetRange.js +0 -77
- package/src/records/getOperations/recordGetRange.ts +0 -77
- package/src/records/portalRecordBase.d.ts +0 -4
- package/src/records/portalRecordBase.js +0 -6
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {RecordGetOperation} from "./recordGetOperation.js";
|
|
6
|
-
import {LayoutRecord} from "../layoutRecord.js";
|
|
7
|
-
import {LayoutInterface} from "../../layouts/layoutInterface";
|
|
8
|
-
import {LayoutBase} from "../../layouts/layoutBase.js";
|
|
9
|
-
import {FMError} from "../../FMError.js";
|
|
10
|
-
import {ApiRecordResponseObj} from "../../models/apiResults";
|
|
11
|
-
|
|
12
|
-
export class Find<T extends LayoutInterface> extends RecordGetOperation<T> {
|
|
13
|
-
protected queries: object[]
|
|
14
|
-
|
|
15
|
-
constructor(layout: LayoutBase, start = 0, limit = 100) {
|
|
16
|
-
super(layout)
|
|
17
|
-
this.setOffset(start)
|
|
18
|
-
this.setLimit(limit)
|
|
19
|
-
this.queries = []
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
private toObject() {
|
|
23
|
-
let out = {query: this.queries, sort: undefined}
|
|
24
|
-
if (this.sort.length !== 0) out.sort = this.sort
|
|
25
|
-
|
|
26
|
-
for (let item of Object.keys(this.scripts)) {
|
|
27
|
-
if (this.scripts[item]) {
|
|
28
|
-
out[item] = this.scripts[item].name
|
|
29
|
-
if (this.scripts[item].parameter) out[item + ".param"] = this.scripts[item].parameter
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (this.limit !== 100) out["limit"] = this.limit
|
|
34
|
-
if (this.offset !== 0) out["offset"] = this.offset
|
|
35
|
-
if (this.limitPortals.length > 0) {
|
|
36
|
-
out["portal"] = this.limitPortals.map(p => p.portalName)
|
|
37
|
-
for (let item of this.limitPortals) {
|
|
38
|
-
out["offset." + item.portalName.replace(/[^0-9A-z]/g, "")] = item.offset
|
|
39
|
-
out["limit." + item.portalName.replace(/[^0-9A-z]/g, "")] = item.limit
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return out
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
addRequests(...requests) {
|
|
47
|
-
for (let item of requests) this.queries.push(item)
|
|
48
|
-
return this
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @deprecated in favour of .fetch()
|
|
53
|
-
*/
|
|
54
|
-
run() {
|
|
55
|
-
return this.fetch()
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async fetch(): Promise<LayoutRecord<T["fields"], T["portals"]>[]> {
|
|
59
|
-
let trace = new Error()
|
|
60
|
-
await this.layout.getLayoutMeta()
|
|
61
|
-
let res = await this.layout.database.apiRequest<ApiRecordResponseObj>(`${this.layout.endpoint}/_find`, {
|
|
62
|
-
port: 443,
|
|
63
|
-
method: "POST",
|
|
64
|
-
body: JSON.stringify(this.toObject())
|
|
65
|
-
})
|
|
66
|
-
if (res.messages[0].code === "0") {
|
|
67
|
-
// console.log("RESOLVING")
|
|
68
|
-
if (!this.layout.metadata) await this.layout.getLayoutMeta()
|
|
69
|
-
return res.response.data.map(item => {
|
|
70
|
-
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData)
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
throw new FMError(res.messages[0].code, res.httpStatus, res, trace)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { LayoutInterface } from "../../layouts/layoutInterface.js";
|
|
2
|
-
import { RecordGetOperation } from "./recordGetOperation.js";
|
|
3
|
-
import { LayoutRecord } from "../layoutRecord.js";
|
|
4
|
-
import { extraBodyOptions } from "../../types.js";
|
|
5
|
-
export declare class RecordGetRange<T extends LayoutInterface> extends RecordGetOperation<T> {
|
|
6
|
-
constructor(layout: any, start?: number, limit?: number);
|
|
7
|
-
private generateQueryParams;
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated in favour of .fetch()
|
|
10
|
-
*/
|
|
11
|
-
run(extraBody?: extraBodyOptions): Promise<LayoutRecord<T["fields"], T["portals"]>[]>;
|
|
12
|
-
fetch(extraBody?: extraBodyOptions): Promise<LayoutRecord<T["fields"], T["portals"]>[]>;
|
|
13
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
|
-
*/
|
|
4
|
-
import { RecordGetOperation } from "./recordGetOperation.js";
|
|
5
|
-
import { LayoutRecord } from "../layoutRecord.js";
|
|
6
|
-
import { FMError } from "../../FMError.js";
|
|
7
|
-
export class RecordGetRange extends RecordGetOperation {
|
|
8
|
-
constructor(layout, start = 0, limit = 100) {
|
|
9
|
-
super(layout);
|
|
10
|
-
this.setOffset(start);
|
|
11
|
-
this.setLimit(limit);
|
|
12
|
-
}
|
|
13
|
-
generateQueryParams(extraBody = {}) {
|
|
14
|
-
let params = [];
|
|
15
|
-
if (this.limit !== 100)
|
|
16
|
-
params.push("_limit=" + this.limit);
|
|
17
|
-
if (this.offset !== 0)
|
|
18
|
-
params.push("_offset=" + this.offset);
|
|
19
|
-
if (this.sort.length > 0)
|
|
20
|
-
params.push("_sort=" + encodeURI(JSON.stringify(this.sort)));
|
|
21
|
-
if (this.limitPortals.length > 0) {
|
|
22
|
-
params.push("portal=" + encodeURI(JSON.stringify(this.limitPortals.map(p => p.portalName))));
|
|
23
|
-
for (let item of this.limitPortals) {
|
|
24
|
-
if (item.offset !== 0)
|
|
25
|
-
params.push("_offset." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.offset);
|
|
26
|
-
if (item.limit !== 100)
|
|
27
|
-
params.push("_limit." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.limit);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (extraBody.scripts) {
|
|
31
|
-
if (extraBody.scripts.prerequest) {
|
|
32
|
-
params.push("script.prerequest=" + extraBody.scripts.prerequest.name);
|
|
33
|
-
if (extraBody.scripts.prerequest.parameter)
|
|
34
|
-
params.push("script.prerequest.param=" + extraBody.scripts.prerequest.parameter);
|
|
35
|
-
}
|
|
36
|
-
if (extraBody.scripts.presort) {
|
|
37
|
-
params.push("script.presort=" + extraBody.scripts.presort.name);
|
|
38
|
-
if (extraBody.scripts.presort.parameter)
|
|
39
|
-
params.push("script.presort.param=" + extraBody.scripts.presort.parameter);
|
|
40
|
-
}
|
|
41
|
-
if (extraBody.scripts.after) {
|
|
42
|
-
params.push("script=" + extraBody.scripts.after.name);
|
|
43
|
-
if (extraBody.scripts.after.parameter)
|
|
44
|
-
params.push("script.param=" + extraBody.scripts.after.parameter);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (params.length === 0)
|
|
48
|
-
return "";
|
|
49
|
-
return "?" + params.join("&");
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* @deprecated in favour of .fetch()
|
|
53
|
-
*/
|
|
54
|
-
run(extraBody = {}) {
|
|
55
|
-
return this.fetch(extraBody);
|
|
56
|
-
}
|
|
57
|
-
async fetch(extraBody = {}) {
|
|
58
|
-
let trace = new Error();
|
|
59
|
-
let res = await this.layout.getLayoutMeta().then(() => {
|
|
60
|
-
return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
|
|
61
|
-
method: "GET"
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
if (res.messages[0].code === "0") {
|
|
65
|
-
// console.log("RESOLVING")
|
|
66
|
-
if (!this.layout.metadata)
|
|
67
|
-
await this.layout.getLayoutMeta();
|
|
68
|
-
let data = res.response.data.map(item => {
|
|
69
|
-
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData);
|
|
70
|
-
});
|
|
71
|
-
return data;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
throw new FMError(res.messages[0].code, res.httpStatus, res, trace);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {LayoutInterface} from "../../layouts/layoutInterface.js";
|
|
6
|
-
import {RecordGetOperation} from "./recordGetOperation.js";
|
|
7
|
-
import {LayoutRecord} from "../layoutRecord.js";
|
|
8
|
-
import {extraBodyOptions} from "../../types.js";
|
|
9
|
-
import {FMError} from "../../FMError.js";
|
|
10
|
-
import {ApiRecordResponseObj} from "../../models/apiResults";
|
|
11
|
-
|
|
12
|
-
export class RecordGetRange<T extends LayoutInterface> extends RecordGetOperation<T> {
|
|
13
|
-
constructor(layout, start = 0, limit = 100) {
|
|
14
|
-
super(layout)
|
|
15
|
-
this.setOffset(start)
|
|
16
|
-
this.setLimit(limit)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
private generateQueryParams(extraBody: extraBodyOptions = {}) {
|
|
20
|
-
let params = []
|
|
21
|
-
if (this.limit !== 100) params.push("_limit=" + this.limit)
|
|
22
|
-
if (this.offset !== 0) params.push("_offset=" + this.offset)
|
|
23
|
-
if (this.sort.length > 0) params.push("_sort=" + encodeURI(JSON.stringify(this.sort)))
|
|
24
|
-
if (this.limitPortals.length > 0) {
|
|
25
|
-
params.push("portal=" + encodeURI(JSON.stringify(this.limitPortals.map(p => p.portalName))))
|
|
26
|
-
for (let item of this.limitPortals) {
|
|
27
|
-
if (item.offset !== 0) params.push("_offset." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.offset)
|
|
28
|
-
if (item.limit !== 100) params.push("_limit." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.limit)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (extraBody.scripts) {
|
|
32
|
-
if (extraBody.scripts.prerequest) {
|
|
33
|
-
params.push("script.prerequest=" + extraBody.scripts.prerequest.name)
|
|
34
|
-
if (extraBody.scripts.prerequest.parameter) params.push("script.prerequest.param=" + extraBody.scripts.prerequest.parameter)
|
|
35
|
-
}
|
|
36
|
-
if (extraBody.scripts.presort) {
|
|
37
|
-
params.push("script.presort=" + extraBody.scripts.presort.name)
|
|
38
|
-
if (extraBody.scripts.presort.parameter) params.push("script.presort.param=" + extraBody.scripts.presort.parameter)
|
|
39
|
-
}
|
|
40
|
-
if (extraBody.scripts.after) {
|
|
41
|
-
params.push("script=" + extraBody.scripts.after.name)
|
|
42
|
-
if (extraBody.scripts.after.parameter) params.push("script.param=" + extraBody.scripts.after.parameter)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (params.length === 0) return ""
|
|
47
|
-
return "?" + params.join("&")
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @deprecated in favour of .fetch()
|
|
52
|
-
*/
|
|
53
|
-
run(extraBody: extraBodyOptions = {}): Promise<LayoutRecord<T["fields"], T["portals"]>[]> {
|
|
54
|
-
return this.fetch(extraBody)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
async fetch(extraBody: extraBodyOptions = {}): Promise<LayoutRecord<T["fields"], T["portals"]>[]> {
|
|
58
|
-
let trace = new Error()
|
|
59
|
-
let res = await this.layout.getLayoutMeta().then(() => {
|
|
60
|
-
return this.layout.database.apiRequest<ApiRecordResponseObj>(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
|
|
61
|
-
method: "GET"
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
if (res.messages[0].code === "0") {
|
|
66
|
-
// console.log("RESOLVING")
|
|
67
|
-
if (!this.layout.metadata) await this.layout.getLayoutMeta()
|
|
68
|
-
let data = res.response.data.map(item => {
|
|
69
|
-
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData)
|
|
70
|
-
})
|
|
71
|
-
return data
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
throw new FMError(res.messages[0].code, res.httpStatus, res, trace)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|