@vertz/fetch 0.2.22 → 0.2.24

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
@@ -71,6 +71,8 @@ interface EntityQueryMeta {
71
71
  readonly entityType: string;
72
72
  readonly kind: "get" | "list";
73
73
  readonly id?: string;
74
+ /** Whether this entity is tenant-scoped. Set by codegen from entity manifest. */
75
+ readonly tenantScoped?: boolean;
74
76
  }
75
77
  /** Metadata for mutation descriptors. */
76
78
  interface MutationMeta {
@@ -205,20 +207,29 @@ interface VertzQLIncludeEntry {
205
207
  interface VertzQLParams {
206
208
  select?: Record<string, true>;
207
209
  include?: Record<string, true | VertzQLIncludeEntry>;
210
+ where?: Record<string, unknown>;
211
+ orderBy?: Record<string, "asc" | "desc">;
212
+ limit?: number;
208
213
  }
209
214
  /**
210
- * Encodes VertzQL parameters (select, include) into a base64url string
215
+ * Encodes VertzQL parameters into a base64url string
211
216
  * suitable for the `q=` query parameter.
212
217
  *
213
218
  * This is the client-side counterpart to `parseVertzQL` on the server.
214
219
  */
215
220
  declare function encodeVertzQL(params: VertzQLParams): string;
216
221
  /**
217
- * Extracts `select` and `include` from a query object, encodes them as a
218
- * base64url `q` parameter, and returns the cleaned query.
222
+ * Extracts structural VertzQL keys (`select`, `include`) from a query object,
223
+ * encodes them as a base64url `q` parameter, and flattens `where`, `orderBy`,
224
+ * and `limit` into URL-native query parameter format.
225
+ *
226
+ * - `select` / `include` → encoded in `q` (complex nested structures)
227
+ * - `where` → bracket notation: `where[field]=value`
228
+ * - `orderBy` → colon format: `orderBy=field:dir`
229
+ * - `limit` → flat number: `limit=N`
219
230
  *
220
231
  * Returns `undefined` if the input is `undefined`.
221
- * Returns the query unchanged if no `select` or `include` is present.
232
+ * Returns the query unchanged if no VertzQL keys are present.
222
233
  */
223
234
  declare function resolveVertzQL(query?: Record<string, unknown>): Record<string, unknown> | undefined;
224
235
  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
@@ -526,17 +526,59 @@ function encodeVertzQL(params) {
526
526
  const b64 = btoa(json);
527
527
  return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
528
528
  }
529
+ var ENCODED_KEYS = new Set(["select", "include"]);
530
+ function flattenWhere(where, target) {
531
+ for (const [field, value] of Object.entries(where)) {
532
+ if (value === undefined || value === null)
533
+ continue;
534
+ if (typeof value === "object" && !Array.isArray(value)) {
535
+ for (const [op, opValue] of Object.entries(value)) {
536
+ if (opValue !== undefined && opValue !== null) {
537
+ target[`where[${field}][${op}]`] = String(opValue);
538
+ }
539
+ }
540
+ } else {
541
+ target[`where[${field}]`] = String(value);
542
+ }
543
+ }
544
+ }
545
+ function flattenOrderBy(orderBy) {
546
+ return Object.entries(orderBy).map(([field, dir]) => `${field}:${dir}`).join(",");
547
+ }
529
548
  function resolveVertzQL(query) {
530
549
  if (!query)
531
550
  return;
532
- const { select, include, ...rest } = query;
533
- if (!select && !include)
551
+ const encodedFields = {};
552
+ const rest = {};
553
+ let hasVertzQL = false;
554
+ for (const key of Object.keys(query)) {
555
+ if (query[key] === undefined) {
556
+ rest[key] = query[key];
557
+ continue;
558
+ }
559
+ if (ENCODED_KEYS.has(key)) {
560
+ encodedFields[key] = query[key];
561
+ hasVertzQL = true;
562
+ } else if (key === "where") {
563
+ flattenWhere(query[key], rest);
564
+ hasVertzQL = true;
565
+ } else if (key === "orderBy") {
566
+ rest.orderBy = flattenOrderBy(query[key]);
567
+ hasVertzQL = true;
568
+ } else if (key === "limit") {
569
+ rest.limit = query[key];
570
+ hasVertzQL = true;
571
+ } else {
572
+ rest[key] = query[key];
573
+ }
574
+ }
575
+ if (!hasVertzQL)
534
576
  return query;
535
- const q = encodeVertzQL({
536
- ...select ? { select } : {},
537
- ...include ? { include } : {}
538
- });
539
- return { ...rest, q };
577
+ if (Object.keys(encodedFields).length > 0) {
578
+ const q = encodeVertzQL(encodedFields);
579
+ return { ...rest, q };
580
+ }
581
+ return rest;
540
582
  }
541
583
  export {
542
584
  unwrapOr,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertz/fetch",
3
- "version": "0.2.22",
3
+ "version": "0.2.24",
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.21"
28
+ "@vertz/errors": "^0.2.23"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "bunup",