| 108 | const patchAuditConstants = ( |
| 109 | content: string, |
| 110 | auditKey: string, |
| 111 | auditValue: string |
| 112 | ): string => { |
| 113 | if (content.includes(`${auditKey}:`)) { |
| 114 | return content; |
| 115 | } |
| 116 | |
| 117 | // Insert ` KEY: "value",\n` immediately before the closing `} as const;`. |
| 118 | const insertion = ` ${auditKey}: "${auditValue}",\n`; |
| 119 | const patched = content.replace(/(} as const;)/, `${insertion}$1`); |
| 120 | |
| 121 | if (patched === content) { |
| 122 | throw new Error( |
| 123 | "Could not auto-patch audit-log.constants.ts; AUDIT_ACTIONS block not found" |
| 124 | ); |
| 125 | } |
| 126 | |
| 127 | return patched; |
| 128 | }; |
| 129 | |
| 130 | const patchRelations = (content: string, filePrefix: string): string => { |
| 131 | if (content.includes(`export const ${filePrefix}Relations`)) { |
| 132 | throw new Error( |
| 133 | `Relation "${filePrefix}Relations" already exists in relations.ts` |