• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / storage / 25738155938

12 May 2026 01:38PM UTC coverage: 39.251% (-35.1%) from 74.366%
25738155938

Pull #1094

github

web-flow
Merge 0f3efcca0 into defbbb616
Pull Request #1094: feat: embedded vector store

2188 of 6152 branches covered (35.57%)

Branch coverage included in aggregate %.

88 of 280 new or added lines in 6 files covered. (31.43%)

3689 existing lines in 165 files now uncovered.

4312 of 10408 relevant lines covered (41.43%)

34.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.21
/src/http/plugins/xml.ts
1
import accepts from '@fastify/accepts'
2
import { ERRORS } from '@internal/errors'
3
import { FastifyInstance } from 'fastify'
4
import fastifyPlugin from 'fastify-plugin'
5
import xml from 'xml2js'
6

7
type XmlParserOptions = { disableContentParser?: boolean; parseAsArray?: string[] }
8
type RequestError = Error & { statusCode?: number }
9

10
function forcePathAsArray(node: unknown, pathSegments: string[]): void {
11
  if (pathSegments.length === 0 || node === null || node === undefined) {
2!
12
    return
×
13
  }
14

15
  if (Array.isArray(node)) {
2!
16
    node.forEach((item) => forcePathAsArray(item, pathSegments))
×
17
    return
×
18
  }
19

20
  if (typeof node !== 'object') {
2!
21
    return
×
22
  }
23

24
  const [current, ...rest] = pathSegments
2✔
25
  const currentRecord = node as Record<string, unknown>
2✔
26

27
  if (!(current in currentRecord)) {
2!
28
    return
×
29
  }
30

31
  if (rest.length === 0) {
2✔
32
    const value = currentRecord[current]
1✔
33
    if (value !== undefined && !Array.isArray(value)) {
1!
34
      currentRecord[current] = [value]
1✔
35
    }
36
    return
1✔
37
  }
38

39
  forcePathAsArray(currentRecord[current], rest)
1✔
40
}
41

42
export const xmlParser = fastifyPlugin(
4✔
43
  async function (fastify: FastifyInstance, opts: XmlParserOptions) {
44
    fastify.register(accepts)
3✔
45

46
    if (!opts.disableContentParser) {
3!
47
      fastify.addContentTypeParser(
3✔
48
        ['text/xml', 'application/xml'],
49
        { parseAs: 'string' },
50
        (_request, body, done) => {
51
          if (!body) {
2!
UNCOV
52
            done(null, null)
×
UNCOV
53
            return
×
54
          }
55

56
          xml.parseString(
2✔
57
            body,
58
            {
59
              explicitArray: false,
60
              trim: true,
61
              valueProcessors: [xml.processors.parseNumbers, xml.processors.parseBooleans],
62
            },
63
            (err: Error | null, parsed: unknown) => {
64
              if (err) {
2✔
65
                const parseError: RequestError = ERRORS.InvalidRequest(
1✔
66
                  `Invalid XML payload: ${err.message}`
67
                )
68
                parseError.statusCode = 400
1✔
69
                done(parseError)
1✔
70
                return
1✔
71
              }
72

73
              if (parsed && opts.parseAsArray?.length) {
1!
74
                opts.parseAsArray.forEach((path) => {
1✔
75
                  if (!path) {
1!
76
                    return
×
77
                  }
78
                  forcePathAsArray(parsed, path.split('.'))
1✔
79
                })
80
              }
81

82
              done(null, parsed)
1✔
83
            }
84
          )
85
        }
86
      )
87
    }
88

89
    fastify.addHook('preSerialization', async (req, res, payload) => {
3✔
90
      const accept = req.accepts()
2✔
91

92
      const acceptedTypes = ['application/xml', 'text/html']
2✔
93

94
      if (acceptedTypes.some((allowed) => accept.types(acceptedTypes) === allowed)) {
3✔
95
        res.serializer((payload) => payload)
1✔
96

97
        const xmlBuilder = new xml.Builder({
1✔
98
          renderOpts: {
99
            pretty: false,
100
          },
101
        })
102
        const xmlPayload = xmlBuilder.buildObject(payload)
1✔
103
        res.type('application/xml')
1✔
104
        res.header('content-type', 'application/xml; charset=utf-8')
1✔
105
        return xmlPayload
1✔
106
      }
107

108
      return payload
1✔
109
    })
110
  },
111
  { name: 'xml-parser' }
112
)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc