@dyrected/cli 2.3.4 → 2.3.5

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.
@@ -0,0 +1,3 @@
1
+ import type { Command } from "commander";
2
+ export declare function registerGenerateTypes(program: Command): void;
3
+ //# sourceMappingURL=generate-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-types.d.ts","sourceRoot":"","sources":["../../src/commands/generate-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIzC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,QAgCrD"}
@@ -0,0 +1,34 @@
1
+ import chalk from "chalk";
2
+ import { runGenerateTypes } from "../utils/type-generator.js";
3
+ export function registerGenerateTypes(program) {
4
+ program
5
+ .command("generate:types")
6
+ .description("Generate TypeScript interfaces from your Dyrected schema")
7
+ .option("-u, --url <url>", "Base URL of your Dyrected API (Cloud or self-hosted)")
8
+ .option("-c, --config <path>", "Path to your dyrected.config.ts (Self-hosted)", "./dyrected.config.ts")
9
+ .option("-o, --output <path>", "Output file path", "./dyrected-types.ts")
10
+ .addHelpText("after", `
11
+ Examples:
12
+ # Generate from local config (default)
13
+ $ npx @dyrected/cli generate:types
14
+
15
+ # Generate from a self-hosted instance
16
+ $ npx @dyrected/cli generate:types --url http://localhost:3000
17
+
18
+ # Generate from Dyrected Cloud
19
+ $ npx @dyrected/cli generate:types --url https://your-site.dyrected.com
20
+
21
+ # Custom config and output paths
22
+ $ npx @dyrected/cli generate:types --config ./cms/dyrected.config.ts --output ./types/cms.ts
23
+ `)
24
+ .action(async (options) => {
25
+ try {
26
+ await runGenerateTypes({ url: options.url, config: options.config, output: options.output });
27
+ }
28
+ catch (error) {
29
+ console.error(chalk.red(`\nError: ${error.message}`));
30
+ process.exit(1);
31
+ }
32
+ });
33
+ }
34
+ //# sourceMappingURL=generate-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-types.js","sourceRoot":"","sources":["../../src/commands/generate-types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACpD,OAAO;SACJ,OAAO,CAAC,gBAAgB,CAAC;SACzB,WAAW,CAAC,0DAA0D,CAAC;SACvE,MAAM,CAAC,iBAAiB,EAAE,sDAAsD,CAAC;SACjF,MAAM,CAAC,qBAAqB,EAAE,+CAA+C,EAAE,sBAAsB,CAAC;SACtG,MAAM,CAAC,qBAAqB,EAAE,kBAAkB,EAAE,qBAAqB,CAAC;SACxE,WAAW,CACV,OAAO,EACP;;;;;;;;;;;;;CAaL,CACI;SACA,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACxB,IAAI,CAAC;YACH,MAAM,gBAAgB,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAC/F,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;YACtD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Command } from "commander";
2
+ export declare function registerInit(program: Command): void;
3
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWzC,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,QA0M5C"}
@@ -0,0 +1,280 @@
1
+ import chalk from "chalk";
2
+ import fs from "fs-extra";
3
+ import path from "path";
4
+ import prompts from "prompts";
5
+ import { execSync } from "child_process";
6
+ import { generateAIPrompt } from "@dyrected/sdk";
7
+ import { detectFramework, detectPackageManager } from "../utils/detect.js";
8
+ import { buildDbConfig, buildStorageConfig, buildEnvTemplate } from "../utils/config-templates.js";
9
+ import { writeNextFiles, writeNuxtFiles } from "../utils/writers.js";
10
+ export function registerInit(program) {
11
+ program
12
+ .command("init")
13
+ .description("Bootstrap a new Dyrected CMS project")
14
+ .addHelpText("after", `
15
+ Examples:
16
+ # Interactive setup (detects your framework automatically)
17
+ $ npx @dyrected/cli init
18
+
19
+ After running init:
20
+ 1. Fill in the values in .env
21
+ 2. Start your dev server
22
+ 3. Open the admin path you chose (default: /cms)
23
+ `)
24
+ .action(async () => {
25
+ console.log(chalk.bold("\nšŸš€ Welcome to Dyrected CMS\n"));
26
+ const cwd = process.cwd();
27
+ const detectedFramework = await detectFramework(cwd);
28
+ if (detectedFramework) {
29
+ console.log(chalk.dim(` Detected framework: ${detectedFramework === "next" ? "Next.js" : "Nuxt 3"}\n`));
30
+ }
31
+ const { framework } = await prompts({
32
+ type: "select",
33
+ name: "framework",
34
+ message: "Which framework are you using?",
35
+ choices: [
36
+ { title: "Next.js", value: "next" },
37
+ { title: "Nuxt 3", value: "nuxt" },
38
+ ],
39
+ initial: detectedFramework === "nuxt" ? 1 : 0,
40
+ });
41
+ if (!framework) {
42
+ console.log(chalk.yellow("\nAborted."));
43
+ process.exit(0);
44
+ }
45
+ const { quickSetup } = await prompts({
46
+ type: "confirm",
47
+ name: "quickSetup",
48
+ message: "Use Quick Setup (SQLite + Local Storage)?",
49
+ initial: true,
50
+ });
51
+ const { adminPath } = await prompts({
52
+ type: "text",
53
+ name: "adminPath",
54
+ message: "What path should the admin dashboard use?",
55
+ initial: "cms",
56
+ format: (val) => val.replace(/^\//, "").replace(/\/$/, ""),
57
+ });
58
+ let db = "sqlite";
59
+ let storage = "local";
60
+ if (!quickSetup) {
61
+ const dbResponse = await prompts({
62
+ type: "select",
63
+ name: "value",
64
+ message: "Which database adapter?",
65
+ choices: [
66
+ { title: "PostgreSQL (recommended)", value: "postgres" },
67
+ { title: "MySQL", value: "mysql" },
68
+ { title: "SQLite (local dev)", value: "sqlite" },
69
+ { title: "MongoDB", value: "mongodb" },
70
+ ],
71
+ });
72
+ db = dbResponse.value;
73
+ const storageResponse = await prompts({
74
+ type: "select",
75
+ name: "value",
76
+ message: "Which storage adapter?",
77
+ choices: [
78
+ { title: "Local filesystem", value: "local" },
79
+ { title: "AWS S3", value: "s3" },
80
+ { title: "Backblaze B2", value: "b2" },
81
+ { title: "Cloudinary", value: "cloudinary" },
82
+ ],
83
+ });
84
+ storage = storageResponse.value;
85
+ }
86
+ const packageManager = detectPackageManager(cwd);
87
+ // ── 1. Install dependencies ────────────────────────────────────────────
88
+ const frameworkPkg = framework === "next" ? "@dyrected/next" : "@dyrected/nuxt";
89
+ const dbPkg = `@dyrected/db-${db}`;
90
+ const storagePkg = `@dyrected/storage-${storage}`;
91
+ const deps = [frameworkPkg, dbPkg, storagePkg].join(" ");
92
+ console.log(chalk.blue(`\nInstalling ${deps}...`));
93
+ try {
94
+ execSync(`${packageManager} add ${deps}`, { cwd, stdio: "inherit" });
95
+ }
96
+ catch {
97
+ console.log(chalk.yellow("\nCould not auto-install. Run the following manually:"));
98
+ console.log(chalk.cyan(` ${packageManager} add ${deps}\n`));
99
+ }
100
+ // ── 2. Write dyrected.config.ts ────────────────────────────────────────
101
+ const dbImport = `import { ${db}Adapter } from '${dbPkg}'`;
102
+ const storageImport = `import { ${storage}Adapter } from '${storagePkg}'`;
103
+ const configContent = buildDyrectedConfig(dbImport, storageImport, buildDbConfig(db), buildStorageConfig(storage));
104
+ const configPath = path.join(cwd, "dyrected.config.ts");
105
+ if (await fs.pathExists(configPath)) {
106
+ const { overwrite } = await prompts({
107
+ type: "confirm",
108
+ name: "overwrite",
109
+ message: "dyrected.config.ts already exists. Overwrite?",
110
+ initial: false,
111
+ });
112
+ if (!overwrite) {
113
+ console.log(chalk.yellow("Skipping config file."));
114
+ }
115
+ else {
116
+ await fs.outputFile(configPath, configContent);
117
+ console.log(chalk.green("āœ” dyrected.config.ts written"));
118
+ }
119
+ }
120
+ else {
121
+ await fs.outputFile(configPath, configContent);
122
+ console.log(chalk.green("āœ” dyrected.config.ts written"));
123
+ }
124
+ // ── 3. Framework-specific files ────────────────────────────────────────
125
+ if (framework === "next") {
126
+ await writeNextFiles(cwd, adminPath);
127
+ }
128
+ else {
129
+ await writeNuxtFiles(cwd, adminPath);
130
+ }
131
+ // ── 4. .env setup ──────────────────────────────────────────────────────
132
+ const envContent = buildEnvTemplate(db, storage, framework);
133
+ const envExamplePath = path.join(cwd, ".env.example");
134
+ await fs.outputFile(envExamplePath, envContent);
135
+ console.log(chalk.green("āœ” .env.example written"));
136
+ const envPath = path.join(cwd, ".env");
137
+ if (await fs.pathExists(envPath)) {
138
+ const existingEnv = await fs.readFile(envPath, "utf-8");
139
+ const missingVars = envContent
140
+ .split("\n")
141
+ .filter((line) => {
142
+ if (!line || line.startsWith("#"))
143
+ return false;
144
+ const key = line.split("=")[0];
145
+ return !existingEnv.includes(`${key}=`);
146
+ })
147
+ .join("\n");
148
+ if (missingVars) {
149
+ const { appendEnv } = await prompts({
150
+ type: "confirm",
151
+ name: "appendEnv",
152
+ message: ".env already exists. Append missing Dyrected variables?",
153
+ initial: true,
154
+ });
155
+ if (appendEnv) {
156
+ await fs.appendFile(envPath, `\n# ── Dyrected CMS ──────────────────────────────────────────────────\n${missingVars}`);
157
+ console.log(chalk.green("āœ” .env file updated with missing variables"));
158
+ }
159
+ }
160
+ else {
161
+ console.log(chalk.dim("ℹ .env already contains all required variables."));
162
+ }
163
+ }
164
+ else {
165
+ const { createEnv } = await prompts({
166
+ type: "confirm",
167
+ name: "createEnv",
168
+ message: ".env file is missing. Create it now?",
169
+ initial: true,
170
+ });
171
+ if (createEnv) {
172
+ await fs.outputFile(envPath, envContent);
173
+ console.log(chalk.green("āœ” .env file created"));
174
+ }
175
+ }
176
+ // ── Done ───────────────────────────────────────────────────────────────
177
+ console.log(chalk.bold.green("\nāœ… Dyrected is ready!\n"));
178
+ console.log(chalk.cyan(` 1. Configure your environment variables in .env`));
179
+ console.log(chalk.cyan(` 2. Open http://localhost:3000/${adminPath} to start managing content.`));
180
+ console.log(chalk.cyan(" 3. Run: npx @dyrected/cli generate:types\n"));
181
+ const promptText = generateAIPrompt(framework, {
182
+ baseUrl: "http://localhost:3000",
183
+ isSelfHosted: true,
184
+ });
185
+ const promptPath = path.join(cwd, "dyrected-ai-prompt.md");
186
+ await fs.outputFile(promptPath, promptText);
187
+ console.log(chalk.bold.magenta("šŸ¤– AI INTEGRATION PROMPT"));
188
+ console.log(chalk.cyan(` Prompt saved to: ${chalk.bold("dyrected-ai-prompt.md")}`));
189
+ console.log(chalk.dim(" Copy the contents of this file to your AI (Claude, GPT, etc.) to scaffold your CMS logic.\n"));
190
+ });
191
+ }
192
+ function buildDyrectedConfig(dbImport, storageImport, dbConfig, storageConfig) {
193
+ return `import { defineCollection, defineGlobal, defineConfig } from '@dyrected/core'
194
+ ${dbImport}
195
+ ${storageImport}
196
+
197
+ // ── Admin Auth ────────────────────────────────────────────────────────────
198
+ // Reserved collection — sole login gateway for the Dyrected dashboard.
199
+ // Email + password are auto-managed; declare only extra fields here.
200
+
201
+ const admins = defineCollection({
202
+ slug: '__admins',
203
+ labels: { singular: 'Admin', plural: 'Admins' },
204
+ auth: true,
205
+ fields: [
206
+ { name: 'name', type: 'text', required: true },
207
+ { name: 'role', type: 'select', options: ['admin', 'editor'], defaultValue: 'admin' },
208
+ ],
209
+ })
210
+
211
+ // ── Collections ──────────────────────────────────────────────────────────
212
+
213
+ const media = defineCollection({
214
+ slug: 'media',
215
+ labels: { singular: 'Media', plural: 'Media' },
216
+ upload: true,
217
+ fields: [
218
+ { name: 'alt', type: 'text' },
219
+ ],
220
+ })
221
+
222
+ const pages = defineCollection({
223
+ slug: 'pages',
224
+ labels: { singular: 'Page', plural: 'Pages' },
225
+ fields: [
226
+ { name: 'title', type: 'text', required: true },
227
+ { name: 'slug', type: 'text', required: true },
228
+ { name: 'content', type: 'richText' },
229
+ { name: 'featuredImage', type: 'relationship', relationTo: 'media' },
230
+ ],
231
+ })
232
+
233
+ const posts = defineCollection({
234
+ slug: 'posts',
235
+ labels: { singular: 'Post', plural: 'Posts' },
236
+ fields: [
237
+ { name: 'title', type: 'text', required: true },
238
+ { name: 'content', type: 'richText' },
239
+ { name: 'featuredImage', type: 'relationship', relationTo: 'media' },
240
+ ],
241
+ })
242
+
243
+ // ── Globals ───────────────────────────────────────────────────────────────
244
+
245
+ const navigation = defineGlobal({
246
+ slug: 'navigation',
247
+ label: 'Navigation',
248
+ fields: [
249
+ {
250
+ name: 'menuItems',
251
+ type: 'array',
252
+ fields: [
253
+ { name: 'label', type: 'text' },
254
+ { name: 'link', type: 'relationship', relationTo: 'pages' },
255
+ ],
256
+ },
257
+ ],
258
+ })
259
+
260
+ const settings = defineGlobal({
261
+ slug: 'settings',
262
+ label: 'Site Settings',
263
+ fields: [
264
+ { name: 'siteName', type: 'text' },
265
+ { name: 'logo', type: 'relationship', relationTo: 'media' },
266
+ { name: 'footerText', type: 'textarea' },
267
+ ],
268
+ })
269
+
270
+ // ── Config ────────────────────────────────────────────────────────────────
271
+
272
+ export default defineConfig({
273
+ collections: [admins, media, pages, posts],
274
+ globals: [navigation, settings],
275
+ db: ${dbConfig},
276
+ storage: ${storageConfig},
277
+ })
278
+ `;
279
+ }
280
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,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AAC,SAAgB,EAAE;YACpD,OAAO,EAAE,uBAAuB;YAChC,YAAY,EAAE,IAAI;SACnB,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,uBAAuB,CAAC,CAAC;QAC3D,MAAM,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QAE5C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC,CAAC;QAC5D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,sBAAsB,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,EAAE,CAAC,CAAC,CAAC;QACrF,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,GAAG,CAAC,+FAA+F,CAAC,CAC3G,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,mBAAmB,CAAC,QAAgB,EAAE,aAAqB,EAAE,QAAgB,EAAE,aAAqB;IAC3G,OAAO;EACP,QAAQ;EACR,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAgFP,QAAQ;aACH,aAAa;;CAEzB,CAAC;AACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Command } from "commander";
2
+ export declare function registerSyncSchema(program: Command): void;
3
+ //# sourceMappingURL=sync-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-schema.d.ts","sourceRoot":"","sources":["../../src/commands/sync-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOzC,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,QA0FlD"}
@@ -0,0 +1,83 @@
1
+ import chalk from "chalk";
2
+ import fs from "fs-extra";
3
+ import path from "path";
4
+ import { createJiti } from "jiti";
5
+ import { runGenerateTypes } from "../utils/type-generator.js";
6
+ export function registerSyncSchema(program) {
7
+ program
8
+ .command("sync:schema")
9
+ .description("Sync your local Dyrected schema with the Cloud dashboard")
10
+ .option("-k, --api-key <key>", "Your Dyrected API Key")
11
+ .option("-s, --site-id <id>", "Your Dyrected Site ID")
12
+ .option("-u, --url <url>", "Cloud API URL", "https://prodeegi-vault.onrender.com")
13
+ .option("-c, --config <path>", "Path to your dyrected.config.ts", "./dyrected.config.ts")
14
+ .option("--skip-on-error", "Do not exit with error if sync fails (useful for CI builds)")
15
+ .option("--skip-types", "Skip automatic type generation after a successful sync")
16
+ .addHelpText("after", `
17
+ Examples:
18
+ # Sync using env vars (DYRECTED_API_KEY, DYRECTED_SITE_ID)
19
+ $ npx @dyrected/cli sync:schema
20
+
21
+ # Sync with explicit credentials
22
+ $ npx @dyrected/cli sync:schema --api-key <key> --site-id <id>
23
+
24
+ # Sync in CI without failing the build on error
25
+ $ npx @dyrected/cli sync:schema --skip-on-error
26
+
27
+ # Sync without regenerating types
28
+ $ npx @dyrected/cli sync:schema --skip-types
29
+ `)
30
+ .action(async (options) => {
31
+ try {
32
+ const apiKey = options.apiKey || process.env.DYRECTED_API_KEY;
33
+ const siteId = options.siteId || process.env.DYRECTED_SITE_ID;
34
+ const apiUrl = options.url || process.env.DYRECTED_URL || "https://prodeegi-vault.onrender.com";
35
+ const configPath = path.resolve(process.cwd(), options.config);
36
+ if (!apiKey || !siteId) {
37
+ console.warn(chalk.yellow("\n⚠ Skipping schema sync: API Key or Site ID missing. (Required for Cloud sync, but optional for self-hosted builds)\n"));
38
+ return;
39
+ }
40
+ if (!(await fs.pathExists(configPath))) {
41
+ throw new Error(`Config file not found at ${configPath}`);
42
+ }
43
+ console.log(chalk.blue(`Loading config from ${configPath}...`));
44
+ const jiti = createJiti(configPath);
45
+ const configModule = (await jiti.import(configPath));
46
+ const config = configModule.default || configModule;
47
+ if (!config.collections)
48
+ throw new Error("Invalid config: No collections found.");
49
+ console.log(chalk.blue(`Syncing schema to ${apiUrl}...`));
50
+ const response = await fetch(`${apiUrl}/cloud/workspaces/sites/${siteId}/schema/sync`, {
51
+ method: "POST",
52
+ headers: {
53
+ "Content-Type": "application/json",
54
+ Authorization: `Bearer ${apiKey}`,
55
+ "X-API-Key": apiKey,
56
+ },
57
+ body: JSON.stringify({
58
+ collections: config.collections,
59
+ globals: config.globals || [],
60
+ admin: config.admin || {},
61
+ }),
62
+ });
63
+ if (!response.ok) {
64
+ const error = await response.json().catch(() => ({ message: response.statusText }));
65
+ throw new Error(`Sync failed: ${error.message || response.statusText}`);
66
+ }
67
+ console.log(chalk.green(`āœ” Schema synced successfully for site ${siteId}`));
68
+ if (!options.skipTypes) {
69
+ console.log(chalk.blue("\nGenerating types from synced schema..."));
70
+ await runGenerateTypes({ config: options.config, output: "./dyrected-types.ts" });
71
+ }
72
+ }
73
+ catch (error) {
74
+ if (options.skipOnError) {
75
+ console.warn(chalk.yellow(`\n⚠ Sync failed, but skipping error as requested: ${error.message}`));
76
+ return;
77
+ }
78
+ console.error(chalk.red(`\nError: ${error.message}`));
79
+ process.exit(1);
80
+ }
81
+ });
82
+ }
83
+ //# sourceMappingURL=sync-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-schema.js","sourceRoot":"","sources":["../../src/commands/sync-schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,MAAM,UAAU,kBAAkB,CAAC,OAAgB;IACjD,OAAO;SACJ,OAAO,CAAC,aAAa,CAAC;SACtB,WAAW,CAAC,0DAA0D,CAAC;SACvE,MAAM,CAAC,qBAAqB,EAAE,uBAAuB,CAAC;SACtD,MAAM,CAAC,oBAA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