@jd-data-limited/easy-fm 3.2.8 → 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.
Files changed (75) hide show
  1. package/README.md +36 -24
  2. package/package.json +12 -9
  3. package/src/FMError.js +2 -2
  4. package/src/FMError.ts +2 -2
  5. package/src/connection/FMHost.d.ts +2 -1
  6. package/src/connection/FMHost.js +1 -2
  7. package/src/connection/FMHost.ts +4 -4
  8. package/src/connection/HostBase.d.ts +1 -1
  9. package/src/connection/HostBase.js +1 -1
  10. package/src/connection/HostBase.ts +2 -4
  11. package/src/connection/database.d.ts +10 -10
  12. package/src/connection/database.js +6 -17
  13. package/src/connection/database.ts +17 -27
  14. package/src/connection/databaseBase.d.ts +4 -4
  15. package/src/connection/databaseBase.js +1 -1
  16. package/src/connection/databaseBase.ts +4 -6
  17. package/src/databaseStructure.d.ts +6 -0
  18. package/src/databaseStructure.js +4 -0
  19. package/src/databaseStructure.ts +12 -0
  20. package/src/index.d.ts +3 -6
  21. package/src/index.js +3 -5
  22. package/src/index.ts +4 -9
  23. package/src/layouts/layout.d.ts +3 -17
  24. package/src/layouts/layout.js +2 -20
  25. package/src/layouts/layout.ts +5 -27
  26. package/src/layouts/layoutBase.d.ts +4 -4
  27. package/src/layouts/layoutBase.js +1 -1
  28. package/src/layouts/layoutBase.ts +5 -6
  29. package/src/layouts/layoutInterface.d.ts +1 -1
  30. package/src/layouts/layoutInterface.js +1 -1
  31. package/src/layouts/layoutInterface.ts +2 -2
  32. package/src/layouts/layoutRecordManager.d.ts +5 -6
  33. package/src/layouts/layoutRecordManager.js +5 -9
  34. package/src/layouts/layoutRecordManager.ts +12 -16
  35. package/src/layouts/recordFieldsMap.d.ts +2 -2
  36. package/src/layouts/recordFieldsMap.js +1 -1
  37. package/src/layouts/recordFieldsMap.ts +3 -3
  38. package/src/models/apiResults.d.ts +3 -3
  39. package/src/models/apiResults.js +1 -1
  40. package/src/models/apiResults.ts +2 -4
  41. package/src/records/field.d.ts +3 -23
  42. package/src/records/field.js +3 -152
  43. package/src/records/field.ts +4 -169
  44. package/src/records/fieldBase.d.ts +30 -0
  45. package/src/records/fieldBase.js +154 -0
  46. package/src/records/fieldBase.ts +174 -0
  47. package/src/records/getOperations/recordGetOperation.d.ts +47 -11
  48. package/src/records/getOperations/recordGetOperation.js +142 -31
  49. package/src/records/getOperations/recordGetOperation.ts +172 -30
  50. package/src/records/layoutRecord.d.ts +14 -11
  51. package/src/records/layoutRecord.js +7 -8
  52. package/src/records/layoutRecord.ts +32 -22
  53. package/src/records/portal.d.ts +6 -5
  54. package/src/records/portal.js +1 -1
  55. package/src/records/portal.ts +10 -8
  56. package/src/records/portalBase.d.ts +5 -4
  57. package/src/records/portalBase.js +1 -1
  58. package/src/records/portalBase.ts +6 -6
  59. package/src/records/portalRecord.d.ts +12 -8
  60. package/src/records/portalRecord.js +6 -8
  61. package/src/records/portalRecord.ts +17 -16
  62. package/src/records/recordBase.d.ts +11 -15
  63. package/src/records/recordBase.js +9 -13
  64. package/src/records/recordBase.ts +17 -25
  65. package/src/types.d.ts +18 -15
  66. package/src/types.js +7 -1
  67. package/src/types.ts +20 -16
  68. package/src/records/getOperations/find.d.ts +0 -15
  69. package/src/records/getOperations/find.js +0 -70
  70. package/src/records/getOperations/find.ts +0 -77
  71. package/src/records/getOperations/recordGetRange.d.ts +0 -13
  72. package/src/records/getOperations/recordGetRange.js +0 -77
  73. package/src/records/getOperations/recordGetRange.ts +0 -77
  74. package/src/records/portalRecordBase.d.ts +0 -4
  75. package/src/records/portalRecordBase.js +0 -6
@@ -1,77 +0,0 @@
1
- /*
2
- * Copyright (c) 2023. See LICENSE file for more information
3
- */
4
-
5
- import {RecordGetOperation} from "./recordGetOperation.js";
6
- import {LayoutRecord} from "../layoutRecord.js";
7
- import {LayoutInterface} from "../../layouts/layoutInterface";
8
- import {LayoutBase} from "../../layouts/layoutBase.js";
9
- import {FMError} from "../../FMError.js";
10
- import {ApiRecordResponseObj} from "../../models/apiResults";
11
-
12
- export class Find<T extends LayoutInterface> extends RecordGetOperation<T> {
13
- protected queries: object[]
14
-
15
- constructor(layout: LayoutBase, start = 0, limit = 100) {
16
- super(layout)
17
- this.setOffset(start)
18
- this.setLimit(limit)
19
- this.queries = []
20
- }
21
-
22
- private toObject() {
23
- let out = {query: this.queries, sort: undefined}
24
- if (this.sort.length !== 0) out.sort = this.sort
25
-
26
- for (let item of Object.keys(this.scripts)) {
27
- if (this.scripts[item]) {
28
- out[item] = this.scripts[item].name
29
- if (this.scripts[item].parameter) out[item + ".param"] = this.scripts[item].parameter
30
- }
31
- }
32
-
33
- if (this.limit !== 100) out["limit"] = this.limit
34
- if (this.offset !== 0) out["offset"] = this.offset
35
- if (this.limitPortals.length > 0) {
36
- out["portal"] = this.limitPortals.map(p => p.portalName)
37
- for (let item of this.limitPortals) {
38
- out["offset." + item.portalName.replace(/[^0-9A-z]/g, "")] = item.offset
39
- out["limit." + item.portalName.replace(/[^0-9A-z]/g, "")] = item.limit
40
- }
41
- }
42
-
43
- return out
44
- }
45
-
46
- addRequests(...requests) {
47
- for (let item of requests) this.queries.push(item)
48
- return this
49
- }
50
-
51
- /**
52
- * @deprecated in favour of .fetch()
53
- */
54
- run() {
55
- return this.fetch()
56
- }
57
-
58
- async fetch(): Promise<LayoutRecord<T["fields"], T["portals"]>[]> {
59
- let trace = new Error()
60
- await this.layout.getLayoutMeta()
61
- let res = await this.layout.database.apiRequest<ApiRecordResponseObj>(`${this.layout.endpoint}/_find`, {
62
- port: 443,
63
- method: "POST",
64
- body: JSON.stringify(this.toObject())
65
- })
66
- if (res.messages[0].code === "0") {
67
- // console.log("RESOLVING")
68
- if (!this.layout.metadata) await this.layout.getLayoutMeta()
69
- return res.response.data.map(item => {
70
- return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData)
71
- })
72
- }
73
- else {
74
- throw new FMError(res.messages[0].code, res.httpStatus, res, trace)
75
- }
76
- }
77
- }
@@ -1,13 +0,0 @@
1
- import { LayoutInterface } from "../../layouts/layoutInterface.js";
2
- import { RecordGetOperation } from "./recordGetOperation.js";
3
- import { LayoutRecord } from "../layoutRecord.js";
4
- import { extraBodyOptions } from "../../types.js";
5
- export declare class RecordGetRange<T extends LayoutInterface> extends RecordGetOperation<T> {
6
- constructor(layout: any, start?: number, limit?: number);
7
- private generateQueryParams;
8
- /**
9
- * @deprecated in favour of .fetch()
10
- */
11
- run(extraBody?: extraBodyOptions): Promise<LayoutRecord<T["fields"], T["portals"]>[]>;
12
- fetch(extraBody?: extraBodyOptions): Promise<LayoutRecord<T["fields"], T["portals"]>[]>;
13
- }
@@ -1,77 +0,0 @@
1
- /*
2
- * Copyright (c) 2023. See LICENSE file for more information
3
- */
4
- import { RecordGetOperation } from "./recordGetOperation.js";
5
- import { LayoutRecord } from "../layoutRecord.js";
6
- import { FMError } from "../../FMError.js";
7
- export class RecordGetRange extends RecordGetOperation {
8
- constructor(layout, start = 0, limit = 100) {
9
- super(layout);
10
- this.setOffset(start);
11
- this.setLimit(limit);
12
- }
13
- generateQueryParams(extraBody = {}) {
14
- let params = [];
15
- if (this.limit !== 100)
16
- params.push("_limit=" + this.limit);
17
- if (this.offset !== 0)
18
- params.push("_offset=" + this.offset);
19
- if (this.sort.length > 0)
20
- params.push("_sort=" + encodeURI(JSON.stringify(this.sort)));
21
- if (this.limitPortals.length > 0) {
22
- params.push("portal=" + encodeURI(JSON.stringify(this.limitPortals.map(p => p.portalName))));
23
- for (let item of this.limitPortals) {
24
- if (item.offset !== 0)
25
- params.push("_offset." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.offset);
26
- if (item.limit !== 100)
27
- params.push("_limit." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.limit);
28
- }
29
- }
30
- if (extraBody.scripts) {
31
- if (extraBody.scripts.prerequest) {
32
- params.push("script.prerequest=" + extraBody.scripts.prerequest.name);
33
- if (extraBody.scripts.prerequest.parameter)
34
- params.push("script.prerequest.param=" + extraBody.scripts.prerequest.parameter);
35
- }
36
- if (extraBody.scripts.presort) {
37
- params.push("script.presort=" + extraBody.scripts.presort.name);
38
- if (extraBody.scripts.presort.parameter)
39
- params.push("script.presort.param=" + extraBody.scripts.presort.parameter);
40
- }
41
- if (extraBody.scripts.after) {
42
- params.push("script=" + extraBody.scripts.after.name);
43
- if (extraBody.scripts.after.parameter)
44
- params.push("script.param=" + extraBody.scripts.after.parameter);
45
- }
46
- }
47
- if (params.length === 0)
48
- return "";
49
- return "?" + params.join("&");
50
- }
51
- /**
52
- * @deprecated in favour of .fetch()
53
- */
54
- run(extraBody = {}) {
55
- return this.fetch(extraBody);
56
- }
57
- async fetch(extraBody = {}) {
58
- let trace = new Error();
59
- let res = await this.layout.getLayoutMeta().then(() => {
60
- return this.layout.database.apiRequest(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
61
- method: "GET"
62
- });
63
- });
64
- if (res.messages[0].code === "0") {
65
- // console.log("RESOLVING")
66
- if (!this.layout.metadata)
67
- await this.layout.getLayoutMeta();
68
- let data = res.response.data.map(item => {
69
- return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData);
70
- });
71
- return data;
72
- }
73
- else {
74
- throw new FMError(res.messages[0].code, res.httpStatus, res, trace);
75
- }
76
- }
77
- }
@@ -1,77 +0,0 @@
1
- /*
2
- * Copyright (c) 2023. See LICENSE file for more information
3
- */
4
-
5
- import {LayoutInterface} from "../../layouts/layoutInterface.js";
6
- import {RecordGetOperation} from "./recordGetOperation.js";
7
- import {LayoutRecord} from "../layoutRecord.js";
8
- import {extraBodyOptions} from "../../types.js";
9
- import {FMError} from "../../FMError.js";
10
- import {ApiRecordResponseObj} from "../../models/apiResults";
11
-
12
- export class RecordGetRange<T extends LayoutInterface> extends RecordGetOperation<T> {
13
- constructor(layout, start = 0, limit = 100) {
14
- super(layout)
15
- this.setOffset(start)
16
- this.setLimit(limit)
17
- }
18
-
19
- private generateQueryParams(extraBody: extraBodyOptions = {}) {
20
- let params = []
21
- if (this.limit !== 100) params.push("_limit=" + this.limit)
22
- if (this.offset !== 0) params.push("_offset=" + this.offset)
23
- if (this.sort.length > 0) params.push("_sort=" + encodeURI(JSON.stringify(this.sort)))
24
- if (this.limitPortals.length > 0) {
25
- params.push("portal=" + encodeURI(JSON.stringify(this.limitPortals.map(p => p.portalName))))
26
- for (let item of this.limitPortals) {
27
- if (item.offset !== 0) params.push("_offset." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.offset)
28
- if (item.limit !== 100) params.push("_limit." + item.portalName.replace(/[^0-9A-z]/g, "") + "=" + item.limit)
29
- }
30
- }
31
- if (extraBody.scripts) {
32
- if (extraBody.scripts.prerequest) {
33
- params.push("script.prerequest=" + extraBody.scripts.prerequest.name)
34
- if (extraBody.scripts.prerequest.parameter) params.push("script.prerequest.param=" + extraBody.scripts.prerequest.parameter)
35
- }
36
- if (extraBody.scripts.presort) {
37
- params.push("script.presort=" + extraBody.scripts.presort.name)
38
- if (extraBody.scripts.presort.parameter) params.push("script.presort.param=" + extraBody.scripts.presort.parameter)
39
- }
40
- if (extraBody.scripts.after) {
41
- params.push("script=" + extraBody.scripts.after.name)
42
- if (extraBody.scripts.after.parameter) params.push("script.param=" + extraBody.scripts.after.parameter)
43
- }
44
- }
45
-
46
- if (params.length === 0) return ""
47
- return "?" + params.join("&")
48
- }
49
-
50
- /**
51
- * @deprecated in favour of .fetch()
52
- */
53
- run(extraBody: extraBodyOptions = {}): Promise<LayoutRecord<T["fields"], T["portals"]>[]> {
54
- return this.fetch(extraBody)
55
- }
56
-
57
- async fetch(extraBody: extraBodyOptions = {}): Promise<LayoutRecord<T["fields"], T["portals"]>[]> {
58
- let trace = new Error()
59
- let res = await this.layout.getLayoutMeta().then(() => {
60
- return this.layout.database.apiRequest<ApiRecordResponseObj>(`${this.layout.endpoint}/records${this.generateQueryParams(extraBody)}`, {
61
- method: "GET"
62
- })
63
- })
64
-
65
- if (res.messages[0].code === "0") {
66
- // console.log("RESOLVING")
67
- if (!this.layout.metadata) await this.layout.getLayoutMeta()
68
- let data = res.response.data.map(item => {
69
- return new LayoutRecord(this.layout, item.recordId, item.modId, item.fieldData, item.portalData)
70
- })
71
- return data
72
- }
73
- else {
74
- throw new FMError(res.messages[0].code, res.httpStatus, res, trace)
75
- }
76
- }
77
- }
@@ -1,4 +0,0 @@
1
- import { RecordBase } from "./recordBase";
2
- import { RecordFieldsMap } from "../layouts/recordFieldsMap";
3
- export declare class PortalRecordBase<T extends RecordFieldsMap> extends RecordBase<T> {
4
- }
@@ -1,6 +0,0 @@
1
- /*
2
- * Copyright (c) 2023. See LICENSE file for more information
3
- */
4
- import { RecordBase } from "./recordBase";
5
- export class PortalRecordBase extends RecordBase {
6
- }