elm-pages 3.0.0-beta.16 → 3.0.0-beta.18
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/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +1 -1
- package/generator/src/build.js +7 -7
- package/generator/src/cli.js +9 -6
- package/generator/src/dev-server.js +6 -6
- package/generator/src/render-test.js +1 -1
- package/generator/src/render.js +97 -126
- package/generator/src/request-cache.js +5 -5
- package/package.json +1 -1
- package/src/BackendTask/{Port.elm → Custom.elm} +47 -47
- package/src/BackendTask/File.elm +1 -1
- package/src/BackendTask/Glob.elm +4 -2
- package/src/BackendTask/Http.elm +6 -6
- package/src/BackendTask.elm +1 -1
- package/src/FatalError.elm +2 -14
- package/src/Pages/Internal/Platform/Cli.elm +8 -6
- package/src/Pages/Internal/Platform/Effect.elm +1 -1
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +8 -6
- package/src/Pages/Internal/Platform/StaticResponses.elm +1 -1
- package/src/Pages/Internal/Platform/ToJsPayload.elm +4 -7
- package/src/Pages/Script.elm +2 -2
|
Binary file
|
|
@@ -75,7 +75,7 @@ console.elmlog = (str) => logs.push(str + "\n");
|
|
|
75
75
|
const { Elm } = require("./Runner.elm.js");
|
|
76
76
|
|
|
77
77
|
// Start the Elm app
|
|
78
|
-
const flags = { initialSeed:
|
|
78
|
+
const flags = { initialSeed: 3582516438, fuzzRuns: 100, filter: null };
|
|
79
79
|
const app = Elm.Runner.init({ flags: flags });
|
|
80
80
|
|
|
81
81
|
// Record the timing at which we received the last "runTest" message
|
|
Binary file
|
|
@@ -75,7 +75,7 @@ console.elmlog = (str) => logs.push(str + "\n");
|
|
|
75
75
|
const { Elm } = require("./Runner.elm.js");
|
|
76
76
|
|
|
77
77
|
// Start the Elm app
|
|
78
|
-
const flags = { initialSeed:
|
|
78
|
+
const flags = { initialSeed: 955237713, fuzzRuns: 100, filter: null };
|
|
79
79
|
const app = Elm.Runner.init({ flags: flags });
|
|
80
80
|
|
|
81
81
|
// Record the timing at which we received the last "runTest" message
|
package/generator/src/build.js
CHANGED
|
@@ -143,9 +143,9 @@ async function run(options) {
|
|
|
143
143
|
|
|
144
144
|
const portBackendTaskCompiled = esbuild
|
|
145
145
|
.build({
|
|
146
|
-
entryPoints: ["./
|
|
146
|
+
entryPoints: ["./custom-backend-task"],
|
|
147
147
|
platform: "node",
|
|
148
|
-
outfile: ".elm-pages/compiled-ports/
|
|
148
|
+
outfile: ".elm-pages/compiled-ports/custom-backend-task.js",
|
|
149
149
|
assetNames: "[name]-[hash]",
|
|
150
150
|
chunkNames: "chunks/[name]-[hash]",
|
|
151
151
|
outExtension: { ".js": ".js" },
|
|
@@ -161,11 +161,11 @@ async function run(options) {
|
|
|
161
161
|
})
|
|
162
162
|
.catch((error) => {
|
|
163
163
|
const portBackendTaskFileFound =
|
|
164
|
-
globby.sync("./
|
|
164
|
+
globby.sync("./custom-backend-task.*").length > 0;
|
|
165
165
|
if (portBackendTaskFileFound) {
|
|
166
|
-
// don't present error if there are no files matching
|
|
167
|
-
// if there are files matching
|
|
168
|
-
console.error("Failed to start
|
|
166
|
+
// don't present error if there are no files matching custom-backend-task
|
|
167
|
+
// if there are files matching custom-backend-task, warn the user in case something went wrong loading it
|
|
168
|
+
console.error("Failed to start custom-backend-task watcher", error);
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
171
|
// TODO extract common code for compiling ports file?
|
|
@@ -617,7 +617,7 @@ async function runAdapter(adaptFn, processedIndexTemplate) {
|
|
|
617
617
|
apiRoutePatterns: JSON.parse(
|
|
618
618
|
await fsPromises.readFile("./dist/api-patterns.json", "utf-8")
|
|
619
619
|
),
|
|
620
|
-
portsFilePath: "./.elm-pages/compiled-ports/
|
|
620
|
+
portsFilePath: "./.elm-pages/compiled-ports/custom-backend-task.js",
|
|
621
621
|
htmlTemplate: processedIndexTemplate,
|
|
622
622
|
});
|
|
623
623
|
console.log("Success - Adapter script complete");
|
package/generator/src/cli.js
CHANGED
|
@@ -131,9 +131,9 @@ async function main() {
|
|
|
131
131
|
|
|
132
132
|
const portBackendTaskCompiled = esbuild
|
|
133
133
|
.build({
|
|
134
|
-
entryPoints: ["./
|
|
134
|
+
entryPoints: ["./custom-backend-task"],
|
|
135
135
|
platform: "node",
|
|
136
|
-
outfile: ".elm-pages/compiled-ports/
|
|
136
|
+
outfile: ".elm-pages/compiled-ports/custom-backend-task.js",
|
|
137
137
|
assetNames: "[name]-[hash]",
|
|
138
138
|
chunkNames: "chunks/[name]-[hash]",
|
|
139
139
|
outExtension: { ".js": ".js" },
|
|
@@ -151,11 +151,14 @@ async function main() {
|
|
|
151
151
|
})
|
|
152
152
|
.catch((error) => {
|
|
153
153
|
const portBackendTaskFileFound =
|
|
154
|
-
globby.sync("./
|
|
154
|
+
globby.sync("./custom-backend-task.*").length > 0;
|
|
155
155
|
if (portBackendTaskFileFound) {
|
|
156
|
-
// don't present error if there are no files matching
|
|
157
|
-
// if there are files matching
|
|
158
|
-
console.error(
|
|
156
|
+
// don't present error if there are no files matching custom-backend-task
|
|
157
|
+
// if there are files matching custom-backend-task, warn the user in case something went wrong loading it
|
|
158
|
+
console.error(
|
|
159
|
+
"Failed to start custom-backend-task watcher",
|
|
160
|
+
error
|
|
161
|
+
);
|
|
159
162
|
}
|
|
160
163
|
});
|
|
161
164
|
const portsPath = await portBackendTaskCompiled;
|
|
@@ -140,7 +140,7 @@ async function start(options) {
|
|
|
140
140
|
);
|
|
141
141
|
esbuild
|
|
142
142
|
.build({
|
|
143
|
-
entryPoints: ["./
|
|
143
|
+
entryPoints: ["./custom-backend-task"],
|
|
144
144
|
platform: "node",
|
|
145
145
|
assetNames: "[name]-[hash]",
|
|
146
146
|
chunkNames: "chunks/[name]-[hash]",
|
|
@@ -171,15 +171,15 @@ async function start(options) {
|
|
|
171
171
|
],
|
|
172
172
|
})
|
|
173
173
|
.then((result) => {
|
|
174
|
-
console.log("Watching
|
|
174
|
+
console.log("Watching custom-backend-task...");
|
|
175
175
|
})
|
|
176
176
|
.catch((error) => {
|
|
177
177
|
const portBackendTaskFileFound =
|
|
178
|
-
globby.sync("./
|
|
178
|
+
globby.sync("./custom-backend-task.*").length > 0;
|
|
179
179
|
if (portBackendTaskFileFound) {
|
|
180
|
-
// don't present error if there are no files matching
|
|
181
|
-
// if there are files matching
|
|
182
|
-
console.error("Failed to start
|
|
180
|
+
// don't present error if there are no files matching custom-backend-task
|
|
181
|
+
// if there are files matching custom-backend-task, warn the user in case something went wrong loading it
|
|
182
|
+
console.error("Failed to start custom-backend-task watcher", error);
|
|
183
183
|
}
|
|
184
184
|
});
|
|
185
185
|
|
|
@@ -27,7 +27,7 @@ async function run({ pathname, serverRequest }) {
|
|
|
27
27
|
console.log("Compiling DONE");
|
|
28
28
|
|
|
29
29
|
const portsFilePath =
|
|
30
|
-
".elm-pages/compiled-ports/
|
|
30
|
+
".elm-pages/compiled-ports/custom-backend-task-FA2IJND6.js";
|
|
31
31
|
const mode = "dev-server";
|
|
32
32
|
|
|
33
33
|
const renderResult = await renderer.render(
|
package/generator/src/render.js
CHANGED
|
@@ -16,8 +16,6 @@ process.on("unhandledRejection", (error) => {
|
|
|
16
16
|
console.error(error);
|
|
17
17
|
});
|
|
18
18
|
let foundErrors;
|
|
19
|
-
let pendingBackendTaskResponses = new Map();
|
|
20
|
-
let pendingBackendTaskCount;
|
|
21
19
|
|
|
22
20
|
module.exports = { render, runGenerator };
|
|
23
21
|
|
|
@@ -44,8 +42,6 @@ async function render(
|
|
|
44
42
|
const { fs, resetInMemoryFs } = require("./request-cache-fs.js")(hasFsAccess);
|
|
45
43
|
resetInMemoryFs();
|
|
46
44
|
foundErrors = false;
|
|
47
|
-
pendingBackendTaskResponses = new Map();
|
|
48
|
-
pendingBackendTaskCount = 0;
|
|
49
45
|
// since init/update are never called in pre-renders, and BackendTask.Http is called using pure NodeJS HTTP fetching
|
|
50
46
|
// we can provide a fake HTTP instead of xhr2 (which is otherwise needed for Elm HTTP requests from Node)
|
|
51
47
|
XMLHttpRequest = {};
|
|
@@ -74,8 +70,6 @@ async function runGenerator(cliOptions, portsFile, elmModule) {
|
|
|
74
70
|
const { fs, resetInMemoryFs } = require("./request-cache-fs.js")(true);
|
|
75
71
|
resetInMemoryFs();
|
|
76
72
|
foundErrors = false;
|
|
77
|
-
pendingBackendTaskResponses = new Map();
|
|
78
|
-
pendingBackendTaskCount = 0;
|
|
79
73
|
// since init/update are never called in pre-renders, and BackendTask.Http is called using pure NodeJS HTTP fetching
|
|
80
74
|
// we can provide a fake HTTP instead of xhr2 (which is otherwise needed for Elm HTTP requests from Node)
|
|
81
75
|
XMLHttpRequest = {};
|
|
@@ -166,33 +160,39 @@ function runGeneratorAppHelp(
|
|
|
166
160
|
);
|
|
167
161
|
}
|
|
168
162
|
} else if (fromElm.tag === "DoHttp") {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
163
|
+
app.ports.gotBatchSub.send(
|
|
164
|
+
Object.fromEntries(
|
|
165
|
+
await Promise.all(
|
|
166
|
+
fromElm.args[0].map(([requestHash, requestToPerform]) => {
|
|
167
|
+
if (
|
|
168
|
+
requestToPerform.url !== "elm-pages-internal://port" &&
|
|
169
|
+
requestToPerform.url.startsWith("elm-pages-internal://")
|
|
170
|
+
) {
|
|
171
|
+
return runInternalJob(
|
|
172
|
+
requestHash,
|
|
173
|
+
app,
|
|
174
|
+
mode,
|
|
175
|
+
requestToPerform,
|
|
176
|
+
fs,
|
|
177
|
+
hasFsAccess,
|
|
178
|
+
patternsToWatch
|
|
179
|
+
);
|
|
180
|
+
} else {
|
|
181
|
+
return runHttpJob(
|
|
182
|
+
requestHash,
|
|
183
|
+
portsFile,
|
|
184
|
+
app,
|
|
185
|
+
mode,
|
|
186
|
+
requestToPerform,
|
|
187
|
+
fs,
|
|
188
|
+
hasFsAccess,
|
|
189
|
+
requestToPerform
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
)
|
|
194
|
+
)
|
|
195
|
+
);
|
|
196
196
|
} else if (fromElm.tag === "Errors") {
|
|
197
197
|
foundErrors = true;
|
|
198
198
|
reject(fromElm.args[0].errorsJson);
|
|
@@ -309,33 +309,39 @@ function runElmApp(
|
|
|
309
309
|
);
|
|
310
310
|
}
|
|
311
311
|
} else if (fromElm.tag === "DoHttp") {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
312
|
+
app.ports.gotBatchSub.send(
|
|
313
|
+
Object.fromEntries(
|
|
314
|
+
await Promise.all(
|
|
315
|
+
fromElm.args[0].map(([requestHash, requestToPerform]) => {
|
|
316
|
+
if (
|
|
317
|
+
requestToPerform.url !== "elm-pages-internal://port" &&
|
|
318
|
+
requestToPerform.url.startsWith("elm-pages-internal://")
|
|
319
|
+
) {
|
|
320
|
+
return runInternalJob(
|
|
321
|
+
requestHash,
|
|
322
|
+
app,
|
|
323
|
+
mode,
|
|
324
|
+
requestToPerform,
|
|
325
|
+
fs,
|
|
326
|
+
hasFsAccess,
|
|
327
|
+
patternsToWatch
|
|
328
|
+
);
|
|
329
|
+
} else {
|
|
330
|
+
return runHttpJob(
|
|
331
|
+
requestHash,
|
|
332
|
+
portsFile,
|
|
333
|
+
app,
|
|
334
|
+
mode,
|
|
335
|
+
requestToPerform,
|
|
336
|
+
fs,
|
|
337
|
+
hasFsAccess,
|
|
338
|
+
requestToPerform
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
)
|
|
343
|
+
)
|
|
344
|
+
);
|
|
339
345
|
} else if (fromElm.tag === "Errors") {
|
|
340
346
|
foundErrors = true;
|
|
341
347
|
reject(fromElm.args[0].errorsJson);
|
|
@@ -404,7 +410,6 @@ async function runHttpJob(
|
|
|
404
410
|
hasFsAccess,
|
|
405
411
|
useCache
|
|
406
412
|
) {
|
|
407
|
-
pendingBackendTaskCount += 1;
|
|
408
413
|
try {
|
|
409
414
|
const lookupResponse = await lookupOrPerform(
|
|
410
415
|
portsFile,
|
|
@@ -416,25 +421,29 @@ async function runHttpJob(
|
|
|
416
421
|
|
|
417
422
|
if (lookupResponse.kind === "cache-response-path") {
|
|
418
423
|
const responseFilePath = lookupResponse.value;
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
424
|
+
return [
|
|
425
|
+
requestHash,
|
|
426
|
+
{
|
|
427
|
+
request: requestToPerform,
|
|
428
|
+
response: JSON.parse(
|
|
429
|
+
(await fs.promises.readFile(responseFilePath, "utf8")).toString()
|
|
430
|
+
),
|
|
431
|
+
},
|
|
432
|
+
];
|
|
425
433
|
} else if (lookupResponse.kind === "response-json") {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
434
|
+
return [
|
|
435
|
+
requestHash,
|
|
436
|
+
{
|
|
437
|
+
request: requestToPerform,
|
|
438
|
+
response: lookupResponse.value,
|
|
439
|
+
},
|
|
440
|
+
];
|
|
430
441
|
} else {
|
|
431
442
|
throw `Unexpected kind ${lookupResponse}`;
|
|
432
443
|
}
|
|
433
444
|
} catch (error) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
pendingBackendTaskCount -= 1;
|
|
437
|
-
flushIfDone(app);
|
|
445
|
+
console.log("@@@ERROR", error);
|
|
446
|
+
// sendError(app, error);
|
|
438
447
|
}
|
|
439
448
|
}
|
|
440
449
|
|
|
@@ -461,43 +470,29 @@ async function runInternalJob(
|
|
|
461
470
|
patternsToWatch
|
|
462
471
|
) {
|
|
463
472
|
try {
|
|
464
|
-
pendingBackendTaskCount += 1;
|
|
465
|
-
|
|
466
473
|
if (requestToPerform.url === "elm-pages-internal://log") {
|
|
467
|
-
|
|
468
|
-
requestHash,
|
|
469
|
-
await runLogJob(requestToPerform)
|
|
470
|
-
);
|
|
474
|
+
return [requestHash, await runLogJob(requestToPerform)];
|
|
471
475
|
} else if (requestToPerform.url === "elm-pages-internal://read-file") {
|
|
472
|
-
|
|
476
|
+
return [
|
|
473
477
|
requestHash,
|
|
474
|
-
await readFileJobNew(requestToPerform, patternsToWatch)
|
|
475
|
-
|
|
478
|
+
await readFileJobNew(requestToPerform, patternsToWatch),
|
|
479
|
+
];
|
|
476
480
|
} else if (requestToPerform.url === "elm-pages-internal://glob") {
|
|
477
|
-
|
|
478
|
-
requestHash,
|
|
479
|
-
await runGlobNew(requestToPerform, patternsToWatch)
|
|
480
|
-
);
|
|
481
|
+
return [requestHash, await runGlobNew(requestToPerform, patternsToWatch)];
|
|
481
482
|
} else if (requestToPerform.url === "elm-pages-internal://env") {
|
|
482
|
-
|
|
483
|
-
requestHash,
|
|
484
|
-
await runEnvJob(requestToPerform, patternsToWatch)
|
|
485
|
-
);
|
|
483
|
+
return [requestHash, await runEnvJob(requestToPerform, patternsToWatch)];
|
|
486
484
|
} else if (requestToPerform.url === "elm-pages-internal://encrypt") {
|
|
487
|
-
|
|
485
|
+
return [
|
|
488
486
|
requestHash,
|
|
489
|
-
await runEncryptJob(requestToPerform, patternsToWatch)
|
|
490
|
-
|
|
487
|
+
await runEncryptJob(requestToPerform, patternsToWatch),
|
|
488
|
+
];
|
|
491
489
|
} else if (requestToPerform.url === "elm-pages-internal://decrypt") {
|
|
492
|
-
|
|
490
|
+
return [
|
|
493
491
|
requestHash,
|
|
494
|
-
await runDecryptJob(requestToPerform, patternsToWatch)
|
|
495
|
-
|
|
492
|
+
await runDecryptJob(requestToPerform, patternsToWatch),
|
|
493
|
+
];
|
|
496
494
|
} else if (requestToPerform.url === "elm-pages-internal://write-file") {
|
|
497
|
-
|
|
498
|
-
requestHash,
|
|
499
|
-
await runWriteFileJob(requestToPerform)
|
|
500
|
-
);
|
|
495
|
+
return [requestHash, await runWriteFileJob(requestToPerform)];
|
|
501
496
|
} else {
|
|
502
497
|
throw `Unexpected internal BackendTask request format: ${kleur.yellow(
|
|
503
498
|
JSON.stringify(2, null, requestToPerform)
|
|
@@ -505,9 +500,6 @@ async function runInternalJob(
|
|
|
505
500
|
}
|
|
506
501
|
} catch (error) {
|
|
507
502
|
sendError(app, error);
|
|
508
|
-
} finally {
|
|
509
|
-
pendingBackendTaskCount -= 1;
|
|
510
|
-
flushIfDone(app);
|
|
511
503
|
}
|
|
512
504
|
}
|
|
513
505
|
|
|
@@ -628,27 +620,6 @@ async function runDecryptJob(req, patternsToWatch) {
|
|
|
628
620
|
}
|
|
629
621
|
}
|
|
630
622
|
|
|
631
|
-
function flushIfDone(app) {
|
|
632
|
-
if (foundErrors) {
|
|
633
|
-
pendingBackendTaskResponses = new Map();
|
|
634
|
-
} else if (pendingBackendTaskCount === 0) {
|
|
635
|
-
// console.log(
|
|
636
|
-
// `Flushing ${pendingBackendTaskResponses.length} items in ${timeUntilThreshold}ms`
|
|
637
|
-
// );
|
|
638
|
-
|
|
639
|
-
flushQueue(app);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
function flushQueue(app) {
|
|
644
|
-
// TODO - could the case where flush is called with size 0 be avoided on the Elm side?
|
|
645
|
-
// if (pendingBackendTaskResponses.size > 0) {
|
|
646
|
-
// console.log("@@@ FLUSHING", pendingBackendTaskResponses.size);
|
|
647
|
-
app.ports.gotBatchSub.send(Object.fromEntries(pendingBackendTaskResponses));
|
|
648
|
-
pendingBackendTaskResponses = new Map();
|
|
649
|
-
// }
|
|
650
|
-
}
|
|
651
|
-
|
|
652
623
|
/**
|
|
653
624
|
* @param {{ ports: { fromJsPort: { send: (arg0: { tag: string; data: any; }) => void; }; }; }} app
|
|
654
625
|
* @param {{ message: string; title: string; }} error
|
|
@@ -43,21 +43,21 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess, useCache) {
|
|
|
43
43
|
resolve({
|
|
44
44
|
kind: "response-json",
|
|
45
45
|
value: jsonResponse({
|
|
46
|
-
"elm-pages-internal-error": "
|
|
46
|
+
"elm-pages-internal-error": "CustomBackendTaskNotDefined",
|
|
47
47
|
}),
|
|
48
48
|
});
|
|
49
49
|
} else if (portBackendTaskImportError === "missing") {
|
|
50
50
|
resolve({
|
|
51
51
|
kind: "response-json",
|
|
52
52
|
value: jsonResponse({
|
|
53
|
-
"elm-pages-internal-error": "
|
|
53
|
+
"elm-pages-internal-error": "MissingCustomBackendTaskFile",
|
|
54
54
|
}),
|
|
55
55
|
});
|
|
56
56
|
} else {
|
|
57
57
|
resolve({
|
|
58
58
|
kind: "response-json",
|
|
59
59
|
value: jsonResponse({
|
|
60
|
-
"elm-pages-internal-error": "
|
|
60
|
+
"elm-pages-internal-error": "ErrorInCustomBackendTaskFile",
|
|
61
61
|
error:
|
|
62
62
|
(portBackendTaskImportError &&
|
|
63
63
|
portBackendTaskImportError.stack) ||
|
|
@@ -83,7 +83,7 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess, useCache) {
|
|
|
83
83
|
resolve({
|
|
84
84
|
kind: "response-json",
|
|
85
85
|
value: jsonResponse({
|
|
86
|
-
"elm-pages-internal-error": "
|
|
86
|
+
"elm-pages-internal-error": "CustomBackendTaskException",
|
|
87
87
|
error: portCallError,
|
|
88
88
|
}),
|
|
89
89
|
});
|
|
@@ -92,7 +92,7 @@ function lookupOrPerform(portsFile, mode, rawRequest, hasFsAccess, useCache) {
|
|
|
92
92
|
} catch (error) {
|
|
93
93
|
console.trace(error);
|
|
94
94
|
reject({
|
|
95
|
-
title: "BackendTask.
|
|
95
|
+
title: "BackendTask.Custom Error",
|
|
96
96
|
message: error.toString(),
|
|
97
97
|
});
|
|
98
98
|
}
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
module BackendTask.
|
|
2
|
-
(
|
|
1
|
+
module BackendTask.Custom exposing
|
|
2
|
+
( run
|
|
3
3
|
, Error(..)
|
|
4
4
|
)
|
|
5
5
|
|
|
6
6
|
{-| In a vanilla Elm application, ports let you either send or receive JSON data between your Elm application and the JavaScript context in the user's browser at runtime.
|
|
7
7
|
|
|
8
|
-
With `BackendTask.
|
|
8
|
+
With `BackendTask.Custom`, you send and receive JSON to JavaScript running in NodeJS. As with any `BackendTask`, Custom BackendTask's are either run at build-time (for pre-rendered routes) or at request-time (for server-rendered routes). See [`BackendTask`](BackendTask) for more about the
|
|
9
9
|
lifecycle of `BackendTask`'s.
|
|
10
10
|
|
|
11
11
|
This means that you can call shell scripts, run NPM packages that are installed, or anything else you could do with NodeJS to perform custom side-effects, get some data, or both.
|
|
12
12
|
|
|
13
|
-
A `BackendTask.
|
|
13
|
+
A `BackendTask.Custom` will call an async JavaScript function with the given name from the definition in a file called `custom-backend-task.js` in your project's root directory. The function receives the input JSON value, and the Decoder is used to decode the return value of the async function.
|
|
14
14
|
|
|
15
|
-
@docs
|
|
15
|
+
@docs run
|
|
16
16
|
|
|
17
|
-
Here is the Elm code and corresponding JavaScript definition for getting an environment variable (or an `FatalError BackendTask.
|
|
17
|
+
Here is the Elm code and corresponding JavaScript definition for getting an environment variable (or an `FatalError BackendTask.Custom.Error` if it isn't found). In this example,
|
|
18
18
|
we're using `BackendTask.allowFatal` to let the framework treat that as an unexpected exception, but we could also handle the possible failures of the `FatalError` (see [`FatalError`](FatalError)).
|
|
19
19
|
|
|
20
20
|
import BackendTask exposing (BackendTask)
|
|
21
|
-
import BackendTask.
|
|
21
|
+
import BackendTask.Custom
|
|
22
22
|
import Json.Encode
|
|
23
23
|
import OptimizedDecoder as Decode
|
|
24
24
|
|
|
25
25
|
data : BackendTask FatalError String
|
|
26
26
|
data =
|
|
27
|
-
BackendTask.
|
|
27
|
+
BackendTask.Custom.run "environmentVariable"
|
|
28
28
|
(Json.Encode.string "EDITOR")
|
|
29
29
|
Decode.string
|
|
30
30
|
|> BackendTask.allowFatal
|
|
@@ -32,7 +32,7 @@ we're using `BackendTask.allowFatal` to let the framework treat that as an unexp
|
|
|
32
32
|
-- will resolve to "VIM" if you run `EDITOR=vim elm-pages dev`
|
|
33
33
|
|
|
34
34
|
```javascript
|
|
35
|
-
//
|
|
35
|
+
// custom-backend-task.js
|
|
36
36
|
|
|
37
37
|
module.exports =
|
|
38
38
|
/**
|
|
@@ -59,38 +59,38 @@ ${Object.keys(process.env).join("\n")}
|
|
|
59
59
|
|
|
60
60
|
## Performance
|
|
61
61
|
|
|
62
|
-
As with any JavaScript or NodeJS code, avoid doing blocking IO operations. For example, avoid using `fs.readFileSync`, because blocking IO can slow down your elm-pages builds and dev server. `elm-pages`
|
|
63
|
-
So if you do `BackendTask.map2 Tuple.pair myHttpBackendTask
|
|
64
|
-
it will need to resolve them in sequence rather than in parallel, but it's still best to avoid blocking IO operations in your BackendTask
|
|
62
|
+
As with any JavaScript or NodeJS code, avoid doing blocking IO operations. For example, avoid using `fs.readFileSync`, because blocking IO can slow down your elm-pages builds and dev server. `elm-pages` performs all `BackendTask`'s in parallel whenever possible.
|
|
63
|
+
So if you do `BackendTask.map2 Tuple.pair myHttpBackendTask myCustomBackendTask`, it will resolve those two in parallel. NodeJS performs best when you take advantage of its ability to do non-blocking I/O (file reads, HTTP requests, etc.). If you use `BackendTask.andThen`,
|
|
64
|
+
it will need to resolve them in sequence rather than in parallel, but it's still best to avoid blocking IO operations in your Custom BackendTask definitions.
|
|
65
65
|
|
|
66
66
|
|
|
67
67
|
## Error Handling
|
|
68
68
|
|
|
69
|
-
There are a few different things that can go wrong when running a
|
|
69
|
+
There are a few different things that can go wrong when running a custom-backend-task. These possible errors are captured in the `BackendTask.Custom.Error` type.
|
|
70
70
|
|
|
71
71
|
@docs Error
|
|
72
72
|
|
|
73
|
-
Any time you throw a JavaScript exception from a BackendTask.
|
|
74
|
-
to handle possible errors, but you can throw a JSON value and handle it in Elm in the `
|
|
73
|
+
Any time you throw a JavaScript exception from a BackendTask.Custom definition, it will give you a `CustomBackendTaskException`. It's usually easier to add a `try`/`catch` in your JavaScript code in `custom-backend-task.js`
|
|
74
|
+
to handle possible errors, but you can throw a JSON value and handle it in Elm in the `CustomBackendTaskException` call error.
|
|
75
75
|
|
|
76
76
|
-}
|
|
77
77
|
|
|
78
78
|
import BackendTask
|
|
79
79
|
import BackendTask.Http
|
|
80
80
|
import BackendTask.Internal.Request
|
|
81
|
-
import FatalError exposing (FatalError
|
|
81
|
+
import FatalError exposing (FatalError)
|
|
82
82
|
import Json.Decode as Decode exposing (Decoder)
|
|
83
83
|
import Json.Encode as Encode
|
|
84
84
|
import TerminalText
|
|
85
85
|
|
|
86
86
|
|
|
87
87
|
{-| -}
|
|
88
|
-
|
|
88
|
+
run :
|
|
89
89
|
String
|
|
90
90
|
-> Encode.Value
|
|
91
91
|
-> Decoder b
|
|
92
92
|
-> BackendTask.BackendTask { fatal : FatalError, recoverable : Error } b
|
|
93
|
-
|
|
93
|
+
run portName input decoder =
|
|
94
94
|
BackendTask.Internal.Request.request
|
|
95
95
|
{ name = "port"
|
|
96
96
|
, body =
|
|
@@ -104,17 +104,17 @@ get portName input decoder =
|
|
|
104
104
|
[ Decode.field "elm-pages-internal-error" Decode.string
|
|
105
105
|
|> Decode.andThen
|
|
106
106
|
(\errorKind ->
|
|
107
|
-
if errorKind == "
|
|
107
|
+
if errorKind == "CustomBackendTaskNotDefined" then
|
|
108
108
|
FatalError.recoverable
|
|
109
|
-
{ title = "
|
|
109
|
+
{ title = "Custom BackendTask Error"
|
|
110
110
|
, body =
|
|
111
|
-
[ TerminalText.text "Something went wrong in a call to BackendTask.
|
|
111
|
+
[ TerminalText.text "Something went wrong in a call to BackendTask.Custom.run. I expected to find a port named `"
|
|
112
112
|
, TerminalText.yellow portName
|
|
113
|
-
, TerminalText.text "` but I couldn't find it. Is the function exported in your
|
|
113
|
+
, TerminalText.text "` but I couldn't find it. Is the function exported in your custom-backend-task file?"
|
|
114
114
|
]
|
|
115
115
|
|> TerminalText.toString
|
|
116
116
|
}
|
|
117
|
-
(
|
|
117
|
+
(CustomBackendTaskNotDefined { name = portName })
|
|
118
118
|
|> Decode.succeed
|
|
119
119
|
|
|
120
120
|
else if errorKind == "ExportIsNotFunction" then
|
|
@@ -122,78 +122,78 @@ get portName input decoder =
|
|
|
122
122
|
|> Decode.maybe
|
|
123
123
|
|> Decode.map (Maybe.withDefault "")
|
|
124
124
|
|> Decode.map
|
|
125
|
-
(\
|
|
125
|
+
(\incorrectType ->
|
|
126
126
|
FatalError.recoverable
|
|
127
|
-
{ title = "
|
|
127
|
+
{ title = "Custom BackendTask Error"
|
|
128
128
|
, body =
|
|
129
|
-
[ TerminalText.text "Something went wrong in a call to BackendTask.
|
|
129
|
+
[ TerminalText.text "Something went wrong in a call to BackendTask.Custom.run. I found an export called `"
|
|
130
130
|
, TerminalText.yellow portName
|
|
131
131
|
, TerminalText.text "` but I expected its type to be function, but instead its type was: "
|
|
132
|
-
, TerminalText.red
|
|
132
|
+
, TerminalText.red incorrectType
|
|
133
133
|
]
|
|
134
134
|
|> TerminalText.toString
|
|
135
135
|
}
|
|
136
136
|
ExportIsNotFunction
|
|
137
137
|
)
|
|
138
138
|
|
|
139
|
-
else if errorKind == "
|
|
139
|
+
else if errorKind == "MissingCustomBackendTaskFile" then
|
|
140
140
|
FatalError.recoverable
|
|
141
|
-
{ title = "
|
|
141
|
+
{ title = "Custom BackendTask Error"
|
|
142
142
|
, body =
|
|
143
|
-
[ TerminalText.text "Something went wrong in a call to BackendTask.
|
|
143
|
+
[ TerminalText.text "Something went wrong in a call to BackendTask.Custom.run. I couldn't find your custom-backend-task file. Be sure to create a 'custom-backend-task.ts' or 'custom-backend-task.js' file."
|
|
144
144
|
]
|
|
145
145
|
|> TerminalText.toString
|
|
146
146
|
}
|
|
147
|
-
|
|
147
|
+
MissingCustomBackendTaskFile
|
|
148
148
|
|> Decode.succeed
|
|
149
149
|
|
|
150
|
-
else if errorKind == "
|
|
150
|
+
else if errorKind == "ErrorInCustomBackendTaskFile" then
|
|
151
151
|
Decode.field "error" Decode.string
|
|
152
152
|
|> Decode.maybe
|
|
153
153
|
|> Decode.map (Maybe.withDefault "")
|
|
154
154
|
|> Decode.map
|
|
155
155
|
(\errorMessage ->
|
|
156
156
|
FatalError.recoverable
|
|
157
|
-
{ title = "
|
|
157
|
+
{ title = "Custom BackendTask Error"
|
|
158
158
|
, body =
|
|
159
|
-
[ TerminalText.text "Something went wrong in a call to BackendTask.
|
|
159
|
+
[ TerminalText.text "Something went wrong in a call to BackendTask.Custom.run. I couldn't import the port definitions file, because of this exception:\n\n"
|
|
160
160
|
, TerminalText.red errorMessage
|
|
161
161
|
, TerminalText.text "\n\nAre there syntax errors or exceptions thrown during import?"
|
|
162
162
|
]
|
|
163
163
|
|> TerminalText.toString
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
ErrorInCustomBackendTaskFile
|
|
166
166
|
)
|
|
167
167
|
|
|
168
|
-
else if errorKind == "
|
|
168
|
+
else if errorKind == "CustomBackendTaskException" then
|
|
169
169
|
Decode.field "error" Decode.value
|
|
170
170
|
|> Decode.maybe
|
|
171
171
|
|> Decode.map (Maybe.withDefault Encode.null)
|
|
172
172
|
|> Decode.map
|
|
173
173
|
(\portCallError ->
|
|
174
174
|
FatalError.recoverable
|
|
175
|
-
{ title = "
|
|
175
|
+
{ title = "Custom BackendTask Error"
|
|
176
176
|
, body =
|
|
177
|
-
[ TerminalText.text "Something went wrong in a call to BackendTask.
|
|
177
|
+
[ TerminalText.text "Something went wrong in a call to BackendTask.Custom.run. I was able to import the port definitions file, but when running it I encountered this exception:\n\n"
|
|
178
178
|
, TerminalText.red (Encode.encode 2 portCallError)
|
|
179
|
-
, TerminalText.text "\n\nYou could add a `try`/`catch` in your `
|
|
179
|
+
, TerminalText.text "\n\nYou could add a `try`/`catch` in your `custom-backend-task` JavaScript code to handle that error."
|
|
180
180
|
]
|
|
181
181
|
|> TerminalText.toString
|
|
182
182
|
}
|
|
183
|
-
(
|
|
183
|
+
(CustomBackendTaskException portCallError)
|
|
184
184
|
)
|
|
185
185
|
|
|
186
186
|
else
|
|
187
187
|
FatalError.recoverable
|
|
188
|
-
{ title = "
|
|
188
|
+
{ title = "Custom BackendTask Error"
|
|
189
189
|
, body =
|
|
190
|
-
[ TerminalText.text "Something went wrong in a call to BackendTask.
|
|
190
|
+
[ TerminalText.text "Something went wrong in a call to BackendTask.Custom.run. I expected to find a port named `"
|
|
191
191
|
, TerminalText.yellow portName
|
|
192
192
|
, TerminalText.text "`."
|
|
193
193
|
]
|
|
194
194
|
|> TerminalText.toString
|
|
195
195
|
}
|
|
196
|
-
|
|
196
|
+
ErrorInCustomBackendTaskFile
|
|
197
197
|
|> Decode.succeed
|
|
198
198
|
)
|
|
199
199
|
|> Decode.map Err
|
|
@@ -207,8 +207,8 @@ get portName input decoder =
|
|
|
207
207
|
{-| -}
|
|
208
208
|
type Error
|
|
209
209
|
= Error
|
|
210
|
-
|
|
|
211
|
-
|
|
|
212
|
-
|
|
|
213
|
-
|
|
|
210
|
+
| ErrorInCustomBackendTaskFile
|
|
211
|
+
| MissingCustomBackendTaskFile
|
|
212
|
+
| CustomBackendTaskNotDefined { name : String }
|
|
213
|
+
| CustomBackendTaskException Decode.Value
|
|
214
214
|
| ExportIsNotFunction
|
package/src/BackendTask/File.elm
CHANGED
package/src/BackendTask/Glob.elm
CHANGED
|
@@ -229,7 +229,7 @@ import BackendTask exposing (BackendTask)
|
|
|
229
229
|
import BackendTask.Http
|
|
230
230
|
import BackendTask.Internal.Glob exposing (Glob(..))
|
|
231
231
|
import BackendTask.Internal.Request
|
|
232
|
-
import FatalError exposing (FatalError
|
|
232
|
+
import FatalError exposing (FatalError)
|
|
233
233
|
import Json.Decode as Decode
|
|
234
234
|
import Json.Encode as Encode
|
|
235
235
|
import List.Extra
|
|
@@ -1054,7 +1054,9 @@ so it's ideal to make this kind of assertion rather than having fallback behavio
|
|
|
1054
1054
|
issues (like if we had instead ignored the case where there are two or more matching blog post files).
|
|
1055
1055
|
|
|
1056
1056
|
-}
|
|
1057
|
-
expectUniqueMatch :
|
|
1057
|
+
expectUniqueMatch :
|
|
1058
|
+
Glob a
|
|
1059
|
+
-> BackendTask { fatal : FatalError, recoverable : String } a
|
|
1058
1060
|
expectUniqueMatch glob =
|
|
1059
1061
|
glob
|
|
1060
1062
|
|> toBackendTask
|
package/src/BackendTask/Http.elm
CHANGED
|
@@ -104,7 +104,7 @@ import Base64
|
|
|
104
104
|
import Bytes exposing (Bytes)
|
|
105
105
|
import Bytes.Decode
|
|
106
106
|
import Dict exposing (Dict)
|
|
107
|
-
import FatalError exposing (FatalError
|
|
107
|
+
import FatalError exposing (FatalError)
|
|
108
108
|
import Json.Decode
|
|
109
109
|
import Json.Encode as Encode
|
|
110
110
|
import Pages.Internal.StaticHttpBody as Body
|
|
@@ -170,7 +170,7 @@ type alias Body =
|
|
|
170
170
|
getJson :
|
|
171
171
|
String
|
|
172
172
|
-> Json.Decode.Decoder a
|
|
173
|
-
-> BackendTask
|
|
173
|
+
-> BackendTask { fatal : FatalError, recoverable : Error } a
|
|
174
174
|
getJson url decoder =
|
|
175
175
|
getWithOptions
|
|
176
176
|
{ url = url
|
|
@@ -231,7 +231,7 @@ getWithOptions :
|
|
|
231
231
|
, timeoutInMs : Maybe Int
|
|
232
232
|
, cachePath : Maybe String
|
|
233
233
|
}
|
|
234
|
-
-> BackendTask
|
|
234
|
+
-> BackendTask { fatal : FatalError, recoverable : Error } a
|
|
235
235
|
getWithOptions request__ =
|
|
236
236
|
let
|
|
237
237
|
request_ : HashRequest.Request
|
|
@@ -258,7 +258,7 @@ post :
|
|
|
258
258
|
String
|
|
259
259
|
-> Body
|
|
260
260
|
-> Expect a
|
|
261
|
-
-> BackendTask
|
|
261
|
+
-> BackendTask { fatal : FatalError, recoverable : Error } a
|
|
262
262
|
post url body expect =
|
|
263
263
|
request
|
|
264
264
|
{ url = url
|
|
@@ -397,7 +397,7 @@ request :
|
|
|
397
397
|
, timeoutInMs : Maybe Int
|
|
398
398
|
}
|
|
399
399
|
-> Expect a
|
|
400
|
-
-> BackendTask
|
|
400
|
+
-> BackendTask { fatal : FatalError, recoverable : Error } a
|
|
401
401
|
request request__ expect =
|
|
402
402
|
let
|
|
403
403
|
request_ : HashRequest.Request
|
|
@@ -475,7 +475,7 @@ with this as a low-level detail, or you can use functions like [BackendTask.Http
|
|
|
475
475
|
requestRaw :
|
|
476
476
|
HashRequest.Request
|
|
477
477
|
-> Expect a
|
|
478
|
-
-> BackendTask
|
|
478
|
+
-> BackendTask { fatal : FatalError, recoverable : Error } a
|
|
479
479
|
requestRaw request__ expect =
|
|
480
480
|
let
|
|
481
481
|
request_ : HashRequest.Request
|
package/src/BackendTask.elm
CHANGED
|
@@ -16,7 +16,7 @@ A `BackendTask` lets you pull in data from:
|
|
|
16
16
|
- Local files ([`BackendTask.File`](BackendTask-File))
|
|
17
17
|
- HTTP requests ([`BackendTask.Http`](BackendTask-Http))
|
|
18
18
|
- Globs, i.e. listing out local files based on a pattern like `content/*.txt` ([`BackendTask.Glob`](BackendTask-Glob))
|
|
19
|
-
- Ports, i.e. getting JSON data from running custom NodeJS, similar to a port in a vanilla Elm app except run at build-time in NodeJS, rather than at run-time in the browser ([`BackendTask.
|
|
19
|
+
- Ports, i.e. getting JSON data from running custom NodeJS, similar to a port in a vanilla Elm app except run at build-time in NodeJS, rather than at run-time in the browser ([`BackendTask.Custom`](BackendTask-Custom))
|
|
20
20
|
- Hardcoded data (`BackendTask.succeed "Hello!"`)
|
|
21
21
|
- Or any combination of the above, using `BackendTask.map2`, `BackendTask.andThen`, or other combining/continuing helpers from this module
|
|
22
22
|
|
package/src/FatalError.elm
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
module FatalError exposing
|
|
2
|
-
( FatalError, fromString, recoverable
|
|
3
|
-
, Recoverable
|
|
4
|
-
)
|
|
1
|
+
module FatalError exposing (FatalError, fromString, recoverable)
|
|
5
2
|
|
|
6
3
|
{-| The Elm language doesn't have the concept of exceptions or special control flow for errors. It just has
|
|
7
4
|
Custom Types, and by convention types like `Result` and the `Err` variant are used to represent possible failure states
|
|
@@ -59,20 +56,11 @@ when these errors occur.
|
|
|
59
56
|
|
|
60
57
|
@docs FatalError, fromString, recoverable
|
|
61
58
|
|
|
62
|
-
@docs Recoverable
|
|
63
|
-
|
|
64
59
|
-}
|
|
65
60
|
|
|
66
61
|
import Pages.Internal.FatalError
|
|
67
62
|
|
|
68
63
|
|
|
69
|
-
{-| -}
|
|
70
|
-
type alias Recoverable error =
|
|
71
|
-
{ fatal : FatalError
|
|
72
|
-
, recoverable : error
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
64
|
{-| -}
|
|
77
65
|
type alias FatalError =
|
|
78
66
|
Pages.Internal.FatalError.FatalError
|
|
@@ -94,7 +82,7 @@ fromString string =
|
|
|
94
82
|
|
|
95
83
|
|
|
96
84
|
{-| -}
|
|
97
|
-
recoverable : { title : String, body : String } ->
|
|
85
|
+
recoverable : { title : String, body : String } -> error -> { fatal : FatalError, recoverable : error }
|
|
98
86
|
recoverable info value =
|
|
99
87
|
{ fatal = build info
|
|
100
88
|
, recoverable = value
|
|
@@ -209,8 +209,13 @@ perform site renderRequest config effect =
|
|
|
209
209
|
Effect.Batch list ->
|
|
210
210
|
flatten site renderRequest config list
|
|
211
211
|
|
|
212
|
-
Effect.FetchHttp
|
|
213
|
-
|
|
212
|
+
Effect.FetchHttp requests ->
|
|
213
|
+
requests
|
|
214
|
+
|> List.map
|
|
215
|
+
(\request ->
|
|
216
|
+
( Pages.StaticHttp.Request.hash request, request )
|
|
217
|
+
)
|
|
218
|
+
|> ToJsPayload.DoHttp
|
|
214
219
|
|> Codec.encoder (ToJsPayload.successCodecNew2 canonicalSiteUrl "")
|
|
215
220
|
|> config.toJsPort
|
|
216
221
|
|> Cmd.map never
|
|
@@ -817,10 +822,7 @@ nextStepToEffect model nextStep =
|
|
|
817
822
|
( { model
|
|
818
823
|
| staticResponses = updatedStaticResponsesModel
|
|
819
824
|
}
|
|
820
|
-
,
|
|
821
|
-
|> List.map Effect.FetchHttp
|
|
822
|
-
)
|
|
823
|
-
|> Effect.Batch
|
|
825
|
+
, Effect.FetchHttp httpRequests
|
|
824
826
|
)
|
|
825
827
|
|
|
826
828
|
StaticResponses.FinishedWithErrors errors ->
|
|
@@ -7,7 +7,7 @@ import Pages.StaticHttp.Request as StaticHttp
|
|
|
7
7
|
|
|
8
8
|
type Effect
|
|
9
9
|
= NoEffect
|
|
10
|
-
| FetchHttp StaticHttp.Request
|
|
10
|
+
| FetchHttp (List StaticHttp.Request)
|
|
11
11
|
| Batch (List Effect)
|
|
12
12
|
| SendSinglePage ToJsSuccessPayloadNewCombined
|
|
13
13
|
| SendSinglePageNew Bytes ToJsSuccessPayloadNewCombined
|
|
@@ -183,8 +183,13 @@ perform config effect =
|
|
|
183
183
|
Effect.Batch list ->
|
|
184
184
|
flatten config list
|
|
185
185
|
|
|
186
|
-
Effect.FetchHttp
|
|
187
|
-
|
|
186
|
+
Effect.FetchHttp requests ->
|
|
187
|
+
requests
|
|
188
|
+
|> List.map
|
|
189
|
+
(\request ->
|
|
190
|
+
( Pages.StaticHttp.Request.hash request, request )
|
|
191
|
+
)
|
|
192
|
+
|> ToJsPayload.DoHttp
|
|
188
193
|
|> Codec.encoder (ToJsPayload.successCodecNew2 canonicalSiteUrl "")
|
|
189
194
|
|> config.toJsPort
|
|
190
195
|
|> Cmd.map never
|
|
@@ -349,10 +354,7 @@ nextStepToEffect model nextStep =
|
|
|
349
354
|
( { model
|
|
350
355
|
| staticResponses = updatedStaticResponsesModel
|
|
351
356
|
}
|
|
352
|
-
,
|
|
353
|
-
|> List.map Effect.FetchHttp
|
|
354
|
-
)
|
|
355
|
-
|> Effect.Batch
|
|
357
|
+
, Effect.FetchHttp httpRequests
|
|
356
358
|
)
|
|
357
359
|
|
|
358
360
|
StaticResponses.Finish () ->
|
|
@@ -2,7 +2,7 @@ module Pages.Internal.Platform.StaticResponses exposing (NextStep(..), empty, ne
|
|
|
2
2
|
|
|
3
3
|
import BackendTask exposing (BackendTask)
|
|
4
4
|
import BuildError exposing (BuildError)
|
|
5
|
-
import FatalError exposing (FatalError
|
|
5
|
+
import FatalError exposing (FatalError)
|
|
6
6
|
import List.Extra
|
|
7
7
|
import Pages.Internal.FatalError
|
|
8
8
|
import Pages.StaticHttp.Request as HashRequest
|
|
@@ -89,7 +89,7 @@ headCodec canonicalSiteUrl currentPagePath =
|
|
|
89
89
|
type ToJsSuccessPayloadNewCombined
|
|
90
90
|
= PageProgress ToJsSuccessPayloadNew
|
|
91
91
|
| SendApiResponse { body : Json.Encode.Value, staticHttpCache : Dict String String, statusCode : Int }
|
|
92
|
-
| DoHttp String Pages.StaticHttp.Request.Request
|
|
92
|
+
| DoHttp (List ( String, Pages.StaticHttp.Request.Request ))
|
|
93
93
|
| Port String
|
|
94
94
|
| Errors (List BuildError)
|
|
95
95
|
| ApiResponse
|
|
@@ -109,8 +109,8 @@ successCodecNew2 canonicalSiteUrl currentPagePath =
|
|
|
109
109
|
PageProgress payload ->
|
|
110
110
|
success payload
|
|
111
111
|
|
|
112
|
-
DoHttp
|
|
113
|
-
vDoHttp
|
|
112
|
+
DoHttp hashRequestPairs ->
|
|
113
|
+
vDoHttp hashRequestPairs
|
|
114
114
|
|
|
115
115
|
SendApiResponse record ->
|
|
116
116
|
vSendApiResponse record
|
|
@@ -121,10 +121,7 @@ successCodecNew2 canonicalSiteUrl currentPagePath =
|
|
|
121
121
|
|> Codec.variant1 "Errors" Errors errorCodec
|
|
122
122
|
|> Codec.variant0 "ApiResponse" ApiResponse
|
|
123
123
|
|> Codec.variant1 "PageProgress" PageProgress (successCodecNew canonicalSiteUrl currentPagePath)
|
|
124
|
-
|> Codec.
|
|
125
|
-
DoHttp
|
|
126
|
-
Codec.string
|
|
127
|
-
Pages.StaticHttp.Request.codec
|
|
124
|
+
|> Codec.variant1 "DoHttp" DoHttp (Codec.list (Codec.tuple Codec.string Pages.StaticHttp.Request.codec))
|
|
128
125
|
|> Codec.variant1 "ApiResponse"
|
|
129
126
|
SendApiResponse
|
|
130
127
|
(Codec.object (\body staticHttpCache statusCode -> { body = body, staticHttpCache = staticHttpCache, statusCode = statusCode })
|
package/src/Pages/Script.elm
CHANGED
|
@@ -34,7 +34,7 @@ import BackendTask.Http
|
|
|
34
34
|
import BackendTask.Internal.Request
|
|
35
35
|
import Cli.OptionsParser as OptionsParser
|
|
36
36
|
import Cli.Program as Program
|
|
37
|
-
import FatalError exposing (FatalError
|
|
37
|
+
import FatalError exposing (FatalError)
|
|
38
38
|
import Json.Decode as Decode
|
|
39
39
|
import Json.Encode as Encode
|
|
40
40
|
import Pages.Internal.Script
|
|
@@ -52,7 +52,7 @@ type Error
|
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
{-| -}
|
|
55
|
-
writeFile : { path : String, body : String } -> BackendTask
|
|
55
|
+
writeFile : { path : String, body : String } -> BackendTask { fatal : FatalError, recoverable : Error } ()
|
|
56
56
|
writeFile { path, body } =
|
|
57
57
|
BackendTask.Internal.Request.request
|
|
58
58
|
{ name = "write-file"
|