MCPcopy Create free account
hub / github.com/effect-app/libs / Struct

Function Struct

packages/effect-app/src/Schema.ts:151–209  ·  view source on GitHub ↗
(
  fields: Fields
)

Source from the content-addressed store, hash-verified

149// ---------------------------------------------------------------------------
150
151export function Struct<const Fields extends S.Struct.Fields>(
152 fields: Fields
153): Struct<Fields> {
154 const result = S.Struct(fields).annotate(concurrencyUnbounded)
155 const allowVoidMake = (schema: any): any => {
156 // Normalize omitted input to an empty object so optional/default-only structs can be constructed with make().
157 const origMake: any = schema.make
158 const origMakeOption: any = schema.makeOption
159 const origMakeEffect: any = schema.makeEffect
160 schema.make = function(this: any, input: any, options?: any) {
161 return origMake.call(this, input === undefined ? {} : input, options)
162 }
163 schema.makeOption = function(this: any, input: any, options?: any) {
164 return origMakeOption.call(this, input === undefined ? {} : input, options)
165 }
166 schema.makeEffect = function(this: any, input: any, options?: any) {
167 return origMakeEffect.call(this, input === undefined ? {} : input, options)
168 }
169 return schema
170 }
171 // eslint-disable-next-line @typescript-eslint/unbound-method, @typescript-eslint/no-unsafe-assignment
172 const origMapFields: any = result.mapFields
173 // eslint-disable-next-line @typescript-eslint/unbound-method, @typescript-eslint/no-unsafe-assignment
174 const origAnnotate: any = result.annotate
175 // eslint-disable-next-line @typescript-eslint/unbound-method, @typescript-eslint/no-unsafe-assignment
176 const origAnnotateKey: any = result.annotateKey
177
178 const preserveCopyAndMethods = (schema: any): any => {
179 schema.copy = copy
180 schema.mapFields = function(this: any, f: any, options?: any) {
181 return (result as any).mapFields.call(this, f, options)
182 }
183 schema.annotate = function(this: any, annotations?: any) {
184 return (result as any).annotate.call(this, annotations)
185 }
186 schema.annotateKey = function(this: any, annotations?: any) {
187 return (result as any).annotateKey.call(this, annotations)
188 }
189 return allowVoidMake(schema)
190 }
191 ;(result as any).mapFields = function(this: any, f: any, options?: any) {
192 // eslint-disable-next-line @typescript-eslint/no-unsafe-call
193 const mapped = origMapFields.call(this, f, options).annotate(concurrencyUnbounded)
194 return preserveCopyAndMethods(mapped)
195 }
196 ;(result as any).annotate = function(this: any, annotations?: any) {
197 // eslint-disable-next-line @typescript-eslint/no-unsafe-call
198 const annotated = origAnnotate.call(this, annotations)
199 return preserveCopyAndMethods(annotated)
200 }
201 ;(result as any).annotateKey = function(this: any, annotations?: any) {
202 // eslint-disable-next-line @typescript-eslint/no-unsafe-call
203 const annotated = origAnnotateKey.call(this, annotations)
204 return preserveCopyAndMethods(annotated)
205 }
206 ;(result as any).copy = copy
207 allowVoidMake(result)
208 return result as Struct<Fields>

Callers 1

TaggedStructFunction · 0.70

Calls 3

preserveCopyAndMethodsFunction · 0.85
allowVoidMakeFunction · 0.85
annotateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…