@jd-data-limited/easy-fm 3.2.7 → 3.2.9
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 +11 -7
- package/src/FMError.d.ts +1 -1
- package/src/FMError.ts +1 -1
- package/src/connection/FMHost.d.ts +1 -1
- package/src/connection/FMHost.ts +3 -3
- package/src/connection/database.d.ts +5 -3
- package/src/connection/database.js +42 -49
- 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 +15 -29
- 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 +24 -27
- 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 +28 -43
- package/src/records/field.ts +46 -64
- package/src/records/getOperations/find.js +18 -28
- package/src/records/getOperations/find.ts +17 -28
- package/src/records/getOperations/recordGetRange.js +15 -22
- package/src/records/getOperations/recordGetRange.ts +17 -24
- package/src/records/layoutRecord.js +73 -102
- package/src/records/layoutRecord.ts +101 -133
- package/src/types.d.ts +0 -4
- package/src/types.ts +0 -5
- 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
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
|
}
|
|
@@ -1,6 +1,15 @@
|
|
|
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
|
+
};
|
|
4
13
|
import { LayoutRecord } from "../records/layoutRecord.js";
|
|
5
14
|
import { RecordGetRange } from "../records/getOperations/recordGetRange.js";
|
|
6
15
|
import { Find } from "../records/getOperations/find.js";
|
|
@@ -9,36 +18,24 @@ export class LayoutRecordManager {
|
|
|
9
18
|
this.layout = layout;
|
|
10
19
|
}
|
|
11
20
|
create() {
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
resolve(new LayoutRecord(this.layout, -1, 0, fields, portals));
|
|
23
|
-
}).catch(e => {
|
|
24
|
-
reject(e);
|
|
25
|
-
});
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
yield this.layout.getLayoutMeta();
|
|
23
|
+
let fields = {};
|
|
24
|
+
for (let _field of this.layout.metadata.fieldMetaData) {
|
|
25
|
+
fields[_field.name] = "";
|
|
26
|
+
}
|
|
27
|
+
let portals = {};
|
|
28
|
+
for (let _portal of Object.keys(this.layout.metadata.portalMetaData))
|
|
29
|
+
portals[_portal] = [];
|
|
30
|
+
return new LayoutRecord(this.layout, -1, 0, fields, portals);
|
|
26
31
|
});
|
|
27
32
|
}
|
|
28
33
|
get(recordId) {
|
|
29
|
-
return
|
|
30
|
-
|
|
31
|
-
this.layout
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return record.get();
|
|
35
|
-
})
|
|
36
|
-
.then(() => {
|
|
37
|
-
resolve(record);
|
|
38
|
-
})
|
|
39
|
-
.catch(e => {
|
|
40
|
-
reject(e);
|
|
41
|
-
});
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
yield this.layout.getLayoutMeta();
|
|
36
|
+
let record = new LayoutRecord(this.layout, recordId);
|
|
37
|
+
yield record.get();
|
|
38
|
+
return record;
|
|
42
39
|
});
|
|
43
40
|
}
|
|
44
41
|
range(start = 0, limit = 100) {
|
|
@@ -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) {
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export declare enum ApiFieldTypes {
|
|
2
|
+
NORMAL = "normal",
|
|
3
|
+
CALCULATION = "calculation",
|
|
4
|
+
SUMMARY = "summary"
|
|
5
|
+
}
|
|
6
|
+
export declare enum ApiFieldDisplayTypes {
|
|
7
|
+
EDIT_TEXT = "editText",
|
|
8
|
+
POPUP_LIST = "popupList",
|
|
9
|
+
CHECKBOX = "checkBox",
|
|
10
|
+
RADIO_BUTTONS = "radioButtons",
|
|
11
|
+
SELECTION_LIST = "selectionList",
|
|
12
|
+
CALENDAR = "calendar",
|
|
13
|
+
SECURE_TEXT = "secureText"
|
|
14
|
+
}
|
|
15
|
+
export declare enum ApiFieldResultTypes {
|
|
16
|
+
TEXT = "text",
|
|
17
|
+
NUMBER = "number",
|
|
18
|
+
DATE = "date",
|
|
19
|
+
TIME = "time",
|
|
20
|
+
TIMESTAMP = "timeStamp",
|
|
21
|
+
CONTAINER = "container"
|
|
22
|
+
}
|
|
23
|
+
export interface ApiMessage {
|
|
24
|
+
code: string;
|
|
25
|
+
message: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ApiResults<T = unknown> {
|
|
28
|
+
response?: null | T & {
|
|
29
|
+
scriptError?: string;
|
|
30
|
+
};
|
|
31
|
+
messages: ApiMessage[];
|
|
32
|
+
httpStatus: number;
|
|
33
|
+
}
|
|
34
|
+
export interface ApiLayout {
|
|
35
|
+
name: string;
|
|
36
|
+
isFolder: boolean;
|
|
37
|
+
folderLayoutNames: string[];
|
|
38
|
+
}
|
|
39
|
+
export interface ApiLayoutMetadata {
|
|
40
|
+
fieldMetaData: ApiFieldMetadata[];
|
|
41
|
+
portalMetaData: {
|
|
42
|
+
[key: string]: ApiFieldMetadata[];
|
|
43
|
+
};
|
|
44
|
+
valueLists: ApiValueList[];
|
|
45
|
+
}
|
|
46
|
+
export interface ApiFieldMetadata {
|
|
47
|
+
name: string;
|
|
48
|
+
type: ApiFieldTypes;
|
|
49
|
+
displayType: ApiFieldDisplayTypes;
|
|
50
|
+
result: ApiFieldResultTypes;
|
|
51
|
+
global: boolean;
|
|
52
|
+
autoEnter: boolean;
|
|
53
|
+
fourDigitYear: boolean;
|
|
54
|
+
maxRepeat: number;
|
|
55
|
+
maxCharacters: number;
|
|
56
|
+
notEmpty: boolean;
|
|
57
|
+
numeric: boolean;
|
|
58
|
+
repetitions: number;
|
|
59
|
+
timeOfDay: boolean;
|
|
60
|
+
valueList: string;
|
|
61
|
+
}
|
|
62
|
+
export interface ApiValueList {
|
|
63
|
+
name: string;
|
|
64
|
+
type: string;
|
|
65
|
+
values: {
|
|
66
|
+
value: string;
|
|
67
|
+
displayName: string;
|
|
68
|
+
}[];
|
|
69
|
+
}
|
|
70
|
+
export interface ApiScriptResult {
|
|
71
|
+
scriptError: string;
|
|
72
|
+
scriptResult?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface ApiRecordResponseObj {
|
|
75
|
+
data: ApiRowDataDef[];
|
|
76
|
+
dataInfo: ApiResultSetObj;
|
|
77
|
+
}
|
|
78
|
+
export interface ApiFieldData {
|
|
79
|
+
[key: string]: string;
|
|
80
|
+
}
|
|
81
|
+
export interface ApiPortalData {
|
|
82
|
+
[key: string]: ApiFieldData[];
|
|
83
|
+
}
|
|
84
|
+
export interface ApiResultSetObj {
|
|
85
|
+
database: string;
|
|
86
|
+
layout: string;
|
|
87
|
+
table: string;
|
|
88
|
+
totalRecordCount: number;
|
|
89
|
+
foundCount: number;
|
|
90
|
+
returnedCount: number;
|
|
91
|
+
}
|
|
92
|
+
export interface ApiRowDataDef {
|
|
93
|
+
fieldData: ApiFieldData;
|
|
94
|
+
portalData: ApiPortalData;
|
|
95
|
+
modId: string;
|
|
96
|
+
recordId: string;
|
|
97
|
+
portalDataInfo: {
|
|
98
|
+
database: string;
|
|
99
|
+
table: string;
|
|
100
|
+
foundCount: number;
|
|
101
|
+
returnedCount: number;
|
|
102
|
+
}[];
|
|
103
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
|
+
*/
|
|
4
|
+
export var ApiFieldTypes;
|
|
5
|
+
(function (ApiFieldTypes) {
|
|
6
|
+
ApiFieldTypes["NORMAL"] = "normal";
|
|
7
|
+
ApiFieldTypes["CALCULATION"] = "calculation";
|
|
8
|
+
ApiFieldTypes["SUMMARY"] = "summary";
|
|
9
|
+
})(ApiFieldTypes || (ApiFieldTypes = {}));
|
|
10
|
+
export var ApiFieldDisplayTypes;
|
|
11
|
+
(function (ApiFieldDisplayTypes) {
|
|
12
|
+
ApiFieldDisplayTypes["EDIT_TEXT"] = "editText";
|
|
13
|
+
ApiFieldDisplayTypes["POPUP_LIST"] = "popupList";
|
|
14
|
+
ApiFieldDisplayTypes["CHECKBOX"] = "checkBox";
|
|
15
|
+
ApiFieldDisplayTypes["RADIO_BUTTONS"] = "radioButtons";
|
|
16
|
+
ApiFieldDisplayTypes["SELECTION_LIST"] = "selectionList";
|
|
17
|
+
ApiFieldDisplayTypes["CALENDAR"] = "calendar";
|
|
18
|
+
ApiFieldDisplayTypes["SECURE_TEXT"] = "secureText";
|
|
19
|
+
})(ApiFieldDisplayTypes || (ApiFieldDisplayTypes = {}));
|
|
20
|
+
export var ApiFieldResultTypes;
|
|
21
|
+
(function (ApiFieldResultTypes) {
|
|
22
|
+
ApiFieldResultTypes["TEXT"] = "text";
|
|
23
|
+
ApiFieldResultTypes["NUMBER"] = "number";
|
|
24
|
+
ApiFieldResultTypes["DATE"] = "date";
|
|
25
|
+
ApiFieldResultTypes["TIME"] = "time";
|
|
26
|
+
ApiFieldResultTypes["TIMESTAMP"] = "timeStamp";
|
|
27
|
+
ApiFieldResultTypes["CONTAINER"] = "container";
|
|
28
|
+
})(ApiFieldResultTypes || (ApiFieldResultTypes = {}));
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023. See LICENSE file for more information
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as stream from "stream";
|
|
6
|
+
|
|
7
|
+
export enum ApiFieldTypes {
|
|
8
|
+
NORMAL = "normal",
|
|
9
|
+
CALCULATION = "calculation",
|
|
10
|
+
SUMMARY = "summary"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export enum ApiFieldDisplayTypes {
|
|
14
|
+
EDIT_TEXT = "editText",
|
|
15
|
+
POPUP_LIST = "popupList",
|
|
16
|
+
CHECKBOX = "checkBox",
|
|
17
|
+
RADIO_BUTTONS = "radioButtons",
|
|
18
|
+
SELECTION_LIST = "selectionList",
|
|
19
|
+
CALENDAR = "calendar",
|
|
20
|
+
SECURE_TEXT = "secureText"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export enum ApiFieldResultTypes {
|
|
24
|
+
TEXT = "text",
|
|
25
|
+
NUMBER = "number",
|
|
26
|
+
DATE = "date",
|
|
27
|
+
TIME = "time",
|
|
28
|
+
TIMESTAMP = "timeStamp",
|
|
29
|
+
CONTAINER = "container"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ApiMessage {
|
|
33
|
+
code: string,
|
|
34
|
+
message: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface ApiResults<T = unknown> {
|
|
38
|
+
response?: null | T & {scriptError? : string},
|
|
39
|
+
messages: ApiMessage[],
|
|
40
|
+
httpStatus: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ApiLayout {
|
|
44
|
+
name: string,
|
|
45
|
+
isFolder: boolean,
|
|
46
|
+
folderLayoutNames: string[]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ApiLayoutMetadata {
|
|
50
|
+
fieldMetaData: ApiFieldMetadata[],
|
|
51
|
+
portalMetaData: {[key: string]: ApiFieldMetadata[]},
|
|
52
|
+
valueLists: ApiValueList[]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ApiFieldMetadata {
|
|
56
|
+
name: string,
|
|
57
|
+
type: ApiFieldTypes,
|
|
58
|
+
displayType: ApiFieldDisplayTypes,
|
|
59
|
+
result: ApiFieldResultTypes,
|
|
60
|
+
global: boolean,
|
|
61
|
+
autoEnter: boolean,
|
|
62
|
+
fourDigitYear: boolean,
|
|
63
|
+
maxRepeat: number,
|
|
64
|
+
maxCharacters: number,
|
|
65
|
+
notEmpty: boolean,
|
|
66
|
+
numeric: boolean,
|
|
67
|
+
repetitions: number,
|
|
68
|
+
timeOfDay: boolean,
|
|
69
|
+
valueList: string
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface ApiValueList {
|
|
73
|
+
name: string,
|
|
74
|
+
type: string,
|
|
75
|
+
values: {value: string, displayName: string}[]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface ApiScriptResult {
|
|
79
|
+
scriptError: string,
|
|
80
|
+
scriptResult?: string
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface ApiRecordResponseObj {
|
|
84
|
+
data: ApiRowDataDef[],
|
|
85
|
+
dataInfo: ApiResultSetObj
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface ApiFieldData {[key: string]: string}
|
|
89
|
+
|
|
90
|
+
export interface ApiPortalData {[key: string]: ApiFieldData[]}
|
|
91
|
+
|
|
92
|
+
export interface ApiResultSetObj {
|
|
93
|
+
database: string,
|
|
94
|
+
layout: string,
|
|
95
|
+
table: string,
|
|
96
|
+
totalRecordCount: number,
|
|
97
|
+
foundCount: number,
|
|
98
|
+
returnedCount: number
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface ApiRowDataDef {
|
|
102
|
+
fieldData: ApiFieldData,
|
|
103
|
+
portalData: ApiPortalData,
|
|
104
|
+
modId: string,
|
|
105
|
+
recordId: string,
|
|
106
|
+
portalDataInfo: {
|
|
107
|
+
database: string,
|
|
108
|
+
table: string,
|
|
109
|
+
foundCount: number,
|
|
110
|
+
returnedCount: number
|
|
111
|
+
}[]
|
|
112
|
+
}
|
package/src/records/field.d.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { RecordBase } from "./recordBase.js";
|
|
4
4
|
import * as http from "http";
|
|
5
|
-
import { ContainerBufferResult, DOWNLOAD_MODES
|
|
5
|
+
import { ContainerBufferResult, DOWNLOAD_MODES } from "../types.js";
|
|
6
|
+
import { ApiFieldMetadata } from "../models/apiResults.js";
|
|
6
7
|
export type FieldValue = string | number | Date | Container;
|
|
7
8
|
export type Container = null;
|
|
8
9
|
export declare class Field<T extends FieldValue> {
|
|
@@ -12,7 +13,7 @@ export declare class Field<T extends FieldValue> {
|
|
|
12
13
|
edited: boolean;
|
|
13
14
|
constructor(record: any, id: any, contents: any);
|
|
14
15
|
set(content: string | number | Date | undefined | null): void;
|
|
15
|
-
get metadata():
|
|
16
|
+
get metadata(): ApiFieldMetadata;
|
|
16
17
|
get value(): T;
|
|
17
18
|
set value(value: T);
|
|
18
19
|
get string(): string;
|
package/src/records/field.js
CHANGED
|
@@ -11,9 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
13
|
import { RecordTypes } from "./recordBase.js";
|
|
14
|
-
import
|
|
14
|
+
import { File, FormData } from "node-fetch";
|
|
15
15
|
import { DOWNLOAD_MODES } from "../types.js";
|
|
16
|
-
import {
|
|
16
|
+
import { ApiFieldDisplayTypes, ApiFieldResultTypes, ApiFieldTypes } from "../models/apiResults.js";
|
|
17
17
|
export class Field {
|
|
18
18
|
constructor(record, id, contents) {
|
|
19
19
|
this.record = record;
|
|
@@ -43,9 +43,9 @@ export class Field {
|
|
|
43
43
|
// Default to a regular text field
|
|
44
44
|
return {
|
|
45
45
|
name: this.id.toString(),
|
|
46
|
-
type:
|
|
47
|
-
displayType:
|
|
48
|
-
result:
|
|
46
|
+
type: ApiFieldTypes.NORMAL,
|
|
47
|
+
displayType: ApiFieldDisplayTypes.EDIT_TEXT,
|
|
48
|
+
result: ApiFieldResultTypes.TEXT,
|
|
49
49
|
global: false,
|
|
50
50
|
autoEnter: true,
|
|
51
51
|
fourDigitYear: false,
|
|
@@ -54,8 +54,8 @@ export class Field {
|
|
|
54
54
|
notEmpty: false,
|
|
55
55
|
numeric: false,
|
|
56
56
|
timeOfDay: false,
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
repetitions: 1,
|
|
58
|
+
valueList: ""
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
if (this.record.type === RecordTypes.PORTAL) {
|
|
@@ -80,9 +80,9 @@ export class Field {
|
|
|
80
80
|
else {
|
|
81
81
|
return this.record.layout.metadata.fieldMetaData.find(i => i.name === this.id) || {
|
|
82
82
|
name: this.id.toString(),
|
|
83
|
-
type:
|
|
84
|
-
displayType:
|
|
85
|
-
result:
|
|
83
|
+
type: ApiFieldTypes.NORMAL,
|
|
84
|
+
displayType: ApiFieldDisplayTypes.EDIT_TEXT,
|
|
85
|
+
result: ApiFieldResultTypes.TEXT,
|
|
86
86
|
global: false,
|
|
87
87
|
autoEnter: true,
|
|
88
88
|
fourDigitYear: false,
|
|
@@ -91,8 +91,8 @@ export class Field {
|
|
|
91
91
|
notEmpty: false,
|
|
92
92
|
numeric: false,
|
|
93
93
|
timeOfDay: false,
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
repetitions: 1,
|
|
95
|
+
valueList: ""
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -122,42 +122,30 @@ export class Field {
|
|
|
122
122
|
throw "Field value is not a number";
|
|
123
123
|
}
|
|
124
124
|
upload(buffer, filename, mime) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
let trace = new Error();
|
|
127
|
+
if (this.metadata.result !== "container")
|
|
128
|
+
throw "Cannot upload a file to the field; " + this.id + " (not a container field)";
|
|
129
129
|
let form = new FormData();
|
|
130
130
|
form.append("upload", new File([buffer], filename, { type: mime }));
|
|
131
|
-
|
|
131
|
+
yield this.record.layout.database.apiRequest(`${this.record.endpoint}/containers/${this.id}/1`, {
|
|
132
132
|
method: "POST",
|
|
133
133
|
// @ts-ignore
|
|
134
|
-
headers: { "Authorization": "Bearer " + this.record.layout.database.token },
|
|
134
|
+
headers: { "Authorization": "Bearer " + this.record.layout.database.token, "Content-Type": "multipart/form-data" },
|
|
135
135
|
body: form
|
|
136
|
-
}).then(res => res.json())
|
|
137
|
-
.then(data => {
|
|
138
|
-
let _res = data;
|
|
139
|
-
if (_res.messages[0].code === "0") {
|
|
140
|
-
resolve();
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
reject(new FMError(_res.messages[0].code, _res.status, data, trace));
|
|
144
|
-
}
|
|
145
|
-
})
|
|
146
|
-
.catch(e => {
|
|
147
|
-
reject(e);
|
|
148
136
|
});
|
|
149
|
-
})
|
|
137
|
+
});
|
|
150
138
|
}
|
|
151
139
|
download(mode = DOWNLOAD_MODES.Stream) {
|
|
152
|
-
return
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
if (this.metadata.result !== ApiFieldResultTypes.CONTAINER)
|
|
142
|
+
throw new Error("Cannot perform download() on a non-container field");
|
|
143
|
+
let stream = yield this.record.layout.database.streamURL(this.string);
|
|
144
|
+
if (mode === DOWNLOAD_MODES.Stream) {
|
|
145
|
+
return stream;
|
|
146
|
+
}
|
|
147
|
+
let body = [];
|
|
148
|
+
return new Promise((resolve, reject) => {
|
|
161
149
|
stream.on("data", chunk => {
|
|
162
150
|
body.push(chunk);
|
|
163
151
|
});
|
|
@@ -171,9 +159,6 @@ export class Field {
|
|
|
171
159
|
request: stream
|
|
172
160
|
});
|
|
173
161
|
});
|
|
174
|
-
})
|
|
175
|
-
.catch(e => {
|
|
176
|
-
reject(e);
|
|
177
162
|
});
|
|
178
163
|
});
|
|
179
164
|
}
|