rouzer 1.0.0-beta.20 → 1.0.0-beta.22

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.
@@ -1,6 +1,7 @@
1
1
  import { mapValues, shake } from '../common.js';
2
2
  export function createClient(config) {
3
3
  const baseURL = config.baseURL.replace(/\/$/, '');
4
+ const defaultHeaders = config.headers && shake(config.headers);
4
5
  async function request({ path: pathBuilder, method, args: { path, query, body, headers }, schema, }) {
5
6
  if (schema.path) {
6
7
  path = schema.path.parse(path);
@@ -16,7 +17,7 @@ export function createClient(config) {
16
17
  }
17
18
  if (schema.query) {
18
19
  query = schema.query.parse(query ?? {});
19
- url.search = new URLSearchParams(query).toString();
20
+ url.search = new URLSearchParams(shake(query)).toString();
20
21
  }
21
22
  else if (query) {
22
23
  throw new Error('Unexpected query parameters');
@@ -27,11 +28,11 @@ export function createClient(config) {
27
28
  else if (body !== undefined) {
28
29
  throw new Error('Unexpected body');
29
30
  }
30
- if (config.headers || headers) {
31
- headers = {
32
- ...config.headers,
33
- ...(headers && shake(headers)),
34
- };
31
+ if (headers) {
32
+ headers = shake(headers);
33
+ if (defaultHeaders) {
34
+ headers = { ...defaultHeaders, ...headers };
35
+ }
35
36
  }
36
37
  if (schema.headers) {
37
38
  headers = schema.headers.parse(headers);
@@ -39,7 +40,7 @@ export function createClient(config) {
39
40
  return fetch(url, {
40
41
  method,
41
42
  body: body !== undefined ? JSON.stringify(body) : undefined,
42
- headers: headers,
43
+ headers: (headers ?? defaultHeaders),
43
44
  });
44
45
  }
45
46
  async function json(props) {
package/dist/route.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { RoutePattern } from '@remix-run/route-pattern';
2
2
  import type { RouteRequestFactory, RouteSchema, RouteSchemaMap, Unchecked } from './types.js';
3
3
  export declare function $type<T>(): Unchecked<T>;
4
+ export declare namespace $type {
5
+ var symbol: symbol;
6
+ }
4
7
  export type Route<P extends string = string, T extends RouteSchemaMap = RouteSchemaMap> = {
5
8
  path: RoutePattern<P>;
6
9
  methods: T;
package/dist/route.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { RoutePattern } from '@remix-run/route-pattern';
2
2
  import { mapEntries } from './common.js';
3
3
  export function $type() {
4
- return null;
4
+ return $type.symbol;
5
5
  }
6
+ $type.symbol = Symbol();
6
7
  export function route(pattern, methods) {
7
8
  const path = new RoutePattern(pattern);
8
9
  const createFetch = (method, schema) => (args = {}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rouzer",
3
- "version": "1.0.0-beta.20",
3
+ "version": "1.0.0-beta.22",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
package/dist/auth.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/auth.js DELETED
@@ -1 +0,0 @@
1
- export {};