@analogjs/router 3.0.0-alpha.92 → 3.0.0-alpha.93
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/fesm2022/analogjs-router-i18n.mjs +4 -0
- package/fesm2022/analogjs-router-i18n.mjs.map +1 -1
- package/fesm2022/analogjs-router-server-actions.mjs +416 -2
- package/fesm2022/analogjs-router-server-actions.mjs.map +1 -0
- package/fesm2022/analogjs-router-server.mjs +294 -63
- package/fesm2022/analogjs-router-server.mjs.map +1 -1
- package/fesm2022/analogjs-router-tanstack-query-server.mjs +4 -4
- package/fesm2022/analogjs-router-tanstack-query-server.mjs.map +1 -1
- package/fesm2022/analogjs-router-tanstack-query.mjs +70 -2
- package/fesm2022/analogjs-router-tanstack-query.mjs.map +1 -1
- package/fesm2022/analogjs-router-tokens.mjs.map +1 -1
- package/fesm2022/analogjs-router.mjs +144 -78
- package/fesm2022/analogjs-router.mjs.map +1 -1
- package/fesm2022/debug.page.mjs +3 -3
- package/fesm2022/route-files.mjs +1 -1
- package/package.json +4 -4
- package/types/server/actions/src/define-action.d.ts +8 -15
- package/types/server/actions/src/define-api-route.d.ts +2 -3
- package/types/server/actions/src/define-page-load.d.ts +8 -9
- package/types/server/actions/src/define-server-route.d.ts +1 -1
- package/types/server/actions/src/index.d.ts +3 -2
- package/types/server/actions/src/parse-request-data.d.ts +3 -4
- package/types/server/actions/src/standard-schema.d.ts +39 -0
- package/types/server/actions/src/validate.d.ts +1 -1
- package/types/server/src/defer-reconcile-runtime.d.ts +1 -1
- package/types/server/src/ssr-navigation.d.ts +6 -0
- package/types/server/src/utils/ssr-stream-lifecycle.d.ts +14 -0
- package/types/server/src/utils/stream-shell.d.ts +3 -0
- package/types/src/index.d.ts +2 -4
- package/types/src/lib/form-action.directive.d.ts +11 -9
- package/types/src/lib/server-fn/inject-server-fn.d.ts +1 -1
- package/types/tanstack-query/server/src/define-page-load-queries.d.ts +4 -6
- package/types/tanstack-query/server/src/index.d.ts +1 -1
- package/types/tanstack-query/server/src/provide-server-analog-query.d.ts +2 -0
- package/types/tanstack-query/src/index.d.ts +3 -2
- package/types/tanstack-query/src/server-query.d.ts +1 -1
- package/types/tokens/src/index.d.ts +8 -0
- package/fesm2022/provide-analog-query.mjs +0 -72
- package/fesm2022/provide-analog-query.mjs.map +0 -1
- package/fesm2022/src.mjs +0 -334
- package/fesm2022/src.mjs.map +0 -1
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import type { StandardSchemaV1 } from '
|
|
1
|
+
import type { StandardSchemaV1 } from './standard-schema';
|
|
2
2
|
import type { H3Event, H3EventContext } from 'h3';
|
|
3
3
|
import type { $Fetch } from 'ofetch';
|
|
4
|
-
type NodeContext = NonNullable<H3Event['node']>;
|
|
5
4
|
type OptionalSchema = StandardSchemaV1 | undefined;
|
|
6
5
|
type InferSchema<TSchema extends OptionalSchema, TFallback> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TFallback;
|
|
7
6
|
export interface PageLoadContext<TParamsSchema extends OptionalSchema = undefined, TQuerySchema extends OptionalSchema = undefined> {
|
|
8
7
|
params: InferSchema<TParamsSchema, H3EventContext['params']>;
|
|
9
8
|
query: InferSchema<TQuerySchema, Record<string, string | string[] | undefined>>;
|
|
10
|
-
req:
|
|
11
|
-
res:
|
|
9
|
+
req: H3Event['node']['req'];
|
|
10
|
+
res: H3Event['node']['res'];
|
|
12
11
|
fetch: $Fetch;
|
|
13
12
|
event: H3Event;
|
|
14
13
|
}
|
|
@@ -21,9 +20,9 @@ export interface DefinePageLoadOptions<TParamsSchema extends OptionalSchema = un
|
|
|
21
20
|
* Creates a typed page server load function with optional
|
|
22
21
|
* Standard Schema validation for route params and query.
|
|
23
22
|
*
|
|
24
|
-
* Follows the same validation
|
|
25
|
-
*
|
|
26
|
-
*
|
|
23
|
+
* Follows the same validation pattern as `defineServerRoute`:
|
|
24
|
+
* validates before invoking the handler and returns
|
|
25
|
+
* `fail(422, issues)` on validation failure.
|
|
27
26
|
*
|
|
28
27
|
* @example
|
|
29
28
|
* ```typescript
|
|
@@ -47,8 +46,8 @@ export interface DefinePageLoadOptions<TParamsSchema extends OptionalSchema = un
|
|
|
47
46
|
*/
|
|
48
47
|
export declare function definePageLoad<TParamsSchema extends OptionalSchema = undefined, TQuerySchema extends OptionalSchema = undefined, TResult = unknown>(options: DefinePageLoadOptions<TParamsSchema, TQuerySchema, TResult>): (ctx: {
|
|
49
48
|
params: H3EventContext['params'];
|
|
50
|
-
req:
|
|
51
|
-
res:
|
|
49
|
+
req: H3Event['node']['req'];
|
|
50
|
+
res: H3Event['node']['res'];
|
|
52
51
|
fetch: $Fetch;
|
|
53
52
|
event: H3Event;
|
|
54
53
|
}) => Promise<TResult | Response>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StandardSchemaV1 } from '
|
|
1
|
+
import type { StandardSchemaV1 } from './standard-schema';
|
|
2
2
|
import type { H3Event } from 'h3';
|
|
3
3
|
export type DefineServerRouteResult = Response | unknown;
|
|
4
4
|
export interface ServerRouteHandler<TQuery = unknown, TBody = unknown, TResult = unknown> {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export type { PageServerAction } from './actions';
|
|
2
2
|
export { json, redirect, fail } from './actions';
|
|
3
|
-
export { defineAction } from './define-action';
|
|
4
|
-
export type { DefineActionContext, DefineActionOptions } from './define-action';
|
|
5
3
|
export { defineServerRoute } from './define-server-route';
|
|
6
4
|
export type { DefineServerRouteContext, DefineServerRouteOptions, DefineServerRouteResult, ServerRouteHandler, InferRouteQuery, InferRouteBody, InferRouteResult, } from './define-server-route';
|
|
7
5
|
export { definePageLoad } from './define-page-load';
|
|
8
6
|
export type { PageLoadContext, DefinePageLoadOptions, } from './define-page-load';
|
|
9
7
|
export { validateWithSchema } from './validate';
|
|
8
|
+
export type { StandardSchemaV1 } from './standard-schema';
|
|
9
|
+
export { defineAction, type DefineActionContext, type DefineActionOptions, } from './define-action';
|
|
10
|
+
export { defineApiRoute, type DefineApiRouteContext, type DefineApiRouteOptions, type DefineApiRouteResult, } from './define-api-route';
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import type { H3Event } from 'h3';
|
|
1
2
|
type RequestEntryValue = string | File;
|
|
2
3
|
type ParsedRequestValue = RequestEntryValue | RequestEntryValue[];
|
|
4
|
+
export declare function getRequestUrl(event: H3Event): string;
|
|
3
5
|
export declare function parseSearchParams(searchParams: URLSearchParams): Record<string, ParsedRequestValue>;
|
|
4
6
|
export declare function parseFormData(formData: FormData): Record<string, ParsedRequestValue>;
|
|
5
|
-
export declare function parseRequestData(event:
|
|
6
|
-
method: string;
|
|
7
|
-
headers: Headers;
|
|
8
|
-
}): Promise<unknown>;
|
|
7
|
+
export declare function parseRequestData(event: H3Event): Promise<unknown>;
|
|
9
8
|
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Standard Schema interface, inlined from the spec at
|
|
3
|
+
* https://standardschema.dev so no runtime dependency is required.
|
|
4
|
+
*/
|
|
5
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
6
|
+
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
|
|
7
|
+
}
|
|
8
|
+
export declare namespace StandardSchemaV1 {
|
|
9
|
+
interface Props<Input = unknown, Output = Input> {
|
|
10
|
+
readonly version: 1;
|
|
11
|
+
readonly vendor: string;
|
|
12
|
+
readonly validate: (value: unknown, options?: Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
13
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
14
|
+
}
|
|
15
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
16
|
+
interface SuccessResult<Output> {
|
|
17
|
+
readonly value: Output;
|
|
18
|
+
readonly issues?: undefined;
|
|
19
|
+
}
|
|
20
|
+
interface FailureResult {
|
|
21
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
22
|
+
}
|
|
23
|
+
interface Issue {
|
|
24
|
+
readonly message: string;
|
|
25
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
26
|
+
}
|
|
27
|
+
interface PathSegment {
|
|
28
|
+
readonly key: PropertyKey;
|
|
29
|
+
}
|
|
30
|
+
interface Options {
|
|
31
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
32
|
+
}
|
|
33
|
+
interface Types<Input = unknown, Output = Input> {
|
|
34
|
+
readonly input: Input;
|
|
35
|
+
readonly output: Output;
|
|
36
|
+
}
|
|
37
|
+
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
|
|
38
|
+
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
|
|
39
|
+
}
|
|
@@ -20,4 +20,4 @@
|
|
|
20
20
|
* Emitted into the document by `renderStream`. Exported as a string so it can
|
|
21
21
|
* be injected verbatim and unit-tested against a DOM.
|
|
22
22
|
*/
|
|
23
|
-
export declare const DEFER_RECONCILE_RUNTIME = "\n(function () {\n function region() {\n return document.querySelector('[data-analog-stream]');\n }\n window.__analogPaint = function (id) {\n var tpl = document.querySelector('template[data-analog-defer=\"' + id + '\"]');\n var r = region();\n if (!tpl || !r) return;\n r.appendChild(tpl.content.cloneNode(true));\n tpl.remove();\n };\n window.__analogReconcileHead = function () {\n // The shell head was flushed before the app rendered, so any title/meta the\n // app set during render (Title/Meta services, route meta) is missing from\n // the live document. Apply the authoritative head here, before hydration \u2014\n // matching how a buffered render would have produced the head. Idempotent:\n // tags already present (charset, viewport, stylesheet/preload links) are\n // matched and left as-is; only changed/added ones are updated.\n var tpl = document.querySelector('template[data-analog-head]');\n if (!tpl) return;\n var frag = tpl.content;\n var head = document.head;\n var title = frag.querySelector('title');\n if (title) document.title = title.textContent || '';\n function metaKey(m) {\n if (m.hasAttribute('charset')) return 'charset';\n var attrs = ['name', 'property', 'http-equiv', 'itemprop'];\n for (var i = 0; i < attrs.length; i++) {\n if (m.hasAttribute(attrs[i])) return attrs[i] + '=' + m.getAttribute(attrs[i]);\n }\n return null;\n }\n var existingMeta = {};\n var metas = head.querySelectorAll('meta');\n for (var i = 0; i < metas.length; i++) {\n var k = metaKey(metas[i]);\n if (k) existingMeta[k] = metas[i];\n }\n frag.querySelectorAll('meta').forEach(function (m) {\n var key = metaKey(m);\n if (key == null) return;\n if (existingMeta[key]) existingMeta[key].replaceWith(m.cloneNode(true));\n else head.appendChild(m.cloneNode(true));\n });\n var existingHref = {};\n var links = head.querySelectorAll('link[href]');\n for (var j = 0; j < links.length; j++) {\n existingHref[links[j].getAttribute('href')] = true;\n }\n frag.querySelectorAll('link').forEach(function (l) {\n var href = l.getAttribute('href');\n if (href && existingHref[href]) return;\n head.appendChild(l.cloneNode(true));\n if (href) existingHref[href] = true;\n });\n tpl.remove();\n };\n window.__analogFinalize = function () {\n var auth = document.querySelector('template[data-analog-authoritative]');\n if (!auth) return;\n // Replace the entire body \u2014 preview region, block templates and runtime\n // scripts \u2014 with just the authoritative body, so the reconciled DOM matches\n // a buffered render byte-for-byte before hydration boots.\n document.body.replaceChildren(
|
|
23
|
+
export declare const DEFER_RECONCILE_RUNTIME = "\n(function () {\n var completed = false;\n var headModules = [];\n function activateModule(source) {\n var script = document.createElement('script');\n Array.from(source.attributes).forEach(function (attr) {\n script.setAttribute(attr.name, attr.value);\n });\n if (source.hasAttribute('nonce')) script.nonce = source.nonce;\n if (!source.hasAttribute('async')) script.async = false;\n script.textContent = source.textContent;\n return script;\n }\n function region() {\n return document.querySelector('[data-analog-stream]');\n }\n function showError() {\n document.title = 'Unable to load this page';\n var robots = document.head.querySelector('meta[name=\"robots\"]');\n if (!robots) {\n robots = document.createElement('meta');\n robots.setAttribute('name', 'robots');\n document.head.appendChild(robots);\n }\n robots.setAttribute('content', 'noindex');\n var error = document.createElement('main');\n error.setAttribute('data-analog-render-error', '');\n error.setAttribute('role', 'alert');\n var heading = document.createElement('h1');\n heading.textContent = 'Unable to load this page';\n var message = document.createElement('p');\n message.textContent = 'The page could not finish loading.';\n error.appendChild(heading);\n error.appendChild(message);\n document.body.replaceChildren(error);\n }\n function checkCompletion() {\n if (!completed && region()) showError();\n }\n window.__analogFail = showError;\n // A Worker HTTP adapter can turn a stream error into ordinary EOF. The\n // authoritative tail, rather than transport completion, proves SSR success.\n document.addEventListener('DOMContentLoaded', checkCompletion, { once: true });\n window.__analogPaint = function (id) {\n var tpl = document.querySelector('template[data-analog-defer=\"' + id + '\"]');\n var r = region();\n if (!tpl || !r) return;\n r.appendChild(tpl.content.cloneNode(true));\n tpl.remove();\n };\n window.__analogReconcileHead = function () {\n // The shell head was flushed before the app rendered, so any title/meta the\n // app set during render (Title/Meta services, route meta) is missing from\n // the live document. Apply the authoritative head here, before hydration \u2014\n // matching how a buffered render would have produced the head. Idempotent:\n // tags already present (charset, viewport, stylesheet/preload links) are\n // matched and left as-is; only changed/added ones are updated.\n var tpl = document.querySelector('template[data-analog-head]');\n if (!tpl) return;\n var frag = tpl.content;\n var head = document.head;\n frag.querySelectorAll('script[type=\"module\"]').forEach(function (script) {\n headModules.push(script.cloneNode(true));\n });\n var title = frag.querySelector('title');\n if (title) document.title = title.textContent || '';\n function metaKey(m) {\n if (m.hasAttribute('charset')) return 'charset';\n var attrs = ['name', 'property', 'http-equiv', 'itemprop'];\n for (var i = 0; i < attrs.length; i++) {\n if (m.hasAttribute(attrs[i])) return attrs[i] + '=' + m.getAttribute(attrs[i]);\n }\n return null;\n }\n var existingMeta = {};\n var metas = head.querySelectorAll('meta');\n for (var i = 0; i < metas.length; i++) {\n var k = metaKey(metas[i]);\n if (k) existingMeta[k] = metas[i];\n }\n frag.querySelectorAll('meta').forEach(function (m) {\n var key = metaKey(m);\n if (key == null) return;\n if (existingMeta[key]) existingMeta[key].replaceWith(m.cloneNode(true));\n else head.appendChild(m.cloneNode(true));\n });\n var existingHref = {};\n var links = head.querySelectorAll('link[href]');\n for (var j = 0; j < links.length; j++) {\n existingHref[links[j].getAttribute('href')] = true;\n }\n frag.querySelectorAll('link').forEach(function (l) {\n var href = l.getAttribute('href');\n if (href && existingHref[href]) return;\n head.appendChild(l.cloneNode(true));\n if (href) existingHref[href] = true;\n });\n tpl.remove();\n };\n window.__analogFinalize = function () {\n var auth = document.querySelector('template[data-analog-authoritative]');\n if (!auth) return;\n completed = true;\n document.removeEventListener('DOMContentLoaded', checkCompletion);\n // Replace the entire body \u2014 preview region, block templates and runtime\n // scripts \u2014 with just the authoritative body, so the reconciled DOM matches\n // a buffered render byte-for-byte before hydration boots.\n var body = auth.content.cloneNode(true);\n var bodyModules = Array.from(body.querySelectorAll('script[type=\"module\"]'));\n document.body.replaceChildren(body);\n headModules.forEach(function (script) {\n document.head.appendChild(activateModule(script));\n });\n headModules = [];\n bodyModules.forEach(function (script) {\n script.replaceWith(activateModule(script));\n });\n };\n})();\n";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type EnvironmentProviders } from '@angular/core';
|
|
2
|
+
/** Angular can settle initial navigation after an error without rejecting renderApplication. */
|
|
3
|
+
export declare function createSsrNavigationTracker(): {
|
|
4
|
+
provider: EnvironmentProviders;
|
|
5
|
+
throwIfFailed: () => void;
|
|
6
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Owns stream closure, queued block flushes and platform cleanup across completion and cancellation. */
|
|
2
|
+
export interface SsrStreamWriter {
|
|
3
|
+
readonly active: boolean;
|
|
4
|
+
enqueue(html: string): void;
|
|
5
|
+
scheduleBlock(serialize: () => string): void;
|
|
6
|
+
finishBlocks(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare function createSsrStream(options: {
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
waitUntil?(task: Promise<void>): void;
|
|
11
|
+
errorHtml?: string;
|
|
12
|
+
render(writer: SsrStreamWriter): Promise<void>;
|
|
13
|
+
destroy(): Promise<void>;
|
|
14
|
+
}): ReadableStream<Uint8Array>;
|
package/types/src/index.d.ts
CHANGED
|
@@ -10,13 +10,11 @@ export { injectLoad, injectLoadData } from './lib/inject-load';
|
|
|
10
10
|
export { getLoadResolver } from './lib/get-load-resolver';
|
|
11
11
|
export { requestContextInterceptor } from './lib/request-context';
|
|
12
12
|
export { injectRouteEndpointURL } from './lib/inject-route-endpoint-url';
|
|
13
|
-
export { FormAction } from './lib/form-action.directive';
|
|
14
|
-
export type
|
|
13
|
+
export { FormAction, type FormActionState } from './lib/form-action.directive';
|
|
14
|
+
export { issuesToFieldErrors, issuesToFormErrors, issuePathToFieldName, type ValidationFieldErrors, } from './lib/validation-errors';
|
|
15
15
|
export { injectDebugRoutes } from './lib/debug/routes';
|
|
16
16
|
export { withDebugRoutes } from './lib/debug';
|
|
17
17
|
export type { AnalogJsonLdDocument } from './lib/json-ld';
|
|
18
|
-
export { issuesToFieldErrors, issuesToFormErrors, issuePathToFieldName, } from './lib/validation-errors';
|
|
19
|
-
export type { ValidationFieldErrors } from './lib/validation-errors';
|
|
20
18
|
export { injectServerFn, injectServerFnMutation, provideServerFnClient, ServerFnClient, } from './lib/server-fn/inject-server-fn';
|
|
21
19
|
export { createServerFnRef, type ServerFnRefConfig, } from './lib/server-fn/server-fn-ref';
|
|
22
20
|
export { SERVER_FN_DISPATCHER, type ServerFnDispatcher, } from './lib/server-fn/dispatcher';
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InputSignal, InputSignalWithTransform, OutputEmitterRef } from '@angular/core';
|
|
2
2
|
import * as i0 from "@angular/core";
|
|
3
3
|
export type FormActionState = 'submitting' | 'error' | 'redirect' | 'success' | 'navigate';
|
|
4
4
|
export declare class FormAction {
|
|
5
5
|
action: InputSignal<string>;
|
|
6
|
+
enhanceForm: InputSignalWithTransform<boolean, unknown>;
|
|
6
7
|
onSuccess: OutputEmitterRef<unknown>;
|
|
7
8
|
onError: OutputEmitterRef<unknown>;
|
|
8
9
|
state: OutputEmitterRef<FormActionState>;
|
|
10
|
+
private currentState;
|
|
11
|
+
private injector;
|
|
9
12
|
private router;
|
|
10
13
|
private route;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
submitted($event: SubmitEvent): void;
|
|
14
|
+
private path;
|
|
15
|
+
constructor();
|
|
16
|
+
submitted($event: any): void;
|
|
15
17
|
private _handleGet;
|
|
16
18
|
private _handlePost;
|
|
17
|
-
private
|
|
18
|
-
private
|
|
19
|
-
private
|
|
19
|
+
private _getPath;
|
|
20
|
+
private _handleEnhancedGet;
|
|
21
|
+
private _handleEnhancedPost;
|
|
20
22
|
private _emitState;
|
|
21
23
|
private _navigateTo;
|
|
22
24
|
private _isJSON;
|
|
23
25
|
static ɵfac: i0.ɵɵFactoryDeclaration<FormAction, never>;
|
|
24
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<FormAction, "form[action],form[method]", never, { "action": { "alias": "action"; "required": false; "isSignal": true; }; }, { "onSuccess": "onSuccess"; "onError": "onError"; "state": "state"; }, never, never, true, never>;
|
|
26
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<FormAction, "form[action],form[method],form[enhanceForm]", never, { "action": { "alias": "action"; "required": false; "isSignal": true; }; "enhanceForm": { "alias": "enhanceForm"; "required": false; "isSignal": true; }; }, { "onSuccess": "onSuccess"; "onError": "onError"; "state": "state"; }, never, never, true, never>;
|
|
25
27
|
}
|
|
@@ -21,7 +21,7 @@ export declare class ServerFnClient {
|
|
|
21
21
|
readSeed<Out>(fn: ServerFn<unknown, Out>, input: unknown): Out | undefined;
|
|
22
22
|
writeSeed<Out>(fn: ServerFn<unknown, Out>, input: unknown, value: Out): void;
|
|
23
23
|
static ɵfac: i0.ɵɵFactoryDeclaration<ServerFnClient, never>;
|
|
24
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<
|
|
24
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
25
25
|
}
|
|
26
26
|
/** No-op provider hook; ServerFnClient is `providedIn: 'root'`. */
|
|
27
27
|
export declare function provideServerFnClient(): readonly [];
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
1
|
import { QueryClient } from '@tanstack/angular-query-experimental';
|
|
3
2
|
import type { DehydratedState } from '@tanstack/angular-query-experimental';
|
|
4
3
|
import type { H3Event, H3EventContext } from 'h3';
|
|
5
4
|
import type { $Fetch } from 'ofetch';
|
|
6
|
-
import { type PageLoadContext } from '
|
|
7
|
-
export { ANALOG_QUERIES_KEY } from '
|
|
8
|
-
type NodeContext = NonNullable<H3Event['node']>;
|
|
5
|
+
import { type PageLoadContext, type StandardSchemaV1 } from '@analogjs/router/server/actions';
|
|
6
|
+
export { ANALOG_QUERIES_KEY } from '@analogjs/router/tanstack-query';
|
|
9
7
|
type OptionalSchema = StandardSchemaV1 | undefined;
|
|
10
8
|
export interface PageLoadQueriesResult<TData> {
|
|
11
9
|
__analogQueries: DehydratedState;
|
|
@@ -59,8 +57,8 @@ export interface DefinePageLoadQueriesOptions<TParamsSchema extends OptionalSche
|
|
|
59
57
|
*/
|
|
60
58
|
export declare function definePageLoadQueries<TParamsSchema extends OptionalSchema = undefined, TQuerySchema extends OptionalSchema = undefined, TData = void>(options: DefinePageLoadQueriesOptions<TParamsSchema, TQuerySchema, TData>): (ctx: {
|
|
61
59
|
params: H3EventContext['params'];
|
|
62
|
-
req:
|
|
63
|
-
res:
|
|
60
|
+
req: H3Event['node']['req'];
|
|
61
|
+
res: H3Event['node']['res'];
|
|
64
62
|
fetch: $Fetch;
|
|
65
63
|
event: H3Event;
|
|
66
64
|
}) => Promise<PageLoadQueriesResult<TData> | Response>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { provideServerAnalogQuery } from '
|
|
1
|
+
export { provideServerAnalogQuery } from './provide-server-analog-query';
|
|
2
2
|
export { definePageLoadQueries, ANALOG_QUERIES_KEY, } from './define-page-load-queries';
|
|
3
3
|
export type { PageLoadQueriesResult, DefinePageLoadQueriesOptions, } from './define-page-load-queries';
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { ANALOG_QUERIES_KEY } from './constants';
|
|
2
|
+
export { ANALOG_QUERY_STATE_KEY, provideAnalogQuery, } from './provide-analog-query';
|
|
3
|
+
export { serverQueryOptions, serverMutationOptions, serverInfiniteQueryOptions, } from './server-query';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HttpClient } from '@angular/common/http';
|
|
2
2
|
import type { CreateQueryOptions, CreateMutationOptions, CreateInfiniteQueryOptions, DefaultError, InfiniteData, QueryKey } from '@tanstack/angular-query-experimental';
|
|
3
|
-
import type { ServerRouteHandler, InferRouteQuery, InferRouteBody, InferRouteResult } from '
|
|
3
|
+
import type { ServerRouteHandler, InferRouteQuery, InferRouteBody, InferRouteResult } from '@analogjs/router/server/actions';
|
|
4
4
|
export declare function serverQueryOptions<TRoute extends ServerRouteHandler<any, any, any>, TError = DefaultError, TData = InferRouteResult<TRoute>, TQueryKey extends QueryKey = QueryKey>(http: HttpClient, url: string, options: {
|
|
5
5
|
queryKey: TQueryKey;
|
|
6
6
|
query?: InferRouteQuery<TRoute>;
|
|
@@ -10,6 +10,14 @@ export type ServerContext = {
|
|
|
10
10
|
req: ServerRequest;
|
|
11
11
|
res: ServerResponse;
|
|
12
12
|
fetch?: ServerInternalFetch;
|
|
13
|
+
/** Trusted route policy supplied by the SSR host. */
|
|
14
|
+
streaming?: boolean;
|
|
15
|
+
/** Aborted when the host request is cancelled. */
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
/** Keeps an edge request alive until stream cleanup completes. */
|
|
18
|
+
waitUntil?: (task: Promise<void>) => void;
|
|
19
|
+
/** Finish failed progressive HTTP documents with a generic error view. */
|
|
20
|
+
renderErrorsAsHtml?: boolean;
|
|
13
21
|
};
|
|
14
22
|
export declare const REQUEST: InjectionToken<ServerRequest>;
|
|
15
23
|
export declare const RESPONSE: InjectionToken<ServerResponse>;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { ResolveEnd, Router } from "@angular/router";
|
|
2
|
-
import { DestroyRef, ENVIRONMENT_INITIALIZER, PLATFORM_ID, TransferState, inject, makeEnvironmentProviders, makeStateKey } from "@angular/core";
|
|
3
|
-
import { isPlatformServer } from "@angular/common";
|
|
4
|
-
import { QueryClient, hydrate } from "@tanstack/angular-query-experimental";
|
|
5
|
-
//#region packages/router/tanstack-query/src/constants.ts
|
|
6
|
-
/**
|
|
7
|
-
* Route-data key under `ActivatedRoute.data['load']` that holds the
|
|
8
|
-
* `DehydratedState` produced by `definePageLoadQueries`. The Router-
|
|
9
|
-
* events hydrator in `provideAnalogQuery()` looks for this key on
|
|
10
|
-
* `ResolveEnd` and merges the dehydrated payload into the active
|
|
11
|
-
* `QueryClient`, so component-issued queries hit a warm cache on
|
|
12
|
-
* first render.
|
|
13
|
-
*/
|
|
14
|
-
var ANALOG_QUERIES_KEY = "__analogQueries";
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region packages/router/tanstack-query/src/provide-analog-query.ts
|
|
17
|
-
var ANALOG_QUERY_STATE_KEY = makeStateKey("analog_query_state");
|
|
18
|
-
function provideAnalogQuery() {
|
|
19
|
-
return makeEnvironmentProviders([{
|
|
20
|
-
provide: ENVIRONMENT_INITIALIZER,
|
|
21
|
-
multi: true,
|
|
22
|
-
useValue() {
|
|
23
|
-
const transferState = inject(TransferState);
|
|
24
|
-
const client = inject(QueryClient);
|
|
25
|
-
const dehydratedState = transferState.get(ANALOG_QUERY_STATE_KEY, null);
|
|
26
|
-
if (dehydratedState) {
|
|
27
|
-
hydrate(client, dehydratedState);
|
|
28
|
-
transferState.remove(ANALOG_QUERY_STATE_KEY);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}, {
|
|
32
|
-
provide: ENVIRONMENT_INITIALIZER,
|
|
33
|
-
multi: true,
|
|
34
|
-
useValue() {
|
|
35
|
-
const router = inject(Router, { optional: true });
|
|
36
|
-
if (!router) return;
|
|
37
|
-
const client = inject(QueryClient);
|
|
38
|
-
const destroyRef = inject(DestroyRef);
|
|
39
|
-
const transferState = isPlatformServer(inject(PLATFORM_ID)) ? inject(TransferState) : null;
|
|
40
|
-
const subscription = router.events.subscribe((event) => {
|
|
41
|
-
if (event instanceof ResolveEnd) mergeRouteSnapshot(event.state.root, client, transferState);
|
|
42
|
-
});
|
|
43
|
-
destroyRef.onDestroy(() => subscription.unsubscribe());
|
|
44
|
-
}
|
|
45
|
-
}]);
|
|
46
|
-
}
|
|
47
|
-
function mergeRouteSnapshot(snapshot, client, transferState) {
|
|
48
|
-
const load = snapshot.data?.["load"];
|
|
49
|
-
if (load && typeof load === "object" && "__analogQueries" in load) {
|
|
50
|
-
const dehydrated = load[ANALOG_QUERIES_KEY];
|
|
51
|
-
if (dehydrated) {
|
|
52
|
-
hydrate(client, dehydrated);
|
|
53
|
-
if (transferState) {
|
|
54
|
-
const existing = transferState.get(ANALOG_QUERY_STATE_KEY, null);
|
|
55
|
-
transferState.set(ANALOG_QUERY_STATE_KEY, existing ? mergeDehydrated(existing, dehydrated) : dehydrated);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
for (const child of snapshot.children) mergeRouteSnapshot(child, client, transferState);
|
|
60
|
-
}
|
|
61
|
-
function mergeDehydrated(base, next) {
|
|
62
|
-
const queriesByHash = new Map(base.queries.map((query) => [query.queryHash, query]));
|
|
63
|
-
for (const query of next.queries) queriesByHash.set(query.queryHash, query);
|
|
64
|
-
return {
|
|
65
|
-
mutations: [...base.mutations, ...next.mutations],
|
|
66
|
-
queries: [...queriesByHash.values()]
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
//#endregion
|
|
70
|
-
export { provideAnalogQuery as n, ANALOG_QUERIES_KEY as r, ANALOG_QUERY_STATE_KEY as t };
|
|
71
|
-
|
|
72
|
-
//# sourceMappingURL=provide-analog-query.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provide-analog-query.mjs","names":[],"sources":["../../tanstack-query/src/constants.ts","../../tanstack-query/src/provide-analog-query.ts"],"sourcesContent":["/**\n * Route-data key under `ActivatedRoute.data['load']` that holds the\n * `DehydratedState` produced by `definePageLoadQueries`. The Router-\n * events hydrator in `provideAnalogQuery()` looks for this key on\n * `ResolveEnd` and merges the dehydrated payload into the active\n * `QueryClient`, so component-issued queries hit a warm cache on\n * first render.\n */\nexport const ANALOG_QUERIES_KEY: '__analogQueries' = '__analogQueries';\n","import {\n DestroyRef,\n ENVIRONMENT_INITIALIZER,\n PLATFORM_ID,\n TransferState,\n inject,\n makeEnvironmentProviders,\n makeStateKey,\n} from '@angular/core';\nimport type { EnvironmentProviders, StateKey } from '@angular/core';\nimport { isPlatformServer } from '@angular/common';\nimport { ResolveEnd, Router } from '@angular/router';\nimport type { ActivatedRouteSnapshot } from '@angular/router';\nimport { QueryClient, hydrate } from '@tanstack/angular-query-experimental';\nimport type { DehydratedState } from '@tanstack/angular-query-experimental';\n\nimport { ANALOG_QUERIES_KEY } from './constants.js';\n\nexport const ANALOG_QUERY_STATE_KEY: StateKey<DehydratedState> =\n makeStateKey<DehydratedState>('analog_query_state');\n\nexport function provideAnalogQuery(): EnvironmentProviders {\n return makeEnvironmentProviders([\n {\n provide: ENVIRONMENT_INITIALIZER,\n multi: true,\n useValue() {\n if (import.meta.env.SSR) {\n return;\n }\n\n const transferState = inject(TransferState);\n const client = inject(QueryClient);\n const dehydratedState = transferState.get<DehydratedState | null>(\n ANALOG_QUERY_STATE_KEY,\n null,\n );\n\n if (dehydratedState) {\n hydrate(client, dehydratedState);\n transferState.remove(ANALOG_QUERY_STATE_KEY);\n }\n },\n },\n {\n provide: ENVIRONMENT_INITIALIZER,\n multi: true,\n useValue() {\n const router = inject(Router, { optional: true });\n if (!router) {\n return;\n }\n\n const client = inject(QueryClient);\n const destroyRef = inject(DestroyRef);\n // On the server, also mirror any dehydrated load payloads into\n // `TransferState` so Angular's own serializer can include them in\n // the `ng-state` script — we can't rely on\n // `provideServerAnalogQuery()`'s `BEFORE_APP_SERIALIZED` running\n // before Angular's `TRANSFER_STATE_SERIALIZATION_PROVIDERS`.\n const transferState = isPlatformServer(inject(PLATFORM_ID))\n ? inject(TransferState)\n : null;\n\n const subscription = router.events.subscribe((event) => {\n if (event instanceof ResolveEnd) {\n mergeRouteSnapshot(event.state.root, client, transferState);\n }\n });\n\n destroyRef.onDestroy(() => subscription.unsubscribe());\n },\n },\n ]);\n}\n\nfunction mergeRouteSnapshot(\n snapshot: ActivatedRouteSnapshot,\n client: QueryClient,\n transferState: TransferState | null,\n): void {\n const load = snapshot.data?.['load'];\n if (load && typeof load === 'object' && ANALOG_QUERIES_KEY in load) {\n const dehydrated = (load as Record<string, unknown>)[ANALOG_QUERIES_KEY] as\n | DehydratedState\n | undefined;\n if (dehydrated) {\n hydrate(client, dehydrated);\n if (transferState) {\n const existing = transferState.get<DehydratedState | null>(\n ANALOG_QUERY_STATE_KEY,\n null,\n );\n transferState.set(\n ANALOG_QUERY_STATE_KEY,\n existing ? mergeDehydrated(existing, dehydrated) : dehydrated,\n );\n }\n }\n }\n for (const child of snapshot.children) {\n mergeRouteSnapshot(child, client, transferState);\n }\n}\n\nfunction mergeDehydrated(\n base: DehydratedState,\n next: DehydratedState,\n): DehydratedState {\n // Last-writer-wins on duplicate `queryHash`: child route resolves run\n // after parent resolves, so the later entry is the fresher one and\n // matches `hydrate()`'s own newer-wins semantics for the QueryClient.\n const queriesByHash = new Map(\n base.queries.map((query) => [query.queryHash, query]),\n );\n for (const query of next.queries) {\n queriesByHash.set(query.queryHash, query);\n }\n return {\n mutations: [...base.mutations, ...next.mutations],\n queries: [...queriesByHash.values()],\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAQA,IAAa,qBAAwC;;;ACUrD,IAAa,yBACX,aAA8B,qBAAqB;AAErD,SAAgB,qBAAkB;AAChC,QAAO,yBAAyB,CAC9B;EACE,SAAS;EACT,OAAO;EACP,WAAQ;GAKN,MAAM,gBAAgB,OAAO,cAAc;GAC3C,MAAM,SAAS,OAAO,YAAY;GAClC,MAAM,kBAAkB,cAAc,IACpC,wBACA,KACD;AAED,OAAI,iBAAiB;AACnB,YAAQ,QAAQ,gBAAgB;AAChC,kBAAc,OAAO,uBAAuB;;;EAGjD,EACD;EACE,SAAS;EACT,OAAO;EACP,WAAQ;GACN,MAAM,SAAS,OAAO,QAAQ,EAAE,UAAU,MAAM,CAAC;AACjD,OAAI,CAAC,OACH;GAGF,MAAM,SAAS,OAAO,YAAY;GAClC,MAAM,aAAa,OAAO,WAAW;GAMrC,MAAM,gBAAgB,iBAAiB,OAAO,YAAY,CAAC,GACvD,OAAO,cAAc,GACrB;GAEJ,MAAM,eAAe,OAAO,OAAO,WAAW,UAAS;AACrD,QAAI,iBAAiB,WACnB,oBAAmB,MAAM,MAAM,MAAM,QAAQ,cAAc;KAE7D;AAEF,cAAW,gBAAgB,aAAa,aAAa,CAAC;;EAEzD,CACF,CAAC;;AAGJ,SAAS,mBACP,UACA,QACA,eAAmC;CAEnC,MAAM,OAAO,SAAS,OAAO;AAC7B,KAAI,QAAQ,OAAO,SAAS,YAAA,qBAAkC,MAAM;EAClE,MAAM,aAAc,KAAiC;AAGrD,MAAI,YAAY;AACd,WAAQ,QAAQ,WAAW;AAC3B,OAAI,eAAe;IACjB,MAAM,WAAW,cAAc,IAC7B,wBACA,KACD;AACD,kBAAc,IACZ,wBACA,WAAW,gBAAgB,UAAU,WAAW,GAAG,WACpD;;;;AAIP,MAAK,MAAM,SAAS,SAAS,SAC3B,oBAAmB,OAAO,QAAQ,cAAc;;AAIpD,SAAS,gBACP,MACA,MAAqB;CAKrB,MAAM,gBAAgB,IAAI,IACxB,KAAK,QAAQ,KAAK,UAAU,CAAC,MAAM,WAAW,MAAM,CAAC,CACtD;AACD,MAAK,MAAM,SAAS,KAAK,QACvB,eAAc,IAAI,MAAM,WAAW,MAAM;AAE3C,QAAO;EACL,WAAW,CAAC,GAAG,KAAK,WAAW,GAAG,KAAK,UAAU;EACjD,SAAS,CAAC,GAAG,cAAc,QAAQ,CAAC;EACrC"}
|