nesoi 3.0.20 → 3.0.21
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/lib/elements/entities/bucket/model/bucket_model.convert.js +1 -1
- package/lib/elements/entities/message/message.builder.js +2 -2
- package/lib/elements/entities/message/message_parser.d.ts +0 -1
- package/lib/elements/entities/message/message_parser.js +1 -68
- package/lib/elements/entities/message/template/message_template.schema.d.ts +11 -1
- package/lib/elements/entities/message/template/message_template.schema.js +7 -1
- package/lib/elements/entities/message/template/message_template_field.builder.d.ts +11 -0
- package/lib/elements/entities/message/template/message_template_field.builder.js +21 -5
- package/lib/elements/entities/message/template/message_template_parser.d.ts +2 -2
- package/lib/elements/entities/message/template/message_template_parser.js +126 -45
- package/lib/engine/data/error.d.ts +12 -11
- package/lib/engine/data/error.js +7 -7
- package/lib/engine/util/parse.d.ts +14 -14
- package/lib/engine/util/parse.js +37 -42
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -9,64 +9,64 @@ import { NesoiDuration } from '../data/duration';
|
|
|
9
9
|
export declare function parseBoolean(field: {
|
|
10
10
|
path_raw: string;
|
|
11
11
|
alias: string;
|
|
12
|
-
}, value: any): boolean;
|
|
12
|
+
}, path: string[], value: any): boolean;
|
|
13
13
|
export declare function parseDate(field: {
|
|
14
14
|
path_raw: string;
|
|
15
15
|
alias: string;
|
|
16
|
-
}, value: any): NesoiDate;
|
|
16
|
+
}, path: string[], value: any): NesoiDate;
|
|
17
17
|
export declare function parseDatetime(field: {
|
|
18
18
|
path_raw: string;
|
|
19
19
|
alias: string;
|
|
20
|
-
}, value: any): NesoiDatetime;
|
|
20
|
+
}, path: string[], value: any): NesoiDatetime;
|
|
21
21
|
export declare function parseDuration(field: {
|
|
22
22
|
path_raw: string;
|
|
23
23
|
alias: string;
|
|
24
|
-
}, value: any): NesoiDuration;
|
|
24
|
+
}, path: string[], value: any): NesoiDuration;
|
|
25
25
|
export declare function parseDecimal(field: {
|
|
26
26
|
path_raw: string;
|
|
27
27
|
alias: string;
|
|
28
|
-
}, value: any): NesoiDecimal;
|
|
28
|
+
}, path: string[], value: any): NesoiDecimal;
|
|
29
29
|
export declare function parseEnum(raw: Record<string, any>, field: {
|
|
30
30
|
path_raw: string;
|
|
31
31
|
name: string;
|
|
32
32
|
alias: string;
|
|
33
|
-
}, value: any, options: string | readonly string[] | Record<string, any>, trx: AnyTrxNode): any;
|
|
33
|
+
}, path: string[], value: any, options: string | readonly string[] | Record<string, any>, trx: AnyTrxNode): any;
|
|
34
34
|
export declare function parseFile(field: {
|
|
35
35
|
path_raw: string;
|
|
36
36
|
name: string;
|
|
37
37
|
alias: string;
|
|
38
|
-
}, value: any, options?: {
|
|
38
|
+
}, path: string[], value: any, options?: {
|
|
39
39
|
maxsize?: number;
|
|
40
40
|
extnames?: string[];
|
|
41
41
|
}): NesoiFile;
|
|
42
42
|
export declare function parseFloat_(field: {
|
|
43
43
|
path_raw: string;
|
|
44
44
|
alias: string;
|
|
45
|
-
}, value: any): number;
|
|
45
|
+
}, path: string[], value: any): number;
|
|
46
46
|
export declare function parseId<M extends $Module, Name extends BucketName<M>, View extends ViewName<M['buckets'][Name]> | undefined>(field: {
|
|
47
47
|
path_raw: string;
|
|
48
48
|
alias: string;
|
|
49
|
-
}, value: any, trx: AnyTrxNode, bucket: Name, type?: 'int' | 'string', view?: View): Promise<{
|
|
49
|
+
}, path: string[], value: any, trx: AnyTrxNode, bucket: Name, type?: 'int' | 'string', view?: View): Promise<{
|
|
50
50
|
id: string | number;
|
|
51
51
|
obj: any;
|
|
52
52
|
}>;
|
|
53
53
|
export declare function parseInt_(field: {
|
|
54
54
|
path_raw: string;
|
|
55
55
|
alias: string;
|
|
56
|
-
}, value: any): number;
|
|
56
|
+
}, path: string[], value: any): number;
|
|
57
57
|
export declare function parseString(field: {
|
|
58
58
|
path_raw: string;
|
|
59
59
|
alias: string;
|
|
60
|
-
}, value: any): string;
|
|
60
|
+
}, path: string[], value: any): string;
|
|
61
61
|
export declare function parseStringOrNumber(field: {
|
|
62
62
|
path_raw: string;
|
|
63
63
|
alias: string;
|
|
64
|
-
}, value: any): string | number;
|
|
64
|
+
}, path: string[], value: any): string | number;
|
|
65
65
|
export declare function parseDict(field: {
|
|
66
66
|
path_raw: string;
|
|
67
67
|
alias: string;
|
|
68
68
|
children?: $MessageTemplateFields;
|
|
69
|
-
}, value: any): Record<string, {
|
|
69
|
+
}, path: string[], value: any): Record<string, {
|
|
70
70
|
field: $MessageTemplateField;
|
|
71
71
|
value?: any;
|
|
72
72
|
}>;
|
|
@@ -74,7 +74,7 @@ export declare function parseObj(field: {
|
|
|
74
74
|
path_raw: string;
|
|
75
75
|
alias: string;
|
|
76
76
|
children?: $MessageTemplateFields;
|
|
77
|
-
},
|
|
77
|
+
}, path: string[], value: any): Record<string, {
|
|
78
78
|
field: $MessageTemplateField;
|
|
79
79
|
value?: any;
|
|
80
80
|
}>;
|
package/lib/engine/util/parse.js
CHANGED
|
@@ -21,7 +21,7 @@ const decimal_1 = require("../data/decimal");
|
|
|
21
21
|
const datetime_1 = require("../data/datetime");
|
|
22
22
|
const file_1 = require("../data/file");
|
|
23
23
|
const duration_1 = require("../data/duration");
|
|
24
|
-
function parseBoolean(field, value) {
|
|
24
|
+
function parseBoolean(field, path, value) {
|
|
25
25
|
if (value === 'true' || value === 1) {
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
@@ -31,34 +31,34 @@ function parseBoolean(field, value) {
|
|
|
31
31
|
if (typeof value === 'boolean') {
|
|
32
32
|
return value;
|
|
33
33
|
}
|
|
34
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
34
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'boolean' });
|
|
35
35
|
}
|
|
36
|
-
function parseDate(field, value) {
|
|
36
|
+
function parseDate(field, path, value) {
|
|
37
37
|
// TODO: limit to date
|
|
38
38
|
if (typeof value === 'string') {
|
|
39
39
|
return date_1.NesoiDate.fromISO(value);
|
|
40
40
|
}
|
|
41
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
41
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'date' });
|
|
42
42
|
}
|
|
43
|
-
function parseDatetime(field, value) {
|
|
43
|
+
function parseDatetime(field, path, value) {
|
|
44
44
|
if (typeof value === 'string') {
|
|
45
45
|
return datetime_1.NesoiDatetime.fromISO(value);
|
|
46
46
|
}
|
|
47
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
47
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'datetime' });
|
|
48
48
|
}
|
|
49
|
-
function parseDuration(field, value) {
|
|
49
|
+
function parseDuration(field, path, value) {
|
|
50
50
|
if (typeof value === 'string') {
|
|
51
51
|
return duration_1.NesoiDuration.fromString(value);
|
|
52
52
|
}
|
|
53
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
53
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'duration' });
|
|
54
54
|
}
|
|
55
|
-
function parseDecimal(field, value) {
|
|
55
|
+
function parseDecimal(field, path, value) {
|
|
56
56
|
if (typeof value === 'string') {
|
|
57
57
|
return new decimal_1.NesoiDecimal(value);
|
|
58
58
|
}
|
|
59
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
59
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'decimal' });
|
|
60
60
|
}
|
|
61
|
-
function parseEnum(raw, field, value, options, trx) {
|
|
61
|
+
function parseEnum(raw, field, path, value, options, trx) {
|
|
62
62
|
if (typeof value === 'string') {
|
|
63
63
|
if (typeof options === 'string') {
|
|
64
64
|
let enumName = options;
|
|
@@ -71,7 +71,7 @@ function parseEnum(raw, field, value, options, trx) {
|
|
|
71
71
|
}
|
|
72
72
|
catch {
|
|
73
73
|
const v = tree_1.Tree.get(raw, enumPath[2]);
|
|
74
|
-
throw error_1.NesoiError.Message.InvalidEnumScope({
|
|
74
|
+
throw error_1.NesoiError.Message.InvalidEnumScope({ alias: field.alias, path: path.join('.'), value: v, fieldpath: enumPath[2] });
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
else {
|
|
@@ -82,7 +82,7 @@ function parseEnum(raw, field, value, options, trx) {
|
|
|
82
82
|
return value;
|
|
83
83
|
}
|
|
84
84
|
else {
|
|
85
|
-
throw error_1.NesoiError.Message.InvalidFieldEnumValue({
|
|
85
|
+
throw error_1.NesoiError.Message.InvalidFieldEnumValue({ alias: field.alias, path: path.join('.'), value, type: 'enum', options: keys });
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
else if (Array.isArray(options)) {
|
|
@@ -90,7 +90,7 @@ function parseEnum(raw, field, value, options, trx) {
|
|
|
90
90
|
return value;
|
|
91
91
|
}
|
|
92
92
|
else {
|
|
93
|
-
throw error_1.NesoiError.Message.InvalidFieldEnumValue({
|
|
93
|
+
throw error_1.NesoiError.Message.InvalidFieldEnumValue({ alias: field.alias, path: path.join('.'), value, type: 'enum', options });
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
else if (typeof options === 'object') {
|
|
@@ -98,34 +98,29 @@ function parseEnum(raw, field, value, options, trx) {
|
|
|
98
98
|
return options[value];
|
|
99
99
|
}
|
|
100
100
|
else {
|
|
101
|
-
throw error_1.NesoiError.Message.InvalidFieldEnumValue({
|
|
101
|
+
throw error_1.NesoiError.Message.InvalidFieldEnumValue({ alias: field.alias, path: path.join('.'), value, type: 'enum', options: Object.keys(options) });
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
105
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'string' });
|
|
106
106
|
}
|
|
107
|
-
function parseFile(field, value, options) {
|
|
107
|
+
function parseFile(field, path, value, options) {
|
|
108
108
|
if (!(value instanceof file_1.NesoiFile)) {
|
|
109
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
109
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'file' });
|
|
110
110
|
}
|
|
111
111
|
if (options?.maxsize) {
|
|
112
112
|
if (value.size > options?.maxsize) {
|
|
113
|
-
throw error_1.NesoiError.Message.FileTooBig({
|
|
114
|
-
path: field.path_raw,
|
|
115
|
-
name: field.name,
|
|
116
|
-
alias: field.alias,
|
|
117
|
-
maxsize: options?.maxsize
|
|
118
|
-
});
|
|
113
|
+
throw error_1.NesoiError.Message.FileTooBig({ alias: field.alias, path: path.join('.'), maxsize: options?.maxsize });
|
|
119
114
|
}
|
|
120
115
|
}
|
|
121
116
|
if (options?.extnames) {
|
|
122
117
|
if (!options?.extnames.includes(value.extname)) {
|
|
123
|
-
throw error_1.NesoiError.Message.FileExtNotAllowed({
|
|
118
|
+
throw error_1.NesoiError.Message.FileExtNotAllowed({ alias: field.alias, path: path.join('.'), options: options?.extnames });
|
|
124
119
|
}
|
|
125
120
|
}
|
|
126
121
|
return value;
|
|
127
122
|
}
|
|
128
|
-
function parseFloat_(field, value) {
|
|
123
|
+
function parseFloat_(field, path, value) {
|
|
129
124
|
if (typeof value === 'string') {
|
|
130
125
|
const val = parseFloat(value);
|
|
131
126
|
if (!Number.isNaN(val)) {
|
|
@@ -137,15 +132,15 @@ function parseFloat_(field, value) {
|
|
|
137
132
|
return value;
|
|
138
133
|
}
|
|
139
134
|
}
|
|
140
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
135
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'float' });
|
|
141
136
|
}
|
|
142
|
-
async function parseId(field, value, trx, bucket, type, view) {
|
|
137
|
+
async function parseId(field, path, value, trx, bucket, type, view) {
|
|
143
138
|
let val;
|
|
144
139
|
if (type === 'string') {
|
|
145
|
-
val = parseString(field, value);
|
|
140
|
+
val = parseString(field, path, value);
|
|
146
141
|
}
|
|
147
142
|
else {
|
|
148
|
-
val = parseInt_(field, value);
|
|
143
|
+
val = parseInt_(field, path, value);
|
|
149
144
|
}
|
|
150
145
|
return {
|
|
151
146
|
id: val,
|
|
@@ -154,7 +149,7 @@ async function parseId(field, value, trx, bucket, type, view) {
|
|
|
154
149
|
: await trx.bucket(bucket).readOneOrFail(val)
|
|
155
150
|
};
|
|
156
151
|
}
|
|
157
|
-
function parseInt_(field, value) {
|
|
152
|
+
function parseInt_(field, path, value) {
|
|
158
153
|
if (typeof value === 'string') {
|
|
159
154
|
const val = parseInt(value);
|
|
160
155
|
if (!Number.isNaN(val)) {
|
|
@@ -167,21 +162,21 @@ function parseInt_(field, value) {
|
|
|
167
162
|
return val;
|
|
168
163
|
}
|
|
169
164
|
}
|
|
170
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
165
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'integer' });
|
|
171
166
|
}
|
|
172
|
-
function parseString(field, value) {
|
|
167
|
+
function parseString(field, path, value) {
|
|
173
168
|
if (typeof value === 'string') {
|
|
174
169
|
return value;
|
|
175
170
|
}
|
|
176
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
171
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'string' });
|
|
177
172
|
}
|
|
178
|
-
function parseStringOrNumber(field, value) {
|
|
173
|
+
function parseStringOrNumber(field, path, value) {
|
|
179
174
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
180
175
|
return value;
|
|
181
176
|
}
|
|
182
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
177
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'string_or_number' });
|
|
183
178
|
}
|
|
184
|
-
function parseDict(field, value) {
|
|
179
|
+
function parseDict(field, path, value) {
|
|
185
180
|
if (typeof value === 'object') {
|
|
186
181
|
const children = {};
|
|
187
182
|
for (const key in value) {
|
|
@@ -193,17 +188,17 @@ function parseDict(field, value) {
|
|
|
193
188
|
}
|
|
194
189
|
return children;
|
|
195
190
|
}
|
|
196
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
191
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'dict' });
|
|
197
192
|
}
|
|
198
|
-
function parseObj(field,
|
|
193
|
+
function parseObj(field, path, value) {
|
|
199
194
|
if (typeof value === 'object') {
|
|
200
195
|
if (!field.children)
|
|
201
196
|
return {};
|
|
202
197
|
const children = {};
|
|
203
198
|
for (const key in field.children) {
|
|
204
199
|
const _field = field.children[key];
|
|
205
|
-
const key_raw = _field.path_raw.split('.')[
|
|
206
|
-
const key_parsed = _field.path_parsed.split('.')[
|
|
200
|
+
const key_raw = _field.path_raw.split('.')[path.length];
|
|
201
|
+
const key_parsed = _field.path_parsed.split('.')[path.length];
|
|
207
202
|
children[key_parsed] = {
|
|
208
203
|
field: _field,
|
|
209
204
|
value: value[key_raw]
|
|
@@ -211,5 +206,5 @@ function parseObj(field, value, path_idx) {
|
|
|
211
206
|
}
|
|
212
207
|
return children;
|
|
213
208
|
}
|
|
214
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
209
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'object' });
|
|
215
210
|
}
|