(options: StandardLinkOptions<T>)
| 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>, |
nothing calls this directly
no test coverage detected