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.
Files changed (27) hide show
  1. package/lib/compiler/elements/bucket.element.d.ts +1 -1
  2. package/lib/compiler/elements/bucket.element.js +25 -27
  3. package/lib/compiler/elements/message.element.js +50 -20
  4. package/lib/elements/blocks/block.builder.d.ts +10 -1
  5. package/lib/elements/blocks/block.builder.js +26 -0
  6. package/lib/elements/blocks/job/job.builder.d.ts +7 -1
  7. package/lib/elements/blocks/job/job.builder.js +4 -0
  8. package/lib/elements/entities/bucket/model/bucket_model.convert.js +11 -9
  9. package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +1 -1
  10. package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +11 -8
  11. package/lib/elements/entities/bucket/view/bucket_view.js +2 -2
  12. package/lib/elements/entities/message/message_parser.d.ts +0 -4
  13. package/lib/elements/entities/message/message_parser.js +41 -75
  14. package/lib/elements/entities/message/template/message_template.schema.d.ts +25 -2
  15. package/lib/elements/entities/message/template/message_template.schema.js +16 -2
  16. package/lib/elements/entities/message/template/message_template_field.builder.d.ts +2 -2
  17. package/lib/elements/entities/message/template/message_template_field.builder.js +12 -10
  18. package/lib/elements/entities/message/template/message_template_parser.d.ts +6 -2
  19. package/lib/elements/entities/message/template/message_template_parser.js +121 -76
  20. package/lib/engine/data/error.d.ts +11 -0
  21. package/lib/engine/data/error.js +4 -0
  22. package/lib/engine/util/deep.d.ts +2 -0
  23. package/lib/engine/util/deep.js +30 -0
  24. package/lib/engine/util/parse.d.ts +39 -28
  25. package/lib/engine/util/parse.js +159 -188
  26. package/package.json +1 -1
  27. package/tsconfig.build.tsbuildinfo +1 -1
@@ -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
- // TODO: check the performance of this wild thing below
25
- async function parse(type, field, value, array, fn) {
26
- if (array) {
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
- return fn(value);
37
- }
38
- function parseBoolean(field, value, array) {
39
- return parse('boolean', field, value, array, (v) => {
40
- if (v === 'true' || v === 1) {
41
- return true;
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, array) {
53
- return parse('date', field, value, array, (v) => {
54
- // TODO: limit to date
55
- if (typeof v === 'string') {
56
- return date_1.NesoiDate.fromISO(v);
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, array) {
62
- return parse('datetime', field, value, array, (v) => {
63
- if (typeof v === 'string') {
64
- return datetime_1.NesoiDatetime.fromISO(v);
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, array) {
70
- return parse('duration', field, value, array, (v) => {
71
- if (typeof v === 'string') {
72
- return duration_1.NesoiDuration.fromString(v);
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, array) {
78
- return parse('decimal', field, value, array, (v) => {
79
- if (typeof v === 'string') {
80
- return new decimal_1.NesoiDecimal(v);
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, array, options, trx) {
86
- return parse('enum', field, value, array, (v) => {
87
- if (typeof v === 'string') {
88
- if (typeof options === 'string') {
89
- let enumName = options;
90
- const enumPath = enumName.match(/(.*)\.\{(.*)\}$/);
91
- let _enum;
92
- if (enumPath) {
93
- enumName += enumPath[1] + '.' + enumPath[2];
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
- const keys = _enum.keys();
106
- if (keys.includes(v)) {
107
- return v;
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 if (Array.isArray(options)) {
114
- if (options.includes(v)) {
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
- else if (typeof options === 'object') {
122
- if (v in options) {
123
- return options[v];
124
- }
125
- else {
126
- throw error_1.NesoiError.Message.InvalidFieldEnumValue({ field: field.alias, value: v, type: 'enum', options: Object.keys(options) });
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
- throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'string' });
131
- });
132
- }
133
- function parseFile(field, value, array, options) {
134
- return parse('file', field, value, array, (v) => {
135
- if (!(v instanceof file_1.NesoiFile)) {
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?.extnames) {
148
- if (!options?.extnames.includes(v.extname)) {
149
- throw error_1.NesoiError.Message.FileExtNotAllowed({ name: field.name, alias: field.alias, options: options?.extnames });
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
- return v;
153
- });
104
+ }
105
+ throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, path: field.path_raw, value, type: 'string' });
154
106
  }
155
- function parseFloat_(field, value, array) {
156
- return parse('float', field, value, array, (v) => {
157
- if (typeof v === 'string') {
158
- const val = parseFloat(v);
159
- if (!Number.isNaN(val)) {
160
- return val;
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
- else if (typeof v === 'number') {
164
- if (!Number.isNaN(v)) {
165
- return v;
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
- throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'float' });
169
- });
125
+ }
126
+ return value;
170
127
  }
171
- async function parseId(field, value, array, trx, bucket, type, view) {
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 = await parseString(field, value, array);
145
+ val = parseString(field, value);
175
146
  }
176
147
  else {
177
- val = await parseInt_(field, value, array);
178
- }
179
- return parse('id', field, val, array, (async (v) => {
180
- return {
181
- id: v,
182
- obj: view
183
- ? await trx.bucket(bucket).viewOneOrFail(v, view)
184
- : await trx.bucket(bucket).readOneOrFail(v)
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, array) {
189
- return parse('int', field, value, array, (v) => {
190
- if (typeof v === 'string') {
191
- const val = parseInt(v);
192
- if (!Number.isNaN(val)) {
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
- else if (typeof v === 'number') {
197
- const val = Math.floor(v);
198
- if (!Number.isNaN(val)) {
199
- return val;
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
- throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'integer' });
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, array) {
206
- return parse('string', field, value, array, (v) => {
207
- if (typeof v === 'string') {
208
- return v;
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, array) {
214
- return parse('string_or_number', field, value, array, (v) => {
215
- if (typeof v === 'string' || typeof v === 'number') {
216
- return v;
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
- async function parseDict(field, value, array, trx, parseFields) {
222
- return parse('dict', field, value, array, (async (v) => {
223
- if (typeof v === 'object') {
224
- const parsed = {};
225
- for (const k in v) {
226
- const pv = await parseFields(trx, field.children, { __dict: v[k] });
227
- parsed[k] = pv['__dict'];
228
- }
229
- return parsed;
230
- }
231
- throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'dict' });
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
- async function parseObj(field, value, array, trx, parseFields) {
235
- return parse('obj', field, value, array, (async (v) => {
236
- if (typeof v === 'object') {
237
- if (field.children) {
238
- return await parseFields(trx, field.children, v);
239
- }
240
- return v;
241
- }
242
- throw error_1.NesoiError.Message.InvalidFieldType({ field: field.alias, value: v, type: 'object' });
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nesoi",
3
- "version": "3.0.18",
3
+ "version": "3.0.20",
4
4
  "description": "Declarative framework for data-driven applications",
5
5
  "repository": {
6
6
  "type": "git",