@highstate/contract 0.26.0 → 0.28.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 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,
@@ -589,7 +599,7 @@ var instanceModelPatchSchema = z4.object({
589
599
  inputs: z4.record(z4.string(), z4.array(instanceInputSchema)).optional(),
590
600
  hubInputs: z4.record(z4.string(), z4.array(hubInputSchema)).optional(),
591
601
  injectionInputs: z4.array(hubInputSchema).optional(),
592
- position: positionSchema.optional()
602
+ position: positionSchema.partial().nullable().optional()
593
603
  });
594
604
  var instanceModelSchema = z4.object({
595
605
  id: instanceIdSchema,
@@ -597,19 +607,21 @@ var instanceModelSchema = z4.object({
597
607
  type: versionedNameSchema,
598
608
  name: genericNameSchema,
599
609
  ...instanceModelPatchSchema.shape,
610
+ position: positionSchema.optional(),
600
611
  resolvedInputs: z4.record(z4.string(), z4.array(instanceInputSchema)).optional(),
601
612
  parentId: instanceIdSchema.optional(),
602
613
  outputs: z4.record(z4.string(), z4.array(instanceInputSchema)).optional(),
603
614
  resolvedOutputs: z4.record(z4.string(), z4.array(instanceInputSchema)).optional()
604
615
  });
605
616
  var hubModelPatchSchema = z4.object({
606
- position: positionSchema.optional(),
617
+ position: positionSchema.partial().nullable().optional(),
607
618
  inputs: z4.array(instanceInputSchema).optional(),
608
619
  injectionInputs: z4.array(hubInputSchema).optional()
609
620
  });
610
621
  var hubModelSchema = z4.object({
611
622
  id: z4.cuid2(),
612
- ...hubModelPatchSchema.shape
623
+ ...hubModelPatchSchema.shape,
624
+ position: positionSchema.optional()
613
625
  });
614
626
  function parseInstanceId(instanceId) {
615
627
  const parts = instanceId.split(":");
@@ -624,7 +636,7 @@ function selectInput(inputs, name) {
624
636
  throw new Error(`Cannot select input "${name}": empty input group has no boundary metadata to build a missing input reference.`);
625
637
  }
626
638
  const input = inputs.find((input2) => input2.provided && (input2.instanceId === name || parseInstanceId(input2.instanceId)[1] === name));
627
- if (!input || !input.provided) {
639
+ if (!input?.provided) {
628
640
  const fallbackBoundary = groupBoundary ?? inputs.find((input2) => Boolean(input2[boundaryInput]))?.[boundaryInput] ?? inputs[0]?.[boundaryInput];
629
641
  if (!fallbackBoundary) {
630
642
  throw new Error(`Cannot select input "${name}": input group has no boundary metadata to build a missing input reference.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@highstate/contract",
3
- "version": "0.26.0",
3
+ "version": "0.28.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -44,7 +44,7 @@
44
44
  "zod": "^4.3.6"
45
45
  },
46
46
  "devDependencies": {
47
- "@biomejs/biome": "2.2.0",
47
+ "@biomejs/biome": "2.5.0",
48
48
  "@typescript/native-preview": "^7.0.0-dev.20250920.1",
49
49
  "@vitest/coverage-v8": "2.1.8",
50
50
  "vitest": "^3.2.4"
@@ -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/component.ts CHANGED
@@ -194,13 +194,14 @@ export type ComponentInputOptionsToSpec<T extends ComponentInputOptions> = T ext
194
194
  export type ComponentOutputOptionsToSpec<
195
195
  TOutput extends ComponentOutputOptions<TInputs>,
196
196
  TInputs extends Record<string, ComponentInputOptions>,
197
- > = TOutput extends FromInputComponentOutputOptions<infer TInputName>
198
- ? TInputName extends keyof TInputs
199
- ? ComponentInputOptionsToSpec<TInputs[TInputName]>
200
- : never
201
- : TOutput extends ComponentInputOptions
202
- ? ComponentInputOptionsToSpec<TOutput>
203
- : never
197
+ > =
198
+ TOutput extends FromInputComponentOutputOptions<infer TInputName>
199
+ ? TInputName extends keyof TInputs
200
+ ? ComponentInputOptionsToSpec<TInputs[TInputName]>
201
+ : never
202
+ : TOutput extends ComponentInputOptions
203
+ ? ComponentInputOptionsToSpec<TOutput>
204
+ : never
204
205
 
205
206
  export type ComponentInputOptionsMapToSpecMap<T extends Record<string, ComponentInputOptions>> =
206
207
  T extends Record<string, never>
@@ -221,9 +222,10 @@ type ComponentOutputMapToCreateOutputValue<
221
222
  type ComponentOutputMapToReturnType<
222
223
  TOutputs extends Record<string, ComponentOutputOptions<TInputs>>,
223
224
  TInputs extends Record<string, ComponentInputOptions>,
224
- > = TOutputs extends Record<string, never> // biome-ignore lint/suspicious/noConfusingVoidType: this is return type
225
- ? void
226
- : Partial<ComponentOutputMapToCreateOutputValue<TOutputs, TInputs>>
225
+ > =
226
+ TOutputs extends Record<string, never> // biome-ignore lint/suspicious/noConfusingVoidType: this is return type
227
+ ? void
228
+ : Partial<ComponentOutputMapToCreateOutputValue<TOutputs, TInputs>>
227
229
 
228
230
  export type ComponentParams<
229
231
  TArgs extends Record<string, ComponentArgumentOptions>,
@@ -397,13 +399,14 @@ export type InputSpecMapToInputRefMap<TInputs extends Record<string, ComponentIn
397
399
  export type OutputRefMap<
398
400
  TInputs extends Record<string, ComponentInputSpec>,
399
401
  TKind extends ComponentKind = "composite",
400
- > = TInputs extends Record<string, [string, never, never]>
401
- ? Record<string, never>
402
- : {
403
- [K in keyof TInputs]: TKind extends "unit"
404
- ? InputSpecToUnitOutputRef<TInputs[K]>
405
- : InputSpecToCompositeOutputRef<TInputs[K]>
406
- }
402
+ > =
403
+ TInputs extends Record<string, [string, never, never]>
404
+ ? Record<string, never>
405
+ : {
406
+ [K in keyof TInputs]: TKind extends "unit"
407
+ ? InputSpecToUnitOutputRef<TInputs[K]>
408
+ : InputSpecToCompositeOutputRef<TInputs[K]>
409
+ }
407
410
 
408
411
  type StaticOutputRefByKind<
409
412
  TOutputSpec extends ComponentInputSpec,
@@ -426,9 +429,10 @@ type ResolveOutputRefForCall<
426
429
  TCallInputs extends Record<string, unknown>,
427
430
  TFallbackSpec extends ComponentInputSpec,
428
431
  TKind extends ComponentKind,
429
- > = TOutputOption extends FromInputComponentOutputOptions<infer TInputName>
430
- ? ResolveForwardedOutputRef<TInputName, TCallInputs, TFallbackSpec, TKind>
431
- : StaticOutputRefByKind<TFallbackSpec, TKind>
432
+ > =
433
+ TOutputOption extends FromInputComponentOutputOptions<infer TInputName>
434
+ ? ResolveForwardedOutputRef<TInputName, TCallInputs, TFallbackSpec, TKind>
435
+ : StaticOutputRefByKind<TFallbackSpec, TKind>
432
436
 
433
437
  type ResolveOutputRefMapForCall<
434
438
  TOutputSpecs extends Record<string, ComponentInputSpec>,
@@ -449,11 +453,12 @@ type IncludesAllExpectedTypes<
449
453
  TExpected extends Record<string, unknown>,
450
454
  > = Exclude<keyof TExpected, keyof TProvided> extends never ? true : false
451
455
 
452
- type ExtractProvidedInputTypes<TValue> = TValue extends RuntimeInput<infer TTypes, any>
453
- ? TTypes
454
- : TValue extends Array<infer TItem>
455
- ? ExtractProvidedInputTypes<TItem>
456
- : never
456
+ type ExtractProvidedInputTypes<TValue> =
457
+ TValue extends RuntimeInput<infer TTypes, any>
458
+ ? TTypes
459
+ : TValue extends Array<infer TItem>
460
+ ? ExtractProvidedInputTypes<TItem>
461
+ : never
457
462
 
458
463
  type ValidateProvidedInputValue<TValue, TExpectedSpec extends ComponentInputSpec> = [
459
464
  ExtractProvidedInputTypes<TValue>,
package/src/entity.ts CHANGED
@@ -177,23 +177,25 @@ type IsIncludeRequired<TIncludeRef> = TIncludeRef extends { required?: infer R }
177
177
  : true
178
178
  : true
179
179
 
180
- type IsOptionalOutputInclude<TIncludeRef> = IsIncludeMultiple<TIncludeRef> extends true
181
- ? false
182
- : IsIncludeRequired<TIncludeRef> extends false
183
- ? true
184
- : false
180
+ type IsOptionalOutputInclude<TIncludeRef> =
181
+ IsIncludeMultiple<TIncludeRef> extends true
182
+ ? false
183
+ : IsIncludeRequired<TIncludeRef> extends false
184
+ ? true
185
+ : false
185
186
 
186
- type IsOptionalInputInclude<TIncludeRef> = IsIncludeRequired<TIncludeRef> extends false
187
- ? true
188
- : false
187
+ type IsOptionalInputInclude<TIncludeRef> =
188
+ IsIncludeRequired<TIncludeRef> extends false ? true : false
189
189
 
190
- type IncludeOutputValue<TIncludeRef> = IsIncludeMultiple<TIncludeRef> extends true
191
- ? EntityValue<ResolveIncludeEntity<TIncludeRef>>[]
192
- : EntityValue<ResolveIncludeEntity<TIncludeRef>>
190
+ type IncludeOutputValue<TIncludeRef> =
191
+ IsIncludeMultiple<TIncludeRef> extends true
192
+ ? EntityValue<ResolveIncludeEntity<TIncludeRef>>[]
193
+ : EntityValue<ResolveIncludeEntity<TIncludeRef>>
193
194
 
194
- type IncludeInputValue<TIncludeRef> = IsIncludeMultiple<TIncludeRef> extends true
195
- ? EntityValueInput<ResolveIncludeEntity<TIncludeRef>>[]
196
- : EntityValueInput<ResolveIncludeEntity<TIncludeRef>>
195
+ type IncludeInputValue<TIncludeRef> =
196
+ IsIncludeMultiple<TIncludeRef> extends true
197
+ ? EntityValueInput<ResolveIncludeEntity<TIncludeRef>>[]
198
+ : EntityValueInput<ResolveIncludeEntity<TIncludeRef>>
197
199
 
198
200
  type InclusionValueShape<TIncludes extends Record<string, EntityIncludeRef>> =
199
201
  TIncludes extends Record<string, never>
@@ -330,58 +332,58 @@ type InclusionShape<TImplements extends Record<string, EntityIncludeRef>> = {
330
332
  : never
331
333
  }
332
334
 
333
- type AddSchemaExtensions<
334
- TSchema extends z.ZodTypeAny,
335
- TExtends extends Record<string, Entity>,
336
- > = TExtends extends Record<string, never>
337
- ? TSchema
338
- : IsEmptyObject<TExtends> extends true
335
+ type AddSchemaExtensions<TSchema extends z.ZodTypeAny, TExtends extends Record<string, Entity>> =
336
+ TExtends extends Record<string, never>
339
337
  ? TSchema
340
- : {
341
- [K in keyof TExtends]: AddSchemaExtensions<
342
- z.ZodIntersection<TSchema, TExtends[K]["schema"]>,
343
- Omit<TExtends, K>
344
- >
345
- }[keyof TExtends]
338
+ : IsEmptyObject<TExtends> extends true
339
+ ? TSchema
340
+ : {
341
+ [K in keyof TExtends]: AddSchemaExtensions<
342
+ z.ZodIntersection<TSchema, TExtends[K]["schema"]>,
343
+ Omit<TExtends, K>
344
+ >
345
+ }[keyof TExtends]
346
346
 
347
347
  type AddTypeExtensions<
348
348
  TImplementedTypes extends EntityTypes,
349
349
  TExtends extends Record<string, Entity>,
350
- > = TExtends extends Record<string, never>
351
- ? TImplementedTypes
352
- : IsEmptyObject<TExtends> extends true
350
+ > =
351
+ TExtends extends Record<string, never>
353
352
  ? TImplementedTypes
354
- : {
355
- [K in keyof TExtends]: AddTypeExtensions<
356
- TImplementedTypes & TExtends[K][typeof implementedTypes],
357
- Omit<TExtends, K>
358
- >
359
- }[keyof TExtends]
353
+ : IsEmptyObject<TExtends> extends true
354
+ ? TImplementedTypes
355
+ : {
356
+ [K in keyof TExtends]: AddTypeExtensions<
357
+ TImplementedTypes & TExtends[K][typeof implementedTypes],
358
+ Omit<TExtends, K>
359
+ >
360
+ }[keyof TExtends]
360
361
 
361
362
  type AddIncludeExtensions<
362
363
  TIncludes extends Record<string, EntityIncludeRef>,
363
364
  TExtends extends Record<string, Entity>,
364
- > = TExtends extends Record<string, never>
365
- ? TIncludes
366
- : IsEmptyObject<TExtends> extends true
365
+ > =
366
+ TExtends extends Record<string, never>
367
367
  ? TIncludes
368
- : {
369
- [K in keyof TExtends]: AddIncludeExtensions<
370
- TIncludes & ExtractEntityIncludes<TExtends[K][typeof entityIncludes]>,
371
- Omit<TExtends, K>
372
- >
373
- }[keyof TExtends]
374
-
375
- type ExtractEntityIncludes<T> = T extends Record<string, EntityIncludeRef>
376
- ? T
377
- : Record<string, never>
368
+ : IsEmptyObject<TExtends> extends true
369
+ ? TIncludes
370
+ : {
371
+ [K in keyof TExtends]: AddIncludeExtensions<
372
+ TIncludes & ExtractEntityIncludes<TExtends[K][typeof entityIncludes]>,
373
+ Omit<TExtends, K>
374
+ >
375
+ }[keyof TExtends]
376
+
377
+ type ExtractEntityIncludes<T> =
378
+ T extends Record<string, EntityIncludeRef> ? T : Record<string, never>
378
379
 
379
380
  type AddSchemaInclusions<
380
381
  TSchema extends z.ZodTypeAny,
381
382
  TImplements extends Record<string, EntityIncludeRef>,
382
- > = TImplements extends Record<string, never>
383
- ? TSchema
384
- : z.ZodIntersection<TSchema, z.ZodObject<InclusionShape<TImplements>>>
383
+ > =
384
+ TImplements extends Record<string, never>
385
+ ? TSchema
386
+ : z.ZodIntersection<TSchema, z.ZodObject<InclusionShape<TImplements>>>
385
387
 
386
388
  /**
387
389
  * The common ancestor of all entities. Any entity can be assigned to this entity.
@@ -515,6 +517,21 @@ export function defineEntity<
515
517
 
516
518
  finalSchema = z.intersection(finalSchema, strictIntersectionBase(entityWithMetaSchema))
517
519
 
520
+ const optionalMultipleInclusions = includeRefs.filter(
521
+ includeRef => includeRef.multiple && !includeRef.required,
522
+ )
523
+ if (optionalMultipleInclusions.length > 0) {
524
+ finalSchema = finalSchema.overwrite(value => {
525
+ const record = value as Record<string, unknown>
526
+
527
+ for (const inclusion of optionalMultipleInclusions) {
528
+ record[inclusion.field] ??= []
529
+ }
530
+
531
+ return value
532
+ })
533
+ }
534
+
518
535
  const directInclusions = () =>
519
536
  includeRefs.map(includeRef => ({
520
537
  type: includeRef.getEntity().type,
package/src/instance.ts CHANGED
@@ -86,19 +86,20 @@ export type RequiredMultipleInput<TInput extends RuntimeInput = RuntimeInput> =
86
86
  export type RequiredMultipleInputs<TInput extends RuntimeInput = RuntimeInput> =
87
87
  RequiredMultipleInput<TInput>
88
88
 
89
- export type EntityInput<TEntity extends Entity> = TEntity extends Entity<
90
- VersionedName,
91
- infer TImplementedTypes,
92
- z.ZodTypeAny,
93
- unknown,
94
- unknown,
95
- infer TIncludes
96
- >
97
- ? RuntimeInput<TImplementedTypes, undefined> &
98
- (TIncludes extends Record<string, EntityIncludeRef>
99
- ? EntityInputIncludes<TIncludes>
100
- : Record<never, never>)
101
- : never
89
+ export type EntityInput<TEntity extends Entity> =
90
+ TEntity extends Entity<
91
+ VersionedName,
92
+ infer TImplementedTypes,
93
+ z.ZodTypeAny,
94
+ unknown,
95
+ unknown,
96
+ infer TIncludes
97
+ >
98
+ ? RuntimeInput<TImplementedTypes, undefined> &
99
+ (TIncludes extends Record<string, EntityIncludeRef>
100
+ ? EntityInputIncludes<TIncludes>
101
+ : Record<never, never>)
102
+ : never
102
103
 
103
104
  export type RequiredEntityInput<TEntity extends Entity> = RequiredInput<EntityInput<TEntity>>
104
105
 
@@ -126,34 +127,32 @@ type IncludeRequired<TIncludeRef> = TIncludeRef extends { required?: infer R }
126
127
  : true
127
128
  : true
128
129
 
129
- type IncludeRefValue<
130
- TIncludeRef,
131
- TDepth extends readonly unknown[],
132
- > = ResolveIncludeEntity<TIncludeRef> extends infer TEntity
133
- ? TEntity extends Entity
134
- ? IncludeMultiple<TIncludeRef> extends true
135
- ? MultipleInput<
136
- EntityInputWithDepth<TEntity, TDepth>,
137
- TDepth extends readonly []
138
- ? Record<never, never>
139
- : TEntity extends Entity<
140
- VersionedName,
141
- EntityTypes,
142
- z.ZodTypeAny,
143
- unknown,
144
- unknown,
145
- infer TIncludes
146
- >
147
- ? TIncludes extends Record<string, EntityIncludeRef>
148
- ? LiftMultipleSelectorFields<EntityInputIncludes<TIncludes, DecDepth<TDepth>>>
130
+ type IncludeRefValue<TIncludeRef, TDepth extends readonly unknown[]> =
131
+ ResolveIncludeEntity<TIncludeRef> extends infer TEntity
132
+ ? TEntity extends Entity
133
+ ? IncludeMultiple<TIncludeRef> extends true
134
+ ? MultipleInput<
135
+ EntityInputWithDepth<TEntity, TDepth>,
136
+ TDepth extends readonly []
137
+ ? Record<never, never>
138
+ : TEntity extends Entity<
139
+ VersionedName,
140
+ EntityTypes,
141
+ z.ZodTypeAny,
142
+ unknown,
143
+ unknown,
144
+ infer TIncludes
145
+ >
146
+ ? TIncludes extends Record<string, EntityIncludeRef>
147
+ ? LiftMultipleSelectorFields<EntityInputIncludes<TIncludes, DecDepth<TDepth>>>
148
+ : Record<never, never>
149
149
  : Record<never, never>
150
- : Record<never, never>
151
- >
152
- : IncludeRequired<TIncludeRef> extends false
153
- ? OptionalEntityInput<TEntity, TDepth>
154
- : EntityInputWithDepth<TEntity, TDepth>
150
+ >
151
+ : IncludeRequired<TIncludeRef> extends false
152
+ ? OptionalEntityInput<TEntity, TDepth>
153
+ : EntityInputWithDepth<TEntity, TDepth>
154
+ : never
155
155
  : never
156
- : never
157
156
 
158
157
  type OptionalEntityInput<TEntity extends Entity, TDepth extends readonly unknown[]> =
159
158
  | ({ provided: true } & EntityInputWithDepth<TEntity, TDepth>)
@@ -185,11 +184,12 @@ type RuntimeInputSelectorFields<TInput extends RuntimeInput> = {
185
184
  : K]: LiftMultipleSelectorValue<TInput[K]>
186
185
  }
187
186
 
188
- type LiftMultipleSelectorValue<T> = T extends MultipleInput<infer TItem, infer TSelectors>
189
- ? MultipleInput<TItem, LiftMultipleSelectorFields<TSelectors>>
190
- : T extends RuntimeInput
191
- ? MultipleInput<T, RuntimeInputSelectorFields<T>>
192
- : T
187
+ type LiftMultipleSelectorValue<T> =
188
+ T extends MultipleInput<infer TItem, infer TSelectors>
189
+ ? MultipleInput<TItem, LiftMultipleSelectorFields<TSelectors>>
190
+ : T extends RuntimeInput
191
+ ? MultipleInput<T, RuntimeInputSelectorFields<T>>
192
+ : T
193
193
 
194
194
  type LiftMultipleSelectorFields<TSelectors extends Record<string, unknown>> = {
195
195
  [K in keyof TSelectors]: LiftMultipleSelectorValue<TSelectors[K]>
@@ -201,43 +201,41 @@ type OptionalizedInputFields<TInput extends RuntimeInput> = {
201
201
  : K]: OptionalizeInputValue<TInput[K]>
202
202
  }
203
203
 
204
- type EntityInputWithDepth<
205
- TEntity extends Entity,
206
- TDepth extends readonly unknown[],
207
- > = TEntity extends Entity<
208
- VersionedName,
209
- infer TImplementedTypes,
210
- z.ZodTypeAny,
211
- unknown,
212
- unknown,
213
- infer TIncludes
214
- >
215
- ? RuntimeInput<TImplementedTypes, undefined> &
216
- (TDepth extends readonly []
217
- ? Record<never, never>
218
- : TIncludes extends Record<string, EntityIncludeRef>
219
- ? EntityInputIncludes<TIncludes, DecDepth<TDepth>>
220
- : Record<never, never>)
221
- : never
204
+ type EntityInputWithDepth<TEntity extends Entity, TDepth extends readonly unknown[]> =
205
+ TEntity extends Entity<
206
+ VersionedName,
207
+ infer TImplementedTypes,
208
+ z.ZodTypeAny,
209
+ unknown,
210
+ unknown,
211
+ infer TIncludes
212
+ >
213
+ ? RuntimeInput<TImplementedTypes, undefined> &
214
+ (TDepth extends readonly []
215
+ ? Record<never, never>
216
+ : TIncludes extends Record<string, EntityIncludeRef>
217
+ ? EntityInputIncludes<TIncludes, DecDepth<TDepth>>
218
+ : Record<never, never>)
219
+ : never
222
220
 
223
221
  type EntityInputIncludes<
224
222
  TIncludes extends Record<string, EntityIncludeRef>,
225
223
  TDepth extends readonly unknown[] = EntityInputDepth,
226
- > = TIncludes extends Record<string, never>
227
- ? Record<never, never>
228
- : string extends keyof TIncludes
224
+ > =
225
+ TIncludes extends Record<string, never>
229
226
  ? Record<never, never>
230
- : {
231
- [K in keyof TIncludes]: IncludeRefValue<TIncludes[K], TDepth>
232
- }
227
+ : string extends keyof TIncludes
228
+ ? Record<never, never>
229
+ : {
230
+ [K in keyof TIncludes]: IncludeRefValue<TIncludes[K], TDepth>
231
+ }
233
232
 
234
233
  export type InstanceInputGroup<TTypes extends EntityTypes = EntityTypes> = MultipleInput<
235
234
  RuntimeInput<TTypes>
236
235
  >
237
236
 
238
- type SelectInputResult<TInput extends RuntimeInput> = TInput extends RequiredInput<infer TRuntime>
239
- ? TRuntime
240
- : TInput
237
+ type SelectInputResult<TInput extends RuntimeInput> =
238
+ TInput extends RequiredInput<infer TRuntime> ? TRuntime : TInput
241
239
 
242
240
  export const positionSchema = z.object({
243
241
  x: z.number(),
@@ -295,7 +293,7 @@ export const instanceModelPatchSchema = z.object({
295
293
  *
296
294
  * Only for designer-first instances.
297
295
  */
298
- position: positionSchema.optional(),
296
+ position: positionSchema.partial().nullable().optional(),
299
297
  })
300
298
 
301
299
  export const instanceModelSchema = z.object({
@@ -327,6 +325,8 @@ export const instanceModelSchema = z.object({
327
325
 
328
326
  ...instanceModelPatchSchema.shape,
329
327
 
328
+ position: positionSchema.optional(),
329
+
330
330
  /**
331
331
  * The id of the top level parent instance.
332
332
  *
@@ -362,7 +362,7 @@ export const hubModelPatchSchema = z.object({
362
362
  /**
363
363
  * The position of the hub on the canvas.
364
364
  */
365
- position: positionSchema.optional(),
365
+ position: positionSchema.partial().nullable().optional(),
366
366
 
367
367
  /**
368
368
  * The inputs of the hub.
@@ -385,6 +385,8 @@ export const hubModelSchema = z.object({
385
385
  id: z.cuid2(),
386
386
 
387
387
  ...hubModelPatchSchema.shape,
388
+
389
+ position: positionSchema.optional(),
388
390
  })
389
391
 
390
392
  export type InstanceModelPatch = z.infer<typeof instanceModelPatchSchema>
@@ -439,7 +441,7 @@ export function selectInput<TInput extends RuntimeInput>(
439
441
  (input.instanceId === name || parseInstanceId(input.instanceId)[1] === name),
440
442
  )
441
443
 
442
- if (!input || !input.provided) {
444
+ if (!input?.provided) {
443
445
  const fallbackBoundary =
444
446
  groupBoundary ??
445
447
  inputs.find(input => Boolean(input[boundaryInput]))?.[boundaryInput] ??
package/src/utils.ts CHANGED
@@ -1,29 +1,28 @@
1
1
  import type { z } from "zod"
2
2
  import { isNonNullish, pickBy } from "remeda"
3
3
 
4
- type PickUndefinedKeys<T extends Record<string, unknown>> = T extends Record<string, never>
5
- ? never
6
- : Exclude<
7
- {
8
- [K in keyof T]: undefined extends T[K] ? K : never
9
- }[keyof T],
10
- undefined
11
- >
12
-
13
- type AllOptionalKeys<T extends Record<string, unknown>> = T extends Record<string, never>
14
- ? never
15
- : Exclude<
16
- {
17
- [K in keyof T]: undefined extends T[K] ? K : never
18
- }[keyof T],
19
- undefined
20
- >
21
-
22
- type HasRequired<T extends Record<string, unknown>> = T extends Record<string, never>
23
- ? false
24
- : [keyof T] extends [AllOptionalKeys<T>]
25
- ? false
26
- : true
4
+ type PickUndefinedKeys<T extends Record<string, unknown>> =
5
+ T extends Record<string, never>
6
+ ? never
7
+ : Exclude<
8
+ {
9
+ [K in keyof T]: undefined extends T[K] ? K : never
10
+ }[keyof T],
11
+ undefined
12
+ >
13
+
14
+ type AllOptionalKeys<T extends Record<string, unknown>> =
15
+ T extends Record<string, never>
16
+ ? never
17
+ : Exclude<
18
+ {
19
+ [K in keyof T]: undefined extends T[K] ? K : never
20
+ }[keyof T],
21
+ undefined
22
+ >
23
+
24
+ type HasRequired<T extends Record<string, unknown>> =
25
+ T extends Record<string, never> ? false : [keyof T] extends [AllOptionalKeys<T>] ? false : true
27
26
 
28
27
  type PickRecordsWithAnyRequired<T extends Record<string, Record<string, unknown>>> =
29
28
  T extends Record<string, never>