@jd-data-limited/easy-fm 4.0.3 → 4.0.5
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 +6 -1
- package/src/FMError.d.ts +0 -1
- package/src/FMError.js +0 -1
- package/src/FMError.ts +0 -1
- package/src/bin/cli.d.ts +2 -0
- package/src/bin/cli.js +19 -0
- package/src/bin/cli.ts +22 -0
- package/src/bin/example.xml +0 -0
- package/src/bin/generateTypes.d.ts +1 -0
- package/src/bin/generateTypes.js +250 -0
- package/src/bin/generateTypes.ts +186 -0
- package/src/connection/FMHost.js +12 -3
- package/src/connection/FMHost.ts +12 -3
- package/src/connection/database.js +4 -4
- package/src/connection/database.ts +5 -5
- package/src/index.d.ts +2 -1
- package/src/index.js +2 -1
- package/src/index.ts +4 -1
- package/src/layouts/layout.d.ts +1 -1
- package/src/layouts/layout.js +7 -2
- package/src/layouts/layout.ts +5 -2
- package/src/layouts/layoutRecordManager.js +3 -3
- package/src/layouts/layoutRecordManager.ts +3 -3
- package/src/models/apiResults.d.ts +1 -1
- package/src/models/apiResults.ts +1 -1
- package/src/records/field.d.ts +2 -1
- package/src/records/field.js +4 -0
- package/src/records/getOperations/recordGetOperation.d.ts +2 -1
- package/src/records/getOperations/recordGetOperation.js +33 -26
- package/src/records/getOperations/recordGetOperation.ts +39 -33
- package/src/records/layoutRecord.d.ts +3 -2
- package/src/records/layoutRecord.js +53 -8
- package/src/records/layoutRecord.ts +56 -9
- package/src/records/portal.d.ts +1 -1
- package/src/records/portal.js +3 -3
- package/src/records/portal.ts +3 -3
- package/src/records/portalRecord.d.ts +3 -2
- package/src/records/portalRecord.js +2 -4
- package/src/records/portalRecord.ts +7 -11
- package/src/records/recordBase.d.ts +3 -4
- package/src/records/recordBase.js +3 -32
- package/src/records/recordBase.ts +5 -37
- package/src/utils/fmQuery.d.ts +4 -0
- package/src/utils/fmQuery.js +20 -0
- package/src/utils/query.d.ts +4 -0
- package/src/utils/query.js +20 -0
- package/src/utils/query.ts +25 -0
- package/src/records/field.ts +0 -10
|
@@ -9,9 +9,10 @@ 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 {ApiPortalData, ApiRecordResponseObj} from "../models/apiResults.js";
|
|
12
|
+
import {ApiFieldData, ApiPortalData, ApiRecordResponseObj, ApiRowDataDef} from "../models/apiResults.js";
|
|
13
13
|
import {LayoutBase} from "../layouts/layoutBase.js"
|
|
14
14
|
import {FieldBase, FieldValue} from "./fieldBase.js";
|
|
15
|
+
import * as moment from "moment/moment.js";
|
|
15
16
|
|
|
16
17
|
export class LayoutRecord<LAYOUT extends LayoutInterface> extends RecordBase<LAYOUT["fields"]> implements LayoutRecordBase {
|
|
17
18
|
// @ts-ignore
|
|
@@ -25,8 +26,7 @@ export class LayoutRecord<LAYOUT extends LayoutInterface> extends RecordBase<LAY
|
|
|
25
26
|
fieldData: Record<string, string | number> = {},
|
|
26
27
|
portalData: ApiPortalData | null = null, portalsToInclude: (keyof LAYOUT["portals"])[] = [])
|
|
27
28
|
{
|
|
28
|
-
super(layout, parseInt(recordId as string), parseInt(modId as string));
|
|
29
|
-
this.processFieldData(fieldData)
|
|
29
|
+
super(layout, parseInt(recordId as string), parseInt(modId as string), fieldData);
|
|
30
30
|
this.portalsToInclude = portalsToInclude
|
|
31
31
|
if (portalData) {
|
|
32
32
|
this.processPortalData(portalData)
|
|
@@ -47,7 +47,7 @@ export class LayoutRecord<LAYOUT extends LayoutInterface> extends RecordBase<LAY
|
|
|
47
47
|
if (extraBody.scripts.after.parameter) data["script.param"] = extraBody.scripts.after.parameter
|
|
48
48
|
}
|
|
49
49
|
if (extraBody.scripts?.prerequest) {
|
|
50
|
-
data["script.prerequest"] = extraBody.scripts.
|
|
50
|
+
data["script.prerequest"] = extraBody.scripts.prerequest.name
|
|
51
51
|
if (extraBody.scripts.prerequest.parameter) data["script.prerequest.param"] = extraBody.scripts.prerequest.parameter
|
|
52
52
|
}
|
|
53
53
|
if (extraBody.scripts?.presort) {
|
|
@@ -63,7 +63,10 @@ export class LayoutRecord<LAYOUT extends LayoutInterface> extends RecordBase<LAY
|
|
|
63
63
|
body: JSON.stringify(data)
|
|
64
64
|
})
|
|
65
65
|
|
|
66
|
-
if (
|
|
66
|
+
if (!res.response) {
|
|
67
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res)
|
|
68
|
+
}
|
|
69
|
+
else if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
67
70
|
throw new FMError(res.response.scriptError, res.httpStatus, res)
|
|
68
71
|
}
|
|
69
72
|
else if (res.messages[0].code === "0") {
|
|
@@ -88,7 +91,10 @@ export class LayoutRecord<LAYOUT extends LayoutInterface> extends RecordBase<LAY
|
|
|
88
91
|
method: "PATCH",
|
|
89
92
|
body: JSON.stringify(data)
|
|
90
93
|
})
|
|
91
|
-
if (
|
|
94
|
+
if (!res.response) {
|
|
95
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res)
|
|
96
|
+
}
|
|
97
|
+
else if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
92
98
|
throw new FMError(res.response.scriptError, res.httpStatus, res)
|
|
93
99
|
}
|
|
94
100
|
else if (res.messages[0].code === "0") {
|
|
@@ -127,13 +133,15 @@ export class LayoutRecord<LAYOUT extends LayoutInterface> extends RecordBase<LAY
|
|
|
127
133
|
method: "GET"
|
|
128
134
|
})
|
|
129
135
|
|
|
130
|
-
if (res.messages[0].code === "0") {
|
|
136
|
+
if (res.response && res.messages[0].code === "0") {
|
|
131
137
|
// console.log(res, res.response.data)
|
|
132
138
|
this.modId = +res.response.data[0].modId
|
|
133
139
|
this.processFieldData(res.response.data[0].fieldData)
|
|
134
140
|
this.portalData = []
|
|
135
141
|
if (res.response.data[0].portalData) this.processPortalData(res.response.data[0].portalData)
|
|
136
142
|
return this
|
|
143
|
+
} else {
|
|
144
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res)
|
|
137
145
|
}
|
|
138
146
|
}
|
|
139
147
|
|
|
@@ -143,7 +151,10 @@ export class LayoutRecord<LAYOUT extends LayoutInterface> extends RecordBase<LAY
|
|
|
143
151
|
port: 443,
|
|
144
152
|
method: "POST"
|
|
145
153
|
})
|
|
146
|
-
if (
|
|
154
|
+
if (!res.response) {
|
|
155
|
+
throw new FMError(res.messages[0].code, res.httpStatus, res, trace)
|
|
156
|
+
}
|
|
157
|
+
else if (typeof res.response.scriptError !== "undefined" && res.response.scriptError !== '0') {
|
|
147
158
|
throw new FMError(res.response.scriptError, res.httpStatus, res, trace)
|
|
148
159
|
}
|
|
149
160
|
else if (res.messages[0].code === "0") {
|
|
@@ -176,13 +187,49 @@ export class LayoutRecord<LAYOUT extends LayoutInterface> extends RecordBase<LAY
|
|
|
176
187
|
}
|
|
177
188
|
}
|
|
178
189
|
|
|
190
|
+
fieldsToObject(filter = (a: FieldBase<FieldValue>) => a.edited): Omit<ApiRowDataDef, "portalData"> {
|
|
191
|
+
let fields_processed: ApiFieldData = {}
|
|
192
|
+
let field: FieldBase<FieldValue>
|
|
193
|
+
for (field of this.fieldsArray.filter(field => filter(field))) {
|
|
194
|
+
let value = field.value as string | number | Date
|
|
195
|
+
if (value instanceof Date) {
|
|
196
|
+
// @ts-ignore
|
|
197
|
+
let _value = moment.default(value)
|
|
198
|
+
.utcOffset(this.layout.database.host.timezoneOffset)
|
|
199
|
+
|
|
200
|
+
// @ts-ignore
|
|
201
|
+
|
|
202
|
+
switch (field.metadata.result) {
|
|
203
|
+
case "time":
|
|
204
|
+
value = _value.format(this.layout.database.host.metadata.productInfo.timeFormat.replace("dd", "DD"))
|
|
205
|
+
break
|
|
206
|
+
case "date":
|
|
207
|
+
value = _value.format(this.layout.database.host.metadata.productInfo.dateFormat.replace("dd", "DD"))
|
|
208
|
+
break
|
|
209
|
+
default:
|
|
210
|
+
value = _value.format(this.layout.database.host.metadata.productInfo.timeStampFormat.replace("dd", "DD"))
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
fields_processed[field.id] = value
|
|
214
|
+
}
|
|
215
|
+
let obj = {
|
|
216
|
+
"recordId": this.recordId.toString(),
|
|
217
|
+
"modId": this.modId.toString(),
|
|
218
|
+
"fieldData": fields_processed
|
|
219
|
+
}
|
|
220
|
+
return obj
|
|
221
|
+
}
|
|
222
|
+
|
|
179
223
|
toObject(
|
|
180
224
|
filter: (a: FieldBase<FieldValue>) => any = (a) => a.edited,
|
|
181
225
|
portalFilter: (a: Portal<any>) => any = (a) => a.records.find(record => record.edited),
|
|
182
226
|
portalRowFilter: (a: PortalRecord<never>) => any = (a) => a.edited,
|
|
183
227
|
portalFieldFilter: (a: FieldBase<FieldValue>) => any = (a) => a.edited
|
|
184
228
|
) {
|
|
185
|
-
let obj =
|
|
229
|
+
let obj: ApiRowDataDef = {
|
|
230
|
+
...this.fieldsToObject(filter),
|
|
231
|
+
portalData: {}
|
|
232
|
+
};
|
|
186
233
|
|
|
187
234
|
// Check if there's been any edited portal information
|
|
188
235
|
let portals = this.portalsArray.filter(a => portalFilter(a))
|
package/src/records/portal.d.ts
CHANGED
package/src/records/portal.js
CHANGED
|
@@ -5,14 +5,14 @@ import { PortalRecord } from "./portalRecord.js";
|
|
|
5
5
|
export class Portal {
|
|
6
6
|
record;
|
|
7
7
|
name;
|
|
8
|
-
records;
|
|
8
|
+
records = [];
|
|
9
9
|
constructor(record, name) {
|
|
10
10
|
this.record = record;
|
|
11
11
|
this.name = name;
|
|
12
12
|
}
|
|
13
|
-
create() {
|
|
13
|
+
async create() {
|
|
14
14
|
let fields = {};
|
|
15
|
-
for (let _field of this.record.layout.
|
|
15
|
+
for (let _field of (await this.record.layout.getLayoutMeta()).portalMetaData[this.name]) {
|
|
16
16
|
fields[_field.name] = "";
|
|
17
17
|
}
|
|
18
18
|
let record = new PortalRecord(this.record, this, -1, -1, fields);
|
package/src/records/portal.ts
CHANGED
|
@@ -10,18 +10,18 @@ import {LayoutRecord} from "./layoutRecord.js";
|
|
|
10
10
|
export class Portal<T extends RecordFieldsMap> implements PortalBase<T> {
|
|
11
11
|
readonly record: LayoutRecord<any>;
|
|
12
12
|
readonly name: string;
|
|
13
|
-
public records: PortalRecord<T>[];
|
|
13
|
+
public records: PortalRecord<T>[] = [];
|
|
14
14
|
|
|
15
15
|
constructor(record: LayoutRecord<any>, name: string) {
|
|
16
16
|
this.record = record
|
|
17
17
|
this.name = name
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
create() {
|
|
20
|
+
async create() {
|
|
21
21
|
let fields: {
|
|
22
22
|
[key: string]: string
|
|
23
23
|
} = {}
|
|
24
|
-
for (let _field of this.record.layout.
|
|
24
|
+
for (let _field of (await this.record.layout.getLayoutMeta()).portalMetaData[this.name]) {
|
|
25
25
|
fields[_field.name] = ""
|
|
26
26
|
}
|
|
27
27
|
let record = new PortalRecord<T>(this.record, this, -1, -1, fields)
|
|
@@ -10,8 +10,9 @@ export declare class PortalRecord<T extends RecordFieldsMap> extends RecordBase<
|
|
|
10
10
|
_onSave(): void;
|
|
11
11
|
commit(extraBody?: extraBodyOptions): Promise<import("./layoutRecord.js").LayoutRecord<import("../index.js").LayoutInterface>>;
|
|
12
12
|
toObject(fieldFilter: (a: FieldBase<FieldValue>) => boolean): {
|
|
13
|
+
modId?: string;
|
|
14
|
+
recordId?: string;
|
|
15
|
+
} & {
|
|
13
16
|
[key: string]: string;
|
|
14
|
-
modId: string;
|
|
15
|
-
recordId: string;
|
|
16
17
|
};
|
|
17
18
|
}
|
|
@@ -7,9 +7,8 @@ export class PortalRecord extends RecordBase {
|
|
|
7
7
|
portal;
|
|
8
8
|
type = RecordTypes.PORTAL;
|
|
9
9
|
constructor(record, portal, recordId, modId = recordId, fieldData = {}) {
|
|
10
|
-
super(record.layout, recordId, modId);
|
|
10
|
+
super(record.layout, recordId, modId, fieldData);
|
|
11
11
|
this.portal = portal;
|
|
12
|
-
this.processFieldData(fieldData);
|
|
13
12
|
}
|
|
14
13
|
_onSave() {
|
|
15
14
|
super._onSave();
|
|
@@ -19,13 +18,12 @@ export class PortalRecord extends RecordBase {
|
|
|
19
18
|
return this.portal.record.commit(extraBody);
|
|
20
19
|
}
|
|
21
20
|
toObject(fieldFilter) {
|
|
22
|
-
super.toObject();
|
|
23
21
|
let res = {
|
|
24
22
|
recordId: this.recordId === -1 ? undefined : this.recordId.toString(),
|
|
25
23
|
modId: this.modId === -1 ? undefined : this.modId.toString()
|
|
26
24
|
};
|
|
27
25
|
for (let field of this.fieldsArray.filter(a => fieldFilter(a)))
|
|
28
|
-
res[field.id] = field.value
|
|
26
|
+
res[field.id] = field.value?.toString();
|
|
29
27
|
// console.log(res)
|
|
30
28
|
return res;
|
|
31
29
|
}
|
|
@@ -14,10 +14,8 @@ export class PortalRecord<T extends RecordFieldsMap> extends RecordBase<T> {
|
|
|
14
14
|
readonly type = RecordTypes.PORTAL
|
|
15
15
|
|
|
16
16
|
constructor(record: RecordBase<any>, portal: PortalBase<any>, recordId: number, modId = recordId, fieldData = {}) {
|
|
17
|
-
super(record.layout, recordId, modId);
|
|
18
|
-
|
|
17
|
+
super(record.layout, recordId, modId, fieldData);
|
|
19
18
|
this.portal = portal
|
|
20
|
-
this.processFieldData(fieldData)
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
_onSave() {
|
|
@@ -29,17 +27,15 @@ export class PortalRecord<T extends RecordFieldsMap> extends RecordBase<T> {
|
|
|
29
27
|
return this.portal.record.commit(extraBody)
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
toObject(fieldFilter: (a: FieldBase<FieldValue>) => boolean) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
[key: string]: string
|
|
38
|
-
} = {
|
|
30
|
+
toObject(fieldFilter: (a: FieldBase<FieldValue>) => boolean): {
|
|
31
|
+
modId?: string,
|
|
32
|
+
recordId?: string,
|
|
33
|
+
} & {[key: string]: string} {
|
|
34
|
+
let res: any = {
|
|
39
35
|
recordId: this.recordId === -1 ? undefined : this.recordId.toString(),
|
|
40
36
|
modId: this.modId === -1 ? undefined : this.modId.toString()
|
|
41
37
|
}
|
|
42
|
-
for (let field of this.fieldsArray.filter(a => fieldFilter(a))) res[field.id] = field.value
|
|
38
|
+
for (let field of this.fieldsArray.filter(a => fieldFilter(a))) res[field.id] = field.value?.toString()
|
|
43
39
|
// console.log(res)
|
|
44
40
|
return res
|
|
45
41
|
}
|
|
@@ -4,19 +4,18 @@ import { FieldBase, FieldValue } from "./fieldBase.js";
|
|
|
4
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
|
|
8
|
-
export declare class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
7
|
+
import { ApiFieldData } from "../models/apiResults.js";
|
|
8
|
+
export declare abstract class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
9
9
|
readonly layout: LayoutBase;
|
|
10
10
|
readonly type: RecordTypes;
|
|
11
11
|
recordId: number;
|
|
12
12
|
modId: number;
|
|
13
13
|
fields: T;
|
|
14
14
|
protected portalData: any[];
|
|
15
|
-
constructor(layout: LayoutBase, recordId: number, modId
|
|
15
|
+
protected constructor(layout: LayoutBase, recordId: number, modId: number | undefined, fieldData: ApiFieldData);
|
|
16
16
|
get endpoint(): string;
|
|
17
17
|
get edited(): boolean;
|
|
18
18
|
get fieldsArray(): FieldBase<FieldValue>[];
|
|
19
19
|
protected processFieldData(fieldData: ApiFieldData): T;
|
|
20
20
|
_onSave(): void;
|
|
21
|
-
toObject(filter?: (a: FieldBase<FieldValue>) => boolean): Partial<Omit<ApiRowDataDef, "portalDataInfo">>;
|
|
22
21
|
}
|
|
@@ -11,12 +11,13 @@ export class RecordBase extends EventEmitter {
|
|
|
11
11
|
recordId;
|
|
12
12
|
modId;
|
|
13
13
|
fields;
|
|
14
|
-
portalData;
|
|
15
|
-
constructor(layout, recordId, modId = recordId) {
|
|
14
|
+
portalData = [];
|
|
15
|
+
constructor(layout, recordId, modId = recordId, fieldData) {
|
|
16
16
|
super();
|
|
17
17
|
this.layout = layout;
|
|
18
18
|
this.recordId = recordId;
|
|
19
19
|
this.modId = modId;
|
|
20
|
+
this.fields = this.processFieldData(fieldData);
|
|
20
21
|
}
|
|
21
22
|
get endpoint() {
|
|
22
23
|
return `${this.layout.endpoint}/records/${this.recordId}`;
|
|
@@ -67,34 +68,4 @@ export class RecordBase extends EventEmitter {
|
|
|
67
68
|
for (let field of this.fieldsArray)
|
|
68
69
|
field.edited = false;
|
|
69
70
|
}
|
|
70
|
-
toObject(filter = (a) => a.edited) {
|
|
71
|
-
let fields_processed = {};
|
|
72
|
-
let field;
|
|
73
|
-
for (field of this.fieldsArray.filter(field => filter(field))) {
|
|
74
|
-
let value = field.value;
|
|
75
|
-
if (value instanceof Date) {
|
|
76
|
-
// @ts-ignore
|
|
77
|
-
let _value = moment.default(value)
|
|
78
|
-
.utcOffset(this.layout.database.host.timezoneOffset);
|
|
79
|
-
// @ts-ignore
|
|
80
|
-
switch (field.metadata.result) {
|
|
81
|
-
case "time":
|
|
82
|
-
value = _value.format(this.layout.database.host.metadata.productInfo.timeFormat.replace("dd", "DD"));
|
|
83
|
-
break;
|
|
84
|
-
case "date":
|
|
85
|
-
value = _value.format(this.layout.database.host.metadata.productInfo.dateFormat.replace("dd", "DD"));
|
|
86
|
-
break;
|
|
87
|
-
default:
|
|
88
|
-
value = _value.format(this.layout.database.host.metadata.productInfo.timeStampFormat.replace("dd", "DD"));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
fields_processed[field.id] = value;
|
|
92
|
-
}
|
|
93
|
-
let obj = {
|
|
94
|
-
"recordId": this.recordId.toString(),
|
|
95
|
-
"modId": this.modId.toString(),
|
|
96
|
-
"fieldData": fields_processed
|
|
97
|
-
};
|
|
98
|
-
return obj;
|
|
99
|
-
}
|
|
100
71
|
}
|
|
@@ -8,21 +8,22 @@ import {FieldBase, FieldValue} from "./fieldBase.js";
|
|
|
8
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
|
|
11
|
+
import {ApiFieldData} from "../models/apiResults.js";
|
|
12
12
|
|
|
13
|
-
export class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
13
|
+
export abstract class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
14
14
|
readonly layout: LayoutBase;
|
|
15
15
|
readonly type: RecordTypes = RecordTypes.UNKNOWN;
|
|
16
16
|
public recordId: number;
|
|
17
17
|
modId: number;
|
|
18
18
|
fields: T;
|
|
19
|
-
protected portalData: any[];
|
|
19
|
+
protected portalData: any[] = [];
|
|
20
20
|
|
|
21
|
-
constructor(layout: LayoutBase, recordId: number, modId = recordId) {
|
|
21
|
+
protected constructor(layout: LayoutBase, recordId: number, modId = recordId, fieldData: ApiFieldData) {
|
|
22
22
|
super();
|
|
23
23
|
this.layout = layout
|
|
24
24
|
this.recordId = recordId
|
|
25
25
|
this.modId = modId
|
|
26
|
+
this.fields = this.processFieldData(fieldData)
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
get endpoint(): string {
|
|
@@ -79,37 +80,4 @@ export class RecordBase<T extends RecordFieldsMap> extends EventEmitter {
|
|
|
79
80
|
this.emit("saved")
|
|
80
81
|
for (let field of this.fieldsArray) field.edited = false
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
-
toObject(filter = (a: FieldBase<FieldValue>) => a.edited): Partial<Omit<ApiRowDataDef, "portalDataInfo">> {
|
|
84
|
-
let fields_processed: ApiFieldData = {}
|
|
85
|
-
let field: FieldBase<FieldValue>
|
|
86
|
-
for (field of this.fieldsArray.filter(field => filter(field))) {
|
|
87
|
-
let value = field.value
|
|
88
|
-
if (value instanceof Date) {
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
let _value = moment.default(value)
|
|
91
|
-
.utcOffset(this.layout.database.host.timezoneOffset)
|
|
92
|
-
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
|
|
95
|
-
switch (field.metadata.result) {
|
|
96
|
-
case "time":
|
|
97
|
-
value = _value.format(this.layout.database.host.metadata.productInfo.timeFormat.replace("dd", "DD"))
|
|
98
|
-
break
|
|
99
|
-
case "date":
|
|
100
|
-
value = _value.format(this.layout.database.host.metadata.productInfo.dateFormat.replace("dd", "DD"))
|
|
101
|
-
break
|
|
102
|
-
default:
|
|
103
|
-
value = _value.format(this.layout.database.host.metadata.productInfo.timeStampFormat.replace("dd", "DD"))
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
fields_processed[field.id] = value
|
|
107
|
-
}
|
|
108
|
-
let obj = {
|
|
109
|
-
"recordId": this.recordId.toString(),
|
|
110
|
-
"modId": this.modId.toString(),
|
|
111
|
-
"fieldData": fields_processed
|
|
112
|
-
}
|
|
113
|
-
return obj
|
|
114
|
-
}
|
|
115
83
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024. See LICENSE file for more information
|
|
3
|
+
*/
|
|
4
|
+
const SPECIAL_CHARACTERS = ["\\", "=", "<", "≤", "≥", ">", "…", "...", "//", "@", "#", "*", "\"", "~"];
|
|
5
|
+
export function fmQueryEscape(str) {
|
|
6
|
+
for (let char of SPECIAL_CHARACTERS) {
|
|
7
|
+
str = str.replace(char, `\\${char}`);
|
|
8
|
+
}
|
|
9
|
+
return str;
|
|
10
|
+
}
|
|
11
|
+
export function fmQuery(strings, ...args) {
|
|
12
|
+
let argStrings = args.map(item => {
|
|
13
|
+
return fmQueryEscape(item.toString());
|
|
14
|
+
});
|
|
15
|
+
// Zip the parameters together
|
|
16
|
+
const query = strings.map((str, index) => {
|
|
17
|
+
return str + (args[index] || '');
|
|
18
|
+
});
|
|
19
|
+
return query.join("");
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024. See LICENSE file for more information
|
|
3
|
+
*/
|
|
4
|
+
const SPECIAL_CHARACTERS = ["\\", "=", "<", "≤", "≥", ">", "…", "...", "//", "@", "#", "*", "\"", "~"];
|
|
5
|
+
export function queryEscape(str) {
|
|
6
|
+
for (let char of SPECIAL_CHARACTERS) {
|
|
7
|
+
str = str.replace(char, `\\${char}`);
|
|
8
|
+
}
|
|
9
|
+
return str;
|
|
10
|
+
}
|
|
11
|
+
export function query(strings, ...args) {
|
|
12
|
+
let argStrings = args.map(item => {
|
|
13
|
+
return queryEscape(item.toString());
|
|
14
|
+
});
|
|
15
|
+
// Zip the parameters together
|
|
16
|
+
const query = strings.map((str, index) => {
|
|
17
|
+
return str + (argStrings[index] || '');
|
|
18
|
+
});
|
|
19
|
+
return query.join("");
|
|
20
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024. See LICENSE file for more information
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const SPECIAL_CHARACTERS = ["\\", "=", "<", "≤", "≥", ">", "…", "...", "//", "@", "#", "*", "\"", "~"]
|
|
6
|
+
type QueryParameter = string | number | Date
|
|
7
|
+
|
|
8
|
+
export function queryEscape(str: string) {
|
|
9
|
+
for (let char of SPECIAL_CHARACTERS) {
|
|
10
|
+
str = str.replace(char, `\\${char}`)
|
|
11
|
+
}
|
|
12
|
+
return str
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function query(strings: TemplateStringsArray, ...args: QueryParameter[]) {
|
|
16
|
+
let argStrings = args.map(item => {
|
|
17
|
+
return queryEscape(item.toString())
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
// Zip the parameters together
|
|
21
|
+
const query = strings.map((str, index) => {
|
|
22
|
+
return str + (argStrings[index] || '')
|
|
23
|
+
})
|
|
24
|
+
return query.join("")
|
|
25
|
+
}
|
package/src/records/field.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2024. See LICENSE file for more information
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {RecordBase} from "./recordBase.js";
|
|
6
|
-
import {FieldBase, FieldValue} from "./fieldBase.js";
|
|
7
|
-
|
|
8
|
-
export class Field<T extends FieldValue> extends FieldBase<T> {
|
|
9
|
-
record: RecordBase<any>;
|
|
10
|
-
}
|