@modern-js/plugin-data-loader 2.14.0 → 2.16.0
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/CHANGELOG.md +19 -0
- package/dist/cjs/cli/createRequest.js +31 -47
- package/dist/cjs/cli/data.js +17 -34
- package/dist/cjs/cli/generateClient.js +15 -41
- package/dist/cjs/cli/loader.js +11 -27
- package/dist/cjs/common/constants.js +13 -27
- package/dist/cjs/common/utils.js +7 -25
- package/dist/cjs/runtime/index.js +45 -60
- package/dist/cjs/runtime/response.js +24 -58
- package/dist/cjs/server/index.js +62 -50
- package/dist/esm/cli/createRequest.js +212 -205
- package/dist/esm/cli/data.js +769 -741
- package/dist/esm/cli/generateClient.js +40 -41
- package/dist/esm/cli/loader.js +219 -201
- package/dist/esm/common/constants.js +3 -4
- package/dist/esm/common/utils.js +17 -18
- package/dist/esm/runtime/index.js +400 -381
- package/dist/esm/runtime/response.js +276 -258
- package/dist/esm/server/index.js +177 -170
- package/dist/esm-node/cli/createRequest.js +11 -22
- package/dist/esm-node/cli/data.js +11 -16
- package/dist/esm-node/cli/generateClient.js +1 -7
- package/dist/esm-node/cli/loader.js +3 -6
- package/dist/esm-node/common/constants.js +3 -8
- package/dist/esm-node/common/utils.js +1 -4
- package/dist/esm-node/runtime/index.js +14 -28
- package/dist/esm-node/runtime/response.js +15 -34
- package/dist/esm-node/server/index.js +4 -17
- package/package.json +12 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @modern-js/plugin-data-loader
|
|
2
2
|
|
|
3
|
+
## 2.16.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4e876ab: chore: package.json include the monorepo-relative directory
|
|
8
|
+
|
|
9
|
+
chore: 在 package.json 中声明 monorepo 的子路径
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [5954330]
|
|
12
|
+
- Updated dependencies [7596520]
|
|
13
|
+
- Updated dependencies [4e876ab]
|
|
14
|
+
- @modern-js/utils@2.16.0
|
|
15
|
+
|
|
16
|
+
## 2.15.0
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- @modern-js/utils@2.15.0
|
|
21
|
+
|
|
3
22
|
## 2.14.0
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -1,66 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var createRequest_exports = {};
|
|
19
|
-
__export(createRequest_exports, {
|
|
20
|
-
createRequest: () => createRequest,
|
|
21
|
-
getRequestUrl: () => getRequestUrl
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
getRequestUrl: () => getRequestUrl,
|
|
14
|
+
createRequest: () => createRequest
|
|
22
15
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const getRequestUrl = ({
|
|
29
|
-
params,
|
|
30
|
-
request,
|
|
31
|
-
routeId
|
|
32
|
-
}) => {
|
|
16
|
+
const _pathtoregexp = require("path-to-regexp");
|
|
17
|
+
const _reactrouterdom = require("react-router-dom");
|
|
18
|
+
const _constants = require("../common/constants");
|
|
19
|
+
const _data = require("./data");
|
|
20
|
+
const getRequestUrl = ({ params, request, routeId }) => {
|
|
33
21
|
const url = new URL(request.url);
|
|
34
|
-
const toPath = (0,
|
|
22
|
+
const toPath = (0, _pathtoregexp.compile)(url.pathname, {
|
|
35
23
|
encode: encodeURIComponent
|
|
36
24
|
});
|
|
37
25
|
const newPathName = toPath(params);
|
|
38
26
|
url.pathname = newPathName;
|
|
39
|
-
url.searchParams.append(
|
|
40
|
-
url.searchParams.append(
|
|
27
|
+
url.searchParams.append(_constants.LOADER_ID_PARAM, routeId);
|
|
28
|
+
url.searchParams.append(_constants.DIRECT_PARAM, "true");
|
|
41
29
|
return url;
|
|
42
30
|
};
|
|
43
31
|
const handleRedirectResponse = (res) => {
|
|
44
32
|
const { headers } = res;
|
|
45
33
|
const location = headers.get("X-Modernjs-Redirect");
|
|
46
34
|
if (location) {
|
|
47
|
-
throw (0,
|
|
35
|
+
throw (0, _reactrouterdom.redirect)(location);
|
|
48
36
|
}
|
|
49
37
|
return res;
|
|
50
38
|
};
|
|
51
39
|
const handleDeferredResponse = async (res) => {
|
|
52
|
-
var
|
|
53
|
-
if (((
|
|
54
|
-
return await (0,
|
|
40
|
+
var _res_headers_get;
|
|
41
|
+
if (((_res_headers_get = res.headers.get("Content-Type")) === null || _res_headers_get === void 0 ? void 0 : _res_headers_get.match(_constants.CONTENT_TYPE_DEFERRED)) && res.body) {
|
|
42
|
+
return await (0, _data.parseDeferredReadableStream)(res.body);
|
|
55
43
|
}
|
|
56
44
|
return res;
|
|
57
45
|
};
|
|
58
46
|
const createRequest = (routeId, method = "get") => {
|
|
59
|
-
return async ({
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
47
|
+
return async ({ params, request }) => {
|
|
48
|
+
const url = getRequestUrl({
|
|
49
|
+
params,
|
|
50
|
+
request,
|
|
51
|
+
routeId
|
|
52
|
+
});
|
|
64
53
|
let res;
|
|
65
54
|
res = await fetch(url, {
|
|
66
55
|
method,
|
|
@@ -74,8 +63,3 @@ const createRequest = (routeId, method = "get") => {
|
|
|
74
63
|
return res;
|
|
75
64
|
};
|
|
76
65
|
};
|
|
77
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
-
0 && (module.exports = {
|
|
79
|
-
createRequest,
|
|
80
|
-
getRequestUrl
|
|
81
|
-
});
|
package/dist/cjs/cli/data.js
CHANGED
|
@@ -1,26 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var data_exports = {};
|
|
19
|
-
__export(data_exports, {
|
|
20
|
-
parseDeferredReadableStream: () => parseDeferredReadableStream
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "parseDeferredReadableStream", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => parseDeferredReadableStream
|
|
21
8
|
});
|
|
22
|
-
|
|
23
|
-
var import_remix_router = require("@modern-js/utils/universal/remix-router");
|
|
9
|
+
const _remixrouter = require("@modern-js/utils/universal/remix-router");
|
|
24
10
|
const DEFERRED_VALUE_PLACEHOLDER_PREFIX = "__deferred_promise:";
|
|
25
11
|
async function parseDeferredReadableStream(stream) {
|
|
26
12
|
if (!stream) {
|
|
@@ -79,9 +65,7 @@ async function parseDeferredReadableStream(stream) {
|
|
|
79
65
|
}
|
|
80
66
|
}
|
|
81
67
|
for (const [key, resolver] of Object.entries(deferredResolvers)) {
|
|
82
|
-
resolver.reject(
|
|
83
|
-
new import_remix_router.AbortedDeferredError(`Deferred ${key} will never resolved`)
|
|
84
|
-
);
|
|
68
|
+
resolver.reject(new _remixrouter.AbortedDeferredError(`Deferred ${key} will never resolved`));
|
|
85
69
|
}
|
|
86
70
|
} catch (error) {
|
|
87
71
|
for (const resolver of Object.values(deferredResolvers)) {
|
|
@@ -89,7 +73,10 @@ async function parseDeferredReadableStream(stream) {
|
|
|
89
73
|
}
|
|
90
74
|
}
|
|
91
75
|
})();
|
|
92
|
-
return new
|
|
76
|
+
return new _remixrouter.UNSAFE_DeferredData({
|
|
77
|
+
...criticalData,
|
|
78
|
+
...deferredData
|
|
79
|
+
});
|
|
93
80
|
} catch (error) {
|
|
94
81
|
for (const resolver of Object.values(deferredResolvers)) {
|
|
95
82
|
resolver.reject(error);
|
|
@@ -120,7 +107,9 @@ async function* readStreamSections(stream) {
|
|
|
120
107
|
const splitSections = bufferedString.split("\n\n");
|
|
121
108
|
if (splitSections.length >= 2) {
|
|
122
109
|
sections.push(...splitSections.slice(0, -1));
|
|
123
|
-
buffer = [
|
|
110
|
+
buffer = [
|
|
111
|
+
encoder.encode(splitSections.slice(-1).join("\n\n"))
|
|
112
|
+
];
|
|
124
113
|
}
|
|
125
114
|
if (sections.length > 0) {
|
|
126
115
|
break;
|
|
@@ -146,9 +135,7 @@ async function* readStreamSections(stream) {
|
|
|
146
135
|
}
|
|
147
136
|
}
|
|
148
137
|
function mergeArrays(...arrays) {
|
|
149
|
-
const out = new Uint8Array(
|
|
150
|
-
arrays.reduce((total, arr) => total + arr.length, 0)
|
|
151
|
-
);
|
|
138
|
+
const out = new Uint8Array(arrays.reduce((total, arr) => total + arr.length, 0));
|
|
152
139
|
let offset = 0;
|
|
153
140
|
for (const arr of arrays) {
|
|
154
141
|
out.set(arr, offset);
|
|
@@ -156,7 +143,3 @@ function mergeArrays(...arrays) {
|
|
|
156
143
|
}
|
|
157
144
|
return out;
|
|
158
145
|
}
|
|
159
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
160
|
-
0 && (module.exports = {
|
|
161
|
-
parseDeferredReadableStream
|
|
162
|
-
});
|
|
@@ -1,45 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 generateClient_exports = {};
|
|
29
|
-
__export(generateClient_exports, {
|
|
30
|
-
generateClient: () => generateClient
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
31
4
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
5
|
+
Object.defineProperty(exports, "generateClient", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => generateClient
|
|
8
|
+
});
|
|
9
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
|
10
|
+
function _interop_require_default(obj) {
|
|
11
|
+
return obj && obj.__esModule ? obj : {
|
|
12
|
+
default: obj
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const generateClient = ({ mapFile, loaderId }) => {
|
|
38
16
|
delete require.cache[mapFile];
|
|
39
17
|
const loadersMap = require(mapFile);
|
|
40
18
|
let requestCode = ``;
|
|
41
19
|
let exportsCode = ``;
|
|
42
|
-
const requestCreatorPath =
|
|
20
|
+
const requestCreatorPath = _path.default.join(__dirname, "./createRequest").replace("/cjs/cli/", "/esm/cli/").replace(/\\/g, "/");
|
|
43
21
|
const importCode = `
|
|
44
22
|
import { createRequest } from '${requestCreatorPath}';
|
|
45
23
|
`;
|
|
@@ -69,7 +47,3 @@ const generateClient = ({
|
|
|
69
47
|
`;
|
|
70
48
|
return generatedCode;
|
|
71
49
|
};
|
|
72
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
-
0 && (module.exports = {
|
|
74
|
-
generateClient
|
|
75
|
-
});
|
package/dist/cjs/cli/loader.js
CHANGED
|
@@ -1,30 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var loader_exports = {};
|
|
19
|
-
__export(loader_exports, {
|
|
20
|
-
default: () => loader
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => loader
|
|
21
8
|
});
|
|
22
|
-
|
|
23
|
-
var import_generateClient = require("./generateClient");
|
|
9
|
+
const _generateClient = require("./generateClient");
|
|
24
10
|
async function loader(source) {
|
|
25
|
-
var
|
|
11
|
+
var _this__compiler;
|
|
26
12
|
this.cacheable();
|
|
27
|
-
const target = (
|
|
13
|
+
const target = (_this__compiler = this._compiler) === null || _this__compiler === void 0 ? void 0 : _this__compiler.options.target;
|
|
28
14
|
if (target === "node") {
|
|
29
15
|
return source;
|
|
30
16
|
}
|
|
@@ -45,11 +31,9 @@ async function loader(source) {
|
|
|
45
31
|
if (!options.mapFile) {
|
|
46
32
|
return source;
|
|
47
33
|
}
|
|
48
|
-
const code = (0,
|
|
34
|
+
const code = (0, _generateClient.generateClient)({
|
|
49
35
|
mapFile: options.mapFile,
|
|
50
36
|
loaderId: options.loaderId
|
|
51
37
|
});
|
|
52
38
|
return code;
|
|
53
39
|
}
|
|
54
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
-
0 && (module.exports = {});
|
|
@@ -1,33 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var constants_exports = {};
|
|
19
|
-
__export(constants_exports, {
|
|
20
|
-
CONTENT_TYPE_DEFERRED: () => CONTENT_TYPE_DEFERRED,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
LOADER_ID_PARAM: () => LOADER_ID_PARAM,
|
|
21
14
|
DIRECT_PARAM: () => DIRECT_PARAM,
|
|
22
|
-
|
|
15
|
+
CONTENT_TYPE_DEFERRED: () => CONTENT_TYPE_DEFERRED
|
|
23
16
|
});
|
|
24
|
-
module.exports = __toCommonJS(constants_exports);
|
|
25
17
|
const LOADER_ID_PARAM = "__loader";
|
|
26
18
|
const DIRECT_PARAM = "__ssrDirect";
|
|
27
19
|
const CONTENT_TYPE_DEFERRED = "text/modernjs-deferred";
|
|
28
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
-
0 && (module.exports = {
|
|
30
|
-
CONTENT_TYPE_DEFERRED,
|
|
31
|
-
DIRECT_PARAM,
|
|
32
|
-
LOADER_ID_PARAM
|
|
33
|
-
});
|
package/dist/cjs/common/utils.js
CHANGED
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var utils_exports = {};
|
|
19
|
-
__export(utils_exports, {
|
|
20
|
-
matchEntry: () => matchEntry
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "matchEntry", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => matchEntry
|
|
21
8
|
});
|
|
22
|
-
module.exports = __toCommonJS(utils_exports);
|
|
23
9
|
function sortByUrlPath(entries) {
|
|
24
10
|
entries.sort(function(a, b) {
|
|
25
11
|
const length1 = a.urlPath.length;
|
|
@@ -38,7 +24,3 @@ const matchEntry = (pathname, entries) => {
|
|
|
38
24
|
sortByUrlPath(entries);
|
|
39
25
|
return entries.find((entry) => pathname.startsWith(entry.urlPath));
|
|
40
26
|
};
|
|
41
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
-
0 && (module.exports = {
|
|
43
|
-
matchEntry
|
|
44
|
-
});
|
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var runtime_exports = {};
|
|
19
|
-
__export(runtime_exports, {
|
|
20
|
-
handleRequest: () => handleRequest,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
21
13
|
isRedirectResponse: () => isRedirectResponse,
|
|
22
|
-
isResponse: () => isResponse
|
|
14
|
+
isResponse: () => isResponse,
|
|
15
|
+
handleRequest: () => handleRequest
|
|
23
16
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
const _node = require("@remix-run/node");
|
|
18
|
+
const _remixrouter = require("@modern-js/utils/universal/remix-router");
|
|
19
|
+
const _lodash = require("@modern-js/utils/lodash");
|
|
20
|
+
const _nestedRoutes = require("@modern-js/utils/universal/nestedRoutes");
|
|
21
|
+
const _constants = require("../common/constants");
|
|
22
|
+
const _utils = require("../common/utils");
|
|
23
|
+
const _response = require("./response");
|
|
24
|
+
(0, _node.installGlobals)();
|
|
25
|
+
const redirectStatusCodes = /* @__PURE__ */ new Set([
|
|
26
|
+
301,
|
|
27
|
+
302,
|
|
28
|
+
303,
|
|
29
|
+
307,
|
|
30
|
+
308
|
|
31
|
+
]);
|
|
34
32
|
function isRedirectResponse(status) {
|
|
35
33
|
return redirectStatusCodes.has(status);
|
|
36
34
|
}
|
|
@@ -45,7 +43,7 @@ function convertModernRedirectResponse(headers, basename) {
|
|
|
45
43
|
}
|
|
46
44
|
newHeaders.set("X-Modernjs-Redirect", redirectUrl);
|
|
47
45
|
newHeaders.delete("Location");
|
|
48
|
-
return new
|
|
46
|
+
return new _node.Response(null, {
|
|
49
47
|
status: 204,
|
|
50
48
|
headers: newHeaders
|
|
51
49
|
});
|
|
@@ -83,19 +81,15 @@ const sendLoaderResponse = async (res, nodeResponse) => {
|
|
|
83
81
|
res.setHeader(key, value);
|
|
84
82
|
}
|
|
85
83
|
if (nodeResponse.body) {
|
|
86
|
-
await (0,
|
|
84
|
+
await (0, _node.writeReadableStreamToWritable)(nodeResponse.body, res);
|
|
87
85
|
} else {
|
|
88
86
|
res.end();
|
|
89
87
|
}
|
|
90
88
|
};
|
|
91
|
-
const handleRequest = async ({
|
|
92
|
-
context,
|
|
93
|
-
serverRoutes,
|
|
94
|
-
routes: routesConfig
|
|
95
|
-
}) => {
|
|
89
|
+
const handleRequest = async ({ context, serverRoutes, routes: routesConfig }) => {
|
|
96
90
|
const { method, query } = context;
|
|
97
|
-
const routeId = query[
|
|
98
|
-
const entry = (0,
|
|
91
|
+
const routeId = query[_constants.LOADER_ID_PARAM];
|
|
92
|
+
const entry = (0, _utils.matchEntry)(context.path, serverRoutes);
|
|
99
93
|
if (!routeId || !entry) {
|
|
100
94
|
return;
|
|
101
95
|
}
|
|
@@ -103,8 +97,8 @@ const handleRequest = async ({
|
|
|
103
97
|
throw new Error("CSR data loader request only support http GET method");
|
|
104
98
|
}
|
|
105
99
|
const basename = entry.urlPath;
|
|
106
|
-
const routes = (0,
|
|
107
|
-
const { queryRoute } = (0,
|
|
100
|
+
const routes = (0, _nestedRoutes.transformNestedRoutes)(routesConfig);
|
|
101
|
+
const { queryRoute } = (0, _remixrouter.createStaticHandler)(routes, {
|
|
108
102
|
basename
|
|
109
103
|
});
|
|
110
104
|
const { res, logger } = context;
|
|
@@ -116,35 +110,32 @@ const handleRequest = async ({
|
|
|
116
110
|
});
|
|
117
111
|
if (isResponse(response) && isRedirectResponse(response.status)) {
|
|
118
112
|
response = convertModernRedirectResponse(response.headers, basename);
|
|
119
|
-
} else if ((0,
|
|
120
|
-
const deferredData = response[
|
|
121
|
-
const body = (0,
|
|
113
|
+
} else if ((0, _lodash.isPlainObject)(response) && _remixrouter.UNSAFE_DEFERRED_SYMBOL in response) {
|
|
114
|
+
const deferredData = response[_remixrouter.UNSAFE_DEFERRED_SYMBOL];
|
|
115
|
+
const body = (0, _response.createDeferredReadableStream)(deferredData, request.signal);
|
|
122
116
|
const init = deferredData.init || {};
|
|
123
117
|
if (init.status && isRedirectResponse(init.status)) {
|
|
124
118
|
if (!init.headers) {
|
|
125
119
|
throw new Error("redirect response includes no headers");
|
|
126
120
|
}
|
|
127
|
-
response = convertModernRedirectResponse(
|
|
128
|
-
new Headers(init.headers),
|
|
129
|
-
basename
|
|
130
|
-
);
|
|
121
|
+
response = convertModernRedirectResponse(new Headers(init.headers), basename);
|
|
131
122
|
} else {
|
|
132
123
|
const headers = new Headers(init.headers);
|
|
133
|
-
headers.set("Content-Type", `${
|
|
124
|
+
headers.set("Content-Type", `${_constants.CONTENT_TYPE_DEFERRED}; charset=UTF-8`);
|
|
134
125
|
init.headers = headers;
|
|
135
|
-
response = new
|
|
126
|
+
response = new _node.Response(body, init);
|
|
136
127
|
}
|
|
137
128
|
} else {
|
|
138
|
-
response = isResponse(response) ? response : new
|
|
129
|
+
response = isResponse(response) ? response : new _node.Response(JSON.stringify(response), {
|
|
139
130
|
headers: {
|
|
140
131
|
"Content-Type": "application/json; charset=utf-8"
|
|
141
132
|
}
|
|
142
133
|
});
|
|
143
134
|
}
|
|
144
135
|
} catch (error) {
|
|
145
|
-
const message = error instanceof
|
|
146
|
-
logger
|
|
147
|
-
response = new
|
|
136
|
+
const message = error instanceof _remixrouter.ErrorResponse ? error.data : String(error);
|
|
137
|
+
logger === null || logger === void 0 ? void 0 : logger.error(message);
|
|
138
|
+
response = new _node.Response(message, {
|
|
148
139
|
status: 500,
|
|
149
140
|
headers: {
|
|
150
141
|
"Content-Type": "text/plain"
|
|
@@ -153,9 +144,3 @@ const handleRequest = async ({
|
|
|
153
144
|
}
|
|
154
145
|
await sendLoaderResponse(res, response);
|
|
155
146
|
};
|
|
156
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
157
|
-
0 && (module.exports = {
|
|
158
|
-
handleRequest,
|
|
159
|
-
isRedirectResponse,
|
|
160
|
-
isResponse
|
|
161
|
-
});
|