Skip to content

Commit 9f5403d

Browse files
committed
allow passing raw query string to plexus api
1 parent 40abbbd commit 9f5403d

File tree

7 files changed

+198
-30
lines changed

7 files changed

+198
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ __snapshots__
88
*.tsbuildinfo
99
*.tgz
1010
*.log
11+
.DS_Store

bun.lockb

32 Bytes
Binary file not shown.

docs/docs/api-reference/batch.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,29 @@ Run a function. During that function's execution, any state changes will be batc
1919
| ----- | ------------------------------------- |
2020
| fn | <p>The function to run in a batch</p> |
2121

22-
<a name='RuntimeInstance+batch'></a>
22+
<a name='Scope+batch'></a>
2323

2424
## .batch(fn)
2525

2626
<p>
27-
The batch function allows you to run a series of reactive actions in a single
28-
transaction. If there is already a batch in progress, the function will be
29-
added to the batch and run when the batch is released.
27+
Run a function. During that function's execution, any state changes will be
28+
batched and only applied once the function has finished.
3029
</p>
3130

32-
| Param | Type | Description |
33-
| ----- | --------------------- | -------------------------- |
34-
| fn | <code>function</code> | <p>The function to run</p> |
31+
| Param | Description |
32+
| ----- | ------------------------------------- |
33+
| fn | <p>The function to run in a batch</p> |
3534

36-
<a name='Scope+batch'></a>
35+
<a name='RuntimeInstance+batch'></a>
3736

3837
## .batch(fn)
3938

4039
<p>
41-
Run a function. During that function's execution, any state changes will be
42-
batched and only applied once the function has finished.
40+
The batch function allows you to run a series of reactive actions in a single
41+
transaction. If there is already a batch in progress, the function will be
42+
added to the batch and run when the batch is released.
4343
</p>
4444

45-
| Param | Description |
46-
| ----- | ------------------------------------- |
47-
| fn | <p>The function to run in a batch</p> |
45+
| Param | Type | Description |
46+
| ----- | --------------------- | -------------------------- |
47+
| fn | <code>function</code> | <p>The function to run</p> |

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,6 @@
8181
},
8282
"publishConfig": {
8383
"registry": "https://npm.pkg.github.com"
84-
}
84+
},
85+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
8586
}

packages/plexus-api/src/api.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,22 @@ export class ApiInstance {
291291
*/
292292
get<ResponseType = any>(
293293
path: string,
294-
query?: Record<string, any>,
294+
query?: Record<string, any> | string,
295295
options?: PlexusApiFetchOptions
296296
) {
297-
const params = new URLSearchParams(query)
297+
let params = query ? new URLSearchParams(query).toString() : ''
298+
if (typeof query === 'string') {
299+
params = query
300+
}
298301

299-
return this.send<ResponseType>(
300-
`${path}${params.toString().length > 0 ? `?${params.toString()}` : ''}`,
301-
{
302-
...options,
303-
method: 'GET',
304-
}
305-
)
302+
if (!params.startsWith('?') && params.length > 0) {
303+
params = `?${params}`
304+
}
305+
306+
return this.send<ResponseType>(`${path}${params}`, {
307+
...options,
308+
method: 'GET',
309+
})
306310
}
307311

308312
/**
@@ -313,7 +317,7 @@ export class ApiInstance {
313317
*/
314318
async post<
315319
ResponseType = any,
316-
BodyType extends Record<string, any> | string = {}
320+
BodyType extends Record<string, any> | string = {},
317321
>(
318322
path: string,
319323
body: BodyType = {} as BodyType,
@@ -466,7 +470,7 @@ export class ApiInstance {
466470
setHeaders<
467471
HeaderFunction extends () =>
468472
| Record<string, any>
469-
| Promise<Record<string, any>>
473+
| Promise<Record<string, any>>,
470474
>(inputFnOrObj: HeaderFunction | Record<string, any>) {
471475
// if (!_headers) _internalStore._options.headers = {}
472476
if (this._internalStore.noFetch) return this

tests/edgecases.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('Collection Relations', () => {
8989
)
9090

9191
test('Batching race condition with selectors', () => {
92-
batch(() => { })
92+
batch(() => {})
9393
})
9494
})
9595

0 commit comments

Comments
 (0)