(definitions: ReadonlyArray<Definition>)
| 74 | } |
| 75 | |
| 76 | export function latest(definitions: ReadonlyArray<Definition>) { |
| 77 | return readonlyMap( |
| 78 | definitions.reduce((result, definition) => { |
| 79 | const existing = result.get(definition.type) |
| 80 | if (!existing) { |
| 81 | result.set(definition.type, definition) |
| 82 | return result |
| 83 | } |
| 84 | if (definition.durable && existing.durable && definition.durable.version !== existing.durable.version) { |
| 85 | if (definition.durable.version > existing.durable.version) result.set(definition.type, definition) |
| 86 | return result |
| 87 | } |
| 88 | if (definition !== existing) throw new Error(`Duplicate latest event definition for ${definition.type}`) |
| 89 | return result |
| 90 | }, new Map<string, Definition>()), |
| 91 | ) |
| 92 | } |
| 93 | |
| 94 | export function versionedType(type: string, version: number) { |
| 95 | return `${type}.${version}` |
no test coverage detected