@gjsify/fetch 0.0.2 → 0.0.4

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/lib/cjs/index.js CHANGED
@@ -1,85 +1,47 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var src_exports = {};
29
- __export(src_exports, {
30
- AbortError: () => import_abort_error.AbortError,
31
- Blob: () => import_blob_from.Blob,
32
- FetchError: () => import_fetch_error.FetchError,
33
- File: () => import_blob_from.File,
34
- FormData: () => import_esm_min.FormData,
35
- Headers: () => import_headers.default,
36
- Request: () => import_request.default,
37
- Response: () => import_response.default,
38
- blobFrom: () => import_blob_from.blobFrom,
39
- blobFromSync: () => import_blob_from.blobFromSync,
40
- default: () => fetch,
41
- fileFrom: () => import_blob_from.fileFrom,
42
- fileFromSync: () => import_blob_from.fileFromSync,
43
- isRedirect: () => import_is_redirect.isRedirect
44
- });
45
- module.exports = __toCommonJS(src_exports);
46
- var import_soup_3 = __toESM(require("@girs/soup-3.0"), 1);
47
- var import_request = __toESM(require("./request.js"), 1);
48
- var import_zlib = __toESM(require("zlib"), 1);
49
- var import_stream = __toESM(require("stream"), 1);
50
- var import_data_uri_to_buffer = __toESM(require("data-uri-to-buffer"), 1);
51
- var import_body = require("./body.js");
52
- var import_response = __toESM(require("./response.js"), 1);
53
- var import_headers = __toESM(require("./headers.js"), 1);
54
- var import_request2 = require("./request.js");
55
- var import_fetch_error = require("./errors/fetch-error.js");
56
- var import_abort_error = require("./errors/abort-error.js");
57
- var import_is_redirect = require("./utils/is-redirect.js");
58
- var import_esm_min = require("formdata-polyfill/esm.min.js");
59
- var import_is = require("./utils/is.js");
60
- var import_referrer = require("./utils/referrer.js");
61
- var import_blob_from = require("./utils/blob-from.js");
62
- var import_url = require("@gjsify/deno-runtime/ext/url/00_url");
1
+ import Soup from "@girs/soup-3.0";
2
+ import Request from "./request.js";
3
+ import zlib from "zlib";
4
+ import Stream, { PassThrough, pipeline as pump } from "stream";
5
+ import dataUriToBuffer from "data-uri-to-buffer";
6
+ import { writeToStream, clone } from "./body.js";
7
+ import Response from "./response.js";
8
+ import Headers from "./headers.js";
9
+ import { getSoupRequestOptions } from "./request.js";
10
+ import { FetchError } from "./errors/fetch-error.js";
11
+ import { AbortError } from "./errors/abort-error.js";
12
+ import { isRedirect } from "./utils/is-redirect.js";
13
+ import { FormData } from "formdata-polyfill/esm.min.js";
14
+ import { isDomainOrSubdomain, isSameProtocol } from "./utils/is.js";
15
+ import { parseReferrerPolicyFromHeader } from "./utils/referrer.js";
16
+ import {
17
+ Blob,
18
+ File,
19
+ fileFromSync,
20
+ fileFrom,
21
+ blobFromSync,
22
+ blobFrom
23
+ } from "./utils/blob-from.js";
24
+ import { URL } from "@gjsify/deno-runtime/ext/url/00_url";
63
25
  const supportedSchemas = /* @__PURE__ */ new Set(["data:", "http:", "https:"]);
64
26
  async function fetch(url, init = {}) {
65
27
  return new Promise(async (resolve, reject) => {
66
- const request = new import_request.default(url, init);
67
- const { parsedURL, options } = (0, import_request2.getSoupRequestOptions)(request);
28
+ const request = new Request(url, init);
29
+ const { parsedURL, options } = getSoupRequestOptions(request);
68
30
  if (!supportedSchemas.has(parsedURL.protocol)) {
69
31
  throw new TypeError(`@gjsify/fetch cannot load ${url}. URL scheme "${parsedURL.protocol.replace(/:$/, "")}" is not supported.`);
70
32
  }
71
33
  if (parsedURL.protocol === "data:") {
72
- const data = (0, import_data_uri_to_buffer.default)(request.url);
73
- const response2 = new import_response.default(data, { headers: { "Content-Type": data.typeFull } });
34
+ const data = dataUriToBuffer(request.url);
35
+ const response2 = new Response(data, { headers: { "Content-Type": data.typeFull } });
74
36
  resolve(response2);
75
37
  return;
76
38
  }
77
39
  const { signal } = request;
78
40
  let response = null;
79
41
  const abort = () => {
80
- const error = new import_abort_error.AbortError("The operation was aborted.");
42
+ const error = new AbortError("The operation was aborted.");
81
43
  reject(error);
82
- if (request.body && request.body instanceof import_stream.default.Readable) {
44
+ if (request.body && request.body instanceof Stream.Readable) {
83
45
  request.body.destroy(error);
84
46
  }
85
47
  if (!response || !response.body) {
@@ -119,28 +81,28 @@ async function fetch(url, init = {}) {
119
81
  };
120
82
  const message = request._message;
121
83
  readable.on("error", (error) => {
122
- reject(new import_fetch_error.FetchError(`request to ${request.url} failed, reason: ${error.message}`, "system", error));
84
+ reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, "system", error));
123
85
  finalize();
124
86
  });
125
87
  message.connect("finished", (message2) => {
126
- const headers = import_headers.default._newFromSoupMessage(request._message, import_soup_3.default.MessageHeadersType.RESPONSE);
88
+ const headers = Headers._newFromSoupMessage(request._message, Soup.MessageHeadersType.RESPONSE);
127
89
  const statusCode = message2.status_code;
128
90
  const statusMessage = message2.get_reason_phrase();
129
- if ((0, import_is_redirect.isRedirect)(statusCode)) {
91
+ if (isRedirect(statusCode)) {
130
92
  const location = headers.get("Location");
131
93
  let locationURL = null;
132
94
  try {
133
- locationURL = location === null ? null : new import_url.URL(location, request.url);
95
+ locationURL = location === null ? null : new URL(location, request.url);
134
96
  } catch {
135
97
  if (request.redirect !== "manual") {
136
- reject(new import_fetch_error.FetchError(`uri requested responds with an invalid redirect URL: ${location}`, "invalid-redirect"));
98
+ reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, "invalid-redirect"));
137
99
  finalize();
138
100
  return;
139
101
  }
140
102
  }
141
103
  switch (request.redirect) {
142
104
  case "error":
143
- reject(new import_fetch_error.FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, "no-redirect"));
105
+ reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, "no-redirect"));
144
106
  finalize();
145
107
  return;
146
108
  case "manual":
@@ -150,30 +112,30 @@ async function fetch(url, init = {}) {
150
112
  break;
151
113
  }
152
114
  if (request.counter >= request.follow) {
153
- reject(new import_fetch_error.FetchError(`maximum redirect reached at: ${request.url}`, "max-redirect"));
115
+ reject(new FetchError(`maximum redirect reached at: ${request.url}`, "max-redirect"));
154
116
  finalize();
155
117
  return;
156
118
  }
157
119
  const requestOptions = {
158
- headers: new import_headers.default(request.headers),
120
+ headers: new Headers(request.headers),
159
121
  follow: request.follow,
160
122
  counter: request.counter + 1,
161
123
  agent: request.agent,
162
124
  compress: request.compress,
163
125
  method: request.method,
164
- body: (0, import_body.clone)(request),
126
+ body: clone(request),
165
127
  signal: request.signal,
166
128
  size: request.size,
167
129
  referrer: request.referrer,
168
130
  referrerPolicy: request.referrerPolicy
169
131
  };
170
- if (!(0, import_is.isDomainOrSubdomain)(request.url, locationURL) || !(0, import_is.isSameProtocol)(request.url, locationURL)) {
132
+ if (!isDomainOrSubdomain(request.url, locationURL) || !isSameProtocol(request.url, locationURL)) {
171
133
  for (const name of ["authorization", "www-authenticate", "cookie", "cookie2"]) {
172
134
  requestOptions.headers.delete(name);
173
135
  }
174
136
  }
175
- if (statusCode !== 303 && request.body && init.body instanceof import_stream.default.Readable) {
176
- reject(new import_fetch_error.FetchError("Cannot follow redirect with body being a readable stream", "unsupported-redirect"));
137
+ if (statusCode !== 303 && request.body && init.body instanceof Stream.Readable) {
138
+ reject(new FetchError("Cannot follow redirect with body being a readable stream", "unsupported-redirect"));
177
139
  finalize();
178
140
  return;
179
141
  }
@@ -182,11 +144,11 @@ async function fetch(url, init = {}) {
182
144
  requestOptions.body = void 0;
183
145
  requestOptions.headers.delete("content-length");
184
146
  }
185
- const responseReferrerPolicy = (0, import_referrer.parseReferrerPolicyFromHeader)(headers);
147
+ const responseReferrerPolicy = parseReferrerPolicyFromHeader(headers);
186
148
  if (responseReferrerPolicy) {
187
149
  requestOptions.referrerPolicy = responseReferrerPolicy;
188
150
  }
189
- resolve(fetch(new import_request.default(locationURL, requestOptions)));
151
+ resolve(fetch(new Request(locationURL, requestOptions)));
190
152
  finalize();
191
153
  return;
192
154
  }
@@ -194,7 +156,7 @@ async function fetch(url, init = {}) {
194
156
  return reject(new TypeError(`Redirect option '${request.redirect}' is not a valid value of RequestRedirect`));
195
157
  }
196
158
  }
197
- let body = (0, import_stream.pipeline)(response_, new import_stream.PassThrough(), (error) => {
159
+ let body = pump(response_, new PassThrough(), (error) => {
198
160
  if (error) {
199
161
  reject(error);
200
162
  }
@@ -210,37 +172,53 @@ async function fetch(url, init = {}) {
210
172
  };
211
173
  const codings = headers.get("Content-Encoding");
212
174
  if (!request.compress || request.method === "HEAD" || codings === null || statusCode === 204 || statusCode === 304) {
213
- response = new import_response.default(body, responseOptions);
175
+ response = new Response(body, responseOptions);
214
176
  resolve(response);
215
177
  return;
216
178
  }
217
179
  const zlibOptions = {
218
- flush: import_zlib.default.Z_SYNC_FLUSH,
219
- finishFlush: import_zlib.default.Z_SYNC_FLUSH
180
+ flush: zlib.Z_SYNC_FLUSH,
181
+ finishFlush: zlib.Z_SYNC_FLUSH
220
182
  };
221
183
  if (codings === "gzip" || codings === "x-gzip") {
222
- body = (0, import_stream.pipeline)(body, import_zlib.default.createGunzip(zlibOptions), (error) => {
184
+ body = pump(body, zlib.createGunzip(zlibOptions), (error) => {
223
185
  if (error) {
224
186
  reject(error);
225
187
  }
226
188
  });
227
- response = new import_response.default(body, responseOptions);
189
+ response = new Response(body, responseOptions);
228
190
  resolve(response);
229
191
  return;
230
192
  }
231
193
  if (codings === "br") {
232
- body = (0, import_stream.pipeline)(body, import_zlib.default.createBrotliDecompress(), (error) => {
194
+ body = pump(body, zlib.createBrotliDecompress(), (error) => {
233
195
  if (error) {
234
196
  reject(error);
235
197
  }
236
198
  });
237
- response = new import_response.default(body, responseOptions);
199
+ response = new Response(body, responseOptions);
238
200
  resolve(response);
239
201
  return;
240
202
  }
241
- response = new import_response.default(body, responseOptions);
203
+ response = new Response(body, responseOptions);
242
204
  resolve(response);
243
205
  });
244
- (0, import_body.writeToStream)(inputStream, request).catch(reject);
206
+ writeToStream(inputStream, request).catch(reject);
245
207
  });
246
208
  }
209
+ export {
210
+ AbortError,
211
+ Blob,
212
+ FetchError,
213
+ File,
214
+ FormData,
215
+ Headers,
216
+ Request,
217
+ Response,
218
+ blobFrom,
219
+ blobFromSync,
220
+ fetch as default,
221
+ fileFrom,
222
+ fileFromSync,
223
+ isRedirect
224
+ };
@@ -1,53 +1,23 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var request_exports = {};
29
- __export(request_exports, {
30
- Request: () => Request,
31
- default: () => request_default,
32
- getSoupRequestOptions: () => getSoupRequestOptions
33
- });
34
- module.exports = __toCommonJS(request_exports);
35
- var import_gjs = require("@girs/gjs");
36
- var import_gio_2 = require("@girs/gio-2.0");
37
- var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
38
- var import_soup_3 = __toESM(require("@girs/soup-3.0"), 1);
39
- var import_gio_22 = __toESM(require("@girs/gio-2.0"), 1);
40
- var SoupExt = __toESM(require("@gjsify/soup-3.0"), 1);
41
- var import_url = require("@gjsify/deno-runtime/ext/url/00_url");
42
- var import_headers = __toESM(require("./headers.js"), 1);
43
- var import_body = __toESM(require("./body.js"), 1);
44
- var import_is = require("./utils/is.js");
45
- var import_referrer = require("./utils/referrer.js");
1
+ import "@girs/gjs";
2
+ import "@girs/gio-2.0";
3
+ import GLib from "@girs/glib-2.0";
4
+ import Soup from "@girs/soup-3.0";
5
+ import Gio from "@girs/gio-2.0";
6
+ import * as SoupExt from "@gjsify/soup-3.0";
7
+ import { URL } from "@gjsify/deno-runtime/ext/url/00_url";
8
+ import Headers from "./headers.js";
9
+ import Body, { clone, extractContentType, getTotalBytes } from "./body.js";
10
+ import { isAbortSignal } from "./utils/is.js";
11
+ import {
12
+ validateReferrerPolicy,
13
+ determineRequestsReferrer,
14
+ DEFAULT_REFERRER_POLICY
15
+ } from "./utils/referrer.js";
46
16
  const INTERNALS = Symbol("Request internals");
47
17
  const isRequest = (obj) => {
48
18
  return typeof obj === "object" && typeof obj.url === "string";
49
19
  };
50
- class Request extends import_body.default {
20
+ class Request extends Body {
51
21
  /** Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching. */
52
22
  cache;
53
23
  /** Returns the credentials mode associated with request, which is a string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. */
@@ -95,7 +65,7 @@ class Request extends import_body.default {
95
65
  return this[INTERNALS].referrerPolicy;
96
66
  }
97
67
  set referrerPolicy(referrerPolicy) {
98
- this[INTERNALS].referrerPolicy = (0, import_referrer.validateReferrerPolicy)(referrerPolicy);
68
+ this[INTERNALS].referrerPolicy = validateReferrerPolicy(referrerPolicy);
99
69
  }
100
70
  /** Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler. */
101
71
  get signal() {
@@ -106,7 +76,7 @@ class Request extends import_body.default {
106
76
  return this[INTERNALS].parsedURL.toString();
107
77
  }
108
78
  get _uri() {
109
- return import_glib_2.default.Uri.parse(this.url, import_glib_2.default.UriFlags.NONE);
79
+ return GLib.Uri.parse(this.url, GLib.UriFlags.NONE);
110
80
  }
111
81
  get _session() {
112
82
  return this[INTERNALS].session;
@@ -132,10 +102,10 @@ class Request extends import_body.default {
132
102
  let parsedURL;
133
103
  let requestObj = {};
134
104
  if (isRequest(input)) {
135
- parsedURL = new import_url.URL(input.url);
105
+ parsedURL = new URL(input.url);
136
106
  requestObj = input;
137
107
  } else {
138
- parsedURL = new import_url.URL(input);
108
+ parsedURL = new URL(input);
139
109
  }
140
110
  if (parsedURL.username !== "" || parsedURL.password !== "") {
141
111
  throw new TypeError(`${parsedURL} is an url with embedded credentials.`);
@@ -147,13 +117,13 @@ class Request extends import_body.default {
147
117
  if ((init.body != null || isRequest(input) && input.body !== null) && (method === "GET" || method === "HEAD")) {
148
118
  throw new TypeError("Request with GET/HEAD method cannot have body");
149
119
  }
150
- const inputBody = init.body ? init.body : isRequest(input) && input.body !== null ? (0, import_body.clone)(input) : null;
120
+ const inputBody = init.body ? init.body : isRequest(input) && input.body !== null ? clone(input) : null;
151
121
  super(inputBody, {
152
122
  size: init.size || init.size || 0
153
123
  });
154
- const headers = new import_headers.default(init.headers || input.headers || {});
124
+ const headers = new Headers(init.headers || input.headers || {});
155
125
  if (inputBody !== null && !headers.has("Content-Type")) {
156
- const contentType = (0, import_body.extractContentType)(inputBody, this);
126
+ const contentType = extractContentType(inputBody, this);
157
127
  if (contentType) {
158
128
  headers.set("Content-Type", contentType);
159
129
  }
@@ -162,20 +132,20 @@ class Request extends import_body.default {
162
132
  if ("signal" in init) {
163
133
  signal = init.signal;
164
134
  }
165
- if (signal != null && !(0, import_is.isAbortSignal)(signal)) {
135
+ if (signal != null && !isAbortSignal(signal)) {
166
136
  throw new TypeError("Expected signal to be an instanceof AbortSignal or EventTarget");
167
137
  }
168
138
  let referrer = init.referrer == null ? input.referrer : init.referrer;
169
139
  if (referrer === "") {
170
140
  referrer = "no-referrer";
171
141
  } else if (referrer) {
172
- const parsedReferrer = new import_url.URL(referrer);
142
+ const parsedReferrer = new URL(referrer);
173
143
  referrer = /^about:(\/\/)?client$/.test(parsedReferrer.toString()) ? "client" : parsedReferrer;
174
144
  } else {
175
145
  referrer = void 0;
176
146
  }
177
147
  const session = SoupExt.ExtSession.new();
178
- const message = new import_soup_3.default.Message({
148
+ const message = new Soup.Message({
179
149
  method,
180
150
  uri: this._uri
181
151
  });
@@ -205,8 +175,8 @@ class Request extends import_body.default {
205
175
  */
206
176
  async _send(options) {
207
177
  options.headers._appendToSoupMessage(this._message);
208
- const cancellable = new import_gio_22.default.Cancellable();
209
- this[INTERNALS].inputStream = await this._session.sendAsync(this._message, import_glib_2.default.PRIORITY_DEFAULT, cancellable);
178
+ const cancellable = new Gio.Cancellable();
179
+ this[INTERNALS].inputStream = await this._session.sendAsync(this._message, GLib.PRIORITY_DEFAULT, cancellable);
210
180
  this[INTERNALS].readable = this[INTERNALS].inputStream.toReadable({});
211
181
  return {
212
182
  inputStream: this[INTERNALS].inputStream,
@@ -249,7 +219,7 @@ Object.defineProperties(Request.prototype, {
249
219
  var request_default = Request;
250
220
  const getSoupRequestOptions = (request) => {
251
221
  const { parsedURL } = request[INTERNALS];
252
- const headers = new import_headers.default(request[INTERNALS].headers);
222
+ const headers = new Headers(request[INTERNALS].headers);
253
223
  if (!headers.has("Accept")) {
254
224
  headers.set("Accept", "*/*");
255
225
  }
@@ -258,7 +228,7 @@ const getSoupRequestOptions = (request) => {
258
228
  contentLengthValue = "0";
259
229
  }
260
230
  if (request.body !== null) {
261
- const totalBytes = (0, import_body.getTotalBytes)(request);
231
+ const totalBytes = getTotalBytes(request);
262
232
  if (typeof totalBytes === "number" && !Number.isNaN(totalBytes)) {
263
233
  contentLengthValue = String(totalBytes);
264
234
  }
@@ -267,14 +237,14 @@ const getSoupRequestOptions = (request) => {
267
237
  headers.set("Content-Length", contentLengthValue);
268
238
  }
269
239
  if (request.referrerPolicy === "") {
270
- request.referrerPolicy = import_referrer.DEFAULT_REFERRER_POLICY;
240
+ request.referrerPolicy = DEFAULT_REFERRER_POLICY;
271
241
  }
272
242
  if (request.referrer && request.referrer !== "no-referrer") {
273
- request[INTERNALS].referrer = (0, import_referrer.determineRequestsReferrer)(request);
243
+ request[INTERNALS].referrer = determineRequestsReferrer(request);
274
244
  } else {
275
245
  request[INTERNALS].referrer = "no-referrer";
276
246
  }
277
- if (request[INTERNALS].referrer instanceof import_url.URL) {
247
+ if (request[INTERNALS].referrer instanceof URL) {
278
248
  headers.set("Referer", request.referrer);
279
249
  }
280
250
  if (!headers.has("User-Agent")) {
@@ -304,3 +274,8 @@ const getSoupRequestOptions = (request) => {
304
274
  options
305
275
  };
306
276
  };
277
+ export {
278
+ Request,
279
+ request_default as default,
280
+ getSoupRequestOptions
281
+ };
@@ -1,52 +1,19 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var response_exports = {};
29
- __export(response_exports, {
30
- Response: () => Response,
31
- default: () => response_default
32
- });
33
- module.exports = __toCommonJS(response_exports);
34
- var import_glib_2 = __toESM(require("@girs/glib-2.0"), 1);
35
- var import_gio_2 = __toESM(require("@girs/gio-2.0"), 1);
36
- var import_headers = __toESM(require("./headers.js"), 1);
37
- var import_body = __toESM(require("./body.js"), 1);
38
- var import_is_redirect = require("./utils/is-redirect.js");
39
- var import_url = require("@gjsify/deno-runtime/ext/url/00_url");
1
+ import GLib from "@girs/glib-2.0";
2
+ import Gio from "@girs/gio-2.0";
3
+ import Headers from "./headers.js";
4
+ import Body, { clone, extractContentType } from "./body.js";
5
+ import { isRedirect } from "./utils/is-redirect.js";
6
+ import { URL } from "@gjsify/deno-runtime/ext/url/00_url";
40
7
  const INTERNALS = Symbol("Response internals");
41
- class Response extends import_body.default {
8
+ class Response extends Body {
42
9
  [INTERNALS];
43
10
  _inputStream = null;
44
11
  constructor(body = null, options = {}) {
45
12
  super(body, options);
46
13
  const status = options.status != null ? options.status : 200;
47
- const headers = new import_headers.default(options.headers);
14
+ const headers = new Headers(options.headers);
48
15
  if (body !== null && !headers.has("Content-Type")) {
49
- const contentType = (0, import_body.extractContentType)(body, this);
16
+ const contentType = extractContentType(body, this);
50
17
  if (contentType) {
51
18
  headers.append("Content-Type", contentType);
52
19
  }
@@ -95,7 +62,7 @@ class Response extends import_body.default {
95
62
  */
96
63
  // @ts-ignore
97
64
  clone() {
98
- return new Response((0, import_body.clone)(this, this.highWaterMark), {
65
+ return new Response(clone(this, this.highWaterMark), {
99
66
  type: this.type,
100
67
  url: this.url,
101
68
  status: this.status,
@@ -113,12 +80,12 @@ class Response extends import_body.default {
113
80
  * @returns A Response object.
114
81
  */
115
82
  static redirect(url, status = 302) {
116
- if (!(0, import_is_redirect.isRedirect)(status)) {
83
+ if (!isRedirect(status)) {
117
84
  throw new RangeError('Failed to execute "redirect" on "response": Invalid status code');
118
85
  }
119
86
  return new Response(null, {
120
87
  headers: {
121
- location: new import_url.URL(url).toString()
88
+ location: new URL(url).toString()
122
89
  },
123
90
  status
124
91
  });
@@ -135,9 +102,9 @@ class Response extends import_body.default {
135
102
  if (!this._inputStream) {
136
103
  return super.text();
137
104
  }
138
- const outputStream = import_gio_2.default.MemoryOutputStream.new_resizable();
105
+ const outputStream = Gio.MemoryOutputStream.new_resizable();
139
106
  await new Promise((resolve, reject) => {
140
- outputStream.splice_async(this._inputStream, import_gio_2.default.OutputStreamSpliceFlags.CLOSE_TARGET | import_gio_2.default.OutputStreamSpliceFlags.CLOSE_SOURCE, import_glib_2.default.PRIORITY_DEFAULT, null, (self, res) => {
107
+ outputStream.splice_async(this._inputStream, Gio.OutputStreamSpliceFlags.CLOSE_TARGET | Gio.OutputStreamSpliceFlags.CLOSE_SOURCE, GLib.PRIORITY_DEFAULT, null, (self, res) => {
141
108
  try {
142
109
  resolve(outputStream.splice_finish(res));
143
110
  } catch (error) {
@@ -160,3 +127,7 @@ Object.defineProperties(Response.prototype, {
160
127
  clone: { enumerable: true }
161
128
  });
162
129
  var response_default = Response;
130
+ export {
131
+ Response,
132
+ response_default as default
133
+ };
@@ -1,17 +1 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var types_exports = {};
16
- module.exports = __toCommonJS(types_exports);
17
- __reExport(types_exports, require("./system-error.js"), module.exports);
1
+ export * from "./system-error.js";
@@ -1,16 +1 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
- var system_error_exports = {};
15
- module.exports = __toCommonJS(system_error_exports);
16
1
  ;