nesoi 3.0.18 → 3.0.20
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/compiler/elements/bucket.element.d.ts +1 -1
- package/lib/compiler/elements/bucket.element.js +25 -27
- package/lib/compiler/elements/message.element.js +50 -20
- package/lib/elements/blocks/block.builder.d.ts +10 -1
- package/lib/elements/blocks/block.builder.js +26 -0
- package/lib/elements/blocks/job/job.builder.d.ts +7 -1
- package/lib/elements/blocks/job/job.builder.js +4 -0
- package/lib/elements/entities/bucket/model/bucket_model.convert.js +11 -9
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +1 -1
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +11 -8
- package/lib/elements/entities/bucket/view/bucket_view.js +2 -2
- package/lib/elements/entities/message/message_parser.d.ts +0 -4
- package/lib/elements/entities/message/message_parser.js +41 -75
- package/lib/elements/entities/message/template/message_template.schema.d.ts +25 -2
- package/lib/elements/entities/message/template/message_template.schema.js +16 -2
- package/lib/elements/entities/message/template/message_template_field.builder.d.ts +2 -2
- package/lib/elements/entities/message/template/message_template_field.builder.js +12 -10
- package/lib/elements/entities/message/template/message_template_parser.d.ts +6 -2
- package/lib/elements/entities/message/template/message_template_parser.js +121 -76
- package/lib/engine/data/error.d.ts +11 -0
- package/lib/engine/data/error.js +4 -0
- package/lib/engine/util/deep.d.ts +2 -0
- package/lib/engine/util/deep.js +30 -0
- package/lib/engine/util/parse.d.ts +39 -28
- package/lib/engine/util/parse.js +159 -188
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
package/lib/engine/util/parse.js
CHANGED
|
@@ -21,224 +21,195 @@ 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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (!Array.isArray(value)) {
|
|
28
|
-
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value, type: `${type}[]` });
|
|
29
|
-
}
|
|
30
|
-
const parsed = [];
|
|
31
|
-
for (const v of value) {
|
|
32
|
-
parsed.push(await fn(v));
|
|
33
|
-
}
|
|
34
|
-
return parsed;
|
|
24
|
+
function parseBoolean(field, value) {
|
|
25
|
+
if (value === 'true' || value === 1) {
|
|
26
|
+
return true;
|
|
35
27
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (v === 'false' || v === 0) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
if (typeof v === 'boolean') {
|
|
47
|
-
return v;
|
|
48
|
-
}
|
|
49
|
-
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'boolean' });
|
|
50
|
-
});
|
|
28
|
+
if (value === 'false' || value === 0) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (typeof value === 'boolean') {
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'boolean' });
|
|
51
35
|
}
|
|
52
|
-
function parseDate(field, value
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'date' });
|
|
59
|
-
});
|
|
36
|
+
function parseDate(field, value) {
|
|
37
|
+
// TODO: limit to date
|
|
38
|
+
if (typeof value === 'string') {
|
|
39
|
+
return date_1.NesoiDate.fromISO(value);
|
|
40
|
+
}
|
|
41
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'date' });
|
|
60
42
|
}
|
|
61
|
-
function parseDatetime(field, value
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'datetime' });
|
|
67
|
-
});
|
|
43
|
+
function parseDatetime(field, value) {
|
|
44
|
+
if (typeof value === 'string') {
|
|
45
|
+
return datetime_1.NesoiDatetime.fromISO(value);
|
|
46
|
+
}
|
|
47
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'datetime' });
|
|
68
48
|
}
|
|
69
|
-
function parseDuration(field, value
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'duration' });
|
|
75
|
-
});
|
|
49
|
+
function parseDuration(field, value) {
|
|
50
|
+
if (typeof value === 'string') {
|
|
51
|
+
return duration_1.NesoiDuration.fromString(value);
|
|
52
|
+
}
|
|
53
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'duration' });
|
|
76
54
|
}
|
|
77
|
-
function parseDecimal(field, value
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'decimal' });
|
|
83
|
-
});
|
|
55
|
+
function parseDecimal(field, value) {
|
|
56
|
+
if (typeof value === 'string') {
|
|
57
|
+
return new decimal_1.NesoiDecimal(value);
|
|
58
|
+
}
|
|
59
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'decimal' });
|
|
84
60
|
}
|
|
85
|
-
function parseEnum(raw, field, value,
|
|
86
|
-
|
|
87
|
-
if (typeof
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
_enum = trx.enum(enumName);
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
const v = tree_1.Tree.get(raw, enumPath[2]);
|
|
99
|
-
throw error_1.NesoiError.Message.InvalidEnumScope({ name: field.name, alias: field.alias, value: v, fieldpath: enumPath[2] });
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
61
|
+
function parseEnum(raw, field, value, options, trx) {
|
|
62
|
+
if (typeof value === 'string') {
|
|
63
|
+
if (typeof options === 'string') {
|
|
64
|
+
let enumName = options;
|
|
65
|
+
const enumPath = enumName.match(/(.*)\.\{(.*)\}$/);
|
|
66
|
+
let _enum;
|
|
67
|
+
if (enumPath) {
|
|
68
|
+
enumName += enumPath[1] + '.' + enumPath[2];
|
|
69
|
+
try {
|
|
103
70
|
_enum = trx.enum(enumName);
|
|
104
71
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
throw error_1.NesoiError.Message.InvalidFieldEnumValue({ field: field.alias, value: v, type: 'enum', options: keys });
|
|
72
|
+
catch {
|
|
73
|
+
const v = tree_1.Tree.get(raw, enumPath[2]);
|
|
74
|
+
throw error_1.NesoiError.Message.InvalidEnumScope({ path: field.path_raw, name: field.name, alias: field.alias, value: v, fieldpath: enumPath[2] });
|
|
111
75
|
}
|
|
112
76
|
}
|
|
113
|
-
else
|
|
114
|
-
|
|
115
|
-
return v;
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
throw error_1.NesoiError.Message.InvalidFieldEnumValue({ field: field.alias, value: v, type: 'enum', options });
|
|
119
|
-
}
|
|
77
|
+
else {
|
|
78
|
+
_enum = trx.enum(enumName);
|
|
120
79
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
80
|
+
const keys = _enum.keys();
|
|
81
|
+
if (keys.includes(value)) {
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
throw error_1.NesoiError.Message.InvalidFieldEnumValue({ field: field.alias, path: field.path_raw, value, type: 'enum', options: keys });
|
|
128
86
|
}
|
|
129
87
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'file' });
|
|
137
|
-
}
|
|
138
|
-
if (options?.maxsize) {
|
|
139
|
-
if (v.size > options?.maxsize) {
|
|
140
|
-
throw error_1.NesoiError.Message.FileTooBig({
|
|
141
|
-
name: field.name,
|
|
142
|
-
alias: field.alias,
|
|
143
|
-
maxsize: options?.maxsize
|
|
144
|
-
});
|
|
88
|
+
else if (Array.isArray(options)) {
|
|
89
|
+
if (options.includes(value)) {
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
throw error_1.NesoiError.Message.InvalidFieldEnumValue({ field: field.alias, path: field.path_raw, value, type: 'enum', options });
|
|
145
94
|
}
|
|
146
95
|
}
|
|
147
|
-
if (options
|
|
148
|
-
if (
|
|
149
|
-
|
|
96
|
+
else if (typeof options === 'object') {
|
|
97
|
+
if (value in options) {
|
|
98
|
+
return options[value];
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
throw error_1.NesoiError.Message.InvalidFieldEnumValue({ field: field.alias, path: field.path_raw, value, type: 'enum', options: Object.keys(options) });
|
|
150
102
|
}
|
|
151
103
|
}
|
|
152
|
-
|
|
153
|
-
});
|
|
104
|
+
}
|
|
105
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'string' });
|
|
154
106
|
}
|
|
155
|
-
function
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
107
|
+
function parseFile(field, value, options) {
|
|
108
|
+
if (!(value instanceof file_1.NesoiFile)) {
|
|
109
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'file' });
|
|
110
|
+
}
|
|
111
|
+
if (options?.maxsize) {
|
|
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
|
+
});
|
|
162
119
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
120
|
+
}
|
|
121
|
+
if (options?.extnames) {
|
|
122
|
+
if (!options?.extnames.includes(value.extname)) {
|
|
123
|
+
throw error_1.NesoiError.Message.FileExtNotAllowed({ path: field.path_raw, name: field.name, alias: field.alias, options: options?.extnames });
|
|
167
124
|
}
|
|
168
|
-
|
|
169
|
-
|
|
125
|
+
}
|
|
126
|
+
return value;
|
|
170
127
|
}
|
|
171
|
-
|
|
128
|
+
function parseFloat_(field, value) {
|
|
129
|
+
if (typeof value === 'string') {
|
|
130
|
+
const val = parseFloat(value);
|
|
131
|
+
if (!Number.isNaN(val)) {
|
|
132
|
+
return val;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (typeof value === 'number') {
|
|
136
|
+
if (!Number.isNaN(value)) {
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'float' });
|
|
141
|
+
}
|
|
142
|
+
async function parseId(field, value, trx, bucket, type, view) {
|
|
172
143
|
let val;
|
|
173
144
|
if (type === 'string') {
|
|
174
|
-
val =
|
|
145
|
+
val = parseString(field, value);
|
|
175
146
|
}
|
|
176
147
|
else {
|
|
177
|
-
val =
|
|
178
|
-
}
|
|
179
|
-
return
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
};
|
|
186
|
-
})); // type only required on query parsers
|
|
148
|
+
val = parseInt_(field, value);
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
id: val,
|
|
152
|
+
obj: view
|
|
153
|
+
? await trx.bucket(bucket).viewOneOrFail(val, view)
|
|
154
|
+
: await trx.bucket(bucket).readOneOrFail(val)
|
|
155
|
+
};
|
|
187
156
|
}
|
|
188
|
-
function parseInt_(field, value
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return val;
|
|
194
|
-
}
|
|
157
|
+
function parseInt_(field, value) {
|
|
158
|
+
if (typeof value === 'string') {
|
|
159
|
+
const val = parseInt(value);
|
|
160
|
+
if (!Number.isNaN(val)) {
|
|
161
|
+
return val;
|
|
195
162
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
163
|
+
}
|
|
164
|
+
else if (typeof value === 'number') {
|
|
165
|
+
const val = Math.floor(value);
|
|
166
|
+
if (!Number.isNaN(val)) {
|
|
167
|
+
return val;
|
|
201
168
|
}
|
|
202
|
-
|
|
203
|
-
});
|
|
169
|
+
}
|
|
170
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'integer' });
|
|
204
171
|
}
|
|
205
|
-
function parseString(field, value
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'string' });
|
|
211
|
-
});
|
|
172
|
+
function parseString(field, value) {
|
|
173
|
+
if (typeof value === 'string') {
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'string' });
|
|
212
177
|
}
|
|
213
|
-
function parseStringOrNumber(field, value
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'string_or_number' });
|
|
219
|
-
});
|
|
178
|
+
function parseStringOrNumber(field, value) {
|
|
179
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
180
|
+
return value;
|
|
181
|
+
}
|
|
182
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'string_or_number' });
|
|
220
183
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
}
|
|
184
|
+
function parseDict(field, value) {
|
|
185
|
+
if (typeof value === 'object') {
|
|
186
|
+
const children = {};
|
|
187
|
+
for (const key in value) {
|
|
188
|
+
const _field = field.children['__dict'];
|
|
189
|
+
children[key] = {
|
|
190
|
+
field: _field,
|
|
191
|
+
value: value[key]
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
return children;
|
|
195
|
+
}
|
|
196
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'dict' });
|
|
233
197
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
198
|
+
function parseObj(field, value, path_idx) {
|
|
199
|
+
if (typeof value === 'object') {
|
|
200
|
+
if (!field.children)
|
|
201
|
+
return {};
|
|
202
|
+
const children = {};
|
|
203
|
+
for (const key in field.children) {
|
|
204
|
+
const _field = field.children[key];
|
|
205
|
+
const key_raw = _field.path_raw.split('.')[path_idx + 1];
|
|
206
|
+
const key_parsed = _field.path_parsed.split('.')[path_idx + 1];
|
|
207
|
+
children[key_parsed] = {
|
|
208
|
+
field: _field,
|
|
209
|
+
value: value[key_raw]
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
return children;
|
|
213
|
+
}
|
|
214
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'object' });
|
|
244
215
|
}
|