@jd-data-limited/easy-fm 4.0.11 → 4.0.12
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/bin/cli.d.ts +2 -0
- package/src/bin/cli.js +17 -0
- package/src/bin/generateTypes.d.ts +1 -0
- package/src/bin/generateTypes.js +161 -0
- package/src/bin/generateTypes.ts +10 -7
- package/src/index.d.ts +3 -3
- package/src/index.js +2 -2
- package/src/index.ts +4 -4
- package/src/layouts/recordFieldsMap.d.ts +2 -2
- package/src/layouts/recordFieldsMap.ts +2 -2
- package/src/records/field.d.ts +16 -10
- package/src/records/field.js +43 -59
- package/src/records/{fieldBase.ts → field.ts} +4 -11
- package/src/records/getOperations/recordGetOperation.d.ts +5 -1
- package/src/records/getOperations/recordGetOperation.js +22 -4
- package/src/records/getOperations/recordGetOperation.ts +26 -4
- package/src/records/layoutRecord.d.ts +3 -3
- package/src/records/layoutRecord.js +1 -1
- package/src/records/layoutRecord.ts +6 -6
- package/src/records/portalRecord.d.ts +2 -2
- package/src/records/portalRecord.ts +2 -2
- package/src/records/recordBase.d.ts +2 -2
- package/src/records/recordBase.js +5 -5
- package/src/records/recordBase.ts +7 -6
- package/src/utils/query.d.ts +4 -5
- package/src/utils/query.js +11 -4
- package/src/utils/query.ts +14 -7
- package/src/records/fieldBase.d.ts +0 -30
- package/src/records/fieldBase.js +0 -155
- package/src/records/getOperations/find.d.ts +0 -15
- package/src/records/getOperations/find.js +0 -80
- package/src/records/getOperations/recordGetRange.d.ts +0 -13
- package/src/records/getOperations/recordGetRange.js +0 -88
- package/src/records/portalRecordBase.d.ts +0 -4
- package/src/records/portalRecordBase.js +0 -6
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
|
-
*/
|
|
4
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
import { RecordGetOperation } from "./recordGetOperation.js";
|
|
14
|
-
import { LayoutRecord } from "../layoutRecord.js";
|
|
15
|
-
import { FMError } from "../../FMError.js";
|
|
16
|
-
export class Find extends RecordGetOperation {
|
|
17
|
-
constructor(layout, start = 0, limit = 100) {
|
|
18
|
-
super(layout);
|
|
19
|
-
this.setOffset(start);
|
|
20
|
-
this.setLimit(limit);
|
|
21
|
-
this.queries = [];
|
|
22
|
-
}
|
|
23
|
-
toObject() {
|
|
24
|
-
let out = { query: this.queries, sort: undefined };
|
|
25
|
-
if (this.sort.length !== 0)
|
|
26
|
-
out.sort = this.sort;
|
|
27
|
-
for (let item of Object.keys(this.scripts)) {
|
|
28
|
-
if (this.scripts[item]) {
|
|
29
|
-
out[item] = this.scripts[item].name;
|
|
30
|
-
if (this.scripts[item].parameter)
|
|
31
|
-
out[item + ".param"] = this.scripts[item].parameter;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (this.limit !== 100)
|
|
35
|
-
out["limit"] = this.limit;
|
|
36
|
-
if (this.offset !== 0)
|
|
37
|
-
out["offset"] = this.offset;
|
|
38
|
-
if (this.limitPortals.length > 0) {
|
|
39
|
-
out["portal"] = this.limitPortals.map(p => p.portalName);
|
|
40
|
-
for (let item of this.limitPortals) {
|
|
41
|
-
out["offset." + item.portalName.replace(/[^0-9A-z]/g, "")] = item.offset;
|
|
42
|
-
out["limit." + item.portalName.replace(/[^0-9A-z]/g, "")] = item.limit;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return out;
|
|
46
|
-
}
|
|
47
|
-
addRequests(...requests) {
|
|
48
|
-
for (let item of requests)
|
|
49
|
-
this.queries.push(item);
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* @deprecated in favour of .fetch()
|
|
54
|
-
*/
|
|
55
|
-
run() {
|
|
56
|
-
return this.fetch();
|
|
57
|
-
}
|
|
58
|
-
fetch() {
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
let trace = new Error();
|
|
61
|
-
yield this.layout.getLayoutMeta();
|
|
62
|
-
let res = yield this.layout.database.apiRequest(`${this.layout.endpoint}/_find`, {
|
|
63
|
-
port: 443,
|
|
64
|
-
method: "POST",
|
|
65
|
-
body: JSON.stringify(this.toObject())
|
|
66
|
-
});
|
|
67
|
-
if (res.messages[0].code === "0") {
|
|
68
|
-
// console.log("RESOLVING")
|
|
69
|
-
if (!this.layout.metadata)
|
|
70
|
-
yield this.layout.getLayoutMeta();
|
|
71
|
-
return res.response.data.map(item => {
|
|
72
|
-
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
throw new FMError(res.messages[0].code, res.httpStatus, res, trace);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
@@ -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,88 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
|
-
*/
|
|
4
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
import { RecordGetOperation } from "./recordGetOperation.js";
|
|
14
|
-
import { LayoutRecord } from "../layoutRecord.js";
|
|
15
|
-
import { FMError } from "../../FMError.js";
|
|
16
|
-
export class RecordGetRange extends RecordGetOperation {
|
|
17
|
-
constructor(layout, start = 0, limit = 100) {
|
|
18
|
-
super(layout);
|
|
19
|
-
this.setOffset(start);
|
|
20
|
-
this.setLimit(limit);
|
|
21
|
-
}
|
|
22
|
-
generateQueryParams(extraBody = {}) {
|
|
23
|
-
let params = [];
|
|
24
|
-
if (this.limit !== 100)
|
|
25
|
-
params.push("_limit=" + this.limit);
|
|
26
|
-
if (this.offset !== 0)
|
|
27
|
-
params.push("_offset=" + this.offset);
|
|
28
|
-
if (this.sort.length > 0)
|
|
29
|
-
params.push("_sort=" + encodeURI(JSON.stringify(this.sort)));
|
|
30
|
-
if (this.limitPortals.length > 0) {
|
|
31
|
-
params.push("portal=" + encodeURI(JSON.stringify(this.limitPortals.map(p => p.portalName))));
|
|
32
|
-
for (let item of this.limitPortals) {
|
|
33
|
-
if (item.offset !== 0)
|
|
34
|
-
params.push("_offset." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.offset);
|
|
35
|
-
if (item.limit !== 100)
|
|
36
|
-
params.push("_limit." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.limit);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (extraBody.scripts) {
|
|
40
|
-
if (extraBody.scripts.prerequest) {
|
|
41
|
-
params.push("script.prerequest=" + extraBody.scripts.prerequest.name);
|
|
42
|
-
if (extraBody.scripts.prerequest.parameter)
|
|
43
|
-
params.push("script.prerequest.param=" + extraBody.scripts.prerequest.parameter);
|
|
44
|
-
}
|
|
45
|
-
if (extraBody.scripts.presort) {
|
|
46
|
-
params.push("script.presort=" + extraBody.scripts.presort.name);
|
|
47
|
-
if (extraBody.scripts.presort.parameter)
|
|
48
|
-
params.push("script.presort.param=" + extraBody.scripts.presort.parameter);
|
|
49
|
-
}
|
|
50
|
-
if (extraBody.scripts.after) {
|
|
51
|
-
params.push("script=" + extraBody.scripts.after.name);
|
|
52
|
-
if (extraBody.scripts.after.parameter)
|
|
53
|
-
params.push("script.param=" + extraBody.scripts.after.parameter);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (params.length === 0)
|
|
57
|
-
return "";
|
|
58
|
-
return "?" + params.join("&");
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @deprecated in favour of .fetch()
|
|
62
|
-
*/
|
|
63
|
-
run(extraBody = {}) {
|
|
64
|
-
return this.fetch(extraBody);
|
|
65
|
-
}
|
|
66
|
-
fetch(extraBody = {}) {
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
let trace = new Error();
|
|
69
|
-
let res = yield this.layout.getLayoutMeta().then(() => {
|
|
70
|
-
return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
|
|
71
|
-
method: "GET"
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
if (res.messages[0].code === "0") {
|
|
75
|
-
// console.log("RESOLVING")
|
|
76
|
-
if (!this.layout.metadata)
|
|
77
|
-
yield this.layout.getLayoutMeta();
|
|
78
|
-
let data = res.response.data.map(item => {
|
|
79
|
-
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData);
|
|
80
|
-
});
|
|
81
|
-
return data;
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
throw new FMError(res.messages[0].code, res.httpStatus, res, trace);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|