nesoi 3.0.20 → 3.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.
- package/lib/compiler/apps/monolyth/stages/4_dump_modules_stage.js +8 -0
- package/lib/compiler/compiler.js +1 -1
- package/lib/compiler/elements/bucket.element.d.ts +2 -1
- package/lib/compiler/elements/bucket.element.js +68 -122
- package/lib/compiler/elements/element.js +2 -1
- package/lib/compiler/elements/externals.element.js +3 -0
- package/lib/compiler/elements/message.element.js +34 -57
- package/lib/compiler/elements/queue.element.js +1 -1
- package/lib/compiler/helpers/dump_helpers.d.ts +2 -0
- package/lib/compiler/helpers/dump_helpers.js +12 -2
- package/lib/compiler/stages/4_build_schemas_stage.js +12 -0
- package/lib/compiler/stages/5_inject_ts_stage.js +4 -1
- package/lib/compiler/stages/7_dump_stage.js +7 -1
- package/lib/compiler/treeshake.js +4 -2
- package/lib/compiler/typescript/bridge/extract.js +37 -107
- package/lib/compiler/typescript/bridge/inject.d.ts +1 -1
- package/lib/compiler/typescript/bridge/inject.js +73 -45
- package/lib/compiler/typescript/bridge/organize.js +9 -5
- package/lib/compiler/typescript/typescript_compiler.d.ts +4 -6
- package/lib/compiler/typescript/typescript_compiler.js +139 -75
- package/lib/elements/blocks/block.builder.d.ts +1 -10
- package/lib/elements/blocks/block.builder.js +0 -32
- package/lib/elements/blocks/job/internal/resource_job.builder.d.ts +3 -21
- package/lib/elements/blocks/job/job.builder.d.ts +6 -20
- package/lib/elements/blocks/job/job.builder.js +0 -4
- package/lib/elements/blocks/machine/machine.builder.d.ts +5 -14
- package/lib/elements/blocks/machine/machine.builder.js +2 -2
- package/lib/elements/blocks/queue/queue.builder.d.ts +6 -15
- package/lib/elements/blocks/queue/queue.builder.js +2 -2
- package/lib/elements/edge/externals/externals.builder.d.ts +2 -0
- package/lib/elements/edge/externals/externals.builder.js +6 -1
- package/lib/elements/edge/externals/externals.schema.d.ts +2 -1
- package/lib/elements/edge/externals/externals.schema.js +3 -1
- package/lib/elements/entities/bucket/adapters/memory.nql.js +1 -1
- package/lib/elements/entities/bucket/bucket.builder.d.ts +6 -4
- package/lib/elements/entities/bucket/bucket.js +7 -16
- package/lib/elements/entities/bucket/bucket.schema.d.ts +2 -1
- package/lib/elements/entities/bucket/graph/bucket_graph.infer.d.ts +7 -5
- package/lib/elements/entities/bucket/graph/bucket_graph_link.builder.d.ts +2 -1
- package/lib/elements/entities/bucket/model/bucket_model.builder.d.ts +1 -1
- package/lib/elements/entities/bucket/model/bucket_model.convert.d.ts +1 -1
- package/lib/elements/entities/bucket/model/bucket_model.convert.js +4 -4
- package/lib/elements/entities/bucket/model/bucket_model.infer.d.ts +45 -9
- package/lib/elements/entities/bucket/model/bucket_model.schema.d.ts +5 -6
- package/lib/elements/entities/bucket/model/bucket_model.schema.js +64 -21
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +88 -55
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +22 -30
- package/lib/elements/entities/bucket/query/nql.schema.d.ts +13 -10
- package/lib/elements/entities/bucket/query/nql_compiler.js +46 -21
- package/lib/elements/entities/bucket/view/bucket_view.builder.js +1 -1
- package/lib/elements/entities/bucket/view/bucket_view.d.ts +19 -0
- package/lib/elements/entities/bucket/view/bucket_view.js +230 -108
- package/lib/elements/entities/bucket/view/bucket_view.schema.d.ts +5 -10
- package/lib/elements/entities/bucket/view/bucket_view.schema.js +3 -5
- package/lib/elements/entities/bucket/view/bucket_view_field.builder.d.ts +16 -12
- package/lib/elements/entities/bucket/view/bucket_view_field.builder.js +55 -40
- package/lib/elements/entities/message/message.builder.d.ts +1 -11
- package/lib/elements/entities/message/message.builder.js +2 -2
- package/lib/elements/entities/message/message.infer.d.ts +6 -30
- package/lib/elements/entities/message/message.schema.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.builder.js +1 -1
- package/lib/elements/entities/message/template/message_template.schema.d.ts +11 -6
- package/lib/elements/entities/message/template/message_template.schema.js +29 -6
- package/lib/elements/entities/message/template/message_template_field.builder.d.ts +50 -203
- package/lib/elements/entities/message/template/message_template_field.builder.js +74 -74
- package/lib/elements/entities/message/template/message_template_parser.d.ts +2 -2
- package/lib/elements/entities/message/template/message_template_parser.js +137 -71
- package/lib/engine/apps/inline.app.js +1 -0
- package/lib/engine/data/error.d.ts +12 -11
- package/lib/engine/data/error.js +7 -7
- package/lib/engine/data/trash.js +7 -7
- package/lib/engine/data/tree.d.ts +3 -0
- package/lib/engine/data/tree.js +36 -0
- package/lib/engine/util/parse.d.ts +36 -28
- package/lib/engine/util/parse.js +53 -43
- package/lib/engine/util/type.d.ts +3 -0
- package/package.json +1 -1
- package/tools/joaquin/bucket.d.ts +9 -0
- package/tools/joaquin/bucket.js +49 -0
- package/tools/joaquin/message.d.ts +2 -1
- package/tools/joaquin/message.js +9 -2
- package/tools/joaquin/mock.d.ts +1 -0
- package/tools/joaquin/mock.js +13 -5
- package/tsconfig.build.tsbuildinfo +1 -1
package/lib/engine/data/tree.js
CHANGED
|
@@ -17,6 +17,8 @@ class Tree {
|
|
|
17
17
|
* - `*`: Return all values of the matched array or dict
|
|
18
18
|
* - `0`: Return the first value of an array or dict (dict ordering is unstable)
|
|
19
19
|
* - `(number|string)[]`: Sequence of values to replace the `#`s on the fieldpath
|
|
20
|
+
*
|
|
21
|
+
* @deprecated Fieldpath was consolidated into Modelpath and Querypath.
|
|
20
22
|
*/
|
|
21
23
|
static get(obj, fieldpath, index = '*') {
|
|
22
24
|
index = (!Array.isArray(index)) ? index : [...index];
|
|
@@ -90,6 +92,40 @@ class Tree {
|
|
|
90
92
|
}
|
|
91
93
|
return ref;
|
|
92
94
|
}
|
|
95
|
+
static getModelpath(obj, modelpath, index) {
|
|
96
|
+
const paths = modelpath.split('.');
|
|
97
|
+
let poll = [obj];
|
|
98
|
+
while (poll.length) {
|
|
99
|
+
const next = [];
|
|
100
|
+
for (const item of poll) {
|
|
101
|
+
const path = paths[item.i];
|
|
102
|
+
// '*'
|
|
103
|
+
if (path === '*') {
|
|
104
|
+
if (typeof item !== 'object') {
|
|
105
|
+
throw new Error(`Can't read *, item is not object (${item})`);
|
|
106
|
+
}
|
|
107
|
+
next.push(...Object.values(item));
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const idx_str = path.match(/^\$(\d+)/)?.[1];
|
|
111
|
+
let _path = path;
|
|
112
|
+
// $0, $1..
|
|
113
|
+
if (idx_str !== undefined) {
|
|
114
|
+
const idx = parseInt(idx_str);
|
|
115
|
+
if (idx >= index.length) {
|
|
116
|
+
throw new Error(`Can't read $${idx}, too few indexes (${index.length})`);
|
|
117
|
+
}
|
|
118
|
+
_path = index[idx];
|
|
119
|
+
}
|
|
120
|
+
const n = typeof item === 'object' ? item[_path] : undefined;
|
|
121
|
+
if (n)
|
|
122
|
+
next.push(n);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
poll = next;
|
|
126
|
+
}
|
|
127
|
+
return poll;
|
|
128
|
+
}
|
|
93
129
|
static set(obj, fieldpath, replacer, __index = []) {
|
|
94
130
|
const paths = fieldpath.split('.');
|
|
95
131
|
class Ptr {
|
|
@@ -7,74 +7,82 @@ import { NesoiDatetime } from '../data/datetime';
|
|
|
7
7
|
import { NesoiFile } from '../data/file';
|
|
8
8
|
import { NesoiDuration } from '../data/duration';
|
|
9
9
|
export declare function parseBoolean(field: {
|
|
10
|
-
|
|
10
|
+
pathRaw: string;
|
|
11
11
|
alias: string;
|
|
12
|
-
}, value: any): boolean;
|
|
12
|
+
}, path: string[], value: any): boolean;
|
|
13
13
|
export declare function parseDate(field: {
|
|
14
|
-
|
|
14
|
+
pathRaw: string;
|
|
15
15
|
alias: string;
|
|
16
|
-
}, value: any): NesoiDate;
|
|
16
|
+
}, path: string[], value: any): NesoiDate;
|
|
17
17
|
export declare function parseDatetime(field: {
|
|
18
|
-
|
|
18
|
+
pathRaw: string;
|
|
19
19
|
alias: string;
|
|
20
|
-
}, value: any): NesoiDatetime;
|
|
20
|
+
}, path: string[], value: any): NesoiDatetime;
|
|
21
21
|
export declare function parseDuration(field: {
|
|
22
|
-
|
|
22
|
+
pathRaw: string;
|
|
23
23
|
alias: string;
|
|
24
|
-
}, value: any): NesoiDuration;
|
|
24
|
+
}, path: string[], value: any): NesoiDuration;
|
|
25
25
|
export declare function parseDecimal(field: {
|
|
26
|
-
|
|
26
|
+
pathRaw: 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
|
+
pathRaw: 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
|
+
pathRaw: 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
|
+
pathRaw: 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
|
+
pathRaw: 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
|
+
pathRaw: string;
|
|
55
55
|
alias: string;
|
|
56
|
-
}, value: any): number;
|
|
56
|
+
}, path: string[], value: any): number;
|
|
57
57
|
export declare function parseString(field: {
|
|
58
|
-
|
|
58
|
+
pathRaw: string;
|
|
59
59
|
alias: string;
|
|
60
|
-
}, value: any): string;
|
|
60
|
+
}, path: string[], value: any): string;
|
|
61
61
|
export declare function parseStringOrNumber(field: {
|
|
62
|
-
|
|
62
|
+
pathRaw: 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
|
+
pathRaw: string;
|
|
67
67
|
alias: string;
|
|
68
68
|
children?: $MessageTemplateFields;
|
|
69
|
-
}, value: any): Record<string, {
|
|
69
|
+
}, path: string[], value: any): Record<string, {
|
|
70
|
+
field: $MessageTemplateField;
|
|
71
|
+
value?: any;
|
|
72
|
+
}>;
|
|
73
|
+
export declare function parseList(field: {
|
|
74
|
+
pathRaw: string;
|
|
75
|
+
alias: string;
|
|
76
|
+
children?: $MessageTemplateFields;
|
|
77
|
+
}, path: string[], value: any): Record<string, {
|
|
70
78
|
field: $MessageTemplateField;
|
|
71
79
|
value?: any;
|
|
72
80
|
}>;
|
|
73
81
|
export declare function parseObj(field: {
|
|
74
|
-
|
|
82
|
+
pathRaw: string;
|
|
75
83
|
alias: string;
|
|
76
84
|
children?: $MessageTemplateFields;
|
|
77
|
-
},
|
|
85
|
+
}, path: string[], value: any): Record<string, {
|
|
78
86
|
field: $MessageTemplateField;
|
|
79
87
|
value?: any;
|
|
80
88
|
}>;
|
package/lib/engine/util/parse.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.parseInt_ = parseInt_;
|
|
|
13
13
|
exports.parseString = parseString;
|
|
14
14
|
exports.parseStringOrNumber = parseStringOrNumber;
|
|
15
15
|
exports.parseDict = parseDict;
|
|
16
|
+
exports.parseList = parseList;
|
|
16
17
|
exports.parseObj = parseObj;
|
|
17
18
|
const date_1 = require("../data/date");
|
|
18
19
|
const error_1 = require("../data/error");
|
|
@@ -21,7 +22,7 @@ const decimal_1 = require("../data/decimal");
|
|
|
21
22
|
const datetime_1 = require("../data/datetime");
|
|
22
23
|
const file_1 = require("../data/file");
|
|
23
24
|
const duration_1 = require("../data/duration");
|
|
24
|
-
function parseBoolean(field, value) {
|
|
25
|
+
function parseBoolean(field, path, value) {
|
|
25
26
|
if (value === 'true' || value === 1) {
|
|
26
27
|
return true;
|
|
27
28
|
}
|
|
@@ -31,34 +32,34 @@ function parseBoolean(field, value) {
|
|
|
31
32
|
if (typeof value === 'boolean') {
|
|
32
33
|
return value;
|
|
33
34
|
}
|
|
34
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
35
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'boolean' });
|
|
35
36
|
}
|
|
36
|
-
function parseDate(field, value) {
|
|
37
|
+
function parseDate(field, path, value) {
|
|
37
38
|
// TODO: limit to date
|
|
38
39
|
if (typeof value === 'string') {
|
|
39
40
|
return date_1.NesoiDate.fromISO(value);
|
|
40
41
|
}
|
|
41
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
42
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'date' });
|
|
42
43
|
}
|
|
43
|
-
function parseDatetime(field, value) {
|
|
44
|
+
function parseDatetime(field, path, value) {
|
|
44
45
|
if (typeof value === 'string') {
|
|
45
46
|
return datetime_1.NesoiDatetime.fromISO(value);
|
|
46
47
|
}
|
|
47
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
48
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'datetime' });
|
|
48
49
|
}
|
|
49
|
-
function parseDuration(field, value) {
|
|
50
|
+
function parseDuration(field, path, value) {
|
|
50
51
|
if (typeof value === 'string') {
|
|
51
52
|
return duration_1.NesoiDuration.fromString(value);
|
|
52
53
|
}
|
|
53
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
54
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'duration' });
|
|
54
55
|
}
|
|
55
|
-
function parseDecimal(field, value) {
|
|
56
|
+
function parseDecimal(field, path, value) {
|
|
56
57
|
if (typeof value === 'string') {
|
|
57
58
|
return new decimal_1.NesoiDecimal(value);
|
|
58
59
|
}
|
|
59
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
60
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'decimal' });
|
|
60
61
|
}
|
|
61
|
-
function parseEnum(raw, field, value, options, trx) {
|
|
62
|
+
function parseEnum(raw, field, path, value, options, trx) {
|
|
62
63
|
if (typeof value === 'string') {
|
|
63
64
|
if (typeof options === 'string') {
|
|
64
65
|
let enumName = options;
|
|
@@ -71,7 +72,7 @@ function parseEnum(raw, field, value, options, trx) {
|
|
|
71
72
|
}
|
|
72
73
|
catch {
|
|
73
74
|
const v = tree_1.Tree.get(raw, enumPath[2]);
|
|
74
|
-
throw error_1.NesoiError.Message.InvalidEnumScope({
|
|
75
|
+
throw error_1.NesoiError.Message.InvalidEnumScope({ alias: field.alias, path: path.join('.'), value: v, fieldpath: enumPath[2] });
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
else {
|
|
@@ -82,7 +83,7 @@ function parseEnum(raw, field, value, options, trx) {
|
|
|
82
83
|
return value;
|
|
83
84
|
}
|
|
84
85
|
else {
|
|
85
|
-
throw error_1.NesoiError.Message.InvalidFieldEnumValue({
|
|
86
|
+
throw error_1.NesoiError.Message.InvalidFieldEnumValue({ alias: field.alias, path: path.join('.'), value, type: 'enum', options: keys });
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
else if (Array.isArray(options)) {
|
|
@@ -90,7 +91,7 @@ function parseEnum(raw, field, value, options, trx) {
|
|
|
90
91
|
return value;
|
|
91
92
|
}
|
|
92
93
|
else {
|
|
93
|
-
throw error_1.NesoiError.Message.InvalidFieldEnumValue({
|
|
94
|
+
throw error_1.NesoiError.Message.InvalidFieldEnumValue({ alias: field.alias, path: path.join('.'), value, type: 'enum', options });
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
else if (typeof options === 'object') {
|
|
@@ -98,34 +99,29 @@ function parseEnum(raw, field, value, options, trx) {
|
|
|
98
99
|
return options[value];
|
|
99
100
|
}
|
|
100
101
|
else {
|
|
101
|
-
throw error_1.NesoiError.Message.InvalidFieldEnumValue({
|
|
102
|
+
throw error_1.NesoiError.Message.InvalidFieldEnumValue({ alias: field.alias, path: path.join('.'), value, type: 'enum', options: Object.keys(options) });
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
106
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'string' });
|
|
106
107
|
}
|
|
107
|
-
function parseFile(field, value, options) {
|
|
108
|
+
function parseFile(field, path, value, options) {
|
|
108
109
|
if (!(value instanceof file_1.NesoiFile)) {
|
|
109
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
110
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'file' });
|
|
110
111
|
}
|
|
111
112
|
if (options?.maxsize) {
|
|
112
113
|
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
|
-
});
|
|
114
|
+
throw error_1.NesoiError.Message.FileTooBig({ alias: field.alias, path: path.join('.'), maxsize: options?.maxsize });
|
|
119
115
|
}
|
|
120
116
|
}
|
|
121
117
|
if (options?.extnames) {
|
|
122
118
|
if (!options?.extnames.includes(value.extname)) {
|
|
123
|
-
throw error_1.NesoiError.Message.FileExtNotAllowed({
|
|
119
|
+
throw error_1.NesoiError.Message.FileExtNotAllowed({ alias: field.alias, path: path.join('.'), options: options?.extnames });
|
|
124
120
|
}
|
|
125
121
|
}
|
|
126
122
|
return value;
|
|
127
123
|
}
|
|
128
|
-
function parseFloat_(field, value) {
|
|
124
|
+
function parseFloat_(field, path, value) {
|
|
129
125
|
if (typeof value === 'string') {
|
|
130
126
|
const val = parseFloat(value);
|
|
131
127
|
if (!Number.isNaN(val)) {
|
|
@@ -137,15 +133,15 @@ function parseFloat_(field, value) {
|
|
|
137
133
|
return value;
|
|
138
134
|
}
|
|
139
135
|
}
|
|
140
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
136
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'float' });
|
|
141
137
|
}
|
|
142
|
-
async function parseId(field, value, trx, bucket, type, view) {
|
|
138
|
+
async function parseId(field, path, value, trx, bucket, type, view) {
|
|
143
139
|
let val;
|
|
144
140
|
if (type === 'string') {
|
|
145
|
-
val = parseString(field, value);
|
|
141
|
+
val = parseString(field, path, value);
|
|
146
142
|
}
|
|
147
143
|
else {
|
|
148
|
-
val = parseInt_(field, value);
|
|
144
|
+
val = parseInt_(field, path, value);
|
|
149
145
|
}
|
|
150
146
|
return {
|
|
151
147
|
id: val,
|
|
@@ -154,7 +150,7 @@ async function parseId(field, value, trx, bucket, type, view) {
|
|
|
154
150
|
: await trx.bucket(bucket).readOneOrFail(val)
|
|
155
151
|
};
|
|
156
152
|
}
|
|
157
|
-
function parseInt_(field, value) {
|
|
153
|
+
function parseInt_(field, path, value) {
|
|
158
154
|
if (typeof value === 'string') {
|
|
159
155
|
const val = parseInt(value);
|
|
160
156
|
if (!Number.isNaN(val)) {
|
|
@@ -167,25 +163,25 @@ function parseInt_(field, value) {
|
|
|
167
163
|
return val;
|
|
168
164
|
}
|
|
169
165
|
}
|
|
170
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
166
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'integer' });
|
|
171
167
|
}
|
|
172
|
-
function parseString(field, value) {
|
|
168
|
+
function parseString(field, path, value) {
|
|
173
169
|
if (typeof value === 'string') {
|
|
174
170
|
return value;
|
|
175
171
|
}
|
|
176
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
172
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'string' });
|
|
177
173
|
}
|
|
178
|
-
function parseStringOrNumber(field, value) {
|
|
174
|
+
function parseStringOrNumber(field, path, value) {
|
|
179
175
|
if (typeof value === 'string' || typeof value === 'number') {
|
|
180
176
|
return value;
|
|
181
177
|
}
|
|
182
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
178
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'string_or_number' });
|
|
183
179
|
}
|
|
184
|
-
function parseDict(field, value) {
|
|
180
|
+
function parseDict(field, path, value) {
|
|
185
181
|
if (typeof value === 'object') {
|
|
186
182
|
const children = {};
|
|
187
183
|
for (const key in value) {
|
|
188
|
-
const _field = field.children['
|
|
184
|
+
const _field = field.children['#'];
|
|
189
185
|
children[key] = {
|
|
190
186
|
field: _field,
|
|
191
187
|
value: value[key]
|
|
@@ -193,17 +189,31 @@ function parseDict(field, value) {
|
|
|
193
189
|
}
|
|
194
190
|
return children;
|
|
195
191
|
}
|
|
196
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
192
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'dict' });
|
|
197
193
|
}
|
|
198
|
-
function
|
|
194
|
+
function parseList(field, path, value) {
|
|
195
|
+
if (!Array.isArray(value)) {
|
|
196
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'list' });
|
|
197
|
+
}
|
|
198
|
+
const children = {};
|
|
199
|
+
for (let i = 0; i < value.length; i++) {
|
|
200
|
+
const _field = field.children['#'];
|
|
201
|
+
children[i] = {
|
|
202
|
+
field: _field,
|
|
203
|
+
value: value[i]
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
return children;
|
|
207
|
+
}
|
|
208
|
+
function parseObj(field, path, value) {
|
|
199
209
|
if (typeof value === 'object') {
|
|
200
210
|
if (!field.children)
|
|
201
211
|
return {};
|
|
202
212
|
const children = {};
|
|
203
213
|
for (const key in field.children) {
|
|
204
214
|
const _field = field.children[key];
|
|
205
|
-
const key_raw = _field.
|
|
206
|
-
const key_parsed = _field.
|
|
215
|
+
const key_raw = _field.pathRaw.split('.')[path.length];
|
|
216
|
+
const key_parsed = _field.pathParsed.split('.')[path.length];
|
|
207
217
|
children[key_parsed] = {
|
|
208
218
|
field: _field,
|
|
209
219
|
value: value[key_raw]
|
|
@@ -211,5 +221,5 @@ function parseObj(field, value, path_idx) {
|
|
|
211
221
|
}
|
|
212
222
|
return children;
|
|
213
223
|
}
|
|
214
|
-
throw error_1.NesoiError.Message.InvalidFieldType({
|
|
224
|
+
throw error_1.NesoiError.Message.InvalidFieldType({ alias: field.alias, path: path.join('.'), value, type: 'object' });
|
|
215
225
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AnyBucketBuilder } from "../../src/elements/entities/bucket/bucket.builder";
|
|
2
|
+
import { NesoiError } from "../../src/engine/data/error";
|
|
3
|
+
import { AnyBuilder } from "../../src/engine/module";
|
|
4
|
+
export declare function expectBucket(def: (builder: AnyBucketBuilder) => any, inject?: AnyBuilder[]): {
|
|
5
|
+
toBuildOne(raw: Record<string, any>, view: string): {
|
|
6
|
+
as(parsed: Record<string, any>): Promise<void>;
|
|
7
|
+
butFail(error: (...args: any[]) => NesoiError.BaseError): Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expectBucket = expectBucket;
|
|
4
|
+
const bucket_builder_1 = require("../../src/elements/entities/bucket/bucket.builder");
|
|
5
|
+
const inline_app_1 = require("../../src/engine/apps/inline.app");
|
|
6
|
+
function expectBucket(def, inject = []) {
|
|
7
|
+
const builder = new bucket_builder_1.BucketBuilder('test', 'test');
|
|
8
|
+
def(builder);
|
|
9
|
+
const app = new inline_app_1.InlineApp('test', [...inject, builder]);
|
|
10
|
+
let promise;
|
|
11
|
+
const step1 = {
|
|
12
|
+
toBuildOne(raw, view) {
|
|
13
|
+
promise = Promise.all([raw].map(raw => app.daemon().then(daemon => daemon.trx('test').run(trx => trx.bucket('test').buildOne(raw, view)))));
|
|
14
|
+
return step2;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const step2 = {
|
|
18
|
+
async as(parsed) {
|
|
19
|
+
const status = await promise;
|
|
20
|
+
status.forEach(st => {
|
|
21
|
+
if (st.state === 'error') {
|
|
22
|
+
console.log(st.summary());
|
|
23
|
+
console.error(st.error?.data);
|
|
24
|
+
console.error(st.error?.data?.unionErrors);
|
|
25
|
+
console.error(st.error?.stack);
|
|
26
|
+
}
|
|
27
|
+
expect(st.state).toEqual('ok');
|
|
28
|
+
expect(st.output)
|
|
29
|
+
.toEqual(parsed);
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
async butFail(error) {
|
|
33
|
+
const errorObj = error({});
|
|
34
|
+
try {
|
|
35
|
+
const status = await promise;
|
|
36
|
+
status.forEach(st => {
|
|
37
|
+
expect(st.state).toEqual('error');
|
|
38
|
+
expect(st.error?.name)
|
|
39
|
+
.toEqual(errorObj.name);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
expect(e.toString())
|
|
44
|
+
.toMatch(new RegExp(`^\\[${errorObj.name}\\]`));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
return step1;
|
|
49
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MessageTemplateDef } from "../../src/elements/entities/message/template/message_template.builder";
|
|
2
2
|
import { NesoiError } from "../../src/engine/data/error";
|
|
3
|
-
|
|
3
|
+
import { AnyBuilder } from "../../src/engine/module";
|
|
4
|
+
export declare function expectMessage(def: MessageTemplateDef<any, any, any>, inject?: AnyBuilder[]): {
|
|
4
5
|
toParse(raw: Record<string, any>): {
|
|
5
6
|
as(parsed: Record<string, any>): Promise<void>;
|
|
6
7
|
butFail(error: (...args: any[]) => NesoiError.BaseError): Promise<void>;
|
package/tools/joaquin/message.js
CHANGED
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.expectMessage = expectMessage;
|
|
4
4
|
const message_builder_1 = require("../../src/elements/entities/message/message.builder");
|
|
5
5
|
const inline_app_1 = require("../../src/engine/apps/inline.app");
|
|
6
|
-
function expectMessage(def) {
|
|
6
|
+
function expectMessage(def, inject = []) {
|
|
7
7
|
const builder = new message_builder_1.MessageBuilder('test', 'test');
|
|
8
8
|
builder.template(def);
|
|
9
|
-
const app = new inline_app_1.InlineApp('test', [builder]);
|
|
9
|
+
const app = new inline_app_1.InlineApp('test', [...inject, builder]);
|
|
10
10
|
let promise;
|
|
11
11
|
const step1 = {
|
|
12
12
|
toParse(raw) {
|
|
@@ -22,6 +22,13 @@ function expectMessage(def) {
|
|
|
22
22
|
async as(parsed) {
|
|
23
23
|
const status = await promise;
|
|
24
24
|
status.forEach(st => {
|
|
25
|
+
if (st.state === 'error') {
|
|
26
|
+
console.log(st.summary());
|
|
27
|
+
console.error(st.error?.message);
|
|
28
|
+
console.error(st.error?.data);
|
|
29
|
+
console.error(st.error?.data?.unionErrors);
|
|
30
|
+
console.error(st.error?.stack);
|
|
31
|
+
}
|
|
25
32
|
expect(st.state).toEqual('ok');
|
|
26
33
|
expect(st.output.getData())
|
|
27
34
|
.toEqual(parsed);
|
package/tools/joaquin/mock.d.ts
CHANGED
package/tools/joaquin/mock.js
CHANGED
|
@@ -40,7 +40,10 @@ class BucketMockObj {
|
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
42
42
|
const field = fields[f];
|
|
43
|
-
if (field.
|
|
43
|
+
if (field.type === 'union') {
|
|
44
|
+
obj[f] = this.makeUnion(field, overrides?.[f]);
|
|
45
|
+
}
|
|
46
|
+
if (field.type === 'list') {
|
|
44
47
|
obj[f] = this.makeList(field, overrides?.[f]);
|
|
45
48
|
}
|
|
46
49
|
else {
|
|
@@ -50,6 +53,11 @@ class BucketMockObj {
|
|
|
50
53
|
}
|
|
51
54
|
return obj;
|
|
52
55
|
}
|
|
56
|
+
makeUnion(field, overrides) {
|
|
57
|
+
const n = Object.keys(field.children).length;
|
|
58
|
+
const r = Math.floor(Math.random() * n);
|
|
59
|
+
return this.makeField(field.children[r], overrides);
|
|
60
|
+
}
|
|
53
61
|
makeList(field, overrides) {
|
|
54
62
|
const list = [];
|
|
55
63
|
for (let i = 0; i < 3; i++) {
|
|
@@ -73,7 +81,7 @@ class BucketMockObj {
|
|
|
73
81
|
else if (field.type === 'dict') {
|
|
74
82
|
const dict = {};
|
|
75
83
|
for (let i = 0; i < 3; i++) {
|
|
76
|
-
dict[Mock.string()] = this.makeField(field.children
|
|
84
|
+
dict[Mock.string()] = this.makeField(field.children['#']);
|
|
77
85
|
}
|
|
78
86
|
return dict;
|
|
79
87
|
}
|
|
@@ -134,8 +142,8 @@ class MessageMock {
|
|
|
134
142
|
}
|
|
135
143
|
else {
|
|
136
144
|
const field = fields[f];
|
|
137
|
-
if (field.
|
|
138
|
-
obj[f] = this.makeList(field, overrides?.[f]);
|
|
145
|
+
if (field.type === 'list') {
|
|
146
|
+
obj[f] = this.makeList(field.children['#'], overrides?.[f]);
|
|
139
147
|
}
|
|
140
148
|
else {
|
|
141
149
|
obj[f] = this.makeField(field, overrides?.[f]);
|
|
@@ -167,7 +175,7 @@ class MessageMock {
|
|
|
167
175
|
else if (field.type === 'dict') {
|
|
168
176
|
const dict = {};
|
|
169
177
|
for (let i = 0; i < 3; i++) {
|
|
170
|
-
dict[Mock.string()] = this.makeField(field.children
|
|
178
|
+
dict[Mock.string()] = this.makeField(field.children['#']);
|
|
171
179
|
}
|
|
172
180
|
return dict;
|
|
173
181
|
}
|