@ryusenkei/maezae 0.2.0 → 0.3.1
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/README.md +2 -0
- package/dist/analytics.d.ts +1 -0
- package/dist/analytics.js +33 -0
- package/dist/body.d.ts +1 -24
- package/dist/body.js +1 -333
- package/dist/declared-9_jI3JXH.js +336 -0
- package/dist/delivery.d.ts +1 -211
- package/dist/integrations.d.ts +1 -72
- package/dist/integrations.js +12 -2
- package/dist/model.d.ts +1 -82
- package/dist/model.js +339 -1
- package/dist/preview.d.ts +1 -2
- package/dist/preview.js +1 -1
- package/dist/{src-CA_67dWy.js → src-Baj-EC2G.js} +105 -3
- package/dist/trace.d.ts +1 -0
- package/dist/trace.js +1 -0
- package/dist/types/access/src/index.d.ts +5 -0
- package/dist/types/access/src/jwt.d.ts +42 -0
- package/dist/types/access/src/oidc.d.ts +47 -0
- package/dist/types/access/src/signed.d.ts +47 -0
- package/dist/types/access/src/span.d.ts +23 -0
- package/dist/types/access/src/traceparent.d.ts +21 -0
- package/dist/types/analytics/src/day.d.ts +2 -0
- package/dist/types/analytics/src/index.d.ts +4 -0
- package/dist/types/analytics/src/record.d.ts +22 -0
- package/dist/types/analytics/src/schedule.d.ts +2 -0
- package/dist/types/analytics/src/source.d.ts +33 -0
- package/dist/types/analytics/src/store.d.ts +24 -0
- package/dist/types/body/src/components.d.ts +25 -0
- package/dist/types/body/src/declared.d.ts +34 -0
- package/dist/types/body/src/derive.d.ts +13 -0
- package/dist/types/body/src/description.d.ts +8 -0
- package/dist/types/body/src/href.d.ts +4 -0
- package/dist/types/body/src/index.d.ts +11 -0
- package/dist/types/body/src/library.d.ts +94 -0
- package/dist/types/body/src/markdown.d.ts +14 -0
- package/dist/types/body/src/normalize.d.ts +7 -0
- package/dist/types/body/src/profile.d.ts +48 -0
- package/dist/types/body/src/schema.d.ts +6 -0
- package/dist/types/body/src/standard.d.ts +20 -0
- package/dist/types/body/src/types.d.ts +91 -0
- package/dist/types/cms-contract/src/apiKeys.d.ts +13 -0
- package/dist/types/cms-contract/src/assets.d.ts +10 -0
- package/dist/types/cms-contract/src/builtins.d.ts +17 -0
- package/dist/types/cms-contract/src/embeds.d.ts +56 -0
- package/dist/types/cms-contract/src/errorLabels.d.ts +22 -0
- package/dist/types/cms-contract/src/errors.d.ts +97 -0
- package/dist/types/cms-contract/src/extensions.d.ts +75 -0
- package/dist/types/cms-contract/src/fieldRules.d.ts +37 -0
- package/dist/types/cms-contract/src/functions.d.ts +71 -0
- package/dist/types/cms-contract/src/index.d.ts +19 -0
- package/dist/types/cms-contract/src/labels.d.ts +6 -0
- package/dist/types/cms-contract/src/modules.d.ts +144 -0
- package/dist/types/cms-contract/src/paths.d.ts +6 -0
- package/dist/types/cms-contract/src/pending.d.ts +4 -0
- package/dist/types/cms-contract/src/permissions.d.ts +69 -0
- package/dist/types/cms-contract/src/roles.d.ts +35 -0
- package/dist/types/cms-contract/src/settings.d.ts +19 -0
- package/dist/types/cms-contract/src/transfer.d.ts +48 -0
- package/dist/types/cms-contract/src/views.d.ts +21 -0
- package/dist/types/cms-contract/src/webhooks.d.ts +45 -0
- package/dist/types/delivery-client/src/client.d.ts +63 -0
- package/dist/types/delivery-client/src/index.d.ts +5 -0
- package/dist/types/delivery-client/src/media.d.ts +12 -0
- package/dist/types/delivery-client/src/query.d.ts +68 -0
- package/dist/types/delivery-client/src/schema.d.ts +19 -0
- package/dist/types/delivery-client/src/values.d.ts +63 -0
- package/dist/types/model/src/asset.d.ts +89 -0
- package/dist/types/model/src/capabilities.d.ts +20 -0
- package/dist/types/model/src/changes.d.ts +23 -0
- package/dist/types/model/src/check.d.ts +10 -0
- package/dist/types/model/src/image.d.ts +38 -0
- package/dist/types/model/src/index.d.ts +14 -0
- package/dist/types/model/src/input.d.ts +26 -0
- package/dist/types/model/src/media.d.ts +5 -0
- package/dist/types/model/src/model.d.ts +194 -0
- package/dist/types/model/src/page.d.ts +47 -0
- package/dist/types/model/src/rules.d.ts +15 -0
- package/dist/types/model/src/schema.d.ts +3 -0
- package/dist/types/model/src/screens.d.ts +72 -0
- package/dist/types/model/src/time.d.ts +25 -0
- package/dist/types/model/src/values.d.ts +24 -0
- package/dist/types/sdk/src/analytics.d.ts +2 -0
- package/dist/types/sdk/src/body.d.ts +2 -0
- package/dist/types/sdk/src/defaults.d.ts +5 -0
- package/dist/types/sdk/src/delivery.d.ts +2 -0
- package/dist/types/sdk/src/integrations.d.ts +4 -0
- package/dist/types/sdk/src/model.d.ts +5 -0
- package/dist/types/sdk/src/preview.d.ts +2 -0
- package/dist/types/sdk/src/trace.d.ts +2 -0
- package/package.json +10 -2
- package/dist/index-C8duwjns.d.ts +0 -157
- package/dist/index-CLDe_wBc.d.ts +0 -340
- package/dist/signed-B_58gV21.d.ts +0 -44
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** 経路ごとのヘッダーの名前(署名と主体) */
|
|
2
|
+
export declare const SIGNED_HEADERS: {
|
|
3
|
+
/** MCP → CMS の署名(鍵は MCP_TOKEN) */
|
|
4
|
+
readonly mcp: "x-mcp-signature";
|
|
5
|
+
/** MCP → CMS のログインのメールアドレス(署名の主体) */
|
|
6
|
+
readonly mcpEmail: "x-mcp-email";
|
|
7
|
+
/** CMS ⇄ サイトのプレビューと下書きの署名(鍵は PREVIEW_TOKEN) */
|
|
8
|
+
readonly preview: "x-preview-signature";
|
|
9
|
+
/** CMS → 外の送信先の Webhook・外の関数の署名(鍵は登録ごと、受け手は verifyParts と同じ手順で照合) */
|
|
10
|
+
readonly outbound: "x-cms-signature";
|
|
11
|
+
};
|
|
12
|
+
/** 署名の対象(body は本文、なしは空) */
|
|
13
|
+
export type SignedParts = Readonly<{
|
|
14
|
+
method: string;
|
|
15
|
+
url: string;
|
|
16
|
+
body?: string | ArrayBuffer | Uint8Array | null;
|
|
17
|
+
/** 主体(MCP のログインのメールアドレスなど、なしは空) */
|
|
18
|
+
subject?: string | null;
|
|
19
|
+
}>;
|
|
20
|
+
/** 署名のヘッダーの値(t=<秒>,v1=<署名>) */
|
|
21
|
+
export declare function signParts(secret: string, parts: SignedParts, now?: number): Promise<string>;
|
|
22
|
+
/** 署名の照合(形の誤り・時刻のずれの超過・不一致は false) */
|
|
23
|
+
export declare function verifyParts(secret: string, header: string | null | undefined, parts: SignedParts, { now, maxSkewSec }?: {
|
|
24
|
+
now?: number;
|
|
25
|
+
maxSkewSec?: number;
|
|
26
|
+
}): Promise<boolean>;
|
|
27
|
+
/** 署名を付けたヘッダー(init のヘッダーに署名と主体を追加した新しい Headers) */
|
|
28
|
+
export declare function signedHeaders(secret: string, { method, url, body, subject }: SignedParts, { header, subjectHeader, init, now }: Readonly<{
|
|
29
|
+
header: string;
|
|
30
|
+
subjectHeader?: string;
|
|
31
|
+
init?: HeadersInit;
|
|
32
|
+
now?: number;
|
|
33
|
+
}>): Promise<Headers>;
|
|
34
|
+
/** 署名つきのリクエストを照合する設定 */
|
|
35
|
+
export type VerifyRequestOptions = Readonly<{
|
|
36
|
+
/** 署名のヘッダーの名前 */
|
|
37
|
+
header: string;
|
|
38
|
+
/** 主体のヘッダーの名前(なしは主体なしで照合) */
|
|
39
|
+
subjectHeader?: string;
|
|
40
|
+
now?: number;
|
|
41
|
+
}>;
|
|
42
|
+
/** リクエストの署名の照合(本文は複製から読み込み、元のリクエストの本文は残す) */
|
|
43
|
+
export declare function verifyRequest(secret: string | undefined, request: Request, { header, subjectHeader, now }: VerifyRequestOptions): Promise<boolean>;
|
|
44
|
+
/** 期限と署名を付けた値(JSON にできる値、ttlSec は有効な秒数) */
|
|
45
|
+
export declare function sealValue(secret: string, value: unknown, ttlSec: number, now?: number): Promise<string>;
|
|
46
|
+
/** 封印した値(署名の不一致・期限切れ・形の誤りは null) */
|
|
47
|
+
export declare function openValue<T = unknown>(secret: string, token: string | null | undefined, now?: number): Promise<T | null>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type TraceContext } from './traceparent.js';
|
|
2
|
+
/** 区間の結果(ok・error、logTracer と同じ値) */
|
|
3
|
+
export type EdgeSpanStatus = 'ok' | 'error';
|
|
4
|
+
/** エントリポイントの区間(context は転送先へ受け渡す自身の区間、traceparent はその値) */
|
|
5
|
+
export type EdgeSpan = Readonly<{
|
|
6
|
+
context: TraceContext;
|
|
7
|
+
traceparent: string;
|
|
8
|
+
/** 応答のステータスの数か例外で終了(500以上・例外は error、2回目以降は無視) */
|
|
9
|
+
end: (result: number | 'error') => void;
|
|
10
|
+
}>;
|
|
11
|
+
/** エントリポイントの区間の引数(write は1行の出力先、既定は console.info) */
|
|
12
|
+
export type EdgeSpanOptions = Readonly<{
|
|
13
|
+
name: string;
|
|
14
|
+
request: Request;
|
|
15
|
+
sampleRate?: number;
|
|
16
|
+
write?: (line: string) => void;
|
|
17
|
+
}>;
|
|
18
|
+
/** 記録の割合(0〜1、なし・範囲の外・数でない値は1) */
|
|
19
|
+
export declare const sampleRateOf: (value: string | undefined) => number;
|
|
20
|
+
/** エントリポイントの区間の開始(受け取った traceparent の子か、新しいトレースの根) */
|
|
21
|
+
export declare function startEdgeSpan({ name, request, sampleRate, write }: EdgeSpanOptions): EdgeSpan;
|
|
22
|
+
/** 処理をエントリポイントの区間で包む(応答のステータスか例外で終了、例外は再送出) */
|
|
23
|
+
export declare function withEdgeSpan(options: EdgeSpanOptions, handle: (span: EdgeSpan) => Promise<Response>): Promise<Response>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** traceparent のヘッダーの名前 */
|
|
2
|
+
export declare const TRACEPARENT_HEADER = "traceparent";
|
|
3
|
+
/** トレースの文脈(traceId は32桁、spanId は呼び出し元の区間の16桁、sampled は記録の対象か) */
|
|
4
|
+
export type TraceContext = Readonly<{
|
|
5
|
+
traceId: string;
|
|
6
|
+
spanId: string;
|
|
7
|
+
sampled: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
/** 受け取った traceparent の解釈(なし・形の違反は null) */
|
|
10
|
+
export declare function parseTraceparent(value: string | null | undefined): TraceContext | null;
|
|
11
|
+
/** traceparent の値(版は00) */
|
|
12
|
+
export declare const formatTraceparent: (ctx: TraceContext) => string;
|
|
13
|
+
/** 新しいトレースの ID(32桁) */
|
|
14
|
+
export declare const newTraceId: () => string;
|
|
15
|
+
/** 新しい区間の ID(16桁) */
|
|
16
|
+
export declare const newSpanId: () => string;
|
|
17
|
+
/**
|
|
18
|
+
* 呼び出し元の区間の文脈(受け取った traceparent があれば同じトレースの子、なければ新しいトレース)
|
|
19
|
+
* - sampled: 受け取った値のフラグ、新しいトレースは引数(既定は記録の対象)
|
|
20
|
+
*/
|
|
21
|
+
export declare function childTraceContext(incoming: string | null | undefined, sampled?: boolean): TraceContext;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { recordView, type Classify, type Dataset } from './record.js';
|
|
2
|
+
export { syncCron } from './schedule.js';
|
|
3
|
+
export { analyticsEngine, type DailyRow, fixedSource, type Source, tenantDaily, type TenantSource } from './source.js';
|
|
4
|
+
export { readDaily, syncDaily } from './store.js';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Analytics Engine のデータセットの binding(書き込みだけ) */
|
|
2
|
+
export type Dataset = {
|
|
3
|
+
writeDataPoint(point: {
|
|
4
|
+
blobs?: string[];
|
|
5
|
+
doubles?: number[];
|
|
6
|
+
indexes?: string[];
|
|
7
|
+
}): void;
|
|
8
|
+
};
|
|
9
|
+
/** パスから種類と ID への対応(利用側が定義、例: /articles/<id> は記事) */
|
|
10
|
+
export type Classify = (path: string) => {
|
|
11
|
+
kind: string;
|
|
12
|
+
id: string;
|
|
13
|
+
};
|
|
14
|
+
/** 記録の設定(tenant は媒体の識別子) */
|
|
15
|
+
type RecordOptions = {
|
|
16
|
+
classify: Classify;
|
|
17
|
+
timeZone: string;
|
|
18
|
+
tenant?: string;
|
|
19
|
+
};
|
|
20
|
+
/** 閲覧を1件記録(対象: GET で応答が200の HTML・ボット以外、記録の失敗は無視) */
|
|
21
|
+
export declare function recordView(dataset: Dataset | undefined, request: Request, response: Response, { classify, timeZone, tenant }: RecordOptions): void;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** 日ごと・種類・ID の閲覧数 */
|
|
2
|
+
export type DailyRow = {
|
|
3
|
+
date: string;
|
|
4
|
+
kind: string;
|
|
5
|
+
id: string;
|
|
6
|
+
views: number;
|
|
7
|
+
};
|
|
8
|
+
/** 読み込み元の接続の型(since 以降の日付の閲覧数) */
|
|
9
|
+
export type Source = {
|
|
10
|
+
daily(since: string): Promise<DailyRow[]>;
|
|
11
|
+
};
|
|
12
|
+
/** Analytics Engine の接続の設定(token は Account Analytics の読み取りの API トークン、tenant は絞り込む媒体の識別子) */
|
|
13
|
+
type AnalyticsEngineOptions = {
|
|
14
|
+
accountId: string;
|
|
15
|
+
token: string;
|
|
16
|
+
dataset: string;
|
|
17
|
+
tenant?: string;
|
|
18
|
+
};
|
|
19
|
+
/** 1回の問い合わせの行数 */
|
|
20
|
+
export declare const PAGE_ROWS = 10000;
|
|
21
|
+
/** 問い合わせの回数の上限(PAGE_ROWS との積が1回で集計できる行数) */
|
|
22
|
+
export declare const MAX_PAGES = 20;
|
|
23
|
+
/** Analytics Engine の SQL API の読み込み元 */
|
|
24
|
+
export declare function analyticsEngine({ accountId, token, dataset, tenant }: AnalyticsEngineOptions): Source;
|
|
25
|
+
/** 全媒体の読み込み元の型(since 以降の日付の閲覧数を媒体の識別子ごとに) */
|
|
26
|
+
export type TenantSource = {
|
|
27
|
+
dailyByTenant(since: string): Promise<ReadonlyMap<string, DailyRow[]>>;
|
|
28
|
+
};
|
|
29
|
+
/** 全媒体を1回の問い合わせで集計する Analytics Engine の読み込み元(媒体の列が空の記録は除外) */
|
|
30
|
+
export declare function tenantDaily(options: Omit<AnalyticsEngineOptions, 'tenant'>): TenantSource;
|
|
31
|
+
/** 集計済みの行の読み込み元(定期の集計で全媒体の問い合わせ結果を媒体ごとに受け渡し、daily は since 以降の行) */
|
|
32
|
+
export declare const fixedSource: (rows: readonly DailyRow[]) => Source;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DailyRow, Source } from './source.js';
|
|
2
|
+
type Statement = {
|
|
3
|
+
bind(...values: unknown[]): Statement;
|
|
4
|
+
all<T = Record<string, unknown>>(): Promise<{
|
|
5
|
+
results: T[];
|
|
6
|
+
}>;
|
|
7
|
+
};
|
|
8
|
+
/** D1 の接続の型(D1Database と互換) */
|
|
9
|
+
export type Db = {
|
|
10
|
+
prepare(sql: string): Statement;
|
|
11
|
+
batch(statements: Statement[]): Promise<unknown>;
|
|
12
|
+
};
|
|
13
|
+
/** 読み込み元の since 以降の閲覧数を表へ(戻り値は行の数) */
|
|
14
|
+
export declare function syncDaily(source: Source, db: Db, since: string): Promise<number>;
|
|
15
|
+
/** 日付が after より後の閲覧数(live は今日の行を読み込み元から、失敗は表の値のままで failure に例外) */
|
|
16
|
+
export declare function readDaily(db: Db, after: string, live?: {
|
|
17
|
+
source: Source;
|
|
18
|
+
today: string;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
rows: DailyRow[];
|
|
21
|
+
live: boolean;
|
|
22
|
+
failure?: unknown;
|
|
23
|
+
}>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Body } from './types.js';
|
|
2
|
+
/** 属性(Markdown の `{…}`、値は文字列) */
|
|
3
|
+
export type Attributes = Readonly<Record<string, string>>;
|
|
4
|
+
/** コンポーネントの Markdown の記法(to と from で往復して同じ props に戻ること) */
|
|
5
|
+
export type ComponentMarkdown<M> = Readonly<{
|
|
6
|
+
to(props: unknown): Readonly<{
|
|
7
|
+
attributes?: Attributes;
|
|
8
|
+
content?: Body<M>;
|
|
9
|
+
}>;
|
|
10
|
+
from(attributes: Attributes, content: Body<M>): unknown;
|
|
11
|
+
}>;
|
|
12
|
+
/** カスタムコンポーネントの定義(inline はインラインのコンポーネント、description と example は Markdown の説明に使用) */
|
|
13
|
+
export type ComponentDef<M> = Readonly<{
|
|
14
|
+
name: string;
|
|
15
|
+
inline?: boolean;
|
|
16
|
+
description?: string;
|
|
17
|
+
example?: string;
|
|
18
|
+
markdown?: ComponentMarkdown<M>;
|
|
19
|
+
}>;
|
|
20
|
+
/** 予約の名前(ブロック) */
|
|
21
|
+
export declare const RESERVED_BLOCK_NAMES: ReadonlySet<string>;
|
|
22
|
+
/** 予約の名前(インライン) */
|
|
23
|
+
export declare const RESERVED_INLINE_NAMES: ReadonlySet<string>;
|
|
24
|
+
/** 既定の記法: props を JSON のコードブロックに */
|
|
25
|
+
export declare const jsonMarkdown: ComponentMarkdown<never>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type ComponentDef } from './components.js';
|
|
3
|
+
/** 引数の型 */
|
|
4
|
+
export type PropType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
|
|
5
|
+
/** 1つの引数の形(title は管理画面の項目名、enum は文字列の選択肢、items は配列の要素、properties・required はオブジェクトの中) */
|
|
6
|
+
export type PropSchema = Readonly<{
|
|
7
|
+
type: PropType;
|
|
8
|
+
title?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
enum?: readonly string[];
|
|
11
|
+
items?: PropSchema;
|
|
12
|
+
properties?: Readonly<Record<string, PropSchema>>;
|
|
13
|
+
required?: readonly string[];
|
|
14
|
+
}>;
|
|
15
|
+
/** 引数の全体の形(最上位はオブジェクト) */
|
|
16
|
+
export type PropsSchema = Readonly<{
|
|
17
|
+
type: 'object';
|
|
18
|
+
properties: Readonly<Record<string, PropSchema>>;
|
|
19
|
+
required?: readonly string[];
|
|
20
|
+
}>;
|
|
21
|
+
/** 導入先が宣言する部品(label は管理画面の表示名、inline の省略はブロック) */
|
|
22
|
+
export type DeclaredComponent = Readonly<{
|
|
23
|
+
name: string;
|
|
24
|
+
label: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
inline?: boolean;
|
|
27
|
+
props: PropsSchema;
|
|
28
|
+
}>;
|
|
29
|
+
/** 宣言の一覧の検査(名前の重複も拒否) */
|
|
30
|
+
export declare const declaredComponentsSchema: z.ZodType<readonly DeclaredComponent[]>;
|
|
31
|
+
/** 宣言した部品の引数の検査(宣言ごとに作成を再利用) */
|
|
32
|
+
export declare function declaredPropsZod(d: DeclaredComponent): z.ZodType;
|
|
33
|
+
/** 宣言から Markdown の変換と説明に使用する部品の定義(記法は既定の JSON) */
|
|
34
|
+
export declare const declaredDefOf: (d: DeclaredComponent) => ComponentDef<never>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Body, Rich } from './types.js';
|
|
2
|
+
/** 読了時間の既定の分速(字/分) */
|
|
3
|
+
export declare const READING_SPEED = 500;
|
|
4
|
+
/** 断片の列の文字(装飾・リンクは文字、インラインのコンポーネントは中の文字) */
|
|
5
|
+
export declare const plainOf: (rich: Rich) => string;
|
|
6
|
+
/** 本文の注が参照する出典の ID(出現の順、重複あり) */
|
|
7
|
+
export declare function citesOf<M>(body: Body<M>): string[];
|
|
8
|
+
/** 本文の導入の文字(最初の見出しまでの段落をつなげたもの、導入がなければ空) */
|
|
9
|
+
export declare function excerptOf<M>(body: Body<M>): string;
|
|
10
|
+
/** 読了時間(分、本文の文字列の字数を分速 speed で割った概算、1分以上) */
|
|
11
|
+
export declare const readMinOf: <M>(body: Body<M>, speed?: number) => number;
|
|
12
|
+
/** 本文にあるサイト内へのリンク先(`/` で始まる href、重複なし) */
|
|
13
|
+
export declare const linksOf: <M>(body: Body<M>) => string[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** meta description の長さの上限(検索結果で省略されにくい字数の目安) */
|
|
2
|
+
export declare const DESCRIPTION_MAX = 120;
|
|
3
|
+
/**
|
|
4
|
+
* 説明を meta description の長さに調整
|
|
5
|
+
* - 上限を超える場合: 上限までの最後の句点まで
|
|
6
|
+
* - 句点がない場合: 上限で切って省略の記号
|
|
7
|
+
*/
|
|
8
|
+
export declare function descriptionOf(excerpt: string, max?: number): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type { ComponentDef } from './components.js';
|
|
2
|
+
export { type DeclaredComponent, declaredComponentsSchema, declaredDefOf, declaredPropsZod, type PropSchema, type PropsSchema, type PropType } from './declared.js';
|
|
3
|
+
export { DESCRIPTION_MAX, descriptionOf } from './description.js';
|
|
4
|
+
export { citesOf, excerptOf, linksOf, plainOf, READING_SPEED, readMinOf } from './derive.js';
|
|
5
|
+
export { CORE_COMPONENTS, coreComponentOf, type Chart, type ChartColor, type ChartDatum, type ComponentName, type ComponentProps, type CoreComponent } from './library.js';
|
|
6
|
+
export { isSafeHref } from './href.js';
|
|
7
|
+
export { fromMarkdown, toMarkdown, type MarkdownOptions } from './markdown.js';
|
|
8
|
+
export { checkBody, describeMarkdown, type BodyProfile } from './profile.js';
|
|
9
|
+
export { blockSchemaOf } from './schema.js';
|
|
10
|
+
export { bodyFromMarkdown, bodyToMarkdown, markdownGuide, type MarkdownResult, type MediaSyntax } from './standard.js';
|
|
11
|
+
export type { Block, Body, ComponentBlock, HeadingLevel, Inline, InlineComponent, Link, List, ListItem, Mark, Rich, StandardBlock, Text } from './types.js';
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ComponentDef } from './components.js';
|
|
3
|
+
/** グラフの項目と値 */
|
|
4
|
+
export type ChartDatum = Readonly<{
|
|
5
|
+
label: string;
|
|
6
|
+
value: number;
|
|
7
|
+
}>;
|
|
8
|
+
/** グラフの色(テーマの系列の番号) */
|
|
9
|
+
export type ChartColor = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
10
|
+
/**
|
|
11
|
+
* グラフ(コンポーネント chart の props から caption を除いた形)
|
|
12
|
+
* - bar: 横棒、pie: 割合
|
|
13
|
+
* - line: 折れ線(series の values は labels と同じ長さ)
|
|
14
|
+
* - heat: 濃淡の表(rows の values は cols と同じ長さ)
|
|
15
|
+
*/
|
|
16
|
+
export type Chart = Readonly<{
|
|
17
|
+
chart: 'bar';
|
|
18
|
+
data: readonly ChartDatum[];
|
|
19
|
+
unit: string;
|
|
20
|
+
color?: ChartColor;
|
|
21
|
+
} | {
|
|
22
|
+
chart: 'line';
|
|
23
|
+
labels: readonly string[];
|
|
24
|
+
series: readonly Readonly<{
|
|
25
|
+
name: string;
|
|
26
|
+
values: readonly number[];
|
|
27
|
+
}>[];
|
|
28
|
+
unit: string;
|
|
29
|
+
} | {
|
|
30
|
+
chart: 'pie';
|
|
31
|
+
data: readonly ChartDatum[];
|
|
32
|
+
unit: string;
|
|
33
|
+
} | {
|
|
34
|
+
chart: 'heat';
|
|
35
|
+
cols: readonly string[];
|
|
36
|
+
rows: readonly Readonly<{
|
|
37
|
+
label: string;
|
|
38
|
+
values: readonly number[];
|
|
39
|
+
}>[];
|
|
40
|
+
unit: string;
|
|
41
|
+
color?: ChartColor;
|
|
42
|
+
}>;
|
|
43
|
+
/** 核のコンポーネントの props(名前ごと、インラインは属性) */
|
|
44
|
+
export type ComponentProps<M> = Readonly<{
|
|
45
|
+
cite: Readonly<{
|
|
46
|
+
id: string;
|
|
47
|
+
}>;
|
|
48
|
+
pending: Readonly<Record<string, never>>;
|
|
49
|
+
speech: Readonly<{
|
|
50
|
+
text: string;
|
|
51
|
+
}>;
|
|
52
|
+
chart: Chart & Readonly<{
|
|
53
|
+
caption: string;
|
|
54
|
+
}>;
|
|
55
|
+
diagram: Readonly<{
|
|
56
|
+
source: string;
|
|
57
|
+
alt: string;
|
|
58
|
+
caption: string;
|
|
59
|
+
}>;
|
|
60
|
+
gallery: Readonly<{
|
|
61
|
+
items: readonly Readonly<{
|
|
62
|
+
media: M;
|
|
63
|
+
caption?: string;
|
|
64
|
+
}>[];
|
|
65
|
+
}>;
|
|
66
|
+
'link-card': Readonly<{
|
|
67
|
+
href: `https://${string}`;
|
|
68
|
+
title: string;
|
|
69
|
+
site?: string;
|
|
70
|
+
desc?: string;
|
|
71
|
+
image?: M;
|
|
72
|
+
}>;
|
|
73
|
+
links: Readonly<{
|
|
74
|
+
label?: string;
|
|
75
|
+
items: readonly Readonly<{
|
|
76
|
+
href: `https://${string}`;
|
|
77
|
+
title: string;
|
|
78
|
+
site?: string;
|
|
79
|
+
}>[];
|
|
80
|
+
}>;
|
|
81
|
+
}>;
|
|
82
|
+
/** 核のコンポーネントの名前 */
|
|
83
|
+
export type ComponentName = keyof ComponentProps<unknown>;
|
|
84
|
+
/** 核のコンポーネントの定義(props は検査、インラインは属性の検査) */
|
|
85
|
+
export type CoreComponent = ComponentDef<unknown> & Readonly<{
|
|
86
|
+
name: ComponentName;
|
|
87
|
+
props: (media: z.ZodType) => z.ZodType;
|
|
88
|
+
}>;
|
|
89
|
+
/** 注のコンポーネントの名前(本文からの算出 citesOf が参照) */
|
|
90
|
+
export declare const CITE = "cite";
|
|
91
|
+
/** 核のコンポーネント(chart の Markdown は既定の JSON) */
|
|
92
|
+
export declare const CORE_COMPONENTS: readonly CoreComponent[];
|
|
93
|
+
/** 名前から核のコンポーネント(なければ undefined) */
|
|
94
|
+
export declare const coreComponentOf: (name: string) => CoreComponent | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ComponentDef } from './components.js';
|
|
2
|
+
import type { Body } from './types.js';
|
|
3
|
+
/** マッパーの設定(media は画像の参照と Markdown の文字列の変換) */
|
|
4
|
+
export type MarkdownOptions<M> = Readonly<{
|
|
5
|
+
media: Readonly<{
|
|
6
|
+
toSrc(media: M): string;
|
|
7
|
+
fromSrc(src: string): M;
|
|
8
|
+
}>;
|
|
9
|
+
components?: readonly ComponentDef<M>[];
|
|
10
|
+
}>;
|
|
11
|
+
/** 本文を Markdown に */
|
|
12
|
+
export declare function toMarkdown<M>(body: Body<M>, options: MarkdownOptions<M>): string;
|
|
13
|
+
/** Markdown を本文に(解析できない構文は例外) */
|
|
14
|
+
export declare function fromMarkdown<M>(markdown: string, options: MarkdownOptions<M>): Body<M>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Body, Mark, Rich } from './types.js';
|
|
2
|
+
/** 装飾の順序(Markdown では外側から内側) */
|
|
3
|
+
export declare const MARK_ORDER: readonly Mark[];
|
|
4
|
+
/** インラインの断片の列を正規化 */
|
|
5
|
+
export declare function normalizeRich(rich: Rich): Rich;
|
|
6
|
+
/** 本文を正規化 */
|
|
7
|
+
export declare function normalizeBody<M>(body: Body<M>): Body<M>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ComponentDef } from './components.js';
|
|
2
|
+
import type { Body, HeadingLevel, Mark } from './types.js';
|
|
3
|
+
/** 本文の設定 */
|
|
4
|
+
export type BodyProfile = Readonly<{
|
|
5
|
+
headings: readonly HeadingLevel[];
|
|
6
|
+
marks: readonly Mark[];
|
|
7
|
+
/** 装飾の重ね掛けと装飾つきのリンク(既定は可) */
|
|
8
|
+
combineMarks?: boolean;
|
|
9
|
+
/** リンクの rel(なしは rel なしのリンクだけ) */
|
|
10
|
+
linkRels?: readonly string[];
|
|
11
|
+
/** 装飾・リンク・インラインのコンポーネントを使用できない場所 */
|
|
12
|
+
plain?: readonly ('heading' | 'tableHead')[];
|
|
13
|
+
list?: Readonly<{
|
|
14
|
+
ordered: boolean;
|
|
15
|
+
nested: boolean;
|
|
16
|
+
variants?: readonly string[];
|
|
17
|
+
}>;
|
|
18
|
+
quote?: Readonly<{
|
|
19
|
+
multiple: boolean;
|
|
20
|
+
cite: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
/** コード(componentLangs はコンポーネントで書く言語とコンポーネントの名前、例: mermaid は図、その言語のフェンスだけのコードは不可) */
|
|
23
|
+
code?: Readonly<{
|
|
24
|
+
caption: boolean;
|
|
25
|
+
componentLangs?: Readonly<Record<string, string>>;
|
|
26
|
+
}>;
|
|
27
|
+
image?: Readonly<{
|
|
28
|
+
variants?: readonly string[];
|
|
29
|
+
}>;
|
|
30
|
+
table?: Readonly<{
|
|
31
|
+
head: 'required' | 'optional';
|
|
32
|
+
caption: 'required' | 'optional' | 'none';
|
|
33
|
+
}>;
|
|
34
|
+
divider?: true;
|
|
35
|
+
html?: true;
|
|
36
|
+
/** 使用できるコンポーネントの名前(ブロック・インライン) */
|
|
37
|
+
components: readonly string[];
|
|
38
|
+
}>;
|
|
39
|
+
/** 本文の設定に合わない箇所(index は本文のブロックの位置、0から) */
|
|
40
|
+
type BodyProblem = Readonly<{
|
|
41
|
+
index: number;
|
|
42
|
+
message: string;
|
|
43
|
+
}>;
|
|
44
|
+
/** 本文を設定で検査(合わない箇所をすべて返却) */
|
|
45
|
+
export declare function checkBody<M>(body: Body<M>, profile: BodyProfile): BodyProblem[];
|
|
46
|
+
/** 書き手と AI への Markdown の説明(使用できるものを記法の例つきで列挙し、使用できないものは末尾) */
|
|
47
|
+
export declare function describeMarkdown<M>(profile: BodyProfile, components?: readonly ComponentDef<M>[]): string;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type DeclaredComponent } from './declared.js';
|
|
3
|
+
import { type BodyProfile } from './profile.js';
|
|
4
|
+
import type { Block } from './types.js';
|
|
5
|
+
/** 本文の1ブロックの検査(profile は本文の設定、media は画像の参照の検査、declared は導入先が宣言した部品) */
|
|
6
|
+
export declare function blockSchemaOf<M>(profile: BodyProfile, media: z.ZodType<M>, declared?: readonly DeclaredComponent[]): z.ZodType<Block<M>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type DeclaredComponent } from './declared.js';
|
|
2
|
+
import { type MarkdownOptions } from './markdown.js';
|
|
3
|
+
import { type BodyProfile } from './profile.js';
|
|
4
|
+
import type { Body } from './types.js';
|
|
5
|
+
/** 画像の参照と Markdown の文字列の変換(example は説明の例の参照) */
|
|
6
|
+
export type MediaSyntax<M> = MarkdownOptions<M>['media'] & Readonly<{
|
|
7
|
+
example: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** Markdown の解析の結果(problems は設定に合わない箇所のすべて) */
|
|
10
|
+
export type MarkdownResult<M> = Readonly<{
|
|
11
|
+
body: Body<M>;
|
|
12
|
+
}> | Readonly<{
|
|
13
|
+
problems: readonly string[];
|
|
14
|
+
}>;
|
|
15
|
+
/** 本文を Markdown に(declared は導入先が宣言した部品) */
|
|
16
|
+
export declare const bodyToMarkdown: <M>(body: Body<M>, media: MediaSyntax<M>, declared?: readonly DeclaredComponent[]) => string;
|
|
17
|
+
/** Markdown を本文に(解析できない・設定に合わない内容は problems、declared は導入先が宣言した部品) */
|
|
18
|
+
export declare function bodyFromMarkdown<M>(markdown: string, profile: BodyProfile, media: MediaSyntax<M>, declared?: readonly DeclaredComponent[]): MarkdownResult<M>;
|
|
19
|
+
/** 書き手と AI へ最初に提示する Markdown の説明(設定と核のコンポーネント・宣言した部品から作成) */
|
|
20
|
+
export declare const markdownGuide: (profile: BodyProfile, media: Pick<MediaSyntax<unknown>, "example">, declared?: readonly DeclaredComponent[]) => string;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** インラインの装飾(strong・em・code・s・mark・sup・sub) */
|
|
2
|
+
export type Mark = 'strong' | 'em' | 'code' | 'strike' | 'mark' | 'sup' | 'sub';
|
|
3
|
+
/** リンク(HTML の a の href・title・rel) */
|
|
4
|
+
export type Link = Readonly<{
|
|
5
|
+
href: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
rel?: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** 装飾・リンクつきの文字列 */
|
|
10
|
+
export type Text = Readonly<{
|
|
11
|
+
text: string;
|
|
12
|
+
marks?: readonly Mark[];
|
|
13
|
+
link?: Link;
|
|
14
|
+
}>;
|
|
15
|
+
/** インラインのコンポーネント(例: 注、属性は文字列だけ、text は中の文字) */
|
|
16
|
+
export type InlineComponent = Readonly<{
|
|
17
|
+
component: string;
|
|
18
|
+
props?: Readonly<Record<string, string>>;
|
|
19
|
+
text?: string;
|
|
20
|
+
}>;
|
|
21
|
+
/** インラインの断片(文字列は装飾なし) */
|
|
22
|
+
export type Inline = string | Text | InlineComponent;
|
|
23
|
+
/** インラインの断片の列(1つの段落・見出し・セルの内容) */
|
|
24
|
+
export type Rich = readonly Inline[];
|
|
25
|
+
/** 見出しの段階 */
|
|
26
|
+
export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
27
|
+
/** リストの1項目(children は入れ子のリスト) */
|
|
28
|
+
export type ListItem = Readonly<{
|
|
29
|
+
content: Rich;
|
|
30
|
+
children?: List;
|
|
31
|
+
}>;
|
|
32
|
+
/** リスト */
|
|
33
|
+
export type List = Readonly<{
|
|
34
|
+
type: 'list';
|
|
35
|
+
ordered?: boolean;
|
|
36
|
+
items: readonly ListItem[];
|
|
37
|
+
variant?: string;
|
|
38
|
+
}>;
|
|
39
|
+
/** 標準のブロック */
|
|
40
|
+
export type StandardBlock<M> = Readonly<{
|
|
41
|
+
type: 'paragraph';
|
|
42
|
+
content: Rich;
|
|
43
|
+
variant?: string;
|
|
44
|
+
}> | Readonly<{
|
|
45
|
+
type: 'heading';
|
|
46
|
+
level: HeadingLevel;
|
|
47
|
+
content: Rich;
|
|
48
|
+
id?: string;
|
|
49
|
+
variant?: string;
|
|
50
|
+
}> | List | Readonly<{
|
|
51
|
+
type: 'quote';
|
|
52
|
+
content: readonly Rich[];
|
|
53
|
+
cite?: Readonly<{
|
|
54
|
+
label: string;
|
|
55
|
+
href?: string;
|
|
56
|
+
}>;
|
|
57
|
+
variant?: string;
|
|
58
|
+
}> | Readonly<{
|
|
59
|
+
type: 'code';
|
|
60
|
+
code: string;
|
|
61
|
+
lang?: string;
|
|
62
|
+
caption?: string;
|
|
63
|
+
variant?: string;
|
|
64
|
+
}> | Readonly<{
|
|
65
|
+
type: 'image';
|
|
66
|
+
media: M;
|
|
67
|
+
alt?: string;
|
|
68
|
+
caption?: string;
|
|
69
|
+
variant?: string;
|
|
70
|
+
}> | Readonly<{
|
|
71
|
+
type: 'table';
|
|
72
|
+
head?: readonly Rich[];
|
|
73
|
+
rows: readonly (readonly Rich[])[];
|
|
74
|
+
caption?: string;
|
|
75
|
+
variant?: string;
|
|
76
|
+
}> | Readonly<{
|
|
77
|
+
type: 'divider';
|
|
78
|
+
}> | Readonly<{
|
|
79
|
+
type: 'html';
|
|
80
|
+
html: string;
|
|
81
|
+
}>;
|
|
82
|
+
/** カスタムコンポーネントのブロック(props は JSON で表せる値) */
|
|
83
|
+
export type ComponentBlock = Readonly<{
|
|
84
|
+
type: 'component';
|
|
85
|
+
name: string;
|
|
86
|
+
props: unknown;
|
|
87
|
+
}>;
|
|
88
|
+
/** 本文のブロック */
|
|
89
|
+
export type Block<M> = StandardBlock<M> | ComponentBlock;
|
|
90
|
+
/** 本文 */
|
|
91
|
+
export type Body<M> = readonly Block<M>[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** 一覧に表示する API の鍵(tail は鍵の末尾、revokedAt は失効の日時で有効なら null) */
|
|
2
|
+
export type ApiKey = Readonly<{
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
tail: string;
|
|
6
|
+
createdAt: string;
|
|
7
|
+
revokedAt: string | null;
|
|
8
|
+
}>;
|
|
9
|
+
/** 公開のエンドポイントで鍵ごとの回数の上限(period は秒) */
|
|
10
|
+
export declare const API_KEY_RATE: {
|
|
11
|
+
readonly limit: 600;
|
|
12
|
+
readonly period: 60;
|
|
13
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** まとめての削除・元に戻すで1回のリクエストに指定できる画像の数(超える分は管理画面が分割して送信) */
|
|
2
|
+
export declare const ASSET_BULK_MAX = 500;
|
|
3
|
+
/**
|
|
4
|
+
* アップロード・取り込みで受け付ける画像の形式(判定はファイルの先頭のバイト、申告の種類は不使用)
|
|
5
|
+
* - SVG: スクリプトを含められ、CMS のオリジンで配信すると実行されうるため対象外
|
|
6
|
+
* - AVIF: OG 画像の生成(photon)が非対応のため対象外
|
|
7
|
+
*/
|
|
8
|
+
export declare const ASSET_IMAGE_TYPES: readonly ["image/jpeg", "image/png", "image/webp", "image/gif"];
|
|
9
|
+
/** 画像1枚の大きさの上限(バイト、アップロード・取り込みで共通) */
|
|
10
|
+
export declare const ASSET_SIZE_MAX: number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ModuleManifest } from './modules.js';
|
|
2
|
+
/** 計測(閲覧数の集計・ダッシュボードの閲覧数) */
|
|
3
|
+
export declare const ANALYTICS_MODULE: ModuleManifest;
|
|
4
|
+
/** OG 画像の自動生成で選択できる書体(id と表示名、文字の範囲はサーバーの側の OG 画像のモジュール) */
|
|
5
|
+
export declare const OG_FONTS: {
|
|
6
|
+
readonly 'noto-serif-jp': "Noto Serif JP(明朝)";
|
|
7
|
+
};
|
|
8
|
+
/** OG 画像の書体の id */
|
|
9
|
+
export type OgFont = keyof typeof OG_FONTS;
|
|
10
|
+
/** OG 画像の設定値(font は自動生成の画像の書体、なしは書体の点検なし) */
|
|
11
|
+
export type OgSettings = Readonly<{
|
|
12
|
+
font?: OgFont;
|
|
13
|
+
}>;
|
|
14
|
+
/** OG 画像(自動生成の画像に付く規則、導入先の設定 modules の og に書体) */
|
|
15
|
+
export declare const OG_MODULE: ModuleManifest<OgSettings>;
|
|
16
|
+
/** コアに組み込みのモジュール(登録の順) */
|
|
17
|
+
export declare const BUILTIN_MODULES: readonly ModuleManifest<unknown>[];
|