@jd-data-limited/easy-fm 4.0.0 → 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/package.json +1 -1
- package/src/connection/database.d.ts +1 -2
- package/src/connection/database.js +0 -10
- package/src/connection/database.ts +3 -14
- package/src/layouts/layoutBase.d.ts +1 -1
- package/src/layouts/layoutBase.ts +1 -1
- package/src/layouts/layoutRecordManager.ts +3 -2
- 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/fieldBase.ts +1 -1
- package/src/records/layoutRecord.d.ts +7 -5
- package/src/records/layoutRecord.js +3 -6
- package/src/records/layoutRecord.ts +15 -13
- package/src/records/portal.ts +3 -1
- package/src/records/portalRecord.d.ts +7 -3
- package/src/records/portalRecord.js +3 -6
- package/src/records/portalRecord.ts +13 -12
- package/src/records/recordBase.d.ts +5 -4
- package/src/records/recordBase.js +3 -3
- package/src/records/recordBase.ts +8 -11
package/package.json
CHANGED
|
@@ -25,8 +25,7 @@ export declare class Database<T extends DatabaseStructure> extends EventEmitter
|
|
|
25
25
|
listLayouts(): Promise<Layout<LayoutInterface>[]>;
|
|
26
26
|
getLayout<R extends keyof T["layouts"]>(name: R): Layout<T["layouts"][R]>;
|
|
27
27
|
getLayout<R extends LayoutInterface>(name: string): Layout<R>;
|
|
28
|
-
|
|
29
|
-
script(name: any, parameter?: string): Script;
|
|
28
|
+
script(name: string, parameter?: string): Script;
|
|
30
29
|
_tokenExpired(): void;
|
|
31
30
|
streamURL(url: string): Promise<IncomingMessage>;
|
|
32
31
|
}
|
|
@@ -123,16 +123,6 @@ export class Database extends EventEmitter {
|
|
|
123
123
|
getLayout(name) {
|
|
124
124
|
return new Layout(this, name);
|
|
125
125
|
}
|
|
126
|
-
/*
|
|
127
|
-
@deprecated
|
|
128
|
-
*/
|
|
129
|
-
async setGlobals(globalFields) {
|
|
130
|
-
// console.log({globalFields})
|
|
131
|
-
await this.apiRequest(`${this.endpoint}/globals`, {
|
|
132
|
-
method: "PATCH",
|
|
133
|
-
body: JSON.stringify({ globalFields })
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
126
|
script(name, parameter = "") {
|
|
137
127
|
return { name, parameter };
|
|
138
128
|
}
|
|
@@ -155,18 +155,7 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
|
|
|
155
155
|
return new Layout<LayoutInterface>(this, name)
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
|
|
159
|
-
@deprecated
|
|
160
|
-
*/
|
|
161
|
-
async setGlobals(globalFields) {
|
|
162
|
-
// console.log({globalFields})
|
|
163
|
-
await this.apiRequest(`${this.endpoint}/globals`, {
|
|
164
|
-
method: "PATCH",
|
|
165
|
-
body: JSON.stringify({globalFields})
|
|
166
|
-
})
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
script(name, parameter = ""): Script {
|
|
158
|
+
script(name: string, parameter = ""): Script {
|
|
170
159
|
return ({name, parameter} as Script)
|
|
171
160
|
}
|
|
172
161
|
|
|
@@ -180,7 +169,7 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
|
|
|
180
169
|
throw new Error("URL is empty, or has invalid value")
|
|
181
170
|
}
|
|
182
171
|
|
|
183
|
-
let headers = {}
|
|
172
|
+
let headers: {[key: string]: string} = {}
|
|
184
173
|
if (Object.keys(this.cookies).length !== 0) {
|
|
185
174
|
headers["Cookie"] = Object.keys(this.cookies)
|
|
186
175
|
.map(key => {
|
|
@@ -189,7 +178,7 @@ export class Database<T extends DatabaseStructure> extends EventEmitter implemen
|
|
|
189
178
|
.join("; ")
|
|
190
179
|
}
|
|
191
180
|
|
|
192
|
-
const check_for_cookies = (res) => {
|
|
181
|
+
const check_for_cookies = (res: HTTP_REDIRECT.ResponseDetails) => {
|
|
193
182
|
// Check for the 'set-cookie' header. If it exists, remember it and strip it for better security.
|
|
194
183
|
if (res.headers['set-cookie']) {
|
|
195
184
|
for (let cookie of res.headers['set-cookie']) {
|
|
@@ -3,7 +3,7 @@ import { DatabaseBase } from "../connection/databaseBase.js";
|
|
|
3
3
|
import { ApiLayoutMetadata } from "../models/apiResults.js";
|
|
4
4
|
export interface LayoutBase {
|
|
5
5
|
readonly name: string;
|
|
6
|
-
metadata:
|
|
6
|
+
metadata: ApiLayoutMetadata | null;
|
|
7
7
|
endpoint: string;
|
|
8
8
|
runScript(script: Script): Promise<ScriptResult>;
|
|
9
9
|
getLayoutMeta(): Promise<ApiLayoutMetadata>;
|
|
@@ -8,7 +8,7 @@ import {ApiLayoutMetadata} from "../models/apiResults.js";
|
|
|
8
8
|
|
|
9
9
|
export interface LayoutBase {
|
|
10
10
|
readonly name: string
|
|
11
|
-
metadata:
|
|
11
|
+
metadata: ApiLayoutMetadata | null
|
|
12
12
|
endpoint: string
|
|
13
13
|
runScript(script: Script): Promise<ScriptResult>
|
|
14
14
|
getLayoutMeta(): Promise<ApiLayoutMetadata>
|
|
@@ -7,6 +7,7 @@ import {LayoutInterface} from "./layoutInterface.js";
|
|
|
7
7
|
import {LayoutBase} from "./layoutBase.js"
|
|
8
8
|
import {GetOperationOptions, RecordGetOperation} from "../records/getOperations/recordGetOperation.js";
|
|
9
9
|
import {RecordFetchOptions} from "../types.js";
|
|
10
|
+
import {ApiFieldData} from "../models/apiResults.js";
|
|
10
11
|
|
|
11
12
|
export class LayoutRecordManager<T extends LayoutInterface> {
|
|
12
13
|
readonly layout: LayoutBase;
|
|
@@ -16,11 +17,11 @@ export class LayoutRecordManager<T extends LayoutInterface> {
|
|
|
16
17
|
|
|
17
18
|
async create<OPTIONS extends RecordFetchOptions>(options: OPTIONS): Promise<LayoutRecord<T, OPTIONS["portals"][number]>> {
|
|
18
19
|
await this.layout.getLayoutMeta()
|
|
19
|
-
let fields = {}
|
|
20
|
+
let fields: ApiFieldData = {}
|
|
20
21
|
for (let _field of this.layout.metadata.fieldMetaData) {
|
|
21
22
|
fields[_field.name] = ""
|
|
22
23
|
}
|
|
23
|
-
let portals = {}
|
|
24
|
+
let portals: {[key: string]: []} = {}
|
|
24
25
|
for (let _portal of Object.keys(this.layout.metadata.portalMetaData)) portals[_portal] = []
|
|
25
26
|
return new LayoutRecord(this.layout, -1, 0, fields, portals)
|
|
26
27
|
}
|
|
@@ -75,9 +75,9 @@ export interface ApiRecordResponseObj {
|
|
|
75
75
|
data: ApiRowDataDef[];
|
|
76
76
|
dataInfo: ApiResultSetObj;
|
|
77
77
|
}
|
|
78
|
-
export
|
|
79
|
-
[key: string]: string;
|
|
80
|
-
}
|
|
78
|
+
export type ApiFieldData = {
|
|
79
|
+
[key: string]: string | number;
|
|
80
|
+
};
|
|
81
81
|
export interface ApiPortalData {
|
|
82
82
|
[key: string]: ApiFieldData[];
|
|
83
83
|
}
|
package/src/models/apiResults.js
CHANGED
package/src/models/apiResults.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright (c) 2023. See LICENSE file for more information
|
|
2
|
+
* Copyright (c) 2023-2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import * as stream from "stream";
|
|
6
|
-
|
|
7
5
|
export enum ApiFieldTypes {
|
|
8
6
|
NORMAL = "normal",
|
|
9
7
|
CALCULATION = "calculation",
|
|
@@ -85,7 +83,7 @@ export interface ApiRecordResponseObj {
|
|
|
85
83
|
dataInfo: ApiResultSetObj
|
|
86
84
|
}
|
|
87
85
|
|
|
88
|
-
export
|
|
86
|
+
export type ApiFieldData = {[key: string]: string | number}
|
|
89
87
|
|
|
90
88
|
export interface ApiPortalData {[key: string]: ApiFieldData[]}
|
|
91
89
|
|
package/src/records/fieldBase.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { extraBodyOptions
|
|
1
|
+
import { extraBodyOptions } from "../types.js";
|
|
2
2
|
import { RecordBase } from "./recordBase.js";
|
|
3
|
+
import { PortalRecord } from "./portalRecord.js";
|
|
3
4
|
import { Portal } from "./portal.js";
|
|
4
5
|
import { LayoutInterface } from "../layouts/layoutInterface.js";
|
|
5
6
|
import { LayoutRecordBase } from "./layoutRecordBase.js";
|
|
7
|
+
import { ApiPortalData } from "../models/apiResults.js";
|
|
6
8
|
import { LayoutBase } from "../layouts/layoutBase.js";
|
|
9
|
+
import { FieldBase, FieldValue } from "./fieldBase.js";
|
|
7
10
|
export declare class LayoutRecord<LAYOUT extends LayoutInterface, PORTALS_TO_INCLUDE = string> extends RecordBase<LAYOUT["fields"]> implements LayoutRecordBase {
|
|
8
11
|
portals: Pick<LAYOUT["portals"], PORTALS_TO_INCLUDE>;
|
|
9
12
|
private readonly portalsToInclude;
|
|
10
|
-
constructor(layout: LayoutBase, recordId: number | string, modId?: string | number, fieldData?: Record<string, string | number>, portalData?:
|
|
13
|
+
constructor(layout: LayoutBase, recordId: number | string, modId?: string | number, fieldData?: Record<string, string | number>, portalData?: ApiPortalData | null, portalsToInclude?: PORTALS_TO_INCLUDE[]);
|
|
11
14
|
get portalsArray(): Portal<any>[];
|
|
12
15
|
commit(extraBody?: extraBodyOptions): Promise<this>;
|
|
13
|
-
protected processPortalData(portalData:
|
|
16
|
+
protected processPortalData(portalData: ApiPortalData): void;
|
|
14
17
|
get(): Promise<this>;
|
|
15
|
-
getPortal(portal: any): Portal<any>;
|
|
16
18
|
duplicate(): Promise<LayoutRecord<LAYOUT>>;
|
|
17
19
|
delete(): Promise<void>;
|
|
18
|
-
toObject(filter?: (a:
|
|
20
|
+
toObject(filter?: (a: FieldBase<FieldValue>) => any, portalFilter?: (a: Portal<any>) => any, portalRowFilter?: (a: PortalRecord<never>) => any, portalFieldFilter?: (a: FieldBase<FieldValue>) => any): Partial<Omit<import("../models/apiResults.js").ApiRowDataDef, "portalDataInfo">>;
|
|
19
21
|
}
|
|
@@ -10,7 +10,7 @@ export class LayoutRecord extends RecordBase {
|
|
|
10
10
|
portals = {};
|
|
11
11
|
portalsToInclude;
|
|
12
12
|
constructor(layout, recordId, modId = recordId, fieldData = {}, portalData = null, portalsToInclude = []) {
|
|
13
|
-
super(layout, recordId, modId);
|
|
13
|
+
super(layout, parseInt(recordId), parseInt(modId));
|
|
14
14
|
this.processFieldData(fieldData);
|
|
15
15
|
this.portalsToInclude = portalsToInclude;
|
|
16
16
|
if (portalData) {
|
|
@@ -83,7 +83,7 @@ export class LayoutRecord extends RecordBase {
|
|
|
83
83
|
let fieldData = item;
|
|
84
84
|
delete fieldData.recordId;
|
|
85
85
|
delete fieldData.modId;
|
|
86
|
-
return new PortalRecord(this, _portal, item.recordId, item.modId, fieldData);
|
|
86
|
+
return new PortalRecord(this, _portal, parseInt(item.recordId), parseInt(item.modId), fieldData);
|
|
87
87
|
});
|
|
88
88
|
// @ts-ignore
|
|
89
89
|
this.portals[portalName] = _portal;
|
|
@@ -110,9 +110,6 @@ export class LayoutRecord extends RecordBase {
|
|
|
110
110
|
return this;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
getPortal(portal) {
|
|
114
|
-
return this.portalsArray.find(p => p.name === portal);
|
|
115
|
-
}
|
|
116
113
|
async duplicate() {
|
|
117
114
|
let trace = new Error();
|
|
118
115
|
let res = await this.layout.database.apiRequest(this.endpoint, {
|
|
@@ -150,7 +147,7 @@ export class LayoutRecord extends RecordBase {
|
|
|
150
147
|
}
|
|
151
148
|
}
|
|
152
149
|
toObject(filter = (a) => a.edited, portalFilter = (a) => a.records.find(record => record.edited), portalRowFilter = (a) => a.edited, portalFieldFilter = (a) => a.edited) {
|
|
153
|
-
let obj = super.toObject(filter
|
|
150
|
+
let obj = super.toObject(filter);
|
|
154
151
|
// Check if there's been any edited portal information
|
|
155
152
|
let portals = this.portalsArray.filter(a => portalFilter(a));
|
|
156
153
|
if (portals) {
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
* Copyright (c) 2023-2024. See LICENSE file for more information
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {extraBodyOptions
|
|
5
|
+
import {extraBodyOptions} from "../types.js";
|
|
6
6
|
import {RecordBase} from "./recordBase.js";
|
|
7
7
|
import {PortalRecord} from "./portalRecord.js";
|
|
8
8
|
import {Portal} from "./portal.js";
|
|
9
9
|
import {LayoutInterface} from "../layouts/layoutInterface.js";
|
|
10
10
|
import {FMError} from "../FMError.js";
|
|
11
11
|
import {LayoutRecordBase} from "./layoutRecordBase.js";
|
|
12
|
-
import {ApiRecordResponseObj} from "../models/apiResults.js";
|
|
12
|
+
import {ApiPortalData, ApiRecordResponseObj} from "../models/apiResults.js";
|
|
13
13
|
import {LayoutBase} from "../layouts/layoutBase.js"
|
|
14
|
+
import {FieldBase, FieldValue} from "./fieldBase.js";
|
|
14
15
|
|
|
15
16
|
export class LayoutRecord<LAYOUT extends LayoutInterface, PORTALS_TO_INCLUDE = string> extends RecordBase<LAYOUT["fields"]> implements LayoutRecordBase {
|
|
16
17
|
// @ts-ignore
|
|
@@ -22,9 +23,9 @@ export class LayoutRecord<LAYOUT extends LayoutInterface, PORTALS_TO_INCLUDE = s
|
|
|
22
23
|
recordId: number | string,
|
|
23
24
|
modId = recordId,
|
|
24
25
|
fieldData: Record<string, string | number> = {},
|
|
25
|
-
portalData = null, portalsToInclude: PORTALS_TO_INCLUDE[] = [])
|
|
26
|
+
portalData: ApiPortalData | null = null, portalsToInclude: PORTALS_TO_INCLUDE[] = [])
|
|
26
27
|
{
|
|
27
|
-
super(layout, recordId, modId);
|
|
28
|
+
super(layout, parseInt(recordId as string), parseInt(modId as string));
|
|
28
29
|
this.processFieldData(fieldData)
|
|
29
30
|
this.portalsToInclude = portalsToInclude
|
|
30
31
|
if (portalData) {
|
|
@@ -37,7 +38,7 @@ export class LayoutRecord<LAYOUT extends LayoutInterface, PORTALS_TO_INCLUDE = s
|
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
async commit(extraBody: extraBodyOptions = {}): Promise<this> {
|
|
40
|
-
let data = this.toObject()
|
|
41
|
+
let data: any = this.toObject()
|
|
41
42
|
delete data.recordId
|
|
42
43
|
delete data.modId
|
|
43
44
|
|
|
@@ -100,14 +101,14 @@ export class LayoutRecord<LAYOUT extends LayoutInterface, PORTALS_TO_INCLUDE = s
|
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
protected processPortalData(portalData): void {
|
|
104
|
+
protected processPortalData(portalData: ApiPortalData): void {
|
|
104
105
|
for (let portalName of Object.keys(portalData)) {
|
|
105
106
|
let _portal = new Portal(this, portalName)
|
|
106
107
|
_portal.records = portalData[portalName].map(item => {
|
|
107
108
|
let fieldData = item;
|
|
108
109
|
delete fieldData.recordId;
|
|
109
110
|
delete fieldData.modId;
|
|
110
|
-
return new PortalRecord(this, _portal, item.recordId, item.modId, fieldData);
|
|
111
|
+
return new PortalRecord(this, _portal, parseInt(item.recordId as string), parseInt(item.modId as string), fieldData);
|
|
111
112
|
})
|
|
112
113
|
|
|
113
114
|
// @ts-ignore
|
|
@@ -136,10 +137,6 @@ export class LayoutRecord<LAYOUT extends LayoutInterface, PORTALS_TO_INCLUDE = s
|
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
getPortal(portal) {
|
|
140
|
-
return this.portalsArray.find(p => p.name === portal)
|
|
141
|
-
}
|
|
142
|
-
|
|
143
140
|
async duplicate(): Promise<LayoutRecord<LAYOUT>> {
|
|
144
141
|
let trace = new Error()
|
|
145
142
|
let res = await this.layout.database.apiRequest<{recordId: string, modId: string}>(this.endpoint, {
|
|
@@ -179,8 +176,13 @@ export class LayoutRecord<LAYOUT extends LayoutInterface, PORTALS_TO_INCLUDE = s
|
|
|
179
176
|
}
|
|
180
177
|
}
|
|
181
178
|
|
|
182
|
-
toObject(
|
|
183
|
-
|
|
179
|
+
toObject(
|
|
180
|
+
filter: (a: FieldBase<FieldValue>) => any = (a) => a.edited,
|
|
181
|
+
portalFilter: (a: Portal<any>) => any = (a) => a.records.find(record => record.edited),
|
|
182
|
+
portalRowFilter: (a: PortalRecord<never>) => any = (a) => a.edited,
|
|
183
|
+
portalFieldFilter: (a: FieldBase<FieldValue>) => any = (a) => a.edited
|
|
184
|
+
) {
|
|
185
|
+
let obj = super.toObject(filter);
|
|
184
186
|
|
|
185
187
|
// Check if there's been any edited portal information
|
|
186
188
|
let portals = this.portalsArray.filter(a => portalFilter(a))
|
package/src/records/portal.ts
CHANGED
|
@@ -19,7 +19,9 @@ export class Portal<T extends RecordFieldsMap> implements PortalBase<T> {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
create() {
|
|
22
|
-
let fields
|
|
22
|
+
let fields: {
|
|
23
|
+
[key: string]: string
|
|
24
|
+
} = {}
|
|
23
25
|
for (let _field of this.record.layout.metadata.portalMetaData[this.name]) {
|
|
24
26
|
fields[_field.name] = ""
|
|
25
27
|
}
|
|
@@ -2,12 +2,16 @@ import { RecordBase } from "./recordBase.js";
|
|
|
2
2
|
import { extraBodyOptions, RecordTypes } from "../types.js";
|
|
3
3
|
import { RecordFieldsMap } from "../layouts/recordFieldsMap.js";
|
|
4
4
|
import { PortalBase } from "./portalBase.js";
|
|
5
|
+
import { FieldBase, FieldValue } from "./fieldBase.js";
|
|
5
6
|
export declare class PortalRecord<T extends RecordFieldsMap> extends RecordBase<T> {
|
|
6
7
|
readonly portal: PortalBase<T>;
|
|
7
8
|
readonly type = RecordTypes.PORTAL;
|
|
8
|
-
constructor(record: any
|
|
9
|
+
constructor(record: RecordBase<any>, portal: PortalBase<any>, recordId: number, modId?: number, fieldData?: {});
|
|
9
10
|
_onSave(): void;
|
|
10
11
|
commit(extraBody?: extraBodyOptions): Promise<import("./layoutRecord.js").LayoutRecord<import("../index.js").LayoutInterface, string>>;
|
|
11
|
-
toObject(fieldFilter:
|
|
12
|
-
|
|
12
|
+
toObject(fieldFilter: (a: FieldBase<FieldValue>) => boolean): {
|
|
13
|
+
[key: string]: string;
|
|
14
|
+
modId: string;
|
|
15
|
+
recordId: string;
|
|
16
|
+
};
|
|
13
17
|
}
|
|
@@ -21,15 +21,12 @@ export class PortalRecord extends RecordBase {
|
|
|
21
21
|
toObject(fieldFilter) {
|
|
22
22
|
super.toObject();
|
|
23
23
|
let res = {
|
|
24
|
-
recordId: this.recordId === -1 ? undefined : this.recordId,
|
|
25
|
-
modId: this.modId === -1 ? undefined : this.modId
|
|
24
|
+
recordId: this.recordId === -1 ? undefined : this.recordId.toString(),
|
|
25
|
+
modId: this.modId === -1 ? undefined : this.modId.toString()
|
|
26
26
|
};
|
|
27
27
|
for (let field of this.fieldsArray.filter(a => fieldFilter(a)))
|
|
28
|
-
res[field.id] = field.value;
|
|
28
|
+
res[field.id] = field.value.toString();
|
|
29
29
|
// console.log(res)
|
|
30
30
|
return res;
|
|
31
31
|
}
|
|
32
|
-
getField(field) {
|
|
33
|
-
return this.fieldsArray.find(_field => _field.id === field) || this.fieldsArray.find(_field => _field.id === this.portal.name + "::" + field);
|
|
34
|
-
}
|
|
35
32
|
}
|
|
@@ -3,16 +3,17 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import {RecordBase} from "./recordBase.js";
|
|
6
|
-
import {extraBodyOptions,
|
|
6
|
+
import {extraBodyOptions, RecordTypes} from "../types.js";
|
|
7
7
|
|
|
8
8
|
import {RecordFieldsMap} from "../layouts/recordFieldsMap.js";
|
|
9
9
|
import {PortalBase} from "./portalBase.js";
|
|
10
|
+
import {FieldBase, FieldValue} from "./fieldBase.js";
|
|
10
11
|
|
|
11
12
|
export class PortalRecord<T extends RecordFieldsMap> extends RecordBase<T> {
|
|
12
13
|
readonly portal: PortalBase<T>;
|
|
13
14
|
readonly type = RecordTypes.PORTAL
|
|
14
15
|
|
|
15
|
-
constructor(record
|
|
16
|
+
constructor(record: RecordBase<any>, portal: PortalBase<any>, recordId: number, modId = recordId, fieldData = {}) {
|
|
16
17
|
super(record.layout, recordId, modId);
|
|
17
18
|
|
|
18
19
|
this.portal = portal
|
|
@@ -28,18 +29,18 @@ export class PortalRecord<T extends RecordFieldsMap> extends RecordBase<T> {
|
|
|
28
29
|
return this.portal.record.commit(extraBody)
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
toObject(fieldFilter
|
|
32
|
+
toObject(fieldFilter: (a: FieldBase<FieldValue>) => boolean) {
|
|
32
33
|
super.toObject()
|
|
33
|
-
let res
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
let res: {
|
|
35
|
+
"modId": string,
|
|
36
|
+
"recordId": string
|
|
37
|
+
[key: string]: string
|
|
38
|
+
} = {
|
|
39
|
+
recordId: this.recordId === -1 ? undefined : this.recordId.toString(),
|
|
40
|
+
modId: this.modId === -1 ? undefined : this.modId.toString()
|
|
41
|
+
}
|
|
42
|
+
for (let field of this.fieldsArray.filter(a => fieldFilter(a))) res[field.id] = field.value.toString()
|
|
38
43
|
// console.log(res)
|
|
39
44
|
return res
|
|
40
45
|
}
|
|
41
|
-
|
|
42
|
-
getField(field) {
|
|
43
|
-
return this.fieldsArray.find(_field => _field.id === field) || this.fieldsArray.find(_field => _field.id === this.portal.name + "::" + field)
|
|
44
|
-
}
|
|
45
46
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
3
|
import { FieldBase, FieldValue } from "./fieldBase.js";
|
|
4
|
-
import {
|
|
4
|
+
import { RecordTypes } from "../types.js";
|
|
5
5
|
import { RecordFieldsMap } from "../layouts/recordFieldsMap.js";
|
|
6
6
|
import { LayoutBase } from "../layouts/layoutBase.js";
|
|
7
|
+
import { ApiFieldData, ApiRowDataDef } from "../models/apiResults.js";
|
|
7
8
|
export declare class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
8
9
|
readonly layout: LayoutBase;
|
|
9
10
|
readonly type: RecordTypes;
|
|
@@ -11,11 +12,11 @@ export declare class RecordBase<T extends RecordFieldsMap> extends EventEmitter
|
|
|
11
12
|
modId: number;
|
|
12
13
|
fields: T;
|
|
13
14
|
protected portalData: any[];
|
|
14
|
-
constructor(layout:
|
|
15
|
+
constructor(layout: LayoutBase, recordId: number, modId?: number);
|
|
15
16
|
get endpoint(): string;
|
|
16
17
|
get edited(): boolean;
|
|
17
18
|
get fieldsArray(): FieldBase<FieldValue>[];
|
|
18
|
-
protected processFieldData(fieldData:
|
|
19
|
+
protected processFieldData(fieldData: ApiFieldData): T;
|
|
19
20
|
_onSave(): void;
|
|
20
|
-
toObject(filter?: (a:
|
|
21
|
+
toObject(filter?: (a: FieldBase<FieldValue>) => boolean): Partial<Omit<ApiRowDataDef, "portalDataInfo">>;
|
|
21
22
|
}
|
|
@@ -67,7 +67,7 @@ export class RecordBase extends EventEmitter {
|
|
|
67
67
|
for (let field of this.fieldsArray)
|
|
68
68
|
field.edited = false;
|
|
69
69
|
}
|
|
70
|
-
toObject(filter = (a) => a.edited
|
|
70
|
+
toObject(filter = (a) => a.edited) {
|
|
71
71
|
let fields_processed = {};
|
|
72
72
|
let field;
|
|
73
73
|
for (field of this.fieldsArray.filter(field => filter(field))) {
|
|
@@ -91,8 +91,8 @@ export class RecordBase extends EventEmitter {
|
|
|
91
91
|
fields_processed[field.id] = value;
|
|
92
92
|
}
|
|
93
93
|
let obj = {
|
|
94
|
-
"recordId": this.recordId,
|
|
95
|
-
"modId": this.modId,
|
|
94
|
+
"recordId": this.recordId.toString(),
|
|
95
|
+
"modId": this.modId.toString(),
|
|
96
96
|
"fieldData": fields_processed
|
|
97
97
|
};
|
|
98
98
|
return obj;
|
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
import {EventEmitter} from "events";
|
|
6
6
|
import * as moment from "moment";
|
|
7
7
|
import {FieldBase, FieldValue} from "./fieldBase.js";
|
|
8
|
-
import {
|
|
8
|
+
import {RecordTypes} from "../types.js";
|
|
9
9
|
import {RecordFieldsMap} from "../layouts/recordFieldsMap.js";
|
|
10
10
|
import {LayoutBase} from "../layouts/layoutBase.js";
|
|
11
|
+
import {ApiFieldData, ApiRowDataDef} from "../models/apiResults.js";
|
|
11
12
|
|
|
12
13
|
export class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
13
14
|
readonly layout: LayoutBase;
|
|
@@ -17,7 +18,7 @@ export class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
|
17
18
|
fields: T;
|
|
18
19
|
protected portalData: any[];
|
|
19
20
|
|
|
20
|
-
constructor(layout, recordId, modId = recordId) {
|
|
21
|
+
constructor(layout: LayoutBase, recordId: number, modId = recordId) {
|
|
21
22
|
super();
|
|
22
23
|
this.layout = layout
|
|
23
24
|
this.recordId = recordId
|
|
@@ -36,7 +37,7 @@ export class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
|
36
37
|
return Object.values(this.fields)
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
protected processFieldData(fieldData) {
|
|
40
|
+
protected processFieldData(fieldData: ApiFieldData) {
|
|
40
41
|
let fields: RecordFieldsMap = {}
|
|
41
42
|
|
|
42
43
|
for (let key of Object.keys(fieldData)) {
|
|
@@ -79,12 +80,8 @@ export class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
|
79
80
|
for (let field of this.fieldsArray) field.edited = false
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
toObject(filter = (a) => a.edited,
|
|
83
|
-
|
|
84
|
-
portalRowFilter = (a) => a.edited,
|
|
85
|
-
portalFieldFilter = (a) => a.edited
|
|
86
|
-
): recordObject {
|
|
87
|
-
let fields_processed = {}
|
|
83
|
+
toObject(filter = (a: FieldBase<FieldValue>) => a.edited): Partial<Omit<ApiRowDataDef, "portalDataInfo">> {
|
|
84
|
+
let fields_processed: ApiFieldData = {}
|
|
88
85
|
let field: FieldBase<FieldValue>
|
|
89
86
|
for (field of this.fieldsArray.filter(field => filter(field))) {
|
|
90
87
|
let value = field.value
|
|
@@ -109,8 +106,8 @@ export class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
|
109
106
|
fields_processed[field.id] = value
|
|
110
107
|
}
|
|
111
108
|
let obj = {
|
|
112
|
-
"recordId": this.recordId,
|
|
113
|
-
"modId": this.modId,
|
|
109
|
+
"recordId": this.recordId.toString(),
|
|
110
|
+
"modId": this.modId.toString(),
|
|
114
111
|
"fieldData": fields_processed
|
|
115
112
|
}
|
|
116
113
|
return obj
|