@drfed/drfed 0.0.0-stage → 0.1.0-dev.0
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/LICENSE +661 -0
- package/README.md +1198 -2
- package/bin/drfed-account.mjs +20 -0
- package/bin/drfed-migrate.mjs +20 -0
- package/bin/drfed-server.mjs +20 -0
- package/bin/drfed-web.mjs +20 -0
- package/completions/bash/drfed-account +219 -0
- package/completions/bash/drfed-migrate +219 -0
- package/completions/bash/drfed-server +219 -0
- package/completions/bash/drfed-web +219 -0
- package/completions/fish/drfed-account.fish +264 -0
- package/completions/fish/drfed-migrate.fish +264 -0
- package/completions/fish/drfed-server.fish +264 -0
- package/completions/fish/drfed-web.fish +264 -0
- package/completions/nu/drfed-account.nu +293 -0
- package/completions/nu/drfed-migrate.nu +293 -0
- package/completions/nu/drfed-server.nu +293 -0
- package/completions/nu/drfed-web.nu +293 -0
- package/completions/pwsh/drfed-account.ps1 +183 -0
- package/completions/pwsh/drfed-migrate.ps1 +183 -0
- package/completions/pwsh/drfed-server.ps1 +183 -0
- package/completions/pwsh/drfed-web.ps1 +183 -0
- package/completions/zsh/_drfed-account +145 -0
- package/completions/zsh/_drfed-migrate +145 -0
- package/completions/zsh/_drfed-server +145 -0
- package/completions/zsh/_drfed-web +145 -0
- package/dist/api-mail-parser.d.mts +106 -0
- package/dist/api-mail-parser.d.mts.map +1 -0
- package/dist/api-mail-parser.mjs +145 -0
- package/dist/api-mail-parser.mjs.map +1 -0
- package/dist/api-mail-settings-BcGaqQ9f.d.mts +142 -0
- package/dist/api-mail-settings-BcGaqQ9f.d.mts.map +1 -0
- package/dist/api-mail-settings.d.mts +2 -0
- package/dist/api-mail-settings.mjs +272 -0
- package/dist/api-mail-settings.mjs.map +1 -0
- package/dist/bounded-mail-runtime.d.mts +9 -0
- package/dist/bounded-mail-runtime.d.mts.map +1 -0
- package/dist/bounded-mail-runtime.mjs +66 -0
- package/dist/bounded-mail-runtime.mjs.map +1 -0
- package/dist/commands/account-create.d.mts +37 -0
- package/dist/commands/account-create.d.mts.map +1 -0
- package/dist/commands/account-create.mjs +87 -0
- package/dist/commands/account-create.mjs.map +1 -0
- package/dist/commands/account-program.d.mts +223 -0
- package/dist/commands/account-program.d.mts.map +1 -0
- package/dist/commands/account-program.mjs +116 -0
- package/dist/commands/account-program.mjs.map +1 -0
- package/dist/commands/account.d.mts +6 -0
- package/dist/commands/account.d.mts.map +1 -0
- package/dist/commands/account.mjs +91 -0
- package/dist/commands/account.mjs.map +1 -0
- package/dist/commands/migrate-program.d.mts +219 -0
- package/dist/commands/migrate-program.d.mts.map +1 -0
- package/dist/commands/migrate-program.mjs +116 -0
- package/dist/commands/migrate-program.mjs.map +1 -0
- package/dist/commands/migrate.d.mts +6 -0
- package/dist/commands/migrate.d.mts.map +1 -0
- package/dist/commands/migrate.mjs +85 -0
- package/dist/commands/migrate.mjs.map +1 -0
- package/dist/commands/web-program.d.mts +213 -0
- package/dist/commands/web-program.d.mts.map +1 -0
- package/dist/commands/web-program.mjs +112 -0
- package/dist/commands/web-program.mjs.map +1 -0
- package/dist/commands/web.d.mts +6 -0
- package/dist/commands/web.d.mts.map +1 -0
- package/dist/commands/web.mjs +184 -0
- package/dist/commands/web.mjs.map +1 -0
- package/dist/configuration-DVVF7xNv.d.mts +432 -0
- package/dist/configuration-DVVF7xNv.d.mts.map +1 -0
- package/dist/configuration.d.mts +2 -0
- package/dist/configuration.mjs +469 -0
- package/dist/configuration.mjs.map +1 -0
- package/dist/data-path.d.mts +9 -0
- package/dist/data-path.d.mts.map +1 -0
- package/dist/data-path.mjs +21 -0
- package/dist/data-path.mjs.map +1 -0
- package/dist/database-runtime.d.mts +26 -0
- package/dist/database-runtime.d.mts.map +1 -0
- package/dist/database-runtime.mjs +92 -0
- package/dist/database-runtime.mjs.map +1 -0
- package/dist/database-settings.d.mts +36 -0
- package/dist/database-settings.d.mts.map +1 -0
- package/dist/database-settings.mjs +67 -0
- package/dist/database-settings.mjs.map +1 -0
- package/dist/diagnostics.d.mts +29 -0
- package/dist/diagnostics.d.mts.map +1 -0
- package/dist/diagnostics.mjs +61 -0
- package/dist/diagnostics.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +344 -0
- package/dist/index.mjs.map +1 -0
- package/dist/jmap-parser.d.mts +35 -0
- package/dist/jmap-parser.d.mts.map +1 -0
- package/dist/jmap-parser.mjs +42 -0
- package/dist/jmap-parser.mjs.map +1 -0
- package/dist/jmap-runtime.d.mts +10 -0
- package/dist/jmap-runtime.d.mts.map +1 -0
- package/dist/jmap-runtime.mjs +17 -0
- package/dist/jmap-runtime.mjs.map +1 -0
- package/dist/jmap-settings-BXNAF1ep.d.mts +41 -0
- package/dist/jmap-settings-BXNAF1ep.d.mts.map +1 -0
- package/dist/jmap-settings.d.mts +2 -0
- package/dist/jmap-settings.mjs +104 -0
- package/dist/jmap-settings.mjs.map +1 -0
- package/dist/logging.d.mts +33 -0
- package/dist/logging.d.mts.map +1 -0
- package/dist/logging.mjs +56 -0
- package/dist/logging.mjs.map +1 -0
- package/dist/mail-parser-DyI4wuQp.d.mts +246 -0
- package/dist/mail-parser-DyI4wuQp.d.mts.map +1 -0
- package/dist/mail-parser.d.mts +2 -0
- package/dist/mail-parser.mjs +100 -0
- package/dist/mail-parser.mjs.map +1 -0
- package/dist/mail-runtime-YROIQ8up.mjs +314 -0
- package/dist/mail-runtime-YROIQ8up.mjs.map +1 -0
- package/dist/mail-runtime.d.mts +68 -0
- package/dist/mail-runtime.d.mts.map +1 -0
- package/dist/mail-runtime.mjs +2 -0
- package/dist/mail-settings-BD1TQ0rt.mjs +427 -0
- package/dist/mail-settings-BD1TQ0rt.mjs.map +1 -0
- package/dist/mail-settings-DjWMAUaE.d.mts +80 -0
- package/dist/mail-settings-DjWMAUaE.d.mts.map +1 -0
- package/dist/mail-settings.d.mts +2 -0
- package/dist/mail-settings.mjs +2 -0
- package/dist/operations.d.mts +32 -0
- package/dist/operations.d.mts.map +1 -0
- package/dist/operations.mjs +55 -0
- package/dist/operations.mjs.map +1 -0
- package/dist/package-7FOUqcPO.mjs +6 -0
- package/dist/package-7FOUqcPO.mjs.map +1 -0
- package/dist/parser-DGIQTgS7.mjs +178 -0
- package/dist/parser-DGIQTgS7.mjs.map +1 -0
- package/dist/parser-TANGHRjL.d.mts +305 -0
- package/dist/parser-TANGHRjL.d.mts.map +1 -0
- package/dist/postgres-settings.d.mts +20 -0
- package/dist/postgres-settings.d.mts.map +1 -0
- package/dist/postgres-settings.mjs +60 -0
- package/dist/postgres-settings.mjs.map +1 -0
- package/dist/query-logger.d.mts +9 -0
- package/dist/query-logger.d.mts.map +1 -0
- package/dist/query-logger.mjs +17 -0
- package/dist/query-logger.mjs.map +1 -0
- package/dist/resources.d.mts +20 -0
- package/dist/resources.d.mts.map +1 -0
- package/dist/resources.mjs +34 -0
- package/dist/resources.mjs.map +1 -0
- package/dist/secret-source-BeZx72Ue.d.mts +21 -0
- package/dist/secret-source-BeZx72Ue.d.mts.map +1 -0
- package/dist/secret-source.d.mts +2 -0
- package/dist/secret-source.mjs +58 -0
- package/dist/secret-source.mjs.map +1 -0
- package/dist/serving.d.mts +82 -0
- package/dist/serving.d.mts.map +1 -0
- package/dist/serving.mjs +138 -0
- package/dist/serving.mjs.map +1 -0
- package/dist/smtp-settings.d.mts +11 -0
- package/dist/smtp-settings.d.mts.map +1 -0
- package/dist/smtp-settings.mjs +38 -0
- package/dist/smtp-settings.mjs.map +1 -0
- package/dist/valueparser.d.mts +46 -0
- package/dist/valueparser.d.mts.map +1 -0
- package/dist/valueparser.mjs +121 -0
- package/dist/valueparser.mjs.map +1 -0
- package/package.json +275 -3
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { m as createConfigurationBindings, o as ConfigurationSource, r as ConfigurationFile, s as Sourced } from "../configuration-DVVF7xNv.mjs";
|
|
2
|
+
import { InferValue } from "@optique/core/parser";
|
|
3
|
+
//#region src/commands/account-program.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Construct an independent database-only command using shared source bindings.
|
|
6
|
+
* @returns Pure program metadata, contexts and the explicit TOML loader.
|
|
7
|
+
*/
|
|
8
|
+
declare function createAccountProgram(options?: Parameters<typeof createConfigurationBindings>[0]): {
|
|
9
|
+
program: {
|
|
10
|
+
metadata: {
|
|
11
|
+
name: string;
|
|
12
|
+
description: import("@optique/core/message").Message;
|
|
13
|
+
};
|
|
14
|
+
parser: import("@optique/core/modifiers").FluentParser<"sync", {
|
|
15
|
+
readonly configPath: Sourced<string> | undefined;
|
|
16
|
+
readonly dataPath: Sourced<string | undefined> | undefined;
|
|
17
|
+
readonly postgresUrl: Sourced<string | undefined> | undefined;
|
|
18
|
+
readonly migrationLockTimeout: Sourced<number | undefined> | undefined;
|
|
19
|
+
readonly email: string;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly migrate: Sourced<boolean | undefined> | undefined;
|
|
22
|
+
readonly printConfig: boolean;
|
|
23
|
+
}, ["matched", string] | ["parsing", {
|
|
24
|
+
readonly configPath: [import("@optique/core/valueparser").ValueParserResult<string> | undefined] | undefined;
|
|
25
|
+
readonly dataPath: import("@optique/core/valueparser").ValueParserResult<string> | undefined;
|
|
26
|
+
readonly postgresUrl: import("@optique/core/valueparser").ValueParserResult<URL> | undefined;
|
|
27
|
+
readonly migrationLockTimeout: import("@optique/core/valueparser").ValueParserResult<number> | undefined;
|
|
28
|
+
readonly email: import("@optique/core/valueparser").ValueParserResult<string> | undefined;
|
|
29
|
+
readonly name: import("@optique/core/valueparser").ValueParserResult<string> | undefined;
|
|
30
|
+
readonly migrate: [0, import("@optique/core/parser").ParserResult<import("@optique/core/valueparser").ValueParserResult<true> | undefined>] | [1, import("@optique/core/parser").ParserResult<import("@optique/core/valueparser").ValueParserResult<true> | undefined>] | undefined;
|
|
31
|
+
readonly printConfig: [import("@optique/core/valueparser").ValueParserResult<true> | undefined] | undefined;
|
|
32
|
+
}] | undefined>;
|
|
33
|
+
};
|
|
34
|
+
contexts: readonly [import("@optique/env").EnvContext, import("@optique/config").ConfigContext<{
|
|
35
|
+
server?: {
|
|
36
|
+
root_origin?: string | undefined;
|
|
37
|
+
listen?: string | undefined;
|
|
38
|
+
login_origins?: string[] | undefined;
|
|
39
|
+
web?: boolean | undefined;
|
|
40
|
+
} | undefined;
|
|
41
|
+
web?: {
|
|
42
|
+
public_origin?: string | undefined;
|
|
43
|
+
listen?: string | undefined;
|
|
44
|
+
backend_url?: string | undefined;
|
|
45
|
+
allow_insecure_backend?: boolean | undefined;
|
|
46
|
+
} | undefined;
|
|
47
|
+
database?: {
|
|
48
|
+
data_path?: string | undefined;
|
|
49
|
+
url?: string | undefined;
|
|
50
|
+
migrate?: boolean | undefined;
|
|
51
|
+
lock_timeout_ms?: number | undefined;
|
|
52
|
+
} | undefined;
|
|
53
|
+
telemetry?: {
|
|
54
|
+
log_level?: string | undefined;
|
|
55
|
+
log_format?: string | undefined;
|
|
56
|
+
log_output?: string | undefined;
|
|
57
|
+
} | undefined;
|
|
58
|
+
mail?: {
|
|
59
|
+
from?: string | undefined;
|
|
60
|
+
transport?: string | undefined;
|
|
61
|
+
api_key?: string | undefined;
|
|
62
|
+
api_key_file?: string | undefined;
|
|
63
|
+
plunk?: {
|
|
64
|
+
api_key?: string | undefined;
|
|
65
|
+
api_key_file?: string | undefined;
|
|
66
|
+
base_url?: string | undefined;
|
|
67
|
+
timeout_ms?: number | undefined;
|
|
68
|
+
} | undefined;
|
|
69
|
+
resend?: {
|
|
70
|
+
api_key?: string | undefined;
|
|
71
|
+
api_key_file?: string | undefined;
|
|
72
|
+
base_url?: string | undefined;
|
|
73
|
+
timeout_ms?: number | undefined;
|
|
74
|
+
retries?: number | undefined;
|
|
75
|
+
} | undefined;
|
|
76
|
+
ses?: {
|
|
77
|
+
auth?: string | undefined;
|
|
78
|
+
access_key_id?: string | undefined;
|
|
79
|
+
access_key_id_file?: string | undefined;
|
|
80
|
+
secret_access_key?: string | undefined;
|
|
81
|
+
secret_access_key_file?: string | undefined;
|
|
82
|
+
session_token?: string | undefined;
|
|
83
|
+
session_token_file?: string | undefined;
|
|
84
|
+
region?: string | undefined;
|
|
85
|
+
timeout_ms?: number | undefined;
|
|
86
|
+
} | undefined;
|
|
87
|
+
sendgrid?: {
|
|
88
|
+
api_key?: string | undefined;
|
|
89
|
+
api_key_file?: string | undefined;
|
|
90
|
+
base_url?: string | undefined;
|
|
91
|
+
timeout_ms?: number | undefined;
|
|
92
|
+
} | undefined;
|
|
93
|
+
mailgun?: {
|
|
94
|
+
api_key?: string | undefined;
|
|
95
|
+
api_key_file?: string | undefined;
|
|
96
|
+
domain?: string | undefined;
|
|
97
|
+
region?: string | undefined;
|
|
98
|
+
base_url?: string | undefined;
|
|
99
|
+
timeout_ms?: number | undefined;
|
|
100
|
+
} | undefined;
|
|
101
|
+
mailtrap?: {
|
|
102
|
+
api_token?: string | undefined;
|
|
103
|
+
api_token_file?: string | undefined;
|
|
104
|
+
sandbox?: boolean | undefined;
|
|
105
|
+
inbox_id?: string | undefined;
|
|
106
|
+
send_base_url?: string | undefined;
|
|
107
|
+
sandbox_base_url?: string | undefined;
|
|
108
|
+
timeout_ms?: number | undefined;
|
|
109
|
+
} | undefined;
|
|
110
|
+
maileroo?: {
|
|
111
|
+
api_key?: string | undefined;
|
|
112
|
+
api_key_file?: string | undefined;
|
|
113
|
+
base_url?: string | undefined;
|
|
114
|
+
timeout_ms?: number | undefined;
|
|
115
|
+
} | undefined;
|
|
116
|
+
lettermint?: {
|
|
117
|
+
api_token?: string | undefined;
|
|
118
|
+
api_token_file?: string | undefined;
|
|
119
|
+
base_url?: string | undefined;
|
|
120
|
+
route?: string | undefined;
|
|
121
|
+
timeout_ms?: number | undefined;
|
|
122
|
+
retries?: number | undefined;
|
|
123
|
+
} | undefined;
|
|
124
|
+
jmap?: {
|
|
125
|
+
session_url?: string | undefined;
|
|
126
|
+
bearer_token?: string | undefined;
|
|
127
|
+
bearer_token_file?: string | undefined;
|
|
128
|
+
user?: string | undefined;
|
|
129
|
+
password?: string | undefined;
|
|
130
|
+
password_file?: string | undefined;
|
|
131
|
+
account_id?: string | undefined;
|
|
132
|
+
identity_id?: string | undefined;
|
|
133
|
+
base_url?: string | undefined;
|
|
134
|
+
timeout_ms?: number | undefined;
|
|
135
|
+
session_cache_ttl_ms?: number | undefined;
|
|
136
|
+
} | undefined;
|
|
137
|
+
smtp?: {
|
|
138
|
+
url?: string | undefined;
|
|
139
|
+
host?: string | undefined;
|
|
140
|
+
port?: number | undefined;
|
|
141
|
+
tls?: string | undefined;
|
|
142
|
+
user?: string | undefined;
|
|
143
|
+
password?: string | undefined;
|
|
144
|
+
password_file?: string | undefined;
|
|
145
|
+
auth_method?: string | undefined;
|
|
146
|
+
access_token?: string | undefined;
|
|
147
|
+
access_token_file?: string | undefined;
|
|
148
|
+
connection_timeout_ms?: number | undefined;
|
|
149
|
+
socket_timeout_ms?: number | undefined;
|
|
150
|
+
pool_size?: number | undefined;
|
|
151
|
+
local_name?: string | undefined;
|
|
152
|
+
ca_file?: string | undefined;
|
|
153
|
+
cert_file?: string | undefined;
|
|
154
|
+
key_file?: string | undefined;
|
|
155
|
+
} | undefined;
|
|
156
|
+
log_content?: boolean | undefined;
|
|
157
|
+
} | undefined;
|
|
158
|
+
}, import("@optique/config").ConfigMeta>];
|
|
159
|
+
load: (parsed: {
|
|
160
|
+
readonly configPath?: Sourced<string> | undefined;
|
|
161
|
+
}) => Promise<{
|
|
162
|
+
config: ConfigurationFile;
|
|
163
|
+
meta: import("@optique/config").ConfigMeta;
|
|
164
|
+
} | undefined>;
|
|
165
|
+
};
|
|
166
|
+
type RawAccountOptions = InferValue<ReturnType<typeof createAccountProgram>["program"]["parser"]>;
|
|
167
|
+
/**
|
|
168
|
+
* Select the winning database and retain source-only diagnostic metadata.
|
|
169
|
+
* @returns Validated command settings without acquiring runtime resources.
|
|
170
|
+
*/
|
|
171
|
+
declare function resolveAccountOptions(raw: RawAccountOptions, cwd?: string): {
|
|
172
|
+
email: string;
|
|
173
|
+
name: string;
|
|
174
|
+
database: {
|
|
175
|
+
driver: "postgres";
|
|
176
|
+
databaseUrl: URL;
|
|
177
|
+
dataPath?: never;
|
|
178
|
+
lockTimeoutMs: number;
|
|
179
|
+
migrate: boolean;
|
|
180
|
+
} | {
|
|
181
|
+
databaseUrl?: never;
|
|
182
|
+
driver: "pglite";
|
|
183
|
+
dataPath: string;
|
|
184
|
+
lockTimeoutMs: number;
|
|
185
|
+
migrate: boolean;
|
|
186
|
+
};
|
|
187
|
+
printConfig: boolean;
|
|
188
|
+
ignored: {
|
|
189
|
+
field: string;
|
|
190
|
+
source: ConfigurationSource;
|
|
191
|
+
}[];
|
|
192
|
+
provenance: {
|
|
193
|
+
[k: string]: {
|
|
194
|
+
source: ConfigurationSource;
|
|
195
|
+
configPath?: string;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Describe database-only settings and their sources without opening resources.
|
|
201
|
+
* @returns Redacted settings and ignored configuration areas for diagnostics.
|
|
202
|
+
*/
|
|
203
|
+
declare function describeAccountConfiguration(options: ReturnType<typeof resolveAccountOptions>): {
|
|
204
|
+
command: "account";
|
|
205
|
+
action: string;
|
|
206
|
+
settings: {
|
|
207
|
+
[k: string]: {
|
|
208
|
+
source: ConfigurationSource;
|
|
209
|
+
configPath?: string;
|
|
210
|
+
value: string | number | boolean | undefined;
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
ignored: ({
|
|
214
|
+
field: string;
|
|
215
|
+
source: ConfigurationSource;
|
|
216
|
+
} | {
|
|
217
|
+
area: "database" | "mail" | "server" | "telemetry" | "web";
|
|
218
|
+
reason: string;
|
|
219
|
+
})[];
|
|
220
|
+
};
|
|
221
|
+
//#endregion
|
|
222
|
+
export { createAccountProgram, describeAccountConfiguration, resolveAccountOptions };
|
|
223
|
+
//# sourceMappingURL=account-program.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-program.d.mts","names":[],"sources":["../../src/commands/account-program.ts"],"mappings":";;;;;;;iBAuCgB,qBACd,UAAS,kBAAkB;;;MAyFrB;MACA,6CAAW;;;2BA1FR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmGN,oBAAoB,WACvB,kBAAkB;;;;;iBAOJ,sBACd,KAAK,mBACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoCc,6BACd,SAAS,kBAAkB;EAmBzB;EACA;EACA;;cArBO;;;;;EAoCP"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { configurationBoolean, configurationProjection, configurationProvenance, configurationSettings, createConfigurationBindings } from "../configuration.mjs";
|
|
2
|
+
import { resolveDatabaseSettings } from "../database-settings.mjs";
|
|
3
|
+
import { r as valueOptionNames } from "../parser-DGIQTgS7.mjs";
|
|
4
|
+
import { accountEmail, resolveAccountInput } from "./account-create.mjs";
|
|
5
|
+
import { message } from "@optique/core/message";
|
|
6
|
+
import { map, optional, withDefault } from "@optique/core/modifiers";
|
|
7
|
+
import { integer, string, url } from "@optique/core/valueparser";
|
|
8
|
+
import { object, or } from "@optique/core/constructs";
|
|
9
|
+
import { command, flag, option } from "@optique/core/primitives";
|
|
10
|
+
import { path } from "@optique/run/valueparser";
|
|
11
|
+
//#region src/commands/account-program.ts
|
|
12
|
+
/**
|
|
13
|
+
* Construct an independent database-only command using shared source bindings.
|
|
14
|
+
* @returns Pure program metadata, contexts and the explicit TOML loader.
|
|
15
|
+
*/
|
|
16
|
+
function createAccountProgram(options = {}) {
|
|
17
|
+
const bindings = createConfigurationBindings(options);
|
|
18
|
+
const { bind } = bindings;
|
|
19
|
+
const lockTimeout = integer({
|
|
20
|
+
min: 1,
|
|
21
|
+
max: 2147483647,
|
|
22
|
+
metavar: "MILLISECONDS"
|
|
23
|
+
});
|
|
24
|
+
const parser = command("create", object({
|
|
25
|
+
configPath: optional(bindings.bindConfigPath(option("--config", path({
|
|
26
|
+
metavar: "FILE",
|
|
27
|
+
type: "file"
|
|
28
|
+
}), { description: message`Read the shared DrFed TOML configuration file.` }))),
|
|
29
|
+
dataPath: bind(option(...valueOptionNames.dataPath, path({
|
|
30
|
+
metavar: "DIRECTORY",
|
|
31
|
+
type: "directory"
|
|
32
|
+
}), { description: message`Persistent PGlite directory; defaults to the OS data location.` }), configurationSettings.dataPath, string(), String),
|
|
33
|
+
postgresUrl: bind(map(option(...valueOptionNames.postgresUrl, url({ allowedProtocols: ["postgres:", "postgresql:"] }), { description: message`PostgreSQL connection URL.` }), (value) => value.href), configurationSettings.postgresUrl, string(), String),
|
|
34
|
+
migrationLockTimeout: bind(option(...valueOptionNames.migrationLockTimeout, lockTimeout, { description: message`Maximum connection and migration lock wait in milliseconds.` }), configurationSettings.migrationLockTimeout, lockTimeout, String, 3e4),
|
|
35
|
+
email: option("--email", accountEmail, { description: message`Login email for the new account.` }),
|
|
36
|
+
name: option("--name", string({ metavar: "NAME" }), { description: message`Display name, between 1 and 100 characters after trimming.` }),
|
|
37
|
+
migrate: bind(or(flag("--migrate", { description: message`Prepare the database before creating an account.` }), map(flag("--no-migrate", "-M", { description: message`Require ready history without applying migrations.` }), () => false)), configurationSettings.migrate, configurationBoolean(), String, true),
|
|
38
|
+
printConfig: withDefault(flag("--print-config", { description: message`Print effective settings and provenance with credentials redacted, then exit without opening runtime resources.` }), false)
|
|
39
|
+
}));
|
|
40
|
+
return {
|
|
41
|
+
program: {
|
|
42
|
+
metadata: {
|
|
43
|
+
name: "drfed-account",
|
|
44
|
+
description: message`Manage local DrFed accounts.`
|
|
45
|
+
},
|
|
46
|
+
parser
|
|
47
|
+
},
|
|
48
|
+
contexts: bindings.contexts,
|
|
49
|
+
load: bindings.load
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Select the winning database and retain source-only diagnostic metadata.
|
|
54
|
+
* @returns Validated command settings without acquiring runtime resources.
|
|
55
|
+
*/
|
|
56
|
+
function resolveAccountOptions(raw, cwd = process.cwd()) {
|
|
57
|
+
const selected = resolveDatabaseSettings({
|
|
58
|
+
dataPath: raw.dataPath,
|
|
59
|
+
postgresUrl: raw.postgresUrl
|
|
60
|
+
}, cwd);
|
|
61
|
+
const lockTimeoutMs = raw.migrationLockTimeout?.value;
|
|
62
|
+
if (lockTimeoutMs === void 0) throw new Error("Missing migration lock timeout.");
|
|
63
|
+
const input = resolveAccountInput(raw.email, raw.name);
|
|
64
|
+
return {
|
|
65
|
+
database: {
|
|
66
|
+
...selected.database,
|
|
67
|
+
lockTimeoutMs,
|
|
68
|
+
migrate: raw.migrate?.value ?? true
|
|
69
|
+
},
|
|
70
|
+
...input,
|
|
71
|
+
printConfig: raw.printConfig,
|
|
72
|
+
ignored: selected.ignored,
|
|
73
|
+
provenance: configurationProvenance({
|
|
74
|
+
dataPath: raw.dataPath,
|
|
75
|
+
postgresUrl: raw.postgresUrl,
|
|
76
|
+
migrate: raw.migrate,
|
|
77
|
+
migrationLockTimeout: raw.migrationLockTimeout
|
|
78
|
+
})
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Describe database-only settings and their sources without opening resources.
|
|
83
|
+
* @returns Redacted settings and ignored configuration areas for diagnostics.
|
|
84
|
+
*/
|
|
85
|
+
function describeAccountConfiguration(options) {
|
|
86
|
+
const values = {
|
|
87
|
+
databaseDriver: options.database.driver,
|
|
88
|
+
dataPath: options.database.driver === "pglite" ? options.database.dataPath : void 0,
|
|
89
|
+
postgresUrl: options.database.driver === "postgres" ? "<redacted>" : void 0,
|
|
90
|
+
migrationLockTimeout: options.database.lockTimeoutMs,
|
|
91
|
+
migrate: options.database.migrate
|
|
92
|
+
};
|
|
93
|
+
const rank = {
|
|
94
|
+
default: 0,
|
|
95
|
+
config: 1,
|
|
96
|
+
env: 2,
|
|
97
|
+
cli: 3
|
|
98
|
+
};
|
|
99
|
+
const selected = ["dataPath", "postgresUrl"].map((key) => options.provenance[key]).filter((value) => value !== void 0).sort((left, right) => rank[right.source] - rank[left.source])[0];
|
|
100
|
+
return {
|
|
101
|
+
command: "account",
|
|
102
|
+
action: "create",
|
|
103
|
+
settings: Object.fromEntries(Object.entries(values).filter(([, value]) => value !== void 0).map(([key, value]) => [key === "databaseDriver" ? "database.driver" : configurationSettings[key].toml, {
|
|
104
|
+
value,
|
|
105
|
+
...(key === "databaseDriver" ? selected : options.provenance[key]) ?? { source: "default" }
|
|
106
|
+
}])),
|
|
107
|
+
ignored: [...options.ignored, ...configurationProjection("account").unusedAreas.map((area) => ({
|
|
108
|
+
area,
|
|
109
|
+
reason: "unused by this command"
|
|
110
|
+
}))]
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
export { createAccountProgram, describeAccountConfiguration, resolveAccountOptions };
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=account-program.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-program.mjs","names":["settings"],"sources":["../../src/commands/account-program.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport { object, or } from \"@optique/core/constructs\";\nimport { message } from \"@optique/core/message\";\nimport { map, optional, withDefault } from \"@optique/core/modifiers\";\nimport type { InferValue } from \"@optique/core/parser\";\nimport { command, flag, option } from \"@optique/core/primitives\";\nimport { integer, string, url } from \"@optique/core/valueparser\";\nimport { path } from \"@optique/run/valueparser\";\n\nimport {\n configurationBoolean,\n configurationProjection,\n configurationProvenance,\n createConfigurationBindings,\n configurationSettings as settings,\n} from \"../configuration.ts\";\nimport { resolveDatabaseSettings } from \"../database-settings.ts\";\nimport { valueOptionNames } from \"../parser.ts\";\nimport { accountEmail, resolveAccountInput } from \"./account-create.ts\";\n\n/**\n * Construct an independent database-only command using shared source bindings.\n * @returns Pure program metadata, contexts and the explicit TOML loader.\n */\nexport function createAccountProgram(\n options: Parameters<typeof createConfigurationBindings>[0] = {},\n) {\n const bindings = createConfigurationBindings(options);\n const { bind } = bindings;\n const lockTimeout = integer({\n min: 1,\n max: 2_147_483_647,\n metavar: \"MILLISECONDS\",\n });\n const parser = command(\n \"create\",\n object({\n configPath: optional(\n bindings.bindConfigPath(\n option(\"--config\", path({ metavar: \"FILE\", type: \"file\" }), {\n description: message`Read the shared DrFed TOML configuration file.`,\n }),\n ),\n ),\n dataPath: bind(\n option(\n ...valueOptionNames.dataPath,\n path({ metavar: \"DIRECTORY\", type: \"directory\" }),\n {\n description: message`Persistent PGlite directory; defaults to the OS data location.`,\n },\n ),\n settings.dataPath,\n string(),\n String,\n ),\n postgresUrl: bind(\n map(\n option(\n ...valueOptionNames.postgresUrl,\n url({ allowedProtocols: [\"postgres:\", \"postgresql:\"] }),\n {\n description: message`PostgreSQL connection URL.`,\n },\n ),\n (value) => value.href,\n ),\n settings.postgresUrl,\n string(),\n String,\n ),\n migrationLockTimeout: bind(\n option(...valueOptionNames.migrationLockTimeout, lockTimeout, {\n description: message`Maximum connection and migration lock wait in milliseconds.`,\n }),\n settings.migrationLockTimeout,\n lockTimeout,\n String,\n 30_000,\n ),\n email: option(\"--email\", accountEmail, {\n description: message`Login email for the new account.`,\n }),\n name: option(\"--name\", string({ metavar: \"NAME\" }), {\n description: message`Display name, between 1 and 100 characters after trimming.`,\n }),\n migrate: bind(\n or(\n flag(\"--migrate\", {\n description: message`Prepare the database before creating an account.`,\n }),\n map(\n flag(\"--no-migrate\", \"-M\", {\n description: message`Require ready history without applying migrations.`,\n }),\n () => false,\n ),\n ),\n settings.migrate,\n configurationBoolean(),\n String,\n true,\n ),\n printConfig: withDefault(\n flag(\"--print-config\", {\n description: message`Print effective settings and provenance with credentials redacted, then exit without opening runtime resources.`,\n }),\n false,\n ),\n }),\n );\n return {\n program: {\n metadata: {\n name: \"drfed-account\",\n description: message`Manage local DrFed accounts.`,\n },\n parser,\n },\n contexts: bindings.contexts,\n load: bindings.load,\n };\n}\n\ntype RawAccountOptions = InferValue<\n ReturnType<typeof createAccountProgram>[\"program\"][\"parser\"]\n>;\n\n/**\n * Select the winning database and retain source-only diagnostic metadata.\n * @returns Validated command settings without acquiring runtime resources.\n */\nexport function resolveAccountOptions(\n raw: RawAccountOptions,\n cwd = process.cwd(),\n) {\n const selected = resolveDatabaseSettings(\n {\n dataPath: raw.dataPath,\n postgresUrl: raw.postgresUrl,\n },\n cwd,\n );\n const lockTimeoutMs = raw.migrationLockTimeout?.value;\n if (lockTimeoutMs === undefined) {\n throw new Error(\"Missing migration lock timeout.\");\n }\n const input = resolveAccountInput(raw.email, raw.name);\n return {\n database: {\n ...selected.database,\n lockTimeoutMs,\n migrate: raw.migrate?.value ?? true,\n },\n ...input,\n printConfig: raw.printConfig,\n ignored: selected.ignored,\n provenance: configurationProvenance({\n dataPath: raw.dataPath,\n postgresUrl: raw.postgresUrl,\n migrate: raw.migrate,\n migrationLockTimeout: raw.migrationLockTimeout,\n }),\n };\n}\n\n/**\n * Describe database-only settings and their sources without opening resources.\n * @returns Redacted settings and ignored configuration areas for diagnostics.\n */\nexport function describeAccountConfiguration(\n options: ReturnType<typeof resolveAccountOptions>,\n) {\n const values = {\n databaseDriver: options.database.driver,\n dataPath:\n options.database.driver === \"pglite\"\n ? options.database.dataPath\n : undefined,\n postgresUrl:\n options.database.driver === \"postgres\" ? \"<redacted>\" : undefined,\n migrationLockTimeout: options.database.lockTimeoutMs,\n migrate: options.database.migrate,\n };\n const rank = { default: 0, config: 1, env: 2, cli: 3 };\n const selected = [\"dataPath\", \"postgresUrl\"]\n .map((key) => options.provenance[key])\n .filter((value) => value !== undefined)\n .sort((left, right) => rank[right.source] - rank[left.source])[0];\n return {\n command: \"account\" as const,\n action: \"create\",\n settings: Object.fromEntries(\n Object.entries(values)\n .filter(([, value]) => value !== undefined)\n .map(([key, value]) => [\n key === \"databaseDriver\"\n ? \"database.driver\"\n : settings[key as keyof typeof settings].toml,\n {\n value,\n ...((key === \"databaseDriver\"\n ? selected\n : options.provenance[key]) ?? { source: \"default\" as const }),\n },\n ]),\n ),\n ignored: [\n ...options.ignored,\n ...configurationProjection(\"account\").unusedAreas.map((area) => ({\n area,\n reason: \"unused by this command\",\n })),\n ],\n };\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.d.mts","names":[],"sources":["../../src/commands/account.ts"],"mappings":";;iBAkCsB,QAAQ"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { t as version } from "../package-7FOUqcPO.mjs";
|
|
2
|
+
import { OperationRegistry } from "../operations.mjs";
|
|
3
|
+
import { ResourceOwner } from "../resources.mjs";
|
|
4
|
+
import { openDatabaseRuntime } from "../database-runtime.mjs";
|
|
5
|
+
import { createAccount } from "./account-create.mjs";
|
|
6
|
+
import { createAccountProgram, describeAccountConfiguration, resolveAccountOptions } from "./account-program.mjs";
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
import { text } from "@optique/core/message";
|
|
9
|
+
import { printError, run } from "@optique/run";
|
|
10
|
+
import { MigrationPreparationError, PgliteStoreError } from "@drfed/models";
|
|
11
|
+
//#region src/commands/account.ts
|
|
12
|
+
/** Run the installed account creation command without server resources. */
|
|
13
|
+
async function main() {
|
|
14
|
+
const invocation = createAccountProgram();
|
|
15
|
+
let options;
|
|
16
|
+
try {
|
|
17
|
+
options = resolveAccountOptions(await run(invocation.program, {
|
|
18
|
+
contexts: invocation.contexts,
|
|
19
|
+
contextOptions: { load: (parsed) => invocation.load(parsed) },
|
|
20
|
+
help: "option",
|
|
21
|
+
completion: "both",
|
|
22
|
+
showChoices: true,
|
|
23
|
+
showDefault: true,
|
|
24
|
+
version: {
|
|
25
|
+
option: true,
|
|
26
|
+
value: version
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
} catch (error) {
|
|
30
|
+
printError([text(error instanceof Error ? error.message : "Could not resolve configuration.")]);
|
|
31
|
+
process.exitCode = 1;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (options.printConfig) {
|
|
35
|
+
console.log(JSON.stringify(describeAccountConfiguration(options), null, 2));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const owner = new ResourceOwner();
|
|
39
|
+
const operations = new OperationRegistry();
|
|
40
|
+
let interrupted = false;
|
|
41
|
+
let failed = false;
|
|
42
|
+
let deadline;
|
|
43
|
+
const abort = () => {
|
|
44
|
+
if (interrupted) process.exit(1);
|
|
45
|
+
interrupted = true;
|
|
46
|
+
failed = true;
|
|
47
|
+
operations.abort();
|
|
48
|
+
deadline = setTimeout(() => process.exit(1), 1e4);
|
|
49
|
+
deadline.unref();
|
|
50
|
+
};
|
|
51
|
+
process.on("SIGINT", abort);
|
|
52
|
+
process.on("SIGTERM", abort);
|
|
53
|
+
try {
|
|
54
|
+
const result = await operations.run(async (signal) => {
|
|
55
|
+
const database = await openDatabaseRuntime(options.database, owner, options.database.migrate ? "apply" : "inspect", signal);
|
|
56
|
+
if (database.state.status !== "ready") throw new MigrationPreparationError("incompatible-history", database.state);
|
|
57
|
+
signal.throwIfAborted();
|
|
58
|
+
return await createAccount(database.db, {
|
|
59
|
+
email: options.email,
|
|
60
|
+
name: options.name
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
console.log(JSON.stringify({
|
|
64
|
+
command: "account",
|
|
65
|
+
action: "create",
|
|
66
|
+
...result
|
|
67
|
+
}, null, 2));
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (!(interrupted && (error === operations.signal.reason || error instanceof MigrationPreparationError && error.code === "aborted" && !error.cleanupFailed))) {
|
|
70
|
+
printError([text(error instanceof MigrationPreparationError || error instanceof PgliteStoreError ? `${error.code}: ${error.message}` : "Could not create the account.")]);
|
|
71
|
+
failed = true;
|
|
72
|
+
}
|
|
73
|
+
} finally {
|
|
74
|
+
operations.abort();
|
|
75
|
+
await operations.drain();
|
|
76
|
+
try {
|
|
77
|
+
await owner.close();
|
|
78
|
+
} catch {
|
|
79
|
+
printError([text("Could not cleanly close the database.")]);
|
|
80
|
+
failed = true;
|
|
81
|
+
}
|
|
82
|
+
if (deadline !== void 0) clearTimeout(deadline);
|
|
83
|
+
process.off("SIGINT", abort);
|
|
84
|
+
process.off("SIGTERM", abort);
|
|
85
|
+
}
|
|
86
|
+
process.exitCode = failed ? 1 : 0;
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
export { main };
|
|
90
|
+
|
|
91
|
+
//# sourceMappingURL=account.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.mjs","names":["metadata.version"],"sources":["../../src/commands/account.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport process from \"node:process\";\n\nimport { MigrationPreparationError, PgliteStoreError } from \"@drfed/models\";\nimport { text } from \"@optique/core/message\";\nimport { printError, run } from \"@optique/run\";\n\nimport metadata from \"../../package.json\" with { type: \"json\" };\nimport { openDatabaseRuntime } from \"../database-runtime.ts\";\nimport { OperationRegistry } from \"../operations.ts\";\nimport { ResourceOwner } from \"../resources.ts\";\nimport { createAccount } from \"./account-create.ts\";\nimport {\n createAccountProgram,\n describeAccountConfiguration,\n resolveAccountOptions,\n} from \"./account-program.ts\";\n\n/** Run the installed account creation command without server resources. */\nexport async function main(): Promise<void> {\n const invocation = createAccountProgram();\n let options: ReturnType<typeof resolveAccountOptions>;\n try {\n const raw = await run(invocation.program, {\n contexts: invocation.contexts,\n contextOptions: { load: (parsed) => invocation.load(parsed) },\n help: \"option\",\n completion: \"both\",\n showChoices: true,\n showDefault: true,\n version: { option: true, value: metadata.version },\n });\n options = resolveAccountOptions(raw);\n } catch (error) {\n printError([\n text(\n error instanceof Error\n ? error.message\n : \"Could not resolve configuration.\",\n ),\n ]);\n process.exitCode = 1;\n return;\n }\n if (options.printConfig) {\n console.log(JSON.stringify(describeAccountConfiguration(options), null, 2));\n return;\n }\n const owner = new ResourceOwner();\n const operations = new OperationRegistry();\n let interrupted = false;\n let failed = false;\n let deadline: ReturnType<typeof setTimeout> | undefined;\n const abort = () => {\n if (interrupted) process.exit(1);\n interrupted = true;\n failed = true;\n operations.abort();\n deadline = setTimeout(() => process.exit(1), 10_000);\n deadline.unref();\n };\n process.on(\"SIGINT\", abort);\n process.on(\"SIGTERM\", abort);\n try {\n const result = await operations.run(async (signal) => {\n const database = await openDatabaseRuntime(\n options.database,\n owner,\n options.database.migrate ? \"apply\" : \"inspect\",\n signal,\n );\n if (database.state.status !== \"ready\") {\n throw new MigrationPreparationError(\n \"incompatible-history\",\n database.state,\n );\n }\n signal.throwIfAborted();\n return await createAccount(database.db, {\n email: options.email,\n name: options.name,\n });\n });\n console.log(\n JSON.stringify(\n { command: \"account\", action: \"create\", ...result },\n null,\n 2,\n ),\n );\n } catch (error) {\n const cleanAbort =\n interrupted &&\n (error === operations.signal.reason ||\n (error instanceof MigrationPreparationError &&\n error.code === \"aborted\" &&\n !error.cleanupFailed));\n if (!cleanAbort) {\n const message =\n error instanceof MigrationPreparationError ||\n error instanceof PgliteStoreError\n ? `${error.code}: ${error.message}`\n : \"Could not create the account.\";\n printError([text(message)]);\n failed = true;\n }\n } finally {\n operations.abort();\n await operations.drain();\n try {\n await owner.close();\n } catch {\n printError([text(\"Could not cleanly close the database.\")]);\n failed = true;\n }\n if (deadline !== undefined) clearTimeout(deadline);\n process.off(\"SIGINT\", abort);\n process.off(\"SIGTERM\", abort);\n }\n process.exitCode = failed ? 1 : 0;\n}\n"],"mappings":";;;;;;;;;;;;AAkCA,eAAsB,OAAsB;CAC1C,MAAM,aAAa,qBAAqB;CACxC,IAAI;CACJ,IAAI;EAUF,UAAU,sBAAsB,MATd,IAAI,WAAW,SAAS;GACxC,UAAU,WAAW;GACrB,gBAAgB,EAAE,OAAO,WAAW,WAAW,KAAK,MAAM,EAAE;GAC5D,MAAM;GACN,YAAY;GACZ,aAAa;GACb,aAAa;GACb,SAAS;IAAE,QAAQ;IAAM,OAAOA;GAAiB;EACnD,CAAC,CACkC;CACrC,SAAS,OAAO;EACd,WAAW,CACT,KACE,iBAAiB,QACb,MAAM,UACN,kCACN,CACF,CAAC;EACD,QAAQ,WAAW;EACnB;CACF;CACA,IAAI,QAAQ,aAAa;EACvB,QAAQ,IAAI,KAAK,UAAU,6BAA6B,OAAO,GAAG,MAAM,CAAC,CAAC;EAC1E;CACF;CACA,MAAM,QAAQ,IAAI,cAAc;CAChC,MAAM,aAAa,IAAI,kBAAkB;CACzC,IAAI,cAAc;CAClB,IAAI,SAAS;CACb,IAAI;CACJ,MAAM,cAAc;EAClB,IAAI,aAAa,QAAQ,KAAK,CAAC;EAC/B,cAAc;EACd,SAAS;EACT,WAAW,MAAM;EACjB,WAAW,iBAAiB,QAAQ,KAAK,CAAC,GAAG,GAAM;EACnD,SAAS,MAAM;CACjB;CACA,QAAQ,GAAG,UAAU,KAAK;CAC1B,QAAQ,GAAG,WAAW,KAAK;CAC3B,IAAI;EACF,MAAM,SAAS,MAAM,WAAW,IAAI,OAAO,WAAW;GACpD,MAAM,WAAW,MAAM,oBACrB,QAAQ,UACR,OACA,QAAQ,SAAS,UAAU,UAAU,WACrC,MACF;GACA,IAAI,SAAS,MAAM,WAAW,SAC5B,MAAM,IAAI,0BACR,wBACA,SAAS,KACX;GAEF,OAAO,eAAe;GACtB,OAAO,MAAM,cAAc,SAAS,IAAI;IACtC,OAAO,QAAQ;IACf,MAAM,QAAQ;GAChB,CAAC;EACH,CAAC;EACD,QAAQ,IACN,KAAK,UACH;GAAE,SAAS;GAAW,QAAQ;GAAU,GAAG;EAAO,GAClD,MACA,CACF,CACF;CACF,SAAS,OAAO;EAOd,IAAI,EALF,gBACC,UAAU,WAAW,OAAO,UAC1B,iBAAiB,6BAChB,MAAM,SAAS,aACf,CAAC,MAAM,iBACI;GAMf,WAAW,CAAC,KAJV,iBAAiB,6BACjB,iBAAiB,mBACb,GAAG,MAAM,KAAK,IAAI,MAAM,YACxB,+BACkB,CAAC,CAAC;GAC1B,SAAS;EACX;CACF,UAAU;EACR,WAAW,MAAM;EACjB,MAAM,WAAW,MAAM;EACvB,IAAI;GACF,MAAM,MAAM,MAAM;EACpB,QAAQ;GACN,WAAW,CAAC,KAAK,uCAAuC,CAAC,CAAC;GAC1D,SAAS;EACX;EACA,IAAI,aAAa,KAAA,GAAW,aAAa,QAAQ;EACjD,QAAQ,IAAI,UAAU,KAAK;EAC3B,QAAQ,IAAI,WAAW,KAAK;CAC9B;CACA,QAAQ,WAAW,SAAS,IAAI;AAClC"}
|