@open-mercato/cli 0.4.6-develop-e321a4e2a1 → 0.4.6-main-24e64eef39
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/lib/generators/entity-ids.js +1 -1
- package/dist/lib/generators/entity-ids.js.map +2 -2
- package/dist/lib/generators/module-registry.js +0 -63
- package/dist/lib/generators/module-registry.js.map +2 -2
- package/dist/lib/testing/integration.js +2 -2
- package/dist/lib/testing/integration.js.map +2 -2
- package/dist/lib/utils.js +2 -2
- package/dist/lib/utils.js.map +2 -2
- package/package.json +2 -2
- package/src/lib/generators/entity-ids.ts +1 -1
- package/src/lib/generators/module-registry.ts +0 -57
- package/src/lib/testing/integration.ts +2 -2
- package/src/lib/utils.ts +2 -2
|
@@ -95,7 +95,7 @@ function writePerEntityFieldFiles(outRoot, fieldsByEntity) {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
function writeEntityFieldsRegistry(generatedRoot, fieldsByEntity) {
|
|
98
|
-
const entities = Object.keys(fieldsByEntity).sort(
|
|
98
|
+
const entities = Object.keys(fieldsByEntity).sort();
|
|
99
99
|
const imports = entities.length > 0 ? entities.map((e) => `import * as ${toVar(e)} from './entities/${e}/index'`).join("\n") : "";
|
|
100
100
|
const registryEntries = entities.length > 0 ? entities.map((e) => ` ${toVar(e)}`).join(",\n") : "";
|
|
101
101
|
const src = `// AUTO-GENERATED by mercato generate entity-ids
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/generators/entity-ids.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport ts from 'typescript'\nimport type { PackageResolver, ModuleEntry } from '../resolver'\nimport {\n calculateChecksum,\n readChecksumRecord,\n writeChecksumRecord,\n ensureDir,\n toVar,\n toSnake,\n rimrafDir,\n logGenerationResult,\n type GeneratorResult,\n createGeneratorResult,\n} from '../utils'\n\ntype GroupKey = '@app' | '@open-mercato/core' | string\ntype EntityFieldMap = Record<string, string[]>\n\nexport interface EntityIdsOptions {\n resolver: PackageResolver\n quiet?: boolean\n}\n\n/**\n * Extract exported class names from a TypeScript source file without dynamic import.\n * This is used for @app modules since Node.js can't import TypeScript files directly.\n */\nfunction parseExportedClassNamesFromFile(filePath: string): string[] {\n const src = fs.readFileSync(filePath, 'utf8')\n const sf = ts.createSourceFile(filePath, src, ts.ScriptTarget.ES2020, true, ts.ScriptKind.TS)\n const classNames: string[] = []\n\n sf.forEachChild((node) => {\n // Check for exported class declarations\n if (ts.isClassDeclaration(node) && node.name) {\n const hasExport = node.modifiers?.some(\n (m) => m.kind === ts.SyntaxKind.ExportKeyword\n )\n if (hasExport) {\n classNames.push(node.name.text)\n }\n }\n })\n\n return classNames\n}\n\nfunction parseEntityFieldsFromFile(filePath: string, exportedClassNames: string[]): EntityFieldMap {\n const src = fs.readFileSync(filePath, 'utf8')\n const sf = ts.createSourceFile(filePath, src, ts.ScriptTarget.ES2020, true, ts.ScriptKind.TS)\n\n const exported = new Set(exportedClassNames)\n const result: EntityFieldMap = {}\n\n function getDecoratorArgNameLiteral(dec: ts.Decorator | undefined): string | undefined {\n if (!dec) return undefined\n const expr = dec.expression\n if (!ts.isCallExpression(expr)) return undefined\n if (!expr.arguments.length) return undefined\n const first = expr.arguments[0]\n if (!ts.isObjectLiteralExpression(first)) return undefined\n for (const prop of first.properties) {\n if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name) && prop.name.text === 'name') {\n if (ts.isStringLiteral(prop.initializer)) return prop.initializer.text\n }\n }\n return undefined\n }\n\n function normalizeDbName(propertyName: string, _decoratorName?: string, nameOverride?: string): string {\n if (nameOverride) return nameOverride\n return toSnake(propertyName)\n }\n\n sf.forEachChild((node) => {\n if (!ts.isClassDeclaration(node) || !node.name) return\n const clsName = node.name.text\n if (!exported.has(clsName)) return\n const entityKey = toSnake(clsName)\n const fields: string[] = []\n\n for (const member of node.members) {\n if (!ts.isPropertyDeclaration(member) || !member.name) continue\n const name = ts.isIdentifier(member.name)\n ? member.name.text\n : ts.isStringLiteral(member.name)\n ? member.name.text\n : undefined\n if (!name) continue\n if (member.modifiers?.some((m) => m.kind === ts.SyntaxKind.StaticKeyword)) continue\n const decorators = ts.canHaveDecorators(member)\n ? ts.getDecorators(member) ?? []\n : []\n let dbName: string | undefined\n if (decorators && decorators.length) {\n for (const d of decorators) {\n const nameOverride = getDecoratorArgNameLiteral(d)\n dbName = normalizeDbName(name, undefined, nameOverride)\n if (dbName) break\n }\n }\n if (!dbName) dbName = normalizeDbName(name)\n fields.push(dbName)\n }\n result[entityKey] = Array.from(new Set(fields))\n })\n\n return result\n}\n\nfunction writePerEntityFieldFiles(outRoot: string, fieldsByEntity: EntityFieldMap): void {\n fs.mkdirSync(outRoot, { recursive: true })\n const desiredEntities = new Set(Object.keys(fieldsByEntity))\n for (const [entity, fields] of Object.entries(fieldsByEntity)) {\n const entDir = path.join(outRoot, entity)\n fs.mkdirSync(entDir, { recursive: true })\n const idx = fields.map((f) => `export const ${toVar(f)} = '${f}'`).join('\\n') + '\\n'\n fs.writeFileSync(path.join(entDir, 'index.ts'), idx)\n }\n\n const existingEntries = fs.existsSync(outRoot) ? fs.readdirSync(outRoot, { withFileTypes: true }) : []\n for (const entry of existingEntries) {\n if (!entry.isDirectory()) continue\n if (desiredEntities.has(entry.name)) continue\n rimrafDir(path.join(outRoot, entry.name))\n }\n}\n\nfunction writeEntityFieldsRegistry(generatedRoot: string, fieldsByEntity: EntityFieldMap): void {\n const entities = Object.keys(fieldsByEntity).sort((a, b) => a.localeCompare(b))\n\n // Always write the file, even if empty, to prevent TypeScript import errors\n const imports = entities.length > 0\n ? entities.map((e) => `import * as ${toVar(e)} from './entities/${e}/index'`).join('\\n')\n : ''\n const registryEntries = entities.length > 0\n ? entities.map((e) => ` ${toVar(e)}`).join(',\\n')\n : ''\n\n const src = `// AUTO-GENERATED by mercato generate entity-ids\n// Static registry for entity fields - eliminates dynamic imports for Turbopack compatibility\n${imports}\n\nexport const entityFieldsRegistry: Record<string, Record<string, string>> = {\n${registryEntries}\n}\n\nexport function getEntityFields(slug: string): Record<string, string> | undefined {\n return entityFieldsRegistry[slug]\n}\n`\n const outPath = path.join(generatedRoot, 'entity-fields-registry.ts')\n ensureDir(outPath)\n fs.writeFileSync(outPath, src)\n}\n\nexport async function generateEntityIds(options: EntityIdsOptions): Promise<GeneratorResult> {\n const { resolver, quiet = false } = options\n const result = createGeneratorResult()\n\n const outputDir = resolver.getOutputDir()\n const outFile = path.join(outputDir, 'entities.ids.generated.ts')\n const checksumFile = path.join(outputDir, 'entities.ids.generated.checksum')\n\n const entries = resolver.loadEnabledModules()\n\n const consolidated: Record<string, Record<string, string>> = {}\n const grouped: Record<GroupKey, Record<string, Record<string, string>>> = {}\n const modulesDict: Record<string, string> = {}\n const groupedModulesDict: Record<GroupKey, Record<string, string>> = {}\n\n const fieldsByGroup: Record<GroupKey, Record<string, EntityFieldMap>> = {}\n\n for (const entry of entries) {\n const modId = entry.id\n const roots = resolver.getModulePaths(entry)\n const imps = resolver.getModuleImportBase(entry)\n const group: GroupKey = (entry.from as GroupKey) || '@open-mercato/core'\n const isAppModule = entry.from === '@app'\n\n // Locate entities definition file (prefer app override)\n const appData = path.join(roots.appBase, 'data')\n const pkgData = path.join(roots.pkgBase, 'data')\n const appDb = path.join(roots.appBase, 'db')\n const pkgDb = path.join(roots.pkgBase, 'db')\n const bases = [appData, pkgData, appDb, pkgDb]\n const candidates = ['entities.override.ts', 'entities.ts', 'schema.ts']\n let importPath: string | null = null\n let filePath: string | null = null\n\n for (const base of bases) {\n for (const f of candidates) {\n const p = path.join(base, f)\n if (fs.existsSync(p)) {\n const fromApp = base.startsWith(roots.appBase)\n const sub = path.basename(base) // 'data' | 'db'\n importPath = `${fromApp ? imps.appBase : imps.pkgBase}/${sub}/${f.replace(/\\.ts$/, '')}`\n filePath = p\n break\n }\n }\n if (importPath) break\n }\n\n // No entities file found -> still register module id\n if (!filePath) {\n modulesDict[modId] = modId\n groupedModulesDict[group] = groupedModulesDict[group] || {}\n groupedModulesDict[group][modId] = modId\n continue\n }\n\n // Get exported class names by parsing TypeScript source directly\n // Since we always read from src/, we can parse TypeScript files\n const exportNames = parseExportedClassNamesFromFile(filePath)\n\n const entityNames = exportNames\n .map((k) => toSnake(k))\n .filter((k, idx, arr) => arr.indexOf(k) === idx)\n\n // Build dictionaries\n modulesDict[modId] = modId\n groupedModulesDict[group] = groupedModulesDict[group] || {}\n groupedModulesDict[group][modId] = modId\n\n consolidated[modId] = consolidated[modId] || {}\n grouped[group] = grouped[group] || {}\n grouped[group][modId] = grouped[group][modId] || {}\n\n for (const en of entityNames) {\n consolidated[modId][en] = `${modId}:${en}`\n grouped[group][modId][en] = `${modId}:${en}`\n }\n\n // Parse entity fields from TypeScript source\n const entityFieldMap = parseEntityFieldsFromFile(filePath, exportNames)\n fieldsByGroup[group] = fieldsByGroup[group] || {}\n fieldsByGroup[group][modId] = entityFieldMap\n }\n\n // Write consolidated output\n const consolidatedSrc = `// AUTO-GENERATED by mercato generate entity-ids\nexport const M = ${JSON.stringify(modulesDict, null, 2)} as const\nexport const E = ${JSON.stringify(consolidated, null, 2)} as const\nexport type KnownModuleId = keyof typeof M\nexport type KnownEntities = typeof E\n`\n\n // Check if content has changed\n const newChecksum = calculateChecksum(consolidatedSrc)\n let shouldWrite = true\n\n const existingRecord = readChecksumRecord(checksumFile)\n if (existingRecord && existingRecord.content === newChecksum) {\n shouldWrite = false\n }\n\n if (shouldWrite) {\n ensureDir(outFile)\n fs.writeFileSync(outFile, consolidatedSrc)\n writeChecksumRecord(checksumFile, { content: newChecksum, structure: '' })\n result.filesWritten.push(outFile)\n if (!quiet) {\n logGenerationResult(path.relative(process.cwd(), outFile), true)\n }\n } else {\n result.filesUnchanged.push(outFile)\n }\n\n // Write per-group outputs\n const groups = Object.keys(grouped) as GroupKey[]\n for (const g of groups) {\n const pkgOutputDir = resolver.getPackageOutputDir(g)\n // Skip @app group since it writes to the same location as the consolidated output\n if (g === '@app' && pkgOutputDir === outputDir) {\n continue\n }\n const out = path.join(pkgOutputDir, 'entities.ids.generated.ts')\n\n const src = `// AUTO-GENERATED by mercato generate entity-ids\nexport const M = ${JSON.stringify(groupedModulesDict[g] || {}, null, 2)} as const\nexport const E = ${JSON.stringify(grouped[g] || {}, null, 2)} as const\nexport type KnownModuleId = keyof typeof M\nexport type KnownEntities = typeof E\n`\n ensureDir(out)\n fs.writeFileSync(out, src)\n result.filesWritten.push(out)\n\n const fieldsRoot = path.join(pkgOutputDir, 'entities')\n const fieldsByModule = fieldsByGroup[g] || {}\n const combined: EntityFieldMap = {}\n for (const mId of Object.keys(fieldsByModule)) {\n const mMap = fieldsByModule[mId]\n for (const [entity, fields] of Object.entries(mMap)) {\n combined[entity] = Array.from(new Set([...(combined[entity] || []), ...fields]))\n }\n }\n writePerEntityFieldFiles(fieldsRoot, combined)\n\n // Generate static entity fields registry for Turbopack compatibility\n writeEntityFieldsRegistry(pkgOutputDir, combined)\n }\n\n // Write combined entity fields to root generated/ folder\n const combinedAll: EntityFieldMap = {}\n for (const groupFields of Object.values(fieldsByGroup)) {\n for (const mMap of Object.values(groupFields)) {\n for (const [entity, fields] of Object.entries(mMap)) {\n combinedAll[entity] = Array.from(new Set([...(combinedAll[entity] || []), ...fields]))\n }\n }\n }\n writePerEntityFieldFiles(path.join(outputDir, 'entities'), combinedAll)\n writeEntityFieldsRegistry(outputDir, combinedAll)\n\n return result\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,QAAQ;AAEf;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAcP,SAAS,gCAAgC,UAA4B;AACnE,QAAM,MAAM,GAAG,aAAa,UAAU,MAAM;AAC5C,QAAM,KAAK,G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QAAQ,EAAE,WAAW,KAAK,CAAC;AACxC,UAAM,MAAM,OAAO,IAAI,CAAC,MAAM,gBAAgB,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,IAAI,IAAI;AAChF,OAAG,cAAc,KAAK,KAAK,QAAQ,UAAU,GAAG,GAAG;AAAA,EACrD;AAEA,QAAM,kBAAkB,GAAG,WAAW,OAAO,IAAI,GAAG,YAAY,SAAS,EAAE,eAAe,KAAK,CAAC,IAAI,CAAC;AACrG,aAAW,SAAS,iBAAiB;AACnC,QAAI,CAAC,MAAM,YAAY,EAAG;AAC1B,QAAI,gBAAgB,IAAI,MAAM,IAAI,EAAG;AACrC,cAAU,KAAK,KAAK,SAAS,MAAM,IAAI,CAAC;AAAA,EAC1C;AACF;AAEA,SAAS,0BAA0B,eAAuB,gBAAsC;AAC9F,QAAM,WAAW,OAAO,KAAK,cAAc,EAAE,KAAK
|
|
4
|
+
"sourcesContent": ["import fs from 'node:fs'\nimport path from 'node:path'\nimport ts from 'typescript'\nimport type { PackageResolver, ModuleEntry } from '../resolver'\nimport {\n calculateChecksum,\n readChecksumRecord,\n writeChecksumRecord,\n ensureDir,\n toVar,\n toSnake,\n rimrafDir,\n logGenerationResult,\n type GeneratorResult,\n createGeneratorResult,\n} from '../utils'\n\ntype GroupKey = '@app' | '@open-mercato/core' | string\ntype EntityFieldMap = Record<string, string[]>\n\nexport interface EntityIdsOptions {\n resolver: PackageResolver\n quiet?: boolean\n}\n\n/**\n * Extract exported class names from a TypeScript source file without dynamic import.\n * This is used for @app modules since Node.js can't import TypeScript files directly.\n */\nfunction parseExportedClassNamesFromFile(filePath: string): string[] {\n const src = fs.readFileSync(filePath, 'utf8')\n const sf = ts.createSourceFile(filePath, src, ts.ScriptTarget.ES2020, true, ts.ScriptKind.TS)\n const classNames: string[] = []\n\n sf.forEachChild((node) => {\n // Check for exported class declarations\n if (ts.isClassDeclaration(node) && node.name) {\n const hasExport = node.modifiers?.some(\n (m) => m.kind === ts.SyntaxKind.ExportKeyword\n )\n if (hasExport) {\n classNames.push(node.name.text)\n }\n }\n })\n\n return classNames\n}\n\nfunction parseEntityFieldsFromFile(filePath: string, exportedClassNames: string[]): EntityFieldMap {\n const src = fs.readFileSync(filePath, 'utf8')\n const sf = ts.createSourceFile(filePath, src, ts.ScriptTarget.ES2020, true, ts.ScriptKind.TS)\n\n const exported = new Set(exportedClassNames)\n const result: EntityFieldMap = {}\n\n function getDecoratorArgNameLiteral(dec: ts.Decorator | undefined): string | undefined {\n if (!dec) return undefined\n const expr = dec.expression\n if (!ts.isCallExpression(expr)) return undefined\n if (!expr.arguments.length) return undefined\n const first = expr.arguments[0]\n if (!ts.isObjectLiteralExpression(first)) return undefined\n for (const prop of first.properties) {\n if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name) && prop.name.text === 'name') {\n if (ts.isStringLiteral(prop.initializer)) return prop.initializer.text\n }\n }\n return undefined\n }\n\n function normalizeDbName(propertyName: string, _decoratorName?: string, nameOverride?: string): string {\n if (nameOverride) return nameOverride\n return toSnake(propertyName)\n }\n\n sf.forEachChild((node) => {\n if (!ts.isClassDeclaration(node) || !node.name) return\n const clsName = node.name.text\n if (!exported.has(clsName)) return\n const entityKey = toSnake(clsName)\n const fields: string[] = []\n\n for (const member of node.members) {\n if (!ts.isPropertyDeclaration(member) || !member.name) continue\n const name = ts.isIdentifier(member.name)\n ? member.name.text\n : ts.isStringLiteral(member.name)\n ? member.name.text\n : undefined\n if (!name) continue\n if (member.modifiers?.some((m) => m.kind === ts.SyntaxKind.StaticKeyword)) continue\n const decorators = ts.canHaveDecorators(member)\n ? ts.getDecorators(member) ?? []\n : []\n let dbName: string | undefined\n if (decorators && decorators.length) {\n for (const d of decorators) {\n const nameOverride = getDecoratorArgNameLiteral(d)\n dbName = normalizeDbName(name, undefined, nameOverride)\n if (dbName) break\n }\n }\n if (!dbName) dbName = normalizeDbName(name)\n fields.push(dbName)\n }\n result[entityKey] = Array.from(new Set(fields))\n })\n\n return result\n}\n\nfunction writePerEntityFieldFiles(outRoot: string, fieldsByEntity: EntityFieldMap): void {\n fs.mkdirSync(outRoot, { recursive: true })\n const desiredEntities = new Set(Object.keys(fieldsByEntity))\n for (const [entity, fields] of Object.entries(fieldsByEntity)) {\n const entDir = path.join(outRoot, entity)\n fs.mkdirSync(entDir, { recursive: true })\n const idx = fields.map((f) => `export const ${toVar(f)} = '${f}'`).join('\\n') + '\\n'\n fs.writeFileSync(path.join(entDir, 'index.ts'), idx)\n }\n\n const existingEntries = fs.existsSync(outRoot) ? fs.readdirSync(outRoot, { withFileTypes: true }) : []\n for (const entry of existingEntries) {\n if (!entry.isDirectory()) continue\n if (desiredEntities.has(entry.name)) continue\n rimrafDir(path.join(outRoot, entry.name))\n }\n}\n\nfunction writeEntityFieldsRegistry(generatedRoot: string, fieldsByEntity: EntityFieldMap): void {\n const entities = Object.keys(fieldsByEntity).sort()\n\n // Always write the file, even if empty, to prevent TypeScript import errors\n const imports = entities.length > 0\n ? entities.map((e) => `import * as ${toVar(e)} from './entities/${e}/index'`).join('\\n')\n : ''\n const registryEntries = entities.length > 0\n ? entities.map((e) => ` ${toVar(e)}`).join(',\\n')\n : ''\n\n const src = `// AUTO-GENERATED by mercato generate entity-ids\n// Static registry for entity fields - eliminates dynamic imports for Turbopack compatibility\n${imports}\n\nexport const entityFieldsRegistry: Record<string, Record<string, string>> = {\n${registryEntries}\n}\n\nexport function getEntityFields(slug: string): Record<string, string> | undefined {\n return entityFieldsRegistry[slug]\n}\n`\n const outPath = path.join(generatedRoot, 'entity-fields-registry.ts')\n ensureDir(outPath)\n fs.writeFileSync(outPath, src)\n}\n\nexport async function generateEntityIds(options: EntityIdsOptions): Promise<GeneratorResult> {\n const { resolver, quiet = false } = options\n const result = createGeneratorResult()\n\n const outputDir = resolver.getOutputDir()\n const outFile = path.join(outputDir, 'entities.ids.generated.ts')\n const checksumFile = path.join(outputDir, 'entities.ids.generated.checksum')\n\n const entries = resolver.loadEnabledModules()\n\n const consolidated: Record<string, Record<string, string>> = {}\n const grouped: Record<GroupKey, Record<string, Record<string, string>>> = {}\n const modulesDict: Record<string, string> = {}\n const groupedModulesDict: Record<GroupKey, Record<string, string>> = {}\n\n const fieldsByGroup: Record<GroupKey, Record<string, EntityFieldMap>> = {}\n\n for (const entry of entries) {\n const modId = entry.id\n const roots = resolver.getModulePaths(entry)\n const imps = resolver.getModuleImportBase(entry)\n const group: GroupKey = (entry.from as GroupKey) || '@open-mercato/core'\n const isAppModule = entry.from === '@app'\n\n // Locate entities definition file (prefer app override)\n const appData = path.join(roots.appBase, 'data')\n const pkgData = path.join(roots.pkgBase, 'data')\n const appDb = path.join(roots.appBase, 'db')\n const pkgDb = path.join(roots.pkgBase, 'db')\n const bases = [appData, pkgData, appDb, pkgDb]\n const candidates = ['entities.override.ts', 'entities.ts', 'schema.ts']\n let importPath: string | null = null\n let filePath: string | null = null\n\n for (const base of bases) {\n for (const f of candidates) {\n const p = path.join(base, f)\n if (fs.existsSync(p)) {\n const fromApp = base.startsWith(roots.appBase)\n const sub = path.basename(base) // 'data' | 'db'\n importPath = `${fromApp ? imps.appBase : imps.pkgBase}/${sub}/${f.replace(/\\.ts$/, '')}`\n filePath = p\n break\n }\n }\n if (importPath) break\n }\n\n // No entities file found -> still register module id\n if (!filePath) {\n modulesDict[modId] = modId\n groupedModulesDict[group] = groupedModulesDict[group] || {}\n groupedModulesDict[group][modId] = modId\n continue\n }\n\n // Get exported class names by parsing TypeScript source directly\n // Since we always read from src/, we can parse TypeScript files\n const exportNames = parseExportedClassNamesFromFile(filePath)\n\n const entityNames = exportNames\n .map((k) => toSnake(k))\n .filter((k, idx, arr) => arr.indexOf(k) === idx)\n\n // Build dictionaries\n modulesDict[modId] = modId\n groupedModulesDict[group] = groupedModulesDict[group] || {}\n groupedModulesDict[group][modId] = modId\n\n consolidated[modId] = consolidated[modId] || {}\n grouped[group] = grouped[group] || {}\n grouped[group][modId] = grouped[group][modId] || {}\n\n for (const en of entityNames) {\n consolidated[modId][en] = `${modId}:${en}`\n grouped[group][modId][en] = `${modId}:${en}`\n }\n\n // Parse entity fields from TypeScript source\n const entityFieldMap = parseEntityFieldsFromFile(filePath, exportNames)\n fieldsByGroup[group] = fieldsByGroup[group] || {}\n fieldsByGroup[group][modId] = entityFieldMap\n }\n\n // Write consolidated output\n const consolidatedSrc = `// AUTO-GENERATED by mercato generate entity-ids\nexport const M = ${JSON.stringify(modulesDict, null, 2)} as const\nexport const E = ${JSON.stringify(consolidated, null, 2)} as const\nexport type KnownModuleId = keyof typeof M\nexport type KnownEntities = typeof E\n`\n\n // Check if content has changed\n const newChecksum = calculateChecksum(consolidatedSrc)\n let shouldWrite = true\n\n const existingRecord = readChecksumRecord(checksumFile)\n if (existingRecord && existingRecord.content === newChecksum) {\n shouldWrite = false\n }\n\n if (shouldWrite) {\n ensureDir(outFile)\n fs.writeFileSync(outFile, consolidatedSrc)\n writeChecksumRecord(checksumFile, { content: newChecksum, structure: '' })\n result.filesWritten.push(outFile)\n if (!quiet) {\n logGenerationResult(path.relative(process.cwd(), outFile), true)\n }\n } else {\n result.filesUnchanged.push(outFile)\n }\n\n // Write per-group outputs\n const groups = Object.keys(grouped) as GroupKey[]\n for (const g of groups) {\n const pkgOutputDir = resolver.getPackageOutputDir(g)\n // Skip @app group since it writes to the same location as the consolidated output\n if (g === '@app' && pkgOutputDir === outputDir) {\n continue\n }\n const out = path.join(pkgOutputDir, 'entities.ids.generated.ts')\n\n const src = `// AUTO-GENERATED by mercato generate entity-ids\nexport const M = ${JSON.stringify(groupedModulesDict[g] || {}, null, 2)} as const\nexport const E = ${JSON.stringify(grouped[g] || {}, null, 2)} as const\nexport type KnownModuleId = keyof typeof M\nexport type KnownEntities = typeof E\n`\n ensureDir(out)\n fs.writeFileSync(out, src)\n result.filesWritten.push(out)\n\n const fieldsRoot = path.join(pkgOutputDir, 'entities')\n const fieldsByModule = fieldsByGroup[g] || {}\n const combined: EntityFieldMap = {}\n for (const mId of Object.keys(fieldsByModule)) {\n const mMap = fieldsByModule[mId]\n for (const [entity, fields] of Object.entries(mMap)) {\n combined[entity] = Array.from(new Set([...(combined[entity] || []), ...fields]))\n }\n }\n writePerEntityFieldFiles(fieldsRoot, combined)\n\n // Generate static entity fields registry for Turbopack compatibility\n writeEntityFieldsRegistry(pkgOutputDir, combined)\n }\n\n // Write combined entity fields to root generated/ folder\n const combinedAll: EntityFieldMap = {}\n for (const groupFields of Object.values(fieldsByGroup)) {\n for (const mMap of Object.values(groupFields)) {\n for (const [entity, fields] of Object.entries(mMap)) {\n combinedAll[entity] = Array.from(new Set([...(combinedAll[entity] || []), ...fields]))\n }\n }\n }\n writePerEntityFieldFiles(path.join(outputDir, 'entities'), combinedAll)\n writeEntityFieldsRegistry(outputDir, combinedAll)\n\n return result\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,QAAQ;AAEf;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AAcP,SAAS,gCAAgC,UAA4B;AACnE,QAAM,MAAM,GAAG,aAAa,UAAU,MAAM;AAC5C,QAAM,KAAK,GAAG,iBAAiB,UAAU,KAAK,GAAG,aAAa,QAAQ,MAAM,GAAG,WAAW,EAAE;AAC5F,QAAM,aAAuB,CAAC;AAE9B,KAAG,aAAa,CAAC,SAAS;AAExB,QAAI,GAAG,mBAAmB,IAAI,KAAK,KAAK,MAAM;AAC5C,YAAM,YAAY,KAAK,WAAW;AAAA,QAChC,CAAC,MAAM,EAAE,SAAS,GAAG,WAAW;AAAA,MAClC;AACA,UAAI,WAAW;AACb,mBAAW,KAAK,KAAK,KAAK,IAAI;AAAA,MAChC;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAEA,SAAS,0BAA0B,UAAkB,oBAA8C;AACjG,QAAM,MAAM,GAAG,aAAa,UAAU,MAAM;AAC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ACpD,KAAK,UAAU,QAAQ,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC;AAAA;AAAA;AAAA;AAIxD,cAAU,GAAG;AACb,OAAG,cAAc,KAAK,GAAG;AACzB,WAAO,aAAa,KAAK,GAAG;AAE5B,UAAM,aAAa,KAAK,KAAK,cAAc,UAAU;AACrD,UAAM,iBAAiB,cAAc,CAAC,KAAK,CAAC;AAC5C,UAAM,WAA2B,CAAC;AAClC,eAAW,OAAO,OAAO,KAAK,cAAc,GAAG;AAC7C,YAAM,OAAO,eAAe,GAAG;AAC/B,iBAAW,CAAC,QAAQ,MAAM,KAAK,OAAO,QAAQ,IAAI,GAAG;AACnD,iBAAS,MAAM,IAAI,MAAM,KAAK,oBAAI,IAAI,CAAC,GAAI,SAAS,MAAM,KAAK,CAAC,GAAI,GAAG,MAAM,CAAC,CAAC;AAAA,MACjF;AAAA,IACF;AACA,6BAAyB,YAAY,QAAQ;AAG7C,8BAA0B,cAAc,QAAQ;AAAA,EAClD;AAGA,QAAM,cAA8B,CAAC;AACrC,aAAW,eAAe,OAAO,OAAO,aAAa,GAAG;AACtD,eAAW,QAAQ,OAAO,OAAO,WAAW,GAAG;AAC7C,iBAAW,CAAC,QAAQ,MAAM,KAAK,OAAO,QAAQ,IAAI,GAAG;AACnD,oBAAY,MAAM,IAAI,MAAM,KAAK,oBAAI,IAAI,CAAC,GAAI,YAAY,MAAM,KAAK,CAAC,GAAI,GAAG,MAAM,CAAC,CAAC;AAAA,MACvF;AAAA,IACF;AAAA,EACF;AACA,2BAAyB,KAAK,KAAK,WAAW,UAAU,GAAG,WAAW;AACtE,4BAA0B,WAAW,WAAW;AAEhD,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -295,10 +295,6 @@ async function generateModuleRegistry(options) {
|
|
|
295
295
|
const transFieldsChecksumFile = path.join(outputDir, "translations-fields.generated.checksum");
|
|
296
296
|
const enrichersOutFile = path.join(outputDir, "enrichers.generated.ts");
|
|
297
297
|
const enrichersChecksumFile = path.join(outputDir, "enrichers.generated.checksum");
|
|
298
|
-
const interceptorsOutFile = path.join(outputDir, "interceptors.generated.ts");
|
|
299
|
-
const interceptorsChecksumFile = path.join(outputDir, "interceptors.generated.checksum");
|
|
300
|
-
const componentOverridesOutFile = path.join(outputDir, "component-overrides.generated.ts");
|
|
301
|
-
const componentOverridesChecksumFile = path.join(outputDir, "component-overrides.generated.checksum");
|
|
302
298
|
const inboxActionsOutFile = path.join(outputDir, "inbox-actions.generated.ts");
|
|
303
299
|
const inboxActionsChecksumFile = path.join(outputDir, "inbox-actions.generated.checksum");
|
|
304
300
|
const enabled = resolver.loadEnabledModules();
|
|
@@ -330,10 +326,6 @@ async function generateModuleRegistry(options) {
|
|
|
330
326
|
const transFieldsImports = [];
|
|
331
327
|
const enricherConfigs = [];
|
|
332
328
|
const enricherImports = [];
|
|
333
|
-
const interceptorConfigs = [];
|
|
334
|
-
const interceptorImports = [];
|
|
335
|
-
const componentOverrideConfigs = [];
|
|
336
|
-
const componentOverrideImports = [];
|
|
337
329
|
const inboxActionsConfigs = [];
|
|
338
330
|
const inboxActionsImports = [];
|
|
339
331
|
for (const entry of enabled) {
|
|
@@ -528,28 +520,6 @@ async function generateModuleRegistry(options) {
|
|
|
528
520
|
standaloneConfigs: enricherConfigs,
|
|
529
521
|
configExpr: (n, id) => `{ moduleId: '${id}', enrichers: ((${n} as any).enrichers ?? (${n} as any).default ?? []) }`
|
|
530
522
|
});
|
|
531
|
-
processStandaloneConfig({
|
|
532
|
-
roots,
|
|
533
|
-
imps,
|
|
534
|
-
modId,
|
|
535
|
-
importIdRef,
|
|
536
|
-
relativePath: "api/interceptors.ts",
|
|
537
|
-
prefix: "INTERCEPTORS",
|
|
538
|
-
standaloneImports: interceptorImports,
|
|
539
|
-
standaloneConfigs: interceptorConfigs,
|
|
540
|
-
configExpr: (n, id) => `{ moduleId: '${id}', interceptors: ((${n} as any).interceptors ?? (${n} as any).default ?? []) }`
|
|
541
|
-
});
|
|
542
|
-
processStandaloneConfig({
|
|
543
|
-
roots,
|
|
544
|
-
imps,
|
|
545
|
-
modId,
|
|
546
|
-
importIdRef,
|
|
547
|
-
relativePath: "widgets/components.ts",
|
|
548
|
-
prefix: "COMPONENT_OVERRIDES",
|
|
549
|
-
standaloneImports: componentOverrideImports,
|
|
550
|
-
standaloneConfigs: componentOverrideConfigs,
|
|
551
|
-
configExpr: (n, id) => `{ moduleId: '${id}', componentOverrides: ((${n} as any).componentOverrides ?? (${n} as any).default ?? []) }`
|
|
552
|
-
});
|
|
553
523
|
let transFieldsImportName = null;
|
|
554
524
|
transFieldsImportName = processStandaloneConfig({
|
|
555
525
|
roots,
|
|
@@ -1137,39 +1107,6 @@ export function getRegisteredActionTypes(): string[] {
|
|
|
1137
1107
|
}
|
|
1138
1108
|
`;
|
|
1139
1109
|
writeGeneratedFile({ outFile: inboxActionsOutFile, checksumFile: inboxActionsChecksumFile, content: inboxActionsOutput, structureChecksum, result, quiet });
|
|
1140
|
-
const interceptorEntriesLiteral = interceptorConfigs.join(",\n ");
|
|
1141
|
-
const interceptorImportSection = interceptorImports.join("\n");
|
|
1142
|
-
const interceptorsOutput = `// AUTO-GENERATED by mercato generate registry
|
|
1143
|
-
import type { ApiInterceptor } from '@open-mercato/shared/lib/crud/api-interceptor'
|
|
1144
|
-
${interceptorImportSection ? `
|
|
1145
|
-
${interceptorImportSection}
|
|
1146
|
-
` : "\n"}type InterceptorEntry = { moduleId: string; interceptors: ApiInterceptor[] }
|
|
1147
|
-
|
|
1148
|
-
export const interceptorEntries: InterceptorEntry[] = [
|
|
1149
|
-
${interceptorEntriesLiteral ? ` ${interceptorEntriesLiteral}
|
|
1150
|
-
` : ""}]
|
|
1151
|
-
`;
|
|
1152
|
-
writeGeneratedFile({ outFile: interceptorsOutFile, checksumFile: interceptorsChecksumFile, content: interceptorsOutput, structureChecksum, result, quiet });
|
|
1153
|
-
const componentOverrideEntriesLiteral = componentOverrideConfigs.join(",\n ");
|
|
1154
|
-
const componentOverrideImportSection = componentOverrideImports.join("\n");
|
|
1155
|
-
const componentOverridesOutput = `// AUTO-GENERATED by mercato generate registry
|
|
1156
|
-
import type { ComponentOverride } from '@open-mercato/shared/modules/widgets/component-registry'
|
|
1157
|
-
${componentOverrideImportSection ? `
|
|
1158
|
-
${componentOverrideImportSection}
|
|
1159
|
-
` : "\n"}type ComponentOverrideEntry = { moduleId: string; componentOverrides: ComponentOverride[] }
|
|
1160
|
-
|
|
1161
|
-
export const componentOverrideEntries: ComponentOverrideEntry[] = [
|
|
1162
|
-
${componentOverrideEntriesLiteral ? ` ${componentOverrideEntriesLiteral}
|
|
1163
|
-
` : ""}]
|
|
1164
|
-
`;
|
|
1165
|
-
writeGeneratedFile({
|
|
1166
|
-
outFile: componentOverridesOutFile,
|
|
1167
|
-
checksumFile: componentOverridesChecksumFile,
|
|
1168
|
-
content: componentOverridesOutput,
|
|
1169
|
-
structureChecksum,
|
|
1170
|
-
result,
|
|
1171
|
-
quiet
|
|
1172
|
-
});
|
|
1173
1110
|
return result;
|
|
1174
1111
|
}
|
|
1175
1112
|
async function generateModuleRegistryCli(options) {
|