@jd-data-limited/easy-fm 4.0.14 → 4.1.0

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 (65) hide show
  1. package/package.json +12 -6
  2. package/src/FMError.d.ts +2 -2
  3. package/src/FMError.js +507 -508
  4. package/src/FMError.ts +510 -511
  5. package/src/bin/cli.js +7 -5
  6. package/src/bin/generateTypes.js +215 -121
  7. package/src/connection/FMHost.d.ts +28 -6
  8. package/src/connection/FMHost.js +52 -25
  9. package/src/connection/FMHost.ts +75 -43
  10. package/src/connection/HostBase.d.ts +7 -3
  11. package/src/connection/HostBase.ts +8 -4
  12. package/src/connection/database.d.ts +50 -17
  13. package/src/connection/database.js +94 -66
  14. package/src/connection/database.ts +125 -105
  15. package/src/connection/databaseBase.d.ts +11 -6
  16. package/src/connection/databaseBase.ts +9 -8
  17. package/src/connection/generateAuthorizationHeaders.d.ts +1 -1
  18. package/src/connection/generateAuthorizationHeaders.js +10 -10
  19. package/src/connection/generateAuthorizationHeaders.ts +21 -21
  20. package/src/databaseStructure.d.ts +2 -4
  21. package/src/databaseStructure.ts +3 -5
  22. package/src/index.d.ts +17 -17
  23. package/src/index.js +14 -14
  24. package/src/index.ts +28 -25
  25. package/src/layouts/layout.d.ts +17 -6
  26. package/src/layouts/layout.js +19 -8
  27. package/src/layouts/layout.ts +33 -23
  28. package/src/layouts/layoutBase.d.ts +5 -5
  29. package/src/layouts/layoutBase.ts +6 -6
  30. package/src/layouts/layoutInterface.d.ts +3 -5
  31. package/src/layouts/layoutInterface.ts +4 -6
  32. package/src/layouts/layoutRecordManager.d.ts +29 -6
  33. package/src/layouts/layoutRecordManager.js +32 -9
  34. package/src/layouts/layoutRecordManager.ts +42 -19
  35. package/src/layouts/recordFieldsMap.d.ts +2 -4
  36. package/src/layouts/recordFieldsMap.ts +2 -4
  37. package/src/models/apiResults.d.ts +7 -13
  38. package/src/models/apiResults.ts +58 -58
  39. package/src/records/field.d.ts +42 -12
  40. package/src/records/field.js +69 -59
  41. package/src/records/field.ts +102 -81
  42. package/src/records/getOperations/recordGetOperation.d.ts +44 -24
  43. package/src/records/getOperations/recordGetOperation.js +89 -58
  44. package/src/records/getOperations/recordGetOperation.ts +137 -108
  45. package/src/records/layoutRecord.d.ts +28 -14
  46. package/src/records/layoutRecord.js +75 -65
  47. package/src/records/layoutRecord.ts +126 -123
  48. package/src/records/layoutRecordBase.d.ts +2 -2
  49. package/src/records/layoutRecordBase.ts +3 -3
  50. package/src/records/portal.d.ts +19 -5
  51. package/src/records/portal.js +19 -5
  52. package/src/records/portal.ts +28 -16
  53. package/src/records/portalBase.d.ts +5 -5
  54. package/src/records/portalBase.ts +6 -6
  55. package/src/records/portalRecord.d.ts +16 -8
  56. package/src/records/portalRecord.js +16 -6
  57. package/src/records/portalRecord.ts +29 -19
  58. package/src/records/recordBase.d.ts +17 -7
  59. package/src/records/recordBase.js +32 -22
  60. package/src/records/recordBase.ts +50 -43
  61. package/src/types.d.ts +21 -24
  62. package/src/types.ts +55 -59
  63. package/src/utils/query.d.ts +12 -5
  64. package/src/utils/query.js +28 -9
  65. package/src/utils/query.ts +40 -15
package/src/types.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  /// <reference types="node" resolution-mode="require"/>
3
- import * as http from "http";
4
- import { FMError } from "./FMError.js";
5
- import { LayoutInterface } from "./layouts/layoutInterface.js";
6
- export type PickPortals<LAYOUT extends LayoutInterface, PORTALS extends string | number | symbol = ""> = Omit<LAYOUT, "portals"> & {
7
- portals: Pick<LAYOUT["portals"], PORTALS>;
3
+ import type * as http from 'http';
4
+ import { type FMError } from './FMError.js';
5
+ import { type LayoutInterface } from './layouts/layoutInterface.js';
6
+ export type PickPortals<LAYOUT extends LayoutInterface, PORTALS extends string | number | symbol = ''> = Omit<LAYOUT, 'portals'> & {
7
+ portals: Pick<LAYOUT['portals'], PORTALS>;
8
8
  };
9
9
  export interface databaseOptionsBase {
10
10
  database: string;
@@ -13,27 +13,28 @@ export interface databaseOptionsBase {
13
13
  }
14
14
  export interface databaseOptionsWithExternalSources extends databaseOptionsBase {
15
15
  database: string;
16
+ debug?: boolean;
16
17
  credentials: loginOptionsOAuth | loginOptionsFileMaker | loginOptionsClaris | loginOptionsToken;
17
18
  externalSources: databaseOptionsBase[];
18
19
  }
19
20
  export interface loginOptionsToken {
20
- method: "token";
21
+ method: 'token';
21
22
  token: string;
22
23
  }
23
24
  export interface loginOptionsOAuth {
24
- method: "oauth";
25
+ method: 'oauth';
25
26
  oauth: {
26
27
  requestId: string;
27
28
  requestIdentifier: string;
28
29
  };
29
30
  }
30
31
  export interface loginOptionsFileMaker {
31
- method: "filemaker";
32
+ method: 'filemaker';
32
33
  username: string;
33
34
  password: string;
34
35
  }
35
36
  export interface loginOptionsClaris {
36
- method: "claris";
37
+ method: 'claris';
37
38
  claris: {
38
39
  fmid: string;
39
40
  };
@@ -43,11 +44,11 @@ export interface portalFetchData<T = string> {
43
44
  offset: number;
44
45
  limit: number;
45
46
  }
46
- export type ScriptRequestData = {
47
+ export interface ScriptRequestData {
47
48
  prerequest?: Script;
48
49
  presort?: Script;
49
50
  after?: Script;
50
- };
51
+ }
51
52
  export interface extraBodyOptions {
52
53
  scripts?: ScriptRequestData;
53
54
  }
@@ -65,9 +66,7 @@ export interface recordObject {
65
66
  fieldData: any;
66
67
  portalData?: portalDataObject;
67
68
  }
68
- export interface portalDataObject {
69
- [key: string]: recordObject;
70
- }
69
+ export type portalDataObject = Record<string, recordObject>;
71
70
  export interface FieldMetaData {
72
71
  name: string;
73
72
  type: string;
@@ -86,9 +85,7 @@ export interface FieldMetaData {
86
85
  }
87
86
  export interface LayoutMetaData {
88
87
  fieldMetaData: FieldMetaData[];
89
- portalMetaData?: {
90
- [key: string]: FieldMetaData[];
91
- };
88
+ portalMetaData?: Record<string, FieldMetaData[]>;
92
89
  }
93
90
  export interface FMHostMetadata {
94
91
  productInfo: {
@@ -106,21 +103,21 @@ export interface ScriptResult {
106
103
  }
107
104
  export interface ContainerBufferResult {
108
105
  buffer: Buffer;
109
- mime: string;
106
+ mime?: string;
110
107
  request: http.IncomingMessage;
111
108
  }
112
109
  export interface AuthorizationHeaders {
113
- "Content-Type": "application/json";
110
+ 'Content-Type': 'application/json';
114
111
  Authorization: string;
115
112
  }
116
113
  export interface AuthorizationHeadersOAuth {
117
- "Content-Type": "application/json";
118
- "X-FM-Data-OAuth-RequestId": string;
119
- "X-FM-Data-OAuth-Identifier": string;
114
+ 'Content-Type': 'application/json';
115
+ 'X-FM-Data-OAuth-RequestId': string;
116
+ 'X-FM-Data-OAuth-Identifier': string;
120
117
  }
121
- export type RecordFetchOptions = {
118
+ export interface RecordFetchOptions {
122
119
  readonly portals: readonly string[];
123
- };
120
+ }
124
121
  export declare enum RecordTypes {
125
122
  UNKNOWN = 0,
126
123
  LAYOUT = 1,
package/src/types.ts CHANGED
@@ -3,62 +3,62 @@
3
3
  */
4
4
 
5
5
  // const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args));
6
- // @ts-ignore
7
- import * as http from "http";
8
- import {FMError} from "./FMError.js";
9
- import {LayoutInterface} from "./layouts/layoutInterface.js";
6
+ import type * as http from 'http'
7
+ import {type FMError} from './FMError.js'
8
+ import {type LayoutInterface} from './layouts/layoutInterface.js'
10
9
 
11
- export type PickPortals<LAYOUT extends LayoutInterface, PORTALS extends string | number | symbol = ""> =
12
- Omit<LAYOUT, "portals"> & { portals: Pick<LAYOUT["portals"], PORTALS> }
10
+ export type PickPortals<LAYOUT extends LayoutInterface, PORTALS extends string | number | symbol = ''> =
11
+ Omit<LAYOUT, 'portals'> & { portals: Pick<LAYOUT['portals'], PORTALS> }
13
12
 
14
13
  export interface databaseOptionsBase {
15
- database: string,
16
- debug?: boolean,
17
- credentials: loginOptionsOAuth | loginOptionsFileMaker | loginOptionsClaris | loginOptionsToken,
14
+ database: string
15
+ debug?: boolean
16
+ credentials: loginOptionsOAuth | loginOptionsFileMaker | loginOptionsClaris | loginOptionsToken
18
17
  }
19
18
 
20
19
  export interface databaseOptionsWithExternalSources extends databaseOptionsBase {
21
20
  database: string
22
- credentials: loginOptionsOAuth | loginOptionsFileMaker | loginOptionsClaris | loginOptionsToken,
21
+ debug?: boolean
22
+ credentials: loginOptionsOAuth | loginOptionsFileMaker | loginOptionsClaris | loginOptionsToken
23
23
  externalSources: databaseOptionsBase[]
24
24
  }
25
25
 
26
26
  export interface loginOptionsToken {
27
- method: "token"
27
+ method: 'token'
28
28
  token: string
29
29
  }
30
30
 
31
31
  export interface loginOptionsOAuth {
32
- method: "oauth"
32
+ method: 'oauth'
33
33
  oauth: {
34
- requestId: string,
34
+ requestId: string
35
35
  requestIdentifier: string
36
36
  }
37
37
  }
38
38
 
39
39
  export interface loginOptionsFileMaker {
40
- method: "filemaker"
41
- username: string,
42
- password: string,
40
+ method: 'filemaker'
41
+ username: string
42
+ password: string
43
43
  }
44
44
 
45
45
  export interface loginOptionsClaris {
46
- method: "claris"
46
+ method: 'claris'
47
47
  claris: {
48
48
  fmid: string
49
49
  }
50
50
  }
51
51
 
52
52
  export interface portalFetchData<T = string> {
53
- portalName: T,
54
- offset: number,
53
+ portalName: T
54
+ offset: number
55
55
  limit: number
56
56
  }
57
57
 
58
- export type ScriptRequestData = {
59
- prerequest?: Script,
60
- presort?: Script,
61
- after?: Script,
58
+ export interface ScriptRequestData {
59
+ prerequest?: Script
60
+ presort?: Script
61
+ after?: Script
62
62
  }
63
63
 
64
64
  export interface extraBodyOptions {
@@ -77,58 +77,54 @@ export interface Script {
77
77
 
78
78
  export interface recordObject {
79
79
  recordId: number
80
- modId: number,
81
- fieldData: any,
80
+ modId: number
81
+ fieldData: any
82
82
  portalData?: portalDataObject
83
83
  }
84
84
 
85
- export interface portalDataObject {
86
- [key: string]: recordObject
87
- }
85
+ export type portalDataObject = Record<string, recordObject>
88
86
 
89
87
  export interface FieldMetaData {
90
- name: string,
91
- type: string,
92
- displayType: string,
93
- result: string,
94
- global: boolean,
95
- autoEnter: boolean,
96
- fourDigitYear: boolean,
97
- maxRepeat: number,
98
- maxCharacters: number,
99
- notEmpty: boolean,
100
- numeric: boolean,
101
- timeOfDay: false,
102
- repetitionStart: number,
88
+ name: string
89
+ type: string
90
+ displayType: string
91
+ result: string
92
+ global: boolean
93
+ autoEnter: boolean
94
+ fourDigitYear: boolean
95
+ maxRepeat: number
96
+ maxCharacters: number
97
+ notEmpty: boolean
98
+ numeric: boolean
99
+ timeOfDay: false
100
+ repetitionStart: number
103
101
  repetitionEnd: number
104
102
  }
105
103
 
106
104
  export interface LayoutMetaData {
107
- fieldMetaData: FieldMetaData[],
108
- portalMetaData?: {
109
- [key: string]: FieldMetaData[]
110
- }
105
+ fieldMetaData: FieldMetaData[]
106
+ portalMetaData?: Record<string, FieldMetaData[]>
111
107
  }
112
108
 
113
109
  export interface FMHostMetadata {
114
110
  productInfo: {
115
- buildDate: Date,
116
- name: string,
117
- version: string,
118
- dateFormat: string,
119
- timeFormat: string,
111
+ buildDate: Date
112
+ name: string
113
+ version: string
114
+ dateFormat: string
115
+ timeFormat: string
120
116
  timeStampFormat: string
121
117
  }
122
118
  }
123
119
 
124
120
  export interface ScriptResult {
125
- scriptError?: FMError,
121
+ scriptError?: FMError
126
122
  scriptResult?: string
127
123
  }
128
124
 
129
125
  export interface ContainerBufferResult {
130
- buffer: Buffer,
131
- mime: string,
126
+ buffer: Buffer
127
+ mime?: string
132
128
  request: http.IncomingMessage
133
129
  }
134
130
 
@@ -138,17 +134,17 @@ export interface ContainerBufferResult {
138
134
  // }
139
135
 
140
136
  export interface AuthorizationHeaders {
141
- "Content-Type": "application/json"
137
+ 'Content-Type': 'application/json'
142
138
  Authorization: string
143
139
  }
144
140
 
145
141
  export interface AuthorizationHeadersOAuth {
146
- "Content-Type": "application/json"
147
- "X-FM-Data-OAuth-RequestId": string,
148
- "X-FM-Data-OAuth-Identifier": string
142
+ 'Content-Type': 'application/json'
143
+ 'X-FM-Data-OAuth-RequestId': string
144
+ 'X-FM-Data-OAuth-Identifier': string
149
145
  }
150
146
 
151
- export type RecordFetchOptions = {
147
+ export interface RecordFetchOptions {
152
148
  readonly portals: readonly string[]
153
149
  }
154
150
 
@@ -156,4 +152,4 @@ export enum RecordTypes {
156
152
  UNKNOWN,
157
153
  LAYOUT,
158
154
  PORTAL
159
- }
155
+ }
@@ -1,9 +1,16 @@
1
- import { Moment } from "moment";
1
+ import { type Moment } from 'moment';
2
2
  export declare const FindRequestSymbol: unique symbol;
3
- type QueryParameter = string | number | Moment;
4
- export type Query = {
5
- [FindRequestSymbol]: (string | Moment)[];
6
- };
3
+ export interface TimestampType {
4
+ type: 'date' | 'time' | 'timestamp';
5
+ moment: Moment;
6
+ }
7
+ type QueryParameter = string | number | TimestampType;
8
+ export interface Query {
9
+ [FindRequestSymbol]: Array<string | TimestampType>;
10
+ }
7
11
  export declare function queryEscape(str: string): string;
8
12
  export declare function query(strings: TemplateStringsArray, ...args: QueryParameter[]): Query;
13
+ export declare function asDate(date: Date | Moment): TimestampType;
14
+ export declare function asTime(date: Date | Moment): TimestampType;
15
+ export declare function asTimestamp(date: Date | Moment): TimestampType;
9
16
  export {};
@@ -1,24 +1,24 @@
1
1
  /*
2
2
  * Copyright (c) 2024. See LICENSE file for more information
3
3
  */
4
- import moment from "moment/moment.js";
5
- export const FindRequestSymbol = Symbol("easyfm-findrequest");
6
- const SPECIAL_CHARACTERS = ["\\", "=", "<", "≤", "≥", ">", "…", "...", "//", "@", "#", "*", "\"", "~"];
4
+ import moment from 'moment';
5
+ export const FindRequestSymbol = Symbol('easyfm-findrequest');
6
+ const SPECIAL_CHARACTERS = ['\\', '=', '<', '≤', '≥', '>', '…', '...', '//', '@', '#', '*', '"', '~'];
7
7
  export function queryEscape(str) {
8
- for (let char of SPECIAL_CHARACTERS) {
8
+ for (const char of SPECIAL_CHARACTERS) {
9
9
  str = str.replace(char, `\\${char}`);
10
10
  }
11
11
  return str;
12
12
  }
13
13
  export function query(strings, ...args) {
14
- let argStrings = args.map(item => {
15
- if (moment.isMoment(item))
16
- return item;
17
- else if (typeof item === "number") {
14
+ const argStrings = args.map(item => {
15
+ if (typeof item === 'number') {
18
16
  return queryEscape(item.toString());
19
17
  }
20
- else
18
+ else if (typeof item === 'string')
21
19
  return queryEscape(item);
20
+ else
21
+ return item;
22
22
  });
23
23
  // Zip the parameters together
24
24
  const query = strings.map((str, index) => {
@@ -26,3 +26,22 @@ export function query(strings, ...args) {
26
26
  }).flat(1);
27
27
  return { [FindRequestSymbol]: query };
28
28
  }
29
+ export function asDate(date) {
30
+ return {
31
+ type: 'date',
32
+ moment: moment(date)
33
+ };
34
+ }
35
+ export function asTime(date) {
36
+ return {
37
+ type: 'time',
38
+ moment: moment(date)
39
+ };
40
+ }
41
+ export function asTimestamp(date) {
42
+ return {
43
+ type: 'timestamp',
44
+ moment: moment(date)
45
+ };
46
+ }
47
+ query;
@@ -2,28 +2,30 @@
2
2
  * Copyright (c) 2024. See LICENSE file for more information
3
3
  */
4
4
 
5
- import {Moment} from "moment";
6
- import moment from "moment/moment.js";
5
+ import moment, {type Moment} from 'moment'
7
6
 
8
- export const FindRequestSymbol = Symbol("easyfm-findrequest");
9
- const SPECIAL_CHARACTERS = ["\\", "=", "<", "≤", "≥", ">", "…", "...", "//", "@", "#", "*", "\"", "~"]
10
- type QueryParameter = string | number | Moment
11
- export type Query = {[FindRequestSymbol]: (string | Moment)[]}
7
+ export const FindRequestSymbol = Symbol('easyfm-findrequest')
8
+ const SPECIAL_CHARACTERS = ['\\', '=', '<', '≤', '≥', '>', '…', '...', '//', '@', '#', '*', '"', '~']
9
+ export interface TimestampType {
10
+ type: 'date' | 'time' | 'timestamp'
11
+ moment: Moment
12
+ }
13
+ type QueryParameter = string | number | TimestampType
14
+ export interface Query { [FindRequestSymbol]: Array<string | TimestampType> }
12
15
 
13
- export function queryEscape(str: string) {
14
- for (let char of SPECIAL_CHARACTERS) {
16
+ export function queryEscape (str: string) {
17
+ for (const char of SPECIAL_CHARACTERS) {
15
18
  str = str.replace(char, `\\${char}`)
16
19
  }
17
20
  return str
18
21
  }
19
22
 
20
- export function query(strings: TemplateStringsArray, ...args: QueryParameter[]): Query {
21
- let argStrings = args.map(item => {
22
- if (moment.isMoment(item)) return item
23
- else if (typeof item === "number") {
23
+ export function query (strings: TemplateStringsArray, ...args: QueryParameter[]): Query {
24
+ const argStrings = args.map(item => {
25
+ if (typeof item === 'number') {
24
26
  return queryEscape(item.toString())
25
- }
26
- else return queryEscape(item)
27
+ } else if (typeof item === 'string') return queryEscape(item)
28
+ else return item
27
29
  })
28
30
 
29
31
  // Zip the parameters together
@@ -31,4 +33,27 @@ export function query(strings: TemplateStringsArray, ...args: QueryParameter[]):
31
33
  return [str, (argStrings[index] || '')]
32
34
  }).flat(1)
33
35
  return {[FindRequestSymbol]: query}
34
- }
36
+ }
37
+
38
+ export function asDate (date: Date | Moment): TimestampType {
39
+ return {
40
+ type: 'date',
41
+ moment: moment(date)
42
+ }
43
+ }
44
+
45
+ export function asTime (date: Date | Moment): TimestampType {
46
+ return {
47
+ type: 'time',
48
+ moment: moment(date)
49
+ }
50
+ }
51
+
52
+ export function asTimestamp (date: Date | Moment): TimestampType {
53
+ return {
54
+ type: 'timestamp',
55
+ moment: moment(date)
56
+ }
57
+ }
58
+
59
+ query