Skip to content

Commit 0074b54

Browse files
committed
v0breaking: refactored *Passthrough to *Loose
1 parent 948de3e commit 0074b54

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ export {}
4242

4343
```
4444

45-
Or if using zod, you can do something like this. Note that you will need to create/extend `zLayoutWindow/Frame` or use `zLayoutWindow/FramePassthrough` to allow for extra properties. All zod types have been made `strict` where possible as it's easy to accidentally use the wrong type and loose properties silently otherwise.
45+
Or if using zod, you can do something like this. Note that you will need to create/extend `zLayoutWindow/Frame` or use `zLayoutWindow/FrameLoose` to allow for extra properties. All zod types have been made `strict` where possible as it's easy to accidentally use the wrong type and loose properties silently otherwise.
4646

4747
```ts
48-
import { zLayoutFramePassthrough, layoutCreate } from "@witchcraft/layout"
48+
import { zLayoutFrameLoose, layoutCreate } from "@witchcraft/layout"
4949
import { z } from "zod"
5050

5151
// we remove the id to set the discriminated union, then add it back,
5252
// otherwise this doesn't work
5353
export const zAppFrame = z.discriminatedUnion("type", [
54-
zLayoutFramePassthrough.extend({
54+
zLayoutFrameLoose.extend({
5555
type: z.literal("contentA"),
5656
content: z.object({
5757
id: z.optional(z.uuid()),
5858
}),
5959
}),
60-
zLayoutFramePassthrough.extend({
60+
zLayoutFrameLoose.extend({
6161
type: z.literal("contentB"),
6262
content: z.object({
6363
someOtherKey: z.optional(z.uuid()),

src/runtime/types/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const zLayoutFrame = z.looseObject({
113113
id: z.uuid()
114114
}).extend(zBaseSquare.shape)
115115

116-
export const zLayoutFramePassthrough = zLayoutFrame.passthrough()
116+
export const zLayoutFrameLoose = zLayoutFrame.loose()
117117

118118
export interface Register {
119119
}
@@ -135,8 +135,8 @@ const baseLayoutWindow = z.object({
135135
}).extend(zPxSize.shape)
136136
.extend(zPxPos.shape)
137137

138-
export const zLayoutWindow = baseLayoutWindow.strict()
139-
export const zLayoutWindowPassthrough = baseLayoutWindow
138+
export const zLayoutWindow = baseLayoutWindow
139+
export const zLayoutWindowLoose = baseLayoutWindow.loose()
140140
// types are re-declared so that if they are extended, the types are still correct
141141

142142
export type BaseLayoutWindow = {
@@ -153,16 +153,16 @@ export type LayoutWindows = Record<string, LayoutWindow>
153153

154154
const baseWorkspace = zLayoutWindow.pick({ activeFrame: true, frames: true })
155155
export const zWorkspace = baseWorkspace.strict()
156-
export const zWorkspacePassthrough = zWorkspace.passthrough()
156+
export const zWorkspaceLoose = zWorkspace.loose()
157157

158158
export type Workspace = Pick<LayoutWindow, "activeFrame" | "frames"> & ExtendedWorkspace
159159

160-
const baseLayout = z.looseObject({
160+
const baseLayout = z.object({
161161
activeWindow: z.string().optional(),
162162
windows: z.record(z.string(), zLayoutWindow)
163163
})
164164

165-
export const zLayout = baseLayout.strict()
165+
export const zLayout = baseLayout
166166

167167
export const zInitializedLayout = zLayout.required({
168168
activeWindow: true
@@ -275,11 +275,11 @@ type AllErrorsInfo = {
275275
// todo rename to toOpposite
276276
export type HasOpposite = Direction | EdgeSide | ExtendedDirection | ExtendedEdgeSide | keyof Point | keyof Size
277277

278-
export const zWindowCreate = zLayoutWindowPassthrough
278+
export const zWindowCreate = zLayoutWindowLoose
279279
.partial({ id: true, pxWidth: true, pxHeight: true, pxX: true, pxY: true })
280280
.extend({ frames: zLayoutWindow.shape.frames.optional() })
281281

282-
export const zLayoutCreate = baseLayout
282+
export const zLayoutCreate = baseLayout.loose()
283283
.extend({
284284
windows: zLayout.shape.windows.optional()
285285
})

0 commit comments

Comments
 (0)