@highstate/contract 0.16.0 → 0.18.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/src/unit.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  /** biome-ignore-all lint/suspicious/noExplicitAny: maybe fix later */
2
2
 
3
3
  import type { InstanceInput } from "./instance"
4
+ import type { VersionedName } from "./meta"
4
5
  import { mapValues } from "remeda"
5
- import z from "zod"
6
+ import { z } from "zod"
6
7
  import {
7
8
  type Component,
8
9
  type ComponentArgumentOptions,
@@ -44,11 +45,12 @@ export type FullComponentSecretOptions = FullComponentArgumentOptions & {
44
45
  export type ComponentSecretOptions = z.ZodType | FullComponentSecretOptions
45
46
 
46
47
  type UnitOptions<
48
+ TType extends VersionedName,
47
49
  TArgs extends Record<string, ComponentArgumentOptions>,
48
50
  TInputs extends Record<string, ComponentInputOptions>,
49
51
  TOutputs extends Record<string, ComponentInputOptions>,
50
52
  TSecrets extends Record<string, ComponentSecretOptions>,
51
- > = Omit<ComponentOptions<TArgs, TInputs, TOutputs>, "create"> & {
53
+ > = Omit<ComponentOptions<TType, TArgs, TInputs, TOutputs>, "create"> & {
52
54
  source: UnitSource
53
55
 
54
56
  secrets?: TSecrets
@@ -87,14 +89,15 @@ export const unitModelSchema = z.object({
87
89
  export type UnitModel = z.infer<typeof unitModelSchema>
88
90
  export type UnitSource = z.infer<typeof unitSourceSchema>
89
91
 
90
- const secrets = Symbol("secrets")
92
+ declare const secrets: unique symbol
91
93
 
92
94
  export type Unit<
95
+ TType extends VersionedName = VersionedName,
93
96
  TArgs extends Record<string, z.ZodType> = Record<string, never>,
94
97
  TInputs extends Record<string, ComponentInputSpec> = Record<string, never>,
95
98
  TOutputs extends Record<string, ComponentInputSpec> = Record<string, never>,
96
99
  TSecrets extends Record<string, unknown> = Record<string, never>,
97
- > = Component<TArgs, TInputs, TOutputs> & {
100
+ > = Component<TType, TArgs, TInputs, TOutputs> & {
98
101
  /**
99
102
  * Holds the type of the unit secrets.
100
103
  *
@@ -109,13 +112,15 @@ export type Unit<
109
112
  }
110
113
 
111
114
  export function defineUnit<
115
+ TType extends VersionedName = VersionedName,
112
116
  TArgs extends Record<string, ComponentArgumentOptions> = Record<string, never>,
113
117
  TInputs extends Record<string, ComponentInputOptions> = Record<string, never>,
114
118
  TOutputs extends Record<string, ComponentInputOptions> = Record<string, never>,
115
119
  TSecrets extends Record<string, ComponentSecretOptions> = Record<string, never>,
116
120
  >(
117
- options: UnitOptions<TArgs, TInputs, TOutputs, TSecrets>,
121
+ options: UnitOptions<TType, TArgs, TInputs, TOutputs, TSecrets>,
118
122
  ): Unit<
123
+ TType,
119
124
  { [K in keyof TArgs]: ComponentArgumentOptionsToSchema<TArgs[K]> },
120
125
  { [K in keyof TInputs]: ComponentInputOptionsToSpec<TInputs[K]> },
121
126
  { [K in keyof TOutputs]: ComponentInputOptionsToSpec<TOutputs[K]> },
@@ -125,7 +130,7 @@ export function defineUnit<
125
130
  throw new Error("Unit source is required")
126
131
  }
127
132
 
128
- const component = defineComponent<TArgs, TInputs, TOutputs>({
133
+ const component = defineComponent<TType, TArgs, TInputs, TOutputs>({
129
134
  ...options,
130
135
  [kind]: "unit",
131
136
 
package/src/utils.ts CHANGED
@@ -133,7 +133,7 @@ export function bytesToHumanReadable(bytes: number): string {
133
133
  export function check<TSchema extends z.ZodType>(
134
134
  schema: TSchema,
135
135
  value: unknown,
136
- ): value is z.input<TSchema> {
136
+ ): value is z.infer<TSchema> {
137
137
  return schema.safeParse(value).success
138
138
  }
139
139