silgi 0.35.1 → 0.35.3

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,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.35.1";
4
+ const version = "0.35.3";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -390,6 +390,38 @@ async function parseRequestInput(req) {
390
390
  }
391
391
  return await req.text();
392
392
  }
393
+ function wrapBodyAndContentType(options) {
394
+ let { body, headers } = options;
395
+ const setContentType = (type) => {
396
+ if (!headers)
397
+ headers = {};
398
+ if (headers instanceof Headers) {
399
+ if (!headers.has("Content-Type"))
400
+ headers.set("Content-Type", type);
401
+ } else if (Array.isArray(headers)) {
402
+ if (!headers.some(([k]) => k.toLowerCase() === "content-type")) {
403
+ headers.push(["Content-Type", type]);
404
+ }
405
+ } else {
406
+ if (!("content-type" in headers)) {
407
+ headers["Content-Type"] = type;
408
+ }
409
+ }
410
+ };
411
+ if (typeof File !== "undefined" && body instanceof File) {
412
+ body = new Blob([body], { type: body.type });
413
+ setContentType(body.type || "application/octet-stream");
414
+ } else if (body instanceof Blob) {
415
+ setContentType(body.type || "application/octet-stream");
416
+ } else if (body && typeof body === "object") {
417
+ body = new Blob([JSON.stringify(body)], { type: "application/json" });
418
+ setContentType("application/json");
419
+ } else if (typeof body === "string") {
420
+ body = new Blob([body], { type: "text/plain" });
421
+ setContentType("text/plain");
422
+ }
423
+ return { body, headers };
424
+ }
393
425
 
394
426
  const plusRegex = /\+/g;
395
427
  function parseQuery(input) {
@@ -804,6 +836,10 @@ function createSilgiCore(event) {
804
836
  async function silgiFetch(_request, options, context) {
805
837
  const silgiCtx = useSilgi();
806
838
  let request;
839
+ if (options) {
840
+ const wrapped = wrapBodyAndContentType(options);
841
+ options.headers = wrapped.headers;
842
+ }
807
843
  if (typeof _request === "string") {
808
844
  _request = substitutePathParams(_request, options?.pathParams);
809
845
  let url = _request;
@@ -893,10 +893,10 @@ interface MergedSilgiSchema {
893
893
  * Creates an object type representing path parameters extracted from a URL pattern.
894
894
  *
895
895
  * @example
896
- * PathParamsObject<'/users/:id/posts/:postId'> // { id: string | number, postId: string | number }
896
+ * PathParamsObject<'/users/:id/posts/:postId'> // { id?: string | number, postId?: string | number }
897
897
  */
898
898
  type PathParamsObject<S extends string> = {
899
- [K in ExtractPathParamKeys<S>]: string | number;
899
+ [K in ExtractPathParamKeys<S>]?: string | number;
900
900
  };
901
901
  /**
902
902
  * Determines if a URL pattern contains any path parameters.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.35.1",
4
+ "version": "0.35.3",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {