forked from deco-cx/deco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
133 lines (120 loc) · 3.96 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// deno-lint-ignore-file no-explicit-any ban-types
import type { Manifest } from "$fresh/server.ts";
import accountBlock from "./blocks/account.ts";
import actionBlock from "./blocks/action.ts";
import appBlock, {
AppContext,
AppManifest,
AppModule,
AppRuntime,
} from "./blocks/app.ts";
import flagBlock from "./blocks/flag.ts";
import functionBlock from "./blocks/function.ts";
import handlerBlock from "./blocks/handler.ts";
import loaderBlock from "./blocks/loader.ts";
import matcherBlock from "./blocks/matcher.ts";
import pageBlock from "./blocks/page.tsx";
import sectionBlock from "./blocks/section.ts";
import { FnContext } from "./blocks/utils.tsx";
import workflowBlock from "./blocks/workflow.ts";
import type { InvocationFunc } from "./clients/withManifest.ts";
import type { JSONSchema7, JSONSchema7Definition } from "./deps.ts";
import { ModuleOf } from "./engine/block.ts";
import { Monitoring, ResolveFunc } from "./engine/core/resolver.ts";
import { PromiseOrValue } from "./engine/core/utils.ts";
import { Release } from "./engine/releases/provider.ts";
import { Route } from "./flags/audience.ts";
import type { InvocationProxy } from "./routes/live/invoke/index.ts";
import { createServerTimings } from "./utils/timings.ts";
export type {
ErrorBoundaryComponent,
ErrorBoundaryParams,
} from "./blocks/section.ts";
export type { AppContext, AppManifest, AppModule, AppRuntime };
export type { App } from "./blocks/app.ts";
export type JSONSchema = JSONSchema7;
export type JSONSchemaDefinition = JSONSchema7Definition;
export interface DecoManifest extends Manifest {
name: string;
baseUrl: string;
apps?: Record<string, ModuleOf<typeof appBlock>>;
workflows?: Record<string, ModuleOf<typeof workflowBlock>>;
actions?: Record<string, ModuleOf<typeof actionBlock>>;
sections?: Record<string, ModuleOf<typeof sectionBlock>>;
functions?: Record<string, ModuleOf<typeof functionBlock>>;
loaders?: Record<string, ModuleOf<typeof loaderBlock>>;
pages?: Record<string, ModuleOf<typeof pageBlock>>;
matchers?: Record<string, ModuleOf<typeof matcherBlock>>;
handlers?: Record<string, ModuleOf<typeof handlerBlock>>;
flags?: Record<string, ModuleOf<typeof flagBlock>>;
accounts?: Record<string, ModuleOf<typeof accountBlock>>;
}
export interface Site {
id: number;
name: string;
thumb_url?: string;
github_repo_url?: string;
created_from?: Site;
domains?: Array<{ domain: string; production: boolean }>;
}
export interface SiteInfo {
siteId?: number;
namespace: string;
}
export type DecoSiteState<T = unknown> = {
site: Site;
t: ReturnType<typeof createServerTimings>;
monitoring: Monitoring;
global: T;
};
export interface Flag {
name: string;
value: boolean;
}
export interface StatefulContext<T> {
params: Record<string, string>;
state: T;
}
export type DecoState<
TConfig = any,
TState = {},
TManifest extends AppManifest = AppManifest,
> =
& TState
& {
correlationId?: string;
debugEnabled?: boolean;
$live: TConfig;
resolve: ResolveFunc;
release: Release;
invoke:
& InvocationProxy<
TManifest
>
& InvocationFunc<TManifest>;
routes?: Route[];
flags: Flag[];
pathTemplate: string;
};
export type { PropsLoader } from "./blocks/propsLoader.ts";
export type { SectionProps } from "./blocks/section.ts";
export type { FnContext } from "./blocks/utils.tsx";
export type ActionContext<
TState = {},
TManifest extends AppManifest = AppManifest,
> = FnContext<TState, TManifest>;
export type LoaderContext<
TState = {},
TManifest extends AppManifest = AppManifest,
> = FnContext<TState, TManifest>;
export type FunctionContext<TProps = any, TState = {}> = StatefulContext<
DecoState<TProps, TState>
>;
export type LoaderFunction<Props = any, Data = any, State = any> = (
req: Request,
ctx: FunctionContext<Props, State>,
props: Props,
) => PromiseOrValue<
{ data: Data } & Partial<Pick<Response, "status" | "headers">>
>;
export type LoaderReturnType<O = unknown> = O;