MCPcopy Create free account
hub / github.com/middleapi/orpc / init

Method init

packages/client/src/plugins/batch.ts:139–181  ·  view source on GitHub ↗
(options: StandardLinkOptions<T>)

Source from the content-addressed store, hash-verified

137 }
138
139 init(options: StandardLinkOptions<T>): void {
140 options.clientInterceptors ??= []
141
142 options.clientInterceptors.push((options) => {
143 if (options.request.headers['x-orpc-batch'] !== '1') {
144 return options.next()
145 }
146
147 return options.next({
148 ...options,
149 request: {
150 ...options.request,
151 headers: {
152 ...options.request.headers,
153 'x-orpc-batch': undefined,
154 },
155 },
156 })
157 })
158
159 options.clientInterceptors.push((options) => {
160 if (
161 this.exclude(options)
162 || options.request.body instanceof Blob
163 || options.request.body instanceof FormData
164 || isAsyncIteratorObject(options.request.body)
165 || options.request.signal?.aborted
166 ) {
167 return options.next()
168 }
169
170 const group = this.groups.find(group => group.condition(options))
171
172 if (!group) {
173 return options.next()
174 }
175
176 return new Promise((resolve, reject) => {
177 this.#enqueueRequest(group, options, resolve, reject)
178 defer(() => this.#processPendingBatches())
179 })
180 })
181 }
182
183 #enqueueRequest(
184 group: BatchLinkPluginGroup<T>,

Callers

nothing calls this directly

Calls 8

#enqueueRequestMethod · 0.95
isAsyncIteratorObjectFunction · 0.90
deferFunction · 0.90
pushMethod · 0.80
conditionMethod · 0.65
nextMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected