MCPcopy Index your code
hub / github.com/Effect-TS/effect / extractMembers

Function extractMembers

packages/platform/src/HttpApi.ts:346–393  ·  view source on GitHub ↗
(
  ast: AST.AST,
  inherited: ReadonlyMap<number, {
    readonly ast: Option.Option<AST.AST>
    readonly description: Option.Option<string>
  }>,
  getStatus: (ast: AST.AST) => number
)

Source from the content-addressed store, hash-verified

344const emptyMap = new Map<never, never>()
345
346const extractMembers = (
347 ast: AST.AST,
348 inherited: ReadonlyMap<number, {
349 readonly ast: Option.Option<AST.AST>
350 readonly description: Option.Option<string>
351 }>,
352 getStatus: (ast: AST.AST) => number
353): ReadonlyMap<number, {
354 readonly ast: Option.Option<AST.AST>
355 readonly description: Option.Option<string>
356}> => {
357 const members = new Map(inherited)
358 function process(type: AST.AST) {
359 if (AST.isNeverKeyword(type)) {
360 return
361 }
362 const annotations = HttpApiSchema.extractAnnotations(ast.annotations)
363 // Avoid changing the reference unless necessary
364 // Otherwise, deduplication of the ASTs below will not be possible
365 if (!Record.isEmptyRecord(annotations)) {
366 type = AST.annotations(type, {
367 ...annotations,
368 ...type.annotations
369 })
370 }
371 const status = getStatus(type)
372 const emptyDecodeable = HttpApiSchema.getEmptyDecodeable(type)
373 const current = members.get(status)
374 members.set(
375 status,
376 {
377 description: (current ? current.description : Option.none()).pipe(
378 Option.orElse(() => getDescriptionOrIdentifier(type))
379 ),
380 ast: (current ? current.ast : Option.none()).pipe(
381 // Deduplicate the ASTs
382 Option.map((current) => HttpApiSchema.UnionUnifyAST(current, type)),
383 Option.orElse(() =>
384 !emptyDecodeable && AST.isVoidKeyword(AST.encodedAST(type)) ? Option.none() : Option.some(type)
385 )
386 )
387 }
388 )
389 }
390
391 HttpApiSchema.extractUnionTypes(ast).forEach(process)
392 return members
393}
394
395const extractPayloads = (topAst: AST.AST): ReadonlyMap<string, {
396 readonly encoding: HttpApiSchema.Encoding

Callers 1

reflectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected