@ekino/rendr-loader
Advanced tools
Comparing version 0.0.12 to 0.0.13
declare module "types" { | ||
import { Page, RequestCtx } from "@ekino/rendr-core"; | ||
export type Loader = (ctx: RequestCtx) => Promise<Page | void> | void; | ||
export type PageCreator = (basePage: Page, ctx: RequestCtx) => Promise<Page>; | ||
export type MaybePage = Promise<Page | void> | Page | void; | ||
export type Loader = (ctx: RequestCtx, page: Page, next: (page?: MaybePage) => MaybePage) => MaybePage; | ||
export type PageBuilder = (ctx: RequestCtx, page: Page) => MaybePage; | ||
export type RouteConfiguration = { | ||
path: string; | ||
matcher: (path: string) => {} | undefined; | ||
pageCreator: PageCreator; | ||
pageBuilder: PageBuilder | Loader; | ||
}; | ||
export interface InMemorySettings { | ||
[index: string]: PageCreator; | ||
[index: string]: PageBuilder | Loader; | ||
} | ||
@@ -23,5 +24,8 @@ } | ||
declare module "index" { | ||
import { Loader } from "types"; | ||
export * from "types"; | ||
export * from "services/inmemory"; | ||
export * from "services/api"; | ||
export const createChainedLoader: (loaders: Loader[]) => Loader; | ||
export const errorBoundaryLoader: Loader; | ||
} |
@@ -64,6 +64,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
matcher: route(path), | ||
pageCreator: paths[path] | ||
pageBuilder: paths[path] | ||
}); | ||
} | ||
return function (ctx) { return __awaiter(_this, void 0, void 0, function () { | ||
return function (ctx, page, next) { return __awaiter(_this, void 0, void 0, function () { | ||
var result; | ||
@@ -85,3 +85,3 @@ return __generator(this, function (_a) { | ||
} | ||
return [4, result.pageCreator(new rendr_core_1.Page(), ctx)]; | ||
return [4, result.pageBuilder(ctx, page, function () { })]; | ||
case 1: return [2, _a.sent()]; | ||
@@ -108,3 +108,3 @@ } | ||
var _this = this; | ||
return function (ctx) { return __awaiter(_this, void 0, void 0, function () { | ||
return function (ctx, page, next) { return __awaiter(_this, void 0, void 0, function () { | ||
var url, headers, responseType, response; | ||
@@ -134,6 +134,7 @@ return __generator(this, function (_a) { | ||
if (!("x-rendr-content-type" in response.headers)) { | ||
return [2]; | ||
return [2, next()]; | ||
} | ||
if (ctx.isClientSide) { | ||
return [2, rendr_core_2.createPage(response.data)]; | ||
page = rendr_core_2.createPage(response.data); | ||
return [2, next(page)]; | ||
} | ||
@@ -186,3 +187,3 @@ if (ctx.isServerSide) { | ||
}); | ||
define("index", ["require", "exports", "services/inmemory", "services/api"], function (require, exports, inmemory_1, api_1) { | ||
define("index", ["require", "exports", "@ekino/rendr-core", "services/inmemory", "services/api"], function (require, exports, rendr_core_3, inmemory_1, api_1) { | ||
"use strict"; | ||
@@ -195,3 +196,57 @@ function __export(m) { | ||
__export(api_1); | ||
exports.createChainedLoader = function (loaders) { | ||
return function (ctx, page, next) { return __awaiter(void 0, void 0, void 0, function () { | ||
function internalNext(nextPage) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var loader; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (nextPage instanceof rendr_core_3.Page) { | ||
internalPage = nextPage; | ||
} | ||
loader = loaders[i]; | ||
if (!loader) { | ||
return [2, internalPage]; | ||
} | ||
i++; | ||
return [4, loader(ctx, internalPage, internalNext)]; | ||
case 1: return [2, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
} | ||
var i, internalPage; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
i = 0; | ||
internalPage = page; | ||
return [4, internalNext()]; | ||
case 1: return [2, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
}; | ||
exports.errorBoundaryLoader = function (ctx, page, next) { return __awaiter(void 0, void 0, void 0, function () { | ||
var resultPage, err_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4, next()]; | ||
case 1: | ||
resultPage = _a.sent(); | ||
return [3, 3]; | ||
case 2: | ||
err_1 = _a.sent(); | ||
resultPage = rendr_core_3.createPage(); | ||
resultPage.statusCode = err_1 instanceof rendr_core_3.NotFoundError ? 404 : 500; | ||
resultPage.settings.message = err_1.message; | ||
return [3, 3]; | ||
case 3: return [2, resultPage]; | ||
} | ||
}); | ||
}); }; | ||
}); | ||
//# sourceMappingURL=rendr-core.js.map |
@@ -0,3 +1,6 @@ | ||
import { Loader } from "./types"; | ||
export * from "./types"; | ||
export * from "./services/inmemory"; | ||
export * from "./services/api"; | ||
export declare const createChainedLoader: (loaders: Loader[]) => Loader; | ||
export declare const errorBoundaryLoader: Loader; |
@@ -0,3 +1,94 @@ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
import { Page, createPage, NotFoundError } from "@ekino/rendr-core"; | ||
export * from "./services/inmemory"; | ||
export * from "./services/api"; | ||
export var createChainedLoader = function (loaders) { | ||
return function (ctx, page, next) { return __awaiter(void 0, void 0, void 0, function () { | ||
function internalNext(nextPage) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var loader; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (nextPage instanceof Page) { | ||
internalPage = nextPage; | ||
} | ||
loader = loaders[i]; | ||
if (!loader) { | ||
return [2, internalPage]; | ||
} | ||
i++; | ||
return [4, loader(ctx, internalPage, internalNext)]; | ||
case 1: return [2, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
} | ||
var i, internalPage; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
i = 0; | ||
internalPage = page; | ||
return [4, internalNext()]; | ||
case 1: return [2, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
}; | ||
export var errorBoundaryLoader = function (ctx, page, next) { return __awaiter(void 0, void 0, void 0, function () { | ||
var resultPage, err_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4, next()]; | ||
case 1: | ||
resultPage = _a.sent(); | ||
return [3, 3]; | ||
case 2: | ||
err_1 = _a.sent(); | ||
resultPage = createPage(); | ||
resultPage.statusCode = err_1 instanceof NotFoundError ? 404 : 500; | ||
resultPage.settings.message = err_1.message; | ||
return [3, 3]; | ||
case 3: return [2, resultPage]; | ||
} | ||
}); | ||
}); }; | ||
//# sourceMappingURL=index.js.map |
@@ -50,3 +50,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
var _this = this; | ||
return function (ctx) { return __awaiter(_this, void 0, void 0, function () { | ||
return function (ctx, page, next) { return __awaiter(_this, void 0, void 0, function () { | ||
var url, headers, responseType, response; | ||
@@ -76,6 +76,7 @@ return __generator(this, function (_a) { | ||
if (!("x-rendr-content-type" in response.headers)) { | ||
return [2]; | ||
return [2, next()]; | ||
} | ||
if (ctx.isClientSide) { | ||
return [2, createPage(response.data)]; | ||
page = createPage(response.data); | ||
return [2, next(page)]; | ||
} | ||
@@ -82,0 +83,0 @@ if (ctx.isServerSide) { |
@@ -37,3 +37,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { Page, NotFoundError } from "@ekino/rendr-core"; | ||
import { NotFoundError } from "@ekino/rendr-core"; | ||
import createMatcher from "path-match"; | ||
@@ -56,6 +56,6 @@ var route = createMatcher({ | ||
matcher: route(path), | ||
pageCreator: paths[path] | ||
pageBuilder: paths[path] | ||
}); | ||
} | ||
return function (ctx) { return __awaiter(_this, void 0, void 0, function () { | ||
return function (ctx, page, next) { return __awaiter(_this, void 0, void 0, function () { | ||
var result; | ||
@@ -77,3 +77,3 @@ return __generator(this, function (_a) { | ||
} | ||
return [4, result.pageCreator(new Page(), ctx)]; | ||
return [4, result.pageBuilder(ctx, page, function () { })]; | ||
case 1: return [2, _a.sent()]; | ||
@@ -80,0 +80,0 @@ } |
import { Page, RequestCtx } from "@ekino/rendr-core"; | ||
export declare type Loader = (ctx: RequestCtx) => Promise<Page | void> | void; | ||
export declare type PageCreator = (basePage: Page, ctx: RequestCtx) => Promise<Page>; | ||
export declare type MaybePage = Promise<Page | void> | Page | void; | ||
export declare type Loader = (ctx: RequestCtx, page: Page, next: (page?: MaybePage) => MaybePage) => MaybePage; | ||
export declare type PageBuilder = (ctx: RequestCtx, page: Page) => MaybePage; | ||
export declare type RouteConfiguration = { | ||
path: string; | ||
matcher: (path: string) => {} | undefined; | ||
pageCreator: PageCreator; | ||
pageBuilder: PageBuilder | Loader; | ||
}; | ||
export interface InMemorySettings { | ||
[index: string]: PageCreator; | ||
[index: string]: PageBuilder | Loader; | ||
} |
@@ -0,3 +1,6 @@ | ||
import { Loader } from "./types"; | ||
export * from "./types"; | ||
export * from "./services/inmemory"; | ||
export * from "./services/api"; | ||
export declare const createChainedLoader: (loaders: Loader[]) => Loader; | ||
export declare const errorBoundaryLoader: Loader; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
function __export(m) { | ||
@@ -6,4 +42,59 @@ for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var rendr_core_1 = require("@ekino/rendr-core"); | ||
__export(require("./services/inmemory")); | ||
__export(require("./services/api")); | ||
exports.createChainedLoader = function (loaders) { | ||
return function (ctx, page, next) { return __awaiter(void 0, void 0, void 0, function () { | ||
function internalNext(nextPage) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var loader; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (nextPage instanceof rendr_core_1.Page) { | ||
internalPage = nextPage; | ||
} | ||
loader = loaders[i]; | ||
if (!loader) { | ||
return [2, internalPage]; | ||
} | ||
i++; | ||
return [4, loader(ctx, internalPage, internalNext)]; | ||
case 1: return [2, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
} | ||
var i, internalPage; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
i = 0; | ||
internalPage = page; | ||
return [4, internalNext()]; | ||
case 1: return [2, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
}; | ||
exports.errorBoundaryLoader = function (ctx, page, next) { return __awaiter(void 0, void 0, void 0, function () { | ||
var resultPage, err_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4, next()]; | ||
case 1: | ||
resultPage = _a.sent(); | ||
return [3, 3]; | ||
case 2: | ||
err_1 = _a.sent(); | ||
resultPage = rendr_core_1.createPage(); | ||
resultPage.statusCode = err_1 instanceof rendr_core_1.NotFoundError ? 404 : 500; | ||
resultPage.settings.message = err_1.message; | ||
return [3, 3]; | ||
case 3: return [2, resultPage]; | ||
} | ||
}); | ||
}); }; | ||
//# sourceMappingURL=index.js.map |
@@ -55,3 +55,3 @@ "use strict"; | ||
var _this = this; | ||
return function (ctx) { return __awaiter(_this, void 0, void 0, function () { | ||
return function (ctx, page, next) { return __awaiter(_this, void 0, void 0, function () { | ||
var url, headers, responseType, response; | ||
@@ -81,6 +81,7 @@ return __generator(this, function (_a) { | ||
if (!("x-rendr-content-type" in response.headers)) { | ||
return [2]; | ||
return [2, next()]; | ||
} | ||
if (ctx.isClientSide) { | ||
return [2, rendr_core_1.createPage(response.data)]; | ||
page = rendr_core_1.createPage(response.data); | ||
return [2, next(page)]; | ||
} | ||
@@ -87,0 +88,0 @@ if (ctx.isServerSide) { |
@@ -60,6 +60,6 @@ "use strict"; | ||
matcher: route(path), | ||
pageCreator: paths[path] | ||
pageBuilder: paths[path] | ||
}); | ||
} | ||
return function (ctx) { return __awaiter(_this, void 0, void 0, function () { | ||
return function (ctx, page, next) { return __awaiter(_this, void 0, void 0, function () { | ||
var result; | ||
@@ -81,3 +81,3 @@ return __generator(this, function (_a) { | ||
} | ||
return [4, result.pageCreator(new rendr_core_1.Page(), ctx)]; | ||
return [4, result.pageBuilder(ctx, page, function () { })]; | ||
case 1: return [2, _a.sent()]; | ||
@@ -84,0 +84,0 @@ } |
import { Page, RequestCtx } from "@ekino/rendr-core"; | ||
export declare type Loader = (ctx: RequestCtx) => Promise<Page | void> | void; | ||
export declare type PageCreator = (basePage: Page, ctx: RequestCtx) => Promise<Page>; | ||
export declare type MaybePage = Promise<Page | void> | Page | void; | ||
export declare type Loader = (ctx: RequestCtx, page: Page, next: (page?: MaybePage) => MaybePage) => MaybePage; | ||
export declare type PageBuilder = (ctx: RequestCtx, page: Page) => MaybePage; | ||
export declare type RouteConfiguration = { | ||
path: string; | ||
matcher: (path: string) => {} | undefined; | ||
pageCreator: PageCreator; | ||
pageBuilder: PageBuilder | Loader; | ||
}; | ||
export interface InMemorySettings { | ||
[index: string]: PageCreator; | ||
[index: string]: PageBuilder | Loader; | ||
} |
{ | ||
"name": "@ekino/rendr-loader", | ||
"license": "MIT", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"main": "dist/lib/index.js", | ||
@@ -13,3 +13,3 @@ "typing": "dist/lib/index.d.ts", | ||
"dependencies": { | ||
"@ekino/rendr-core": "0.0.12", | ||
"@ekino/rendr-core": "0.0.13", | ||
"axios": "^0.19.0", | ||
@@ -26,3 +26,3 @@ "path-match": "^1.2.4", | ||
}, | ||
"gitHead": "b98b2ce22a1baff12a5c89262b28464d8701f5b8" | ||
"gitHead": "e9fcc0a6671174e9a2c54ac38bf3f8833143d568" | ||
} |
@@ -0,3 +1,44 @@ | ||
import { Loader } from "./types"; | ||
import { Page, createPage, NotFoundError } from "@ekino/rendr-core"; | ||
export * from "./types"; | ||
export * from "./services/inmemory"; | ||
export * from "./services/api"; | ||
export const createChainedLoader: (loaders: Loader[]) => Loader = loaders => { | ||
return async (ctx, page, next) => { | ||
let i = 0; | ||
let internalPage = page; | ||
async function internalNext(nextPage?: Page) { | ||
if (nextPage instanceof Page) { | ||
internalPage = nextPage; | ||
} | ||
const loader = loaders[i]; | ||
if (!loader) { | ||
return internalPage; | ||
} | ||
i++; | ||
return await loader(ctx, internalPage, internalNext); | ||
} | ||
return await internalNext(); | ||
}; | ||
}; | ||
// Simple version of a loader that catches errors during the execution of | ||
// following loaders | ||
// Feel free to use your own if you want to manage other error codes | ||
export const errorBoundaryLoader: Loader = async (ctx, page, next) => { | ||
let resultPage: Page | void; | ||
try { | ||
resultPage = await next(); | ||
} catch (err) { | ||
resultPage = createPage(); | ||
resultPage.statusCode = err instanceof NotFoundError ? 404 : 500; | ||
resultPage.settings.message = err.message; | ||
} | ||
return resultPage; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { RequestCtx, createPage, Page } from "@ekino/rendr-core"; | ||
import { createPage, Page } from "@ekino/rendr-core"; | ||
import { Readable, Writable } from "stream"; | ||
@@ -21,3 +21,3 @@ import Axios, { ResponseType } from "axios"; | ||
export function createApiLoader(baseUrl: string): Loader { | ||
return async (ctx: RequestCtx) => { | ||
return async (ctx, page, next) => { | ||
const url = `${baseUrl}${ctx.asPath}`; | ||
@@ -50,3 +50,3 @@ | ||
// @todo: check how we can add a logger here | ||
return; | ||
return next(); | ||
} | ||
@@ -57,3 +57,4 @@ | ||
if (ctx.isClientSide) { | ||
return createPage(response.data); | ||
page = createPage(response.data); | ||
return next(page); | ||
} | ||
@@ -60,0 +61,0 @@ |
@@ -24,3 +24,3 @@ import { RequestCtx, Page } from "@ekino/rendr-core"; | ||
const paths: InMemorySettings = { | ||
"/blog/:id": (basePage, ctx) => { | ||
"/blog/:id": (ctx: RequestCtx, basePage: Page) => { | ||
basePage.statusCode = 419; | ||
@@ -33,3 +33,3 @@ | ||
}, | ||
"/": basePage => { | ||
"/": (_ctx: RequestCtx, basePage: Page) => { | ||
basePage.statusCode = 418; | ||
@@ -63,3 +63,5 @@ return Promise.resolve(basePage); | ||
const result = await loader( | ||
createContext({ pathname: check.pathname }) | ||
createContext({ pathname: check.pathname }), | ||
new Page(), | ||
() => {} | ||
); | ||
@@ -66,0 +68,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Page, RequestCtx, NotFoundError } from "@ekino/rendr-core"; | ||
import { NotFoundError } from "@ekino/rendr-core"; | ||
import { Loader, InMemorySettings, RouteConfiguration } from "../types"; | ||
@@ -26,7 +26,7 @@ // @ts-ignore - definition does not exist... | ||
matcher: route(path), | ||
pageCreator: paths[path] | ||
pageBuilder: paths[path] | ||
}); | ||
} | ||
return async (ctx: RequestCtx) => { | ||
return async (ctx, page, next) => { | ||
const result = routes.find(conf => { | ||
@@ -51,4 +51,4 @@ const { matcher, path } = conf; | ||
return await result.pageCreator(new Page(), ctx); | ||
return await result.pageBuilder(ctx, page, () => {}); | ||
}; | ||
} |
import { Page, RequestCtx } from "@ekino/rendr-core"; | ||
export type Loader = (ctx: RequestCtx) => Promise<Page | void> | void; | ||
export type MaybePage = Promise<Page | void> | Page | void; | ||
export type PageCreator = (basePage: Page, ctx: RequestCtx) => Promise<Page>; | ||
export type Loader = ( | ||
ctx: RequestCtx, | ||
page: Page, | ||
next: (page?: MaybePage) => MaybePage | ||
) => MaybePage; | ||
export type PageBuilder = (ctx: RequestCtx, page: Page) => MaybePage; | ||
export type RouteConfiguration = { | ||
path: string; | ||
matcher: (path: string) => {} | undefined; | ||
pageCreator: PageCreator; | ||
pageBuilder: PageBuilder | Loader; | ||
}; | ||
export interface InMemorySettings { | ||
[index: string]: PageCreator; | ||
[index: string]: PageBuilder | Loader; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
75163
39
1412
+ Added@ekino/rendr-core@0.0.13(transitive)
- Removed@ekino/rendr-core@0.0.12(transitive)
Updated@ekino/rendr-core@0.0.13