@highstate/contract 0.26.0 → 0.27.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/dist/index.js +10 -0
- package/package.json +1 -1
- package/src/component.spec.ts +11 -0
- package/src/entity.ts +15 -0
package/dist/index.js
CHANGED
|
@@ -322,6 +322,16 @@ function defineEntity(options) {
|
|
|
322
322
|
finalSchema = z2.intersection(finalSchema, strictIntersectionBase(z2.object(inclusionShape)));
|
|
323
323
|
}
|
|
324
324
|
finalSchema = z2.intersection(finalSchema, strictIntersectionBase(entityWithMetaSchema));
|
|
325
|
+
const optionalMultipleInclusions = includeRefs.filter((includeRef) => includeRef.multiple && !includeRef.required);
|
|
326
|
+
if (optionalMultipleInclusions.length > 0) {
|
|
327
|
+
finalSchema = finalSchema.overwrite((value) => {
|
|
328
|
+
const record = value;
|
|
329
|
+
for (const inclusion of optionalMultipleInclusions) {
|
|
330
|
+
record[inclusion.field] ??= [];
|
|
331
|
+
}
|
|
332
|
+
return value;
|
|
333
|
+
});
|
|
334
|
+
}
|
|
325
335
|
const directInclusions = () => includeRefs.map((includeRef) => ({
|
|
326
336
|
type: includeRef.getEntity().type,
|
|
327
337
|
required: includeRef.required,
|
package/package.json
CHANGED
package/src/component.spec.ts
CHANGED
|
@@ -190,6 +190,17 @@ describe("defineComponent", () => {
|
|
|
190
190
|
},
|
|
191
191
|
])
|
|
192
192
|
|
|
193
|
+
expect(
|
|
194
|
+
server.schema.parse({
|
|
195
|
+
$meta: {
|
|
196
|
+
type: "common.server.v1",
|
|
197
|
+
identity: "server-1",
|
|
198
|
+
},
|
|
199
|
+
tag: "prod",
|
|
200
|
+
endpoint: "127.0.0.1",
|
|
201
|
+
}).resource,
|
|
202
|
+
).toEqual([])
|
|
203
|
+
|
|
193
204
|
expect(
|
|
194
205
|
server.schema.safeParse({
|
|
195
206
|
$meta: {
|
package/src/entity.ts
CHANGED
|
@@ -515,6 +515,21 @@ export function defineEntity<
|
|
|
515
515
|
|
|
516
516
|
finalSchema = z.intersection(finalSchema, strictIntersectionBase(entityWithMetaSchema))
|
|
517
517
|
|
|
518
|
+
const optionalMultipleInclusions = includeRefs.filter(
|
|
519
|
+
includeRef => includeRef.multiple && !includeRef.required,
|
|
520
|
+
)
|
|
521
|
+
if (optionalMultipleInclusions.length > 0) {
|
|
522
|
+
finalSchema = finalSchema.overwrite(value => {
|
|
523
|
+
const record = value as Record<string, unknown>
|
|
524
|
+
|
|
525
|
+
for (const inclusion of optionalMultipleInclusions) {
|
|
526
|
+
record[inclusion.field] ??= []
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
return value
|
|
530
|
+
})
|
|
531
|
+
}
|
|
532
|
+
|
|
518
533
|
const directInclusions = () =>
|
|
519
534
|
includeRefs.map(includeRef => ({
|
|
520
535
|
type: includeRef.getEntity().type,
|