@@ -6,7 +6,7 @@ import * as search from './services/search.ts'
66import * as info from './services/info.ts'
77import * as storage from './services/storage.ts'
88import * as queue from './services/queue.ts'
9- import { hyper } from './utils/hyper-request.ts'
9+ import { fetchWithShim , hyper } from './utils/hyper-request.ts'
1010
1111import type {
1212 HyperCache ,
@@ -60,174 +60,183 @@ export function connect(CONNECTION_STRING: string, domain = 'default'): Hyper {
6060 . then ( ( r ) => ( response . ok ? r : assoc ( 'status' , response . status , r ) ) )
6161 . then ( ( r ) => ( response . status >= 500 ? Promise . reject ( r ) : r ) )
6262
63+ /**
64+ * This is a shim to support https://github.com/hyper63/hyper/issues/566
65+ */
66+ const $fetch = fetchWithShim ( fetch )
67+
6368 return {
6469 data : {
6570 add : ( body ) =>
6671 Promise . resolve ( h )
6772 . then ( data . add ( body ) )
68- . then ( fetch )
73+ . then ( $ fetch)
6974 . then ( handleResponse ) ,
70- get : ( id ) => Promise . resolve ( h ) . then ( data . get ( id ) ) . then ( fetch ) . then ( handleResponse ) ,
75+ get : ( id ) => Promise . resolve ( h ) . then ( data . get ( id ) ) . then ( $ fetch) . then ( handleResponse ) ,
7176 list : ( options ) =>
7277 Promise . resolve ( h )
7378 . then ( data . list ( options ) )
74- . then ( fetch )
79+ . then ( $ fetch)
7580 . then ( handleResponse ) ,
7681 update : ( id , doc ) =>
7782 Promise . resolve ( h )
7883 . then ( data . update ( id , doc ) )
79- . then ( fetch )
84+ . then ( $ fetch)
8085 . then ( handleResponse ) ,
8186 remove : ( id ) =>
8287 Promise . resolve ( h )
8388 . then ( data . remove ( id ) )
84- . then ( fetch )
89+ . then ( $ fetch)
8590 . then ( handleResponse ) ,
8691 query : ( selector , options ) =>
8792 Promise . resolve ( h )
8893 . then ( data . query ( selector , options ) )
89- . then ( fetch )
94+ . then ( $ fetch)
9095 . then ( handleResponse ) ,
9196 bulk : ( docs ) =>
9297 Promise . resolve ( h )
9398 . then ( data . bulk ( docs ) )
94- . then ( fetch )
99+ . then ( $ fetch)
95100 . then ( handleResponse ) ,
96101 index : ( indexName , fields ) =>
97102 Promise . resolve ( h )
98103 . then ( data . index ( indexName , fields ) )
99- . then ( fetch )
104+ . then ( $fetch )
105+ . then ( handleResponse ) ,
106+ create : ( ) =>
107+ Promise . resolve ( h )
108+ . then ( data . create ( ) )
109+ . then ( $fetch )
100110 . then ( handleResponse ) ,
101- create : ( ) => Promise . resolve ( h ) . then ( data . create ( ) ) . then ( fetch ) . then ( handleResponse ) ,
102111 destroy : ( confirm ) =>
103112 Promise . resolve ( h )
104113 . then ( data . destroy ( confirm ) )
105- . then ( fetch )
114+ . then ( $ fetch)
106115 . then ( handleResponse ) ,
107116 } ,
108117 cache : {
109118 add : ( key , value , ttl ) =>
110119 Promise . resolve ( h )
111120 . then ( cache . add ( key , value , ttl ) )
112- . then ( fetch )
121+ . then ( $ fetch)
113122 . then ( handleResponse ) ,
114123 get : ( key ) =>
115124 Promise . resolve ( h )
116125 . then ( cache . get ( key ) )
117- . then ( fetch )
126+ . then ( $ fetch)
118127 . then ( handleResponse ) ,
119128 remove : ( key ) =>
120129 Promise . resolve ( h )
121130 . then ( cache . remove ( key ) )
122- . then ( fetch )
131+ . then ( $ fetch)
123132 . then ( handleResponse ) ,
124133 set : ( key , value , ttl ) =>
125134 Promise . resolve ( h )
126135 . then ( cache . set ( key , value , ttl ) )
127- . then ( fetch )
136+ . then ( $ fetch)
128137 . then ( handleResponse ) ,
129138 query : ( pattern ) =>
130139 Promise . resolve ( h )
131140 . then ( cache . query ( pattern ) )
132- . then ( fetch )
141+ . then ( $ fetch)
133142 . then ( handleResponse ) ,
134143 create : ( ) =>
135144 Promise . resolve ( h )
136145 . then ( cache . create ( ) )
137- . then ( fetch )
146+ . then ( $ fetch)
138147 . then ( handleResponse ) ,
139148 destroy : ( confirm ) =>
140149 Promise . resolve ( h )
141150 . then ( cache . destroy ( confirm ) )
142- . then ( fetch )
151+ . then ( $ fetch)
143152 . then ( handleResponse ) ,
144153 } ,
145154 search : {
146155 add : ( key , doc ) =>
147156 Promise . resolve ( h )
148157 . then ( search . add ( key , doc ) )
149- . then ( fetch )
158+ . then ( $ fetch)
150159 . then ( handleResponse ) ,
151160 remove : ( key ) =>
152161 Promise . resolve ( h )
153162 . then ( search . remove ( key ) )
154- . then ( fetch )
163+ . then ( $ fetch)
155164 . then ( handleResponse ) ,
156165 get : ( key ) =>
157166 Promise . resolve ( h )
158167 . then ( search . get ( key ) )
159- . then ( fetch )
168+ . then ( $ fetch)
160169 . then ( handleResponse ) ,
161170 update : ( key , doc ) =>
162171 Promise . resolve ( h )
163172 . then ( search . update ( key , doc ) )
164- . then ( fetch )
173+ . then ( $ fetch)
165174 . then ( handleResponse ) ,
166175 query : ( query , options ) =>
167176 Promise . resolve ( h )
168177 . then ( search . query ( query , options ) )
169- . then ( fetch )
178+ . then ( $ fetch)
170179 . then ( handleResponse ) ,
171180 load : ( docs ) =>
172181 Promise . resolve ( h )
173182 . then ( search . load ( docs ) )
174- . then ( fetch )
183+ . then ( $ fetch)
175184 . then ( handleResponse ) ,
176185 create : ( fields , storeFields ) =>
177186 Promise . resolve ( h )
178187 . then ( search . create ( fields , storeFields ) )
179- . then ( fetch )
188+ . then ( $ fetch)
180189 . then ( handleResponse ) ,
181190 destroy : ( confirm ) =>
182191 Promise . resolve ( h )
183192 . then ( search . destroy ( confirm ) )
184- . then ( fetch )
193+ . then ( $ fetch)
185194 . then ( handleResponse ) ,
186195 } ,
187196 storage : {
188197 upload : ( name , data ) =>
189198 Promise . resolve ( h )
190199 . then ( storage . upload ( name , data ) )
191- . then ( fetch )
200+ . then ( $ fetch)
192201 . then ( handleResponse ) ,
193202 download : ( name ) =>
194203 Promise . resolve ( h )
195204 . then ( storage . download ( name ) )
196- . then ( fetch )
205+ . then ( $ fetch)
197206 . then ( ( res ) => res . body as ReadableStream ) ,
198207 signedUrl : ( name , options ) =>
199208 Promise . resolve ( h )
200209 . then ( storage . signedUrl ( name , options ) )
201- . then ( fetch )
210+ . then ( $ fetch)
202211 . then ( handleResponse ) ,
203212 remove : ( name ) =>
204213 Promise . resolve ( h )
205214 . then ( storage . remove ( name ) )
206- . then ( fetch )
215+ . then ( $ fetch)
207216 . then ( handleResponse ) ,
208217 } ,
209218 queue : {
210219 enqueue : ( job ) =>
211220 Promise . resolve ( h )
212221 . then ( queue . enqueue ( job ) )
213- . then ( fetch )
222+ . then ( $ fetch)
214223 . then ( handleResponse ) ,
215224 errors : ( ) =>
216225 Promise . resolve ( h )
217226 . then ( queue . errors ( ) )
218- . then ( fetch )
227+ . then ( $ fetch)
219228 . then ( handleResponse ) ,
220229 queued : ( ) =>
221230 Promise . resolve ( h )
222231 . then ( queue . queued ( ) )
223- . then ( fetch )
232+ . then ( $ fetch)
224233 . then ( handleResponse ) ,
225234 } ,
226235 info : {
227236 services : ( ) =>
228237 Promise . resolve ( h )
229238 . then ( info . services ( ) )
230- . then ( fetch )
239+ . then ( $ fetch)
231240 . then ( handleResponse ) ,
232241 } ,
233242 }
0 commit comments