@vertz/fetch 0.2.14 → 0.2.16

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/dist/index.d.ts CHANGED
@@ -194,4 +194,31 @@ declare class ServiceUnavailableError extends FetchError2 {
194
194
  constructor(message: string, body?: unknown);
195
195
  }
196
196
  declare function createErrorFromStatus(status: number, message: string, body?: unknown): FetchError2;
197
- export { unwrapOr, unwrap, ok, matchError, isQueryDescriptor, isOk, isMutationDescriptor, isErr, err, createMutationDescriptor, createErrorFromStatus, createDescriptor, UnprocessableEntityError, UnauthorizedError, StreamingRequestOptions, StreamingFormat, ServiceUnavailableError, RetryConfig, Result3 as Result, RequestOptions, RateLimitError, QueryDescriptor, OptimisticHandler, NotFoundError, MutationMeta, MutationDescriptor, ListResponse, InternalServerError, HooksConfig, GoneError, ForbiddenError, FetchResponse, FetchErrorType, FetchError2 as FetchError, FetchClientConfig, FetchClient, EntityQueryMeta, EntityErrorType, ConflictError, BadRequestError, AuthStrategy };
197
+ /** Shape of a single include entry for VertzQL client params. */
198
+ interface VertzQLIncludeEntry {
199
+ select?: Record<string, true>;
200
+ where?: Record<string, unknown>;
201
+ orderBy?: Record<string, "asc" | "desc">;
202
+ limit?: number;
203
+ include?: Record<string, true | VertzQLIncludeEntry>;
204
+ }
205
+ interface VertzQLParams {
206
+ select?: Record<string, true>;
207
+ include?: Record<string, true | VertzQLIncludeEntry>;
208
+ }
209
+ /**
210
+ * Encodes VertzQL parameters (select, include) into a base64url string
211
+ * suitable for the `q=` query parameter.
212
+ *
213
+ * This is the client-side counterpart to `parseVertzQL` on the server.
214
+ */
215
+ declare function encodeVertzQL(params: VertzQLParams): string;
216
+ /**
217
+ * Extracts `select` and `include` from a query object, encodes them as a
218
+ * base64url `q` parameter, and returns the cleaned query.
219
+ *
220
+ * Returns `undefined` if the input is `undefined`.
221
+ * Returns the query unchanged if no `select` or `include` is present.
222
+ */
223
+ declare function resolveVertzQL(query?: Record<string, unknown>): Record<string, unknown> | undefined;
224
+ export { unwrapOr, unwrap, resolveVertzQL, ok, matchError, isQueryDescriptor, isOk, isMutationDescriptor, isErr, err, encodeVertzQL, createMutationDescriptor, createErrorFromStatus, createDescriptor, VertzQLParams, UnprocessableEntityError, UnauthorizedError, StreamingRequestOptions, StreamingFormat, ServiceUnavailableError, RetryConfig, Result3 as Result, RequestOptions, RateLimitError, QueryDescriptor, OptimisticHandler, NotFoundError, MutationMeta, MutationDescriptor, ListResponse, InternalServerError, HooksConfig, GoneError, ForbiddenError, FetchResponse, FetchErrorType, FetchError2 as FetchError, FetchClientConfig, FetchClient, EntityQueryMeta, EntityErrorType, ConflictError, BadRequestError, AuthStrategy };
package/dist/index.js CHANGED
@@ -516,9 +516,28 @@ function createErrorFromStatus(status, message, body) {
516
516
  }
517
517
  return new FetchError(message, status, body);
518
518
  }
519
+ // src/vertzql.ts
520
+ function encodeVertzQL(params) {
521
+ const json = JSON.stringify(params);
522
+ const b64 = btoa(json);
523
+ return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
524
+ }
525
+ function resolveVertzQL(query) {
526
+ if (!query)
527
+ return;
528
+ const { select, include, ...rest } = query;
529
+ if (!select && !include)
530
+ return query;
531
+ const q = encodeVertzQL({
532
+ ...select ? { select } : {},
533
+ ...include ? { include } : {}
534
+ });
535
+ return { ...rest, q };
536
+ }
519
537
  export {
520
538
  unwrapOr,
521
539
  unwrap,
540
+ resolveVertzQL,
522
541
  ok3 as ok,
523
542
  matchError,
524
543
  isQueryDescriptor,
@@ -526,6 +545,7 @@ export {
526
545
  isMutationDescriptor,
527
546
  isErr,
528
547
  err2 as err,
548
+ encodeVertzQL,
529
549
  createMutationDescriptor,
530
550
  createErrorFromStatus,
531
551
  createDescriptor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertz/fetch",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Type-safe HTTP client for Vertz",
@@ -25,7 +25,7 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
- "@vertz/errors": "^0.2.13"
28
+ "@vertz/errors": "^0.2.15"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "bunup",