@jd-data-limited/easy-fm 3.2.6 → 3.2.8
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 +10 -6
- package/src/FMError.d.ts +1 -1
- package/src/FMError.js +5 -0
- package/src/FMError.ts +1 -1
- package/src/connection/FMHost.d.ts +1 -1
- package/src/connection/FMHost.js +36 -45
- package/src/connection/FMHost.ts +3 -3
- package/src/connection/database.d.ts +5 -3
- package/src/connection/database.js +90 -112
- package/src/connection/database.ts +70 -82
- package/src/connection/databaseBase.d.ts +4 -1
- package/src/connection/databaseBase.ts +4 -1
- package/src/layouts/layout.d.ts +3 -3
- package/src/layouts/layout.js +26 -50
- package/src/layouts/layout.ts +22 -39
- package/src/layouts/layoutBase.d.ts +2 -2
- package/src/layouts/layoutBase.ts +2 -1
- package/src/layouts/layoutRecordManager.d.ts +1 -1
- package/src/layouts/layoutRecordManager.js +16 -31
- package/src/layouts/layoutRecordManager.ts +14 -30
- package/src/models/apiResults.d.ts +103 -0
- package/src/models/apiResults.js +28 -0
- package/src/models/apiResults.ts +112 -0
- package/src/records/field.d.ts +3 -2
- package/src/records/field.js +44 -68
- package/src/records/field.ts +46 -64
- package/src/records/getOperations/find.js +18 -38
- package/src/records/getOperations/find.ts +17 -28
- package/src/records/getOperations/recordGetOperation.js +7 -4
- package/src/records/getOperations/recordGetOperation.ts +1 -1
- package/src/records/getOperations/recordGetRange.js +16 -34
- package/src/records/getOperations/recordGetRange.ts +17 -24
- package/src/records/layoutRecord.js +103 -151
- package/src/records/layoutRecord.ts +101 -133
- package/src/records/portal.js +3 -0
- package/src/records/portalRecord.js +2 -1
- package/src/records/recordBase.js +6 -1
- package/src/types.d.ts +0 -4
- package/src/types.ts +1 -7
- package/.expo/README.md +0 -15
- package/.expo/settings.json +0 -8
- package/.idea/compiler.xml +0 -7
- package/.idea/copyright/JD_Data.xml +0 -6
- package/.idea/copyright/profiles_settings.xml +0 -7
- package/.idea/discord.xml +0 -7
- package/.idea/easy-fm.iml +0 -8
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/php.xml +0 -18
- package/.idea/vcs.xml +0 -6
- package/decs.d.ts +0 -7
- package/dist/index.min.js +0 -2
- package/dist/index.min.js.LICENSE.txt +0 -3
- package/docs/classes/FileMakerConnection.md +0 -86
- package/docs/classes/layout.md +0 -0
- package/examples/test.js +0 -7
- package/fmErrors.json +0 -1010
- package/img.png +0 -0
- package/test.d.ts +0 -2
- package/test.js +0 -30
- package/test.ts +0 -33
- package/test2.d.ts +0 -1
- package/test2.js +0 -15
- package/tsconfig.json +0 -16
- package/webpack.config.cjs +0 -20
|
@@ -12,13 +12,13 @@ import HTTP_REDIRECT from "follow-redirects"
|
|
|
12
12
|
import {
|
|
13
13
|
databaseOptionsBase,
|
|
14
14
|
databaseOptionsWithExternalSources, DatabaseStructure,
|
|
15
|
-
fileMakerResponse,
|
|
16
15
|
loginOptionsFileMaker,
|
|
17
16
|
loginOptionsToken,
|
|
18
17
|
Script
|
|
19
18
|
} from "../types.js";
|
|
20
19
|
import {HostBase} from "./HostBase.js"
|
|
21
20
|
import {DatabaseBase} from "./databaseBase";
|
|
21
|
+
import {ApiLayout, ApiResults} from "../models/apiResults";
|
|
22
22
|
|
|
23
23
|
type GetLayoutReturnType<T extends DatabaseStructure, R extends LayoutInterface | string> = R extends string ? T["layouts"][R] : R
|
|
24
24
|
|
|
@@ -50,67 +50,55 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
logout(): Promise<void> {
|
|
54
|
-
|
|
55
|
-
if (!this.token) reject(new Error("Not logged in"))
|
|
53
|
+
async logout(): Promise<void> {
|
|
54
|
+
if (!this.token) throw new Error("Not logged in")
|
|
56
55
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
})
|
|
63
|
-
let data = await _fetch.json()
|
|
64
|
-
// console.log(data)
|
|
65
|
-
this._token = null
|
|
66
|
-
resolve()
|
|
56
|
+
let _fetch = await fetch(`${this.endpoint}/sessions/${this.token}`, {
|
|
57
|
+
method: "DELETE",
|
|
58
|
+
headers: {
|
|
59
|
+
"content-type": "application/json"
|
|
60
|
+
}
|
|
67
61
|
})
|
|
62
|
+
let data = await _fetch.json()
|
|
63
|
+
// console.log(data)
|
|
64
|
+
this._token = null
|
|
68
65
|
}
|
|
69
66
|
|
|
70
|
-
login() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
this.cookies = {}
|
|
67
|
+
async login() {
|
|
68
|
+
// Reset cookies
|
|
69
|
+
this.cookies = {}
|
|
74
70
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
} catch (e) {
|
|
78
|
-
reject(e)
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
if (this.token) throw new Error("Already logged in. Run logout() first")
|
|
71
|
+
await this.host.getMetadata()
|
|
72
|
+
if (this.token) throw new Error("Already logged in. Run logout() first")
|
|
82
73
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
74
|
+
if (this.connection_details.credentials.method === "token") {
|
|
75
|
+
this._token = (<loginOptionsToken>this.connection_details.credentials).token
|
|
76
|
+
return this.token
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
console.time()
|
|
80
|
+
let res = await fetch(`${this.endpoint}/sessions`, {
|
|
81
|
+
hostname: this.host.hostname,
|
|
82
|
+
port: 443,
|
|
83
|
+
method: "POST",
|
|
84
|
+
headers: generateAuthorizationHeaders(this.connection_details.credentials) as unknown as HeadersInit,
|
|
85
|
+
body: JSON.stringify({
|
|
86
|
+
fmDataSource: this.connection_details.externalSources.map(i => {
|
|
87
|
+
let _i = <databaseOptionsBase>i
|
|
88
|
+
return this.generateExternalSourceLogin(_i)
|
|
98
89
|
})
|
|
99
|
-
}).then(async res => {
|
|
100
|
-
let _res = <any>(await res.json())
|
|
101
|
-
if (res.status === 200) {
|
|
102
|
-
this._token = res.headers.get('x-fm-data-access-token')
|
|
103
|
-
resolve(this._token)
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
reject(new FMError(_res.messages[0].code, _res.status, res))
|
|
107
|
-
}
|
|
108
90
|
})
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
91
|
+
})
|
|
92
|
+
console.time()
|
|
93
|
+
let _res = <any>(await res.json())
|
|
94
|
+
if (res.status === 200) {
|
|
95
|
+
this._token = res.headers.get('x-fm-data-access-token')
|
|
96
|
+
return this._token
|
|
112
97
|
}
|
|
113
|
-
|
|
98
|
+
else {
|
|
99
|
+
throw new FMError(_res.messages[0].code, _res.status, res)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
114
102
|
}
|
|
115
103
|
|
|
116
104
|
get token() {
|
|
@@ -121,7 +109,7 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
|
|
|
121
109
|
return `${this.host.hostname}/fmi/data/v2/databases/${this.name}`
|
|
122
110
|
}
|
|
123
111
|
|
|
124
|
-
async apiRequest<T = any>(url: string | Request, options: any = {}, autoRelogin = true): Promise<T
|
|
112
|
+
async apiRequest<T = any>(url: string | Request, options: any = {}, autoRelogin = true): Promise<ApiResults<T>> {
|
|
125
113
|
if (!options.headers) options.headers = {}
|
|
126
114
|
options.headers["content-type"] = options.headers["content-type"] ? options.headers["content-type"] : "application/json"
|
|
127
115
|
options.headers["authorization"] = "Bearer " + this._token
|
|
@@ -134,14 +122,30 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
|
|
|
134
122
|
this.cookies[cookie_split[0]] = cookie_split[1]
|
|
135
123
|
}
|
|
136
124
|
}
|
|
137
|
-
let data = await _fetch.json() as
|
|
125
|
+
let data = await _fetch.json() as ApiResults<T>
|
|
126
|
+
|
|
127
|
+
// Remove response if it is empty. This makes checking for an empty response easier
|
|
128
|
+
if (Object.keys(data.response).length === 0) delete data.response
|
|
129
|
+
|
|
138
130
|
// console.log(data.messages[0])
|
|
139
|
-
if (data.messages[0].code
|
|
131
|
+
if (data.messages[0].code === "952" && autoRelogin) {
|
|
140
132
|
this._token = null
|
|
141
133
|
await this.login()
|
|
142
134
|
return await this.apiRequest(url, options, false)
|
|
143
135
|
}
|
|
144
|
-
|
|
136
|
+
else if (data.messages[0].code !== "0") {
|
|
137
|
+
throw new FMError(data.messages[0].code, _fetch.status, data)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
data.httpStatus = _fetch.status
|
|
141
|
+
return data
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async listLayouts() {
|
|
145
|
+
let req = await this.apiRequest<{layouts: ApiLayout[]}>(`${this.endpoint}/layouts`)
|
|
146
|
+
if (!req.response) throw new FMError(req.messages[0].code, req.httpStatus, req.messages[0].message)
|
|
147
|
+
|
|
148
|
+
return req.response.layouts.filter(i => !i.isFolder).map(layout => new Layout(this, layout.name))
|
|
145
149
|
}
|
|
146
150
|
|
|
147
151
|
getLayout<R extends string>(name: R): Layout<T["layouts"][R]>
|
|
@@ -150,25 +154,14 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
|
|
|
150
154
|
return new Layout<LayoutInterface>(this, name)
|
|
151
155
|
}
|
|
152
156
|
|
|
153
|
-
|
|
157
|
+
/*
|
|
158
|
+
@deprecated
|
|
159
|
+
*/
|
|
160
|
+
async setGlobals(globalFields) {
|
|
154
161
|
// console.log({globalFields})
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
body: JSON.stringify({globalFields})
|
|
159
|
-
}).then(res => {
|
|
160
|
-
// console.log(res)
|
|
161
|
-
if (res.messages[0].code === "0") {
|
|
162
|
-
resolve()
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
reject(
|
|
166
|
-
(res.messages[0].code, res.status, res))
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
|
-
.catch(e => {
|
|
170
|
-
reject(e)
|
|
171
|
-
})
|
|
162
|
+
await this.apiRequest(`${this.endpoint}/globals`, {
|
|
163
|
+
method: "PATCH",
|
|
164
|
+
body: JSON.stringify({globalFields})
|
|
172
165
|
})
|
|
173
166
|
}
|
|
174
167
|
|
|
@@ -180,15 +173,10 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
|
|
|
180
173
|
this.emit("token_expired")
|
|
181
174
|
}
|
|
182
175
|
|
|
183
|
-
|
|
176
|
+
streamURL(url: string): Promise<HTTP_REDIRECT.http.IncomingMessage> {
|
|
184
177
|
return new Promise((resolve, reject) => {
|
|
185
|
-
if (field.metadata.result !== "container") {
|
|
186
|
-
reject("Cannot stream the field " + field.id + " as it is not a container")
|
|
187
|
-
return
|
|
188
|
-
}
|
|
189
178
|
if (!url || typeof url !== "string") {
|
|
190
|
-
|
|
191
|
-
return
|
|
179
|
+
throw new Error("URL is empty, or has invalid value")
|
|
192
180
|
}
|
|
193
181
|
|
|
194
182
|
let headers = {}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { HostBase } from "./HostBase.js";
|
|
2
2
|
import { Request } from "node-fetch";
|
|
3
|
+
import { ApiResults } from "../models/apiResults";
|
|
4
|
+
import HTTP_REDIRECT from "follow-redirects";
|
|
3
5
|
export interface DatabaseBase {
|
|
4
6
|
host: HostBase;
|
|
5
7
|
readonly name: string;
|
|
6
8
|
endpoint: string;
|
|
7
|
-
apiRequest(url: string | Request, options?: any, autoRelogin?: boolean): Promise<
|
|
9
|
+
apiRequest<T = unknown>(url: string | Request, options?: any, autoRelogin?: boolean): Promise<ApiResults<T>>;
|
|
10
|
+
streamURL(url: string): Promise<HTTP_REDIRECT.http.IncomingMessage>;
|
|
8
11
|
}
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
import {HostBase} from "./HostBase.js"
|
|
6
6
|
import {Request} from "node-fetch";
|
|
7
7
|
import {DatabaseStructure} from "../types";
|
|
8
|
+
import {ApiResults} from "../models/apiResults";
|
|
9
|
+
import HTTP_REDIRECT from "follow-redirects"
|
|
8
10
|
|
|
9
11
|
export interface DatabaseBase {
|
|
10
12
|
host: HostBase,
|
|
@@ -13,5 +15,6 @@ export interface DatabaseBase {
|
|
|
13
15
|
|
|
14
16
|
// layouts: DatabaseStructure["layouts"]
|
|
15
17
|
|
|
16
|
-
apiRequest(url: string | Request, options?: any, autoRelogin?: boolean): Promise<
|
|
18
|
+
apiRequest<T = unknown>(url: string | Request, options?: any, autoRelogin?: boolean): Promise<ApiResults<T>>
|
|
19
|
+
streamURL(url: string): Promise<HTTP_REDIRECT.http.IncomingMessage>
|
|
17
20
|
}
|
package/src/layouts/layout.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { LayoutRecord } from "../records/layoutRecord.js";
|
|
|
3
3
|
import { Script, ScriptResult } from "../types.js";
|
|
4
4
|
import { LayoutInterface } from "./layoutInterface.js";
|
|
5
5
|
import { Find } from "../records/getOperations/find.js";
|
|
6
|
-
import { FMError } from "../FMError.js";
|
|
7
6
|
import { LayoutBase } from "./layoutBase.js";
|
|
8
7
|
import { DatabaseBase } from "../connection/databaseBase";
|
|
8
|
+
import { ApiLayoutMetadata } from "../models/apiResults";
|
|
9
9
|
export declare class Layout<T extends LayoutInterface> implements LayoutBase {
|
|
10
10
|
readonly database: DatabaseBase;
|
|
11
11
|
readonly records: LayoutRecordManager<T>;
|
|
12
12
|
readonly name: string;
|
|
13
|
-
metadata:
|
|
13
|
+
metadata: ApiLayoutMetadata;
|
|
14
14
|
constructor(database: DatabaseBase, name: string);
|
|
15
15
|
get endpoint(): string;
|
|
16
16
|
/**
|
|
@@ -26,5 +26,5 @@ export declare class Layout<T extends LayoutInterface> implements LayoutBase {
|
|
|
26
26
|
*/
|
|
27
27
|
newFind(): Find<T>;
|
|
28
28
|
runScript(script: Script): Promise<ScriptResult>;
|
|
29
|
-
getLayoutMeta(): Promise<
|
|
29
|
+
getLayoutMeta(): Promise<ApiLayoutMetadata>;
|
|
30
30
|
}
|
package/src/layouts/layout.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
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
4
|
import { LayoutRecordManager } from "./layoutRecordManager.js";
|
|
14
5
|
import { FMError } from "../FMError.js";
|
|
15
6
|
export class Layout {
|
|
7
|
+
database;
|
|
8
|
+
records = new LayoutRecordManager(this);
|
|
9
|
+
name;
|
|
10
|
+
metadata;
|
|
16
11
|
constructor(database, name) {
|
|
17
|
-
this.records = new LayoutRecordManager(this);
|
|
18
12
|
this.database = database;
|
|
19
13
|
this.name = name;
|
|
20
14
|
}
|
|
@@ -39,46 +33,28 @@ export class Layout {
|
|
|
39
33
|
newFind() {
|
|
40
34
|
return this.records.find();
|
|
41
35
|
}
|
|
42
|
-
runScript(script) {
|
|
43
|
-
let
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
port: 443,
|
|
50
|
-
method: "GET"
|
|
51
|
-
})
|
|
52
|
-
.then(res => {
|
|
53
|
-
if (res.messages[0].code === "0") {
|
|
54
|
-
let error = parseInt(res.response.scriptError);
|
|
55
|
-
let msg = {
|
|
56
|
-
scriptError: error ? new FMError(error, 200, res, trace) : undefined,
|
|
57
|
-
scriptResult: res.response.scriptResult
|
|
58
|
-
};
|
|
59
|
-
resolve(msg);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
// console.log(res)
|
|
63
|
-
reject(new FMError(res.messages[0].code, res.status, res, trace));
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
.catch(e => {
|
|
67
|
-
reject(e);
|
|
68
|
-
});
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
getLayoutMeta() {
|
|
72
|
-
return new Promise((resolve, reject) => {
|
|
73
|
-
if (this.metadata) {
|
|
74
|
-
resolve(this.metadata);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
this.database.apiRequest(this.endpoint).then(res => {
|
|
78
|
-
this.metadata = res.response;
|
|
79
|
-
resolve(this);
|
|
80
|
-
})
|
|
81
|
-
.catch(e => reject(e));
|
|
36
|
+
async runScript(script) {
|
|
37
|
+
let url = `${this.endpoint}/script/${encodeURIComponent(script.name)}`;
|
|
38
|
+
if (script.parameter)
|
|
39
|
+
url += "?script.param=" + encodeURIComponent(script.parameter);
|
|
40
|
+
let res = await this.database.apiRequest(url, {
|
|
41
|
+
port: 443,
|
|
42
|
+
method: "GET"
|
|
82
43
|
});
|
|
44
|
+
if (res.messages[0].code === "0") {
|
|
45
|
+
let error = parseInt(res.response.scriptError);
|
|
46
|
+
return {
|
|
47
|
+
scriptError: error ? new FMError(error, 200, res) : undefined,
|
|
48
|
+
scriptResult: res.response.scriptResult
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async getLayoutMeta() {
|
|
53
|
+
if (this.metadata) {
|
|
54
|
+
return this.metadata;
|
|
55
|
+
}
|
|
56
|
+
let res = await this.database.apiRequest(this.endpoint);
|
|
57
|
+
this.metadata = res.response;
|
|
58
|
+
return this.metadata;
|
|
83
59
|
}
|
|
84
60
|
}
|
package/src/layouts/layout.ts
CHANGED
|
@@ -10,12 +10,13 @@ import {Find} from "../records/getOperations/find.js";
|
|
|
10
10
|
import {FMError} from "../FMError.js";
|
|
11
11
|
import {LayoutBase} from "./layoutBase.js"
|
|
12
12
|
import {DatabaseBase} from "../connection/databaseBase";
|
|
13
|
+
import {ApiLayoutMetadata, ApiScriptResult} from "../models/apiResults";
|
|
13
14
|
|
|
14
15
|
export class Layout<T extends LayoutInterface> implements LayoutBase {
|
|
15
16
|
readonly database: DatabaseBase;
|
|
16
17
|
readonly records = new LayoutRecordManager<T>(this)
|
|
17
18
|
readonly name: string;
|
|
18
|
-
metadata:
|
|
19
|
+
metadata: ApiLayoutMetadata;
|
|
19
20
|
|
|
20
21
|
constructor(database: DatabaseBase, name: string) {
|
|
21
22
|
this.database = database
|
|
@@ -47,47 +48,29 @@ export class Layout<T extends LayoutInterface> implements LayoutBase {
|
|
|
47
48
|
return this.records.find()
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
runScript(script: Script): Promise<ScriptResult> {
|
|
51
|
-
let
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
port: 443,
|
|
57
|
-
method: "GET"
|
|
58
|
-
})
|
|
59
|
-
.then(res => {
|
|
60
|
-
if (res.messages[0].code === "0") {
|
|
61
|
-
let error = parseInt(res.response.scriptError)
|
|
62
|
-
let msg: ScriptResult = {
|
|
63
|
-
scriptError: error ? new FMError(error, 200, res, trace) : undefined,
|
|
64
|
-
scriptResult: res.response.scriptResult
|
|
65
|
-
}
|
|
66
|
-
resolve(msg)
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
// console.log(res)
|
|
70
|
-
reject(new FMError(res.messages[0].code, res.status, res, trace))
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
.catch(e => {
|
|
74
|
-
reject(e)
|
|
75
|
-
})
|
|
51
|
+
async runScript(script: Script): Promise<ScriptResult> {
|
|
52
|
+
let url = `${this.endpoint}/script/${encodeURIComponent(script.name)}`
|
|
53
|
+
if (script.parameter) url += "?script.param=" + encodeURIComponent(script.parameter)
|
|
54
|
+
let res = await this.database.apiRequest<ApiScriptResult>(url, {
|
|
55
|
+
port: 443,
|
|
56
|
+
method: "GET"
|
|
76
57
|
})
|
|
58
|
+
if (res.messages[0].code === "0") {
|
|
59
|
+
let error = parseInt(res.response.scriptError)
|
|
60
|
+
return {
|
|
61
|
+
scriptError: error ? new FMError(error, 200, res) : undefined,
|
|
62
|
+
scriptResult: res.response.scriptResult
|
|
63
|
+
}
|
|
64
|
+
}
|
|
77
65
|
}
|
|
78
66
|
|
|
79
|
-
public getLayoutMeta(): Promise<
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return
|
|
84
|
-
}
|
|
67
|
+
public async getLayoutMeta(): Promise<ApiLayoutMetadata> {
|
|
68
|
+
if (this.metadata) {
|
|
69
|
+
return this.metadata
|
|
70
|
+
}
|
|
85
71
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
})
|
|
90
|
-
.catch(e => reject(e))
|
|
91
|
-
})
|
|
72
|
+
let res = await this.database.apiRequest<ApiLayoutMetadata>(this.endpoint)
|
|
73
|
+
this.metadata = res.response
|
|
74
|
+
return this.metadata
|
|
92
75
|
}
|
|
93
76
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Script, ScriptResult } from "../types";
|
|
2
|
-
import { FMError } from "../FMError";
|
|
3
2
|
import { DatabaseBase } from "../connection/databaseBase";
|
|
3
|
+
import { ApiLayoutMetadata } from "../models/apiResults";
|
|
4
4
|
export interface LayoutBase {
|
|
5
5
|
readonly name: string;
|
|
6
6
|
metadata: any;
|
|
7
7
|
endpoint: string;
|
|
8
8
|
runScript(script: Script): Promise<ScriptResult>;
|
|
9
|
-
getLayoutMeta(): Promise<
|
|
9
|
+
getLayoutMeta(): Promise<ApiLayoutMetadata>;
|
|
10
10
|
database: DatabaseBase;
|
|
11
11
|
}
|
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
import {Script, ScriptResult} from "../types";
|
|
6
6
|
import {FMError} from "../FMError";
|
|
7
7
|
import {DatabaseBase} from "../connection/databaseBase";
|
|
8
|
+
import {ApiLayoutMetadata} from "../models/apiResults";
|
|
8
9
|
|
|
9
10
|
export interface LayoutBase {
|
|
10
11
|
readonly name: string
|
|
11
12
|
metadata: any
|
|
12
13
|
endpoint: string
|
|
13
14
|
runScript(script: Script): Promise<ScriptResult>
|
|
14
|
-
getLayoutMeta(): Promise<
|
|
15
|
+
getLayoutMeta(): Promise<ApiLayoutMetadata>
|
|
15
16
|
database: DatabaseBase
|
|
16
17
|
}
|
|
@@ -7,7 +7,7 @@ export declare class LayoutRecordManager<T extends LayoutInterface> {
|
|
|
7
7
|
readonly layout: LayoutBase;
|
|
8
8
|
constructor(layout: LayoutBase);
|
|
9
9
|
create(): Promise<LayoutRecord<T["fields"], T["portals"]>>;
|
|
10
|
-
get(recordId:
|
|
10
|
+
get(recordId: number): Promise<LayoutRecord<T["fields"], T["portals"]>>;
|
|
11
11
|
range(start?: number, limit?: number): RecordGetRange<T>;
|
|
12
12
|
find(start?: number, limit?: number): Find<T>;
|
|
13
13
|
}
|
|
@@ -5,41 +5,26 @@ import { LayoutRecord } from "../records/layoutRecord.js";
|
|
|
5
5
|
import { RecordGetRange } from "../records/getOperations/recordGetRange.js";
|
|
6
6
|
import { Find } from "../records/getOperations/find.js";
|
|
7
7
|
export class LayoutRecordManager {
|
|
8
|
+
layout;
|
|
8
9
|
constructor(layout) {
|
|
9
10
|
this.layout = layout;
|
|
10
11
|
}
|
|
11
|
-
create() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
portals[_portal] = [];
|
|
22
|
-
resolve(new LayoutRecord(this.layout, -1, 0, fields, portals));
|
|
23
|
-
}).catch(e => {
|
|
24
|
-
reject(e);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
12
|
+
async create() {
|
|
13
|
+
await this.layout.getLayoutMeta();
|
|
14
|
+
let fields = {};
|
|
15
|
+
for (let _field of this.layout.metadata.fieldMetaData) {
|
|
16
|
+
fields[_field.name] = "";
|
|
17
|
+
}
|
|
18
|
+
let portals = {};
|
|
19
|
+
for (let _portal of Object.keys(this.layout.metadata.portalMetaData))
|
|
20
|
+
portals[_portal] = [];
|
|
21
|
+
return new LayoutRecord(this.layout, -1, 0, fields, portals);
|
|
27
22
|
}
|
|
28
|
-
get(recordId) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
record = new LayoutRecord(this.layout, recordId);
|
|
34
|
-
return record.get();
|
|
35
|
-
})
|
|
36
|
-
.then(() => {
|
|
37
|
-
resolve(record);
|
|
38
|
-
})
|
|
39
|
-
.catch(e => {
|
|
40
|
-
reject(e);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
23
|
+
async get(recordId) {
|
|
24
|
+
await this.layout.getLayoutMeta();
|
|
25
|
+
let record = new LayoutRecord(this.layout, recordId);
|
|
26
|
+
await record.get();
|
|
27
|
+
return record;
|
|
43
28
|
}
|
|
44
29
|
range(start = 0, limit = 100) {
|
|
45
30
|
return new RecordGetRange(this.layout, start, limit);
|
|
@@ -15,38 +15,22 @@ export class LayoutRecordManager<T extends LayoutInterface> {
|
|
|
15
15
|
this.layout = layout
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
create(): Promise<LayoutRecord<T["fields"], T["portals"]>> {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
for (let _portal of Object.keys(this.layout.metadata.portalMetaData)) portals[_portal] = []
|
|
28
|
-
resolve(new LayoutRecord(this.layout, -1, 0, fields, portals))
|
|
29
|
-
}).catch(e => {
|
|
30
|
-
reject(e)
|
|
31
|
-
})
|
|
32
|
-
})
|
|
18
|
+
async create(): Promise<LayoutRecord<T["fields"], T["portals"]>> {
|
|
19
|
+
await this.layout.getLayoutMeta()
|
|
20
|
+
let fields = {}
|
|
21
|
+
for (let _field of this.layout.metadata.fieldMetaData) {
|
|
22
|
+
fields[_field.name] = ""
|
|
23
|
+
}
|
|
24
|
+
let portals = {}
|
|
25
|
+
for (let _portal of Object.keys(this.layout.metadata.portalMetaData)) portals[_portal] = []
|
|
26
|
+
return new LayoutRecord(this.layout, -1, 0, fields, portals)
|
|
33
27
|
}
|
|
34
28
|
|
|
35
|
-
get(recordId): Promise<LayoutRecord<T["fields"], T["portals"]>> {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
record = new LayoutRecord(this.layout, recordId)
|
|
41
|
-
return record.get()
|
|
42
|
-
})
|
|
43
|
-
.then(() => {
|
|
44
|
-
resolve(record)
|
|
45
|
-
})
|
|
46
|
-
.catch(e => {
|
|
47
|
-
reject(e)
|
|
48
|
-
})
|
|
49
|
-
})
|
|
29
|
+
async get(recordId: number): Promise<LayoutRecord<T["fields"], T["portals"]>> {
|
|
30
|
+
await this.layout.getLayoutMeta()
|
|
31
|
+
let record = new LayoutRecord(this.layout, recordId)
|
|
32
|
+
await record.get()
|
|
33
|
+
return record
|
|
50
34
|
}
|
|
51
35
|
|
|
52
36
|
range(start = 0, limit = 100) {
|