persistence-source-metadata.ts 729 B

123456789101112131415161718
  1. /** Stable source-file metadata for saved persistence inventories. */
  2. import type { PersistenceSchemaInventory } from './persistence-schema-model.ts'
  3. /**
  4. * Remove source line positions without changing schemas, names, or fingerprints.
  5. * @param inventory - validated inventory whose source metadata will be copied.
  6. * @returns an inventory with unique source paths in their original order.
  7. */
  8. export function withoutPersistenceSourceLines(inventory: PersistenceSchemaInventory): PersistenceSchemaInventory {
  9. return {
  10. ...inventory,
  11. types: inventory.types.map(type => ({
  12. ...type,
  13. sources: [...new Set(type.sources.map(source => source.replace(/(?::\d+(?::\d+)?|#L\d+(?:-L\d+)?)$/u, '')))],
  14. })),
  15. }
  16. }