laravel-query-gate-sdk 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/index.js +6 -4
- package/dist/index.mjs +6 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -385,21 +385,27 @@ console.log(posts.total) // 100
|
|
|
385
385
|
```typescript
|
|
386
386
|
import type { CursorPaginateResponse } from 'laravel-query-gate-sdk'
|
|
387
387
|
|
|
388
|
-
// First page
|
|
388
|
+
// First page (with filters)
|
|
389
389
|
const posts = await queryGate<PostContract>('posts')
|
|
390
|
+
.filter('status', 'eq', 'published')
|
|
391
|
+
.sort('created_at', 'desc')
|
|
390
392
|
.cursor()
|
|
391
393
|
.get() as CursorPaginateResponse<Post>
|
|
394
|
+
// URL: /posts?filter[status][eq]=published&sort=created_at:desc
|
|
392
395
|
|
|
393
|
-
// Next page
|
|
396
|
+
// Next page - only cursor is sent (filters are encoded in the cursor)
|
|
394
397
|
const nextPage = await queryGate<PostContract>('posts')
|
|
395
398
|
.cursor(posts.next_cursor)
|
|
396
399
|
.get() as CursorPaginateResponse<Post>
|
|
400
|
+
// URL: /posts?cursor=eyJjcmVhdGVkX2F0Ijoi...
|
|
397
401
|
|
|
398
402
|
// Response includes: data, next_cursor, prev_cursor, next_page_url, prev_page_url
|
|
399
403
|
console.log(posts.data) // Post[]
|
|
400
404
|
console.log(posts.next_cursor) // "eyJjcmVhdGVkX2F0Ijoi..."
|
|
401
405
|
```
|
|
402
406
|
|
|
407
|
+
> **Note:** When navigating with a cursor, filters and sorts are not sent in the URL because Laravel's cursor already contains all query parameters encoded in base64.
|
|
408
|
+
|
|
403
409
|
#### No Pagination (Fetch All)
|
|
404
410
|
|
|
405
411
|
```typescript
|
package/dist/index.js
CHANGED
|
@@ -241,6 +241,12 @@ function buildUrl(config, state) {
|
|
|
241
241
|
path += `/${state.action}`;
|
|
242
242
|
}
|
|
243
243
|
const params = new URLSearchParams();
|
|
244
|
+
const isCursorNavigation = state.pagination?.type === "cursor" && state.pagination.cursor !== void 0 && state.pagination.cursor !== null;
|
|
245
|
+
if (isCursorNavigation) {
|
|
246
|
+
params.append("cursor", state.pagination.cursor);
|
|
247
|
+
const queryString2 = params.toString();
|
|
248
|
+
return `${baseUrl}${path}?${queryString2}`;
|
|
249
|
+
}
|
|
244
250
|
for (const filter of state.filters) {
|
|
245
251
|
params.append(`filter[${filter.field}][${filter.operator}]`, String(filter.value));
|
|
246
252
|
}
|
|
@@ -253,10 +259,6 @@ function buildUrl(config, state) {
|
|
|
253
259
|
if (state.pagination.page !== void 0) {
|
|
254
260
|
params.append("page", String(state.pagination.page));
|
|
255
261
|
}
|
|
256
|
-
} else if (state.pagination.type === "cursor") {
|
|
257
|
-
if (state.pagination.cursor !== void 0 && state.pagination.cursor !== null) {
|
|
258
|
-
params.append("cursor", state.pagination.cursor);
|
|
259
|
-
}
|
|
260
262
|
}
|
|
261
263
|
}
|
|
262
264
|
const queryString = params.toString();
|
package/dist/index.mjs
CHANGED
|
@@ -185,6 +185,12 @@ function buildUrl(config, state) {
|
|
|
185
185
|
path += `/${state.action}`;
|
|
186
186
|
}
|
|
187
187
|
const params = new URLSearchParams();
|
|
188
|
+
const isCursorNavigation = state.pagination?.type === "cursor" && state.pagination.cursor !== void 0 && state.pagination.cursor !== null;
|
|
189
|
+
if (isCursorNavigation) {
|
|
190
|
+
params.append("cursor", state.pagination.cursor);
|
|
191
|
+
const queryString2 = params.toString();
|
|
192
|
+
return `${baseUrl}${path}?${queryString2}`;
|
|
193
|
+
}
|
|
188
194
|
for (const filter of state.filters) {
|
|
189
195
|
params.append(`filter[${filter.field}][${filter.operator}]`, String(filter.value));
|
|
190
196
|
}
|
|
@@ -197,10 +203,6 @@ function buildUrl(config, state) {
|
|
|
197
203
|
if (state.pagination.page !== void 0) {
|
|
198
204
|
params.append("page", String(state.pagination.page));
|
|
199
205
|
}
|
|
200
|
-
} else if (state.pagination.type === "cursor") {
|
|
201
|
-
if (state.pagination.cursor !== void 0 && state.pagination.cursor !== null) {
|
|
202
|
-
params.append("cursor", state.pagination.cursor);
|
|
203
|
-
}
|
|
204
206
|
}
|
|
205
207
|
}
|
|
206
208
|
const queryString = params.toString();
|