@meshagent/meshagent 0.7.0 → 0.8.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.8.1]
2
+ - Stability
3
+
4
+ ## [0.8.0]
5
+ - Stability
6
+
7
+ ## [0.7.1]
8
+ - Stability
9
+
1
10
  ## [0.7.0]
2
11
  - Stability
3
12
 
@@ -23,11 +23,13 @@ export declare abstract class ElementProperty {
23
23
  export declare class ValueProperty extends ElementProperty {
24
24
  readonly type: SimpleValue;
25
25
  readonly enumValues?: any[];
26
- constructor({ name, description, type, enumValues }: {
26
+ readonly required: boolean;
27
+ constructor({ name, description, type, enumValues, required }: {
27
28
  name: string;
28
29
  description?: string;
29
30
  type: SimpleValue;
30
31
  enumValues?: any[];
32
+ required?: boolean;
31
33
  });
32
34
  validate(_: MeshSchema): void;
33
35
  toJson(): Record<string, any>;
@@ -40,26 +40,38 @@ class ElementProperty {
40
40
  }
41
41
  exports.ElementProperty = ElementProperty;
42
42
  class ValueProperty extends ElementProperty {
43
- constructor({ name, description, type, enumValues }) {
43
+ constructor({ name, description, type, enumValues, required = false }) {
44
44
  super({ name, description });
45
45
  this.type = type;
46
46
  this.enumValues = enumValues;
47
+ this.required = required;
47
48
  }
48
49
  validate(_) {
49
50
  }
50
51
  toJson() {
51
- const obj = {
52
- [this.name]: {
52
+ let propertyJson;
53
+ if (this.enumValues) {
54
+ propertyJson = {
53
55
  type: this.type,
54
- },
55
- };
56
- if (this.description) {
57
- obj[this.name].description = this.description;
56
+ enum: this.enumValues,
57
+ };
58
58
  }
59
- if (this.enumValues) {
60
- obj[this.name].enum = this.enumValues;
59
+ else if (this.required) {
60
+ propertyJson = {
61
+ type: this.type,
62
+ };
61
63
  }
62
- return obj;
64
+ else {
65
+ propertyJson = {
66
+ type: [this.type, "null"],
67
+ };
68
+ }
69
+ if (this.description) {
70
+ propertyJson.description = this.description;
71
+ }
72
+ return {
73
+ [this.name]: propertyJson,
74
+ };
63
75
  }
64
76
  }
65
77
  exports.ValueProperty = ValueProperty;
@@ -144,7 +156,16 @@ class ElementType {
144
156
  const pMap = pVal;
145
157
  const propDescription = pMap["description"];
146
158
  const pType = pMap["type"];
147
- if (pType === "array") {
159
+ let required = true;
160
+ let pTypeValue;
161
+ if (Array.isArray(pType) && pType.length > 0) {
162
+ pTypeValue = pType[0];
163
+ required = false;
164
+ }
165
+ else {
166
+ pTypeValue = pType;
167
+ }
168
+ if (pTypeValue === "array") {
148
169
  if (pMap["prefixItems"]) {
149
170
  const prefixItems = pMap["prefixItems"];
150
171
  const childTagNames = [];
@@ -188,7 +209,7 @@ class ElementType {
188
209
  }
189
210
  }
190
211
  else {
191
- const valTypeStr = pType;
212
+ const valTypeStr = pTypeValue;
192
213
  const valType = SimpleValue.fromString(valTypeStr);
193
214
  if (!valType) {
194
215
  throw new MeshSchemaValidationException(`Invalid value type: ${valTypeStr}`);
@@ -199,6 +220,7 @@ class ElementType {
199
220
  description: propDescription,
200
221
  type: valType,
201
222
  enumValues: enumVal,
223
+ required,
202
224
  }));
203
225
  }
204
226
  }
@@ -23,11 +23,13 @@ export declare abstract class ElementProperty {
23
23
  export declare class ValueProperty extends ElementProperty {
24
24
  readonly type: SimpleValue;
25
25
  readonly enumValues?: any[];
26
- constructor({ name, description, type, enumValues }: {
26
+ readonly required: boolean;
27
+ constructor({ name, description, type, enumValues, required }: {
27
28
  name: string;
28
29
  description?: string;
29
30
  type: SimpleValue;
30
31
  enumValues?: any[];
32
+ required?: boolean;
31
33
  });
32
34
  validate(_: MeshSchema): void;
33
35
  toJson(): Record<string, any>;
@@ -35,26 +35,38 @@ export class ElementProperty {
35
35
  }
36
36
  }
37
37
  export class ValueProperty extends ElementProperty {
38
- constructor({ name, description, type, enumValues }) {
38
+ constructor({ name, description, type, enumValues, required = false }) {
39
39
  super({ name, description });
40
40
  this.type = type;
41
41
  this.enumValues = enumValues;
42
+ this.required = required;
42
43
  }
43
44
  validate(_) {
44
45
  }
45
46
  toJson() {
46
- const obj = {
47
- [this.name]: {
47
+ let propertyJson;
48
+ if (this.enumValues) {
49
+ propertyJson = {
48
50
  type: this.type,
49
- },
50
- };
51
- if (this.description) {
52
- obj[this.name].description = this.description;
51
+ enum: this.enumValues,
52
+ };
53
53
  }
54
- if (this.enumValues) {
55
- obj[this.name].enum = this.enumValues;
54
+ else if (this.required) {
55
+ propertyJson = {
56
+ type: this.type,
57
+ };
56
58
  }
57
- return obj;
59
+ else {
60
+ propertyJson = {
61
+ type: [this.type, "null"],
62
+ };
63
+ }
64
+ if (this.description) {
65
+ propertyJson.description = this.description;
66
+ }
67
+ return {
68
+ [this.name]: propertyJson,
69
+ };
58
70
  }
59
71
  }
60
72
  export class ChildProperty extends ElementProperty {
@@ -137,7 +149,16 @@ export class ElementType {
137
149
  const pMap = pVal;
138
150
  const propDescription = pMap["description"];
139
151
  const pType = pMap["type"];
140
- if (pType === "array") {
152
+ let required = true;
153
+ let pTypeValue;
154
+ if (Array.isArray(pType) && pType.length > 0) {
155
+ pTypeValue = pType[0];
156
+ required = false;
157
+ }
158
+ else {
159
+ pTypeValue = pType;
160
+ }
161
+ if (pTypeValue === "array") {
141
162
  if (pMap["prefixItems"]) {
142
163
  const prefixItems = pMap["prefixItems"];
143
164
  const childTagNames = [];
@@ -181,7 +202,7 @@ export class ElementType {
181
202
  }
182
203
  }
183
204
  else {
184
- const valTypeStr = pType;
205
+ const valTypeStr = pTypeValue;
185
206
  const valType = SimpleValue.fromString(valTypeStr);
186
207
  if (!valType) {
187
208
  throw new MeshSchemaValidationException(`Invalid value type: ${valTypeStr}`);
@@ -192,6 +213,7 @@ export class ElementType {
192
213
  description: propDescription,
193
214
  type: valType,
194
215
  enumValues: enumVal,
216
+ required,
195
217
  }));
196
218
  }
197
219
  }
@@ -23,11 +23,13 @@ export declare abstract class ElementProperty {
23
23
  export declare class ValueProperty extends ElementProperty {
24
24
  readonly type: SimpleValue;
25
25
  readonly enumValues?: any[];
26
- constructor({ name, description, type, enumValues }: {
26
+ readonly required: boolean;
27
+ constructor({ name, description, type, enumValues, required }: {
27
28
  name: string;
28
29
  description?: string;
29
30
  type: SimpleValue;
30
31
  enumValues?: any[];
32
+ required?: boolean;
31
33
  });
32
34
  validate(_: MeshSchema): void;
33
35
  toJson(): Record<string, any>;
@@ -40,26 +40,38 @@ class ElementProperty {
40
40
  }
41
41
  exports.ElementProperty = ElementProperty;
42
42
  class ValueProperty extends ElementProperty {
43
- constructor({ name, description, type, enumValues }) {
43
+ constructor({ name, description, type, enumValues, required = false }) {
44
44
  super({ name, description });
45
45
  this.type = type;
46
46
  this.enumValues = enumValues;
47
+ this.required = required;
47
48
  }
48
49
  validate(_) {
49
50
  }
50
51
  toJson() {
51
- const obj = {
52
- [this.name]: {
52
+ let propertyJson;
53
+ if (this.enumValues) {
54
+ propertyJson = {
53
55
  type: this.type,
54
- },
55
- };
56
- if (this.description) {
57
- obj[this.name].description = this.description;
56
+ enum: this.enumValues,
57
+ };
58
58
  }
59
- if (this.enumValues) {
60
- obj[this.name].enum = this.enumValues;
59
+ else if (this.required) {
60
+ propertyJson = {
61
+ type: this.type,
62
+ };
61
63
  }
62
- return obj;
64
+ else {
65
+ propertyJson = {
66
+ type: [this.type, "null"],
67
+ };
68
+ }
69
+ if (this.description) {
70
+ propertyJson.description = this.description;
71
+ }
72
+ return {
73
+ [this.name]: propertyJson,
74
+ };
63
75
  }
64
76
  }
65
77
  exports.ValueProperty = ValueProperty;
@@ -144,7 +156,16 @@ class ElementType {
144
156
  const pMap = pVal;
145
157
  const propDescription = pMap["description"];
146
158
  const pType = pMap["type"];
147
- if (pType === "array") {
159
+ let required = true;
160
+ let pTypeValue;
161
+ if (Array.isArray(pType) && pType.length > 0) {
162
+ pTypeValue = pType[0];
163
+ required = false;
164
+ }
165
+ else {
166
+ pTypeValue = pType;
167
+ }
168
+ if (pTypeValue === "array") {
148
169
  if (pMap["prefixItems"]) {
149
170
  const prefixItems = pMap["prefixItems"];
150
171
  const childTagNames = [];
@@ -188,7 +209,7 @@ class ElementType {
188
209
  }
189
210
  }
190
211
  else {
191
- const valTypeStr = pType;
212
+ const valTypeStr = pTypeValue;
192
213
  const valType = SimpleValue.fromString(valTypeStr);
193
214
  if (!valType) {
194
215
  throw new MeshSchemaValidationException(`Invalid value type: ${valTypeStr}`);
@@ -199,6 +220,7 @@ class ElementType {
199
220
  description: propDescription,
200
221
  type: valType,
201
222
  enumValues: enumVal,
223
+ required,
202
224
  }));
203
225
  }
204
226
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshagent/meshagent",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "Meshagent Client",
5
5
  "homepage": "https://github.com/meshagent/meshagent-ts",
6
6
  "scripts": {