@gearu/cli 1.2.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.
@@ -0,0 +1,55 @@
1
+ import {
2
+ init_esm_shims
3
+ } from "./chunk-RAR5OL4C.js";
4
+
5
+ // src/lib/parsers.ts
6
+ init_esm_shims();
7
+ function parseInteger(value, label) {
8
+ const parsed = Number.parseInt(value, 10);
9
+ if (!Number.isInteger(parsed)) {
10
+ throw new Error(`${label} must be an integer.`);
11
+ }
12
+ return parsed;
13
+ }
14
+ function createIntegerParser(label) {
15
+ return (value) => parseInteger(value, label);
16
+ }
17
+ function parseNullableOption(value) {
18
+ if (value === void 0) return void 0;
19
+ return value === "null" ? null : value;
20
+ }
21
+ function parseEntryFields(value) {
22
+ if (value === void 0) return void 0;
23
+ let parsed;
24
+ try {
25
+ parsed = JSON.parse(value);
26
+ } catch {
27
+ throw new Error("`--fields` must be valid JSON.");
28
+ }
29
+ if (!Array.isArray(parsed)) {
30
+ throw new Error("`--fields` must be a JSON array.");
31
+ }
32
+ return parsed.map((item, index) => {
33
+ if (!item || typeof item !== "object") {
34
+ throw new Error(`Field at index ${index} must be an object.`);
35
+ }
36
+ const candidate = item;
37
+ if (!Number.isInteger(candidate.fieldId)) {
38
+ throw new Error(`Field at index ${index} must include an integer fieldId.`);
39
+ }
40
+ if (!(typeof candidate.value === "string" || candidate.value === null)) {
41
+ throw new Error(`Field at index ${index} must include a string or null value.`);
42
+ }
43
+ return {
44
+ fieldId: candidate.fieldId,
45
+ value: candidate.value
46
+ };
47
+ });
48
+ }
49
+
50
+ export {
51
+ createIntegerParser,
52
+ parseNullableOption,
53
+ parseEntryFields
54
+ };
55
+ //# sourceMappingURL=chunk-HI5EA6RV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/parsers.ts"],"sourcesContent":["export interface EntryFieldInput {\n fieldId: number\n value: string | null\n}\n\nexport function parseInteger(value: string, label: string): number {\n const parsed = Number.parseInt(value, 10)\n if (!Number.isInteger(parsed)) {\n throw new Error(`${label} must be an integer.`)\n }\n return parsed\n}\n\nexport function createIntegerParser(label: string) {\n return (value: string) => parseInteger(value, label)\n}\n\nexport function parseNullableOption(value: string | undefined): string | null | undefined {\n if (value === undefined) return undefined\n return value === \"null\" ? null : value\n}\n\nexport function parseEntryFields(value: string | undefined): EntryFieldInput[] | undefined {\n if (value === undefined) return undefined\n\n let parsed: unknown\n try {\n parsed = JSON.parse(value)\n } catch {\n throw new Error(\"`--fields` must be valid JSON.\")\n }\n\n if (!Array.isArray(parsed)) {\n throw new Error(\"`--fields` must be a JSON array.\")\n }\n\n return parsed.map((item, index) => {\n if (!item || typeof item !== \"object\") {\n throw new Error(`Field at index ${index} must be an object.`)\n }\n\n const candidate = item as Record<string, unknown>\n if (!Number.isInteger(candidate.fieldId)) {\n throw new Error(`Field at index ${index} must include an integer fieldId.`)\n }\n\n if (!(typeof candidate.value === \"string\" || candidate.value === null)) {\n throw new Error(`Field at index ${index} must include a string or null value.`)\n }\n\n return {\n fieldId: candidate.fieldId,\n value: candidate.value,\n }\n })\n}\n"],"mappings":";;;;;AAAA;AAKO,SAAS,aAAa,OAAe,OAAuB;AACjE,QAAM,SAAS,OAAO,SAAS,OAAO,EAAE;AACxC,MAAI,CAAC,OAAO,UAAU,MAAM,GAAG;AAC7B,UAAM,IAAI,MAAM,GAAG,KAAK,sBAAsB;AAAA,EAChD;AACA,SAAO;AACT;AAEO,SAAS,oBAAoB,OAAe;AACjD,SAAO,CAAC,UAAkB,aAAa,OAAO,KAAK;AACrD;AAEO,SAAS,oBAAoB,OAAsD;AACxF,MAAI,UAAU,OAAW,QAAO;AAChC,SAAO,UAAU,SAAS,OAAO;AACnC;AAEO,SAAS,iBAAiB,OAA0D;AACzF,MAAI,UAAU,OAAW,QAAO;AAEhC,MAAI;AACJ,MAAI;AACF,aAAS,KAAK,MAAM,KAAK;AAAA,EAC3B,QAAQ;AACN,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AAEA,MAAI,CAAC,MAAM,QAAQ,MAAM,GAAG;AAC1B,UAAM,IAAI,MAAM,kCAAkC;AAAA,EACpD;AAEA,SAAO,OAAO,IAAI,CAAC,MAAM,UAAU;AACjC,QAAI,CAAC,QAAQ,OAAO,SAAS,UAAU;AACrC,YAAM,IAAI,MAAM,kBAAkB,KAAK,qBAAqB;AAAA,IAC9D;AAEA,UAAM,YAAY;AAClB,QAAI,CAAC,OAAO,UAAU,UAAU,OAAO,GAAG;AACxC,YAAM,IAAI,MAAM,kBAAkB,KAAK,mCAAmC;AAAA,IAC5E;AAEA,QAAI,EAAE,OAAO,UAAU,UAAU,YAAY,UAAU,UAAU,OAAO;AACtE,YAAM,IAAI,MAAM,kBAAkB,KAAK,uCAAuC;AAAA,IAChF;AAEA,WAAO;AAAA,MACL,SAAS,UAAU;AAAA,MACnB,OAAO,UAAU;AAAA,IACnB;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,33 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __commonJS = (cb, mod) => function __require2() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
14
+
15
+ // ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.8_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/esm_shims.js
16
+ import path from "path";
17
+ import { fileURLToPath } from "url";
18
+ var getFilename, __filename;
19
+ var init_esm_shims = __esm({
20
+ "../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.8_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/esm_shims.js"() {
21
+ "use strict";
22
+ getFilename = () => fileURLToPath(import.meta.url);
23
+ __filename = /* @__PURE__ */ getFilename();
24
+ }
25
+ });
26
+
27
+ export {
28
+ __require,
29
+ __commonJS,
30
+ __filename,
31
+ init_esm_shims
32
+ };
33
+ //# sourceMappingURL=chunk-RAR5OL4C.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.8_tsx@4.21.0_typescript@5.9.3/node_modules/tsup/assets/esm_shims.js"],"sourcesContent":["// Shim globals in esm bundle\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n"],"mappings":";;;;;;;;;;;;;;;AACA,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAF9B,IAIM,aAIO;AARb;AAAA;AAAA;AAIA,IAAM,cAAc,MAAM,cAAc,YAAY,GAAG;AAIhD,IAAM,aAA6B,4BAAY;AAAA;AAAA;","names":[]}
@@ -0,0 +1,169 @@
1
+ import {
2
+ init_esm_shims
3
+ } from "./chunk-RAR5OL4C.js";
4
+
5
+ // src/lib/runtime.ts
6
+ init_esm_shims();
7
+ import { existsSync, readFileSync } from "fs";
8
+ import { isAbsolute, join, resolve } from "path";
9
+ import { pathToFileURL } from "url";
10
+ import { cwd } from "process";
11
+ import ts from "typescript";
12
+ import { createDb, resolveConfig } from "@gearu/core";
13
+ import {
14
+ createGearuRouterRecord,
15
+ createGearuTRPC
16
+ } from "@gearu/core/trpc";
17
+ var CONFIG_CANDIDATES = [
18
+ "gearu.config.ts",
19
+ "gearu.config.mts",
20
+ "gearu.config.cts",
21
+ "gearu.config.js",
22
+ "gearu.config.mjs",
23
+ "gearu.config.cjs"
24
+ ];
25
+ var trpc = createGearuTRPC();
26
+ var appRouter = trpc.createTRPCRouter(
27
+ createGearuRouterRecord({
28
+ db: null,
29
+ publicProcedure: trpc.publicProcedure,
30
+ protectedProcedure: trpc.protectedProcedure,
31
+ TRPCError: trpc.TRPCError
32
+ })
33
+ );
34
+ function getConfigPath(root) {
35
+ for (const name of CONFIG_CANDIDATES) {
36
+ const filePath = join(root, name);
37
+ if (existsSync(filePath)) {
38
+ return filePath;
39
+ }
40
+ }
41
+ throw new Error("No gearu config found. Expected gearu.config.ts (or .js/.mjs/.cjs) in the current directory.");
42
+ }
43
+ function isTypeScriptConfig(configPath) {
44
+ return /\.(cts|mts|ts)$/.test(configPath);
45
+ }
46
+ async function importConfigModule(configPath) {
47
+ if (!isTypeScriptConfig(configPath)) {
48
+ return import(pathToFileURL(configPath).href);
49
+ }
50
+ const source = readFileSync(configPath, "utf-8");
51
+ const compiled = ts.transpileModule(source, {
52
+ compilerOptions: {
53
+ module: ts.ModuleKind.ESNext,
54
+ target: ts.ScriptTarget.ES2022,
55
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
56
+ esModuleInterop: true,
57
+ resolveJsonModule: true
58
+ },
59
+ fileName: configPath
60
+ }).outputText;
61
+ const url = `data:text/javascript;base64,${Buffer.from(compiled).toString("base64")}`;
62
+ return import(url);
63
+ }
64
+ async function loadGearuConfig(root = cwd()) {
65
+ const configPath = getConfigPath(root);
66
+ const moduleExports = await importConfigModule(configPath);
67
+ const rawConfig = moduleExports.default ?? moduleExports;
68
+ if (!rawConfig || typeof rawConfig !== "object") {
69
+ throw new Error("gearu.config.ts must export a default config object.");
70
+ }
71
+ return {
72
+ config: resolveConfig(rawConfig),
73
+ configPath
74
+ };
75
+ }
76
+ function toDatabasePath(databaseUrl, root) {
77
+ if (databaseUrl === ":memory:" || databaseUrl === "file::memory:") {
78
+ return ":memory:";
79
+ }
80
+ if (/^(https?|libsql|postgres|mysql):/i.test(databaseUrl)) {
81
+ throw new Error("The Gearu CLI CRUD commands currently support local SQLite databases only.");
82
+ }
83
+ if (databaseUrl.startsWith("file://")) {
84
+ return new URL(databaseUrl).pathname;
85
+ }
86
+ const normalized = databaseUrl.startsWith("file:") ? databaseUrl.slice("file:".length) : databaseUrl;
87
+ const [pathWithoutQuery] = normalized.split("?");
88
+ if (!pathWithoutQuery) {
89
+ throw new Error("The configured database URL is empty.");
90
+ }
91
+ if (pathWithoutQuery === ":memory:") {
92
+ return ":memory:";
93
+ }
94
+ return isAbsolute(pathWithoutQuery) ? pathWithoutQuery : resolve(root, pathWithoutQuery);
95
+ }
96
+ async function createGearuCliRuntime(root = cwd()) {
97
+ const { config, configPath } = await loadGearuConfig(root);
98
+ const databasePath = toDatabasePath(config.databaseUrl, root);
99
+ const betterSqlite3 = await import("./lib-K5RL2DZX.js");
100
+ const connection = new betterSqlite3.default(databasePath);
101
+ connection.pragma("foreign_keys = ON");
102
+ const db = createDb(connection);
103
+ const router = trpc.createTRPCRouter(
104
+ createGearuRouterRecord({
105
+ db,
106
+ publicProcedure: trpc.publicProcedure,
107
+ protectedProcedure: trpc.protectedProcedure,
108
+ TRPCError: trpc.TRPCError
109
+ })
110
+ );
111
+ return {
112
+ caller: router.createCaller({
113
+ headers: new Headers(),
114
+ session: { user: { id: "cli", name: "Gearu CLI" } }
115
+ }),
116
+ close: () => connection.close(),
117
+ config,
118
+ configPath,
119
+ databasePath,
120
+ root
121
+ };
122
+ }
123
+
124
+ // src/lib/output.ts
125
+ init_esm_shims();
126
+ import { getUserFacingErrorMessage } from "@gearu/core/trpc";
127
+ function printSuccess(result, options, toText) {
128
+ if (options.json) {
129
+ console.log(JSON.stringify({ success: true, data: result }, null, 2));
130
+ return;
131
+ }
132
+ console.log(toText(result));
133
+ }
134
+ function printError(error, options) {
135
+ const message = getErrorMessage(error);
136
+ if (options.json) {
137
+ console.error(
138
+ JSON.stringify(
139
+ {
140
+ success: false,
141
+ error: {
142
+ message
143
+ }
144
+ },
145
+ null,
146
+ 2
147
+ )
148
+ );
149
+ } else {
150
+ console.error(message);
151
+ }
152
+ process.exitCode = 1;
153
+ }
154
+ function getErrorMessage(error) {
155
+ if (error && typeof error === "object" && "code" in error && "message" in error) {
156
+ return getUserFacingErrorMessage(error);
157
+ }
158
+ if (error instanceof Error) {
159
+ return error.message;
160
+ }
161
+ return "Something went wrong. Please try again.";
162
+ }
163
+
164
+ export {
165
+ createGearuCliRuntime,
166
+ printSuccess,
167
+ printError
168
+ };
169
+ //# sourceMappingURL=chunk-U5KPPK2Y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/runtime.ts","../src/lib/output.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\"\nimport { isAbsolute, join, resolve } from \"node:path\"\nimport { pathToFileURL } from \"node:url\"\nimport { cwd } from \"node:process\"\nimport ts from \"typescript\"\nimport { createDb, resolveConfig, type GearuConfig, type ResolvedGearuConfig } from \"@gearu/core\"\nimport {\n createGearuRouterRecord,\n createGearuTRPC,\n} from \"@gearu/core/trpc\"\n\nconst CONFIG_CANDIDATES = [\n \"gearu.config.ts\",\n \"gearu.config.mts\",\n \"gearu.config.cts\",\n \"gearu.config.js\",\n \"gearu.config.mjs\",\n \"gearu.config.cjs\",\n] as const\n\nconst trpc = createGearuTRPC<{\n headers: Headers\n session: { user: { id: string; name: string } } | null\n}>()\n\nconst appRouter = trpc.createTRPCRouter(\n createGearuRouterRecord({\n db: null as never,\n publicProcedure: trpc.publicProcedure,\n protectedProcedure: trpc.protectedProcedure,\n TRPCError: trpc.TRPCError,\n }),\n)\n\nexport type GearuCliCaller = ReturnType<typeof appRouter.createCaller>\n\nexport interface GearuCliRuntime {\n caller: GearuCliCaller\n close: () => void\n config: ResolvedGearuConfig\n configPath: string\n databasePath: string\n root: string\n}\n\nfunction getConfigPath(root: string): string {\n for (const name of CONFIG_CANDIDATES) {\n const filePath = join(root, name)\n if (existsSync(filePath)) {\n return filePath\n }\n }\n\n throw new Error(\"No gearu config found. Expected gearu.config.ts (or .js/.mjs/.cjs) in the current directory.\")\n}\n\nfunction isTypeScriptConfig(configPath: string): boolean {\n return /\\.(cts|mts|ts)$/.test(configPath)\n}\n\nasync function importConfigModule(configPath: string): Promise<{ default?: unknown }> {\n if (!isTypeScriptConfig(configPath)) {\n return import(pathToFileURL(configPath).href)\n }\n\n const source = readFileSync(configPath, \"utf-8\")\n const compiled = ts.transpileModule(source, {\n compilerOptions: {\n module: ts.ModuleKind.ESNext,\n target: ts.ScriptTarget.ES2022,\n moduleResolution: ts.ModuleResolutionKind.Bundler,\n esModuleInterop: true,\n resolveJsonModule: true,\n },\n fileName: configPath,\n }).outputText\n\n const url = `data:text/javascript;base64,${Buffer.from(compiled).toString(\"base64\")}`\n return import(url)\n}\n\nexport async function loadGearuConfig(root = cwd()): Promise<{\n config: ResolvedGearuConfig\n configPath: string\n}> {\n const configPath = getConfigPath(root)\n const moduleExports = await importConfigModule(configPath)\n const rawConfig = (moduleExports.default ?? moduleExports) as Partial<GearuConfig> | undefined\n\n if (!rawConfig || typeof rawConfig !== \"object\") {\n throw new Error(\"gearu.config.ts must export a default config object.\")\n }\n\n return {\n config: resolveConfig(rawConfig),\n configPath,\n }\n}\n\nfunction toDatabasePath(databaseUrl: string, root: string): string {\n if (databaseUrl === \":memory:\" || databaseUrl === \"file::memory:\") {\n return \":memory:\"\n }\n\n if (/^(https?|libsql|postgres|mysql):/i.test(databaseUrl)) {\n throw new Error(\"The Gearu CLI CRUD commands currently support local SQLite databases only.\")\n }\n\n if (databaseUrl.startsWith(\"file://\")) {\n return new URL(databaseUrl).pathname\n }\n\n const normalized = databaseUrl.startsWith(\"file:\")\n ? databaseUrl.slice(\"file:\".length)\n : databaseUrl\n\n const [pathWithoutQuery] = normalized.split(\"?\")\n if (!pathWithoutQuery) {\n throw new Error(\"The configured database URL is empty.\")\n }\n\n if (pathWithoutQuery === \":memory:\") {\n return \":memory:\"\n }\n\n return isAbsolute(pathWithoutQuery)\n ? pathWithoutQuery\n : resolve(root, pathWithoutQuery)\n}\n\nexport async function createGearuCliRuntime(root = cwd()): Promise<GearuCliRuntime> {\n const { config, configPath } = await loadGearuConfig(root)\n const databasePath = toDatabasePath(config.databaseUrl, root)\n const betterSqlite3 = (await import(\"better-sqlite3\")) as {\n default: new (path: string) => {\n close: () => void\n pragma: (statement: string) => void\n }\n }\n const connection = new betterSqlite3.default(databasePath)\n connection.pragma(\"foreign_keys = ON\")\n\n const db = createDb(connection as never)\n const router = trpc.createTRPCRouter(\n createGearuRouterRecord({\n db,\n publicProcedure: trpc.publicProcedure,\n protectedProcedure: trpc.protectedProcedure,\n TRPCError: trpc.TRPCError,\n }),\n )\n\n return {\n caller: router.createCaller({\n headers: new Headers(),\n session: { user: { id: \"cli\", name: \"Gearu CLI\" } },\n }),\n close: () => connection.close(),\n config,\n configPath,\n databasePath,\n root,\n }\n}\n","import { getUserFacingErrorMessage } from \"@gearu/core/trpc\"\n\nexport interface JsonFlagOption {\n json?: boolean\n}\n\nexport function printSuccess<T>(\n result: T,\n options: JsonFlagOption,\n toText: (result: T) => string,\n) {\n if (options.json) {\n console.log(JSON.stringify({ success: true, data: result }, null, 2))\n return\n }\n\n console.log(toText(result))\n}\n\nexport function printError(error: unknown, options: JsonFlagOption) {\n const message = getErrorMessage(error)\n\n if (options.json) {\n console.error(\n JSON.stringify(\n {\n success: false,\n error: {\n message,\n },\n },\n null,\n 2,\n ),\n )\n } else {\n console.error(message)\n }\n\n process.exitCode = 1\n}\n\nfunction getErrorMessage(error: unknown): string {\n if (error && typeof error === \"object\" && \"code\" in error && \"message\" in error) {\n return getUserFacingErrorMessage(error as Parameters<typeof getUserFacingErrorMessage>[0])\n }\n\n if (error instanceof Error) {\n return error.message\n }\n\n return \"Something went wrong. Please try again.\"\n}\n"],"mappings":";;;;;AAAA;AAAA,SAAS,YAAY,oBAAoB;AACzC,SAAS,YAAY,MAAM,eAAe;AAC1C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A,IAClB,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,QAAQ,OAAO,aAAa;AAAA,MAC1B,SAAS,IAAI,QAAQ;AAAA,MACrB,SAAS,EAAE,MAAM,EAAE,IAAI,OAAO,MAAM,YAAY,EAAE;AAAA,IACpD,CAAC;AAAA,IACD,OAAO,MAAM,WAAW,MAAM;AAAA,IAC9B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;;ACnKA;AAAA,SAAS,iCAAiC;AAMnC,SAAS,aACd,QACA,SACA,QACA;AACA,MAAI,QAAQ,MAAM;AAChB,YAAQ,IAAI,KAAK,UAAU,EAAE,SAAS,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC;AACpE;AAAA,EACF;AAEA,UAAQ,IAAI,OAAO,MAAM,CAAC;AAC5B;AAEO,SAAS,WAAW,OAAgB,SAAyB;AAClE,QAAM,UAAU,gBAAgB,KAAK;AAErC,MAAI,QAAQ,MAAM;AAChB,YAAQ;AAAA,MACN,KAAK;AAAA,QACH;AAAA,UACE,SAAS;AAAA,UACT,OAAO;AAAA,YACL;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AACL,YAAQ,MAAM,OAAO;AAAA,EACvB;AAEA,UAAQ,WAAW;AACrB;AAEA,SAAS,gBAAgB,OAAwB;AAC/C,MAAI,SAAS,OAAO,UAAU,YAAY,UAAU,SAAS,aAAa,OAAO;AAC/E,WAAO,0BAA0B,KAAwD;AAAA,EAC3F;AAEA,MAAI,iBAAiB,OAAO;AAC1B,WAAO,MAAM;AAAA,EACf;AAEA,SAAO;AACT;","names":[]}
package/dist/cli.js ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ createIntegerParser
4
+ } from "./chunk-HI5EA6RV.js";
5
+ import {
6
+ init_esm_shims
7
+ } from "./chunk-RAR5OL4C.js";
8
+
9
+ // src/cli.ts
10
+ init_esm_shims();
11
+ import updateNotifier from "update-notifier";
12
+ import { readFileSync } from "fs";
13
+ import { dirname, join } from "path";
14
+ import { fileURLToPath } from "url";
15
+
16
+ // src/program.ts
17
+ init_esm_shims();
18
+ import { Command } from "commander";
19
+ var parseCollectionId = createIntegerParser("collection id");
20
+ var parseEntryId = createIntegerParser("entry id");
21
+ var parseLimit = createIntegerParser("limit");
22
+ var parseOffset = createIntegerParser("offset");
23
+ function createCliProgram(version) {
24
+ const program = new Command();
25
+ program.name("gearu").description("Gearu CMS CLI").version(version).showHelpAfterError();
26
+ program.command("init").description("Create gearu.config.ts and ensure admin route exists").action(async () => {
27
+ const { init } = await import("./init-YPPWOECE.js");
28
+ await init();
29
+ });
30
+ program.command("migrate").description("Generate and apply migrations (core + plugins)").option("--dry-run", "Only generate, do not apply").action(async (opts) => {
31
+ const { migrate } = await import("./migrate-H4ZAQQ6P.js");
32
+ await migrate(opts);
33
+ });
34
+ program.command("upgrade").description("Check for updates and optionally run migrations").action(async () => {
35
+ const { upgrade } = await import("./upgrade-3I7PAU7K.js");
36
+ await upgrade();
37
+ });
38
+ const collections = program.command("collections").description("List, inspect, and mutate collections");
39
+ collections.command("list").description("List all collections").option("--json", "Print machine-readable JSON output").action(async (opts) => {
40
+ const { listCollections } = await import("./collections-SC2PJQKG.js");
41
+ await listCollections(opts);
42
+ });
43
+ collections.command("get").description("Get one collection by id").argument("<id>", "Collection id", parseCollectionId).option("--json", "Print machine-readable JSON output").action(async (id, opts) => {
44
+ const { getCollection } = await import("./collections-SC2PJQKG.js");
45
+ await getCollection(id, opts);
46
+ });
47
+ collections.command("create").description("Create a collection").requiredOption("--name <name>", "Collection name").option("--slug <slug>", "Collection slug").option("--description <description>", "Collection description").option("--json", "Print machine-readable JSON output").action(async (opts) => {
48
+ const { createCollection } = await import("./collections-SC2PJQKG.js");
49
+ await createCollection(opts);
50
+ });
51
+ collections.command("update").description("Update a collection").argument("<id>", "Collection id", parseCollectionId).option("--name <name>", "Collection name").option("--slug <slug>", "Collection slug").option("--description <description>", "Collection description").option("--json", "Print machine-readable JSON output").action(async (id, opts) => {
52
+ const { updateCollection } = await import("./collections-SC2PJQKG.js");
53
+ await updateCollection(id, opts);
54
+ });
55
+ collections.command("delete").description("Delete a collection").argument("<id>", "Collection id", parseCollectionId).option("--json", "Print machine-readable JSON output").action(async (id, opts) => {
56
+ const { deleteCollection } = await import("./collections-SC2PJQKG.js");
57
+ await deleteCollection(id, opts);
58
+ });
59
+ const entries = program.command("entries").description("List, inspect, and mutate entries");
60
+ entries.command("list").description("List entries").option("--collection-id <id>", "Filter by collection id", parseCollectionId).option("--status <status>", "Filter by status (draft, published, archived)").option("--limit <limit>", "Max entries to return", parseLimit).option("--offset <offset>", "Skip the first N entries", parseOffset).option("--json", "Print machine-readable JSON output").action(async (opts) => {
61
+ const { listEntries } = await import("./entries-AKHKPFRA.js");
62
+ await listEntries(opts);
63
+ });
64
+ entries.command("get").description("Get one entry by id").argument("<id>", "Entry id", parseEntryId).option("--json", "Print machine-readable JSON output").action(async (id, opts) => {
65
+ const { getEntry } = await import("./entries-AKHKPFRA.js");
66
+ await getEntry(id, opts);
67
+ });
68
+ entries.command("create").description("Create an entry").requiredOption("--collection-id <id>", "Collection id", parseCollectionId).requiredOption("--title <title>", "Entry title").option("--slug <slug>", "Entry slug").option("--status <status>", "Entry status (draft or published)").option("--meta-title <metaTitle>", "SEO meta title").option("--meta-description <metaDescription>", "SEO meta description").option("--og-image <url>", "Open Graph image URL").option("--fields <json>", "JSON array of { fieldId, value } objects").option("--json", "Print machine-readable JSON output").action(async (opts) => {
69
+ const { createEntry } = await import("./entries-AKHKPFRA.js");
70
+ await createEntry(opts);
71
+ });
72
+ entries.command("update").description("Update an entry").argument("<id>", "Entry id", parseEntryId).option("--title <title>", "Entry title").option("--slug <slug>", "Entry slug").option("--status <status>", "Entry status (draft, published, archived)").option("--meta-title <metaTitle>", "SEO meta title, or `null` to clear it").option("--meta-description <metaDescription>", "SEO meta description, or `null` to clear it").option("--og-image <url>", "Open Graph image URL, or `null` to clear it").option("--fields <json>", "JSON array of { fieldId, value } objects").option("--json", "Print machine-readable JSON output").action(async (id, opts) => {
73
+ const { updateEntry } = await import("./entries-AKHKPFRA.js");
74
+ await updateEntry(id, opts);
75
+ });
76
+ entries.command("delete").description("Delete an entry").argument("<id>", "Entry id", parseEntryId).option("--json", "Print machine-readable JSON output").action(async (id, opts) => {
77
+ const { deleteEntry } = await import("./entries-AKHKPFRA.js");
78
+ await deleteEntry(id, opts);
79
+ });
80
+ return program;
81
+ }
82
+
83
+ // src/cli.ts
84
+ var __dirname2 = dirname(fileURLToPath(import.meta.url));
85
+ var pkg = JSON.parse(
86
+ readFileSync(join(__dirname2, "../package.json"), "utf-8")
87
+ );
88
+ updateNotifier({ pkg }).notify();
89
+ await createCliProgram(pkg.version).parseAsync();
90
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli.ts","../src/program.ts"],"sourcesContent":["#!/usr/bin/env node\nimport updateNotifier from \"update-notifier\"\nimport { readFileSync } from \"fs\"\nimport { dirname, join } from \"path\"\nimport { fileURLToPath } from \"url\"\nimport { createCliProgram } from \"./program\"\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\nconst pkg = JSON.parse(\n readFileSync(join(__dirname, \"../package.json\"), \"utf-8\"),\n) as { name: string; version: string }\n\nupdateNotifier({ pkg }).notify()\n\nawait createCliProgram(pkg.version).parseAsync()\n","import { Command } from \"commander\"\nimport { createIntegerParser } from \"./lib/parsers\"\n\nconst parseCollectionId = createIntegerParser(\"collection id\")\nconst parseEntryId = createIntegerParser(\"entry id\")\nconst parseLimit = createIntegerParser(\"limit\")\nconst parseOffset = createIntegerParser(\"offset\")\n\nexport function createCliProgram(version: string) {\n const program = new Command()\n program\n .name(\"gearu\")\n .description(\"Gearu CMS CLI\")\n .version(version)\n .showHelpAfterError()\n\n program\n .command(\"init\")\n .description(\"Create gearu.config.ts and ensure admin route exists\")\n .action(async () => {\n const { init } = await import(\"./commands/init.js\")\n await init()\n })\n\n program\n .command(\"migrate\")\n .description(\"Generate and apply migrations (core + plugins)\")\n .option(\"--dry-run\", \"Only generate, do not apply\")\n .action(async (opts: { dryRun?: boolean }) => {\n const { migrate } = await import(\"./commands/migrate.js\")\n await migrate(opts)\n })\n\n program\n .command(\"upgrade\")\n .description(\"Check for updates and optionally run migrations\")\n .action(async () => {\n const { upgrade } = await import(\"./commands/upgrade.js\")\n await upgrade()\n })\n\n const collections = program\n .command(\"collections\")\n .description(\"List, inspect, and mutate collections\")\n\n collections\n .command(\"list\")\n .description(\"List all collections\")\n .option(\"--json\", \"Print machine-readable JSON output\")\n .action(async (opts: { json?: boolean }) => {\n const { listCollections } = await import(\"./commands/collections.js\")\n await listCollections(opts)\n })\n\n collections\n .command(\"get\")\n .description(\"Get one collection by id\")\n .argument(\"<id>\", \"Collection id\", parseCollectionId)\n .option(\"--json\", \"Print machine-readable JSON output\")\n .action(async (id: number, opts: { json?: boolean }) => {\n const { getCollection } = await import(\"./commands/collections.js\")\n await getCollection(id, opts)\n })\n\n collections\n .command(\"create\")\n .description(\"Create a collection\")\n .requiredOption(\"--name <name>\", \"Collection name\")\n .option(\"--slug <slug>\", \"Collection slug\")\n .option(\"--description <description>\", \"Collection description\")\n .option(\"--json\", \"Print machine-readable JSON output\")\n .action(async (opts: { name: string; slug?: string; description?: string; json?: boolean }) => {\n const { createCollection } = await import(\"./commands/collections.js\")\n await createCollection(opts)\n })\n\n collections\n .command(\"update\")\n .description(\"Update a collection\")\n .argument(\"<id>\", \"Collection id\", parseCollectionId)\n .option(\"--name <name>\", \"Collection name\")\n .option(\"--slug <slug>\", \"Collection slug\")\n .option(\"--description <description>\", \"Collection description\")\n .option(\"--json\", \"Print machine-readable JSON output\")\n .action(async (id: number, opts: { name?: string; slug?: string; description?: string; json?: boolean }) => {\n const { updateCollection } = await import(\"./commands/collections.js\")\n await updateCollection(id, opts)\n })\n\n collections\n .command(\"delete\")\n .description(\"Delete a collection\")\n .argument(\"<id>\", \"Collection id\", parseCollectionId)\n .option(\"--json\", \"Print machine-readable JSON output\")\n .action(async (id: number, opts: { json?: boolean }) => {\n const { deleteCollection } = await import(\"./commands/collections.js\")\n await deleteCollection(id, opts)\n })\n\n const entries = program\n .command(\"entries\")\n .description(\"List, inspect, and mutate entries\")\n\n entries\n .command(\"list\")\n .description(\"List entries\")\n .option(\"--collection-id <id>\", \"Filter by collection id\", parseCollectionId)\n .option(\"--status <status>\", \"Filter by status (draft, published, archived)\")\n .option(\"--limit <limit>\", \"Max entries to return\", parseLimit)\n .option(\"--offset <offset>\", \"Skip the first N entries\", parseOffset)\n .option(\"--json\", \"Print machine-readable JSON output\")\n .action(async (opts: {\n collectionId?: number\n status?: \"draft\" | \"published\" | \"archived\"\n limit?: number\n offset?: number\n json?: boolean\n }) => {\n const { listEntries } = await import(\"./commands/entries.js\")\n await listEntries(opts)\n })\n\n entries\n .command(\"get\")\n .description(\"Get one entry by id\")\n .argument(\"<id>\", \"Entry id\", parseEntryId)\n .option(\"--json\", \"Print machine-readable JSON output\")\n .action(async (id: number, opts: { json?: boolean }) => {\n const { getEntry } = await import(\"./commands/entries.js\")\n await getEntry(id, opts)\n })\n\n entries\n .command(\"create\")\n .description(\"Create an entry\")\n .requiredOption(\"--collection-id <id>\", \"Collection id\", parseCollectionId)\n .requiredOption(\"--title <title>\", \"Entry title\")\n .option(\"--slug <slug>\", \"Entry slug\")\n .option(\"--status <status>\", \"Entry status (draft or published)\")\n .option(\"--meta-title <metaTitle>\", \"SEO meta title\")\n .option(\"--meta-description <metaDescription>\", \"SEO meta description\")\n .option(\"--og-image <url>\", \"Open Graph image URL\")\n .option(\"--fields <json>\", \"JSON array of { fieldId, value } objects\")\n .option(\"--json\", \"Print machine-readable JSON output\")\n .action(async (opts: {\n collectionId: number\n title: string\n slug?: string\n status?: \"draft\" | \"published\"\n metaTitle?: string\n metaDescription?: string\n ogImage?: string\n fields?: string\n json?: boolean\n }) => {\n const { createEntry } = await import(\"./commands/entries.js\")\n await createEntry(opts)\n })\n\n entries\n .command(\"update\")\n .description(\"Update an entry\")\n .argument(\"<id>\", \"Entry id\", parseEntryId)\n .option(\"--title <title>\", \"Entry title\")\n .option(\"--slug <slug>\", \"Entry slug\")\n .option(\"--status <status>\", \"Entry status (draft, published, archived)\")\n .option(\"--meta-title <metaTitle>\", \"SEO meta title, or `null` to clear it\")\n .option(\"--meta-description <metaDescription>\", \"SEO meta description, or `null` to clear it\")\n .option(\"--og-image <url>\", \"Open Graph image URL, or `null` to clear it\")\n .option(\"--fields <json>\", \"JSON array of { fieldId, value } objects\")\n .option(\"--json\", \"Print machine-readable JSON output\")\n .action(async (id: number, opts: {\n title?: string\n slug?: string\n status?: \"draft\" | \"published\" | \"archived\"\n metaTitle?: string\n metaDescription?: string\n ogImage?: string\n fields?: string\n json?: boolean\n }) => {\n const { updateEntry } = await import(\"./commands/entries.js\")\n await updateEntry(id, opts)\n })\n\n entries\n .command(\"delete\")\n .description(\"Delete an entry\")\n .argument(\"<id>\", \"Entry id\", parseEntryId)\n .option(\"--json\", \"Print machine-readable JSON output\")\n .action(async (id: number, opts: { json?: boolean }) => {\n const { deleteEntry } = await import(\"./commands/entries.js\")\n await deleteEntry(id, opts)\n })\n\n return program\n}\n"],"mappings":";;;;;;;;;AAAA;AACA,OAAO,oBAAoB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;;;ACJ9B;AAAA,SAAS,eAAe;AAGxB,IAAM,oBAAoB,oBAAoB,eAAe;AAC7D,IAAM,eAAe,oBAAoB,UAAU;AACnD,IAAM,aAAa,oBAAoB,OAAO;AAC9C,IAAM,cAAc,oBAAoB,QAAQ;AAEzC,SAAS,iBAAiB,SAAiB;AAChD,QAAM,UAAU,IAAI,QAAQ;AAC5B,UACG,KAAK,OAAO,EACZ,YAAY,eAAe,EAC3B,QAAQ,OAAO,EACf,mBAAmB;AAEtB,UACG,QAAQ,MA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,eAAe,EAAE,IAAI,CAAC,EAAE,OAAO;AAE/B,MAAM,iBAAiB,IAAI,OAAO,EAAE,WAAW;","names":["__dirname"]}
@@ -0,0 +1,117 @@
1
+ import {
2
+ createGearuCliRuntime,
3
+ printError,
4
+ printSuccess
5
+ } from "./chunk-U5KPPK2Y.js";
6
+ import {
7
+ init_esm_shims
8
+ } from "./chunk-RAR5OL4C.js";
9
+
10
+ // src/commands/collections.ts
11
+ init_esm_shims();
12
+ async function listCollections(options) {
13
+ const runtime = await createGearuCliRuntime();
14
+ try {
15
+ const collections = await runtime.caller.collections.list();
16
+ printSuccess(collections, options, (result) => {
17
+ if (result.length === 0) {
18
+ return "No collections found.";
19
+ }
20
+ return [
21
+ `Found ${result.length} collection${result.length === 1 ? "" : "s"}.`,
22
+ ...result.map(
23
+ (collection) => `#${collection.id} ${collection.name} (${collection.slug}) - ${collection.fields.length} field${collection.fields.length === 1 ? "" : "s"}, ${collection.entries.length} entr${collection.entries.length === 1 ? "y" : "ies"}`
24
+ )
25
+ ].join("\n");
26
+ });
27
+ } catch (error) {
28
+ printError(error, options);
29
+ } finally {
30
+ runtime.close();
31
+ }
32
+ }
33
+ async function getCollection(id, options) {
34
+ const runtime = await createGearuCliRuntime();
35
+ try {
36
+ const collection = await runtime.caller.collections.getById({ id });
37
+ if (!collection) {
38
+ throw new Error(`Collection #${id} was not found.`);
39
+ }
40
+ printSuccess(collection, options, (result) => {
41
+ const lines = [`Collection #${result.id}: ${result.name} (${result.slug})`];
42
+ if (result.description) {
43
+ lines.push(`Description: ${result.description}`);
44
+ }
45
+ lines.push(`Fields: ${result.fields.length}`);
46
+ for (const field of result.fields) {
47
+ lines.push(
48
+ `- #${field.id} ${field.name} (${field.slug}) [${field.type}]${field.required ? " required" : ""}`
49
+ );
50
+ }
51
+ return lines.join("\n");
52
+ });
53
+ } catch (error) {
54
+ printError(error, options);
55
+ } finally {
56
+ runtime.close();
57
+ }
58
+ }
59
+ async function createCollection(options) {
60
+ const runtime = await createGearuCliRuntime();
61
+ try {
62
+ if (!options.name) {
63
+ throw new Error("`--name` is required.");
64
+ }
65
+ const collection = await runtime.caller.collections.create({
66
+ name: options.name,
67
+ slug: options.slug,
68
+ description: options.description
69
+ });
70
+ printSuccess(collection, options, (result) => `Created collection #${result.id} ${result.name} (${result.slug}).`);
71
+ } catch (error) {
72
+ printError(error, options);
73
+ } finally {
74
+ runtime.close();
75
+ }
76
+ }
77
+ async function updateCollection(id, options) {
78
+ const runtime = await createGearuCliRuntime();
79
+ try {
80
+ if (options.name === void 0 && options.slug === void 0 && options.description === void 0) {
81
+ throw new Error("Provide at least one of `--name`, `--slug`, or `--description`.");
82
+ }
83
+ const collection = await runtime.caller.collections.update({
84
+ id,
85
+ name: options.name,
86
+ slug: options.slug,
87
+ description: options.description
88
+ });
89
+ if (!collection) {
90
+ throw new Error(`Collection #${id} was not found.`);
91
+ }
92
+ printSuccess(collection, options, (result) => `Updated collection #${result.id} ${result.name} (${result.slug}).`);
93
+ } catch (error) {
94
+ printError(error, options);
95
+ } finally {
96
+ runtime.close();
97
+ }
98
+ }
99
+ async function deleteCollection(id, options) {
100
+ const runtime = await createGearuCliRuntime();
101
+ try {
102
+ await runtime.caller.collections.delete({ id });
103
+ printSuccess({ id }, options, (result) => `Deleted collection #${result.id}.`);
104
+ } catch (error) {
105
+ printError(error, options);
106
+ } finally {
107
+ runtime.close();
108
+ }
109
+ }
110
+ export {
111
+ createCollection,
112
+ deleteCollection,
113
+ getCollection,
114
+ listCollections,
115
+ updateCollection
116
+ };
117
+ //# sourceMappingURL=collections-SC2PJQKG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/collections.ts"],"sourcesContent":["import { createGearuCliRuntime } from \"../lib/runtime\"\nimport { printError, printSuccess, type JsonFlagOption } from \"../lib/output\"\n\ninterface CollectionMutationOptions extends JsonFlagOption {\n name?: string\n slug?: string\n description?: string\n}\n\nexport async function listCollections(options: JsonFlagOption) {\n const runtime = await createGearuCliRuntime()\n\n try {\n const collections = await runtime.caller.collections.list()\n printSuccess(collections, options, (result) => {\n if (result.length === 0) {\n return \"No collections found.\"\n }\n\n return [\n `Found ${result.length} collection${result.length === 1 ? \"\" : \"s\"}.`,\n ...result.map(\n (collection) =>\n `#${collection.id} ${collection.name} (${collection.slug}) - ${collection.fields.length} field${collection.fields.length === 1 ? \"\" : \"s\"}, ${collection.entries.length} entr${collection.entries.length === 1 ? \"y\" : \"ies\"}`,\n ),\n ].join(\"\\n\")\n })\n } catch (error) {\n printError(error, options)\n } finally {\n runtime.close()\n }\n}\n\nexport async function getCollection(id: number, options: JsonFlagOption) {\n const runtime = await createGearuCliRuntime()\n\n try {\n const collection = await runtime.caller.collections.getById({ id })\n if (!collection) {\n throw new Error(`Collection #${id} was not found.`)\n }\n\n printSuccess(collection, options, (result) => {\n const lines = [`Collection #${result.id}: ${result.name} (${result.slug})`]\n if (result.description) {\n lines.push(`Description: ${result.description}`)\n }\n lines.push(`Fields: ${result.fields.length}`)\n for (const field of result.fields) {\n lines.push(\n `- #${field.id} ${field.name} (${field.slug}) [${field.type}]${field.required ? \" required\" : \"\"}`,\n )\n }\n return lines.join(\"\\n\")\n })\n } catch (error) {\n printError(error, options)\n } finally {\n runtime.close()\n }\n}\n\nexport async function createCollection(options: CollectionMutationOptions) {\n const runtime = await createGearuCliRuntime()\n\n try {\n if (!options.name) {\n throw new Error(\"`--name` is required.\")\n }\n\n const collection = await runtime.caller.collections.create({\n name: options.name,\n slug: options.slug,\n description: options.description,\n })\n\n printSuccess(collection, options, (result) => `Created collection #${result.id} ${result.name} (${result.slug}).`)\n } catch (error) {\n printError(error, options)\n } finally {\n runtime.close()\n }\n}\n\nexport async function updateCollection(id: number, options: CollectionMutationOptions) {\n const runtime = await createGearuCliRuntime()\n\n try {\n if (options.name === undefined && options.slug === undefined && options.description === undefined) {\n throw new Error(\"Provide at least one of `--name`, `--slug`, or `--description`.\")\n }\n\n const collection = await runtime.caller.collections.update({\n id,\n name: options.name,\n slug: options.slug,\n description: options.description,\n })\n\n if (!collection) {\n throw new Error(`Collection #${id} was not found.`)\n }\n\n printSuccess(collection, options, (result) => `Updated collection #${result.id} ${result.name} (${result.slug}).`)\n } catch (error) {\n printError(error, options)\n } finally {\n runtime.close()\n }\n}\n\nexport async function deleteCollection(id: number, options: JsonFlagOption) {\n const runtime = await createGearuCliRuntime()\n\n try {\n await runtime.caller.collections.delete({ id })\n printSuccess({ id }, options, (result) => `Deleted collection #${result.id}.`)\n } catch (error) {\n printError(error, options)\n } finally {\n runtime.close()\n }\n}\n"],"mappings":";;;;;;;;;;AAAA;AASA,eAAsB,gBAAgB,SAAyB;AAC7D,QAAM,UAAU,MAAM,sBAAsB;AAE5C,MAAI;AACF,UAAM,cAAc,MAAM,QAAQ,OAAO,YAAY,KAAK;AAC1D,iBAAa,aAAa,SAAS,CAAC,WAAW;AAC7C,UAAI,OAAO,WAAW,GAAG;AACvB,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,QACL,SAAS,OAAO,MAAM,cAAc,OAAO,WAAW,IAAI,KAAK,GAAG;AAAA,QAClE,GAAG,OAAO;AAAA,UACR,CAAC,eACC,IAAI,WAAW,EAAE,IAAI,WAAW,IAAI,KAAK,WAAW,IAAI,OAAO,WAAW,OAAO,MAAM,SAAS,WAAW,OAAO,WAAW,IAAI,KAAK,GAAG,KAAK,WAAW,QAAQ,MAAM,QAAQ,WAAW,QAAQ,WAAW,IAAI,MAAM,KAAK;AAAA,QAChO;AAAA,MACF,EAAE,KAAK,IAAI;AAAA,IACb,CAAC;AAAA,EACH,SAAS,OAAO;AACd,eAAW,OAAO,OAAO;AAAA,EAC3B,UAAE;AACA,YAAQ,MAAM;AAAA,EAChB;AACF;AAEA,eAAsB,cAAc,IAAY,SAAyB;AACvE,QAAM,UAAU,MAAM,sBAAsB;AAE5C,MAAI;AACF,UAAM,aAAa,MAAM,QAAQ,OAAO,YAAY,QAAQ,EAAE,GAAG,CAAC;AAClE,QAAI,CAAC,YAAY;AACf,Y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