Skip to content

Commit

Permalink
fix: #2 by set useRecord to false (kriszyp/msgpackr#120 (comment))
Browse files Browse the repository at this point in the history
  • Loading branch information
kravetsone committed Jun 24, 2024
1 parent eb2f9d5 commit 21d502a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ import type { AppType } from "./server";

const app = treaty<AppType>("localhost:4888", {
onRequest: (path, { body }) => {
if (typeof body === "object")
return {
headers: {
"content-type": "application/x-msgpack",
},
body: pack(body),
};
return {
headers: {
"content-type": "application/x-msgpack",
accept: "application/x-msgpack",
},
body: pack(body),
};
},
onResponse: async (response) => {
if (
Expand All @@ -72,7 +72,7 @@ console.log(data);

### Options

[All options of msgpackr constructor](https://github.com/kriszyp/msgpackr?tab=readme-ov-file#options)
[All options of msgpackr constructor](https://github.com/kriszyp/msgpackr?tab=readme-ov-file#options) (but we set useRecords to `false` by default)

and `mimeType` - it's value to detect msgpack content-type and responding with it if accept contains this `mimeType`. Default is `application/x-msgpack`.

Expand Down
14 changes: 7 additions & 7 deletions example/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import type { AppType } from "./server";

const app = treaty<AppType>("localhost:4888", {
onRequest: (path, { body }) => {
if (typeof body === "object")
return {
headers: {
"content-type": "application/x-msgpack",
},
body: pack(body),
};
return {
headers: {
"content-type": "application/x-msgpack",
accept: "application/x-msgpack",
},
body: pack(body),
};
},
onResponse: async (response) => {
if (
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ export interface ElysiaMsgpackOptions<Type extends LifeCycleType = "scoped">
as?: Type;
}

export function msgpack<Type extends LifeCycleType>(
export function msgpack<Type extends LifeCycleType = "scoped">(
options: ElysiaMsgpackOptions<Type> = {},
) {
options.useRecords ??= false;
const packr = new Packr(options);

const mimeType = options.mimeType ?? DEFAULT_MIME_TYPE;
Expand All @@ -30,7 +31,7 @@ export function msgpack<Type extends LifeCycleType>(
if (response && (options.force || headers.accept?.includes(mimeType))) {
return new Response(packr.pack(response), {
headers: {
"content-type": mimeType,
"Content-Type": mimeType,
},
});
}
Expand Down

0 comments on commit 21d502a

Please sign in to comment.