diff --git a/deno.lock b/deno.lock index 0adc9ab62..6ff6d0d79 100644 --- a/deno.lock +++ b/deno.lock @@ -60,6 +60,11 @@ "https://deno.land/std@0.178.0/uuid/v1.ts": "fe36009afce7ced96e1b5928565e12c5a8eb0df1a2b5063c0a72bda6b75c0de5", "https://deno.land/std@0.178.0/uuid/v4.ts": "0f081880c156fd59b9e44e2f84ea0f94a3627e89c224eaf6cc982b53d849f37e", "https://deno.land/std@0.178.0/uuid/v5.ts": "10558a9c09a06b86fef9e61205180b9585ec4fe3fed7d696e675b8e118f74e8e", + "https://deno.land/std@0.179.0/fmt/colors.ts": "938c5d44d889fb82eff6c358bea8baa7e85950a16c9f6dae3ec3a7a729164471", + "https://deno.land/std@0.179.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", + "https://deno.land/std@0.179.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", + "https://deno.land/std@0.179.0/testing/asserts.ts": "984ab0bfb3faeed92ffaa3a6b06536c66811185328c5dd146257c702c41b01ab", + "https://deno.land/std@0.179.0/testing/mock.ts": "220ed9b8151cb2cac141043d4cfea7c47673fab5d18d1c1f0943297c8afb5d13", "https://deno.land/std@0.181.0/_util/asserts.ts": "178dfc49a464aee693a7e285567b3d0b555dc805ff490505a8aae34f9cfb1462", "https://deno.land/std@0.181.0/_util/os.ts": "d932f56d41e4f6a6093d56044e29ce637f8dcc43c5a90af43504a889cf1775e3", "https://deno.land/std@0.181.0/async/abortable.ts": "fd682fa46f3b7b16b4606a5ab52a7ce309434b76f820d3221bdfb862719a15d7", @@ -124,8 +129,12 @@ "https://deno.land/std@0.181.0/path/separator.ts": "0fb679739d0d1d7bf45b68dacfb4ec7563597a902edbaf3c59b50d5bcadd93b1", "https://deno.land/std@0.181.0/path/win32.ts": "d186344e5583bcbf8b18af416d13d82b35a317116e6460a5a3953508c3de5bba", "https://deno.land/std@0.181.0/semver/mod.ts": "200f50cf6872212667df532fb09f0b1a33d3427a5201f75fad30a0d0c6dbcce3", + "https://deno.land/std@0.181.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", + "https://deno.land/std@0.181.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", + "https://deno.land/std@0.181.0/testing/asserts.ts": "e16d98b4d73ffc4ed498d717307a12500ae4f2cbe668f1a215632d19fcffc22f", "https://deno.land/std@0.186.0/encoding/base64.ts": "144ae6234c1fbe5b68666c711dc15b1e9ee2aef6d42b3b4345bf9a6c91d70d0d", "https://deno.land/std@0.61.0/_util/assert.ts": "e1f76e77c5ccb5a8e0dbbbe6cce3a56d2556c8cb5a9a8802fc9565af72462149", + "https://deno.land/std@0.61.0/hash/sha1.ts": "c1a97bde767b98b88495470f39c30c37e44ac3984409f120ef65fd84c9d27608", "https://deno.land/std@0.61.0/path/_constants.ts": "e11f32a36644e04dce243f3c1f30c02cc5d149827f48a755628176f0707cfc70", "https://deno.land/std@0.61.0/path/_globrex.ts": "696996deed47bd98fcab9de0034233380ead443a5cd702631151c6a71e3d21a2", "https://deno.land/std@0.61.0/path/_interface.ts": "5876f91d35fd42624893a4aaddaee352144e1f46e719f1dde6511bab7c3c1029", diff --git a/engine/releases/pages.ts b/engine/releases/pages.ts index 547edcf8f..fdbf316d2 100644 --- a/engine/releases/pages.ts +++ b/engine/releases/pages.ts @@ -171,10 +171,13 @@ function mapGlobalToAccount( } c[middlewareConfig] = { ...middleware, - [state]: { + [state]: [ ...middleware[state], - [name]: wellKnownAccount ? { __resolveType: name } : globalSection.props, - }, + { + key: name, + value: wellKnownAccount ? { __resolveType: name } : globalSection.props, + }, + ], }; return c; } @@ -237,10 +240,8 @@ const baseEntrypoint = Object.freeze({ __resolveType: "$live/flags/everyone.ts", }, [middlewareConfig]: { - __resolveType: "resolve", - [state]: { - __resolveType: "resolve", - }, + __resolveType: "$live/loaders/state.ts", + [state]: [], }, [ENTRYPOINT]: { audiences: [ @@ -411,7 +412,7 @@ const pagesToConfig = ( flags: Pick[], ns: string, ) => { - const configs = p.sort((pageA, pageB) => + const { [globalSections]: _, ...configs } = p.sort((pageA, pageB) => pageA.state === "global" ? -1 : pageB.state === "global" ? 1 : 0 ) // process global first .reduce(pageToConfig(ns), structuredClone(baseEntrypoint)); diff --git a/handlers/routesSelection.ts b/handlers/routesSelection.ts index c391d8ad0..6a2c80e89 100644 --- a/handlers/routesSelection.ts +++ b/handlers/routesSelection.ts @@ -43,7 +43,7 @@ const createUrlPatternFromHref = (href: string) => { export const router = ( routes: Route[], - hrefRoutes: Record>, + hrefRoutes: Record> = {}, configs?: ResolveOptions, flags?: Map, ): Handler => { diff --git a/loaders/state.ts b/loaders/state.ts index b87b8966e..fcc25c3c5 100644 --- a/loaders/state.ts +++ b/loaders/state.ts @@ -1,4 +1,5 @@ import { Resolvable } from "../engine/core/resolver.ts"; +import { LoaderContext } from "../mod.ts"; import { MiddlewareConfig } from "../routes/_middleware.ts"; export interface StateProp { @@ -13,13 +14,21 @@ export interface Props { * @title Shared application State Loader. * @description Set the application state using resolvables. */ -export default function StateLoader( +export default async function StateLoader( { state }: Props, -): MiddlewareConfig { + _req: Request, + { get }: LoaderContext, +): Promise { + const mState: Promise<[string, Resolvable]>[] = []; + + for (const { key, value } of state) { + const resolved = get(value).then((resolved) => + [key, resolved] as [string, Resolvable] + ); + mState.push(resolved); + } + return { - state: state.reduce((acc, st) => { - acc[st.key] = st.value; - return acc; - }, {} as Record), + state: Object.fromEntries(await Promise.all(mState)), }; }