@jd-data-limited/easy-fm 3.2.8 → 4.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.
- 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 +9 -8
- package/src/connection/database.js +6 -7
- package/src/connection/database.ts +14 -13
- 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 +3 -3
- package/src/layouts/layoutBase.js +1 -1
- package/src/layouts/layoutBase.ts +4 -5
- 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 +9 -14
- package/src/layouts/recordFieldsMap.d.ts +2 -2
- package/src/layouts/recordFieldsMap.js +1 -1
- package/src/layouts/recordFieldsMap.ts +3 -3
- 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 +8 -7
- package/src/records/layoutRecord.js +4 -2
- package/src/records/layoutRecord.ts +19 -11
- package/src/records/portal.d.ts +6 -5
- package/src/records/portal.js +1 -1
- package/src/records/portal.ts +7 -7
- 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 +6 -6
- package/src/records/portalRecord.js +3 -2
- package/src/records/portalRecord.ts +5 -5
- package/src/records/recordBase.d.ts +7 -12
- package/src/records/recordBase.js +6 -10
- package/src/records/recordBase.ts +10 -15
- 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
package/src/types.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import * as http from "http";
|
|
4
4
|
import { FMError } from "./FMError.js";
|
|
5
|
-
import { LayoutInterface } from "./layouts/layoutInterface";
|
|
6
|
-
export interface DatabaseStructure {
|
|
7
|
-
layouts: {
|
|
8
|
-
[key: string]: LayoutInterface;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
5
|
export interface databaseOptionsBase {
|
|
12
6
|
database: string;
|
|
13
7
|
credentials: loginOptionsOAuth | loginOptionsFileMaker | loginOptionsClaris | loginOptionsToken;
|
|
@@ -39,17 +33,18 @@ export interface loginOptionsClaris {
|
|
|
39
33
|
fmid: string;
|
|
40
34
|
};
|
|
41
35
|
}
|
|
42
|
-
export interface
|
|
43
|
-
portalName:
|
|
36
|
+
export interface portalFetchData<T = string> {
|
|
37
|
+
portalName: T;
|
|
44
38
|
offset: number;
|
|
45
39
|
limit: number;
|
|
46
40
|
}
|
|
41
|
+
export type ScriptRequestData = {
|
|
42
|
+
prerequest?: Script;
|
|
43
|
+
presort?: Script;
|
|
44
|
+
after?: Script;
|
|
45
|
+
};
|
|
47
46
|
export interface extraBodyOptions {
|
|
48
|
-
scripts?:
|
|
49
|
-
prerequest?: Script;
|
|
50
|
-
presort?: Script;
|
|
51
|
-
after?: Script;
|
|
52
|
-
};
|
|
47
|
+
scripts?: ScriptRequestData;
|
|
53
48
|
}
|
|
54
49
|
export declare enum DOWNLOAD_MODES {
|
|
55
50
|
Stream = 0,
|
|
@@ -118,3 +113,11 @@ export interface AuthorizationHeadersOAuth {
|
|
|
118
113
|
"X-FM-Data-OAuth-RequestId": string;
|
|
119
114
|
"X-FM-Data-OAuth-Identifier": string;
|
|
120
115
|
}
|
|
116
|
+
export type RecordFetchOptions = {
|
|
117
|
+
readonly portals: readonly string[];
|
|
118
|
+
};
|
|
119
|
+
export declare enum RecordTypes {
|
|
120
|
+
UNKNOWN = 0,
|
|
121
|
+
LAYOUT = 1,
|
|
122
|
+
PORTAL = 2
|
|
123
|
+
}
|
package/src/types.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c) 2022-
|
|
2
|
+
* Copyright (c) 2022-2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
4
|
export var DOWNLOAD_MODES;
|
|
5
5
|
(function (DOWNLOAD_MODES) {
|
|
6
6
|
DOWNLOAD_MODES[DOWNLOAD_MODES["Stream"] = 0] = "Stream";
|
|
7
7
|
DOWNLOAD_MODES[DOWNLOAD_MODES["Buffer"] = 1] = "Buffer";
|
|
8
8
|
})(DOWNLOAD_MODES || (DOWNLOAD_MODES = {}));
|
|
9
|
+
export var RecordTypes;
|
|
10
|
+
(function (RecordTypes) {
|
|
11
|
+
RecordTypes[RecordTypes["UNKNOWN"] = 0] = "UNKNOWN";
|
|
12
|
+
RecordTypes[RecordTypes["LAYOUT"] = 1] = "LAYOUT";
|
|
13
|
+
RecordTypes[RecordTypes["PORTAL"] = 2] = "PORTAL";
|
|
14
|
+
})(RecordTypes || (RecordTypes = {}));
|
package/src/types.ts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c) 2022-
|
|
2
|
+
* Copyright (c) 2022-2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
// const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
|
|
6
6
|
// @ts-ignore
|
|
7
7
|
import * as http from "http";
|
|
8
8
|
import {FMError} from "./FMError.js";
|
|
9
|
-
import {LayoutInterface} from "./layouts/layoutInterface";
|
|
10
|
-
|
|
11
|
-
// import * as btoa from "btoa";
|
|
12
|
-
export interface DatabaseStructure {
|
|
13
|
-
layouts: {
|
|
14
|
-
[key: string]: LayoutInterface
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
9
|
|
|
18
10
|
export interface databaseOptionsBase {
|
|
19
11
|
database: string
|
|
@@ -52,18 +44,20 @@ export interface loginOptionsClaris {
|
|
|
52
44
|
}
|
|
53
45
|
}
|
|
54
46
|
|
|
55
|
-
export interface
|
|
56
|
-
portalName:
|
|
47
|
+
export interface portalFetchData<T = string> {
|
|
48
|
+
portalName: T,
|
|
57
49
|
offset: number,
|
|
58
50
|
limit: number
|
|
59
51
|
}
|
|
60
52
|
|
|
53
|
+
export type ScriptRequestData = {
|
|
54
|
+
prerequest?: Script,
|
|
55
|
+
presort?: Script,
|
|
56
|
+
after?: Script,
|
|
57
|
+
}
|
|
58
|
+
|
|
61
59
|
export interface extraBodyOptions {
|
|
62
|
-
scripts?:
|
|
63
|
-
prerequest?: Script,
|
|
64
|
-
presort?: Script,
|
|
65
|
-
after?: Script,
|
|
66
|
-
}
|
|
60
|
+
scripts?: ScriptRequestData
|
|
67
61
|
}
|
|
68
62
|
|
|
69
63
|
export enum DOWNLOAD_MODES {
|
|
@@ -147,4 +141,14 @@ export interface AuthorizationHeadersOAuth {
|
|
|
147
141
|
"Content-Type": "application/json"
|
|
148
142
|
"X-FM-Data-OAuth-RequestId": string,
|
|
149
143
|
"X-FM-Data-OAuth-Identifier": string
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type RecordFetchOptions = {
|
|
147
|
+
readonly portals: readonly string[]
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export enum RecordTypes {
|
|
151
|
+
UNKNOWN,
|
|
152
|
+
LAYOUT,
|
|
153
|
+
PORTAL
|
|
150
154
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { RecordGetOperation } from "./recordGetOperation.js";
|
|
2
|
-
import { LayoutRecord } from "../layoutRecord.js";
|
|
3
|
-
import { LayoutInterface } from "../../layouts/layoutInterface";
|
|
4
|
-
import { LayoutBase } from "../../layouts/layoutBase.js";
|
|
5
|
-
export declare class Find<T extends LayoutInterface> extends RecordGetOperation<T> {
|
|
6
|
-
protected queries: object[];
|
|
7
|
-
constructor(layout: LayoutBase, start?: number, limit?: number);
|
|
8
|
-
private toObject;
|
|
9
|
-
addRequests(...requests: any[]): this;
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated in favour of .fetch()
|
|
12
|
-
*/
|
|
13
|
-
run(): Promise<LayoutRecord<T["fields"], T["portals"]>[]>;
|
|
14
|
-
fetch(): Promise<LayoutRecord<T["fields"], T["portals"]>[]>;
|
|
15
|
-
}
|
|
@@ -1,70 +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 Find extends RecordGetOperation {
|
|
8
|
-
queries;
|
|
9
|
-
constructor(layout, start = 0, limit = 100) {
|
|
10
|
-
super(layout);
|
|
11
|
-
this.setOffset(start);
|
|
12
|
-
this.setLimit(limit);
|
|
13
|
-
this.queries = [];
|
|
14
|
-
}
|
|
15
|
-
toObject() {
|
|
16
|
-
let out = { query: this.queries, sort: undefined };
|
|
17
|
-
if (this.sort.length !== 0)
|
|
18
|
-
out.sort = this.sort;
|
|
19
|
-
for (let item of Object.keys(this.scripts)) {
|
|
20
|
-
if (this.scripts[item]) {
|
|
21
|
-
out[item] = this.scripts[item].name;
|
|
22
|
-
if (this.scripts[item].parameter)
|
|
23
|
-
out[item + ".param"] = this.scripts[item].parameter;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (this.limit !== 100)
|
|
27
|
-
out["limit"] = this.limit;
|
|
28
|
-
if (this.offset !== 0)
|
|
29
|
-
out["offset"] = this.offset;
|
|
30
|
-
if (this.limitPortals.length > 0) {
|
|
31
|
-
out["portal"] = this.limitPortals.map(p => p.portalName);
|
|
32
|
-
for (let item of this.limitPortals) {
|
|
33
|
-
out["offset." + item.portalName.replace(/[^0-9A-z]/g, "")] = item.offset;
|
|
34
|
-
out["limit." + item.portalName.replace(/[^0-9A-z]/g, "")] = item.limit;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return out;
|
|
38
|
-
}
|
|
39
|
-
addRequests(...requests) {
|
|
40
|
-
for (let item of requests)
|
|
41
|
-
this.queries.push(item);
|
|
42
|
-
return this;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* @deprecated in favour of .fetch()
|
|
46
|
-
*/
|
|
47
|
-
run() {
|
|
48
|
-
return this.fetch();
|
|
49
|
-
}
|
|
50
|
-
async fetch() {
|
|
51
|
-
let trace = new Error();
|
|
52
|
-
await this.layout.getLayoutMeta();
|
|
53
|
-
let res = await this.layout.database.apiRequest(`${this.layout.endpoint}/_find`, {
|
|
54
|
-
port: 443,
|
|
55
|
-
method: "POST",
|
|
56
|
-
body: JSON.stringify(this.toObject())
|
|
57
|
-
});
|
|
58
|
-
if (res.messages[0].code === "0") {
|
|
59
|
-
// console.log("RESOLVING")
|
|
60
|
-
if (!this.layout.metadata)
|
|
61
|
-
await this.layout.getLayoutMeta();
|
|
62
|
-
return res.response.data.map(item => {
|
|
63
|
-
return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
throw new FMError(res.messages[0].code, res.httpStatus, res, trace);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
@@ -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
|
-
}
|