@ubean/pages 0.4.5 → 0.4.6
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/dist/index.d.ts +49 -49
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -70,28 +70,28 @@ interface PageRenderer {
|
|
|
70
70
|
renderToStream?: PageStreamRenderFn;
|
|
71
71
|
preambleScript?: string;
|
|
72
72
|
}
|
|
73
|
-
declare const PAGE_DATA_ID = "__UBEAN_PAGE_DATA__";
|
|
74
|
-
declare const LOCALE_DATA_ID = "__UBEAN_LOCALE__";
|
|
75
|
-
declare const STATE_DATA_ID = "__UBEAN_STATE__";
|
|
76
|
-
declare const PAGE_REQUEST_HEADER = "x-ubeanpages";
|
|
77
|
-
declare const SSR_CONTENT_MARKER = "<!--UBEAN_SSR_CONTENT-->";
|
|
73
|
+
export declare const PAGE_DATA_ID = "__UBEAN_PAGE_DATA__";
|
|
74
|
+
export declare const LOCALE_DATA_ID = "__UBEAN_LOCALE__";
|
|
75
|
+
export declare const STATE_DATA_ID = "__UBEAN_STATE__";
|
|
76
|
+
export declare const PAGE_REQUEST_HEADER = "x-ubeanpages";
|
|
77
|
+
export declare const SSR_CONTENT_MARKER = "<!--UBEAN_SSR_CONTENT-->";
|
|
78
78
|
/** Shell 中 state script 的占位符,render 后由 `insertStateContent` 替换为实际 JSON */
|
|
79
|
-
declare const STATE_MARKER = "<!--UBEAN_STATE-->";
|
|
80
|
-
declare function isPagesRequest(c: {
|
|
79
|
+
export declare const STATE_MARKER = "<!--UBEAN_STATE-->";
|
|
80
|
+
export declare function isPagesRequest(c: {
|
|
81
81
|
req: {
|
|
82
82
|
header: (k: string) => string | undefined;
|
|
83
83
|
};
|
|
84
84
|
}): boolean;
|
|
85
|
-
declare function safeJsonStringify(value: unknown): string;
|
|
86
|
-
declare function serializePageData(pageObj: PageObject): string;
|
|
87
|
-
declare function pageJsonResponse(pageObj: PageObject, headers?: Record<string, string>): Response;
|
|
85
|
+
export declare function safeJsonStringify(value: unknown): string;
|
|
86
|
+
export declare function serializePageData(pageObj: PageObject): string;
|
|
87
|
+
export declare function pageJsonResponse(pageObj: PageObject, headers?: Record<string, string>): Response;
|
|
88
88
|
/**
|
|
89
89
|
* 生成 favicon `<link>` 标签字符串。
|
|
90
90
|
* 当 `favicon` 为空/未设置时返回空字符串。
|
|
91
91
|
*/
|
|
92
|
-
declare function renderFaviconLink(favicon?: string): string;
|
|
93
|
-
declare function buildPageShell(pageObj: PageObject, assetTags: PageAssetTags, preambleScript?: string, appId?: string, renderContext?: PageRenderContext): string;
|
|
94
|
-
declare function insertSsrContent(shell: string, appHtml: string): string;
|
|
92
|
+
export declare function renderFaviconLink(favicon?: string): string;
|
|
93
|
+
export declare function buildPageShell(pageObj: PageObject, assetTags: PageAssetTags, preambleScript?: string, appId?: string, renderContext?: PageRenderContext): string;
|
|
94
|
+
export declare function insertSsrContent(shell: string, appHtml: string): string;
|
|
95
95
|
/**
|
|
96
96
|
* 将序列化后的 state JSON 注入 shell 中的 `__UBEAN_STATE__` script 标签。
|
|
97
97
|
*
|
|
@@ -101,9 +101,9 @@ declare function insertSsrContent(shell: string, appHtml: string): string;
|
|
|
101
101
|
* 若 `stateJson` 为空字符串或 `null`,将占位符替换为空字符串(产出空 script 体,
|
|
102
102
|
* 客户端 `getInitialState()` 会返回 `null`)。
|
|
103
103
|
*/
|
|
104
|
-
declare function insertStateContent(shell: string, stateJson: string | null): string;
|
|
105
|
-
declare function buildClientOnlyShell(pageObj: PageObject, assetTags: PageAssetTags, preambleScript?: string, appId?: string, renderContext?: PageRenderContext): string;
|
|
106
|
-
declare function renderPage(pageObj: PageObject, assetTags: PageAssetTags, renderer: PageRenderer | null, appId?: string, renderContext?: PageRenderContext): Promise<string>;
|
|
104
|
+
export declare function insertStateContent(shell: string, stateJson: string | null): string;
|
|
105
|
+
export declare function buildClientOnlyShell(pageObj: PageObject, assetTags: PageAssetTags, preambleScript?: string, appId?: string, renderContext?: PageRenderContext): string;
|
|
106
|
+
export declare function renderPage(pageObj: PageObject, assetTags: PageAssetTags, renderer: PageRenderer | null, appId?: string, renderContext?: PageRenderContext): Promise<string>;
|
|
107
107
|
/**
|
|
108
108
|
* 流式渲染页面:当 renderer 提供 `renderToStream` 时,返回一个
|
|
109
109
|
* `ReadableStream<Uint8Array>`,将完整 HTML 文档分块流式输出。
|
|
@@ -114,7 +114,7 @@ declare function renderPage(pageObj: PageObject, assetTags: PageAssetTags, rende
|
|
|
114
114
|
* 调用方应使用 `c.body(stream, { headers: { 'Content-Type': 'text/html; charset=utf-8' } })`
|
|
115
115
|
* 将流作为 HTTP 响应返回。
|
|
116
116
|
*/
|
|
117
|
-
declare function renderPageToStream(pageObj: PageObject, assetTags: PageAssetTags, renderer: PageRenderer | null, appId?: string, renderContext?: PageRenderContext): ReadableStream<Uint8Array>;
|
|
117
|
+
export declare function renderPageToStream(pageObj: PageObject, assetTags: PageAssetTags, renderer: PageRenderer | null, appId?: string, renderContext?: PageRenderContext): ReadableStream<Uint8Array>;
|
|
118
118
|
//#endregion
|
|
119
119
|
//#region src/data.d.ts
|
|
120
120
|
type DataKey = string | symbol;
|
|
@@ -126,7 +126,7 @@ interface DataCacheEntry<T = unknown> {
|
|
|
126
126
|
tags?: string[];
|
|
127
127
|
}
|
|
128
128
|
type DataFetcher<T> = () => T | Promise<T>;
|
|
129
|
-
declare function defineDataKey(key: string): symbol;
|
|
129
|
+
export declare function defineDataKey(key: string): symbol;
|
|
130
130
|
/**
|
|
131
131
|
* `__UBEAN_DATA__` script 标签 ID — SSR 渲染时,useData 解析的数据以 JSON 形式
|
|
132
132
|
* 注入到此标签中,客户端水合时读取,避免二次请求。
|
|
@@ -134,7 +134,7 @@ declare function defineDataKey(key: string): symbol;
|
|
|
134
134
|
* 与 `__UBEAN_DEFERRED__`(非关键延迟数据)和 `__UBEAN_STATE__`(用户状态如 Pinia)
|
|
135
135
|
* 分离,职责单一,便于 SSG payload 提取(roadmap Task 3)。
|
|
136
136
|
*/
|
|
137
|
-
declare const DATA_PAYLOAD_ID = "__UBEAN_DATA__";
|
|
137
|
+
export declare const DATA_PAYLOAD_ID = "__UBEAN_DATA__";
|
|
138
138
|
/**
|
|
139
139
|
* SSR payload 条目:记录 useData 解析结果,序列化到 `__UBEAN_DATA__`。
|
|
140
140
|
* `error` 以字符串形式存储(可序列化),客户端水合时重建为 Error。
|
|
@@ -150,25 +150,25 @@ interface DataPayloadEntry {
|
|
|
150
150
|
* 在 `useData` 的 SSR 分支中调用。每次渲染前应调用 `__clearDataPayload()`。
|
|
151
151
|
* 仅 string key 可注册(symbol 无法序列化)。
|
|
152
152
|
*/
|
|
153
|
-
declare function __registerDataPayload(key: string, entry: DataPayloadEntry): void;
|
|
153
|
+
export declare function __registerDataPayload(key: string, entry: DataPayloadEntry): void;
|
|
154
154
|
/**
|
|
155
155
|
* SSR 内部:返回所有已注册的 payload 条目,用于序列化到 `__UBEAN_DATA__`。
|
|
156
156
|
*/
|
|
157
|
-
declare function __resolveDataPayload(): Record<string, DataPayloadEntry>;
|
|
157
|
+
export declare function __resolveDataPayload(): Record<string, DataPayloadEntry>;
|
|
158
158
|
/**
|
|
159
159
|
* SSR 内部:清空 payload 注册表 + 全局 inflight。每次渲染前调用,
|
|
160
160
|
* 避免上一个请求的残留。
|
|
161
161
|
*/
|
|
162
|
-
declare function __clearDataPayload(): void;
|
|
162
|
+
export declare function __clearDataPayload(): void;
|
|
163
163
|
/**
|
|
164
164
|
* SSR 内部:将 data payload 序列化为 `<script>` 标签字符串。
|
|
165
165
|
* 无数据时返回空字符串(不注入标签)。
|
|
166
166
|
*/
|
|
167
|
-
declare function __serializeDataPayload(data: Record<string, DataPayloadEntry>): string;
|
|
167
|
+
export declare function __serializeDataPayload(data: Record<string, DataPayloadEntry>): string;
|
|
168
168
|
/**
|
|
169
169
|
* 重置客户端 payload 缓存(测试用)。
|
|
170
170
|
*/
|
|
171
|
-
declare function __resetDataPayloadCache(): void;
|
|
171
|
+
export declare function __resetDataPayloadCache(): void;
|
|
172
172
|
interface UseDataOptions<T> {
|
|
173
173
|
key?: DataKey;
|
|
174
174
|
tags?: string[];
|
|
@@ -199,7 +199,7 @@ interface DataResult<T> {
|
|
|
199
199
|
*/
|
|
200
200
|
refresh: () => Promise<void>;
|
|
201
201
|
}
|
|
202
|
-
declare function useData<T>(options: UseDataOptions<T>, context?: object): Promise<DataResult<T>>;
|
|
202
|
+
export declare function useData<T>(options: UseDataOptions<T>, context?: object): Promise<DataResult<T>>;
|
|
203
203
|
/**
|
|
204
204
|
* `useAsyncData` 选项:Nuxt 风格的 `useAsyncData(key, fn, options)` 第三参数。
|
|
205
205
|
*
|
|
@@ -227,25 +227,25 @@ interface UseAsyncDataOptions {
|
|
|
227
227
|
* );
|
|
228
228
|
* ```
|
|
229
229
|
*/
|
|
230
|
-
declare function useAsyncData<T>(key: string, fn: DataFetcher<T>, options?: UseAsyncDataOptions, context?: object): Promise<DataResult<T>>;
|
|
231
|
-
declare function invalidateData(keyOrTag: DataKey | string, context?: object): number;
|
|
232
|
-
declare function invalidateAll(context?: object): void;
|
|
233
|
-
declare function clearPageData(context?: object): void;
|
|
234
|
-
declare function hasData(key: DataKey, context?: object): boolean;
|
|
230
|
+
export declare function useAsyncData<T>(key: string, fn: DataFetcher<T>, options?: UseAsyncDataOptions, context?: object): Promise<DataResult<T>>;
|
|
231
|
+
export declare function invalidateData(keyOrTag: DataKey | string, context?: object): number;
|
|
232
|
+
export declare function invalidateAll(context?: object): void;
|
|
233
|
+
export declare function clearPageData(context?: object): void;
|
|
234
|
+
export declare function hasData(key: DataKey, context?: object): boolean;
|
|
235
235
|
interface DependencyDeclaration {
|
|
236
236
|
keys: DataKey[];
|
|
237
237
|
tags?: string[];
|
|
238
238
|
}
|
|
239
|
-
declare function declareDependencies(deps: DependencyDeclaration): DependencyDeclaration;
|
|
240
|
-
declare function withDependencies<T>(fn: () => T | Promise<T>, _deps: DependencyDeclaration): () => Promise<T>;
|
|
241
|
-
declare function getInvalidatedKeysForAction(actionName: string, invalidationMap: Record<string, Array<DataKey | string>>, context?: object): number;
|
|
239
|
+
export declare function declareDependencies(deps: DependencyDeclaration): DependencyDeclaration;
|
|
240
|
+
export declare function withDependencies<T>(fn: () => T | Promise<T>, _deps: DependencyDeclaration): () => Promise<T>;
|
|
241
|
+
export declare function getInvalidatedKeysForAction(actionName: string, invalidationMap: Record<string, Array<DataKey | string>>, context?: object): number;
|
|
242
242
|
interface InternalFetchOptions {
|
|
243
243
|
baseURL?: string;
|
|
244
244
|
headers?: Record<string, string>;
|
|
245
245
|
credentials?: 'include' | 'omit' | 'same-origin';
|
|
246
246
|
forwardHeaders?: string[];
|
|
247
247
|
}
|
|
248
|
-
declare function createInternalFetch(c: {
|
|
248
|
+
export declare function createInternalFetch(c: {
|
|
249
249
|
req: {
|
|
250
250
|
raw?: Request;
|
|
251
251
|
header?: (name: string) => string | undefined;
|
|
@@ -258,8 +258,8 @@ interface StreamHelper {
|
|
|
258
258
|
error: (err: Error) => void;
|
|
259
259
|
response: Response;
|
|
260
260
|
}
|
|
261
|
-
declare function createStreamResponse(init?: ResponseInit, onStart?: (stream: StreamHelper) => void | Promise<void>): Response;
|
|
262
|
-
declare function createSseStream(onStart?: (stream: StreamHelper) => void | Promise<void>): Response;
|
|
261
|
+
export declare function createStreamResponse(init?: ResponseInit, onStart?: (stream: StreamHelper) => void | Promise<void>): Response;
|
|
262
|
+
export declare function createSseStream(onStart?: (stream: StreamHelper) => void | Promise<void>): Response;
|
|
263
263
|
//#endregion
|
|
264
264
|
//#region src/fetch.d.ts
|
|
265
265
|
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
@@ -281,16 +281,16 @@ interface UseFetchOptions<T> extends UseAsyncDataOptions {
|
|
|
281
281
|
request?: FetchClient;
|
|
282
282
|
transform?: (data: T) => T;
|
|
283
283
|
}
|
|
284
|
-
declare function setDefaultFetch(request: FetchClient | undefined): void;
|
|
285
|
-
declare function getDefaultFetch(): FetchClient | undefined;
|
|
286
|
-
declare function useFetch<T>(key: string, url: string, options?: UseFetchOptions<T>, context?: object): Promise<DataResult<T>>;
|
|
284
|
+
export declare function setDefaultFetch(request: FetchClient | undefined): void;
|
|
285
|
+
export declare function getDefaultFetch(): FetchClient | undefined;
|
|
286
|
+
export declare function useFetch<T>(key: string, url: string, options?: UseFetchOptions<T>, context?: object): Promise<DataResult<T>>;
|
|
287
287
|
//#endregion
|
|
288
288
|
//#region src/defer.d.ts
|
|
289
289
|
/**
|
|
290
290
|
* `__UBEAN_DEFERRED__` script 标签 ID — SSR 流式渲染完成后,延迟数据
|
|
291
291
|
* 以 JSON 形式注入到此标签中,客户端水合时读取。
|
|
292
292
|
*/
|
|
293
|
-
declare const DEFERRED_DATA_ID = "__UBEAN_DEFERRED__";
|
|
293
|
+
export declare const DEFERRED_DATA_ID = "__UBEAN_DEFERRED__";
|
|
294
294
|
/**
|
|
295
295
|
* 延迟值:包装一个 factory 函数,标记为"非关键数据"。
|
|
296
296
|
*
|
|
@@ -315,38 +315,38 @@ interface DeferredValue<T> {
|
|
|
315
315
|
* const nonCritical = defer(() => fetchNonCritical());
|
|
316
316
|
* ```
|
|
317
317
|
*/
|
|
318
|
-
declare function defer<T>(factory: (() => Promise<T>) | Promise<T>): DeferredValue<T>;
|
|
318
|
+
export declare function defer<T>(factory: (() => Promise<T>) | Promise<T>): DeferredValue<T>;
|
|
319
319
|
/**
|
|
320
320
|
* 判断值是否为 DeferredValue(类型守卫)。
|
|
321
321
|
*/
|
|
322
|
-
declare function isDeferredValue<T>(value: unknown): value is DeferredValue<T>;
|
|
322
|
+
export declare function isDeferredValue<T>(value: unknown): value is DeferredValue<T>;
|
|
323
323
|
/**
|
|
324
324
|
* SSR 内部:注册一个 deferred promise,在流式渲染后统一解析。
|
|
325
325
|
*
|
|
326
326
|
* 在 `useDeferredData` 的 SSR 分支中调用。每次渲染前应调用 `__clearDeferred()`。
|
|
327
327
|
*/
|
|
328
|
-
declare function __registerDeferred(key: string, promise: Promise<unknown>): void;
|
|
328
|
+
export declare function __registerDeferred(key: string, promise: Promise<unknown>): void;
|
|
329
329
|
/**
|
|
330
330
|
* SSR 内部:解析所有已注册的 deferred promise,返回 key → data 映射。
|
|
331
331
|
*
|
|
332
332
|
* 失败的 promise 以 `{ __deferredError: message }` 形式包含在结果中,
|
|
333
333
|
* 不影响其他 promise 的解析。
|
|
334
334
|
*/
|
|
335
|
-
declare function __resolveDeferred(): Promise<Record<string, unknown>>;
|
|
335
|
+
export declare function __resolveDeferred(): Promise<Record<string, unknown>>;
|
|
336
336
|
/**
|
|
337
337
|
* SSR 内部:清空注册表。每次渲染前调用,避免上一个请求的残留。
|
|
338
338
|
*/
|
|
339
|
-
declare function __clearDeferred(): void;
|
|
339
|
+
export declare function __clearDeferred(): void;
|
|
340
340
|
/**
|
|
341
341
|
* SSR 内部:将 deferred 数据序列化为 `<script>` 标签字符串。
|
|
342
342
|
*
|
|
343
343
|
* 无数据时返回空字符串(不注入标签)。
|
|
344
344
|
*/
|
|
345
|
-
declare function __serializeDeferred(data: Record<string, unknown>): string;
|
|
345
|
+
export declare function __serializeDeferred(data: Record<string, unknown>): string;
|
|
346
346
|
/**
|
|
347
347
|
* 重置客户端缓存(测试用)。
|
|
348
348
|
*/
|
|
349
|
-
declare function __resetDeferredCache(): void;
|
|
349
|
+
export declare function __resetDeferredCache(): void;
|
|
350
350
|
interface UseDeferredDataResult<T> {
|
|
351
351
|
/** 延迟数据(初始为 undefined,解析后更新) */
|
|
352
352
|
data: ShallowRef<T | undefined>;
|
|
@@ -381,6 +381,6 @@ interface UseDeferredDataResult<T> {
|
|
|
381
381
|
* </template>
|
|
382
382
|
* ```
|
|
383
383
|
*/
|
|
384
|
-
declare function useDeferredData<T>(key: string, deferred: DeferredValue<T>): UseDeferredDataResult<T>;
|
|
384
|
+
export declare function useDeferredData<T>(key: string, deferred: DeferredValue<T>): UseDeferredDataResult<T>;
|
|
385
385
|
//#endregion
|
|
386
|
-
export {
|
|
386
|
+
export type { DataCacheEntry, DataKey, DataPayloadEntry, DataResult, DataStatus, DeferredValue, DependencyDeclaration, FetchClient, InternalFetchOptions, LocaleMetaInfo, PageAssetTags, PageHead, PageHeadMeta, PageObject, PageRenderContext, PageRenderFn, PageRenderResult, PageRenderer, PageStreamRenderFn, StreamHelper, UseAsyncDataOptions, UseDataOptions, UseDeferredDataResult, UseFetchOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ubean/pages",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
4
4
|
"description": "Page data protocol and isomorphic data layer for ubean (PageObject, useData, invalidateData)",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ubean/shared": "0.4.
|
|
19
|
+
"@ubean/shared": "0.4.6"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^26.5.0",
|
|
23
|
-
"typescript": "
|
|
24
|
-
"vite-plus": "0.3.
|
|
23
|
+
"typescript": "npm:typescript-native-bridge@latest",
|
|
24
|
+
"vite-plus": "0.3.1"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"vue": ">=3.4.0"
|