@kuckit/db 4.0.5 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/schema-discovery.js
CHANGED
|
@@ -138,7 +138,7 @@ function resolvePackageInfo(packageName) {
|
|
|
138
138
|
schemaDir: readPackageSchemaDir(root)
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
|
-
const DEFAULT_SCHEMA_DIR = "src/server/
|
|
141
|
+
const DEFAULT_SCHEMA_DIR = "src/server/schema";
|
|
142
142
|
/**
|
|
143
143
|
* Get schema paths for Drizzle configuration.
|
|
144
144
|
* Derives paths from kuckit.config.ts (single source of truth).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-discovery.js","names":["dirname","resolve","existsSync","createRequire","root: string | null"],"sources":["../../sdk/dist/loader-BJ2ClBV6.js","../src/schema-discovery.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport { existsSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\n\n//#region rolldown:runtime\nvar __require = /* @__PURE__ */ createRequire(import.meta.url);\n\n//#endregion\n//#region src/config/loader.ts\nconst CONFIG_FILES = [\n\t\"kuckit.config.ts\",\n\t\"kuckit.config.js\",\n\t\"kuckit.config.mjs\"\n];\n/**\n* Find the config file path by searching from cwd upward\n*/\nfunction findConfigFile(cwd = process.cwd()) {\n\tlet dir = cwd;\n\twhile (dir !== dirname(dir)) {\n\t\tfor (const file of CONFIG_FILES) {\n\t\t\tconst configPath = resolve(dir, file);\n\t\t\tif (existsSync(configPath)) return configPath;\n\t\t}\n\t\tdir = dirname(dir);\n\t}\n\tfor (const file of CONFIG_FILES) {\n\t\tconst configPath = resolve(dir, file);\n\t\tif (existsSync(configPath)) return configPath;\n\t}\n\treturn null;\n}\n/**\n* Check if a unified config file exists\n*/\nfunction hasUnifiedConfig(cwd = process.cwd()) {\n\treturn findConfigFile(cwd) !== null;\n}\n/**\n* Load Kuckit configuration from file\n*\n* Uses jiti for TypeScript support at runtime.\n* Falls back to dynamic import for JS/MJS files.\n*\n* @param cwd - Directory to start searching from (default: process.cwd())\n* @throws Error if config file not found or invalid\n*/\nasync function loadKuckitConfig(cwd = process.cwd()) {\n\tconst configPath = findConfigFile(cwd);\n\tif (!configPath) throw new Error(`No Kuckit config file found. Create a kuckit.config.ts at your project root.\\nSearched from: ${cwd}`);\n\tlet config;\n\tif (configPath.endsWith(\".ts\")) {\n\t\tconst { createJiti } = await import(\"jiti\");\n\t\tconst loaded = await createJiti(cwd, { interopDefault: true }).import(configPath);\n\t\tconfig = loaded.default ?? loaded;\n\t} else {\n\t\tconst loaded = await import(configPath);\n\t\tconfig = loaded.default ?? loaded;\n\t}\n\tif (!config || typeof config !== \"object\") throw new Error(`Invalid Kuckit config at ${configPath}: expected an object`);\n\tif (!Array.isArray(config.modules)) throw new Error(`Invalid Kuckit config at ${configPath}: 'modules' must be an array`);\n\treturn {\n\t\t...config,\n\t\t_configPath: configPath\n\t};\n}\n/**\n* Synchronously load config (for non-async contexts like drizzle.config.ts)\n* Uses jiti synchronously to load TypeScript config\n*/\nfunction loadKuckitConfigSync(cwd = process.cwd()) {\n\tconst configPath = findConfigFile(cwd);\n\tif (!configPath) return null;\n\ttry {\n\t\tconst { createJiti } = __require(\"jiti\");\n\t\tconst loaded = createJiti(cwd, { interopDefault: true })(configPath);\n\t\tconst config = loaded.default ?? loaded;\n\t\tif (!config || typeof config !== \"object\" || !Array.isArray(config.modules)) return null;\n\t\treturn {\n\t\t\t...config,\n\t\t\t_configPath: configPath\n\t\t};\n\t} catch {\n\t\treturn null;\n\t}\n}\n/**\n* Try to load config, returning null if not found\n*/\nasync function tryLoadKuckitConfig(cwd = process.cwd()) {\n\ttry {\n\t\treturn await loadKuckitConfig(cwd);\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n//#endregion\nexport { tryLoadKuckitConfig as a, loadKuckitConfigSync as i, hasUnifiedConfig as n, loadKuckitConfig as r, findConfigFile as t };\n//# sourceMappingURL=loader-BJ2ClBV6.js.map","import { existsSync, readdirSync } from 'fs'\nimport { resolve, dirname } from 'path'\nimport { fileURLToPath } from 'url'\nimport { createRequire } from 'module'\nimport { loadKuckitConfigSync, type KuckitModuleConfig } from '@kuckit/sdk/config/node'\n\nconst currentDirPath = dirname(fileURLToPath(import.meta.url))\nconst require = createRequire(import.meta.url)\n\n/**\n * Find the monorepo/project root by walking up from current directory.\n * Looks for kuckit.config.ts or package.json with workspaces.\n */\nfunction findProjectRoot(): string | null {\n\tlet dir = currentDirPath\n\tfor (let i = 0; i < 10; i++) {\n\t\tif (existsSync(resolve(dir, 'kuckit.config.ts'))) {\n\t\t\treturn dir\n\t\t}\n\t\tconst parent = dirname(dir)\n\t\tif (parent === dir) break\n\t\tdir = parent\n\t}\n\treturn null\n}\n\n/**\n * Scan workspace directories (packages/, apps/) for a package.\n * Fallback when require.resolve fails in monorepo context.\n */\nfunction findPackageInWorkspace(packageName: string, projectRoot: string): string | null {\n\tconst workspaceDirs = ['packages', 'apps']\n\n\tfor (const wsDir of workspaceDirs) {\n\t\tconst wsPath = resolve(projectRoot, wsDir)\n\t\tif (!existsSync(wsPath)) continue\n\n\t\ttry {\n\t\t\tconst entries = readdirSync(wsPath, { withFileTypes: true })\n\t\t\tfor (const entry of entries) {\n\t\t\t\tif (!entry.isDirectory()) continue\n\n\t\t\t\tconst pkgJsonPath = resolve(wsPath, entry.name, 'package.json')\n\t\t\t\tif (!existsSync(pkgJsonPath)) continue\n\n\t\t\t\ttry {\n\t\t\t\t\tconst pkgJson = JSON.parse(require('fs').readFileSync(pkgJsonPath, 'utf-8'))\n\t\t\t\t\tif (pkgJson.name === packageName) {\n\t\t\t\t\t\treturn resolve(wsPath, entry.name)\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Skip invalid package.json\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Skip unreadable directories\n\t\t}\n\t}\n\treturn null\n}\n\ninterface PackageInfo {\n\troot: string\n\tschemaDir?: string\n}\n\n/**\n * Read package.json kuckit.schemaDir field if present.\n */\nfunction readPackageSchemaDir(packageRoot: string): string | undefined {\n\ttry {\n\t\tconst pkgJsonPath = resolve(packageRoot, 'package.json')\n\t\tconst pkgJson = JSON.parse(require('fs').readFileSync(pkgJsonPath, 'utf-8'))\n\t\treturn pkgJson.kuckit?.schemaDir\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\n/**\n * Resolve a module's package root directory and optional schemaDir from package.json.\n * Falls back to workspace scanning in monorepo context.\n *\n * @param packageName - NPM package name (e.g., '@kuckit/users-module')\n * @returns Package info with root path and optional schemaDir, or null if not found\n */\nfunction resolvePackageInfo(packageName: string): PackageInfo | null {\n\tlet root: string | null = null\n\n\t// First try require.resolve (works for installed packages)\n\ttry {\n\t\tconst packageJsonPath = require.resolve(`${packageName}/package.json`)\n\t\troot = dirname(packageJsonPath)\n\t} catch {\n\t\t// Package not installed or doesn't have package.json exports\n\t\ttry {\n\t\t\tconst mainPath = require.resolve(packageName)\n\t\t\tlet dir = dirname(mainPath)\n\t\t\tfor (let i = 0; i < 10; i++) {\n\t\t\t\tif (existsSync(resolve(dir, 'package.json'))) {\n\t\t\t\t\troot = dir\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tconst parent = dirname(dir)\n\t\t\t\tif (parent === dir) break\n\t\t\t\tdir = parent\n\t\t\t}\n\t\t} catch {\n\t\t\t// Package not resolvable - try workspace scanning\n\t\t}\n\t}\n\n\t// Fallback: scan workspace directories (monorepo support)\n\tif (!root) {\n\t\tconst projectRoot = findProjectRoot()\n\t\tif (projectRoot) {\n\t\t\troot = findPackageInWorkspace(packageName, projectRoot)\n\t\t}\n\t}\n\n\tif (!root) return null\n\n\treturn {\n\t\troot,\n\t\tschemaDir: readPackageSchemaDir(root),\n\t}\n}\n\nconst DEFAULT_SCHEMA_DIR = 'src/server/adapters'\n\n/**\n * Get schema paths for Drizzle configuration.\n * Derives paths from kuckit.config.ts (single source of truth).\n *\n * Schema directory priority:\n * 1. kuckit.config.ts schemaDir option\n * 2. package.json kuckit.schemaDir field\n * 3. Default: 'src/server/adapters'\n *\n * Uses require.resolve to dynamically locate packages, supporting:\n * - Modules in packages/ directory\n * - Modules in apps/ directory\n * - External modules in node_modules\n * - Nested package directories\n *\n * Returns glob patterns (*.js) for compiled modules to prevent drizzle-kit\n * from loading .d.ts files which causes TypeScript parsing errors.\n *\n * @returns Array of absolute paths/globs to schema files, starting with core schema\n */\nexport function getModuleSchemaPaths(): string[] {\n\tconst coreSchema = resolve(currentDirPath, './schema')\n\n\t// Load config using the SDK's pure config loader (no side effects)\n\tconst config = loadKuckitConfigSync()\n\tif (!config) {\n\t\t// Fall back to just core schema if no config found\n\t\treturn [coreSchema]\n\t}\n\n\tconst modulePaths = config.modules\n\t\t.filter((m: KuckitModuleConfig) => m.enabled !== false)\n\t\t.map((m: KuckitModuleConfig) => {\n\t\t\tconst pkgInfo = resolvePackageInfo(m.package)\n\t\t\tif (!pkgInfo) return null\n\n\t\t\t// Priority: kuckit.config.ts > package.json kuckit.schemaDir > default\n\t\t\tconst schemaDir = m.schemaDir ?? pkgInfo.schemaDir ?? DEFAULT_SCHEMA_DIR\n\t\t\tconst schemaPath = resolve(pkgInfo.root, schemaDir)\n\n\t\t\tif (!existsSync(schemaPath)) return null\n\n\t\t\t// For compiled modules (dist/), return glob pattern to exclude .d.ts files\n\t\t\t// which cause drizzle-kit to fail with TypeScript parsing errors\n\t\t\tif (schemaDir.includes('dist')) {\n\t\t\t\treturn `${schemaPath}/*.js`\n\t\t\t}\n\n\t\t\treturn schemaPath\n\t\t})\n\t\t.filter((p): p is string => p !== null)\n\n\treturn [coreSchema, ...modulePaths]\n}\n"],"mappings":";;;;;;;;;AAKA,IAAI,YAA4B,8BAAc,OAAO,KAAK,IAAI;AAI9D,MAAM,eAAe;CACpB;CACA;CACA;CACA;;;;AAID,SAAS,eAAe,MAAM,QAAQ,KAAK,EAAE;CAC5C,IA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AS,sBAAsB;AACrC,KAAI,CAAC,OAEJ,QAAO,CAAC,WAAW;AAyBpB,QAAO,CAAC,YAAY,GAtBA,OAAO,QACzB,QAAQ,MAA0B,EAAE,YAAY,MAAM,CACtD,KAAK,MAA0B;EAC/B,MAAM,UAAU,mBAAmB,EAAE,QAAQ;AAC7C,MAAI,CAAC,QAAS,QAAO;EAGrB,MAAM,YAAY,EAAE,aAAa,QAAQ,aAAa;EACtD,MAAM,aAAa,QAAQ,QAAQ,MAAM,UAAU;AAEnD,MAAI,CAAC,WAAW,WAAW,CAAE,QAAO;AAIpC,MAAI,UAAU,SAAS,OAAO,CAC7B,QAAO,GAAG,WAAW;AAGtB,SAAO;GACN,CACD,QAAQ,MAAmB,MAAM,KAAK,CAEL"}
|
|
1
|
+
{"version":3,"file":"schema-discovery.js","names":["dirname","resolve","existsSync","createRequire","root: string | null"],"sources":["../../sdk/dist/loader-BJ2ClBV6.js","../src/schema-discovery.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport { existsSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\n\n//#region rolldown:runtime\nvar __require = /* @__PURE__ */ createRequire(import.meta.url);\n\n//#endregion\n//#region src/config/loader.ts\nconst CONFIG_FILES = [\n\t\"kuckit.config.ts\",\n\t\"kuckit.config.js\",\n\t\"kuckit.config.mjs\"\n];\n/**\n* Find the config file path by searching from cwd upward\n*/\nfunction findConfigFile(cwd = process.cwd()) {\n\tlet dir = cwd;\n\twhile (dir !== dirname(dir)) {\n\t\tfor (const file of CONFIG_FILES) {\n\t\t\tconst configPath = resolve(dir, file);\n\t\t\tif (existsSync(configPath)) return configPath;\n\t\t}\n\t\tdir = dirname(dir);\n\t}\n\tfor (const file of CONFIG_FILES) {\n\t\tconst configPath = resolve(dir, file);\n\t\tif (existsSync(configPath)) return configPath;\n\t}\n\treturn null;\n}\n/**\n* Check if a unified config file exists\n*/\nfunction hasUnifiedConfig(cwd = process.cwd()) {\n\treturn findConfigFile(cwd) !== null;\n}\n/**\n* Load Kuckit configuration from file\n*\n* Uses jiti for TypeScript support at runtime.\n* Falls back to dynamic import for JS/MJS files.\n*\n* @param cwd - Directory to start searching from (default: process.cwd())\n* @throws Error if config file not found or invalid\n*/\nasync function loadKuckitConfig(cwd = process.cwd()) {\n\tconst configPath = findConfigFile(cwd);\n\tif (!configPath) throw new Error(`No Kuckit config file found. Create a kuckit.config.ts at your project root.\\nSearched from: ${cwd}`);\n\tlet config;\n\tif (configPath.endsWith(\".ts\")) {\n\t\tconst { createJiti } = await import(\"jiti\");\n\t\tconst loaded = await createJiti(cwd, { interopDefault: true }).import(configPath);\n\t\tconfig = loaded.default ?? loaded;\n\t} else {\n\t\tconst loaded = await import(configPath);\n\t\tconfig = loaded.default ?? loaded;\n\t}\n\tif (!config || typeof config !== \"object\") throw new Error(`Invalid Kuckit config at ${configPath}: expected an object`);\n\tif (!Array.isArray(config.modules)) throw new Error(`Invalid Kuckit config at ${configPath}: 'modules' must be an array`);\n\treturn {\n\t\t...config,\n\t\t_configPath: configPath\n\t};\n}\n/**\n* Synchronously load config (for non-async contexts like drizzle.config.ts)\n* Uses jiti synchronously to load TypeScript config\n*/\nfunction loadKuckitConfigSync(cwd = process.cwd()) {\n\tconst configPath = findConfigFile(cwd);\n\tif (!configPath) return null;\n\ttry {\n\t\tconst { createJiti } = __require(\"jiti\");\n\t\tconst loaded = createJiti(cwd, { interopDefault: true })(configPath);\n\t\tconst config = loaded.default ?? loaded;\n\t\tif (!config || typeof config !== \"object\" || !Array.isArray(config.modules)) return null;\n\t\treturn {\n\t\t\t...config,\n\t\t\t_configPath: configPath\n\t\t};\n\t} catch {\n\t\treturn null;\n\t}\n}\n/**\n* Try to load config, returning null if not found\n*/\nasync function tryLoadKuckitConfig(cwd = process.cwd()) {\n\ttry {\n\t\treturn await loadKuckitConfig(cwd);\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n//#endregion\nexport { tryLoadKuckitConfig as a, loadKuckitConfigSync as i, hasUnifiedConfig as n, loadKuckitConfig as r, findConfigFile as t };\n//# sourceMappingURL=loader-BJ2ClBV6.js.map","import { existsSync, readdirSync } from 'fs'\nimport { resolve, dirname } from 'path'\nimport { fileURLToPath } from 'url'\nimport { createRequire } from 'module'\nimport { loadKuckitConfigSync, type KuckitModuleConfig } from '@kuckit/sdk/config/node'\n\nconst currentDirPath = dirname(fileURLToPath(import.meta.url))\nconst require = createRequire(import.meta.url)\n\n/**\n * Find the monorepo/project root by walking up from current directory.\n * Looks for kuckit.config.ts or package.json with workspaces.\n */\nfunction findProjectRoot(): string | null {\n\tlet dir = currentDirPath\n\tfor (let i = 0; i < 10; i++) {\n\t\tif (existsSync(resolve(dir, 'kuckit.config.ts'))) {\n\t\t\treturn dir\n\t\t}\n\t\tconst parent = dirname(dir)\n\t\tif (parent === dir) break\n\t\tdir = parent\n\t}\n\treturn null\n}\n\n/**\n * Scan workspace directories (packages/, apps/) for a package.\n * Fallback when require.resolve fails in monorepo context.\n */\nfunction findPackageInWorkspace(packageName: string, projectRoot: string): string | null {\n\tconst workspaceDirs = ['packages', 'apps']\n\n\tfor (const wsDir of workspaceDirs) {\n\t\tconst wsPath = resolve(projectRoot, wsDir)\n\t\tif (!existsSync(wsPath)) continue\n\n\t\ttry {\n\t\t\tconst entries = readdirSync(wsPath, { withFileTypes: true })\n\t\t\tfor (const entry of entries) {\n\t\t\t\tif (!entry.isDirectory()) continue\n\n\t\t\t\tconst pkgJsonPath = resolve(wsPath, entry.name, 'package.json')\n\t\t\t\tif (!existsSync(pkgJsonPath)) continue\n\n\t\t\t\ttry {\n\t\t\t\t\tconst pkgJson = JSON.parse(require('fs').readFileSync(pkgJsonPath, 'utf-8'))\n\t\t\t\t\tif (pkgJson.name === packageName) {\n\t\t\t\t\t\treturn resolve(wsPath, entry.name)\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Skip invalid package.json\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Skip unreadable directories\n\t\t}\n\t}\n\treturn null\n}\n\ninterface PackageInfo {\n\troot: string\n\tschemaDir?: string\n}\n\n/**\n * Read package.json kuckit.schemaDir field if present.\n */\nfunction readPackageSchemaDir(packageRoot: string): string | undefined {\n\ttry {\n\t\tconst pkgJsonPath = resolve(packageRoot, 'package.json')\n\t\tconst pkgJson = JSON.parse(require('fs').readFileSync(pkgJsonPath, 'utf-8'))\n\t\treturn pkgJson.kuckit?.schemaDir\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\n/**\n * Resolve a module's package root directory and optional schemaDir from package.json.\n * Falls back to workspace scanning in monorepo context.\n *\n * @param packageName - NPM package name (e.g., '@kuckit/users-module')\n * @returns Package info with root path and optional schemaDir, or null if not found\n */\nfunction resolvePackageInfo(packageName: string): PackageInfo | null {\n\tlet root: string | null = null\n\n\t// First try require.resolve (works for installed packages)\n\ttry {\n\t\tconst packageJsonPath = require.resolve(`${packageName}/package.json`)\n\t\troot = dirname(packageJsonPath)\n\t} catch {\n\t\t// Package not installed or doesn't have package.json exports\n\t\ttry {\n\t\t\tconst mainPath = require.resolve(packageName)\n\t\t\tlet dir = dirname(mainPath)\n\t\t\tfor (let i = 0; i < 10; i++) {\n\t\t\t\tif (existsSync(resolve(dir, 'package.json'))) {\n\t\t\t\t\troot = dir\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tconst parent = dirname(dir)\n\t\t\t\tif (parent === dir) break\n\t\t\t\tdir = parent\n\t\t\t}\n\t\t} catch {\n\t\t\t// Package not resolvable - try workspace scanning\n\t\t}\n\t}\n\n\t// Fallback: scan workspace directories (monorepo support)\n\tif (!root) {\n\t\tconst projectRoot = findProjectRoot()\n\t\tif (projectRoot) {\n\t\t\troot = findPackageInWorkspace(packageName, projectRoot)\n\t\t}\n\t}\n\n\tif (!root) return null\n\n\treturn {\n\t\troot,\n\t\tschemaDir: readPackageSchemaDir(root),\n\t}\n}\n\nconst DEFAULT_SCHEMA_DIR = 'src/server/schema'\n\n/**\n * Get schema paths for Drizzle configuration.\n * Derives paths from kuckit.config.ts (single source of truth).\n *\n * Schema directory priority:\n * 1. kuckit.config.ts schemaDir option\n * 2. package.json kuckit.schemaDir field\n * 3. Default: 'src/server/adapters'\n *\n * Uses require.resolve to dynamically locate packages, supporting:\n * - Modules in packages/ directory\n * - Modules in apps/ directory\n * - External modules in node_modules\n * - Nested package directories\n *\n * Returns glob patterns (*.js) for compiled modules to prevent drizzle-kit\n * from loading .d.ts files which causes TypeScript parsing errors.\n *\n * @returns Array of absolute paths/globs to schema files, starting with core schema\n */\nexport function getModuleSchemaPaths(): string[] {\n\tconst coreSchema = resolve(currentDirPath, './schema')\n\n\t// Load config using the SDK's pure config loader (no side effects)\n\tconst config = loadKuckitConfigSync()\n\tif (!config) {\n\t\t// Fall back to just core schema if no config found\n\t\treturn [coreSchema]\n\t}\n\n\tconst modulePaths = config.modules\n\t\t.filter((m: KuckitModuleConfig) => m.enabled !== false)\n\t\t.map((m: KuckitModuleConfig) => {\n\t\t\tconst pkgInfo = resolvePackageInfo(m.package)\n\t\t\tif (!pkgInfo) return null\n\n\t\t\t// Priority: kuckit.config.ts > package.json kuckit.schemaDir > default\n\t\t\tconst schemaDir = m.schemaDir ?? pkgInfo.schemaDir ?? DEFAULT_SCHEMA_DIR\n\t\t\tconst schemaPath = resolve(pkgInfo.root, schemaDir)\n\n\t\t\tif (!existsSync(schemaPath)) return null\n\n\t\t\t// For compiled modules (dist/), return glob pattern to exclude .d.ts files\n\t\t\t// which cause drizzle-kit to fail with TypeScript parsing errors\n\t\t\tif (schemaDir.includes('dist')) {\n\t\t\t\treturn `${schemaPath}/*.js`\n\t\t\t}\n\n\t\t\treturn schemaPath\n\t\t})\n\t\t.filter((p): p is string => p !== null)\n\n\treturn [coreSchema, ...modulePaths]\n}\n"],"mappings":";;;;;;;;;AAKA,IAAI,YAA4B,8BAAc,OAAO,KAAK,IAAI;AAI9D,MAAM,eAAe;CACpB;CACA;CACA;CACA;;;;AAID,SAAS,eAAe,MAAM,Q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