| 74 | } |
| 75 | |
| 76 | export const createPiece = <PieceAuth extends PieceAuthProperty | PieceAuthProperty[] | undefined>( |
| 77 | params: CreatePieceParams<PieceAuth> |
| 78 | ) => { |
| 79 | if(params.auth && Array.isArray(params.auth)) { |
| 80 | const isUnique = params.auth.every((auth, index, self) => |
| 81 | index === self.findIndex((t) => t.type === auth.type) |
| 82 | ); |
| 83 | if(!isUnique) { |
| 84 | throw new Error('Auth properties must be unique by type'); |
| 85 | } |
| 86 | } |
| 87 | return new Piece<PieceAuth>( |
| 88 | params.displayName, |
| 89 | params.logoUrl, |
| 90 | params.authors ?? [], |
| 91 | params.events, |
| 92 | params.actions, |
| 93 | params.triggers, |
| 94 | params.categories ?? [], |
| 95 | params.auth, |
| 96 | params.minimumSupportedRelease, |
| 97 | params.maximumSupportedRelease, |
| 98 | params.description, |
| 99 | ); |
| 100 | }; |
| 101 | |
| 102 | type CreatePieceParams< |
| 103 | PieceAuth extends PieceAuthProperty | PieceAuthProperty[] | undefined = undefined |