146f023faSEvan Bacon"use strict";
246f023faSEvan BaconObject.defineProperty(exports, "__esModule", { value: true });
346f023faSEvan Baconexports.ExpoRequest = exports.ExpoURL = exports.NON_STANDARD_SYMBOL = exports.ExpoResponse = exports.installGlobals = void 0;
446f023faSEvan Baconconst node_1 = require("@remix-run/node");
546f023faSEvan Baconconst node_url_1 = require("node:url");
646f023faSEvan Bacon// Ensure these are available for the API Routes.
746f023faSEvan Baconfunction installGlobals() {
846f023faSEvan Bacon    (0, node_1.installGlobals)();
946f023faSEvan Bacon    // @ts-expect-error
1046f023faSEvan Bacon    global.Request = ExpoRequest;
1146f023faSEvan Bacon    // @ts-expect-error
1246f023faSEvan Bacon    global.Response = ExpoResponse;
1346f023faSEvan Bacon    // @ts-expect-error
1446f023faSEvan Bacon    global.ExpoResponse = ExpoResponse;
1546f023faSEvan Bacon    // @ts-expect-error
1646f023faSEvan Bacon    global.ExpoRequest = ExpoRequest;
1746f023faSEvan Bacon}
1846f023faSEvan Baconexports.installGlobals = installGlobals;
1946f023faSEvan Baconclass ExpoResponse extends node_1.Response {
2046f023faSEvan Bacon    // TODO: Drop when we upgrade to node-fetch v3
2146f023faSEvan Bacon    static json(data = undefined, init = {}) {
2246f023faSEvan Bacon        const body = JSON.stringify(data);
2346f023faSEvan Bacon        if (body === undefined) {
2446f023faSEvan Bacon            throw new TypeError('data is not JSON serializable');
2546f023faSEvan Bacon        }
2646f023faSEvan Bacon        const headers = new node_1.Headers(init?.headers);
2746f023faSEvan Bacon        if (!headers.has('content-type')) {
2846f023faSEvan Bacon            headers.set('content-type', 'application/json');
2946f023faSEvan Bacon        }
3046f023faSEvan Bacon        return new ExpoResponse(body, {
3146f023faSEvan Bacon            ...init,
3246f023faSEvan Bacon            headers,
3346f023faSEvan Bacon        });
3446f023faSEvan Bacon    }
3546f023faSEvan Bacon}
3646f023faSEvan Baconexports.ExpoResponse = ExpoResponse;
3746f023faSEvan Baconexports.NON_STANDARD_SYMBOL = Symbol('non-standard');
3846f023faSEvan Baconclass ExpoURL extends node_url_1.URL {
3946f023faSEvan Bacon    static from(url, config) {
4046f023faSEvan Bacon        const expoUrl = new ExpoURL(url);
4146f023faSEvan Bacon        const match = config.namedRegex.exec(expoUrl.pathname);
4246f023faSEvan Bacon        if (match?.groups) {
4346f023faSEvan Bacon            for (const [key, value] of Object.entries(match.groups)) {
4446f023faSEvan Bacon                const namedKey = config.routeKeys[key];
4546f023faSEvan Bacon                expoUrl.searchParams.set(namedKey, value);
4646f023faSEvan Bacon            }
4746f023faSEvan Bacon        }
4846f023faSEvan Bacon        return expoUrl;
4946f023faSEvan Bacon    }
5046f023faSEvan Bacon}
5146f023faSEvan Baconexports.ExpoURL = ExpoURL;
5246f023faSEvan Baconclass ExpoRequest extends node_1.Request {
53*1a3a1db5SEvan Bacon    [exports.NON_STANDARD_SYMBOL];
5446f023faSEvan Bacon    constructor(info, init) {
5546f023faSEvan Bacon        super(info, init);
5646f023faSEvan Bacon        this[exports.NON_STANDARD_SYMBOL] = {
5746f023faSEvan Bacon            url: new ExpoURL(typeof info !== 'string' && 'url' in info ? info.url : String(info)),
5846f023faSEvan Bacon        };
5946f023faSEvan Bacon    }
6046f023faSEvan Bacon    get expoUrl() {
6146f023faSEvan Bacon        return this[exports.NON_STANDARD_SYMBOL].url;
6246f023faSEvan Bacon    }
6346f023faSEvan Bacon}
6446f023faSEvan Baconexports.ExpoRequest = ExpoRequest;
6546f023faSEvan Bacon//# sourceMappingURL=environment.js.map