exact-mirror 0.2.6 → 0.2.7

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.
@@ -10,6 +10,7 @@ export interface Instruction {
10
10
  unions: TypeCheck<any>[][];
11
11
  unionKeys: Record<string, 1>;
12
12
  sanitize: MaybeArray<(v: string) => string> | undefined;
13
+ fromUnion?: boolean;
13
14
  /**
14
15
  * TypeCompiler is required when using Union
15
16
  *
package/dist/cjs/index.js CHANGED
@@ -89,7 +89,11 @@ var handleTuple = (schema, property, instruction) => {
89
89
  if (i2 !== 0) v += ",";
90
90
  v += mirror(
91
91
  schema[i2],
92
- joinProperty(property, i2, instruction.parentIsOptional),
92
+ joinProperty(
93
+ property,
94
+ i2,
95
+ instruction.parentIsOptional || instruction.fromUnion
96
+ ),
93
97
  instruction
94
98
  );
95
99
  }
@@ -173,14 +177,16 @@ var handleUnion = (schemas, property, instruction) => {
173
177
  {
174
178
  ...instruction,
175
179
  recursion: instruction.recursion + 1,
176
- parentIsOptional: true
180
+ parentIsOptional: true,
181
+ fromUnion: true
177
182
  }
178
183
  )}}
179
184
  `;
180
185
  cleanThenCheck += (i ? "" : "let ") + "tmp=" + mirror(type, property, {
181
186
  ...instruction,
182
187
  recursion: instruction.recursion + 1,
183
- parentIsOptional: true
188
+ parentIsOptional: true,
189
+ fromUnion: true
184
190
  }) + `
185
191
  if(d.unions[${ui}][${i}].Check(tmp))return tmp
186
192
  `;
@@ -223,7 +229,8 @@ var mirror = (schema, property, instruction) => {
223
229
  const name = joinProperty(
224
230
  property,
225
231
  key,
226
- instruction.parentIsOptional
232
+ // If parent is a union, any property could be undefined
233
+ instruction.parentIsOptional || instruction.fromUnion
227
234
  );
228
235
  if (isOptional) {
229
236
  const index = instruction.array;
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export interface Instruction {
10
10
  unions: TypeCheck<any>[][];
11
11
  unionKeys: Record<string, 1>;
12
12
  sanitize: MaybeArray<(v: string) => string> | undefined;
13
+ fromUnion?: boolean;
13
14
  /**
14
15
  * TypeCompiler is required when using Union
15
16
  *
package/dist/index.mjs CHANGED
@@ -62,7 +62,11 @@ var handleTuple = (schema, property, instruction) => {
62
62
  if (i2 !== 0) v += ",";
63
63
  v += mirror(
64
64
  schema[i2],
65
- joinProperty(property, i2, instruction.parentIsOptional),
65
+ joinProperty(
66
+ property,
67
+ i2,
68
+ instruction.parentIsOptional || instruction.fromUnion
69
+ ),
66
70
  instruction
67
71
  );
68
72
  }
@@ -146,14 +150,16 @@ var handleUnion = (schemas, property, instruction) => {
146
150
  {
147
151
  ...instruction,
148
152
  recursion: instruction.recursion + 1,
149
- parentIsOptional: true
153
+ parentIsOptional: true,
154
+ fromUnion: true
150
155
  }
151
156
  )}}
152
157
  `;
153
158
  cleanThenCheck += (i ? "" : "let ") + "tmp=" + mirror(type, property, {
154
159
  ...instruction,
155
160
  recursion: instruction.recursion + 1,
156
- parentIsOptional: true
161
+ parentIsOptional: true,
162
+ fromUnion: true
157
163
  }) + `
158
164
  if(d.unions[${ui}][${i}].Check(tmp))return tmp
159
165
  `;
@@ -196,7 +202,8 @@ var mirror = (schema, property, instruction) => {
196
202
  const name = joinProperty(
197
203
  property,
198
204
  key,
199
- instruction.parentIsOptional
205
+ // If parent is a union, any property could be undefined
206
+ instruction.parentIsOptional || instruction.fromUnion
200
207
  );
201
208
  if (isOptional) {
202
209
  const index = instruction.array;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exact-mirror",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "Mirror exact value to TypeBox/OpenAPI model",
5
5
  "license": "MIT",
6
6
  "scripts": {